From babab61e3b6f2a90e0569c9d44458b179a5a6a0b Mon Sep 17 00:00:00 2001 From: DarioS Date: Fri, 30 Apr 2021 19:44:13 +0200 Subject: [PATCH] DataBeam : - aumentata lunghezza minima barre da progetto a 2500 mm - migliorata gestione sega a catena con PF1250 - aggiunto script per filling automatico barre. --- BatchProcessNew.lua | 2 +- LuaLibs/ProcessLapJoint.lua | 23 ++++ NestProcess.lua | 240 ++++++++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 NestProcess.lua diff --git a/BatchProcessNew.lua b/BatchProcessNew.lua index 095c039..65657eb 100644 --- a/BatchProcessNew.lua +++ b/BatchProcessNew.lua @@ -255,7 +255,7 @@ if bToProcess then -- Assegno lunghezza della barra dBarLen = vBeam[1].Box:getDimX() + 10 if dBarLen < 1500 then - dBarLen = 2000 + dBarLen = 2500 end -- Assegno posizione prima ed unica trave vBeam[1].PosX = 10 diff --git a/LuaLibs/ProcessLapJoint.lua b/LuaLibs/ProcessLapJoint.lua index 2f67372..5004b91 100644 --- a/LuaLibs/ProcessLapJoint.lua +++ b/LuaLibs/ProcessLapJoint.lua @@ -2196,6 +2196,13 @@ local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, return false, sErr end EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, EgtIf( BD.C_SIMM, 'A=0', 'A=90')) + if BD.C_SIMM then + if vtN:getY() > 0 then + EgtSetMachiningParam( MCH_MP.INITANGS, 'C=180') + else + EgtSetMachiningParam( MCH_MP.INITANGS, 'C=-180') + end + end if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) @@ -2270,6 +2277,14 @@ local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, return false, sErr end EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, EgtIf( BD.C_SIMM, 'A=0', 'A=90')) + if BD.C_SIMM then + local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nLundIdFace, GDB_ID.ROOT) + if vtN:getY() > 0 then + EgtSetMachiningParam( MCH_MP.INITANGS, 'C=180') + else + EgtSetMachiningParam( MCH_MP.INITANGS, 'C=-180') + end + end if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) @@ -3145,6 +3160,14 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, dOvmHead, bSinglePa return false, sErr end EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, EgtIf( BD.C_SIMM, 'A=0', 'A=90')) + if BD.C_SIMM then + local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nLundIdFace, GDB_ID.ROOT) + if vtN:getY() > 0 then + EgtSetMachiningParam( MCH_MP.INITANGS, 'C=180') + else + EgtSetMachiningParam( MCH_MP.INITANGS, 'C=-180') + end + end if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) diff --git a/NestProcess.lua b/NestProcess.lua new file mode 100644 index 0000000..23a6a39 --- /dev/null +++ b/NestProcess.lua @@ -0,0 +1,240 @@ +-- 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')