- 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
This commit is contained in:
Emmanuele Sassi
2025-12-09 18:11:46 +01:00
parent 8e485aac69
commit a1700f635c
6 changed files with 1098 additions and 93 deletions
+21 -24
View File
@@ -15,7 +15,7 @@
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( true)
EgtEnableDebug( false)
-- modalita' di chiamata
QUESTION_MODES = {
@@ -69,9 +69,9 @@ math.randomseed( os.time() + math.floor( os.clock() * 1000000000))
local function AGBHardwareShapeConverter( sShape)
if sShape == 'R' then
return 'Rectangular'
return 'Rectangle'
elseif sShape == 'T' then
return 'Trapezoidal'
return 'Trapezoid'
elseif sShape == 'AS' then
return 'FullArc'
elseif sShape == 'AR' then
@@ -211,7 +211,7 @@ local function Calc_WindowHardware( nManufacturer, QuestionArgs)
end
if HardwareOptionListFlag and not HardwareListFlag and not MachiningListFlag and not HardwarePositionListFlag then
sText = sText .. 'OUTPUTKIT=' .. sAGBOutputKitFile .. '\n'
sText = sText .. 'only_options=on\n'
--sText = sText .. 'only_options=on\n'
end
sText = sText .. sInput
sText = sText .. 'RUN'
@@ -273,6 +273,8 @@ local function Calc_WindowHardware( nManufacturer, QuestionArgs)
end
-- Chiudo file OutputKit in lettura
fhHardwareList:close()
-- elimino file creati
EgtEraseFile( sOutputKitFile)
sHardwareList = JSON:encode( HardwareList)
end
@@ -306,6 +308,8 @@ local function Calc_WindowHardware( nManufacturer, QuestionArgs)
end
-- Chiudo file OutputKit in lettura
fhMachiningList:close()
-- elimino file creati
EgtEraseFile( sOutputMachiningFile)
sMachiningList = JSON:encode( MachiningList)
end
@@ -339,27 +343,17 @@ local function Calc_WindowHardware( nManufacturer, QuestionArgs)
end
-- Chiudo file OutputKit in lettura
fhPositionList:close()
-- elimino file creati
EgtEraseFile( sOutputPositionFile)
sPositionList = JSON:encode( PositionList)
end
--local OutputKit = {}
---- Apro file OutputKit in lettura
--local fhOutputKit = io.open( sOutputKitFile, 'r')
--if not fhOutputKit then
-- EgtOutLog( 'Error opening file ' .. sOutputKitFile)
-- return false
--end
--local nKitLineIndex = 1
--for sLine in fhOutputKit:lines('l') do
-- local KitParams = EgtSplitString( sLine, ';')
-- local DescriptionSplit = EgtSplitString( KitParams[4], '_')
-- OutputKit[nKitLineIndex] = { Id = KitParams[3], FamilyName = DescriptionSplit[1], Description = KitParams[4], OpeningType = KitParams[5], Shape = KitParams[6], SashQty = tonumber(KitParams[7]), SashPosition = tonumber(KitParams[8])}
-- nKitLineIndex = nKitLineIndex + 1
--end
---- Chiudo file OutputKit in lettura
--fhOutputKit:close()
--local JsonOutputKit = JSON:encode( OutputKit)
-- elimino file input creati
EgtEraseFile( sInputFile)
if EgtExistsFile( sInputOptionFile) then
EgtEraseFile( sInputOptionFile)
end
local AnswerArgs = { OptionList = OptionList,
HardwareList = sHardwareList,
MachiningList = sMachiningList,
@@ -403,7 +397,7 @@ while bRun do
local sUid = QuestionArgs["UID"]
local nMode = tonumber( QuestionArgs["Mode"])
-- esecuzione della corretta modalita'
EgtOutLog('Esecuzione calcolo')
EgtOutLog('Ricevuta richiesta calcolo: nThreadIndex=' .. nThreadIndex .. ', nId=' .. nId .. ', UID=' .. sUid .. ', nMode=' .. nMode)
--if nMode == QUESTION_MODES.PREVIEW then
-- nResult, AnswerArgs = Calc_Preview( QuestionArgs)
--elseif nMode == QUESTION_MODES.BOM then
@@ -412,15 +406,18 @@ while bRun do
if QuestionArgs.SubMode and QuestionArgs.Manufacturer then
local nSubMode = tonumber( QuestionArgs["SubMode"])
local nManufacturer = tonumber( QuestionArgs["Manufacturer"])
EgtOutLog('SubMode=' .. nSubMode .. ', Manufacturer=' .. nManufacturer)
if nSubMode == QUESTION_HARDWARE_SUBMODES.LIST then
nResult, AnswerArgs = Calc_HardwareModelList( nManufacturer)
if AnswerArgs then
AnswerArgs.OutputChannel = QuestionArgs["OutputChannel"]
EgtOutLog('OutputChannel=' .. AnswerArgs.OutputChannel)
end
elseif nSubMode == QUESTION_HARDWARE_SUBMODES.CALCHARDWARE then
nResult, AnswerArgs = Calc_WindowHardware( nManufacturer, QuestionArgs)
if AnswerArgs then
AnswerArgs.OutputChannel = QuestionArgs["OutputChannel"]
EgtOutLog('OutputChannel=' .. AnswerArgs.OutputChannel)
end
else
nResult = 0
+51 -33
View File
@@ -10,8 +10,8 @@
-- EEEEEEEEEE GGGGGGGGGG TTTT
-- EEEEEEEEEE GGGGGG TTTT
--
-- by Egalware s.r.l.
-- Door manager by Egalware s.r.l. 2023/05/09
-- 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()
@@ -22,22 +22,36 @@ 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 sBaseDir = EgtGetStringFromIni( 'Aedifica', 'BaseDir', '', sIniFilePath)
EgtAddToPackagePath( sBaseDir .. '\\?.lua')
--_G.package.loaded.WinProject = nil
--local WinProject = require( 'WinProject')
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["Btl"]
local sBtl = QuestionArgs["SerializedData"]
if sFile and #sFile > 0 then
if sBtl and #sBtl > 0 then
_, sFileName, sExt = EgtSplitPath( sFile)
@@ -70,25 +84,31 @@ local function Calc_Preview( QuestionArgs)
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)
EgtBeamCalcAllSolids( true)
EgtBeamShowBuilding( 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()
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)
os.remove(sSvgFilePath)
-- do risultato
return 1, { Svg = content}
local Base64Png = EgtBase64Encode( sPngFilePath)
os.remove(sPngFilePath)
return 1, { Png = Base64Png}
else
local sErrorMsg = 'Errore! Btl file vuoto!'
EgtOutLog(sErrorMsg)
@@ -104,7 +124,7 @@ end
local function Calc_BOM( QuestionArgs)
-- leggo argomenti passati
local sFile = QuestionArgs["FileName"]
local sBtl = QuestionArgs["Btl"]
local sBtl = QuestionArgs["SerializedData"]
if sFile and #sFile > 0 then
if sBtl and #sBtl > 0 then
_, sFileName, sExt = EgtSplitPath( sFile)
@@ -147,8 +167,8 @@ local function Calc_BOM( QuestionArgs)
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')
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
@@ -159,8 +179,9 @@ local function Calc_BOM( QuestionArgs)
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)})
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)
@@ -172,6 +193,7 @@ local function Calc_BOM( QuestionArgs)
ItemCode = 'Pine-' .. Section.W .. 'x' .. Section.H,
ItemQty = Section.Qty,
DescriptionCode = '',
Volume = Section.Volume / 1000000000,
Qty = Section.TotLen / 1000})
end
-- do risultato
@@ -189,11 +211,6 @@ local function Calc_BOM( QuestionArgs)
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')
@@ -205,7 +222,8 @@ while bRun do
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 sSanitizedReadLine = sanitize_utf8(sReadLine)
local Question = JSON:decode( sSanitizedReadLine)
local nThreadIndex = -1
local nId = -1
local ExecEnvironment = -1
@@ -220,7 +238,7 @@ while bRun do
local sUid = QuestionArgs["UID"]
local nMode = tonumber( QuestionArgs["Mode"])
-- esecuzione della corretta modilita'
EgtOutLog('Esecuzione calcolo')
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)
+355
View File
@@ -0,0 +1,355 @@
--
-- 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
--
-- BeamRESTPipe by Egalware s.r.l. 2025/12/02
-- Questo script gestisce le richieste REST 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,
}
PART_VERIFICATION_RESULTS = {
CALCULATIONFAILED = -1,
NOTMACHINABLE = 0,
MACHINABLE = 1,
}
_G.package.loaded.JSON = nil
local JSON = require( 'JSON')
local sIniFilePath = EgtGetIniFile()
local sScriptDir = EgtGetStringFromIni( 'Lux', 'ScriptDir', '', sIniFilePath)
EgtAddToPackagePath( sScriptDir .. '\\?.lua')
local sBaseDir = EgtGetStringFromIni( 'Beam', 'BaseDir', '', sIniFilePath)
EgtAddToPackagePath( sBaseDir .. '\\?.lua')
_G.package.loaded.BeamWallPipeLib = nil
local BeamWallPipeLib = require( 'BeamWallPipeLib')
-- 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 Create_Order( QuestionArgs)
-- leggo argomenti passati
local sFile = QuestionArgs["FileName"]
local sBtl = QuestionArgs["SerializedData"]
local sOrderUID = QuestionArgs["OrderUID"]
local sUID = QuestionArgs["UID"]
local sTagList = QuestionArgs["TagsList"]
if sFile and #sFile > 0 then
if sBtl and #sBtl > 0 then
if sOrderUID and #sOrderUID > 0 then
if sUID and #sUID > 0 then
if sTagList and #sTagList > 0 then
-- scrivo testo su file
local sDataDir = EgtGetStringFromIni( 'Lux', 'DataDir', '', sIniFilePath)
-- creo cartella ordine
local sBtlFilePath = sDataDir .. '\\Beam\\' .. sOrderUID
if not EgtExistsDirectory( sBtlFilePath) then
if not EgtCreateDirectory( sBtlFilePath) then
local sErrorMsg = 'Errore! Impossibile creare cartella ' .. sBtlFilePath .. ' per il progetto ' .. sOrderUID .. '!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
-- creo cartella riga d'ordine
sBtlFilePath = sDataDir .. '\\Beam\\' .. sOrderUID .. '\\' .. sUID
if EgtExistsDirectory( sBtlFilePath) then
if not EgtEmptyDirectory( sBtlFilePath) then
local sErrorMsg = 'Errore! Impossibile svuotare cartella ' .. sBtlFilePath .. ' per il progetto ' .. sOrderUID .. '!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
else
if not EgtCreateDirectory( sBtlFilePath) then
local sErrorMsg = 'Errore! Impossibile creare cartella ' .. sBtlFilePath .. ' per il progetto ' .. sOrderUID .. '!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
_, _, sExt = EgtSplitPath( sFile)
sBtlFilePath = sBtlFilePath .. '\\' .. sUID .. sExt
-- Apro file Input in scrittura
local fhBtl = io.open( sBtlFilePath, 'w')
if not fhBtl then
local sErrorMsg = 'Errore! Apertura file ' .. sBtlFilePath .. ' per scrittura btl non riuscita!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
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
if not bOk then
local sErrorMsg = 'Errore! Importazione file non riuscita!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
-- assegno etichette ai pezzi
local TagList = EgtSplitString( sTagList, ',')
local nPartId = EgtGetFirstPart()
local nTagIndex = 1
while nPartId do
local nCnt = EgtGetInfo( nPartId, "CNT", 'i')
local sPartTagList = ''
for nCntIndex = 1, nCnt do
sPartTagList = sPartTagList .. TagList[nTagIndex] .. EgtIf( nCntIndex < nCnt, ',', '')
nTagIndex = nTagIndex + 1
end
EgtSetInfo( nPartId, 'LuxTagList', sPartTagList)
nPartId = EgtGetNextPart( nPartId)
end
local sNgeFilePath = sDataDir .. '\\Beam\\' .. sOrderUID .. '\\' .. sUID .. '\\' .. sUID .. '.nge'
EgtSaveFile( sNgeFilePath, GDB_NT.CMPTXT)
-- do risultato
return 1, {}
else
local sErrorMsg = 'Errore! Lista etichette vuota!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
else
local sErrorMsg = 'Errore! UID vuoto!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
else
local sErrorMsg = 'Errore! Nome ordine vuoto!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
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_Estimate( QuestionArgs)
-- leggo argomenti passati
local sOrderUID = QuestionArgs["OrderUID"]
local sUID = QuestionArgs["UID"]
if sOrderUID and #sOrderUID > 0 then
if sUID and #sUID > 0 then
-- apro progetto
local sDataDir = EgtGetStringFromIni( 'Lux', 'DataDir', '', sIniFilePath)
local sOrderDirPath = sDataDir .. '\\Beam\\' .. sOrderUID .. '\\' .. sUID
if not EgtExistsDirectory( sOrderDirPath) then
local sErrorMsg = 'Errore! Cartella della riga d\'ordine non trovata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
local sNgeFilePath = sOrderDirPath .. '\\' .. sUID .. '.nge'
if not EgtOpenFile( sNgeFilePath) then
local sErrorMsg = 'Errore! Fallita apertura del file!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
-- recupero cartella macchine
local MachineDirPath = EgtGetStringFromIni( 'Mach', 'MachinesDir', '', sIniFilePath)
if not MachineDirPath or #MachineDirPath <=0 then
local sErrorMsg = 'Errore! Cartella delle macchine non impostata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
--local MachinesDir = EgtFindAllFiles( MachineDirPath .. '\\*.*')
local MachinesDir = { MachineDirPath .. '\\Saomad-KAIROS', MachineDirPath .. '\\Essetre-PF1250' }
local BeamMachineList = {}
for nMachineIndex = 1, #MachinesDir do
local _, sMachineName, _ = EgtSplitPath( MachinesDir[nMachineIndex])
local sMaterial = EgtGetStringFromIni( 'General', 'Material', '', MachineDirPath .. '\\' .. sMachineName .. '\\' .. sMachineName .. '.ini')
if sMaterial == 'Beam' then
local CurrMachine = { Name = sMachineName, PartList = { }}
-- creo i singoli bwe e li mando da eseguire via redis
--BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState)
local nPartId = EgtGetFirstPart()
local AnswerArgs = {}
local TagTimeList = {}
local dTotTime = 0
local nNotMachinedPart = 0
while nPartId do
local BarPath = sOrderDirPath
local ProjType = BWTYPES.BEAM
local GlobState = CALCSTATES.NOTCALCULATED
local nResult, PartAnswerArgs = BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState)
local sTagList = EgtGetInfo( nPartId, 'LuxTagList')
local TagList = EgtSplitString( sTagList, ',')
local CalcResult
if nResult == 1 then
CalcResult = EgtIf( tonumber( PartAnswerArgs.MachiningOk) == 1, PART_VERIFICATION_RESULTS.MACHINABLE, PART_VERIFICATION_RESULTS.NOTMACHINABLE)
else
CalcResult = PART_VERIFICATION_RESULTS.CALCULATIONFAILED
local sErrorMsg = 'Errore! Verifica sul pezzo ' .. nPartId .. ' fallita!'
EgtOutLog(sErrorMsg)
end
for nTagIndex = 1, #TagList do
table.insert( CurrMachine.PartList, { Tag = TagList[nTagIndex], CalcResult = CalcResult, Time = ( PartAnswerArgs.Time or 0)})
end
nPartId = EgtGetNextPart( nPartId)
end
table.insert( BeamMachineList, CurrMachine)
end
end
-- do risultato
local JsonBeamMachineList = JSON:encode( BeamMachineList)
return 1, { Estimate = JsonBeamMachineList}
else
local sErrorMsg = 'Errore! UID vuoto!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
else
local sErrorMsg = 'Errore! OrderUID 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 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 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.ORDER then
if QuestionArgs.SubMode then
local nSubMode = tonumber( QuestionArgs["SubMode"])
EgtOutLog('SubMode=' .. nSubMode)
if nSubMode == QUESTION_ORDER_SUBMODES.CREATE then
nResult, AnswerArgs = Create_Order( QuestionArgs)
elseif nSubMode == QUESTION_ORDER_SUBMODES.ESTIMATE then
_G.LUX = {}
LUX.REDISID = nRedisConnectionId
nResult, AnswerArgs = Calc_Estimate( QuestionArgs)
else
nResult = 0
local sErrorMsg = 'Errore! Valore di SubMode errato!'
AnswerArgs = { Error = sErrorMsg}
EgtOutLog( sErrorMsg)
end
if AnswerArgs then
AnswerArgs.Mode = nMode
AnswerArgs.SubMode = nSubMode
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')
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)
+342
View File
@@ -0,0 +1,342 @@
--
-- 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
--
-- BeamWallPipeLib by Egalware s.r.l. 2023/05/09
-- Questo script fa da libreria delle funzioni di calcolo e verifica delle travi e pareti
-- Tabella per definizione modulo
local BeamWallPipeLib = {}
require( 'EgtBase')
--_ENV = EgtProtectGlobal()
--EgtEnableDebug( true)
local sIniFilePath = EgtGetIniFile()
local sBaseDir = EgtGetStringFromIni( 'Beam', 'BaseDir', '', sIniFilePath)
EgtAddToPackagePath( sBaseDir .. '\\?.lua')
-- modalita' di chiamata
QUESTION_MODES = {
NULL = 0,
PREVIEW = 1,
BOM = 2,
HARDWARE = 3,
CONFIG = 4,
ORDER = 5,
VERIFY = 6,
}
-- Tipo di progetto
PROJECT_TYPES = {
NULL = 0,
PROJ = 1,
PROD = 2,
}
-- Tipo di progetto (Beam o Wall)
BWTYPES = {
NULL = 0,
BEAM = 1,
WALL = 2,
}
CALCSTATES = {
NOTCALCULATED = -1,
OK = 0,
INFO = 1,
WARNING = 2,
ERROR_ = 3,
COLLISION = 4,
}
CMDTYPES = {
GENERATE = 0,
MODIFY = 1,
SIMULATE = 2,
CHECK = 3,
CHECKGEN = 4,
POINT_CLOUD = 5,
RAWPART = 6,
EDIT = 7,
CHECKNOSIM = 8,
TOPOLOGY = 9,
OPENTOOLDB = 11, -- Non utilizzato
OPENMACHINIGDB = 12, -- Non utilizzato
}
local CUTID = 'CUTID'
local BTL_PRT_PDN = 'PDN'
local OUTLINE = 'Outline'
local BTL_FTR_GRP = 'GRP'
local BTL_FTR_MAINID = 'MAINID'
local BTL_FTR_AUXID = 'AUXID'
local PROCESSINGS = 'Processings'
local TASKID = 'TASKID'
_G.package.loaded.JSON = nil
local JSON = require( 'JSON')
-- Canali
local QuestionChannel = "EgwVerifyQuestion"
local AnswerChannel = "EgwVerifyAnswer"
local nRedisConnectionId = 0
---------------------------------------------------------------------
-- funzione che aggiorna CutId e TaskId
local function UpdateCutIdAndTaskId( nPartId)
-- Assegno Id a CutId per calcoli
EgtSetInfo( nPartId, CUTID, nPartId, true)
-- Assegno TASKID agli outline per calcoli
local nOutLayerId = EgtGetFirstNameInGroup( nPartId, OUTLINE)
local nOutlineId = EgtGetFirstInGroup( nOutLayerId)
while nOutlineId do
-- verifico che sia una feature
local nGRP = EgtGetInfo( nOutlineId, BTL_FTR_GRP, 'i')
if nGRP then
-- verifico se ha un principale
local nMainOffsId = EgtGetInfo( nOutlineId, BTL_FTR_MAINID, 'i')
local nTaskId = nOutlineId
if nMainOffsId then
nTaskId = nOutlineId + nMainOffsId
end
-- assegno TASKID alla feature per calcoli
EgtSetInfo( nOutlineId, TASKID, nTaskId)
-- recupero eventuali AuxId
local sAuxIds = EgtGetInfo( nOutlineId, BTL_FTR_AUXID)
if sAuxIds then
local AuxIdArray = EgtSplitString( sAuxIds, ",")
if AuxIdArray.Count > 0 then
for AuxIdIndex = 1, #AuxIdArray do
local AuxId = AuxIdArray[AuxIdIndex]
AuxId = EgtTrim( AuxId)
AuxId = AuxId:gsub("^%+", "")
local nAuxId = tonumber( AuxId)
if nAuxId then
EgtSetInfo( nOutlineId + nAuxId, TASKID, nTaskId)
end
end
end
end
end
nOutlineId = EgtGetNext( nOutlineId)
end
-- Assegno TASKID alle feature per calcoli
local nProcessingId = EgtGetFirstNameInGroup( nPartId, PROCESSINGS)
local nFeatureId = EgtGetFirstInGroup( nProcessingId)
while nFeatureId do
-- verifico che sia una feature
local nGRP = EgtGetInfo( nFeatureId, BTL_FTR_GRP, 'i')
if nGRP then
-- verifico se ha un principale
local nMainOffsId = EgtGetInfo( nFeatureId, BTL_FTR_MAINID, 'i')
local nTaskId = nFeatureId
if nMainOffsId then
nTaskId = nFeatureId + nMainOffsId
end
-- assegno TASKID alla feature per calcoli
EgtSetInfo( nFeatureId, TASKID, nTaskId)
-- recupero eventuali AuxId
local sAuxIds = EgtGetInfo( nFeatureId, BTL_FTR_AUXID)
if sAuxIds then
local AuxIdArray = EgtSplitString( sAuxIds, ",")
for AuxIdIndex = 1, #AuxIdArray do
local AuxId = AuxIdArray[AuxIdIndex]
AuxId = EgtTrim( AuxId)
AuxId = AuxId:gsub("^%+", "")
local nAuxId = tonumber( AuxId)
if nAuxId then
EgtSetInfo( nFeatureId + nAuxId, TASKID, nTaskId)
end
end
end
end
nFeatureId = EgtGetNext( nFeatureId)
end
return true
end
---------------------------------------------------------------------
-- funzione che crea un Bwe da un pezzo Btl
local function CreateBWEFromPart( nPartId, sProjDirPath)
-- Aggiorno identificativi per segnalazione errori
UpdateCutIdAndTaskId( nPartId)
-- Disabilito segnalazione modificato
local bOldEnMod = EgtGetEnableModified()
if bOldEnMod then
EgtDisableModified()
end
-- Recupero visibilita' pezzo e lo imposto a visibile
local nOldPartMode = 0
EgtGetMode( nPartId, nOldPartMode)
EgtSetMode( nPartId, GDB_MD.STD)
-- Salvo pezzo nel suo progetto
local bOk = false
local nPDN = EgtGetInfo( nPartId, BTL_PRT_PDN, 'i')
--EgtSaveFile( 'c:\\Temp\\TestPDN.nge')
local sPartFilePath = sProjDirPath .. '\\' .. tostring(nPDN) .. '.bwe'
bOk = EgtSaveObjToFile({ nPartId, EgtGetFirstNameInGroup( GDB_ID.ROOT, BTLINFO), EgtGetFirstNameInGroup( GDB_ID.ROOT, PROJECTINFO)}, sPartFilePath, GDB_NT.CMPTXT)
-- Ripristino visibilita' pezzo
EgtSetMode( nPartId, nOldPartMode)
-- Ripristino stato segnalazione modifica
if bOldEnMod then
EgtEnableModified()
end
return EgtIf( bOk, sPartFilePath, '')
end
---------------------------------------------------------------------
-- funzione che verifica un pezzo Btl
function BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState)
-- connessione a Redis
local bRedisConnect = false
if LUX and LUX.REDISID and LUX.REDISID > 0 then
-- connessione già creata dall'esterno
nRedisConnectionId = LUX.REDISID
elseif nRedisConnectionId == 0 then
-- se nessuna connessione la creo
bRedisConnect, nRedisConnectionId = EgtRedisAsyncConnect( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
if not bRedisConnect then
EgtOutLog( 'Errore! Impossibile connettersi con il server Redis dal Lua!')
end
end
BarPath = CreateBWEFromPart( nPartId, BarPath)
local CurrAnswerChannel = AnswerChannel .. os.time()
local Args = { BarId = nPartId,
--ProgramPage = PROJECT_TYPES.PROJ,
BarPath = BarPath,
--ProjType = BWTYPES.BEAM,
MachineName = sMachineName,
--GlobState = CALCSTATES.NOTCALCULATED,
CmdType = CMDTYPES.CHECKNOSIM,
OutputChannel = CurrAnswerChannel,
Mode = QUESTION_MODES.VERIFY,
UID = 1}
--Dim BarPath As String = ProjectManagerVM.CurrProd.sProdDirPath & "\Projs\" & CurrPart.nPROJ.ToString("0000")
--Args.Add("BarPath", BarPath)
--Dim nCmdType As CalcIntegration.CmdTypes = CmdTypes.GENERATE
--Select Case CurrPart.nGlobalState
-- Case Core.CalcStates.OK, CalcStates.INFO
-- nCmdType = CalcIntegration.CmdTypes.GENERATE
-- Case Else
-- If CurrPart.nGlobalState = CalcStates.NOTCALCULATED OrElse CurrPart.nFeaturesGlobalState > CalcStates.INFO Then
-- Dim sBTLPartFilePath As String = BarPath & "\" & CurrPart.nPDN.ToString() & ".ori.bwe"
-- If File.Exists(sBTLPartFilePath) Then File.Delete(sBTLPartFilePath)
-- End If
-- nCmdType = CalcIntegration.CmdTypes.CHECKNOSIM
--End Select
--Args.Add("CmdType", nCmdType)
local Question = { nThreadIndex = 0,
nId = 1,
ExecEnvironment = 2,
Args = Args}
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, CurrAnswerChannel, 60000)
-- se la connessione è stata creata in questa funzione la chiudo
if bRedisConnect then
EgtRedisAsyncDisconnect( nRedisConnectionId)
nRedisConnectionId = 0
end
if bOk then
EgtOutLog('Risposta Redis ricevuta:' .. Answer)
local JsonAnswer = JSON:decode( Answer)
AnswerArgs = JsonAnswer['Args']
AnswerArgs.OutputChannel = nil
return 1, AnswerArgs
else
local sErrorMsg = 'Errore! Risposta dal canale di verifica non arrivata!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
else
local sErrorMsg = 'Errore! Pubblicazione sul canale di verifica fallita!'
EgtOutLog(sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
---------------------------------------------------------------------
-- funzione che analizza i risultati della verifica
local function AnalyzeResult( RESULT)
local bMachiningOk = true
local dTime = 0
for nElementIndex = 1, #RESULT do
local CurrElement = RESULT[nElementIndex]
if CurrElement.sType == 'Part' then
if CurrElement.nErr > 0 then
bMachiningOk = false
end
elseif CurrElement.sType == 'Feature' then
if not CurrElement.ChosenStrategy or not CurrElement.ChosenStrategy.sStatus or ( CurrElement.ChosenStrategy.sStatus ~= 'Completed' and CurrElement.ChosenStrategy.sStatus ~= 'NotCompleted') then
bMachiningOk = false
end
elseif CurrElement.sType == 'Time' then
dTime = CurrElement.dTime
end
end
return bMachiningOk, dTime
end
---------------------------------------------------------------------
-- funzione che verifica una trave
function BeamWallPipeLib.VerifyBeam( QuestionArgs)
if QuestionArgs and QuestionArgs.BarPath and QuestionArgs.MachineName and QuestionArgs.CmdType then
local BarId = tonumber( QuestionArgs["BarId"])
local BarPath = QuestionArgs["BarPath"]
local MachineName = QuestionArgs["MachineName"]
local CmdType = tonumber( QuestionArgs["CmdType"])
--local ProgramPage = tonumber( QuestionArgs["ProgramPage"])
_G.BEAM = { BASEDIR = sBaseDir,
FILE = BarPath,
MACHINE = MachineName,
FLAG = CmdType,
BW = true }
local bOk, sErr = pcall( dofile, BEAM.BASEDIR .. "\\BatchProcessNew.lua")
if not bOk then
EgtOutLog( 'Error in BatchProcessNew.lua call (' .. ( sErr or '') ..')')
end
local bMachiningOk ,dTime = AnalyzeResult( RESULT)
--local nResult = EgtIf( bMachiningOk, 1, 0)
local AnswerArgs = {}
AnswerArgs.ERR = BEAM.ERR
AnswerArgs.BarId = BarId
AnswerArgs.BarPath = BarPath
AnswerArgs.Time = dTime
AnswerArgs.MachiningOk = EgtIf( bMachiningOk, 1, 0)
_G.BEAM = {}
return 1, AnswerArgs
else
local sErrorMsg = 'Errore! Domanda senza argomenti che sono obbligatori!'
EgtOutLog( sErrorMsg)
return 0, { Error = sErrorMsg}
end
end
---------------------------------------------------------------------
return BeamWallPipeLib
+144
View File
@@ -0,0 +1,144 @@
--
-- 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
--
-- BeamWallVerifyPipe by Egalware s.r.l. 2025/12/02
-- Questo script gestisce le richieste le richieste di verifica travi che arrivano da LUX
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')
local sBaseDir = EgtGetStringFromIni( 'Beam', 'BaseDir', '', sIniFilePath)
EgtAddToPackagePath( sBaseDir .. '\\?.lua')
_G.package.loaded.BeamWallPipeLib = nil
local BeamWallPipeLib = require( 'BeamWallPipeLib')
-- 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
-- funzione che verifica un bwe
local function Calc_Verify( QuestionArgs)
local nResult, AnswerArgs = BeamWallPipeLib.VerifyBeam( QuestionArgs)
return nResult, AnswerArgs
end
local nErr = 999
local nNilCount = 0
local bRun = true
-- ciclo principale che analizza le richieste
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('Ricevuta richiesta calcolo: nThreadIndex=' .. nThreadIndex .. ', nId=' .. nId .. ', UID=' .. sUid .. ', nMode=' .. nMode)
local Result = {}
if nMode == QUESTION_MODES.VERIFY then
_G.LUX = {}
LUX.REDISID = nRedisConnectionId
nResult, AnswerArgs = Calc_Verify( QuestionArgs)
if AnswerArgs then
AnswerArgs.OutputChannel = QuestionArgs["OutputChannel"]
EgtOutLog('OutputChannel=' .. AnswerArgs.OutputChannel)
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')
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)
+185 -36
View File
@@ -24,6 +24,7 @@ QUESTION_MODES = {
BOM = 2,
HARDWARE = 3,
CONFIG = 4,
ORDER = 5,
}
QUESTION_CONFIG_SUBMODES = {
@@ -58,9 +59,18 @@ EgtAddToPackagePath( sBaseDir .. '\\Designing\\?.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["Jwd"]
local sJwd = QuestionArgs["SerializedData"]
if sJwd and #sJwd > 0 then
-- imposto cartella profili
local sProfileDir = ''
@@ -89,10 +99,10 @@ local function Calc_Preview( QuestionArgs)
WinCalculate_CreatePartFromArea()
-- calcolo hardware
--WDG.FRAMEID = AreaId
WDG.CALC_HARDWARELIST=false
WDG.CALC_POSITIONLIST=false
WDG.CALC_MACHININGLIST=false
WDG.CALC_OPTIONLIST=false
--WDG.CALC_HARDWARELIST=false
--WDG.CALC_POSITIONLIST=false
--WDG.CALC_MACHININGLIST=false
--WDG.CALC_OPTIONLIST=false
--WinCalculate_AddHardware()
-- creo file svg
@@ -119,7 +129,7 @@ end
local function Calc_BOM( QuestionArgs)
-- leggo argomenti passati
local sJwd = QuestionArgs["Jwd"]
local sJwd = QuestionArgs["SerializedData"]
if sJwd and #sJwd > 0 then
-- imposto cartella profili
local sProfileDir = ''
@@ -141,7 +151,7 @@ local function Calc_BOM( QuestionArgs)
_G.WinCalculate_SetCalcSolid()
WDG.VALUE = false
WinCalculate_SetSimplifiedSolid()
WDG.VALUE = true
WDG.VALUE = false
WinCalculate_SetCalcPreview()
-- creazione pezzi
WDG.FRAMEID = AreaId
@@ -208,7 +218,7 @@ local function Calc_BOM( QuestionArgs)
end
end
local function Calc_Hardware( QuestionArgs, sReadLine)
local function Calc_HardwareList( QuestionArgs, sReadLine)
local nManufacturer = tonumber( QuestionArgs["Manufacturer"])
if nManufacturer == MANUFACTURERS.AGB then
-- Canali
@@ -220,11 +230,11 @@ local function Calc_Hardware( QuestionArgs, sReadLine)
local JsonQuestion = JSON:encode( Question)
local bOk = EgtRedisAsyncPublish( QuestionChannel, JsonQuestion)
local bOk = EgtRedisAsyncPublish( nRedisConnectionId, QuestionChannel, JsonQuestion)
local AnswerArgs
if bOk then
EgtOutLog('Messaggio Redis pubblicato:' .. QuestionChannel .. ' ' .. JsonQuestion)
local bOk, Answer = EgtRedisAsyncSubscribeOneMessage( AnswerChannel, 10000)
local bOk, Answer = EgtRedisAsyncSubscribeOneMessage( nRedisConnectionId, AnswerChannel, 10000)
if bOk then
EgtOutLog('Risposta Redis ricevuta:' .. Answer)
local JsonAnswer = JSON:decode( Answer)
@@ -245,12 +255,150 @@ local function Calc_Hardware( QuestionArgs, sReadLine)
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)
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
@@ -264,26 +412,6 @@ local nErr = 999
local nNilCount = 0
local bRun = true
--local sRedisConnection = ENG.Param2
--local RedisConnectionParamList = EgtSplitString( sRedisConnection, ',')
--local sRedisAddressPort = RedisConnectionParamList[1]
--sRedisAddressPort, _ = EgtReplaceString( sRedisAddressPort, 'server=', '')
--local RedisAddressPortLi st = EgtSplitString( sRedisAddressPort, ':')
--local nDefaultDatabase = ''
--for nIndex = 2, #RedisConnectionParamList do
-- local sParam = ''
-- local nParam = 0
-- sParam, nParam = EgtReplaceString( RedisConnectionParamList[nIndex], 'DefaultDatabase=', '')
-- if nParam == 1 then
-- nDefaultDatabase = tonumber( EgtTrim( sParam))
-- end
--end
local bRedisConnect = EgtRedisAsyncConnect( ENG.Param2)
--local bRedisConnect = EgtRedisAsyncConnect( 'redis02.ufficio:6378, serviceName=devel, DefaultDatabase=0, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
if not bRedisConnect then
EgtOutLog('Errore! Impossibile connettersi con il server Redis dal Lua!')
end
local size = 2^13 -- good buffer size (8K)
while bRun do
local sReadLine = io.stdin:read( 'l')
@@ -311,15 +439,36 @@ while bRun do
local sUid = QuestionArgs["UID"]
local nMode = tonumber( QuestionArgs["Mode"])
_G.WDG = {}
-- esecuzione della corretta modilita'
EgtOutLog('Esecuzione calcolo')
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
nResult, AnswerArgs = Calc_Hardware( QuestionArgs, sReadLine)
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"])
@@ -358,7 +507,7 @@ while bRun do
nResult = nResult,
Args = AnswerArgs}
-- invio risposta
EgtOutLog( '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()
@@ -375,4 +524,4 @@ while bRun do
end
end
EgtRedisAsyncDisconnect()
EgtRedisAsyncDisconnect( nRedisConnectionId)