Aggiunti file
This commit is contained in:
+473
@@ -0,0 +1,473 @@
|
||||
--
|
||||
-- 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( true)
|
||||
|
||||
-- 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 'Rectangular'
|
||||
elseif sShape == 'T' then
|
||||
return 'Trapezoidal'
|
||||
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
|
||||
EgtOutLog( 'Error opening file ' .. sInputFile)
|
||||
return false
|
||||
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
|
||||
EgtOutLog( 'Error opening file ' .. sInputOptionFile)
|
||||
return false
|
||||
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
|
||||
EgtOutLog( 'Error opening file ' .. sOutputKitFile)
|
||||
return false
|
||||
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()
|
||||
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
|
||||
EgtOutLog( 'Error opening file ' .. sOutputMachiningFile)
|
||||
return false
|
||||
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()
|
||||
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
|
||||
EgtOutLog( 'Error opening file ' .. sOutputPositionFile)
|
||||
return false
|
||||
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()
|
||||
sPositionList = JSON:encode( PositionList)
|
||||
end
|
||||
|
||||
--local OutputKit = {}
|
||||
---- Apro file OutputKit in lettura
|
||||
--local fhOutputKit = io.open( sOutputKitFile, 'r')
|
||||
--if not fhOutputKit then
|
||||
-- EgtOutLog( 'Error opening file ' .. sOutputKitFile)
|
||||
-- return false
|
||||
--end
|
||||
--local nKitLineIndex = 1
|
||||
--for sLine in fhOutputKit:lines('l') do
|
||||
-- local KitParams = EgtSplitString( sLine, ';')
|
||||
-- local DescriptionSplit = EgtSplitString( KitParams[4], '_')
|
||||
-- OutputKit[nKitLineIndex] = { Id = KitParams[3], FamilyName = DescriptionSplit[1], Description = KitParams[4], OpeningType = KitParams[5], Shape = KitParams[6], SashQty = tonumber(KitParams[7]), SashPosition = tonumber(KitParams[8])}
|
||||
-- nKitLineIndex = nKitLineIndex + 1
|
||||
--end
|
||||
---- Chiudo file OutputKit in lettura
|
||||
--fhOutputKit:close()
|
||||
|
||||
--local JsonOutputKit = JSON:encode( OutputKit)
|
||||
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 nMode = tonumber( QuestionArgs["Mode"])
|
||||
-- esecuzione della corretta modalita'
|
||||
EgtOutLog('Esecuzione calcolo')
|
||||
--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"])
|
||||
if nSubMode == QUESTION_HARDWARE_SUBMODES.LIST then
|
||||
nResult, AnswerArgs = Calc_HardwareModelList( nManufacturer)
|
||||
if AnswerArgs then
|
||||
AnswerArgs.OutputChannel = QuestionArgs["OutputChannel"]
|
||||
end
|
||||
elseif nSubMode == QUESTION_HARDWARE_SUBMODES.CALCHARDWARE then
|
||||
nResult, AnswerArgs = Calc_WindowHardware( nManufacturer, QuestionArgs)
|
||||
if AnswerArgs then
|
||||
AnswerArgs.OutputChannel = QuestionArgs["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
|
||||
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
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
--
|
||||
-- EEEEEEEEEE GGGGGG TTTTTTTTTTTTTT
|
||||
-- EEEEEEEEEE GGGGGGGGGG TTTTTTTTTTTTTT
|
||||
-- EEEE GGGG GGGG TTTT
|
||||
-- EEEE GGGG TTTT
|
||||
-- EEEEEEE GGGG GGGGGGG TTTT
|
||||
-- EEEEEEE GGGG GGGGGGG TTTT
|
||||
-- EEEE GGGG GGGG TTTT
|
||||
-- EEEE GGGG GGGG TTTT
|
||||
-- EEEEEEEEEE GGGGGGGGGG TTTT
|
||||
-- EEEEEEEEEE GGGGGG TTTT
|
||||
--
|
||||
-- by Egalware s.r.l.
|
||||
-- Door manager by Egalware s.r.l. 2023/05/09
|
||||
|
||||
require( 'EgtBase')
|
||||
_ENV = EgtProtectGlobal()
|
||||
EgtEnableDebug( false)
|
||||
|
||||
-- modalita' di chiamata
|
||||
QUESTION_MODES = {
|
||||
NULL = 0,
|
||||
PREVIEW = 1,
|
||||
BOM = 2,
|
||||
}
|
||||
|
||||
_G.package.loaded.JSON = nil
|
||||
local JSON = require( 'JSON')
|
||||
|
||||
local sIniFilePath = EgtGetIniFile()
|
||||
local sBaseDir = EgtGetStringFromIni( 'Aedifica', 'BaseDir', '', sIniFilePath)
|
||||
EgtAddToPackagePath( sBaseDir .. '\\?.lua')
|
||||
|
||||
--_G.package.loaded.WinProject = nil
|
||||
--local WinProject = require( 'WinProject')
|
||||
|
||||
local function Calc_Preview( QuestionArgs)
|
||||
-- leggo argomenti passati
|
||||
local sFile = QuestionArgs["FileName"]
|
||||
local sBtl = QuestionArgs["Btl"]
|
||||
if sFile and #sFile > 0 then
|
||||
if sBtl and #sBtl > 0 then
|
||||
_, sFileName, sExt = EgtSplitPath( sFile)
|
||||
-- scrivo testo su file
|
||||
local sBtlFilePath = EgtGetTempDir() .. '\\' .. sFileName .. '_' .. os.time() .. sExt
|
||||
-- Apro file Input in scrittura
|
||||
local fhBtl = io.open( sBtlFilePath, 'w')
|
||||
if not fhBtl then
|
||||
EgtOutLog( 'Error opening file ' .. sBtlFilePath)
|
||||
return false
|
||||
end
|
||||
-- Scrittura nuova linea
|
||||
fhBtl:write( sBtl .. '\n')
|
||||
-- Chiudo file
|
||||
fhBtl:close()
|
||||
-- verifico tipo di file
|
||||
local bOk = false
|
||||
if string.lower( sExt) == '.btl' then
|
||||
bOk = EgtImportBtl( sBtlFilePath)
|
||||
elseif string.lower( sExt) == '.btlx' then
|
||||
bOk = EgtImportBtlx( sBtlFilePath)
|
||||
else
|
||||
local sErrorMsg = 'Errore! Estensione file non riconosciuta!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
if not bOk then
|
||||
local sErrorMsg = 'Errore! Importazione file non riuscita!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
-- assemblo
|
||||
--EgtBeamShowBuilding( true)
|
||||
-- creo file svg
|
||||
-- sistemo la vista
|
||||
--EgtSetView( SCE_VD.ISO_SW, false)
|
||||
EgtZoom( SCE_ZM.ALL, true)
|
||||
-- salvo immagine
|
||||
local sSvgFilePath = EgtGetTempDir() .. '\\' .. sFileName .. '_' .. os.time() .. '.svg'
|
||||
EgtExportSvg( GDB_ID.ROOT, sSvgFilePath)
|
||||
-- leggo il file svg
|
||||
local SouFh = io.open( sSvgFilePath, "rb")
|
||||
local content
|
||||
if SouFh then
|
||||
content = SouFh:read( "*all")
|
||||
SouFh:close()
|
||||
end
|
||||
os.remove(sBtlFilePath)
|
||||
os.remove(sSvgFilePath)
|
||||
-- do risultato
|
||||
return 1, { Svg = content}
|
||||
else
|
||||
local sErrorMsg = 'Errore! Btl file vuoto!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
else
|
||||
local sErrorMsg = 'Errore! Nome file vuoto!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
|
||||
local function Calc_BOM( QuestionArgs)
|
||||
-- leggo argomenti passati
|
||||
local sFile = QuestionArgs["FileName"]
|
||||
local sBtl = QuestionArgs["Btl"]
|
||||
if sFile and #sFile > 0 then
|
||||
if sBtl and #sBtl > 0 then
|
||||
_, sFileName, sExt = EgtSplitPath( sFile)
|
||||
-- scrivo testo su file
|
||||
local sBtlFilePath = EgtGetTempDir() .. '\\' .. sFileName .. '_' .. os.time() .. sExt
|
||||
-- Apro file Input in scrittura
|
||||
local fhBtl = io.open( sBtlFilePath, 'w')
|
||||
if not fhBtl then
|
||||
EgtOutLog( 'Error opening file ' .. sBtlFilePath)
|
||||
return false
|
||||
end
|
||||
-- Scrittura nuova linea
|
||||
fhBtl:write( sBtl .. '\n')
|
||||
-- Chiudo file
|
||||
fhBtl:close()
|
||||
-- verifico tipo di file
|
||||
local bOk = false
|
||||
if string.lower( sExt) == '.btl' then
|
||||
bOk = EgtImportBtl( sBtlFilePath)
|
||||
elseif string.lower( sExt) == '.btlx' then
|
||||
bOk = EgtImportBtlx( sBtlFilePath)
|
||||
else
|
||||
local sErrorMsg = 'Errore! Estensione file non riconosciuta!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
os.remove(sBtlFilePath)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
os.remove(sBtlFilePath)
|
||||
if not bOk then
|
||||
local sErrorMsg = 'Errore! Importazione file non riuscita!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
-- calcolo quantita' pezzi, volume, barre lineari
|
||||
local PartList = {}
|
||||
local SectionList = {}
|
||||
local TotVol = 0
|
||||
local nPartId = EgtGetFirstPart()
|
||||
while nPartId do
|
||||
local dW = EgtGetInfo( nPartId, "W", 'd')
|
||||
local dH = EgtGetInfo( nPartId, "H", 'd')
|
||||
local dL = EgtGetInfo( nPartId, "L", 'd')
|
||||
local sMaterial = EgtGetInfo( nPartId, "MATERIAL", 'd')
|
||||
local nCnt = EgtGetInfo( nPartId, "CNT", 'd')
|
||||
table.insert( PartList, { W = dW, H = dH, L = dL , Material = sMaterial})
|
||||
local Section = nil
|
||||
for nSectionIndex = 1, #SectionList do
|
||||
if SectionList[nSectionIndex].W == dW and SectionList[nSectionIndex].H == dH and SectionList[nSectionIndex].Material == sMaterial then
|
||||
Section = SectionList[nSectionIndex]
|
||||
end
|
||||
end
|
||||
if Section then
|
||||
Section.Qty = Section.Qty + nCnt
|
||||
Section.TotLen = Section.TotLen + ( dL * nCnt)
|
||||
else
|
||||
table.insert( SectionList, { W = dW, H = dH, Material = sMaterial, Qty = nCnt, TotLen = ( dL * nCnt)})
|
||||
end
|
||||
TotVol = TotVol + ((( dW / 1000) * ( dH / 1000) * ( dL / 1000)) * nCnt)
|
||||
nPartId = EgtGetNextPart( nPartId)
|
||||
end
|
||||
local BOM = {}
|
||||
for nSectionIndex = 1, #SectionList do
|
||||
local Section = SectionList[nSectionIndex]
|
||||
table.insert( BOM, { ClassCode = 'BeamTrunk',
|
||||
ItemCode = 'Pine-' .. Section.W .. 'x' .. Section.H,
|
||||
ItemQty = Section.Qty,
|
||||
DescriptionCode = '',
|
||||
Qty = Section.TotLen / 1000})
|
||||
end
|
||||
-- do risultato
|
||||
local JsonBOM = JSON:encode( BOM)
|
||||
return 1, { BOM = JsonBOM}
|
||||
else
|
||||
local sErrorMsg = 'Errore! Btl file vuoto!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
else
|
||||
local sErrorMsg = 'Errore! Nome file vuoto!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local nErr = 999
|
||||
local nNilCount = 0
|
||||
local bRun = true
|
||||
|
||||
while bRun do
|
||||
local sReadLine = io.stdin:read( 'l')
|
||||
EgtOutLog( 'Letta riga da stdin')
|
||||
if sReadLine then
|
||||
if sReadLine == 'quit' then
|
||||
EgtOutLog( 'Chiusura processo')
|
||||
break
|
||||
end
|
||||
if sReadLine ~= '' and sReadLine:find( '^#8477271#') and sReadLine:find( '#8477271#$') then
|
||||
EgtOutLog( 'Lettura istruzione valida')
|
||||
sReadLine = string.sub( sReadLine, 10, #sReadLine - 9)
|
||||
local Question = JSON:decode( sReadLine)
|
||||
local nThreadIndex = -1
|
||||
local nId = -1
|
||||
local ExecEnvironment = -1
|
||||
local nResult = 0
|
||||
local AnswerArgs = {}
|
||||
if Question and Question.nThreadIndex and Question.nId and Question.Args then
|
||||
nThreadIndex = tonumber( Question["nThreadIndex"])
|
||||
nId = tonumber( Question["nId"])
|
||||
ExecEnvironment = tonumber( Question["ExecEnvironment"])
|
||||
local QuestionArgs = Question["Args"]
|
||||
if QuestionArgs and QuestionArgs.Mode and QuestionArgs.UID then
|
||||
local sUid = QuestionArgs["UID"]
|
||||
local nMode = tonumber( QuestionArgs["Mode"])
|
||||
-- esecuzione della corretta modilita'
|
||||
EgtOutLog('Esecuzione calcolo')
|
||||
local Result = {}
|
||||
if nMode == QUESTION_MODES.PREVIEW then
|
||||
nResult, AnswerArgs = Calc_Preview( QuestionArgs)
|
||||
elseif nMode == QUESTION_MODES.BOM then
|
||||
nResult, AnswerArgs = Calc_BOM( QuestionArgs)
|
||||
end
|
||||
AnswerArgs.UID = sUid
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Domanda senza argomenti o senza UID o Mode che sono obbligatori!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Formato domanda non riconosciuto o senza nThreadIndex, nId o Args!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
-- do risultato
|
||||
local Result = { nThreadIndex = nThreadIndex,
|
||||
nId = nId,
|
||||
ExecEnvironment = ExecEnvironment,
|
||||
nResult = nResult,
|
||||
Args = AnswerArgs}
|
||||
-- invio risposta
|
||||
EgtOutLog( 'Invio risposta')
|
||||
local JsonResult = JSON:encode( Result)
|
||||
io.stdout:write( "#8376261#" .. JsonResult .. "#8376261#" .. '\n')
|
||||
io.stdout:flush()
|
||||
EgtOutLog( 'Risposta inviata')
|
||||
EgtNewFile()
|
||||
end
|
||||
else
|
||||
if nNilCount >= 20 then
|
||||
bRun = false
|
||||
EgtOutLog( 'Errore! Lettura da stdin fallita!')
|
||||
end
|
||||
nNilCount = nNilCount + 1
|
||||
EgtPause( 100, true)
|
||||
end
|
||||
end
|
||||
+468
@@ -0,0 +1,468 @@
|
||||
--
|
||||
-- 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,
|
||||
}
|
||||
|
||||
QUESTION_CONFIG_SUBMODES = {
|
||||
NULL = 0,
|
||||
PROFILELIST = 1,
|
||||
}
|
||||
|
||||
QUESTION_HARDWARE_SUBMODES = {
|
||||
NULL = 0,
|
||||
LIST = 1,
|
||||
CALCHARDWARE = 2,
|
||||
HARDWAREOPTION = 3,
|
||||
}
|
||||
|
||||
-- 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')
|
||||
|
||||
local function Calc_Preview( QuestionArgs)
|
||||
-- leggo argomenti passati
|
||||
local sJwd = QuestionArgs["Jwd"]
|
||||
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["Jwd"]
|
||||
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_MACHINING=false
|
||||
WDG.CALC_HARDWARELIST=true
|
||||
WDG.CALC_POSITIONLIST=false
|
||||
WDG.CALC_OPTIONLIST=false
|
||||
WinCalculate_AddHardware()
|
||||
|
||||
---- creo file svg
|
||||
--WDG.GROUPID = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_PREVIEW)
|
||||
--WDG.FILE = 'C:\\Temp\\TestSvgManager.svg'
|
||||
--WinGetSvg()
|
||||
---- leggo il file
|
||||
--local SouFh = io.open( WDG.FILE, "rb")
|
||||
--local content
|
||||
--if SouFh then
|
||||
-- content = SouFh:read( "*all")
|
||||
-- --EgtOutBox( 'Error opening ' .. sFilePath, 'ReadFromFile', 'ERROR')
|
||||
-- SouFh:close()
|
||||
-- --return false
|
||||
--end
|
||||
WinGetSectionsTotalLenghts()
|
||||
WinGetGlassesList()
|
||||
-- do risultato
|
||||
local BOM = {}
|
||||
for Index = 1, #WDG.SECTIONS_LENGTHS do
|
||||
table.insert( BOM, { ClassCode = 'WindowTrunk',
|
||||
ItemCode = 'Pine-' .. WDG.SECTIONS_LENGTHS[Index].W .. 'x' .. WDG.SECTIONS_LENGTHS[Index].H,
|
||||
ItemQty = #WDG.SECTIONS_LENGTHS[Index].L,
|
||||
DescriptionCode = '',
|
||||
Qty = WDG.SECTIONS_LENGTHS[Index].TotL / 1000})
|
||||
end
|
||||
for Index = 1, #WDG.GLASSES_LIST do
|
||||
table.insert( BOM, { ClassCode = 'WindowGlass',
|
||||
ItemCode = '6/14argon/6-' .. EgtIf( WDG.GLASSES_LIST[Index].Rect, 'Rect-', 'Special-') .. WDG.GLASSES_LIST[Index].T,
|
||||
ItemQty = 1,
|
||||
DescriptionCode = WDG.GLASSES_LIST[Index].W .. 'x' .. WDG.GLASSES_LIST[Index].L,
|
||||
Qty = WDG.GLASSES_LIST[Index].W * WDG.GLASSES_LIST[Index].L / 1000000})
|
||||
end
|
||||
if WDG.HARDWAREKIT_LIST then
|
||||
for SashIndex = 1, #WDG.HARDWAREKIT_LIST do
|
||||
for HardwareIndex = 1, #WDG.HARDWAREKIT_LIST[SashIndex] do
|
||||
local Hardware = WDG.HARDWAREKIT_LIST[SashIndex][HardwareIndex]
|
||||
table.insert( BOM, { ClassCode = 'WindowHardware',
|
||||
ItemCode = '' .. Hardware['ArtCode'] .. '-' .. Hardware['Description'],
|
||||
ItemQty = 1,
|
||||
DescriptionCode = '',
|
||||
Price = Hardware['Price'],
|
||||
Qty = Hardware['Qty']})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local JsonBOM = JSON:encode( BOM)
|
||||
return 1, { BOM = JsonBOM}
|
||||
else
|
||||
local sErrorMsg = 'Errore! Jwd non trovato!'
|
||||
EgtOutLog(sErrorMsg)
|
||||
return 0, { Error = sErrorMsg}
|
||||
end
|
||||
end
|
||||
|
||||
local function Calc_Hardware( 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( QuestionChannel, JsonQuestion)
|
||||
local AnswerArgs
|
||||
if bOk then
|
||||
EgtOutLog('Messaggio Redis pubblicato:' .. QuestionChannel .. ' ' .. JsonQuestion)
|
||||
local bOk, Answer = EgtRedisAsyncSubscribeOneMessage( 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_ProfileList()
|
||||
-- leggo cartella profili
|
||||
local sProfileDir = ''
|
||||
sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', '', sIniFilePath)
|
||||
if sProfileDir and #sProfileDir > 0 then
|
||||
local Profiles = EgtFindAllFiles( sProfileDir)
|
||||
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_HardwareOptions( QuestionArgs, sReadLine)
|
||||
local sJwd = QuestionArgs["Jwd"]
|
||||
local nManufacturer = tonumber( QuestionArgs["Manufacturer"])
|
||||
if sJwd and #sJwd > 0 then
|
||||
if nManufacturer and nManufacturer == MANUFACTURERS.AGB 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()
|
||||
end
|
||||
end
|
||||
---- leggo argomenti passati
|
||||
--local sJwd = QuestionArgs["Jwd"]
|
||||
--if sJwd and #sJwd > 0 then
|
||||
-- local sNow = os.date( '_%Y_%m_%d_%H_%M_%S', os.time())
|
||||
-- local sInputFile = 'a:\\InputBatch\\Input' .. sNow .. '.txt'
|
||||
-- local sAGBOutputKitFile = 'C:\\AGB3000NG\\OutputBatch\\Output' .. sNow .. '.txt'
|
||||
-- local sOutputKitFile = 'a:\\OutputBatch\\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 < 20 do
|
||||
-- nWait = nWait + 1
|
||||
-- EgtPause( 500, true)
|
||||
-- end
|
||||
--
|
||||
-- EgtPause( 500, 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 = KitParams[5], Shape = KitParams[6], SashQty = tonumber(KitParams[7]), SashPosition = tonumber(KitParams[8])}
|
||||
-- nKitLineIndex = nKitLineIndex + 1
|
||||
-- end
|
||||
-- -- Chiudo file OutputKit in lettura
|
||||
-- fhOutputKit:close()
|
||||
--
|
||||
-- local JsonOutputKit = JSON:encode( OutputKit)
|
||||
-- return 1, { HardwareModelList = JsonOutputKit}
|
||||
--else
|
||||
-- local sErrorMsg = 'Errore! Jwd non trovato!'
|
||||
-- EgtOutLog(sErrorMsg)
|
||||
-- return 0, { Error = sErrorMsg}
|
||||
--end
|
||||
end
|
||||
|
||||
local nErr = 999
|
||||
local nNilCount = 0
|
||||
local bRun = true
|
||||
|
||||
--local sRedisConnection = ENG.Param2
|
||||
--local RedisConnectionParamList = EgtSplitString( sRedisConnection, ',')
|
||||
--local sRedisAddressPort = RedisConnectionParamList[1]
|
||||
--sRedisAddressPort, _ = EgtReplaceString( sRedisAddressPort, 'server=', '')
|
||||
--local RedisAddressPortLi st = EgtSplitString( sRedisAddressPort, ':')
|
||||
--local nDefaultDatabase = ''
|
||||
--for nIndex = 2, #RedisConnectionParamList do
|
||||
-- local sParam = ''
|
||||
-- local nParam = 0
|
||||
-- sParam, nParam = EgtReplaceString( RedisConnectionParamList[nIndex], 'DefaultDatabase=', '')
|
||||
-- if nParam == 1 then
|
||||
-- nDefaultDatabase = tonumber( EgtTrim( sParam))
|
||||
-- end
|
||||
--end
|
||||
local bRedisConnect = EgtRedisAsyncConnect( ENG.Param2)
|
||||
--local bRedisConnect = EgtRedisAsyncConnect( 'redis02.ufficio:6378, serviceName=devel, DefaultDatabase=0, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
|
||||
if not bRedisConnect then
|
||||
EgtOutLog('Errore! Impossibile connettersi con il server Redis dal Lua!')
|
||||
end
|
||||
|
||||
local size = 2^13 -- good buffer size (8K)
|
||||
while bRun do
|
||||
local sReadLine = io.stdin:read( 'l')
|
||||
EgtOutLog( 'Letta riga da stdin')
|
||||
if sReadLine then
|
||||
if sReadLine == 'quit' then
|
||||
EgtOutLog( 'Chiusura processo')
|
||||
break
|
||||
end
|
||||
if sReadLine ~= '' and sReadLine:find( '^#8477271#') and sReadLine:find( '#8477271#$') then
|
||||
EgtOutLog( 'Lettura istruzione valida')
|
||||
sReadLine = string.sub( sReadLine, 10, #sReadLine - 9)
|
||||
local Question = JSON:decode( sReadLine)
|
||||
local nThreadIndex = -1
|
||||
local nId = -1
|
||||
local ExecEnvironment = -1
|
||||
local nResult = 0
|
||||
local AnswerArgs = {}
|
||||
if Question and Question.nThreadIndex and Question.nId and Question.Args then
|
||||
nThreadIndex = tonumber( Question["nThreadIndex"])
|
||||
nId = tonumber( Question["nId"])
|
||||
ExecEnvironment = tonumber( Question["ExecEnvironment"])
|
||||
local QuestionArgs = Question["Args"]
|
||||
if QuestionArgs and QuestionArgs.Mode and QuestionArgs.UID then
|
||||
local sUid = QuestionArgs["UID"]
|
||||
local nMode = tonumber( QuestionArgs["Mode"])
|
||||
_G.WDG = {}
|
||||
-- esecuzione della corretta modilita'
|
||||
EgtOutLog('Esecuzione calcolo')
|
||||
local Result = {}
|
||||
if nMode == QUESTION_MODES.PREVIEW then
|
||||
nResult, AnswerArgs = Calc_Preview( QuestionArgs)
|
||||
elseif nMode == QUESTION_MODES.BOM then
|
||||
nResult, AnswerArgs = Calc_BOM( QuestionArgs)
|
||||
elseif nMode == QUESTION_MODES.HARDWARE then
|
||||
nResult, AnswerArgs = Calc_Hardware( QuestionArgs, sReadLine)
|
||||
elseif nMode == QUESTION_MODES.CONFIG then
|
||||
if QuestionArgs.SubMode then
|
||||
local nSubMode = tonumber( QuestionArgs["SubMode"])
|
||||
if nSubMode == QUESTION_CONFIG_SUBMODES.PROFILELIST then
|
||||
nResult, AnswerArgs = Calc_ProfileList()
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Valore di SubMode errato!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Domanda senza SubMode che é obbligatorio!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
end
|
||||
AnswerArgs.UID = sUid
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Domanda senza argomenti o senza UID o Mode che sono obbligatori!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
else
|
||||
nResult = 0
|
||||
local sErrorMsg = 'Errore! Formato domanda non riconosciuto o senza nThreadIndex, nId o Args!'
|
||||
AnswerArgs = { Error = sErrorMsg}
|
||||
EgtOutLog( sErrorMsg)
|
||||
end
|
||||
-- do risultato
|
||||
local Result = { nThreadIndex = nThreadIndex,
|
||||
nId = nId,
|
||||
ExecEnvironment = ExecEnvironment,
|
||||
nResult = nResult,
|
||||
Args = AnswerArgs}
|
||||
-- invio risposta
|
||||
EgtOutLog( 'Invio risposta')
|
||||
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()
|
||||
Reference in New Issue
Block a user