diff --git a/BatchProcessNew.lua b/BatchProcessNew.lua index cd558cb..6462258 100644 --- a/BatchProcessNew.lua +++ b/BatchProcessNew.lua @@ -1,21 +1,6 @@ --- BatchProcess.lua by Egaltech s.r.l. 2020/06/12 +-- BatchProcess.lua by Egaltech s.r.l. 2021/01/07 -- Gestione calcolo batch disposizione e lavorazioni per Travi --- 2019/07/11 Aggiunta gestione stato rotazione di feature per TS3. --- 2019/07/16 Aggiunta gestione modalità oltre 10 per impostazione macchina e uscita. --- 2019/07/19 Aggiunta gestione collisioni. --- 2019/07/24 Aggiunta gestione extra-corse. --- 2019/08/29 Aggiunta possibilità di processare file NGE. --- 2019/10/04 Migliorato log dei parametri ricevuti. --- 2019/10/07 Aggiunta gestione Flag 4 = Check+Generate. --- 2019/10/09 In ImportBtl aggiunto flag per usare UserAttr. --- 2019/12/09 Gestione conservazione modifiche su barre. --- 2019/12/20 Gestione LOAD90 tramite file ausiliario (btm). --- 2019/12/28 Tolta uscita in caso di errore su features. --- 2020/01/08 Aggiunta seconda sezione limite (BD.MAX_WIDTH2 x BD.MAX_HEIGHT2). --- 2020/01/14 Si carica ultimo gruppo di lavoro. Corretto problema con nome non definito in segnalazione errore in generazione o stima. --- 2020/01/30 File Diff con nome del btl. --- 2020/02/12 Migliorie nella gestione degli errori. --- 2020/06/12 Si esegue sempre Processing se parametri macchina TS3 successivi al btl. +-- 2021/01/07 Per nuova interfaccia Egt. -- Intestazioni require( 'EgtBase') @@ -25,7 +10,7 @@ EgtEnableDebug( false) -- Per test --BEAM = {} --BEAM.FILE = 'c:\\EgtData\\Varie\\TestEssetreFast\\TestFilippo\\BTL\\Bar_20_1.btl' ---BEAM.MACHINE = 'FAST' +--BEAM.MACHINE = 'Essetre-FAST' --BEAM.FLAG = 3 -- Log dati in input @@ -40,10 +25,8 @@ elseif BEAM.FLAG == 3 then sFlag = 'CHECK' elseif BEAM.FLAG == 4 then sFlag = 'CHECK+GENERATE' -elseif BEAM.FLAG == 11 then - sFlag = 'TOOLS' -elseif BEAM.FLAG == 12 then - sFlag = 'JOBS' +elseif BEAM.FLAG == 5 then + sFlag = 'CREATE_BAR' else sFlag = 'FLAG='..tostring( BEAM.FLAG) end @@ -54,17 +37,6 @@ EgtOutLog( sLog) local sLogFile = EgtChangePathExtension( BEAM.FILE, '.txt') EgtEraseFile( sLogFile) -local function WriteErr( nErr, sMsg, nRot, nCutId, nTaskId) - if nTaskId > 0 then - EgtSetInfo(nTaskId, "nErr", nErr) - EgtSetInfo(nTaskId, "sMsg", sMsg) - EgtSetInfo(nTaskId, "nRot", nRot) - elseif nCutId > 0 then - EgtSetInfo(nCutId, "nErr", nErr) - EgtSetInfo(nCutId, "sMsg", sMsg) - end -end - -- Funzioni per scrittura su file di log specifico local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) local hFile = io.open( sLogFile, 'a') @@ -74,7 +46,6 @@ local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) hFile:write( 'CUTID=' .. tostring( nCutId or 0) .. '\n') hFile:write( 'TASKID=' .. tostring( nTaskId or 0) .. '\n') hFile:close() - WriteErr( nErr, sMsg, nRot, nCutId, nTaskId) end local function WriteTimeToLogFile( dTime) @@ -118,15 +89,17 @@ end local sBaseDir = EgtGetSourceDir() EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua') --- Impostazione della macchina corrente -EgtResetCurrMachGroup() -local sMachine = 'Essetre-' .. BEAM.MACHINE -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 +-- Se necessario, impostazione della macchina corrente +if BEAM.FLAG ~= 5 then + EgtResetCurrMachGroup() + local sMachine = BEAM.MACHINE + 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 @@ -143,12 +116,6 @@ end EgtRemoveBaseMachineDirFromPackagePath() EgtAddToPackagePath( sMachDir .. '\\Beam\\?.lua') --- Se modalità visualizzazione finestre per DB esco -if BEAM.FLAG > 10 then - BEAM.ERR = 0 - return -end - -- Carico le librerie _G.package.loaded.BeamExec = nil local BE = require( 'BeamExec') @@ -175,7 +142,7 @@ if bBtl and string.find( sTitle, 'Bar_', 1, true) and EgtExistsFile( sNgeFile) t -- se BTL corrente coincide con originale, salto il riprocessamento if nDiff == 0 then bToProcess = false - -- se cambiata configurazione macchina da ultima elaborazione, devo riprocessare + -- 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 then bToRecalc = true @@ -190,23 +157,15 @@ local nWarnCnt = 0 -- Se da elaborare if bToProcess then EgtOutLog( ' +++ Processing Parts >>>') - -- Se Btl, lo importo - if bBtl then - -- cancello eventuale vecchio progetto omonimo - EgtEraseFile( sNgeFile) - -- eseguo import - EgtNewFile() - if not EgtImportBtl( BEAM.FILE, EIB_FL.TS3_POS + EIB_FL.USEUATTR) then - BEAM.ERR = 13 - BEAM.MSG = 'Error importing BTL file : ' .. BEAM.FILE - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) - return - end - -- faccio copia del file btl originale - EgtCopyFile( BEAM.FILE, sDir..sTitle..'.ori'..sExt) - -- altrimenti Bwe, lo apro - else + + -- Flag di barra da creare + local bCreateBar + -- Lunghezza della barra ed elenco travi + local dBarLen + local vBeam = {} + + -- Se necessario, apro il file Bwe + if BEAM.FLAG ~= 5 then if not EgtOpenFile( BEAM.FILE) then BEAM.ERR = 13 BEAM.MSG = 'Error opening BWE file : ' .. BEAM.FILE @@ -214,145 +173,212 @@ if bToProcess then PostErrView( BEAM.ERR, BEAM.MSG) return end - -- faccio copia del file originale + -- Faccio copia del file originale EgtCopyFile( BEAM.FILE, sDir..sTitle..'.ori'..sExt) - end - -- Aggiorno eventuali dati ausiliari - UpdateAuxData( sBtmFile) + -- Aggiorno eventuali dati ausiliari + UpdateAuxData( sBtmFile) - -- Recupero l'elenco ordinato delle travi - local vBeam = {} - local nPartId = EgtGetFirstPart() - while nPartId do - table.insert( vBeam, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) - nPartId = EgtGetNextPart( nPartId) - end - if #vBeam == 0 then - BEAM.ERR = 14 - BEAM.MSG = 'Error no beams in the file : ' .. BEAM.FILE - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) - return - else - local sOut = '' - for i = 1, #vBeam do - sOut = sOut .. vBeam[i].Name .. ', ' + -- Se già presente un gruppo di lavoro + if EgtGetFirstMachGroup() then + -- Barra già presente + bCreateBar = false + -- Rendo corrente il gruppo di lavoro + EgtSetCurrMachGroup() + -- Area tavola + local b3Tab = EgtGetTableArea() + -- Calcolo posizione estremo TR della tavola rispetto a sua origine in BL + BD.OriTR = Point3d( b3Tab:getDimX(), b3Tab:getDimY(), 0) + -- Calcolo minimo grezzo scaricabile + local nRawId = EgtGetFirstRawPart() + if not nRawId then + BEAM.ERR = 14 + BEAM.MSG = 'Error no Raw Oarts in the file : ' .. BEAM.FILE + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end + local b3Raw = EgtGetRawPartBBox( nRawId) + BE.CalcMinUnloadableRaw( b3Raw:getDimY(), b3Raw:getDimZ()) + -- altrimenti devo recuperare i pezzi per creare la barra + else + -- Barra da creare + bCreateBar = true + -- Recupero l'elenco ordinato delle travi + local nPartId = EgtGetFirstPart() + while nPartId do + table.insert( vBeam, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) + nPartId = EgtGetNextPart( nPartId) + end + if #vBeam == 0 then + BEAM.ERR = 14 + BEAM.MSG = 'Error no beams in the file : ' .. BEAM.FILE + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + else + local sOut = '' + for i = 1, #vBeam do + sOut = sOut .. vBeam[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') + 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 + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + else + vBeam[i].Box = b3Solid + end + end + -- Assegno lunghezza della barra + dBarLen = vBeam[1].Box:getDimX() + 10 + if dBarLen < 1500 then + dBarLen = 2000 + end + -- Assegno posizione prima ed unica trave + vBeam[1].PosX = 10 + end + + -- Altrimenti, opero sul progetto corrente + else + -- Recupero l'identificativo del gruppo di lavoro corrente + local nMGrpId = EgtGetCurrMachGroup() + -- Barra da creare + bCreateBar = true + -- Lunghezza della barra + dBarLen = EgtGetInfo( nMGrpId, 'BARLEN') + -- Recupero l'elenco ordinato delle travi da inserire nella barra + for i = 1, 100 do + local sKey = 'PART'..tostring( i) + local sVal = EgtGetInfo( nMGrpId, sKey) + local vVal = EgtSplitString( sVal or '') + 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)))}) + end + if #vBeam == 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 .. ', ' + 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') + 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 + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + return + else + vBeam[i].Box = b3Solid + end 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') - 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 + + -- Se devo creare la barra + if bCreateBar then + -- Ne verifico le dimensioni + local dRawW = vBeam[1].Box:getDimY() + local dRawH = vBeam[1].Box:getDimZ() + local vBeamErr = {} + for i = 2, #vBeam do + local dDimW = vBeam[i].Box:getDimY() + local dDimH = vBeam[i].Box:getDimZ() + if ( abs( dDimW - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimH - dRawH) > 10 * GEO.EPS_SMALL) and + ( abs( dDimH - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimW - dRawH) > 10 * GEO.EPS_SMALL) then + table.insert( vBeamErr, i) + end + end + 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]) + end + BEAM.ERR = 16 + BEAM.MSG = sOut WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return - else - vBeam[i].Box = b3Solid end - end - - -- Ne recupero la posizione - for i = 1, #vBeam do - local PosX = EgtGetInfo( vBeam[i].Id, 'POSX', 'd') - vBeam[i].PosX = PosX - end - - -- Eseguo eventuali rotazioni e inversioni testa-coda - for i = 1, #vBeam do - local b3Solid = vBeam[i].Box - -- rotazione --- local dRotAng = EgtGetInfo( vBeam[i].Id, 'ROTATED', 'd') --- if dRotAng and abs( dRotAng) > GEO.EPS_ANG_SMALL then --- local ptRotCen = b3Solid:getCenter() --- EgtRotate( vBeam[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB) --- b3Solid:rotate( ptRotCen, X_AX(), dRotAng) --- end - -- inversione - local dInvAng = 180 - ( EgtGetInfo( vBeam[i].Id, 'INVERTED', 'd') or 0) - if abs( dInvAng) > GEO.EPS_ANG_SMALL then - local ptInvCen = b3Solid:getCenter() - EgtRotate( vBeam[i].Id, ptInvCen, Z_AX(), dInvAng, GDB_RT.GLOB) + + -- Verifico sezione barra non troppo grande + if ( dRawW > BD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT + 10 * GEO.EPS_SMALL) and + ( dRawW > BD.MAX_WIDTH2 + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT2 + 10 * GEO.EPS_SMALL) then + local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. + c 'oltre i limiti della macchina (' .. EgtNumToString( BD.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BD.MAX_HEIGHT, 2) .. ') ' .. + c 'e (' .. EgtNumToString( BD.MAX_WIDTH2, 2) .. ' x ' .. EgtNumToString( BD.MAX_HEIGHT2, 2) .. ')' + BEAM.ERR = 17 + BEAM.MSG = sOut + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return end - end - - -- Ne verifico le dimensioni - local dRawW = vBeam[1].Box:getDimY() - local dRawH = vBeam[1].Box:getDimZ() - local vBeamErr = {} - for i = 2, #vBeam do - local dDimW = vBeam[i].Box:getDimY() - local dDimH = vBeam[i].Box:getDimZ() - if ( abs( dDimW - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimH - dRawH) > 10 * GEO.EPS_SMALL) and - ( abs( dDimH - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimW - dRawH) > 10 * GEO.EPS_SMALL) then - table.insert( vBeamErr, i) - end - end - 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]) - end - BEAM.ERR = 16 - BEAM.MSG = sOut - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) - return - end - - -- Verifico sezione barra non troppo grande - if ( dRawW > BD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT + 10 * GEO.EPS_SMALL) and - ( dRawW > BD.MAX_WIDTH2 + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT2 + 10 * GEO.EPS_SMALL) then - local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. - 'oltre i limiti della macchina (' .. EgtNumToString( BD.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BD.MAX_HEIGHT, 2) .. ') ' .. - 'e (' .. EgtNumToString( BD.MAX_WIDTH2, 2) .. ' x ' .. EgtNumToString( BD.MAX_HEIGHT2, 2) .. ')' - BEAM.ERR = 17 - BEAM.MSG = sOut - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) - return - end - + -- Verifico sezione barra non troppo piccola - if dRawW < BD.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < BD.MIN_HEIGHT - 10 * GEO.EPS_SMALL then - local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. - 'sotto i limiti della macchina (' .. EgtNumToString( BD.MIN_WIDTH, 2) .. ' x ' .. EgtNumToString( BD.MIN_HEIGHT, 2) .. ')' - BEAM.ERR = 17 - BEAM.MSG = sOut - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) + if dRawW < BD.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < BD.MIN_HEIGHT - 10 * GEO.EPS_SMALL then + local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. + c 'sotto i limiti della macchina (' .. EgtNumToString( BD.MIN_WIDTH, 2) .. ' x ' .. EgtNumToString( BD.MIN_HEIGHT, 2) .. ')' + BEAM.ERR = 17 + BEAM.MSG = sOut + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end + + -- Lunghezza della barra + local dRawL = dBarLen + 0.1 + -- Sovramateriale di testa + local dOvmHead = vBeam[1].PosX or 0 + + -- Sistemo le travi nel grezzo + local bPbOk, sPbErr = BE.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, vBeam, BEAM.FLAG == 5) + if not bPbOk then + BEAM.ERR = 18 + BEAM.MSG = sPbErr + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end + end + + -- Se richiesta solo barra, esco + if BEAM.FLAG == 5 then + -- Completamento senza errori e avvisi + if nWarnCnt == 0 then + BEAM.ERR = 0 + BEAM.MSG = '---' + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + end + EgtOutLog( ' +++ BatchProcess completed') return end - - -- Lunghezza della barra - local dRawL = ( EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL, 'BARLEN', 'd') or 12000) + 0.1 - -- Sovramateriale di testa - local dOvmHead = vBeam[1].PosX or 0 - - -- Sistemo le travi nel grezzo - local bPbOk, sPbErr = BE.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, vBeam) - if not bPbOk then - BEAM.ERR = 18 - BEAM.MSG = sPbErr - WriteErrToLogFile( BEAM.ERR, BEAM.MSG) - PostErrView( BEAM.ERR, BEAM.MSG) - return - end - + -- Imposto Nome file CN local _, sName, _ = EgtSplitPath( BEAM.FILE) EgtSetInfo( EgtGetCurrMachGroup(), 'NcName', sName .. '.cnc') - + -- Abilito Vmill EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1') - + -- Lavoro le features local bPfOk, Stats = BE.ProcessFeatures() local sOutput = '' diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index e7ffc16..b6f27e3 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -119,17 +119,19 @@ EgtMdbSave() ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle travi nel grezzo *** ------------------------------------------------------------------------------------------------------------- -function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, vBeam) +function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, vBeam, bMachGroupOk) -- Determinazione minimo grezzo scaricabile BeamExec.CalcMinUnloadableRaw( dRawW, dRawH) -- Creazione nuovo gruppo di lavoro - local sMgName = EgtGetMachGroupNewName( 'Mach_1') - local NewMgId = EgtAddMachGroup( sMgName) - if not NewMgId then - local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName - return false, sOut + if not bMachGroupOk then + local sMgName = EgtGetMachGroupNewName( 'Mach_1') + local NewMgId = EgtAddMachGroup( sMgName) + if not NewMgId then + local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName + return false, sOut + end end -- Impostazione della tavola