a1700f635c
- aggiunte linee di debug per processi - aggiunta modalita' hardware, config, order, verify - migliorato png delle travi - aggiunto volume in BOM - aggiunto sanitizeUtf8 - spostata connessione Redis a inizio file - gestite chiamate REST per beam - gestita verifica non parallela per travi - aggiunte opzioni hardware finestre - aggiunta calcolo forma anta finestra
342 lines
12 KiB
Lua
342 lines
12 KiB
Lua
--
|
|
-- EEEEEEEEEE GGGGGG TTTTTTTTTTTTTT
|
|
-- EEEEEEEEEE GGGGGGGGGG TTTTTTTTTTTTTT
|
|
-- EEEE GGGG GGGG TTTT
|
|
-- EEEE GGGG TTTT
|
|
-- EEEEEEE GGGG GGGGGGG TTTT
|
|
-- EEEEEEE GGGG GGGGGGG TTTT
|
|
-- EEEE GGGG GGGG TTTT
|
|
-- EEEE GGGG GGGG TTTT
|
|
-- EEEEEEEEEE GGGGGGGGGG TTTT
|
|
-- EEEEEEEEEE GGGGGG TTTT
|
|
--
|
|
-- BeamWallPipeLib by Egalware s.r.l. 2023/05/09
|
|
-- Questo script fa da libreria delle funzioni di calcolo e verifica delle travi e pareti
|
|
|
|
-- Tabella per definizione modulo
|
|
local BeamWallPipeLib = {}
|
|
|
|
require( 'EgtBase')
|
|
--_ENV = EgtProtectGlobal()
|
|
--EgtEnableDebug( true)
|
|
|
|
local sIniFilePath = EgtGetIniFile()
|
|
local sBaseDir = EgtGetStringFromIni( 'Beam', 'BaseDir', '', sIniFilePath)
|
|
EgtAddToPackagePath( sBaseDir .. '\\?.lua')
|
|
|
|
-- modalita' di chiamata
|
|
QUESTION_MODES = {
|
|
NULL = 0,
|
|
PREVIEW = 1,
|
|
BOM = 2,
|
|
HARDWARE = 3,
|
|
CONFIG = 4,
|
|
ORDER = 5,
|
|
VERIFY = 6,
|
|
}
|
|
|
|
-- Tipo di progetto
|
|
PROJECT_TYPES = {
|
|
NULL = 0,
|
|
PROJ = 1,
|
|
PROD = 2,
|
|
}
|
|
|
|
-- Tipo di progetto (Beam o Wall)
|
|
BWTYPES = {
|
|
NULL = 0,
|
|
BEAM = 1,
|
|
WALL = 2,
|
|
}
|
|
|
|
CALCSTATES = {
|
|
NOTCALCULATED = -1,
|
|
OK = 0,
|
|
INFO = 1,
|
|
WARNING = 2,
|
|
ERROR_ = 3,
|
|
COLLISION = 4,
|
|
}
|
|
|
|
CMDTYPES = {
|
|
GENERATE = 0,
|
|
MODIFY = 1,
|
|
SIMULATE = 2,
|
|
CHECK = 3,
|
|
CHECKGEN = 4,
|
|
POINT_CLOUD = 5,
|
|
RAWPART = 6,
|
|
EDIT = 7,
|
|
CHECKNOSIM = 8,
|
|
TOPOLOGY = 9,
|
|
OPENTOOLDB = 11, -- Non utilizzato
|
|
OPENMACHINIGDB = 12, -- Non utilizzato
|
|
}
|
|
|
|
local CUTID = 'CUTID'
|
|
local BTL_PRT_PDN = 'PDN'
|
|
local OUTLINE = 'Outline'
|
|
local BTL_FTR_GRP = 'GRP'
|
|
local BTL_FTR_MAINID = 'MAINID'
|
|
local BTL_FTR_AUXID = 'AUXID'
|
|
local PROCESSINGS = 'Processings'
|
|
local TASKID = 'TASKID'
|
|
|
|
_G.package.loaded.JSON = nil
|
|
local JSON = require( 'JSON')
|
|
|
|
-- Canali
|
|
local QuestionChannel = "EgwVerifyQuestion"
|
|
local AnswerChannel = "EgwVerifyAnswer"
|
|
|
|
local nRedisConnectionId = 0
|
|
|
|
---------------------------------------------------------------------
|
|
-- funzione che aggiorna CutId e TaskId
|
|
local function UpdateCutIdAndTaskId( nPartId)
|
|
-- Assegno Id a CutId per calcoli
|
|
EgtSetInfo( nPartId, CUTID, nPartId, true)
|
|
|
|
-- Assegno TASKID agli outline per calcoli
|
|
local nOutLayerId = EgtGetFirstNameInGroup( nPartId, OUTLINE)
|
|
local nOutlineId = EgtGetFirstInGroup( nOutLayerId)
|
|
while nOutlineId do
|
|
-- verifico che sia una feature
|
|
local nGRP = EgtGetInfo( nOutlineId, BTL_FTR_GRP, 'i')
|
|
if nGRP then
|
|
-- verifico se ha un principale
|
|
local nMainOffsId = EgtGetInfo( nOutlineId, BTL_FTR_MAINID, 'i')
|
|
local nTaskId = nOutlineId
|
|
if nMainOffsId then
|
|
nTaskId = nOutlineId + nMainOffsId
|
|
end
|
|
-- assegno TASKID alla feature per calcoli
|
|
EgtSetInfo( nOutlineId, TASKID, nTaskId)
|
|
-- recupero eventuali AuxId
|
|
local sAuxIds = EgtGetInfo( nOutlineId, BTL_FTR_AUXID)
|
|
if sAuxIds then
|
|
local AuxIdArray = EgtSplitString( sAuxIds, ",")
|
|
if AuxIdArray.Count > 0 then
|
|
for AuxIdIndex = 1, #AuxIdArray do
|
|
local AuxId = AuxIdArray[AuxIdIndex]
|
|
AuxId = EgtTrim( AuxId)
|
|
AuxId = AuxId:gsub("^%+", "")
|
|
local nAuxId = tonumber( AuxId)
|
|
if nAuxId then
|
|
EgtSetInfo( nOutlineId + nAuxId, TASKID, nTaskId)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
nOutlineId = EgtGetNext( nOutlineId)
|
|
end
|
|
|
|
-- Assegno TASKID alle feature per calcoli
|
|
local nProcessingId = EgtGetFirstNameInGroup( nPartId, PROCESSINGS)
|
|
local nFeatureId = EgtGetFirstInGroup( nProcessingId)
|
|
while nFeatureId do
|
|
-- verifico che sia una feature
|
|
local nGRP = EgtGetInfo( nFeatureId, BTL_FTR_GRP, 'i')
|
|
if nGRP then
|
|
-- verifico se ha un principale
|
|
local nMainOffsId = EgtGetInfo( nFeatureId, BTL_FTR_MAINID, 'i')
|
|
local nTaskId = nFeatureId
|
|
if nMainOffsId then
|
|
nTaskId = nFeatureId + nMainOffsId
|
|
end
|
|
-- assegno TASKID alla feature per calcoli
|
|
EgtSetInfo( nFeatureId, TASKID, nTaskId)
|
|
-- recupero eventuali AuxId
|
|
local sAuxIds = EgtGetInfo( nFeatureId, BTL_FTR_AUXID)
|
|
if sAuxIds then
|
|
local AuxIdArray = EgtSplitString( sAuxIds, ",")
|
|
for AuxIdIndex = 1, #AuxIdArray do
|
|
local AuxId = AuxIdArray[AuxIdIndex]
|
|
AuxId = EgtTrim( AuxId)
|
|
AuxId = AuxId:gsub("^%+", "")
|
|
local nAuxId = tonumber( AuxId)
|
|
if nAuxId then
|
|
EgtSetInfo( nFeatureId + nAuxId, TASKID, nTaskId)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
nFeatureId = EgtGetNext( nFeatureId)
|
|
end
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- funzione che crea un Bwe da un pezzo Btl
|
|
local function CreateBWEFromPart( nPartId, sProjDirPath)
|
|
-- Aggiorno identificativi per segnalazione errori
|
|
UpdateCutIdAndTaskId( nPartId)
|
|
|
|
-- Disabilito segnalazione modificato
|
|
local bOldEnMod = EgtGetEnableModified()
|
|
if bOldEnMod then
|
|
EgtDisableModified()
|
|
end
|
|
|
|
-- Recupero visibilita' pezzo e lo imposto a visibile
|
|
local nOldPartMode = 0
|
|
EgtGetMode( nPartId, nOldPartMode)
|
|
EgtSetMode( nPartId, GDB_MD.STD)
|
|
|
|
-- Salvo pezzo nel suo progetto
|
|
local bOk = false
|
|
local nPDN = EgtGetInfo( nPartId, BTL_PRT_PDN, 'i')
|
|
--EgtSaveFile( 'c:\\Temp\\TestPDN.nge')
|
|
|
|
local sPartFilePath = sProjDirPath .. '\\' .. tostring(nPDN) .. '.bwe'
|
|
bOk = EgtSaveObjToFile({ nPartId, EgtGetFirstNameInGroup( GDB_ID.ROOT, BTLINFO), EgtGetFirstNameInGroup( GDB_ID.ROOT, PROJECTINFO)}, sPartFilePath, GDB_NT.CMPTXT)
|
|
|
|
-- Ripristino visibilita' pezzo
|
|
EgtSetMode( nPartId, nOldPartMode)
|
|
|
|
-- Ripristino stato segnalazione modifica
|
|
if bOldEnMod then
|
|
EgtEnableModified()
|
|
end
|
|
|
|
return EgtIf( bOk, sPartFilePath, '')
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- funzione che verifica un pezzo Btl
|
|
function BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState)
|
|
|
|
-- connessione a Redis
|
|
local bRedisConnect = false
|
|
if LUX and LUX.REDISID and LUX.REDISID > 0 then
|
|
-- connessione già creata dall'esterno
|
|
nRedisConnectionId = LUX.REDISID
|
|
elseif nRedisConnectionId == 0 then
|
|
-- se nessuna connessione la creo
|
|
bRedisConnect, nRedisConnectionId = EgtRedisAsyncConnect( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
|
|
if not bRedisConnect then
|
|
EgtOutLog( 'Errore! Impossibile connettersi con il server Redis dal Lua!')
|
|
end
|
|
end
|
|
|
|
BarPath = CreateBWEFromPart( nPartId, BarPath)
|
|
local CurrAnswerChannel = AnswerChannel .. os.time()
|
|
|
|
local Args = { BarId = nPartId,
|
|
--ProgramPage = PROJECT_TYPES.PROJ,
|
|
BarPath = BarPath,
|
|
--ProjType = BWTYPES.BEAM,
|
|
MachineName = sMachineName,
|
|
--GlobState = CALCSTATES.NOTCALCULATED,
|
|
CmdType = CMDTYPES.CHECKNOSIM,
|
|
OutputChannel = CurrAnswerChannel,
|
|
Mode = QUESTION_MODES.VERIFY,
|
|
UID = 1}
|
|
--Dim BarPath As String = ProjectManagerVM.CurrProd.sProdDirPath & "\Projs\" & CurrPart.nPROJ.ToString("0000")
|
|
--Args.Add("BarPath", BarPath)
|
|
--Dim nCmdType As CalcIntegration.CmdTypes = CmdTypes.GENERATE
|
|
--Select Case CurrPart.nGlobalState
|
|
-- Case Core.CalcStates.OK, CalcStates.INFO
|
|
-- nCmdType = CalcIntegration.CmdTypes.GENERATE
|
|
-- Case Else
|
|
-- If CurrPart.nGlobalState = CalcStates.NOTCALCULATED OrElse CurrPart.nFeaturesGlobalState > CalcStates.INFO Then
|
|
-- Dim sBTLPartFilePath As String = BarPath & "\" & CurrPart.nPDN.ToString() & ".ori.bwe"
|
|
-- If File.Exists(sBTLPartFilePath) Then File.Delete(sBTLPartFilePath)
|
|
-- End If
|
|
-- nCmdType = CalcIntegration.CmdTypes.CHECKNOSIM
|
|
--End Select
|
|
--Args.Add("CmdType", nCmdType)
|
|
local Question = { nThreadIndex = 0,
|
|
nId = 1,
|
|
ExecEnvironment = 2,
|
|
Args = Args}
|
|
local JsonQuestion = JSON:encode( Question)
|
|
|
|
local bOk = EgtRedisAsyncPublish( nRedisConnectionId, QuestionChannel, JsonQuestion)
|
|
local AnswerArgs
|
|
if bOk then
|
|
EgtOutLog('Messaggio Redis pubblicato:' .. QuestionChannel .. ' ' .. JsonQuestion)
|
|
local bOk, Answer = EgtRedisAsyncSubscribeOneMessage( nRedisConnectionId, CurrAnswerChannel, 60000)
|
|
-- se la connessione è stata creata in questa funzione la chiudo
|
|
if bRedisConnect then
|
|
EgtRedisAsyncDisconnect( nRedisConnectionId)
|
|
nRedisConnectionId = 0
|
|
end
|
|
if bOk then
|
|
EgtOutLog('Risposta Redis ricevuta:' .. Answer)
|
|
local JsonAnswer = JSON:decode( Answer)
|
|
AnswerArgs = JsonAnswer['Args']
|
|
AnswerArgs.OutputChannel = nil
|
|
return 1, AnswerArgs
|
|
else
|
|
local sErrorMsg = 'Errore! Risposta dal canale di verifica non arrivata!'
|
|
EgtOutLog(sErrorMsg)
|
|
return 0, { Error = sErrorMsg}
|
|
end
|
|
else
|
|
local sErrorMsg = 'Errore! Pubblicazione sul canale di verifica fallita!'
|
|
EgtOutLog(sErrorMsg)
|
|
return 0, { Error = sErrorMsg}
|
|
end
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- funzione che analizza i risultati della verifica
|
|
local function AnalyzeResult( RESULT)
|
|
local bMachiningOk = true
|
|
local dTime = 0
|
|
for nElementIndex = 1, #RESULT do
|
|
local CurrElement = RESULT[nElementIndex]
|
|
if CurrElement.sType == 'Part' then
|
|
if CurrElement.nErr > 0 then
|
|
bMachiningOk = false
|
|
end
|
|
elseif CurrElement.sType == 'Feature' then
|
|
if not CurrElement.ChosenStrategy or not CurrElement.ChosenStrategy.sStatus or ( CurrElement.ChosenStrategy.sStatus ~= 'Completed' and CurrElement.ChosenStrategy.sStatus ~= 'NotCompleted') then
|
|
bMachiningOk = false
|
|
end
|
|
elseif CurrElement.sType == 'Time' then
|
|
dTime = CurrElement.dTime
|
|
end
|
|
end
|
|
return bMachiningOk, dTime
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- funzione che verifica una trave
|
|
function BeamWallPipeLib.VerifyBeam( QuestionArgs)
|
|
if QuestionArgs and QuestionArgs.BarPath and QuestionArgs.MachineName and QuestionArgs.CmdType then
|
|
local BarId = tonumber( QuestionArgs["BarId"])
|
|
local BarPath = QuestionArgs["BarPath"]
|
|
local MachineName = QuestionArgs["MachineName"]
|
|
local CmdType = tonumber( QuestionArgs["CmdType"])
|
|
--local ProgramPage = tonumber( QuestionArgs["ProgramPage"])
|
|
_G.BEAM = { BASEDIR = sBaseDir,
|
|
FILE = BarPath,
|
|
MACHINE = MachineName,
|
|
FLAG = CmdType,
|
|
BW = true }
|
|
local bOk, sErr = pcall( dofile, BEAM.BASEDIR .. "\\BatchProcessNew.lua")
|
|
if not bOk then
|
|
EgtOutLog( 'Error in BatchProcessNew.lua call (' .. ( sErr or '') ..')')
|
|
end
|
|
local bMachiningOk ,dTime = AnalyzeResult( RESULT)
|
|
--local nResult = EgtIf( bMachiningOk, 1, 0)
|
|
local AnswerArgs = {}
|
|
AnswerArgs.ERR = BEAM.ERR
|
|
AnswerArgs.BarId = BarId
|
|
AnswerArgs.BarPath = BarPath
|
|
AnswerArgs.Time = dTime
|
|
AnswerArgs.MachiningOk = EgtIf( bMachiningOk, 1, 0)
|
|
_G.BEAM = {}
|
|
return 1, AnswerArgs
|
|
else
|
|
local sErrorMsg = 'Errore! Domanda senza argomenti che sono obbligatori!'
|
|
EgtOutLog( sErrorMsg)
|
|
return 0, { Error = sErrorMsg}
|
|
end
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return BeamWallPipeLib |