From 64c800ab3efc3d5eba82f43cbbb930341ca61e47 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Thu, 24 Apr 2025 18:13:39 +0200 Subject: [PATCH] - in BatchProcessNew refactoring e rinominate alcune variabili per essere coerenti con Process - in BeamExec aggiunta bCreateMachGroup per gestire caso creazione barra in BatchProcessNew - da testare e ultimare!! --- BatchProcessNew.lua | 104 +++++++++++++++++++++---------------------- LuaLibs/BeamExec.lua | 20 +++++---- 2 files changed, 63 insertions(+), 61 deletions(-) diff --git a/BatchProcessNew.lua b/BatchProcessNew.lua index 170921b..e09efbc 100644 --- a/BatchProcessNew.lua +++ b/BatchProcessNew.lua @@ -8,6 +8,8 @@ EgtEnableDebug( false) -- 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') -- Carico le librerie _G.package.loaded.BeamExec = nil @@ -17,12 +19,6 @@ local BeamLib = require( 'BeamLib') -- Carico i dati globali local BeamData = require( 'BeamData') --- Dati del file -local sDir, sTitle = EgtSplitPath( BEAM.FILE) -local sOriFile = sDir..sTitle..'.ori.bwe' -local sNgeFile = sDir..sTitle..'.bwe' -local sTxtLogFile = EgtChangePathExtension( BEAM.FILE, '.txt') - ------------------------------------------------------------------------------------------------------------- -- Funzioni per scrittura su file di log specifico local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) @@ -68,15 +64,14 @@ local function PostWarnView( nWarn, sMsg) end -- Funzione di reset gruppo di lavoro in caso di impossibilità di inserire i pezzi -local function ResetMachGroup( vBeam) - for i = 1, #vBeam do - EgtErase( vBeam[i].Id) +local function ResetMachGroup( PARTS) + for i = 1, #PARTS do + EgtErase( PARTS[i].Id) end EgtRemoveMachGroup( EgtGetCurrMachGroup() or GDB_ID.NULL) end ------------------------------------------------------------------------------------------------------------- --- Log dati in input local sFlag = '' if BEAM.FLAG == 0 then sFlag = 'GENERATE' @@ -96,7 +91,15 @@ end local sLog = 'BatchProcess : ' .. BEAM.FILE .. ', ' .. BEAM.MACHINE .. ', ' .. sFlag EgtOutLog( sLog) +-- Dati dei file +local sDir, sTitle = EgtSplitPath( BEAM.FILE) +local sOriFile = sDir..sTitle..'.ori.bwe' +local sNgeFile = sDir..sTitle..'.bwe' +local sTxtLogFile = EgtChangePathExtension( BEAM.FILE, '.txt') + +-- cancellazione file log txt precedente -- in caso sia richiesta generazione senza check, verifico prima che il file log specifico non contenga errori: se sì, forzo il check +-- TODO serve ancora?? forzare sempre il check e simulazione? if BEAM.FLAG == 0 then local hLogFile = io.open( sTxtLogFile, 'r') if hLogFile then @@ -109,15 +112,12 @@ if BEAM.FLAG == 0 then hLogFile:close() end end - -- Cancello file di log specifico EgtEraseFile( sTxtLogFile) --- Imposto direttorio libreria specializzata per Travi -EgtAddToPackagePath( BEAM.BASEDIR .. '\\LuaLibs\\?.lua') - --- Se necessario, impostazione della macchina corrente +-- impostazione della macchina corrente local sMachine = BEAM.MACHINE + if BEAM.FLAG ~= 6 then EgtResetCurrMachGroup() if not EgtSetCurrMachine( sMachine) then @@ -131,6 +131,7 @@ 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 @@ -145,7 +146,7 @@ local bToRecalc = false -- se BTL, barra ed esiste già il corrispondente progetto Nge if EgtExistsFile( sOriFile) then bToProcess = false - EgtCopyFile( sOriFile, sNgeFile) + EgtCopyFile( sOriFile, sNgeFile) -- se cambiata configurazione macchina da ultima elaborazione, devo aggiornare if EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\Beam\\TS3Data.lua') == -1 or EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\Tools\\Tools.data') == -1 or @@ -166,7 +167,7 @@ if bToProcess then local bCreateBar -- Lunghezza della barra ed elenco travi local dBarLen - local vBeam = {} + local PARTS = {} -- Se necessario, apro il file Bwe if BEAM.FLAG ~= 6 then @@ -180,9 +181,6 @@ if bToProcess then -- Faccio copia del file originale EgtCopyFile( BEAM.FILE, sOriFile) - -- Aggiorno eventuali dati ausiliari - --UpdateAuxData( sBtmFile) - -- Se già presente un gruppo di lavoro if EgtGetFirstMachGroup() then -- Barra già presente @@ -214,10 +212,10 @@ if bToProcess then -- Recupero l'elenco ordinato delle travi local nPartId = EgtGetFirstPart() while nPartId do - table.insert( vBeam, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) + table.insert( PARTS, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) nPartId = EgtGetNextPart( nPartId) end - if #vBeam == 0 then + if #PARTS == 0 then BEAM.ERR = 14 BEAM.MSG = 'Error no beams in the file : ' .. BEAM.FILE WriteErrToLogFile( BEAM.ERR, BEAM.MSG) @@ -225,33 +223,33 @@ if bToProcess then return else local sOut = '' - for i = 1, #vBeam do - sOut = sOut .. vBeam[i].Name .. ', ' + for i = 1, #PARTS do + sOut = sOut .. PARTS[i].Name .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi trovate : ' .. sOut, 1) end -- Ne recupero le dimensioni - for i = 1, #vBeam do - local Ls = EgtGetFirstNameInGroup( vBeam[i].Id, 'Box') + for i = 1, #PARTS do + 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 ' .. vBeam[i].Name + BEAM.MSG = 'Box undefined for beam ' .. PARTS[i].Name WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return else - vBeam[i].Box = b3Solid + PARTS[i].b3PartOriginal = b3Solid end end -- Assegno lunghezza della barra - dBarLen = vBeam[1].Box:getDimX() + 10 + dBarLen = PARTS[1].b3PartOriginal:getDimX() + 10 if dBarLen < 2200 then dBarLen = dBarLen + 1800 end -- Assegno posizione prima ed unica trave - vBeam[1].PosX = 10 + PARTS[1].PosX = 10 end -- Altrimenti, opero sul progetto corrente @@ -270,32 +268,32 @@ if bToProcess then if not vVal or #vVal < 2 then break end local nPartId = tonumber( vVal[1]) local dPosX = tonumber( vVal[2]) - table.insert( vBeam, { Id = nPartId, PosX = dPosX, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) + table.insert( PARTS, { Id = nPartId, PosX = dPosX, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) end - if #vBeam == 0 then + if #PARTS == 0 then BEAM.ERR = 14 BEAM.MSG = 'Error : no beams in the project' WriteErrToLogFile( BEAM.ERR, BEAM.MSG) return else local sOut = '' - for i = 1, #vBeam do - sOut = sOut .. vBeam[i].Name .. ', ' + for i = 1, #PARTS do + sOut = sOut .. PARTS[i].Name .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi trovate : ' .. sOut, 1) end -- Ne recupero le dimensioni - for i = 1, #vBeam do - local Ls = EgtGetFirstNameInGroup( vBeam[i].Id, 'Box') + for i = 1, #PARTS do + 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 ' .. vBeam[i].Name + BEAM.MSG = 'Box undefined for beam ' .. PARTS[i].Name WriteErrToLogFile( BEAM.ERR, BEAM.MSG) return else - vBeam[i].Box = b3Solid + PARTS[i].b3PartOriginal = b3Solid end end end @@ -304,7 +302,7 @@ if bToProcess then if bCreateBar then local dRawW local dRawH - if #vBeam == 0 then + if #PARTS == 0 then -- Recupero l'identificativo del gruppo di lavoro corrente local nMGrpId = EgtGetCurrMachGroup() -- Recupero le dimensioni della barra @@ -312,13 +310,13 @@ if bToProcess then dRawH = EgtGetInfo(nMGrpId, 'BARHEIGHT', 'd') else -- Ne verifico le dimensioni - dRawW = vBeam[1].Box:getDimY() - dRawH = vBeam[1].Box:getDimZ() + dRawW = PARTS[1].b3PartOriginal:getDimY() + dRawH = PARTS[1].b3PartOriginal:getDimZ() end local vBeamErr = {} - for i = 2, #vBeam do - local dDimW = vBeam[i].Box:getDimY() - local dDimH = vBeam[i].Box:getDimZ() + for i = 2, #PARTS do + local dDimW = PARTS[i].b3PartOriginal:getDimY() + local dDimH = PARTS[i].b3PartOriginal:getDimZ() if ( abs( dDimW - dRawW) > 100 * GEO.EPS_SMALL or abs( dDimH - dRawH) > 100 * GEO.EPS_SMALL) and ( abs( dDimH - dRawW) > 100 * GEO.EPS_SMALL or abs( dDimW - dRawH) > 100 * GEO.EPS_SMALL) then table.insert( vBeamErr, i) @@ -327,10 +325,10 @@ 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 .. vBeam[vBeamErr[i]].Name .. '\n' - table.remove( vBeam, vBeamErr[i]) + sOut = sOut .. PARTS[vBeamErr[i]].Name .. '\n' + table.remove( PARTS, vBeamErr[i]) end - ResetMachGroup( vBeam) + ResetMachGroup( PARTS) BEAM.ERR = 16 BEAM.MSG = sOut WriteErrToLogFile( BEAM.ERR, BEAM.MSG) @@ -341,7 +339,7 @@ if bToProcess then -- Verifico sezione barra non troppo grande if not BeamData.MAX_WIDTH2 or not BeamData.MAX_HEIGHT2 then if ( dRawW > BeamData.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BeamData.MAX_HEIGHT + 10 * GEO.EPS_SMALL) then - ResetMachGroup( vBeam) + ResetMachGroup( PARTS) local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'oltre i limiti della macchina (' .. EgtNumToString( BeamData.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BeamData.MAX_HEIGHT, 2) .. ') ' BEAM.ERR = 17 @@ -353,7 +351,7 @@ if bToProcess then else if ( dRawW > BeamData.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BeamData.MAX_HEIGHT + 10 * GEO.EPS_SMALL) and ( dRawW > BeamData.MAX_WIDTH2 + 10 * GEO.EPS_SMALL or dRawH > BeamData.MAX_HEIGHT2 + 10 * GEO.EPS_SMALL) then - ResetMachGroup( vBeam) + ResetMachGroup( PARTS) local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'oltre i limiti della macchina (' .. EgtNumToString( BeamData.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BeamData.MAX_HEIGHT, 2) .. ') ' .. 'e (' .. EgtNumToString( BeamData.MAX_WIDTH2, 2) .. ' x ' .. EgtNumToString( BeamData.MAX_HEIGHT2, 2) .. ')' @@ -367,7 +365,7 @@ if bToProcess then -- Verifico sezione barra non troppo piccola if dRawW < BeamData.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < BeamData.MIN_HEIGHT - 10 * GEO.EPS_SMALL then - ResetMachGroup( vBeam) + ResetMachGroup( PARTS) local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'sotto i limiti della macchina (' .. EgtNumToString( BeamData.MIN_WIDTH, 2) .. ' x ' .. EgtNumToString( BeamData.MIN_HEIGHT, 2) .. ')' BEAM.ERR = 17 @@ -381,12 +379,12 @@ if bToProcess then local dRawL = dBarLen + 0.1 -- Sovramateriale di testa local dOvmHead = 0 - if #vBeam > 0 then - dOvmHead = vBeam[1].PosX or 0 + if #PARTS > 0 then + dOvmHead = PARTS[1].PosX or 0 end -- Sistemo le travi nel grezzo - local bPbOk, sPbErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, nil, vBeam, BEAM.FLAG == 6) + local bPbOk, sPbErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, nil, PARTS, BEAM.FLAG ~= 6) if not bPbOk then BEAM.ERR = 18 BEAM.MSG = sPbErr diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index a76b480..4913fe9 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -349,8 +349,7 @@ end ------------------------------------------------------------------------------------------------------------- -- *** funzioni posizionamento pezzi all'interno della barra *** ------------------------------------------------------------------------------------------------------------- -function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS) - +function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS, bCreateMachGroup) -- default per nuove costanti qualora non definite BeamData.OVM_BLADE_HBEAM = ( BeamData.OVM_BLADE_HBEAM or 11) BeamData.OVM_CHAIN_HBEAM = ( BeamData.OVM_CHAIN_HBEAM or 8) @@ -361,12 +360,17 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS) -- Determinazione minimo grezzo scaricabile BeamExec.CalcMinUnloadableRaw( dRawW, dRawH) - -- Creazione nuovo gruppo di lavoro - local sMgName = EgtGetMachGroupNewName( 'Mach_1') - local idNewMg = EgtAddMachGroup( sMgName) - if not idNewMg then - local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName - return false, sOut + -- Creazione nuovo gruppo di lavoro (di default va creato) + if bCreateMachGroup == nil then + bCreateMachGroup = true + end + if bCreateMachGroup then + local sMgName = EgtGetMachGroupNewName( 'Mach_1') + local idNewMg = EgtAddMachGroup( sMgName) + if not idNewMg then + local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName + return false, sOut + end end -- Impostazione della tavola