-- -- EEEEEEEEEE GGGGGG wwww wwww -- EEEEEEEEEE GGGGGGGGGG wwww wwww -- EEEE GGGG GGGG wwww wwww wwww -- EEEE GGGG wwww wwww wwww -- EEEEEEE GGGG GGGGGGG wwww wwwwww wwww -- EEEEEEE GGGG GGGGGGG wwww wwwwww wwww -- EEEE GGGG GGGG wwww wwwwwwww wwww -- EEEE GGGG GGGG wwww wwww wwww wwww -- EEEEEEEEEE GGGGGGGGGG wwwwwwww wwwwwwww -- EEEEEEEEEE GGGGGG wwwwwww wwwwwww -- -- DOORMatch.lua by EgalWare s.r.l. -- definizione del Modulo local DOORMatch = {} DOORMatch.OutTemplate = "" -- Intestazioni require( 'EgtBase') EgtEnableDebug( false) -- per messaggi -- EgtAddToPackagePath( EgtGetSourceDir() .. '?.lua') -- EgtAddToPackagePath( DGD.BASEDIR .. '?.lua') -- dichairazione delle variabili locali del modulo che devono essere caricate all'avvio local TemplateDirectory -- direttorio + file template local MatchTable -- tabella delle associazioni local CompoDirectory = "" local CompoPath = "" local OutTemplate = "" -- ricavo il direttorio sorgente local function CurrCompoDirectory(Path) local PatternSubString= "(.*)Compo.*" CompoDirectory = string.match(Path, PatternSubString) .."Compo\\" return CompoDirectory end -- --costruisce il percorso completo della componente RICEVE IL NOME DEL TEMPLATE E IL PERCORSO DEL DIRETTORIO DELLE COMPONENTI local function CompletetPath() --local sDir, sName, sExt = EgtSplitPath( CurrCompoPath .. "\\" .. CurrTemplate) --local sCompletePath = sDir ..'\\' .. sName ..'.lua' local sCompletePath = CompoDirectory .. "\\" .. TemplateDirectory CurrCompoDirectory(sCompletePath) -->C:/EgtData/Doors/EgtCompoBase/Compo/ return sCompletePath end -- --legge i direttori della tabella controlla cosa deve essere associato local function CompareDirectory(TemplateTable) if string.match(TemplateTable,"*")=="*" then TemplateTable=string.gsub(TemplateTable,"*","(.*)") end TemplateTable = string.match(CompoPath, TemplateTable) -- la stringa della tabella e quella passata non hanno nulla in comune allora ritorno falso if TemplateTable == nil then return false else return true end end -- --restituisce il nome del file da associare local function ComputeDirectory(Dir) -- controllo se ha "*" if string.match(Dir,"*")=="*" then -- allora riscrivo la stringa i modo da poter copiare l'argomento al posto dell'asterisco Dir=string.gsub(Dir,"*","(.*)") end -- se il nome passato coincide completamente con quello scritto in tabella allora non devo ricalcolare il percorso if CompoDirectory==Dir then return "" else -- recupero dal template il nome completo del file da associare alla cartella dei frame Dir = string.match(CompoPath, Dir) --> C:/EgtData/Doors/EgtCompoBase/Compo/Hinges/SOSS/216 - Hinges/SOSS/(.*) return Dir --> 216 end end -- -- legge nel file .lua la dischiarazione di associazione local function ReadDefaultParam(File) ReadingFile = File..".lua" local f = io.open(ReadingFile,"r") local t = f:read("*l") i=0 while t~=nil do i =1+i if string.match(t,"%s*--%s*%[Graphic parameters%]")==t then t = f:read("*l") t = string.match(t,"%s*--%s*Default%s*=%s*(.*)") return t end t = f:read("*l") end f:close() return "1" end -- -- ricerca all'interno del file lua chiamante se esiste un'associazione local function FileNameInLua( sFile) local f = io.open( sFile,"r") if not f then return end local t = f:read("*l") local i = 0 while t~=nil do i = 1 + i if string.match( t, "%s*--%s*%[Match%]")==t then t = f:read( "*l") t = string.match( t, "%s*--%s*FileName%s*=%s*(.*)") f:close() return t end t = f:read("*l") end f:close() end -- -- controlla che il file passato esista local function FileExist( NameFile) return EgtExistsFile( NameFile) end -- -------------------------------------------------------------------------------------------------------------------------------------- --legge la tabella e ricostruisce le associazioni restituendo il file associato function DOORMatch.Matching(sSourceDirectory ,sTemplateDirectory ,tMatchTable) print("\n DOORMatch") print(" ", sTemplateDirectory) -- caricamento delle variabili CompoDirectory = sSourceDirectory --< C:/EgtData/Doors/EgtCompoBase/Compo/Hinges TemplateDirectory = sTemplateDirectory --< SOSS/216 MatchTable = tMatchTable local OutDirectory = "" local FIleNameTemlpate = "" -- costruisco il percorso compoleto CompoPath = CompletetPath() -->C:/EgtData/Doors/EgtCompoBase/Compo/Hinges/SOSS/216 -- ricerco all'inetrno del file se esiste un'associazione diretta local AppOutTemplate = FileNameInLua( CompoPath) if AppOutTemplate then -- print("\n [Match] FileName = ", AppOutTemplate, "\n") local sDir, sName, sExt = EgtSplitPath( AppOutTemplate) return sDir ..sName end -- se la ricerca fallisce inizio la ricerca all'interno della tabella delle associazioni for i=1, #MatchTable do if CompareDirectory(MatchTable[i].InTemplate) then -- print("\n",CompoPath, "--> row",i," ", MatchTable[i].InTemplate) -- carico il valore associato nella tabella in uscita AppOutTemplate = MatchTable[i].OutTemplate -- controllo se ha estensione "*" if string.match( AppOutTemplate,"*") == "*" then --> Hinges/SOSS.Frame/* AppOutTemplate = string.gsub(AppOutTemplate,"*","") --> Hinges/SOSS.Frame/ OutDirectory = CompoDirectory .. AppOutTemplate --> C:/EgtData/Doors/EgtCompoBase/Compo/Hinges/SOSS.Frame/ FIleNameTemlpate = ComputeDirectory(MatchTable[i].InTemplate) --> 216 OutDirectory = OutDirectory .. FIleNameTemlpate --> C:/EgtData/Doors/EgtCompoBase/Compo/Hinges/SOSS.Frame/216 if FileExist( OutDirectory .. ".lua") then --> C:/EgtData/Doors/EgtCompoBase/Compo/Hinges/SOSS.Frame/216.lua DOORMatch.OutTemplate = OutDirectory print("\n", AppOutTemplate .. FIleNameTemlpate) --> Hinges/SOSS.Frame/216 return AppOutTemplate .. FIleNameTemlpate else -- print("\n" ,OutDirectory ," doesn't exist") AppOutTemplate = nil FIleNameTemlpate = "" OutDirectory = "" end else --> Hinges/SOSS.Frame/212 -- il template in uscita è direttamente un file OutDirectory = CompoDirectory .. AppOutTemplate --> C:/EgtData/Doors/EgtCompoBase/Compo/Hinges/SOSS.Frame/212 if FileExist( OutDirectory .. ".lua") then --> C:/EgtData/Doors/EgtCompoBase/Compo/Hinges/SOSS.Frame/212.lua DOORMatch.OutTemplate = OutDirectory --STU.OutTemplate = AppOutTemplate print(" ",AppOutTemplate) return AppOutTemplate else print("\n", OutDirectory ," doesn't exist") AppOutTemplate = nil OutDirectory = "" end end end end -- terminato il ciclo for if AppOutTemplate == nil then print("\n no match found") end end function DOORMatch.ReadDefaultParam() sFile = DOORMatch.OutTemplate ..".lua" local f = io.open( sFile, "r") local t = f:read("*l") local i = 0 while t~=nil do i =1+i if string.match(t,"%s*--%s*%[Graphic parameters%]")==t then t = f:read("*l") t = string.match(t,"%s*--%s*Default%s*=%s*(.*)") f:close() print("Configuration Hardware: ",t) return t end t = f:read("*l") end f:close() return "1" end -- return DOORMatch