d76c2e37e6
- introdotta funzione EgtSanitizeUtf8 da LuaLibs - aggiunta modalita' Balance su chiamata REST per Beam - aggiunta funzione CreateBWEFromMachGroup - aggiunta funzione per nesting travi - aggiunto calcolo lista soglie per finestre - copiato file WindowRESTPipe da BeamRESTPipe
289 lines
11 KiB
Lua
289 lines
11 KiB
Lua
--
|
|
-- 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
|
|
--
|
|
-- BeamPipe by Egalware s.r.l. 2023/05/09
|
|
-- Questo script gestisce le richieste Redis che arrivano da LUX per le travi
|
|
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( false)
|
|
|
|
-- modalita' di chiamata
|
|
QUESTION_MODES = {
|
|
NULL = 0,
|
|
PREVIEW = 1,
|
|
BOM = 2,
|
|
HARDWARE = 3,
|
|
CONFIG = 4,
|
|
ORDER = 5,
|
|
VERIFY = 6,
|
|
}
|
|
|
|
QUESTION_ORDER_SUBMODES = {
|
|
NULL = 0,
|
|
CREATE = 1,
|
|
ESTIMATE = 2,
|
|
CONFIRM = 3,
|
|
}
|
|
|
|
_G.package.loaded.JSON = nil
|
|
local JSON = require( 'JSON')
|
|
|
|
local sIniFilePath = EgtGetIniFile()
|
|
|
|
local sScriptDir = EgtGetStringFromIni( 'Lux', 'ScriptDir', '', sIniFilePath)
|
|
EgtAddToPackagePath( sScriptDir .. '\\?.lua')
|
|
_G.package.loaded.BeamWallPipeLib = nil
|
|
local BeamWallPipeLib = require( 'BeamWallPipeLib')
|
|
|
|
local sBaseDir = EgtGetStringFromIni( 'Beam', 'BaseDir', '', sIniFilePath)
|
|
EgtAddToPackagePath( sBaseDir .. '\\?.lua')
|
|
|
|
local function Calc_Preview( QuestionArgs)
|
|
-- leggo argomenti passati
|
|
local sFile = QuestionArgs["FileName"]
|
|
local sBtl = QuestionArgs["SerializedData"]
|
|
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
|
|
EgtBeamCalcAllSolids( true)
|
|
EgtBeamShowBuilding( true)
|
|
-- salvo immagine
|
|
local sPngFilePath = EgtGetTempDir() .. '\\' .. sFileName .. '_' .. os.time() .. '.png'
|
|
local nDriver = EgtGetNumberFromIni( 'OpenGL','Driver', 3, EgtGetIniFile())
|
|
local b2Buff = ( EgtGetNumberFromIni( 'OpenGL','DoubleBuffer', 1, EgtGetIniFile()) ~= 0)
|
|
local nColorBits = EgtGetNumberFromIni( 'OpenGL','ColorBits', 32, EgtGetIniFile())
|
|
local nDepthBits = EgtGetNumberFromIni( 'OpenGL','DepthBits', 24, EgtGetIniFile())
|
|
|
|
local dWidth = 1500
|
|
if QuestionArgs["Width"] then
|
|
dWidth = tonumber( QuestionArgs["Width"])
|
|
end
|
|
local dHeight = 1500
|
|
if QuestionArgs["Height"] then
|
|
dHeight = tonumber( QuestionArgs["Height"])
|
|
end
|
|
|
|
bOk = EgtGetImageEx( nDriver, b2Buff, nColorBits, nDepthBits, SCE_SM.SH, WHITE(), WHITE(), SCE_VD.ISO_SW, dWidth, dHeight, sPngFilePath)
|
|
|
|
os.remove(sBtlFilePath)
|
|
-- do risultato
|
|
local Base64Png = EgtBase64Encode( sPngFilePath)
|
|
os.remove(sPngFilePath)
|
|
return 1, { Png = Base64Png}
|
|
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["SerializedData"]
|
|
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")
|
|
local nCnt = EgtGetInfo( nPartId, "CNT", 'i')
|
|
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)
|
|
Section.Volume = Section.Volume + ( dW * dH * dL * nCnt)
|
|
else
|
|
table.insert( SectionList, { W = dW, H = dH, Material = sMaterial, Qty = nCnt, TotLen = ( dL * nCnt), Volume = (dW * dH * 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 = '',
|
|
Volume = Section.Volume / 1000000000,
|
|
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 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 sSanitizedReadLine = EgtSanitizeUtf8( sReadLine)
|
|
local Question = JSON:decode( sSanitizedReadLine)
|
|
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 sRUID = QuestionArgs["RUID"]
|
|
local nMode = tonumber( QuestionArgs["Mode"])
|
|
-- esecuzione della corretta modilita'
|
|
EgtOutLog('Ricevuta richiesta calcolo: nThreadIndex=' .. nThreadIndex .. ', nId=' .. nId .. ', UID=' .. sUid .. ', nMode=' .. nMode)
|
|
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
|
|
AnswerArgs.RUID = sRUID or 0
|
|
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
|