Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 491da764ff | |||
| d76c2e37e6 | |||
| 4c871f76ef | |||
| 27e1ddc3f0 | |||
| 8c8cc5056d | |||
| a1700f635c | |||
| 8e485aac69 | |||
| 35f360fcd3 |
+513
@@ -0,0 +1,513 @@
|
||||
--
|
||||
-- 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,
|
||||
}
|
||||
|
||||
-- modalita' di chiamata
|
||||
QUESTION_HARDWARE_SUBMODES = {
|
||||
NULL = 0,
|
||||
LIST = 1,
|
||||
CALCHARDWARE = 2,
|
||||
HARDWAREOPTION = 3,
|
||||
}
|
||||
|
||||
-- produttore
|
||||
MANUFACTURERS = {
|
||||
NULL = 0,
|
||||
AGB = 1,
|
||||
MAICO = 2,
|
||||
ROTO = 3,
|
||||
}
|
||||
|
||||
OPENINGTYPES = {
|
||||
NULL = 0,
|
||||
TURNONLY = 1,
|
||||
TILTTURN = 2,
|
||||
TILTONLY = 3,
|
||||
PIVOT = 4,
|
||||
FIXED = 5,
|
||||
COMPLANARSLIDE = 6,
|
||||
LIFTSLIDE = 7
|
||||
}
|
||||
|
||||
_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')
|
||||
|
||||
-- creo seed random utilizzando data e clock della CPU che fornisce i decimali di secondo
|
||||
math.randomseed( os.time() + math.floor( os.clock() * 1000000000))
|
||||
|
||||
local function AGBHardwareShapeConverter( sShape)
|
||||
if sShape == 'R' then
|
||||
return 'Rectangle'
|
||||
elseif sShape == 'T' then
|
||||
return 'Trapezoid'
|
||||
elseif sShape == 'AS' then
|
||||
return 'FullArc'
|
||||
elseif sShape == 'AR' then
|
||||
return 'Arc'
|
||||
elseif sShape == 'SS' then
|
||||
return 'SemiFullArc'
|
||||
elseif sShape == 'SR' then
|
||||
return 'SemiArc'
|
||||
elseif sShape == 'C' then
|
||||
return 'Circular'
|
||||
end
|
||||
end
|
||||
|
||||
local function AGBHardwareOpeningTypesConverter( sOpeningType)
|
||||
if sOpeningType == 'AR' then
|
||||
return 'TiltTurn'
|
||||
elseif sOpeningType == 'AB' then
|
||||
return 'TurnOnly'
|
||||
elseif sOpeningType == 'CO' then
|
||||
return 'ComplanarSlide'
|
||||
elseif sOpeningType == 'AS' then
|
||||
return 'LiftSlide'
|
||||
elseif sOpeningType == 'BI' then
|
||||
return 'Pivot'
|
||||
elseif sOpeningType == 'VA' then
|
||||
return 'TiltOnly'
|
||||
end
|
||||
end
|
||||
|
||||
local function Calc_HardwareModelList( nManufacturer)
|
||||
-- leggo argomenti passati
|
||||
if nManufacturer == MANUFACTURERS.AGB then
|
||||
local sNow = os.date( '_%Y_%m_%d_%H_%M_%S', os.time())
|
||||
local nRandomAdd = math.random( 1, 9999999999)
|
||||
local sIdentifier = sNow .. '_' .. string.format( '%010d', nRandomAdd)
|
||||
local sInputFileDir = EgtGetStringFromIni( 'AGB', 'InputFileDir', 'A:\\InputBatch', sIniFilePath)
|
||||
local sInputFile = sInputFileDir .. '\\Input' .. sNow .. '.txt'
|
||||
local sAGBOutputFileDir = EgtGetStringFromIni( 'AGB', 'AGBOutputFileDir', 'C:\\AGB3000NG\\OutputBatch', sIniFilePath)
|
||||
local sAGBOutputKitFile = sAGBOutputFileDir .. '\\Output' .. sNow .. '.txt'
|
||||
local sOutputFileDir = EgtGetStringFromIni( 'AGB', 'OutputFileDir', 'A:\\OutputBatch', sIniFilePath)
|
||||
local sOutputKitFile = sOutputFileDir .. '\\Output' .. sNow .. '.txt'
|
||||
-- Apro file Input in scrittura
|
||||
local fhInput = io.open( sInputFile, 'w')
|
||||
if not fhInput then
|
||||
EgtOutLog( 'Error opening file ' .. sInputFile)
|
||||
return false
|
||||
end
|
||||
|
||||
local sText = 'OUTPUTKIT=' .. sAGBOutputKitFile .. '\n' ..
|
||||
'DATAREQUEST=SE\n' ..
|
||||
'RUN'
|
||||
|
||||
-- Scrittura nuova linea
|
||||
fhInput:write( sText .. '\n')
|
||||
|
||||
-- Chiudo file
|
||||
fhInput:close()
|
||||
|
||||
-- attendo scrittura output
|
||||
local nWait = 0
|
||||
while not EgtExistsFile( sOutputKitFile) and nWait < 500 do
|
||||
nWait = nWait + 1
|
||||
EgtPause( 10, true)
|
||||
end
|
||||
|
||||
EgtPause( 10, true)
|
||||
|
||||
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 = AGBHardwareOpeningTypesConverter( KitParams[5]), Shape = AGBHardwareShapeConverter(KitParams[6]), SashQty = tonumber(KitParams[7]), SashPosition = tonumber(KitParams[8])}
|
||||
nKitLineIndex = nKitLineIndex + 1
|
||||
end
|
||||
-- Chiudo file OutputKit in lettura
|
||||
fhOutputKit:close()
|
||||
-- elimino file creati
|
||||
EgtEraseFile( sInputFile)
|
||||
EgtEraseFile( sOutputKitFile)
|
||||
local JsonOutputKit = JSON:encode( OutputKit)
|
||||
return 1, { HardwareModelList = JsonOutputKit}
|
||||
else
|
||||
local sErrorMsg = 'Errore! Produttore ' .. nManufacturer .. ' non gestito!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
|
||||
local function Calc_WindowHardware( nManufacturer, QuestionArgs)
|
||||
-- leggo argomenti passati
|
||||
if nManufacturer == MANUFACTURERS.AGB then
|
||||
local sNow = os.date( '_%Y_%m_%d_%H_%M_%S', os.time())
|
||||
local nRandomAdd = math.random( 1, 9999999999)
|
||||
local sIdentifier = sNow .. '_' .. string.format( '%010d', nRandomAdd)
|
||||
local sInputFileDir = EgtGetStringFromIni( 'AGB', 'InputFileDir', 'A:\\InputBatch', sIniFilePath)
|
||||
local sInputFile = sInputFileDir .. '\\Input' .. sNow .. '.txt'
|
||||
local sAGBOutputFileDir = EgtGetStringFromIni( 'AGB', 'AGBOutputFileDir', 'C:\\AGB3000NG\\OutputBatch', sIniFilePath)
|
||||
local sOutputFileDir = EgtGetStringFromIni( 'AGB', 'OutputFileDir', 'A:\\OutputBatch', sIniFilePath)
|
||||
local sAGBOutputKitFile = sAGBOutputFileDir .. '\\Output' .. sNow .. '.txt'
|
||||
local sAGBOutputPositionFile = sAGBOutputFileDir .. '\\OutputPosition' .. sNow .. '.txt'
|
||||
local sAGBOutputLavFile = sAGBOutputFileDir .. '\\OutputLav' .. sNow .. '.txt'
|
||||
local sOutputKitFile = sOutputFileDir .. '\\Output' .. sNow .. '.txt'
|
||||
local sOutputPositionFile = sOutputFileDir .. '\\OutputPosition' .. sNow .. '.txt'
|
||||
local sOutputMachiningFile = sOutputFileDir .. '\\OutputLav' .. sNow .. '.txt'
|
||||
local sInputOptionFile = sInputFileDir .. '\\Input' .. sNow .. '.opt'
|
||||
|
||||
-- Apro file Input in scrittura
|
||||
local fhInput = io.open( sInputFile, 'w')
|
||||
if not fhInput then
|
||||
local sErrorMsg = 'Error opening file ' .. sInputFile
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
|
||||
local ReturnMode = tonumber( QuestionArgs['ReturnMode'])
|
||||
local HardwareListFlag = ( ReturnMode & 1) ~= 0
|
||||
local HardwarePositionListFlag = ( ReturnMode & 2) ~= 0
|
||||
local MachiningListFlag = ( ReturnMode & 4) ~= 0
|
||||
local HardwareOptionListFlag = ( ReturnMode & 8) ~= 0
|
||||
local sInput = QuestionArgs['Input']
|
||||
local sText = ''
|
||||
if HardwareListFlag then
|
||||
sText = sText .. 'OUTPUTKIT=' .. sAGBOutputKitFile .. '\n' ..
|
||||
'EXTINFO=ON\n'
|
||||
end
|
||||
if MachiningListFlag then
|
||||
sText = sText .. 'CNCOUTPUT=' .. sAGBOutputLavFile .. '\n'
|
||||
end
|
||||
if HardwarePositionListFlag then
|
||||
sText = sText .. 'OUTPUTARTICLEPOSITION=' .. sAGBOutputPositionFile .. '\n'
|
||||
end
|
||||
if HardwareOptionListFlag and not HardwareListFlag and not MachiningListFlag and not HardwarePositionListFlag then
|
||||
sText = sText .. 'OUTPUTKIT=' .. sAGBOutputKitFile .. '\n'
|
||||
--sText = sText .. 'only_options=on\n'
|
||||
end
|
||||
sText = sText .. sInput
|
||||
sText = sText .. 'RUN'
|
||||
|
||||
-- Scrittura nuova linea
|
||||
fhInput:write( sText .. '\n')
|
||||
|
||||
-- Chiudo file
|
||||
fhInput:close()
|
||||
|
||||
|
||||
local OptionList = ''
|
||||
if HardwareOptionListFlag then
|
||||
|
||||
-- attendo scrittura OptionList
|
||||
local nWait = 0
|
||||
while not EgtExistsFile( sInputOptionFile) and nWait < 500 do
|
||||
nWait = nWait + 1
|
||||
EgtPause( 10, true)
|
||||
end
|
||||
|
||||
EgtPause( 10, true)
|
||||
|
||||
-- Apro file OptionList in lettura
|
||||
local fhOptionList = io.open( sInputOptionFile, 'r')
|
||||
if not fhOptionList then
|
||||
local sErrorInputOptionFile = EgtChangePathExtension( sInputOptionFile, '.err')
|
||||
local fhHardwareOptionListError = io.open( sErrorInputOptionFile, 'r')
|
||||
if not fhHardwareOptionListError then
|
||||
local sErrorMsg = 'Error opening file ' .. sInputOptionFile
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
else
|
||||
local sErrorMsg = 'Error opening file ' .. sInputOptionFile .. '\n' .. fhHardwareOptionListError:read('*a')
|
||||
fhHardwareOptionListError:close()
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
OptionList = fhOptionList:read('*a')
|
||||
-- Chiudo file OutputKit in lettura
|
||||
fhOptionList:close()
|
||||
end
|
||||
|
||||
local sHardwareList = ''
|
||||
if HardwareListFlag then
|
||||
|
||||
-- attendo scrittura OptionList
|
||||
local nWait = 0
|
||||
while not EgtExistsFile( sOutputKitFile) and nWait < 500 do
|
||||
nWait = nWait + 1
|
||||
EgtPause( 10, true)
|
||||
end
|
||||
|
||||
EgtPause( 10, true)
|
||||
|
||||
local HardwareList = {}
|
||||
-- Apro file OptionList in lettura
|
||||
local fhHardwareList = io.open( sOutputKitFile, 'r')
|
||||
if not fhHardwareList then
|
||||
local sErrorOutputKitFile = EgtChangePathExtension( sOutputKitFile, '.err')
|
||||
local fhHardwareListError = io.open( sErrorOutputKitFile, 'r')
|
||||
if not fhHardwareListError then
|
||||
local sErrorMsg = 'Error opening file ' .. sOutputKitFile
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
else
|
||||
local sErrorMsg = 'Error opening file ' .. sOutputKitFile .. '\n' .. fhHardwareListError:read('*a')
|
||||
fhHardwareListError:close()
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
local nHardwareLineIndex = 1
|
||||
for sLine in fhHardwareList:lines('l') do
|
||||
local HardwareListParams = EgtSplitString( sLine, ';')
|
||||
HardwareList[nHardwareLineIndex] = { Id = HardwareListParams[1], Qty = tonumber( HardwareListParams[2]), ArtCode = HardwareListParams[3], Description = HardwareListParams[4], UM = HardwareListParams[5], Price = tonumber(HardwareListParams[6]), Weight = tonumber(HardwareListParams[7])}
|
||||
nHardwareLineIndex = nHardwareLineIndex + 1
|
||||
end
|
||||
-- Chiudo file OutputKit in lettura
|
||||
fhHardwareList:close()
|
||||
-- elimino file creati
|
||||
EgtEraseFile( sOutputKitFile)
|
||||
sHardwareList = JSON:encode( HardwareList)
|
||||
end
|
||||
|
||||
local sMachiningList = ''
|
||||
if MachiningListFlag then
|
||||
|
||||
-- attendo scrittura OptionList
|
||||
local nWait = 0
|
||||
while not EgtExistsFile( sOutputMachiningFile) and nWait < 500 do
|
||||
nWait = nWait + 1
|
||||
EgtPause( 10, true)
|
||||
end
|
||||
|
||||
EgtPause( 10, true)
|
||||
|
||||
local MachiningList = {}
|
||||
-- Apro file OptionList in lettura
|
||||
local fhMachiningList = io.open( sOutputMachiningFile, 'r')
|
||||
if not fhMachiningList then
|
||||
local sErrorOutputMachiningFile = EgtChangePathExtension( sOutputMachiningFile, '.err')
|
||||
local fhMachiningListError = io.open( sErrorOutputMachiningFile, 'r')
|
||||
if not fhMachiningListError then
|
||||
local sErrorMsg = 'Error opening file ' .. sOutputMachiningFile
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
else
|
||||
local sErrorMsg = 'Error opening file ' .. sOutputMachiningFile .. '\n' .. fhMachiningListError:read('*a')
|
||||
fhMachiningListError:close()
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
local nMachiningLineIndex = 1
|
||||
for sLine in fhMachiningList:lines('l') do
|
||||
local MachiningListParams = EgtSplitString( sLine, ';')
|
||||
MachiningList[nMachiningLineIndex] = { RecordID = MachiningListParams[1], Sequence = MachiningListParams[2], WindowPart = MachiningListParams[3], SashIndex = tonumber( MachiningListParams[4]), SashPart = MachiningListParams[5], PosX = tonumber(MachiningListParams[6]), PosY = tonumber(MachiningListParams[7]), PosZ = tonumber(MachiningListParams[8]),
|
||||
Macro = MachiningListParams[9], AngleXY = tonumber( MachiningListParams[10]), AngleXZ = tonumber( MachiningListParams[11]), AngleYZ = tonumber( MachiningListParams[12]), RasabilitySup = tonumber( MachiningListParams[13]), RasabilityInf = tonumber( MachiningListParams[14]), Dimension = MachiningListParams[15],
|
||||
Direction = tonumber( MachiningListParams[16]), Name = MachiningListParams[17], Description = MachiningListParams[18], ArtCode = MachiningListParams[19], ArtDescription = MachiningListParams[20], Side = MachiningListParams[21], Screw = tonumber(MachiningListParams[22]), Screwdriver = tonumber( MachiningListParams[23]),
|
||||
Origin = MachiningListParams[24], Qty = tonumber( MachiningListParams[25])}
|
||||
nMachiningLineIndex = nMachiningLineIndex + 1
|
||||
end
|
||||
-- Chiudo file OutputKit in lettura
|
||||
fhMachiningList:close()
|
||||
-- elimino file creati
|
||||
EgtEraseFile( sOutputMachiningFile)
|
||||
sMachiningList = JSON:encode( MachiningList)
|
||||
end
|
||||
|
||||
local sPositionList = ''
|
||||
if HardwarePositionListFlag then
|
||||
|
||||
-- attendo scrittura OptionList
|
||||
local nWait = 0
|
||||
while not EgtExistsFile( sOutputPositionFile) and nWait < 500 do
|
||||
nWait = nWait + 1
|
||||
EgtPause( 10, true)
|
||||
end
|
||||
|
||||
EgtPause( 10, true)
|
||||
|
||||
local PositionList = {}
|
||||
-- Apro file OptionList in lettura
|
||||
local fhPositionList = io.open( sOutputPositionFile, 'r')
|
||||
if not fhPositionList then
|
||||
local sErrorOutputPositionFile = EgtChangePathExtension( sOutputPositionFile, '.err')
|
||||
local fhHardwarePositionListError = io.open( sErrorOutputPositionFile, 'r')
|
||||
if not fhHardwarePositionListError then
|
||||
local sErrorMsg = 'Error opening file ' .. sOutputPositionFile
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
else
|
||||
local sErrorMsg = 'Error opening file ' .. sOutputPositionFile .. '\n' .. fhHardwarePositionListError:read('*a')
|
||||
fhHardwarePositionListError:close()
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
local nPositionLineIndex = 1
|
||||
for sLine in fhPositionList:lines('l') do
|
||||
local PositionListParams = EgtSplitString( sLine, ';')
|
||||
PositionList[nPositionLineIndex] = { RecordID = PositionListParams[1], Sequence = PositionListParams[2], WindowPart = PositionListParams[3], SashIndex = tonumber( PositionListParams[4]), SashPart = PositionListParams[5], PosX = tonumber(PositionListParams[6]), PosY = tonumber(PositionListParams[7]), PosZ = tonumber(PositionListParams[8]),
|
||||
Macro = PositionListParams[9], ArticlePosX = tonumber( PositionListParams[10]), ArticlePosY = tonumber( PositionListParams[11]), ArticlePosZ = tonumber( PositionListParams[12]), RasabilitySup = tonumber( PositionListParams[13]), RasabilityInf = tonumber( PositionListParams[14]), Dimension = PositionListParams[15],
|
||||
Direction = tonumber( PositionListParams[16]), Name = PositionListParams[17], Description = PositionListParams[18], ArtCode = PositionListParams[19], ArtDescription = PositionListParams[20], Side = PositionListParams[21], Screw = tonumber(PositionListParams[22]), Screwdriver = tonumber( PositionListParams[23]),
|
||||
Origin = PositionListParams[24], Qty = tonumber( PositionListParams[25]), PosXMarker = tonumber( PositionListParams[26]), PosYMarker = tonumber( PositionListParams[27]), PosXxDes = tonumber( PositionListParams[28]), PosYxDes = tonumber( PositionListParams[29]), QuotaxDes = PositionListParams[30]}
|
||||
nPositionLineIndex = nPositionLineIndex + 1
|
||||
end
|
||||
-- Chiudo file OutputKit in lettura
|
||||
fhPositionList:close()
|
||||
-- elimino file creati
|
||||
EgtEraseFile( sOutputPositionFile)
|
||||
sPositionList = JSON:encode( PositionList)
|
||||
end
|
||||
|
||||
-- elimino file input creati
|
||||
EgtEraseFile( sInputFile)
|
||||
if EgtExistsFile( sInputOptionFile) then
|
||||
EgtEraseFile( sInputOptionFile)
|
||||
end
|
||||
|
||||
local AnswerArgs = { OptionList = OptionList,
|
||||
HardwareList = sHardwareList,
|
||||
MachiningList = sMachiningList,
|
||||
PositionList = sPositionList}
|
||||
return 1, AnswerArgs
|
||||
else
|
||||
local sErrorMsg = 'Errore! Produttore ' .. nManufacturer .. ' non gestito!'
|
||||
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.UID and QuestionArgs.Mode and QuestionArgs.SubMode then
|
||||
local sUid = QuestionArgs["UID"]
|
||||
local sRUID = QuestionArgs["RUID"]
|
||||
local nMode = tonumber( QuestionArgs["Mode"])
|
||||
-- esecuzione della corretta modalita'
|
||||
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
|
||||
-- nResult, AnswerArgs = Calc_BOM( QuestionArgs)
|
||||
if nMode == QUESTION_MODES.HARDWARE then
|
||||
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
|
||||
local sErrorMsg = 'Errore! Valore di SubMode errato!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Domanda senza SubMode o Manufacturer che sono obbligatori!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
end
|
||||
AnswerArgs.UID = sUid
|
||||
AnswerArgs.RUID = sRUID or 0
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Domanda senza argomenti, 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
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
--
|
||||
-- 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
|
||||
+1294
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,496 @@
|
||||
--
|
||||
-- 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 nAnswerChannel_Count = 0
|
||||
local nAnswerChannel_LastSecond = 0
|
||||
|
||||
local nRedisConnectionId = 0
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- funzione che verifica la connessione a Redis
|
||||
local function VerifyRedisConnection( sConnectionString)
|
||||
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( sConnectionString)
|
||||
if not bRedisConnect then
|
||||
EgtOutLog( 'Errore! Impossibile connettersi con il server Redis dal Lua!')
|
||||
end
|
||||
end
|
||||
return bRedisConnect
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- 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 crea un Bwe da un MachGroup
|
||||
local function CreateBWEFromMachGroup( nMachGroupId, sProjDirPath)
|
||||
-- Aggiorno identificativi per segnalazione errori
|
||||
EgtSetCurrMachGroup( nMachGroupId)
|
||||
local nRawId = EgtGetFirstRawPart()
|
||||
while nRawId do
|
||||
if EgtVerifyRawPartPhase( nRawId, 1) then
|
||||
local nPartId = EgtGetFirstPartInRawPart( nRawId)
|
||||
while nPartId do
|
||||
UpdateCutIdAndTaskId(nPartId)
|
||||
nPartId = EgtGetNextPartInRawPart( nPartId)
|
||||
end
|
||||
end
|
||||
nRawId = EgtGetNextRawPart( nRawId)
|
||||
end
|
||||
|
||||
-- Salvo gruppo di lavorazione nel suo progetto
|
||||
local sMachGroupName = EgtGetMachGroupName( nMachGroupId)
|
||||
local sMachGroupFilePath = sProjDirPath .. '\\' .. sMachGroupName .. '.bwe'
|
||||
if EgtSaveMachGroupToFile( nMachGroupId, { EgtGetFirstNameInGroup( GDB_ID.ROOT, BTLINFO), EgtGetFirstNameInGroup( GDB_ID.ROOT, PROJECTINFO)}, sMachGroupFilePath, GDB_NT.CMPTEXT) then
|
||||
return sMachGroupFilePath
|
||||
end
|
||||
return ''
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- funzione che verifica un pezzo Btl
|
||||
function BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState)
|
||||
|
||||
-- verifico connessione a Redis
|
||||
local bRedisConnect = VerifyRedisConnection( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
|
||||
|
||||
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}
|
||||
|
||||
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
|
||||
|
||||
local function GetAnswerChannelCode()
|
||||
local nCurrTime = os.time()
|
||||
if nCurrTime == nAnswerChannel_LastSecond then
|
||||
nAnswerChannel_Count = nAnswerChannel_Count + 1
|
||||
return nCurrTime .. nAnswerChannel_Count
|
||||
else
|
||||
nAnswerChannel_LastSecond = nCurrTime
|
||||
nAnswerChannel_Count = 0
|
||||
return nCurrTime
|
||||
end
|
||||
end
|
||||
|
||||
function BeamWallPipeLib.AsyncVerifyPartCalc( nPartId, BarPath, ProjType, sMachineName, GlobState, bIsMachGroup)
|
||||
|
||||
-- verifico connessione a Redis
|
||||
local bRedisConnect = VerifyRedisConnection( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
|
||||
|
||||
EgtResetCurrMachGroup()
|
||||
|
||||
if bIsMachGroup then
|
||||
BarPath = CreateBWEFromMachGroup( nPartId, BarPath)
|
||||
else
|
||||
BarPath = CreateBWEFromPart( nPartId, BarPath)
|
||||
end
|
||||
local CurrAnswerChannel = AnswerChannel .. GetAnswerChannelCode()
|
||||
|
||||
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}
|
||||
|
||||
local Question = { nThreadIndex = 0,
|
||||
nId = 1,
|
||||
ExecEnvironment = 2,
|
||||
Args = Args}
|
||||
local JsonQuestion = JSON:encode( Question)
|
||||
|
||||
EgtRedisAsyncSubscribe( nRedisConnectionId, CurrAnswerChannel)
|
||||
local bOk = EgtRedisAsyncPublish( nRedisConnectionId, QuestionChannel, JsonQuestion)
|
||||
if not bOk then
|
||||
EgtOutLog( 'Error! Verify Redis publish failed on PartId ' .. nPartId .. ' and channel ' .. CurrAnswerChannel .. '!')
|
||||
EgtRedisAsyncUnsubscribe( nRedisConnectionId, CurrAnswerChannel)
|
||||
EgtOutLog( 'EgtRedisAsyncUnsubscribe ' .. nRedisConnectionId .. ' ' .. CurrAnswerChannel)
|
||||
end
|
||||
return bOk, CurrAnswerChannel
|
||||
end
|
||||
|
||||
function BeamWallPipeLib.AsyncVerifyPartResult( CurrAnswerChannel)
|
||||
|
||||
-- verifico connessione a Redis
|
||||
local bRedisConnect = VerifyRedisConnection( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
|
||||
|
||||
local bOk, nCount, Answer = EgtRedisAsyncGetMessage( nRedisConnectionId, CurrAnswerChannel)
|
||||
|
||||
if bRedisConnect then
|
||||
EgtRedisAsyncDisconnect( nRedisConnectionId)
|
||||
nRedisConnectionId = 0
|
||||
end
|
||||
|
||||
if bOk then
|
||||
if nCount > 0 then
|
||||
EgtOutLog('Risposta Redis ricevuta:' .. Answer)
|
||||
EgtRedisAsyncUnsubscribe( nRedisConnectionId, CurrAnswerChannel)
|
||||
EgtOutLog( 'EgtRedisAsyncUnsubscribe ' .. nRedisConnectionId .. ' ' .. CurrAnswerChannel)
|
||||
local JsonAnswer = JSON:decode( Answer)
|
||||
if JsonAnswer then
|
||||
AnswerArgs = JsonAnswer['Args']
|
||||
AnswerArgs.OutputChannel = nil
|
||||
return true, true, AnswerArgs
|
||||
else
|
||||
return true, true
|
||||
end
|
||||
else
|
||||
return true, false
|
||||
end
|
||||
else
|
||||
return false
|
||||
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 tonumber( 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 ~= 'Not-Completed') 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
|
||||
local sErrorMsg = 'Errore! Chiamata alla funzione BatchProcessNew.lua fallita! (' .. ( sErr or '') .. ')'
|
||||
EgtOutLog( sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
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
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- funzione che esegue il nesting sui pezzi passati
|
||||
function BeamWallPipeLib.NestBeam( PartIdList, RawList, MachineNameList, StartOffset, Offset, LogFile)
|
||||
--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.NEST = { BASEDIR = sBaseDir,
|
||||
FILE = LogFile,
|
||||
MACHINELIST = MachineNameList,
|
||||
STARTOFFSET = 20,
|
||||
OFFSET = 7 }
|
||||
_G.PARTLIST = PartIdList
|
||||
_G.RAWLIST = RawList
|
||||
local sFileName = EgtGetStringFromIni( 'Nest', 'NestExec', '', sIniFilePath)
|
||||
--local bOk, sErr = pcall( dofile, sBaseDir .. '\\' .. sFileName .. 'New.lua')
|
||||
local bOk, sErr = pcall( dofile, sBaseDir .. '\\' .. 'NestProcessNew.lua')
|
||||
if not bOk then
|
||||
local sErrorMsg = 'Errore! Chiamata alla funzione NestProcessNew.lua fallita! (' .. ( sErr or '') .. ')'
|
||||
EgtOutLog( sErrorMsg)
|
||||
return false, sErrorMsg
|
||||
end
|
||||
--EgtSaveFile()
|
||||
--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 true
|
||||
--else
|
||||
-- local sErrorMsg = 'Errore! Domanda senza argomenti che sono obbligatori!'
|
||||
-- EgtOutLog( sErrorMsg)
|
||||
-- return 0, { Error = sErrorMsg}
|
||||
--end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
return BeamWallPipeLib
|
||||
@@ -0,0 +1,152 @@
|
||||
--
|
||||
-- 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
|
||||
|
||||
-- funzione che esegue il nesting
|
||||
local function Calc_Nesting( QuestionArgs)
|
||||
local nResult, AnswerArgs = BeamWallPipeLib.NestBeam( 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 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.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
|
||||
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
|
||||
|
||||
EgtRedisAsyncDisconnect( nRedisConnectionId)
|
||||
+621
@@ -0,0 +1,621 @@
|
||||
--
|
||||
-- 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,
|
||||
THRESHOLDLIST = 2,
|
||||
}
|
||||
|
||||
QUESTION_HARDWARE_SUBMODES = {
|
||||
NULL = 0,
|
||||
LIST = 1,
|
||||
CALCHARDWARE = 2,
|
||||
HARDWAREOPTION = 3,
|
||||
SASHSHAPE = 4,
|
||||
PROFILEDATAFROMAREA = 5,
|
||||
}
|
||||
|
||||
-- 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()
|
||||
|
||||
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_AreaProfiles( 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
|
||||
WinGetAreaProfiles()
|
||||
local nCalcShape = 0
|
||||
local AnswerGroupId = {}
|
||||
if WDG.AREAPROFILES and #WDG.AREAPROFILES > 0 then
|
||||
local JsonAnswerGroupId = JSON:encode( WDG.AREAPROFILES)
|
||||
return 1, { AreaProfiles = JsonAnswerGroupId}
|
||||
else
|
||||
return 0, { Error = "Errore! Dati profilo per l'area non trovati!", 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 function Calc_ThresholdList( QuestionArgs)
|
||||
-- leggo argomenti passati
|
||||
local sProfileName = QuestionArgs["ProfileName"]
|
||||
if sProfileName and #sProfileName > 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
|
||||
WDG.PROFILE = sProfileName
|
||||
GetProfileThresholdsList()
|
||||
WinGetProfileData()
|
||||
if not WDG.THRESHOLDSLIST then
|
||||
local sErrorMsg = 'Errore! Soglie non trovate!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
if not WDG.PROFILEDATA then
|
||||
local sErrorMsg = 'Errore! Dati profilo non trovati!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
local ThresholdList = { }
|
||||
for ThresholdIndex = 1, #WDG.THRESHOLDSLIST do
|
||||
table.insert( ThresholdList, { Type = WDG.THRESHOLDSLIST[ThresholdIndex].nType, Name = WDG.THRESHOLDSLIST[ThresholdIndex].sName})
|
||||
end
|
||||
local JsonThresholdList = JSON:encode( ThresholdList)
|
||||
--return 1, { ThresholdList = JsonThresholdList}
|
||||
--local ProfileDataDictionary = { }
|
||||
--for ThresholdIndex = 1, #WDG.THRESHOLDSLIST do
|
||||
-- table.insert( ProfileDataDictionary.ThresholdList, { Type = WDG.THRESHOLDSLIST[ThresholdIndex].nType, Name = WDG.THRESHOLDSLIST[ThresholdIndex].sName})
|
||||
--end
|
||||
--for k, v in pairs(WDG.PROFILEDATA) do
|
||||
-- ProfileDataDictionary[k] = v
|
||||
--end
|
||||
local JsonProfileDataDictionary = JSON:encode( WDG.PROFILEDATA)
|
||||
return 1, { ThresholdList = JsonThresholdList, ProfileData = JsonProfileDataDictionary}
|
||||
else
|
||||
local sErrorMsg = 'Errore! Profilo non trovato!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
|
||||
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 sRUID = QuestionArgs["RUID"]
|
||||
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)
|
||||
elseif nSubMode == QUESTION_HARDWARE_SUBMODES.PROFILEDATAFROMAREA then
|
||||
nResult, AnswerArgs = Calc_AreaProfiles( 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()
|
||||
elseif nSubMode == QUESTION_CONFIG_SUBMODES.THRESHOLDLIST then
|
||||
nResult, AnswerArgs = Calc_ThresholdList( 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
|
||||
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: 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)
|
||||
@@ -0,0 +1,436 @@
|
||||
--
|
||||
-- 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-FAST', MachineDirPath .. '\\Essetre-PF1250MAX' }
|
||||
--local MachinesDir = { MachineDirPath .. '\\Essetre-FAST'}
|
||||
local BeamMachineList = {}
|
||||
local AnswerChannelList = {}
|
||||
for nMachineIndex = 1, #MachinesDir do
|
||||
local _, sMachineName, _ = EgtSplitPath( MachinesDir[nMachineIndex])
|
||||
local sMaterial = EgtGetStringFromIni( 'General', 'Material', '', MachineDirPath .. '\\' .. sMachineName .. '\\' .. sMachineName .. '.ini')
|
||||
if sMaterial == 'Beam' then
|
||||
local sMachineOrderDirPath = sOrderDirPath .. '\\' .. sMachineName
|
||||
-- creo cartella per macchina
|
||||
if EgtExistsDirectory( sMachineOrderDirPath) then
|
||||
if not EgtEmptyDirectory( sMachineOrderDirPath) then
|
||||
local sErrorMsg = 'Errore! Impossibile svuotare cartella ' .. sMachineOrderDirPath .. ' per il progetto ' .. sOrderUID .. '!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
else
|
||||
if not EgtCreateDirectory( sMachineOrderDirPath) then
|
||||
local sErrorMsg = 'Errore! Impossibile creare cartella ' .. sMachineOrderDirPath .. ' per il progetto ' .. sOrderUID .. '!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
local sMachineNgeFilePath = sMachineOrderDirPath .. '\\' .. sUID .. '.nge'
|
||||
-- e copio file nge
|
||||
if not EgtCopyFile( sNgeFilePath, sMachineNgeFilePath) then
|
||||
local sErrorMsg = 'Errore! Copia del file nge per macchina ' .. sMachineName .. ' e progetto ' .. sUID .. ' fallita!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
if not EgtOpenFile( sMachineNgeFilePath) then
|
||||
local sErrorMsg = 'Errore! Fallita apertura del file per macchina ' .. sMachineName .. '!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
-- creo i singoli bwe e li mando da eseguire via redis
|
||||
local nPartId = EgtGetFirstPart()
|
||||
local AnswerArgs = {}
|
||||
local TagTimeList = {}
|
||||
local dTotTime = 0
|
||||
local nNotMachinedPart = 0
|
||||
while nPartId do
|
||||
local BarPath = sMachineOrderDirPath
|
||||
local ProjType = BWTYPES.BEAM
|
||||
local GlobState = CALCSTATES.NOTCALCULATED
|
||||
local bResult, AnswerChannel = BeamWallPipeLib.AsyncVerifyBtlPartCalc( nPartId, BarPath, ProjType, sMachineName, GlobState)
|
||||
if bResult then
|
||||
table.insert( AnswerChannelList, { Channel = AnswerChannel, PartId = nPartId, Machine = sMachineName})
|
||||
else
|
||||
local sErrorMsg = 'Errore! Tentativo di verifica del pezzo ' .. nPartId .. ' fallito!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
end
|
||||
nPartId = EgtGetNextPart( nPartId)
|
||||
end
|
||||
table.insert( BeamMachineList, { Name = sMachineName, PartList = { }})
|
||||
end
|
||||
end
|
||||
local nTimeCount = 0
|
||||
local nTimeClock = 100
|
||||
while nTimeCount < 1200 and #AnswerChannelList > 0 do
|
||||
local RemoveAnswerList = {}
|
||||
for nAnswerIndex = 1, #AnswerChannelList do
|
||||
local AnswerChannel = AnswerChannelList[nAnswerIndex]
|
||||
-- verifico se ci sono i risultati e aspetto che arrivino tutti
|
||||
local bOk, bAnswerReceived, PartAnswerArgs = BeamWallPipeLib.AsyncVerifyBtlPartResult( AnswerChannel.Channel)
|
||||
if bOk then
|
||||
if bAnswerReceived then
|
||||
if PartAnswerArgs then
|
||||
local sTagList = EgtGetInfo( AnswerChannel.PartId, 'LuxTagList')
|
||||
local TagList = EgtSplitString( sTagList, ',')
|
||||
local CalcResult
|
||||
CalcResult = EgtIf( tonumber( PartAnswerArgs.MachiningOk) == 1, PART_VERIFICATION_RESULTS.MACHINABLE, PART_VERIFICATION_RESULTS.NOTMACHINABLE)
|
||||
local BeamMachine = ''
|
||||
for nMachineIndex = 1, #BeamMachineList do
|
||||
if BeamMachineList[nMachineIndex].Name == AnswerChannel.Machine then
|
||||
BeamMachine = BeamMachineList[nMachineIndex]
|
||||
end
|
||||
end
|
||||
for nTagIndex = 1, #TagList do
|
||||
table.insert( BeamMachine.PartList, { Tag = TagList[nTagIndex], CalcResult = CalcResult, Time = ( PartAnswerArgs.Time or 0)})
|
||||
end
|
||||
table.insert( RemoveAnswerList, nAnswerIndex)
|
||||
else
|
||||
local sErrorMsg = 'Errore! Tentativo di verifica del pezzo sul canale' .. AnswerChannel.Channel .. ' fallito!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
end
|
||||
end
|
||||
elseif bOk then
|
||||
local sErrorMsg = 'Errore! Funzione di lettura risultato sul canale ' .. AnswerChannel.Channel .. ' fallita!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
end
|
||||
end
|
||||
for nRemoveAnswerCount = #RemoveAnswerList, 1, -1 do
|
||||
table.remove( AnswerChannelList, RemoveAnswerList[nRemoveAnswerCount])
|
||||
end
|
||||
EgtPause( nTimeClock, true)
|
||||
nTimeCount = nTimeCount + 1
|
||||
end
|
||||
if #AnswerChannelList > 0 then
|
||||
for nAnswerCount = 1, #AnswerChannelList do
|
||||
local sTagList = EgtGetInfo( AnswerChannelList[nAnswerCount].PartId, 'LuxTagList')
|
||||
local TagList = EgtSplitString( sTagList, ',')
|
||||
CalcResult = PART_VERIFICATION_RESULTS.CALCULATIONFAILED
|
||||
local sErrorMsg = 'Errore! Verifica sul pezzo ' .. AnswerChannelList[nAnswerCount].PartId .. ' fallita!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
local BeamMachine
|
||||
for nMachineIndex = 1, #BeamMachineList do
|
||||
if BeamMachineList[nMachineIndex].Name == AnswerChannelList[nAnswerCount].Machine then
|
||||
BeamMachine = BeamMachineList[nMachineIndex]
|
||||
end
|
||||
end
|
||||
for nTagIndex = 1, #TagList do
|
||||
table.insert( BeamMachine.PartList, { Tag = TagList[nTagIndex], CalcResult = CalcResult, Time = 0})
|
||||
end
|
||||
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 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.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
|
||||
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
|
||||
|
||||
EgtRedisAsyncDisconnect( nRedisConnectionId)
|
||||
Reference in New Issue
Block a user