From 3bc9ef46889b04cd90ef0819c4c12eab10511d61 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Fri, 25 Apr 2025 19:39:37 +0200 Subject: [PATCH] - in BatchProcessNew varie modifiche per renderla compatibile con nuovo automatismo; manca restituzione risultati - in BeamExec prima versione della tabella globale RESULT per la restituzione risultati --- BatchProcessNew.lua | 146 +++++++++++++++++------- LuaLibs/BeamExec.lua | 15 ++- Strategies/Standard/STR0009/STR0009.lua | 1 + 3 files changed, 117 insertions(+), 45 deletions(-) diff --git a/BatchProcessNew.lua b/BatchProcessNew.lua index e09efbc..aaae33c 100644 --- a/BatchProcessNew.lua +++ b/BatchProcessNew.lua @@ -3,24 +3,109 @@ -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() -EgtEnableDebug( false) +EgtEnableDebug( true) + +-- Imposto direttorio libreria specializzata per Travi +EgtAddToPackagePath( BEAM.BASEDIR .. '\\LuaLibs\\?.lua') +-- Imposto direttorio strategie. N.B. Le strategie dovranno essere caricate con il nome del direttorio padre +EgtAddToPackagePath( BEAM.BASEDIR .. '\\Strategies\\Standard\\?.lua') +EgtAddToPackagePath( BEAM.BASEDIR .. '\\StrategyLibs\\?.lua') + +-- Verifico che la macchina corrente sia abilitata per la lavorazione delle Travi +local sMachine = BEAM.MACHINE +if BEAM.FLAG ~= 6 then + EgtResetCurrMachGroup() + if not EgtSetCurrMachine( sMachine) then + BEAM.ERR = 11 + BEAM.MSG = 'Error selecting machine : ' .. sMachine + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end +end +local sMachDir = EgtGetCurrMachineDir() +if not sMachDir then + EgtOutBox( 'Errore nel caricamento della macchina corrente', 'Lavora Travi', 'ERROR') + return +end +if not EgtExistsFile( sMachDir .. '\\Beam\\BeamData.lua') then + EgtOutBox( 'La macchina corrente non è configurata per lavorare travi', 'Lavora Travi', 'ERROR') + BEAM.ERR = 12 + BEAM.MSG = 'Error not configured for beams machine : ' .. sMachine + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return +end -- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie EgtRemoveBaseMachineDirFromPackagePath() EgtAddToPackagePath( sMachDir .. '\\Beam\\?.lua') --- Imposto direttorio libreria specializzata per Travi -EgtAddToPackagePath( BEAM.BASEDIR .. '\\LuaLibs\\?.lua') + +-- Segnalazione avvio +EgtOutLog( '*** Beam Process Start ***', 1) -- Carico le librerie _G.package.loaded.BeamExec = nil -local BeamExec = require( 'BeamExec') -local BeamLib = require( 'BeamLib') +_G.package.loaded.BeamLib = nil +_G.package.loaded.BeamData = nil +_G.package.loaded.Identity = nil +_G.package.loaded.BasicCustomerStrategies = nil +_G.package.loaded.FeatureLib = nil +_G.package.loaded.FaceData = nil +_G.package.loaded.MachiningLib = nil +_G.package.loaded.DiceCut = nil +_G.package.loaded.Logs = nil +-- strategie di base sempre presenti +_G.package.loaded['HEADCUT\\HEADCUT'] = nil +_G.package.loaded['TAILCUT\\TAILCUT'] = nil + +-- TODO controllare se c'è un modo migliore per resettare librerie delle strategie caricate precedentemente +-- Per ottimizzare potremmo anche ciclare solo fino al numero di strategie raggiunto per il momento. +-- Infatti difficile ci siano 9999 strategie. +-- reset strategie caricate come librerie +for i = 1, 9999 do + local IdSTRTemp = EgtReplaceString( tostring( i/10000, 4), '0.', '') + local sLibraryToReload = "STR" .. IdSTRTemp .. "\\STR" .. IdSTRTemp + if _G.package.loaded[sLibraryToReload] then + _G.package.loaded[sLibraryToReload] = nil + end +end +local vtCoreStrategiesNames = EgtFindAllFiles( BEAM.BASEDIR .. '\\StrategyLibs\\*.lua') +for i = 1, #vtCoreStrategiesNames do + local sCurrentName = EgtSplitString( vtCoreStrategiesNames[i], '.')[1] + if _G.package.loaded[sCurrentName] then + _G.package.loaded[sCurrentName] = nil + end +end + + +-- Variabili globali +PARTS = {} -- tabella contenente tutte le informazioni di ogni pezzo -- Carico i dati globali local BeamData = require( 'BeamData') +-- carico librerie +local BeamExec = require( 'BeamExec') + +-- Variabili di modulo +local dRawW +local dRawH ------------------------------------------------------------------------------------------------------------- --- Funzioni per scrittura su file di log specifico +-- Funzioni di supporto + +local function GetDataConfig() + -- recupero utensili dal magazzino + BeamExec.GetToolsFromDB() + -- se si utilizza interfaccia B&W, si carica il file JSON + local bIsBeamWall = true -- TODO serve parametro per capire se stiamo utilizzando B&W + if bIsBeamWall then + BeamExec.GetStrategiesFromJSONinBD() + end + -- TODO da gestire eventuali errori bloccanti + return true +end + local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) local hFile = io.open( sTxtLogFile, 'a') hFile:write( 'ERR=' .. tostring( nErr) .. '\n') @@ -66,7 +151,7 @@ end -- Funzione di reset gruppo di lavoro in caso di impossibilità di inserire i pezzi local function ResetMachGroup( PARTS) for i = 1, #PARTS do - EgtErase( PARTS[i].Id) + EgtErase( PARTS[i].id) end EgtRemoveMachGroup( EgtGetCurrMachGroup() or GDB_ID.NULL) end @@ -115,31 +200,6 @@ end -- Cancello file di log specifico EgtEraseFile( sTxtLogFile) --- impostazione della macchina corrente -local sMachine = BEAM.MACHINE - -if BEAM.FLAG ~= 6 then - EgtResetCurrMachGroup() - if not EgtSetCurrMachine( sMachine) then - BEAM.ERR = 11 - BEAM.MSG = 'Error selecting machine : ' .. sMachine - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) - return - end -end - --- Verifico che la macchina corrente sia abilitata per la lavorazione delle Travi -local sMachDir = EgtGetCurrMachineDir() - -if not EgtExistsFile( sMachDir .. '\\Beam\\BeamData.lua') then - BEAM.ERR = 12 - BEAM.MSG = 'Error not configured for beams machine : ' .. sMachine - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) - return -end - -- In generale va completamente riprocessato local bToProcess = true local bToRecalc = false @@ -167,7 +227,6 @@ if bToProcess then local bCreateBar -- Lunghezza della barra ed elenco travi local dBarLen - local PARTS = {} -- Se necessario, apro il file Bwe if BEAM.FLAG ~= 6 then @@ -212,7 +271,7 @@ if bToProcess then -- Recupero l'elenco ordinato delle travi local nPartId = EgtGetFirstPart() while nPartId do - table.insert( PARTS, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) + table.insert( PARTS, { id = nPartId, sName = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) nPartId = EgtGetNextPart( nPartId) end if #PARTS == 0 then @@ -224,18 +283,18 @@ if bToProcess then else local sOut = '' for i = 1, #PARTS do - sOut = sOut .. PARTS[i].Name .. ', ' + sOut = sOut .. PARTS[i].sName .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi trovate : ' .. sOut, 1) end -- Ne recupero le dimensioni for i = 1, #PARTS do - local Ls = EgtGetFirstNameInGroup( PARTS[i].Id, 'Box') + local Ls = EgtGetFirstNameInGroup( PARTS[i].id, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then BEAM.ERR = 15 - BEAM.MSG = 'Box undefined for beam ' .. PARTS[i].Name + BEAM.MSG = 'Box undefined for beam ' .. PARTS[i].sName WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return @@ -268,7 +327,7 @@ if bToProcess then if not vVal or #vVal < 2 then break end local nPartId = tonumber( vVal[1]) local dPosX = tonumber( vVal[2]) - table.insert( PARTS, { Id = nPartId, PosX = dPosX, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) + table.insert( PARTS, { id = nPartId, dPosX = dPosX, sName = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) end if #PARTS == 0 then BEAM.ERR = 14 @@ -278,18 +337,18 @@ if bToProcess then else local sOut = '' for i = 1, #PARTS do - sOut = sOut .. PARTS[i].Name .. ', ' + sOut = sOut .. PARTS[i].sName .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi trovate : ' .. sOut, 1) end -- Ne recupero le dimensioni for i = 1, #PARTS do - local Ls = EgtGetFirstNameInGroup( PARTS[i].Id, 'Box') + local Ls = EgtGetFirstNameInGroup( PARTS[i].id, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then BEAM.ERR = 15 - BEAM.MSG = 'Box undefined for beam ' .. PARTS[i].Name + BEAM.MSG = 'Box undefined for beam ' .. PARTS[i].sName WriteErrToLogFile( BEAM.ERR, BEAM.MSG) return else @@ -300,8 +359,6 @@ if bToProcess then -- Se devo creare la barra if bCreateBar then - local dRawW - local dRawH if #PARTS == 0 then -- Recupero l'identificativo del gruppo di lavoro corrente local nMGrpId = EgtGetCurrMachGroup() @@ -325,7 +382,7 @@ if bToProcess then if #vBeamErr > 0 then local sOut = 'Rimosse travi con sezioni diverse dalla prima :\n' for i = #vBeamErr, 1, -1 do - sOut = sOut .. PARTS[vBeamErr[i]].Name .. '\n' + sOut = sOut .. PARTS[vBeamErr[i]].sName .. '\n' table.remove( PARTS, vBeamErr[i]) end ResetMachGroup( PARTS) @@ -447,6 +504,7 @@ if bToProcess then -- Lavoro le features --local bPfOk, Stats = BeamExec.ProcessFeatures() + if not GetDataConfig() then return end BeamExec.GetProcessings( PARTS) local bOk, Stats = BeamExec.ProcessMachinings( PARTS) local sOutput = '' diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 4913fe9..6c6a77d 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -34,6 +34,7 @@ STRATEGIES_CONFIG = {} -- tabella contenente i parametri di default delle strat MACHININGS = {} -- tabella contenente le lavorazioni da applicare MACHININGS.Info = {} PROCESSINGS = {} -- tabella contenente tutte le informazioni di ogni feature, processate per ogni rotazione +RESULT = {} -- tabella contenente il risultato, feature per feature, dell'applicazione della strategia scelta e il resoconto dell'analisi fatta ------------------------------------------------------------------------------------------------------------- -- *** COSTANTI *** TODO -> DA SPOSTARE IN BEAMDATA??? @@ -1054,6 +1055,18 @@ local function CalculateMachinings( vProc, Part, nInitialRotation) local StrategyScript = require( StrategyScriptName) -- eseguo la strategia e si applicano le lavorazioni. Si passa la Proc e i parametri personalizzati _, _ = StrategyScript.Make( true, Proc, Part, Proc.ChosenStrategy) + -- scrivo risultato in tabella globale + -- TODO funzione + RESULT[#RESULT+1] = { + id = Proc.id, + idFeature = Proc.idFeature, + idTask = Proc.idTask, + idCut = Proc.idCut, + nFlag = Proc.nFlg, + nRotation = nCurrRotation, + ChosenStrategy = BeamLib.TableCopyDeep( Proc.ChosenStrategy), + AvailableStrategies = BeamLib.TableCopyDeep( Proc.AvailableStrategies) + } else -- se non esiste una strategia scelta (non dovrebbe mai succedere) cancello da lista generale PROCESSINGS[Proc.nIndexPartInParts].Rotation[Proc.nIndexRotation][Proc.nIndexInVProc].ChosenStrategy = nil @@ -1637,7 +1650,7 @@ function BeamExec.ProcessMachinings( PARTS) end end - return ( nTotErr == 0), Stats + return ( nTotErr == 0), RESULT end ------------------------------------------------------------------------------------------------------------- diff --git a/Strategies/Standard/STR0009/STR0009.lua b/Strategies/Standard/STR0009/STR0009.lua index b850940..bb09a69 100644 --- a/Strategies/Standard/STR0009/STR0009.lua +++ b/Strategies/Standard/STR0009/STR0009.lua @@ -17,6 +17,7 @@ local STR0009 = {} local Strategy = {} ------------------------------------------------------------------------------------------------------------- +-- TODO gestire il caso in cui non si trova l'utensile local function GetArcStrategy( Proc, Part) local Machining = {} local ToolSearchParameters = {}