248 lines
8.8 KiB
Lua
248 lines
8.8 KiB
Lua
-- Process.lua by Egalware s.r.l. 2024/04/02
|
|
-- Gestione calcolo disposizione e lavorazioni per Travi
|
|
-- Si opera sulla macchina corrente
|
|
-- 2024/04/02 PRIMA VERSIONE
|
|
|
|
|
|
-- Intestazioni
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( false)
|
|
|
|
-- 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 sMachDir = EgtGetCurrMachineDir()
|
|
if not sMachDir then
|
|
EgtOutBox( 'Errore nel caricamento della macchina corrente', 'Lavora Travi', 'ERROR')
|
|
return
|
|
end
|
|
if not EgtExistsFile( sMachDir .. '\\Beam\\BeamDataNew.lua') then
|
|
EgtOutBox( 'La macchina corrente non è configurata per lavorare travi', 'Lavora Travi', 'ERROR')
|
|
return
|
|
end
|
|
|
|
-- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie
|
|
EgtRemoveBaseMachineDirFromPackagePath()
|
|
EgtAddToPackagePath( sMachDir .. '\\Beam\\?.lua')
|
|
|
|
-- Segnalazione avvio
|
|
EgtOutLog( '*** Beam Process Start ***', 1)
|
|
|
|
-- Carico le librerie
|
|
_G.package.loaded.BasicCustomerStrategies = nil
|
|
_G.package.loaded.BeamExec = nil
|
|
_G.package.loaded.BeamLib = nil
|
|
_G.package.loaded.DiceCut = nil
|
|
_G.package.loaded.FaceData = nil
|
|
_G.package.loaded.FeatureLib = nil
|
|
_G.package.loaded.Identity = nil
|
|
_G.package.loaded.Logs = nil
|
|
_G.package.loaded.MachiningLib = nil
|
|
_G.package.loaded.PreSimulationLib = nil
|
|
_G.package.loaded.LeadInOutLib = nil
|
|
-- strategie di base sempre presenti
|
|
_G.package.loaded['HEADCUT\\HEADCUT'] = nil
|
|
_G.package.loaded['TAILCUT\\TAILCUT'] = nil
|
|
-- libreria macchina
|
|
_G.package.loaded.BeamDataNew = nil
|
|
-- libreria calcolo tempo esecuzione
|
|
_G.package.loaded.TimeLib = 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( EgtNumToString( 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( 'BeamDataNew')
|
|
-- carico librerie
|
|
local BeamExec = require( 'BeamExec')
|
|
local BeamLib = require( 'BeamLib')
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
-- *** Recupero trave (E' SEMPRE E SOLO UNA) ***
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function MyProcessInputData()
|
|
-- Recupero il pezzo e i suoi dati
|
|
local nId = EgtGetFirstPart()
|
|
if nId then
|
|
table.insert( PARTS, { nInd = #PARTS + 1, id = nId, sName = ( EgtGetName( nId) or ( 'Id=' .. tonumber( nId)))})
|
|
local Ls = EgtGetFirstNameInGroup( PARTS[1].id, 'Box')
|
|
local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD)
|
|
if not b3Solid then
|
|
return false
|
|
end
|
|
PARTS[1].b3PartOriginal = b3Solid
|
|
else
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function GetDataConfig()
|
|
-- recupero utensili dal magazzino
|
|
BeamExec.GetToolsFromDB()
|
|
-- TODO da gestire eventuali errori bloccanti
|
|
return true
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
-- *** Inserimento delle travi nel grezzo ***
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function MyProcessBeams()
|
|
-- Lunghezza totale delle travi
|
|
local dLen = PARTS[1].b3PartOriginal:getDimX()
|
|
local dRawW = PARTS[1].b3PartOriginal:getDimY()
|
|
local dRawH = PARTS[1].b3PartOriginal:getDimZ()
|
|
|
|
-- Determinazione minimo grezzo scaricabile
|
|
BeamExec.CalcMinUnloadableRaw( dRawW, dRawH)
|
|
|
|
local dOvmHead = BeamData.OVM_HEAD or 10
|
|
local dOvmMid = BeamData.OVM_MID or 10
|
|
|
|
local dRawL = max( dLen + dOvmHead + dOvmMid, BeamData.dMinRaw)
|
|
|
|
-- Recupero info pezzi
|
|
local bOk, sErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS, nil, true)
|
|
if not bOk then
|
|
EgtOutLog( sErr)
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
-- *** Inserimento delle lavorazioni nelle travi ***
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function MyProcessFeatures()
|
|
|
|
BeamExec.GetProcessings( PARTS, true)
|
|
BeamExec.GetCombinationMatrix( PARTS, true)
|
|
BeamExec.ProcessMachinings( PARTS, true)
|
|
|
|
-- scrittura variabili globali per interfaccia
|
|
BEAM.PREROTATE90 = PARTS[1].nInitialPosition - 1
|
|
BEAM.PREINVERT = EgtIf( PARTS[1].bPartInCombiIsInverted, 1, 0)
|
|
|
|
local nErrCnt = 0
|
|
local nWarnCnt = 0
|
|
local sOutput = ''
|
|
for i = 1, #RESULT do
|
|
local sMsg = ''
|
|
if RESULT[i].sType == 'Feature' then
|
|
sMsg = RESULT[i].ChosenStrategy.sInfo
|
|
elseif RESULT[i].sType == 'Part' then
|
|
sMsg = RESULT[i].sMsg
|
|
end
|
|
sMsg = string.gsub( sMsg or '', '\n', ' ', 10)
|
|
sMsg = string.gsub( sMsg or '', '\r', ' ', 10)
|
|
-- trovata almeno una strategia e feature lavorata completamente
|
|
if RESULT[i].sType == 'Feature' and RESULT[i].ChosenStrategy.sStatus == 'Completed' then
|
|
sOutput = sOutput .. string.format( '[%d,%d] %s\n', RESULT[i].idCut, RESULT[i].idTask, sMsg or '')
|
|
|
|
-- trovata almeno una strategia ma nessuna applicabile oppure non trovata alcuna strategia
|
|
elseif RESULT[i].sType == 'Feature'
|
|
and ( ( RESULT[i].ChosenStrategy.sStatus == 'Not-Applicable')
|
|
or ( not RESULT[i].ChosenStrategy.sStrategyName)) then
|
|
|
|
nErrCnt = nErrCnt + 1
|
|
if #sMsg == 0 then
|
|
sMsg = 'No applicable strategy found'
|
|
end
|
|
sOutput = sOutput .. string.format( '[%d,%d] %s\n', RESULT[i].idCut, RESULT[i].idTask, sMsg)
|
|
else
|
|
-- segnalazione scarico pezzo standard, incompleto o a caduta
|
|
if RESULT[i].sType == 'Part' and ( RESULT[i].nErr == -100 or RESULT[i].nErr == -101 or RESULT[i].nErr == -102) then
|
|
-- nulla da segnalare
|
|
|
|
-- feature incompleta e altro
|
|
elseif RESULT[i].sType == 'Feature' and RESULT[i].ChosenStrategy.sStatus == 'Not-Completed' then
|
|
nWarnCnt = nWarnCnt + 1
|
|
sMsg = 'Incomplete : Completion index ' .. RESULT[i].ChosenStrategy.dCompletionIndex .. '/5\n' .. sMsg
|
|
sOutput = sOutput .. string.format( '[%d,%d] %s\n', RESULT[i].idCut, RESULT[i].idTask, sMsg)
|
|
|
|
end
|
|
end
|
|
end
|
|
|
|
-- si calcolano alternative
|
|
TIMER:startElapsed('Alternatives')
|
|
BeamExec.ProcessAlternatives( PARTS)
|
|
TIMER:stopElapsed('Alternatives')
|
|
|
|
-- cancello gruppo temporaneo
|
|
local idTempGroup = BeamLib.GetTempGroup()
|
|
EgtErase( idTempGroup)
|
|
|
|
if #sOutput > 0 then EgtOutLog( sOutput) end
|
|
if nErrCnt > 0 then
|
|
EgtOutBox( sOutput, 'Lavora Travi', 'ERRORS')
|
|
return false
|
|
elseif nWarnCnt > 0 then
|
|
EgtOutBox( sOutput, 'Lavora Travi', 'WARNINGS')
|
|
return true
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
-- *** Esecuzione ***
|
|
-------------------------------------------------------------------------------------------------------------
|
|
|
|
-- calcolo tempo esecuzione
|
|
TIMER:start()
|
|
EgtOutLog( ' Execution timer started')
|
|
|
|
-- script principale
|
|
|
|
if not MyProcessInputData() then return end
|
|
|
|
-- recupero parametri generali da progetto
|
|
BeamExec.GetGeneralParameters()
|
|
|
|
-- creo un gruppo temporaneo dove finiranno tutte le entità che non bisogna salvare, alla fine lo si cancella
|
|
BeamLib.CreateTempGroup()
|
|
|
|
if not MyProcessBeams() then return end
|
|
|
|
if not GetDataConfig() then return end
|
|
|
|
-- Abilito Vmill
|
|
EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1')
|
|
|
|
MyProcessFeatures()
|
|
|
|
-- log tempi di esecuzione
|
|
if EgtGetDebugLevel() >= 3 then
|
|
TIMER:logAllElapsed()
|
|
end
|
|
|