-- NestProcess.lua by Egaltech s.r.l. 2021/02/13 -- Gestione nesting automatico pareti -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- Per test --NEST = {} --NEST.FILE = 'c:\\TechnoEssetre7\\EgtData\\Prods\\0010\\Bar_10_1.btl' --NEST.MACHINE = 'Essetre-90480019_MW' --NEST.FLAG = 3 local sLog = 'BeamNestProcess : ' .. NEST.FILE .. ', ' .. NEST.MACHINE .. ', ' .. NEST.LEN .. ', ' .. NEST.WIDTH EgtOutLog( sLog) -- Cancello file di log specifico local sLogFile = EgtChangePathExtension( NEST.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 ( NEST.FLAG == 1 or NEST.FLAG == 2 or NEST.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 ( NEST.FLAG == 1 or NEST.FLAG == 2 or NEST.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 local function PartsToFill( Parts) local nToFill = 0 for i = 1, #Parts do if Parts[i].Cnt > 0 then nToFill = nToFill + Parts[i].Cnt end end return nToFill end local function ExecMaximumFilling( Raw, Parts) -- Inizializzo maximum filler EgtMaxFillerStart() -- Inserisco i pezzi for i = 1, #Parts do EgtMaxFillerAddPart( i, Parts[i].Len, Parts[i].DispLen or Parts[i].Len, Parts[i].Cnt or 1) end -- Eseguo l'ottimizzazione EgtStartCounter() EgtMaxFillerCompute( Raw.LenToFill, Raw.StartGap, Raw.MidGap, Raw.EndGap, Raw.SortType) local dTime = EgtStopCounter() -- Recupero i risultati local nFilledParts, nDiffParts, dTotFillRatio = EgtMaxFillerGetResults() local OneRes = {} for i = 0, nDiffParts - 1 do local nPartId, nCount = EgtMaxFillerGetOneResult( i) table.insert( OneRes, { Id=nPartId, Count=nCount}) end return { FilledParts=nFilledParts, DiffParts=nDiffParts, FillRatio=dTotFillRatio, Time=dTime, Data=OneRes} end -- Funzione per trovare nome MachGroup local function NewMachGroupName() local nMachGroupId = EgtGetFirstMachGroup() if not nMachGroupId then return 1 end local nMaxMachGroup = 0 while nMachGroupId do sMachGroupName = EgtGetMachGroupName(nMachGroupId) local nMachGroupName = tonumber(sMachGroupName) if nMachGroupName > nMaxMachGroup then nMaxMachGroup = nMachGroupName end nMachGroupId = EgtGetNextMachGroup(nMachGroupId) end return nMaxMachGroup + 1 end -- Imposto direttorio libreria specializzata per Travi local sBaseDir = EgtGetSourceDir() EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua') -- Verifico che la macchina corrente sia abilitata per la lavorazione delle Travi local sMachDir = EgtGetCurrMachineDir() if not EgtExistsFile( sMachDir .. '\\Beam\\BeamData.lua') then NEST.ERR = 12 NEST.MSG = 'Error not configured for beam machine : ' .. sMachine WriteErrToLogFile( NEST.ERR, NEST.MSG) PostErrView( NEST.ERR, NEST.MSG) return end -- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie EgtRemoveBaseMachineDirFromPackagePath() EgtAddToPackagePath( sMachDir .. '\\Beam\\?.lua') ---- Carico le librerie --_G.package.loaded.WallExec = nil --local WE = require( 'BeamExec') --_G.package.loaded.WallLib = nil --local WL = require( 'BeamLib') --_G.package.loaded.WProcessLapJoint = nil --local LapJoint = require( 'WProcessLapJoint') -- Inizializzo contatori errori e avvisi local nErrCnt = 0 local nWarnCnt = 0 -- Grezzi local Raws = { LenToFill = NEST.LEN, StartGap = NEST.STARTOFFSET, MidGap = NEST.OFFSET, EndGap = 0, SortType = -1, Count = 100} local nTotRaws = Raws.Count -- Pezzi local Parts = {} --local Parts = {{ Len=1050, DispLen=9050, Cnt=16}, -- { Len=3800, Cnt=20}, -- { Len=4654, Cnt=10}, -- { Len=1060, Cnt=9}, -- { Len=2200, Cnt=15}, -- { Len=1331, Cnt=11}, -- { Len=3060, Cnt=21}, -- { Len=3500, Cnt=6}, -- { Len=1622, Cnt=18}, -- { Len=1689, Cnt=11}, -- { Len=5810, Cnt=8}, -- { Len=770, DispLen=9770, Cnt=11}, -- { Len=7700, Cnt=2}, -- { Len=482, DispLen=11482, Cnt=8}, -- { Len=2911, Cnt=9}} --local nTotParts = PartsToFill( Parts) -- ciclo su pezzi per aggiungerli al nesting for nPartId, nCount in pairs( PART) do -- recupero lunghezza pezzo local Len = EgtGetInfo(nPartId, "L", 'd') local DispLen = EgtIf(Len < 1000, 2000, 0) table.insert(Parts, {Id = nPartId, Len = Len, DispLen = DispLen, Cnt = nCount}) end -- Ciclo fino ad esaurimento pezzi o barre local dTime = 0 while Raws.Count > 0 and PartsToFill( Parts) > 0 do -- Eseguo ottimizzazione per una barra e visualizzo il risultato local Res = ExecMaximumFilling( Raws, Parts) -- creo gruppo di lavorazione local MachGroupName = NewMachGroupName() nMachGroup = EgtAddMachGroup(MachGroupName, sCurrMachName) EgtSetInfo(nMachGroup, "BARLEN", Raws.LenToFill) EgtSetInfo(nMachGroup, "AUTONEST", 1) -- Disegno i pezzi local CurrX = Raws.StartGap for i = 1, Res.DiffParts do local PartIndex = Res.Data[i].Id local PartId = Parts[PartIndex].Id local dLen = Parts[PartIndex].Len for j = 1, Res.Data[i].Count do -- creo pezzo copia local nPartDuploId = EgtDuploNew(PartId) EgtSetInfo(nMachGroup, "PART" .. i, nPartDuploId .. "," .. CurrX) -- local PtId = EgtSurfFrRectangle( GDB_ID.CL, ptOrig + Vector3d( CurrX, 10, 0), ptOrig + Vector3d( CurrX + dLen, 190, 0)) -- EgtSetColor( PtId, Color3d( 256 - 4 * PartId, 16 * PartId, 8 * PartId, 40)) -- EgtExtractSurfFrChunkLoops( PtId, 0, EgtGetParent( PtId)) -- local sText = string.format( 'P%d (%.0f)', Res.Data[i].Id, Parts[Res.Data[i].Id].Len) -- EgtTextAdv( GDB_ID.CL, ptOrig + Vector3d( CurrX + 0.5 * dLen, 100,0), 0, sText, 'ModernPropS.Nfe', 100, 'S', 60, 0.8, 0, GDB_TI.MC) CurrX = CurrX + dLen + Raws.MidGap end end -- DrawBarWithParts( ptOrig, Raws, Parts, Res) -- EgtZoom( SCE_ZM.ALL) -- dTime = dTime + Res.Time -- Aggiorno per prossima iterazione Raws.Count = Raws.Count - 1 for i = 1, Res.DiffParts do local PartId = Res.Data[i].Id Parts[PartId].Cnt = Parts[PartId].Cnt - Res.Data[i].Count end -- ptOrig = ptOrig + Vector3d( 0, 400, 0) end -- creo grezzi per ogni gruppo di lavorazione _G.BEAM = {} BEAM.FILE = NEST.FILE BEAM.MACHINE = NEST.MACHINE BEAM.FLAG = 6 -- CREATE_PANEL nMachGroup = EgtGetFirstMachGroup() while nMachGroup do EgtSetCurrMachGroup(nMachGroup) if EgtGetInfo(nMachGroup, "AUTONEST",'i') == 1 then EgtSetInfo(nMachGroup, "AUTONEST", "") dofile(EgtGetSourceDir() .. "BatchProcessNew.lua") end nMachGroup = EgtGetNextMachGroup(nMachGroup) end EgtResetCurrMachGroup() -- nascondo rettangolo --EgtErase(SheetPartId) -- EgtSaveFile("c:\\Temp\\Prova1.nge") EgtOutLog( ' +++ NestProcess completed')