ce75804923
- migliorata segnalazione errore avvio simulazione - migliorata gestione contorno libero con una sola faccia - in ottimizzazione lavorazioni non si abilitano più le lavorazioni disabilitate (perchè errate).
618 lines
22 KiB
Lua
618 lines
22 KiB
Lua
-- BatchProcess.lua by Egaltech s.r.l. 2021/05/16
|
|
-- Gestione calcolo batch disposizione e lavorazioni per Pareti
|
|
-- 2021/01/15 Per nuova interfaccia Egt.
|
|
|
|
|
|
-- Intestazioni
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( false)
|
|
|
|
-- Per test
|
|
--WALL = {}
|
|
--WALL.FILE = 'c:\\TechnoEssetre7\\EgtData\\Prods\\0010\\Bar_10_1.btl'
|
|
--WALL.MACHINE = 'Essetre-90480019_MW'
|
|
--WALL.FLAG = 3
|
|
|
|
-- Log dati in input
|
|
local sFlag = ''
|
|
if WALL.FLAG == 0 then
|
|
sFlag = 'GENERATE'
|
|
elseif WALL.FLAG == 1 then
|
|
sFlag = 'MODIFY'
|
|
elseif WALL.FLAG == 2 then
|
|
sFlag = 'SIMULATE'
|
|
elseif WALL.FLAG == 3 then
|
|
sFlag = 'CHECK'
|
|
elseif WALL.FLAG == 4 then
|
|
sFlag = 'CHECK+GENERATE'
|
|
elseif WALL.FLAG == 5 then
|
|
sFlag = 'CLOUD'
|
|
elseif WALL.FLAG == 6 then
|
|
sFlag = 'CREATE_PANEL'
|
|
else
|
|
sFlag = 'FLAG='..tostring( WALL.FLAG)
|
|
end
|
|
local sLog = 'BatchProcess : ' .. WALL.FILE .. ', ' .. WALL.MACHINE .. ', ' .. sFlag
|
|
EgtOutLog( sLog)
|
|
|
|
-- Cancello file di log specifico
|
|
local sLogFile = EgtChangePathExtension( WALL.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 ( WALL.FLAG == 1 or WALL.FLAG == 2 or WALL.FLAG == 5) then
|
|
EgtSetView( SCE_VD.ISO_SW, false)
|
|
EgtZoom( SCE_ZM.ALL)
|
|
EgtOutBox( sMsg, 'BatchProcess (err=' .. tostring( nErr) .. ')', 'ERRORS')
|
|
end
|
|
end
|
|
|
|
-- Funzione per gestire visualizzazione dopo warning
|
|
local function PostWarnView( nWarn, sMsg)
|
|
if nWarn ~= 0 and ( WALL.FLAG == 1 or WALL.FLAG == 2 or WALL.FLAG == 5) then
|
|
EgtSetView( SCE_VD.ISO_SW, false)
|
|
EgtZoom( SCE_ZM.ALL)
|
|
EgtOutBox( sMsg, 'BatchProcess (wrn=' .. tostring( nWarn) .. ')', 'WARNINGS')
|
|
end
|
|
end
|
|
|
|
-- Funzione per aggiornare dati ausiliari
|
|
local function UpdateAuxData( sAuxFile)
|
|
local bModif = false
|
|
-- Se definito LOAD90, aggiorno
|
|
local sLoad90 = EgtGetStringFromIni( 'AuxData', 'LOAD90', '', sAuxFile)
|
|
if sLoad90 ~= '' then
|
|
local BtlInfoId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL
|
|
EgtSetInfo( BtlInfoId, 'LOAD90', sLoad90)
|
|
bModif = true
|
|
end
|
|
return bModif
|
|
end
|
|
|
|
-- Imposto direttorio libreria specializzata per Travi
|
|
local sBaseDir = EgtGetSourceDir()
|
|
EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua')
|
|
|
|
-- Se necessario, impostazione della macchina corrente
|
|
if WALL.FLAG ~= 6 then
|
|
EgtResetCurrMachGroup()
|
|
local sMachine = WALL.MACHINE
|
|
if not EgtSetCurrMachine( sMachine) then
|
|
WALL.ERR = 11
|
|
WALL.MSG = 'Error selecting machine : ' .. sMachine
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
end
|
|
|
|
-- Verifico che la macchina corrente sia abilitata per la lavorazione delle Pareti
|
|
local sMachDir = EgtGetCurrMachineDir()
|
|
if not EgtExistsFile( sMachDir .. '\\Wall\\WallData.lua') then
|
|
WALL.ERR = 12
|
|
WALL.MSG = 'Error not configured for walls machine : ' .. sMachine
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
|
|
-- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie
|
|
EgtRemoveBaseMachineDirFromPackagePath()
|
|
EgtAddToPackagePath( sMachDir .. '\\Wall\\?.lua')
|
|
|
|
-- Carico le librerie
|
|
_G.package.loaded.WallExec = nil
|
|
local WE = require( 'WallExec')
|
|
local WL = require( 'WallLib')
|
|
|
|
-- Carico i dati globali
|
|
local WD = require( 'WallData')
|
|
|
|
-- Dati del file
|
|
local sDir, sTitle, sExt = EgtSplitPath( WALL.FILE)
|
|
local bBtl = ( string.upper( sExt or '') ~= '.BWE')
|
|
local sNgeFile = sDir..sTitle..'.bwe'
|
|
local sBtmFile = sDir..sTitle..'.btm'
|
|
local sPntFile = sDir..sTitle..'.pnt'
|
|
|
|
-- In generale va completamente riprocessato
|
|
local bToProcess = true
|
|
local bToRecalc = false
|
|
-- se BTL, barra ed esiste già il corrispondente progetto Nge
|
|
if bBtl and string.find( sTitle, 'Bar_', 1, true) and EgtExistsFile( sNgeFile) then
|
|
local sOriFile = sDir..sTitle..'.ori'..sExt
|
|
local sDiffFile = sDir..sTitle..'.diff.txt'
|
|
EgtEraseFile( sDiffFile)
|
|
local _, nDiff = EgtTextFileCompare( WALL.FILE, sOriFile, ';', sDiffFile)
|
|
-- se BTL corrente coincide con originale, salto il riprocessamento
|
|
if nDiff == 0 then
|
|
bToProcess = false
|
|
-- se cambiata configurazione macchina da ultima elaborazione, devo aggiornare
|
|
if EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\Wall\\TS3Data.lua') == -1 or
|
|
EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\Tools\\Tools.data') == -1 then
|
|
bToRecalc = true
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Inizializzo contatori errori e avvisi
|
|
local nErrCnt = 0
|
|
local nWarnCnt = 0
|
|
|
|
-- Se da elaborare
|
|
if bToProcess then
|
|
EgtOutLog( ' +++ Processing Parts >>>')
|
|
|
|
-- Flag di pannello da creare
|
|
local bCreatePanel
|
|
-- Dimensioni del pannello ed elenco pareti
|
|
local dPanelLen
|
|
local dPanelWidth
|
|
local vWall = {}
|
|
|
|
-- Se necessario, apro il file Bwe
|
|
if WALL.FLAG ~= 6 then
|
|
if not EgtOpenFile( WALL.FILE) then
|
|
WALL.ERR = 13
|
|
WALL.MSG = 'Error opening BWE file : ' .. WALL.FILE
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
-- faccio copia del file originale
|
|
EgtCopyFile( WALL.FILE, sDir..sTitle..'.ori'..sExt)
|
|
|
|
-- Aggiorno eventuali dati ausiliari
|
|
UpdateAuxData( sBtmFile)
|
|
|
|
-- Se già presente un gruppo di lavoro
|
|
if EgtGetFirstMachGroup() then
|
|
-- Barra già presente
|
|
bCreatePanel = 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
|
|
WD.OriTR = Point3d( b3Tab:getDimX(), b3Tab:getDimY(), 0)
|
|
|
|
-- altrimenti devo recuperare i pezzi per creare il pannello
|
|
else
|
|
-- Pannello da creare
|
|
bCreatePanel = true
|
|
-- Recupero l'elenco ordinato delle pareti
|
|
local nPartId = EgtGetFirstPart()
|
|
while nPartId do
|
|
table.insert( vWall, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))})
|
|
nPartId = EgtGetNextPart( nPartId)
|
|
end
|
|
if #vWall == 0 then
|
|
WALL.ERR = 14
|
|
WALL.MSG = 'Error no beams in the file : ' .. WALL.FILE
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
else
|
|
local sOut = ''
|
|
for i = 1, #vWall do
|
|
sOut = sOut .. vWall[i].Name .. ', '
|
|
end
|
|
sOut = sOut:sub( 1, -3)
|
|
EgtOutLog( 'Pareti trovate : ' .. sOut, 1)
|
|
end
|
|
-- Ne recupero le dimensioni
|
|
for i = 1, #vWall do
|
|
local Ls = EgtGetFirstNameInGroup( vWall[i].Id, 'Box')
|
|
local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD)
|
|
if not b3Solid then
|
|
WALL.ERR = 15
|
|
WALL.MSG = 'Box undefined for wall ' .. vWall[i].Name
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
else
|
|
vWall[i].Box = b3Solid
|
|
end
|
|
end
|
|
-- Assegno dimensioni del pannello
|
|
dPanelLen = vWall[1].Box:getDimX() + 20
|
|
dPanelWidth = vWall[1].Box:getDimY() + 20
|
|
-- Assegno posizione prima ed unica parete
|
|
vWall[1].PosX = 10
|
|
vWall[1].PosZ = 10
|
|
vWall[1].Rot = 0
|
|
vWall[1].Flip = 0
|
|
end
|
|
|
|
-- Altrimenti, opero sul progetto corrente
|
|
else
|
|
-- Recupero l'identificativo del gruppo di lavoro corrente
|
|
local nMGrpId = EgtGetCurrMachGroup()
|
|
-- Pannello da creare
|
|
bCreatePanel = true
|
|
-- Lunghezza e larghezza del pannello
|
|
dPanelLen = EgtGetInfo( nMGrpId, 'PANELLEN', 'd')
|
|
dPanelWidth = EgtGetInfo( nMGrpId, 'PANELWIDTH', 'd')
|
|
-- Recupero l'elenco ordinato delle pareti da inserire nel pannello
|
|
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 < 5 then break end
|
|
local nPartId = tonumber( vVal[1])
|
|
local dPosX = tonumber( vVal[2])
|
|
local dPosY = tonumber( vVal[3])
|
|
local dRot = tonumber( vVal[4])
|
|
local dFlip = tonumber( vVal[5])
|
|
table.insert( vWall, { Id = nPartId, PosX = dPosX, PosZ = dPosY, Rot = dRot, Flip = dFlip, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))})
|
|
end
|
|
if #vWall == 0 then
|
|
WALL.ERR = 14
|
|
WALL.MSG = 'Error : no walls in the project'
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
return
|
|
else
|
|
local sOut = ''
|
|
for i = 1, #vWall do
|
|
sOut = sOut .. vWall[i].Name .. ', '
|
|
end
|
|
sOut = sOut:sub( 1, -3)
|
|
EgtOutLog( 'Pareti trovate : ' .. sOut, 1)
|
|
end
|
|
-- Ne recupero le dimensioni
|
|
for i = 1, #vWall do
|
|
local Ls = EgtGetFirstNameInGroup( vWall[i].Id, 'Box')
|
|
local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD)
|
|
if not b3Solid then
|
|
WALL.ERR = 15
|
|
WALL.MSG = 'Box undefined for beam ' .. vWall[i].Name
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
return
|
|
else
|
|
vWall[i].Box = b3Solid
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Se devo creare il pannello
|
|
if bCreatePanel then
|
|
-- Ne verifico le dimensioni
|
|
local dRawH = vWall[1].Box:getDimZ()
|
|
local vWallErr = {}
|
|
for i = 2, #vWall do
|
|
local dDimH = vWall[i].Box:getDimZ()
|
|
if abs( dDimH - dRawH) > 10 * GEO.EPS_SMALL then
|
|
table.insert( vWallErr, i)
|
|
end
|
|
end
|
|
if #vWallErr > 0 then
|
|
local sOut = 'Rimosse pareti con spessore diverso dalla prima :\n'
|
|
for i = #vWallErr, 1, -1 do
|
|
sOut = sOut .. vWall[vWallErr[i]].Name .. '\n'
|
|
table.remove( vWall, vWallErr[i])
|
|
end
|
|
WALL.ERR = 16
|
|
WALL.MSG = sOut
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
|
|
local dRawL = dPanelLen
|
|
local dRawW = dPanelWidth
|
|
|
|
-- Verifico dimensioni massime grezzo
|
|
if dRawL > WD.MAX_LENGTH + 10 * GEO.EPS_SMALL or dRawW > WD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > WD.MAX_HEIGHT + 10 * GEO.EPS_SMALL then
|
|
local sOut = 'Grezzo (' .. EgtNumToString( dRawL, 2) .. ' x ' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' ..
|
|
'oltre il limite della macchina ('..EgtNumToString( WD.MAX_LENGTH, 2)..' x '..EgtNumToString( WD.MAX_WIDTH, 2)..' x '..EgtNumToString( WD.MAX_HEIGHT, 2)..') '
|
|
WALL.ERR = 17
|
|
WALL.MSG = sOut
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
|
|
-- Verifico dimensioni minime del grezzo
|
|
if dRawL < WD.MIN_LENGTH - 10 * GEO.EPS_SMALL or dRawW < WD.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < WD.MIN_HEIGHT - 10 * GEO.EPS_SMALL then
|
|
local sOut = 'Grezzo (' .. EgtNumToString( dRawL, 2) .. ' x ' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' ..
|
|
'sotto il limite della macchina ('..EgtNumToString( WD.MIN_LENGTH, 2)..' x '..EgtNumToString( WD.MIN_WIDTH, 2)..' x '..EgtNumToString( WD.MIN_HEIGHT, 2)..')'
|
|
WALL.ERR = 17
|
|
WALL.MSG = sOut
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
|
|
-- Sistemo le pareti nel grezzo
|
|
local bPbOk, sPbErr = WE.ProcessWalls( dRawL, dRawW, dRawH, vWall, WALL.FLAG == 6, true)
|
|
if not bPbOk then
|
|
WALL.ERR = 18
|
|
WALL.MSG = sPbErr
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
else
|
|
-- Scrivo altezza grezzo nel gruppo di lavoro corrente
|
|
local nMGrpId = EgtGetCurrMachGroup()
|
|
EgtSetInfo(nMGrpId, 'PANELHEIGHT', dRawH)
|
|
end
|
|
-- altrimenti sistemo
|
|
else
|
|
-- recupero il grezzo
|
|
local nRawId = EgtGetFirstRawPart()
|
|
-- ciclo sui pezzi
|
|
local nPartId = EgtGetFirstPartInRawPart( nRawId)
|
|
while nPartId do
|
|
WL.CreateOrEmptyAddGroup( nPartId)
|
|
nPartId = EgtGetNextPartInRawPart( nPartId)
|
|
end
|
|
end
|
|
|
|
-- Se richiesta solo pannello, esco
|
|
if WALL.FLAG == 6 then
|
|
-- Completamento senza errori e avvisi
|
|
if nWarnCnt == 0 then
|
|
WALL.ERR = 0
|
|
WALL.MSG = '---'
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
end
|
|
EgtOutLog( ' +++ BatchProcess completed')
|
|
return
|
|
end
|
|
|
|
-- Imposto Nome file CN
|
|
local _, sName, _ = EgtSplitPath( WALL.FILE)
|
|
EgtSetInfo( EgtGetCurrMachGroup(), 'NcName', sName .. '.cnc')
|
|
|
|
-- Abilito Vmill
|
|
EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1')
|
|
|
|
-- Lavoro le features
|
|
local bPfOk, Stats = WE.ProcessFeatures()
|
|
local sOutput = ''
|
|
for i = 1, #Stats do
|
|
local sMsg = Stats[i].Msg
|
|
sMsg = string.gsub( sMsg or '', '\n', ' ', 10)
|
|
sMsg = string.gsub( sMsg or '', '\r', ' ', 10)
|
|
if Stats[i].Err == 0 then
|
|
WALL.ERR = 0
|
|
WALL.MSG = '---'
|
|
WALL.ROT = Stats[i].Rot or 0
|
|
WALL.CUTID = Stats[i].CutId
|
|
WALL.TASKID = Stats[i].TaskId
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID)
|
|
elseif Stats[i].Err > 0 then
|
|
nErrCnt = nErrCnt + 1
|
|
sOutput = sOutput .. string.format( '[%d,%d] %s\n', Stats[i].CutId, Stats[i].TaskId, sMsg)
|
|
WALL.ERR = 19
|
|
WALL.MSG = sMsg
|
|
WALL.ROT = Stats[i].Rot or 0
|
|
WALL.CUTID = Stats[i].CutId
|
|
WALL.TASKID = Stats[i].TaskId
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID)
|
|
elseif Stats[i].Err < 0 then
|
|
nWarnCnt = nWarnCnt + 1
|
|
sOutput = sOutput .. string.format( '[%d,%d] %s\n', Stats[i].CutId, Stats[i].TaskId, sMsg)
|
|
WALL.ERR = -19
|
|
WALL.MSG = sMsg
|
|
WALL.ROT = Stats[i].Rot or 0
|
|
WALL.CUTID = Stats[i].CutId
|
|
WALL.TASKID = Stats[i].TaskId
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID)
|
|
end
|
|
end
|
|
|
|
-- Salvo il progetto
|
|
EgtSaveFile( sNgeFile)
|
|
|
|
-- Visualizzazione avvisi o errori
|
|
if #sOutput > 0 then EgtOutLog( sOutput) end
|
|
if nErrCnt > 0 then
|
|
PostErrView( 19, sOutput)
|
|
elseif nWarnCnt > 0 then
|
|
PostWarnView( 19, sOutput)
|
|
end
|
|
|
|
-- Altrimenti carico il progetto salvato e dichiaro nessun errore
|
|
else
|
|
EgtOutLog( ' +++ Loading Project already processed >>>')
|
|
-- Carico il progetto già fatto
|
|
EgtOpenFile( sNgeFile)
|
|
-- Dichiaro nessun errore
|
|
local nPartId = EgtGetFirstPart()
|
|
while nPartId do
|
|
local nCutId = EgtGetInfo( nPartId, 'CUTID', 'i')
|
|
if nCutId then
|
|
local LayerId = {}
|
|
LayerId[1] = EgtGetFirstNameInGroup( nPartId, 'Outline')
|
|
LayerId[2] = EgtGetFirstNameInGroup( nPartId, 'Processings')
|
|
for nInd = 1, #LayerId do
|
|
local nProcId = EgtGetFirstInGroup( LayerId[nInd] or GDB_ID.NULL)
|
|
while nProcId do
|
|
local bIsFea = EgtExistsInfo( nProcId, 'GRP') and EgtExistsInfo( nProcId, 'PRC')
|
|
local nTaskId = EgtGetInfo( nProcId, 'TASKID', 'i')
|
|
if bIsFea and nTaskId then
|
|
WALL.ERR = 0
|
|
WALL.MSG = '---'
|
|
WALL.ROT = 0
|
|
WALL.CUTID = nCutId
|
|
WALL.TASKID = nTaskId
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID)
|
|
end
|
|
nProcId = EgtGetNext( nProcId)
|
|
end
|
|
end
|
|
end
|
|
nPartId = EgtGetNextPart( nPartId)
|
|
end
|
|
-- Aggiorno eventuali dati ausiliari
|
|
UpdateAuxData( sBtmFile)
|
|
-- Passo in modalità lavora
|
|
EgtSetCurrMachGroup( EgtGetLastMachGroup())
|
|
-- Se necessario eseguo aggiornamento con ricalcolo delle lavorazioni
|
|
if bToRecalc then
|
|
EgtOutLog( ' +++ Recalculating all dispositions and machinings >>>')
|
|
EgtApplyAllMachinings()
|
|
-- copia del file btl originale (per dichiarare progetto ricalcolato)
|
|
EgtCopyFile( WALL.FILE, sDir..sTitle..'.ori'..sExt)
|
|
end
|
|
-- Salvo il progetto
|
|
EgtSaveFile( sNgeFile)
|
|
end
|
|
|
|
-- *** Eseguo simulazione con verifica collisione in cieco ***
|
|
if ( WALL.FLAG == 0 and ( bToProcess or bToRecalc)) or WALL.FLAG == 3 or WALL.FLAG == 4 then
|
|
EgtOutLog( ' +++ Simulating with collision check >>>')
|
|
local bSimOk, nErr, sErr = EgtSimulate()
|
|
if not bSimOk then
|
|
if nErr == MCH_SHE.INIT then
|
|
WALL.ERR = 19
|
|
WALL.MSG = 'Error starting simulation'
|
|
elseif nErr == MCH_SHE.COLLISION then
|
|
WALL.ERR = 22
|
|
WALL.MSG = 'Head-part collision'
|
|
elseif nErr == MCH_SHE.OUTSTROKE then
|
|
WALL.ERR = 23
|
|
WALL.MSG = 'Axis outstroke ' .. sErr
|
|
elseif nErr == MCH_SHE.SPECIAL then
|
|
WALL.ERR = 24
|
|
WALL.MSG = 'Special error ' .. sErr
|
|
else
|
|
WALL.ERR = 25
|
|
WALL.MSG = 'General failure (contact supplier)'
|
|
end
|
|
WALL.ROT = 0
|
|
WALL.CUTID = 0
|
|
WALL.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
|
|
WALL.CUTID = EgtGetVal( vItem[i], 'CUTID', 'i') or 0
|
|
elseif string.find( vItem[i], 'TASKID', 1, true) then
|
|
WALL.TASKID = EgtGetVal( vItem[i], 'TASKID', 'i') or 0
|
|
end
|
|
end
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID)
|
|
return
|
|
end
|
|
end
|
|
|
|
-- *** Genero programma CN *** ( se richiesto)
|
|
if WALL.FLAG == 0 or WALL.FLAG == 4 then
|
|
EgtOutLog( ' +++ Generating NC part program >>>')
|
|
if not EgtGenerate( '', 'EgtCAM5 - ' .. sNgeFile) then
|
|
WALL.ERR = 20
|
|
local _, sName, _ = EgtSplitPath( WALL.FILE)
|
|
WALL.MSG = 'Error generating NC part program : ' .. sName
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
end
|
|
|
|
-- *** Eseguo stima tempi ***
|
|
EgtOutLog( ' +++ Estimating T&L >>>')
|
|
if not EgtEstimate( '', 'EgtCAM5 - ' .. sNgeFile) then
|
|
WALL.ERR = 21
|
|
local _, sName, _ = EgtSplitPath( WALL.FILE)
|
|
WALL.MSG = 'Error estimating production time : ' .. sName
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
PostErrView( WALL.ERR, WALL.MSG)
|
|
return
|
|
end
|
|
local Ttot = EgtGetInfo( EgtGetCurrMachGroup(), 'Ttot', 'd')
|
|
local sTime = 'Total Time = ' .. EgtNumToString( Ttot, 1)
|
|
EgtOutLog( sTime)
|
|
|
|
-- Se modalità Cloud, importo la nuvola di punti
|
|
if WALL.FLAG == 5 then
|
|
EgtOutLog( ' +++ Importing Point Cloud >>>')
|
|
-- Creo gruppo Cloud nel gruppo di lavorazione
|
|
local nMGrpId = EgtGetCurrMachGroup()
|
|
local nCloudId = EgtGetFirstNameInGroup( nMGrpId or GDB_ID.NULL, 'Cloud')
|
|
if nCloudId then
|
|
EgtEmptyGroup( nCloudId)
|
|
else
|
|
nCloudId = EgtGroup( nMGrpId)
|
|
EgtSetName( nCloudId, 'Cloud')
|
|
end
|
|
-- Recupero BBox della tavola
|
|
local b3Tab = EgtGetTableArea()
|
|
if not b3Tab or b3Tab:isEmpty() then
|
|
WALL.ERR = 22
|
|
WALL.MSG = 'Machine table not found'
|
|
return
|
|
end
|
|
-- Recupero i punti della nuvola
|
|
local hFile = io.open( sPntFile, 'r')
|
|
if not hFile then
|
|
WALL.ERR = 23
|
|
WALL.MSG = 'Missing point cloud file'
|
|
return
|
|
end
|
|
local vPoints = {}
|
|
local sLine = hFile:read( '*l')
|
|
while sLine do
|
|
local vCoord = EgtSplitString( sLine, ' ')
|
|
if vCoord and #vCoord >= 2 then
|
|
local dX = tonumber( vCoord[1]) + b3Tab:getMax():getX()
|
|
local dY = tonumber( vCoord[2]) + b3Tab:getMin():getY()
|
|
local dZ = b3Tab:getMax():getZ()
|
|
EgtOutLog( ' X='..EgtNumToString( dX, 3)..' Y='..EgtNumToString( dY, 3), 3)
|
|
table.insert( vPoints, { dX, dY, dZ})
|
|
end
|
|
sLine = hFile:read( '*l')
|
|
end
|
|
hFile:close()
|
|
-- Inserisco la curva di contorno della nuvola
|
|
local nClCrvId = EgtCurveCompoFromPoints( nCloudId, vPoints, GDB_RT.GLOB)
|
|
if not nClCrvId then
|
|
WALL.ERR = 24
|
|
WALL.MSG = 'Failed to create Point cloud Contour'
|
|
return
|
|
end
|
|
EgtCloseCurveCompo( nClCrvId)
|
|
EgtApproxCurve( nClCrvId, GDB_CA.LINES, 1.0)
|
|
EgtSetColor( nClCrvId, 'RED')
|
|
end
|
|
|
|
-- Se modifica o simula, imposto la vista ISO 3d
|
|
if WALL.FLAG == 1 or WALL.FLAG == 2 then
|
|
EgtSetView( SCE_VD.ISO_SW, false)
|
|
-- se cloud, imposto la vista TOP
|
|
elseif WALL.FLAG == 5 then
|
|
EgtSetView( SCE_VD.TOP, false)
|
|
end
|
|
|
|
-- Completamento senza errori e avvisi
|
|
if nWarnCnt == 0 then
|
|
WALL.ERR = 0
|
|
WALL.MSG = '---'
|
|
WriteErrToLogFile( WALL.ERR, WALL.MSG)
|
|
end
|
|
|
|
-- Scrittura tempo totale stimato di lavorazione
|
|
WriteTimeToLogFile( Ttot)
|
|
|
|
EgtOutLog( ' +++ BatchProcess completed')
|