Files
egwmultienginescript/WindowPipe.lua
T
Emmanuele Sassi a1700f635c - commentato onlyoption in Agb
- aggiunte linee di debug per processi
- aggiunta modalita' hardware, config, order, verify
- migliorato png delle travi
- aggiunto volume in BOM
- aggiunto sanitizeUtf8
- spostata connessione Redis a inizio file
- gestite chiamate REST per beam
- gestita verifica non parallela per travi
- aggiunte opzioni hardware finestre
- aggiunta calcolo forma anta finestra
2025-12-09 18:11:46 +01:00

527 lines
19 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
--
-- 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,
HARDWARE = 3,
CONFIG = 4,
ORDER = 5,
}
QUESTION_CONFIG_SUBMODES = {
NULL = 0,
PROFILELIST = 1,
}
QUESTION_HARDWARE_SUBMODES = {
NULL = 0,
LIST = 1,
CALCHARDWARE = 2,
HARDWAREOPTION = 3,
SASHSHAPE = 4,
}
-- produttore
MANUFACTURERS = {
NULL = 0,
AGB = 1,
MAICO = 2,
ROTO = 3,
}
_G.package.loaded.JSON = nil
local JSON = require( 'JSON')
local sIniFilePath = EgtGetIniFile()
local sBaseDir = EgtGetStringFromIni( 'Window', 'BaseDir', '', sIniFilePath)
EgtAddToPackagePath( sBaseDir .. '\\Designing\\?.lua')
--EgtAddToPackagePath( sBaseDir .. '\\Machining\\?.lua')
_G.package.loaded.WinProject = nil
local WinProject = require( 'WinProject')
-- Connessiona a Redis
local bRedisConnect, nRedisConnectionId = EgtRedisAsyncConnect( ENG.Param2)
if bRedisConnect then
EgtOutLog('Connessione con il server Redis dal Lua effettuata con successo con Id=' .. nRedisConnectionId .. '!')
else
nRedisConnectionId = 0
EgtOutLog('Errore! Impossibile connettersi con il server Redis dal Lua!')
end
local function Calc_Preview( QuestionArgs)
-- leggo argomenti passati
local sJwd = QuestionArgs["SerializedData"]
if sJwd and #sJwd > 0 then
-- imposto cartella profili
local sProfileDir = ''
sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath)
if sProfileDir and #sProfileDir > 0 then
WDG.PROFILEPATH = sProfileDir
SetProfilePath()
else
local sErrorMsg = 'Errore! Cartella dei profili non trovata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
-- carico jwd
WDG.JWD = sJwd
WinManage_LoadJwd()
local AreaId = WDG.AREAID
-- imposto opzioni visualizzazione
WDG.VALUE = false
_G.WinCalculate_SetCalcSolid()
WDG.VALUE = false
WinCalculate_SetSimplifiedSolid()
WDG.VALUE = true
WinCalculate_SetCalcPreview()
-- creazione pezzi
WDG.FRAMEID = AreaId
WinCalculate_CreatePartFromArea()
-- calcolo hardware
--WDG.FRAMEID = AreaId
--WDG.CALC_HARDWARELIST=false
--WDG.CALC_POSITIONLIST=false
--WDG.CALC_MACHININGLIST=false
--WDG.CALC_OPTIONLIST=false
--WinCalculate_AddHardware()
-- creo file svg
WDG.GROUPID = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_PREVIEW)
WDG.FILE = 'C:\\Temp\\TestSvgManager.svg'
WinGetSvg()
-- leggo il file
local SouFh = io.open( WDG.FILE, "rb")
local content
if SouFh then
content = SouFh:read( "*all")
--EgtOutBox( 'Error opening ' .. sFilePath, 'ReadFromFile', 'ERROR')
SouFh:close()
--return false
end
-- do risultato
return 1, { Svg = content}
else
local sErrorMsg = 'Errore! Jwd non trovato!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
local function Calc_BOM( QuestionArgs)
-- leggo argomenti passati
local sJwd = QuestionArgs["SerializedData"]
if sJwd and #sJwd > 0 then
-- imposto cartella profili
local sProfileDir = ''
sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath)
if sProfileDir and #sProfileDir > 0 then
WDG.PROFILEPATH = sProfileDir
SetProfilePath()
else
local sErrorMsg = 'Errore! Cartella dei profili non trovata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
-- carico jwd
WDG.JWD = sJwd
WinManage_LoadJwd()
local AreaId = WDG.AREAID
-- imposto opzioni visualizzazione
WDG.VALUE = false
_G.WinCalculate_SetCalcSolid()
WDG.VALUE = false
WinCalculate_SetSimplifiedSolid()
WDG.VALUE = false
WinCalculate_SetCalcPreview()
-- creazione pezzi
WDG.FRAMEID = AreaId
WinCalculate_CreatePartFromArea()
-- calcolo hardware
WDG.FRAMEID = AreaId
WDG.CALC_MACHINING=false
WDG.CALC_HARDWARELIST=true
WDG.CALC_POSITIONLIST=false
WDG.CALC_OPTIONLIST=false
WinCalculate_AddHardware()
---- creo file svg
--WDG.GROUPID = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_PREVIEW)
--WDG.FILE = 'C:\\Temp\\TestSvgManager.svg'
--WinGetSvg()
---- leggo il file
--local SouFh = io.open( WDG.FILE, "rb")
--local content
--if SouFh then
-- content = SouFh:read( "*all")
-- --EgtOutBox( 'Error opening ' .. sFilePath, 'ReadFromFile', 'ERROR')
-- SouFh:close()
-- --return false
--end
WinGetSectionsTotalLenghts()
WinGetGlassesList()
-- do risultato
local BOM = {}
for Index = 1, #WDG.SECTIONS_LENGTHS do
table.insert( BOM, { ClassCode = 'WindowTrunk',
ItemCode = 'Pine-' .. WDG.SECTIONS_LENGTHS[Index].W .. 'x' .. WDG.SECTIONS_LENGTHS[Index].H,
ItemQty = #WDG.SECTIONS_LENGTHS[Index].L,
DescriptionCode = '',
Qty = WDG.SECTIONS_LENGTHS[Index].TotL / 1000})
end
for Index = 1, #WDG.GLASSES_LIST do
table.insert( BOM, { ClassCode = 'WindowGlass',
ItemCode = '6/14argon/6-' .. EgtIf( WDG.GLASSES_LIST[Index].Rect, 'Rect-', 'Special-') .. WDG.GLASSES_LIST[Index].T,
ItemQty = 1,
DescriptionCode = WDG.GLASSES_LIST[Index].W .. 'x' .. WDG.GLASSES_LIST[Index].L,
Qty = WDG.GLASSES_LIST[Index].W * WDG.GLASSES_LIST[Index].L / 1000000})
end
if WDG.HARDWAREKIT_LIST then
for SashIndex = 1, #WDG.HARDWAREKIT_LIST do
for HardwareIndex = 1, #WDG.HARDWAREKIT_LIST[SashIndex] do
local Hardware = WDG.HARDWAREKIT_LIST[SashIndex][HardwareIndex]
table.insert( BOM, { ClassCode = 'WindowHardware',
ItemCode = '' .. Hardware['ArtCode'] .. '-' .. Hardware['Description'],
ItemQty = 1,
DescriptionCode = '',
Price = Hardware['Price'],
Qty = Hardware['Qty']})
end
end
end
local JsonBOM = JSON:encode( BOM)
return 1, { BOM = JsonBOM}
else
local sErrorMsg = 'Errore! Jwd non trovato!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
local function Calc_HardwareList( QuestionArgs, sReadLine)
local nManufacturer = tonumber( QuestionArgs["Manufacturer"])
if nManufacturer == MANUFACTURERS.AGB then
-- Canali
local QuestionChannel = "EgwHardwareQuestion"
local AnswerChannel = "EgwHardwareAnswer" .. os.time()
local Question = JSON:decode( sReadLine)
Question['Args'].OutputChannel = AnswerChannel
local JsonQuestion = JSON:encode( Question)
local bOk = EgtRedisAsyncPublish( nRedisConnectionId, QuestionChannel, JsonQuestion)
local AnswerArgs
if bOk then
EgtOutLog('Messaggio Redis pubblicato:' .. QuestionChannel .. ' ' .. JsonQuestion)
local bOk, Answer = EgtRedisAsyncSubscribeOneMessage( nRedisConnectionId, AnswerChannel, 10000)
if bOk then
EgtOutLog('Risposta Redis ricevuta:' .. Answer)
local JsonAnswer = JSON:decode( Answer)
AnswerArgs = JsonAnswer['Args']
AnswerArgs.OutputChannel = nil
else
local sErrorMsg = 'Errore! Risposta dal canale calcolo hardware Agb non arrivata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
else
local sErrorMsg = 'Errore! Pubblicazione sul canale calcolo hardware Agb fallita!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
return 1, AnswerArgs
end
end
local function Calc_HardwareOptions( QuestionArgs)
-- leggo argomenti passati
local sJwd = QuestionArgs["SerializedData"]
local JsonGroupId = QuestionArgs["GroupId"]
if sJwd and JsonGroupId and #sJwd > 0 and #JsonGroupId > 0 then
-- imposto cartella profili
local sProfileDir = ''
sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath)
if sProfileDir and #sProfileDir > 0 then
WDG.PROFILEPATH = sProfileDir
SetProfilePath()
else
local sErrorMsg = 'Errore! Cartella dei profili non trovata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
local GroupId = JSON:decode( JsonGroupId)
-- carico jwd
WDG.JWD = sJwd
WinManage_LoadJwd()
local AreaId = WDG.AREAID
-- imposto opzioni visualizzazione
WDG.VALUE = false
_G.WinCalculate_SetCalcSolid()
WDG.VALUE = false
WinCalculate_SetSimplifiedSolid()
WDG.VALUE = false
WinCalculate_SetCalcPreview()
-- creazione pezzi
WDG.FRAMEID = AreaId
WinCalculate_CreatePartFromArea()
-- calcolo hardware
for i = 1, #GroupId do
WDG['AREANBR' .. tostring(i)] = GroupId[i]
end
WDG.FRAMEID = AreaId
WDG.CALC_MACHINING=false
WDG.CALC_HARDWARELIST=false
WDG.CALC_POSITIONLIST=false
WDG.CALC_OPTIONLIST=true
WinCalculate_AddHardwareByGroupId()
local nCalcHardwareOption = 0
local AnswerGroupId = {}
for i = 1, #GroupId do
local HardwareOptionList = WDG['HARDWAREOPTION_LIST' .. tostring(i)]
if HardwareOptionList then
nCalcHardwareOption = nCalcHardwareOption + 1
AnswerGroupId[ tostring( GroupId[i])] = HardwareOptionList[1]
else
AnswerGroupId[ tostring( GroupId[i])] = ''
end
end
if nCalcHardwareOption == #GroupId then
local JsonAnswerGroupId = JSON:encode( AnswerGroupId)
return 1, { HardwareOptions = JsonAnswerGroupId, GroupId = JsonGroupId}
elseif nCalcHardwareOption == 0 then
return 0, { Error = "Errore! Lista opzioni hardware non trovata!", GroupId = JsonGroupId}
end
--if WDG.HARDWAREOPTION_LIST and #WDG.HARDWAREOPTION_LIST > 0 then
-- return 1, { HardwareOptions = WDG.HARDWAREOPTION_LIST[1]}
--else
-- return 0, { Error = "Errore! Opzioni hardware non trovate!"}
--end
else
local sErrorMsg = 'Errore! Jwd non trovato!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
local function Calc_SashShape( QuestionArgs)
-- leggo argomenti passati
local sJwd = QuestionArgs["SerializedData"]
local JsonGroupId = QuestionArgs["GroupId"]
if sJwd and JsonGroupId and #sJwd > 0 and #JsonGroupId > 0 then
-- imposto cartella profili
local sProfileDir = ''
sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath)
if sProfileDir and #sProfileDir > 0 then
WDG.PROFILEPATH = sProfileDir
SetProfilePath()
else
local sErrorMsg = 'Errore! Cartella dei profili non trovata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
local GroupId = JSON:decode( JsonGroupId)
-- carico jwd
WDG.JWD = sJwd
WinManage_LoadJwd()
local AreaId = WDG.AREAID
-- imposto opzioni visualizzazione
WDG.VALUE = false
_G.WinCalculate_SetCalcSolid()
WDG.VALUE = false
WinCalculate_SetSimplifiedSolid()
WDG.VALUE = false
WinCalculate_SetCalcPreview()
-- creazione pezzi
--WDG.FRAMEID = AreaId
--WinCalculate_CreatePartFromArea()
for i = 1, #GroupId do
WDG['AREANBR' .. tostring(i)] = GroupId[i]
end
WinGetSashShape()
local nCalcShape = 0
local AnswerGroupId = {}
for i = 1, #GroupId do
local SashShape = WDG['SASHSHAPE' .. tostring(i)]
if SashShape then
nCalcShape = nCalcShape + 1
AnswerGroupId[ tostring( GroupId[i])] = SashShape
else
AnswerGroupId[ tostring( GroupId[i])] = ''
end
end
if nCalcShape == #GroupId then
local JsonAnswerGroupId = JSON:encode( AnswerGroupId)
return 1, { SashShape = JsonAnswerGroupId, GroupId = JsonGroupId}
else
return 0, { Error = "Errore! Forma serramento non trovata!", GroupId = JsonGroupId}
end
else
local sErrorMsg = 'Errore! Jwd o GroupId non trovato!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg, GroupId = JsonGroupId}
end
end
local function Calc_ProfileList()
-- leggo cartella profili
local sProfileDir = ''
sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath)
if sProfileDir and #sProfileDir > 0 then
local Profiles = EgtFindAllFiles( sProfileDir .. '\\*.nge')
for i = 1, #Profiles do
_, Profiles[i], _ = EgtSplitPath( Profiles[i])
end
local ProfilesBOM = JSON:encode( Profiles)
return 1, { ProfileList = ProfilesBOM}
else
local sErrorMsg = 'Errore! Cartella dei profili non trovata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
local nErr = 999
local nNilCount = 0
local bRun = true
local size = 2^13 -- good buffer size (8K)
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"])
_G.WDG = {}
WDG.REDISID = nRedisConnectionId
-- esecuzione della corretta modalita'
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)
elseif nMode == QUESTION_MODES.HARDWARE then
if QuestionArgs.SubMode then
local nSubMode = tonumber( QuestionArgs["SubMode"])
EgtOutLog('SubMode=' .. nSubMode)
if nSubMode == QUESTION_HARDWARE_SUBMODES.LIST then
nResult, AnswerArgs = Calc_HardwareList( QuestionArgs, sReadLine)
elseif nSubMode == QUESTION_HARDWARE_SUBMODES.HARDWAREOPTION then
nResult, AnswerArgs = Calc_HardwareOptions( QuestionArgs)
elseif nSubMode == QUESTION_HARDWARE_SUBMODES.SASHSHAPE then
nResult, AnswerArgs = Calc_SashShape( QuestionArgs)
else
nResult = 0
local sErrorMsg = 'Errore! Valore di SubMode errato!'
AnswerArgs = { Error = sErrorMsg}
EgtOutLog( sErrorMsg)
end
else
nResult = 0
local sErrorMsg = 'Errore! Domanda senza SubMode che é obbligatorio!'
AnswerArgs = { Error = sErrorMsg}
EgtOutLog( sErrorMsg)
end
elseif nMode == QUESTION_MODES.CONFIG then
if QuestionArgs.SubMode then
local nSubMode = tonumber( QuestionArgs["SubMode"])
if nSubMode == QUESTION_CONFIG_SUBMODES.PROFILELIST then
nResult, AnswerArgs = Calc_ProfileList()
else
nResult = 0
local sErrorMsg = 'Errore! Valore di SubMode errato!'
AnswerArgs = { Error = sErrorMsg}
EgtOutLog( sErrorMsg)
end
else
nResult = 0
local sErrorMsg = 'Errore! Domanda senza SubMode che é obbligatorio!'
AnswerArgs = { Error = sErrorMsg}
EgtOutLog( sErrorMsg)
end
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: nThreadIndex=' .. nThreadIndex .. ', nId=' .. nId .. ', nResult=' .. nResult)
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
EgtRedisAsyncDisconnect( nRedisConnectionId)