-- -- EEEEEEEEEE GGGGGG TTTTTTTTTTTTTT -- EEEEEEEEEE GGGGGGGGGG TTTTTTTTTTTTTT -- EEEE GGGG GGGG TTTT -- EEEE GGGG TTTT -- EEEEEEE GGGG GGGGGGG TTTT -- EEEEEEE GGGG GGGGGGG TTTT -- EEEE GGGG GGGG TTTT -- EEEE GGGG GGGG TTTT -- EEEEEEEEEE GGGGGGGGGG TTTT -- EEEEEEEEEE GGGGGG TTTT -- -- by Egalware s.r.l. -- Door manager by Egalware s.r.l. 2023/05/09 require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- modalita' di chiamata QUESTION_MODES = { NULL = 0, PREVIEW = 1, BOM = 2, } _G.package.loaded.JSON = nil local JSON = require( 'JSON') local sIniFilePath = EgtGetIniFile() local sBaseDir = EgtGetStringFromIni( 'Aedifica', 'BaseDir', '', sIniFilePath) EgtAddToPackagePath( sBaseDir .. '\\?.lua') --_G.package.loaded.WinProject = nil --local WinProject = require( 'WinProject') local function Calc_Preview( QuestionArgs) -- leggo argomenti passati local sFile = QuestionArgs["FileName"] local sBtl = QuestionArgs["Btl"] if sFile and #sFile > 0 then if sBtl and #sBtl > 0 then _, sFileName, sExt = EgtSplitPath( sFile) -- scrivo testo su file local sBtlFilePath = EgtGetTempDir() .. '\\' .. sFileName .. '_' .. os.time() .. sExt -- Apro file Input in scrittura local fhBtl = io.open( sBtlFilePath, 'w') if not fhBtl then EgtOutLog( 'Error opening file ' .. sBtlFilePath) return false end -- Scrittura nuova linea fhBtl:write( sBtl .. '\n') -- Chiudo file fhBtl:close() -- verifico tipo di file local bOk = false if string.lower( sExt) == '.btl' then bOk = EgtImportBtl( sBtlFilePath) elseif string.lower( sExt) == '.btlx' then bOk = EgtImportBtlx( sBtlFilePath) else local sErrorMsg = 'Errore! Estensione file non riconosciuta!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end if not bOk then local sErrorMsg = 'Errore! Importazione file non riuscita!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end -- assemblo --EgtBeamShowBuilding( true) -- creo file svg -- sistemo la vista --EgtSetView( SCE_VD.ISO_SW, false) EgtZoom( SCE_ZM.ALL, true) -- salvo immagine local sSvgFilePath = EgtGetTempDir() .. '\\' .. sFileName .. '_' .. os.time() .. '.svg' EgtExportSvg( GDB_ID.ROOT, sSvgFilePath) -- leggo il file svg local SouFh = io.open( sSvgFilePath, "rb") local content if SouFh then content = SouFh:read( "*all") SouFh:close() end os.remove(sBtlFilePath) os.remove(sSvgFilePath) -- do risultato return 1, { Svg = content} else local sErrorMsg = 'Errore! Btl file vuoto!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end else local sErrorMsg = 'Errore! Nome file vuoto!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end end local function Calc_BOM( QuestionArgs) -- leggo argomenti passati local sFile = QuestionArgs["FileName"] local sBtl = QuestionArgs["Btl"] if sFile and #sFile > 0 then if sBtl and #sBtl > 0 then _, sFileName, sExt = EgtSplitPath( sFile) -- scrivo testo su file local sBtlFilePath = EgtGetTempDir() .. '\\' .. sFileName .. '_' .. os.time() .. sExt -- Apro file Input in scrittura local fhBtl = io.open( sBtlFilePath, 'w') if not fhBtl then EgtOutLog( 'Error opening file ' .. sBtlFilePath) return false end -- Scrittura nuova linea fhBtl:write( sBtl .. '\n') -- Chiudo file fhBtl:close() -- verifico tipo di file local bOk = false if string.lower( sExt) == '.btl' then bOk = EgtImportBtl( sBtlFilePath) elseif string.lower( sExt) == '.btlx' then bOk = EgtImportBtlx( sBtlFilePath) else local sErrorMsg = 'Errore! Estensione file non riconosciuta!' EgtOutLog(sErrorMsg) os.remove(sBtlFilePath) return 0, { Error = sErrorMsg} end os.remove(sBtlFilePath) if not bOk then local sErrorMsg = 'Errore! Importazione file non riuscita!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end -- calcolo quantita' pezzi, volume, barre lineari local PartList = {} local SectionList = {} local TotVol = 0 local nPartId = EgtGetFirstPart() while nPartId do local dW = EgtGetInfo( nPartId, "W", 'd') local dH = EgtGetInfo( nPartId, "H", 'd') local dL = EgtGetInfo( nPartId, "L", 'd') local sMaterial = EgtGetInfo( nPartId, "MATERIAL", 'd') local nCnt = EgtGetInfo( nPartId, "CNT", 'd') table.insert( PartList, { W = dW, H = dH, L = dL , Material = sMaterial}) local Section = nil for nSectionIndex = 1, #SectionList do if SectionList[nSectionIndex].W == dW and SectionList[nSectionIndex].H == dH and SectionList[nSectionIndex].Material == sMaterial then Section = SectionList[nSectionIndex] end end if Section then Section.Qty = Section.Qty + nCnt Section.TotLen = Section.TotLen + ( dL * nCnt) else table.insert( SectionList, { W = dW, H = dH, Material = sMaterial, Qty = nCnt, TotLen = ( dL * nCnt)}) end TotVol = TotVol + ((( dW / 1000) * ( dH / 1000) * ( dL / 1000)) * nCnt) nPartId = EgtGetNextPart( nPartId) end local BOM = {} for nSectionIndex = 1, #SectionList do local Section = SectionList[nSectionIndex] table.insert( BOM, { ClassCode = 'BeamTrunk', ItemCode = 'Pine-' .. Section.W .. 'x' .. Section.H, ItemQty = Section.Qty, DescriptionCode = '', Qty = Section.TotLen / 1000}) end -- do risultato local JsonBOM = JSON:encode( BOM) return 1, { BOM = JsonBOM} else local sErrorMsg = 'Errore! Btl file vuoto!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end else local sErrorMsg = 'Errore! Nome file vuoto!' EgtOutLog(sErrorMsg) return 0, { Error = sErrorMsg} end end local nErr = 999 local nNilCount = 0 local bRun = true while bRun do local sReadLine = io.stdin:read( 'l') EgtOutLog( 'Letta riga da stdin') if sReadLine then if sReadLine == 'quit' then EgtOutLog( 'Chiusura processo') break end if sReadLine ~= '' and sReadLine:find( '^#8477271#') and sReadLine:find( '#8477271#$') then EgtOutLog( 'Lettura istruzione valida') sReadLine = string.sub( sReadLine, 10, #sReadLine - 9) local Question = JSON:decode( sReadLine) local nThreadIndex = -1 local nId = -1 local ExecEnvironment = -1 local nResult = 0 local AnswerArgs = {} if Question and Question.nThreadIndex and Question.nId and Question.Args then nThreadIndex = tonumber( Question["nThreadIndex"]) nId = tonumber( Question["nId"]) ExecEnvironment = tonumber( Question["ExecEnvironment"]) local QuestionArgs = Question["Args"] if QuestionArgs and QuestionArgs.Mode and QuestionArgs.UID then local sUid = QuestionArgs["UID"] local nMode = tonumber( QuestionArgs["Mode"]) -- esecuzione della corretta modilita' EgtOutLog('Esecuzione calcolo') local Result = {} if nMode == QUESTION_MODES.PREVIEW then nResult, AnswerArgs = Calc_Preview( QuestionArgs) elseif nMode == QUESTION_MODES.BOM then nResult, AnswerArgs = Calc_BOM( QuestionArgs) end AnswerArgs.UID = sUid else nResult = 0 local sErrorMsg = 'Errore! Domanda senza argomenti o senza UID o Mode che sono obbligatori!' AnswerArgs = { Error = sErrorMsg} EgtOutLog( sErrorMsg) end else nResult = 0 local sErrorMsg = 'Errore! Formato domanda non riconosciuto o senza nThreadIndex, nId o Args!' AnswerArgs = { Error = sErrorMsg} EgtOutLog( sErrorMsg) end -- do risultato local Result = { nThreadIndex = nThreadIndex, nId = nId, ExecEnvironment = ExecEnvironment, nResult = nResult, Args = AnswerArgs} -- invio risposta EgtOutLog( 'Invio risposta') local JsonResult = JSON:encode( Result) io.stdout:write( "#8376261#" .. JsonResult .. "#8376261#" .. '\n') io.stdout:flush() EgtOutLog( 'Risposta inviata') EgtNewFile() end else if nNilCount >= 20 then bRun = false EgtOutLog( 'Errore! Lettura da stdin fallita!') end nNilCount = nNilCount + 1 EgtPause( 100, true) end end