Modul:Kembox/Chembox Structure

Kembox/Chembox Structure[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

local csopfej = "Kristályszerkezet"

local boxtbl = {   -- a paraméterek sorrendje és infóboxbeli felirata. Az 1-es sorszám fenntartva csopfej-nek.
        CrystalStruct           = { 2, "[[Kristályszerkezet]]" },
        SpaceGroup              = { 3, "[[Tércsoport]]" },
        Coordination            = { 4, "[[Koordinációs geometria|Koordinációs<br/>geometria]]" },
--                                                              -- az 5-ös sorszám fenntartva LattConst-nak (lásd alább)
--                                                              -- a 6-os sorszám fenntartva LattConstAngle-nak (lásd alább)
        MolShape                = { 7, "[[Molekulaforma]]" },
        OrbitalHybridisation    = { 8, "[[Hibridizáció]]" },
        Dipole                  = { 9, "[[Dipólusmomentum]]" },
        }

local szintbl = {  -- szinonimaszótár. Programon belül Chembox_new neveit használjuk.
        ["KristálySzerkezet"]   = 'CrystalStruct',               -- Chembox_új
        ["kristályszerkezet"]   = 'CrystalStruct',               -- Vegyület_infobox
        ["TérCsoport"]          = 'SpaceGroup',                  -- Chembox_új
        ["Koordináció"]         = 'Coordination',                -- Chembox_új
        ["koordináció"]         = 'Coordination',                -- Vegyület_infobox
        ["RácsÁllandó_a"]       = 'LattConst_a',                 -- Chembox_új
        ["RácsÁllandó_b"]       = 'LattConst_b',                 -- Chembox_új
        ["RácsÁllandó_c"]       = 'LattConst_c',                 -- Chembox_új
        ["RácsÁllandó_alpha"]   = 'LattConst_alpha',             -- Chembox_új
        ["RácsÁllandó_beta"]    = 'LattConst_beta',              -- Chembox_új
        ["RácsÁllandó_gamma"]   = 'LattConst_gamma',             -- Chembox_új
        ["MolAlak"]             = 'MolShape',                    -- Chembox_új
        ["molekulaalak"]        = 'MolShape',                    -- Vegyület_infobox
        ["OrbitálHibridizáció"] = 'OrbitalHybridisation',        -- Chembox_új
        ["Dipólus"]             = 'Dipole',                      -- Chembox_új
        }


local munka = {}    -- { { sorsz, címke }, érték }
local uto   = {}    -- utófeldolgozást igénylő paraméterek (egy eredménysor több paraméterből áll elő)

function egysor(nev,ertek)
    local utotbl = {    -- automatikusan uto-ba kerülő paraméterek listája. A true nem kell, de enélkül nem lesz asszociatív a tömb.
          LattConst_a           = true,
          LattConst_b           = true,
          LattConst_c           = true,
          LattConst_alpha       = true,
          LattConst_beta        = true,
          LattConst_gamma       = true,
          }

    if szintbl[nev] then n = szintbl[nev] else n = nev end  -- n a Chembox_new-beli név
    if boxtbl[n] and ertek and #ertek > 0                   -- a boxtbl tábla (lásd feljebb) az ismert paramétereket és azok sorrendjét tartalmazza
    then   table.insert(munka,{boxtbl[n],ertek})            -- az üres paramétereket nem írjuk ki
    end
    if utotbl[n] and ertek and #ertek > 0 then uto[n] = ertek end       -- a második menetben feldolgozandó paraméter: az elsőben nincs vele tennivaló
end


function menet2()
    local LattConst             = { 5, "[[Rácsállandó]]" }
    local LattConstAngle        = { 6, "[[Rácsállandó]]-szög" }

--  Rácsállandó
    if uto.LattConst_a
    then   str = 'a&nbsp;=&nbsp;'..uto.LattConst_a..'&nbsp;Å'
           if uto.LattConst_b then str = str..', b&nbsp;=&nbsp;'..uto.LattConst_b..'&nbsp;Å' end
           if uto.LattConst_c then str = str..', c&nbsp;=&nbsp;'..uto.LattConst_c..'&nbsp;Å' end
           table.insert(munka,{LattConst,str})
    end
--  Rácsállandó-szög
    if uto.LattConst_alpha or uto.LattConst_beta or uto.LattConst_gamma
    then   if not uto.LattConst_alpha then uto.LattConst_alpha = '90' end
           if not uto.LattConst_beta  then uto.LattConst_beta  = '90' end
           if not uto.LattConst_gamma then uto.LattConst_gamma = '90' end
           str = 'α&nbsp;=&nbsp;'..uto.LattConst_alpha..'°'
           str = str..', β&nbsp;=&nbsp;'..uto.LattConst_beta..'°'
           str = str..', γ&nbsp;=&nbsp;'..uto.LattConst_gamma..'°'
           table.insert(munka,{LattConstAngle,str})
    end
end


local eredm = {}    -- { címke, érték } rendezve

-- A munka-beli értékek rendezése és kiírása
local function rendez(hivo)
    if next(munka)
    then    -- van megadott paraméter
          local kozos = require("Module:Kembox/kozos")
          eredm[1] = csopfej
          kozos.adatcsoport(munka,eredm)       -- munka rendezése és átmásolása eredm-be
          return kozos.kiir(eredm,hivo)
    end
return ""
end


-- Kívülről is hívható függvények
local p = {}

function p.Chembox_Structure(frame)
    local hivo  = frame.args['infobox']   -- hívó sablon
    local szulo = frame:getParent()       -- a chembox_related sablon által kapott paraméterek

    for nev,ertek in szulo:argumentPairs()
    do     egysor(nev,ertek)
    end
    menet2()
    return rendez(hivo)
end


-- Hívás modulból
function p.lua(partbl,hivo)
    for nev,ertek in pairs(partbl)
    do    egysor(nev,ertek)
    end
    menet2()
    return rendez(hivo)
end

return p;