7e3c951901
- aggiunta gestione extracorse in simulazione cieca - aggiunta configurazione per lista lavorazioni - migliorata gestione lughezza minima barre in Process - migliorie varie.
345 lines
11 KiB
Lua
345 lines
11 KiB
Lua
-- BatchProcess.lua by Egaltech s.r.l. 2019/07/24
|
|
-- 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.
|
|
|
|
-- Intestazioni
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( false)
|
|
|
|
-- Flag abilitazione controllo collisione
|
|
local bVerifyCollision = true
|
|
|
|
-- Log dati di generazione
|
|
local sLog = 'BatchProcess : ' .. BEAM.FILE .. ', ' .. BEAM.MACHINE .. ', ' .. tostring( BEAM.FLAG)
|
|
EgtOutLog( sLog)
|
|
|
|
-- Cancello file di log specifico
|
|
local sLogFile = EgtChangePathExtension( BEAM.FILE, '.txt')
|
|
EgtEraseFile( sLogFile)
|
|
|
|
-- Funzioni per scrittura su file di log specifico
|
|
local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId)
|
|
local hFile = io.open( sLogFile, 'a')
|
|
hFile:write( 'ERR=' .. tostring( nErr) .. '\n')
|
|
hFile:write( sMsg .. '\n')
|
|
hFile:write( 'ROT=' .. tostring( nRot or 0) .. '\n')
|
|
hFile:write( 'CUTID=' .. tostring( nCutId or 0) .. '\n')
|
|
hFile:write( 'TASKID=' .. tostring( nTaskId or 0) .. '\n')
|
|
hFile:close()
|
|
end
|
|
local function WriteTimeToLogFile( dTime)
|
|
local hFile = io.open( sLogFile, 'a')
|
|
hFile:write( 'TIME=' .. EgtNumToString( dTime) .. '\n')
|
|
hFile:close()
|
|
end
|
|
|
|
-- Funzione per gestire visualizzazione dopo errore
|
|
local function PostErrView( nErr, sMsg)
|
|
if nErr ~= 0 and ( BEAM.FLAG == 1 or BEAM.FLAG == 2) then
|
|
EgtSetView( SCE_VD.ISO_SW, false)
|
|
EgtZoom( SCE_ZM.ALL)
|
|
EgtOutBox( sMsg .. ' (error ' .. tostring( nErr) .. ')', 'BatchProcess', 'ERRORS')
|
|
end
|
|
end
|
|
|
|
-- Funzione per gestire visualizzazione dopo errore
|
|
local function PostWarnView( nWarn, sMsg)
|
|
if nWarn ~= 0 and ( BEAM.FLAG == 1 or BEAM.FLAG == 2) then
|
|
EgtSetView( SCE_VD.ISO_SW, false)
|
|
EgtZoom( SCE_ZM.ALL)
|
|
EgtOutBox( sMsg .. ' (warning ' .. tostring( nWarn) .. ')', 'BatchProcess', 'WARNINGS')
|
|
end
|
|
end
|
|
|
|
-- Imposto direttorio libreria specializzata per Travi
|
|
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
|
|
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
|
|
|
|
-- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie
|
|
EgtRemoveBaseMachineDirFromPackagePath()
|
|
EgtAddToPackagePath( sMachDir .. '\\Beam\\?.lua')
|
|
|
|
-- Se modalità visualizzazione finestre per DB esco
|
|
if BEAM.FLAG > 10 then
|
|
BEAM.ERR = 0
|
|
return
|
|
end
|
|
|
|
-- Segnalazione avvio
|
|
EgtOutLog( '*** Beam BatchProcess Start ***', 1)
|
|
|
|
-- Carico le librerie
|
|
_G.package.loaded.BeamExec = nil
|
|
local BE = require( 'BeamExec')
|
|
local BL = require( 'BeamLib')
|
|
|
|
-- Carico i dati globali
|
|
local BD = require( 'BeamData')
|
|
|
|
-- Importo il file Btl
|
|
EgtNewFile()
|
|
if not EgtImportBtl( BEAM.FILE, EIB_FL.TS3_POS) then
|
|
BEAM.ERR = 13
|
|
BEAM.MSG = 'Error importing BTL file : ' .. BEAM.FILE
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG)
|
|
PostErrView( BEAM.ERR, BEAM.MSG)
|
|
return
|
|
end
|
|
|
|
-- 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 .. ', '
|
|
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
|
|
|
|
-- 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)
|
|
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
|
|
if dRawW > BD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT + 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) .. ')'
|
|
BEAM.ERR = 17
|
|
BEAM.MSG = sOut
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG)
|
|
PostErrView( BEAM.ERR, BEAM.MSG)
|
|
return
|
|
end
|
|
|
|
-- Lunghezza della barra
|
|
local dRawL = EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo'), 'BARLEN', 'd') or 12000
|
|
-- Sovramateriale di testa
|
|
local dOvmHead = EgtGetInfo( EgtGetFirstPart(), 'POSX', 'd') or 10
|
|
|
|
-- 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 nErrCnt = 0
|
|
local nWarnCnt = 0
|
|
local sOutput = ''
|
|
for i = 1, #Stats do
|
|
if Stats[i].Err == 0 then
|
|
sOutput = sOutput .. string.format( 'Cut=%d Tsk=%d Ok\n', Stats[i].CutId, Stats[i].TaskId)
|
|
BEAM.ERR = 0
|
|
BEAM.MSG = '---'
|
|
BEAM.ROT = Stats[i].Rot or 0
|
|
BEAM.CUTID = Stats[i].CutId
|
|
BEAM.TASKID = Stats[i].TaskId
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID)
|
|
elseif Stats[i].Err > 0 then
|
|
nErrCnt = nErrCnt + 1
|
|
sOutput = sOutput .. string.format( 'Cut=%d Tsk=%d %s\n', Stats[i].CutId, Stats[i].TaskId, Stats[i].Msg)
|
|
BEAM.ERR = 19
|
|
BEAM.MSG = Stats[i].Msg
|
|
BEAM.ROT = Stats[i].Rot or 0
|
|
BEAM.CUTID = Stats[i].CutId
|
|
BEAM.TASKID = Stats[i].TaskId
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID)
|
|
elseif Stats[i].Err < 0 then
|
|
nWarnCnt = nWarnCnt + 1
|
|
sOutput = sOutput .. string.format( 'Cut=%d Tsk=%d %s\n', Stats[i].CutId, Stats[i].TaskId, Stats[i].Msg)
|
|
BEAM.ERR = -19
|
|
BEAM.MSG = Stats[i].Msg
|
|
BEAM.ROT = Stats[i].Rot or 0
|
|
BEAM.CUTID = Stats[i].CutId
|
|
BEAM.TASKID = Stats[i].TaskId
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID)
|
|
end
|
|
end
|
|
if #sOutput > 0 then EgtOutLog( sOutput) end
|
|
if nErrCnt > 0 then
|
|
PostErrView( 19, sOutput)
|
|
return
|
|
elseif nWarnCnt > 0 then
|
|
PostWarnView( 19, sOutput)
|
|
end
|
|
|
|
-- Salvo il progetto
|
|
local sNgeFile = EgtChangePathExtension( BEAM.FILE, '.nge')
|
|
EgtSaveFile( sNgeFile)
|
|
|
|
-- Genero programma CN, se richiesto
|
|
if BEAM.FLAG == 0 then
|
|
if not EgtGenerate( '', 'EgtCAM5 - ' .. sNgeFile) then
|
|
BEAM.ERR = 20
|
|
BEAM.MSG = 'Error generating NC part program : ' .. sName
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG)
|
|
PostErrView( BEAM.ERR, BEAM.MSG)
|
|
return
|
|
end
|
|
end
|
|
|
|
-- Eseguo stima tempi
|
|
if not EgtEstimate( '', 'EgtCAM5 - ' .. sNgeFile) then
|
|
BEAM.ERR = 21
|
|
BEAM.MSG = 'Error estimating production time : ' .. sName
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG)
|
|
PostErrView( BEAM.ERR, BEAM.MSG)
|
|
return
|
|
end
|
|
local Ttot = EgtGetInfo( EgtGetCurrMachGroup(), 'Ttot')
|
|
local sTime = 'Total Time = ' .. EgtNumToString( Ttot, 1)
|
|
EgtOutLog( sTime)
|
|
|
|
-- Se verifica, eseguo simulazione in cieco
|
|
if BEAM.FLAG == 3 and bVerifyCollision then
|
|
local bSimOk, nErr, sErr = EgtSimulate()
|
|
if not bSimOk then
|
|
BEAM.ERR = 22
|
|
if nErr == MCH_SHE.OUTSTROKE then
|
|
BEAM.MSG = 'Axis outstroke ' .. sErr
|
|
elseif nErr == MCH_SHE.COLLISION then
|
|
BEAM.MSG = 'Head-part collision'
|
|
else
|
|
BEAM.MSG = 'General failure (contact supplier)'
|
|
end
|
|
BEAM.ROT = 0
|
|
BEAM.CUTID = 0
|
|
BEAM.TASKID = 0
|
|
local vItem = EgtSplitString( sErr, ';') or {}
|
|
for i = 1, #vItem do
|
|
vItem[i] = EgtTrim( vItem[i] or '')
|
|
if string.find( vItem[i], 'CUTID', 1, true) then
|
|
BEAM.CUTID = EgtGetVal( vItem[i], 'CUTID', 'i') or 0
|
|
elseif string.find( vItem[i], 'TASKID', 1, true) then
|
|
BEAM.TASKID = EgtGetVal( vItem[i], 'TASKID', 'i') or 0
|
|
end
|
|
end
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID)
|
|
return
|
|
end
|
|
end
|
|
|
|
-- Imposto la vista ISO 3d, se richiesto
|
|
if BEAM.FLAG == 1 or BEAM.FLAG == 2 then
|
|
EgtSetView( SCE_VD.ISO_SW, false)
|
|
end
|
|
|
|
-- Completamento senza errori e avvisi
|
|
if nWarnCnt == 0 then
|
|
BEAM.ERR = 0
|
|
BEAM.MSG = '---'
|
|
WriteErrToLogFile( BEAM.ERR, BEAM.MSG)
|
|
end
|
|
|
|
-- Scrittura tempo totale stimato di lavorazione
|
|
WriteTimeToLogFile( Ttot)
|