From 5617f476bc0d87db388db6eadeefb72bd6a45ce8 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 16 Feb 2021 10:00:22 +0000 Subject: [PATCH] DataWall : - correzione lav. tasche con pulitura angoli interni - modifiche per nuova interfaccia - aggiunta script per nesting. --- BatchProcessNew.lua | 6 +- LuaLibs/WProcessLapJoint.lua | 2 +- LuaLibs/WallExec.lua | 9 +- NestProcess.lua | 277 +++++++++++++++++++++++++++++++++++ 4 files changed, 290 insertions(+), 4 deletions(-) create mode 100644 NestProcess.lua diff --git a/BatchProcessNew.lua b/BatchProcessNew.lua index 8f5859e..13319bb 100644 --- a/BatchProcessNew.lua +++ b/BatchProcessNew.lua @@ -390,13 +390,17 @@ if bToProcess then end -- Sistemo le pareti nel grezzo - local bPbOk, sPbErr = WE.ProcessWalls( dRawL, dRawW, dRawH, vWall, WALL.FLAG == 6) + 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 end diff --git a/LuaLibs/WProcessLapJoint.lua b/LuaLibs/WProcessLapJoint.lua index 7ea26b8..dcaa202 100644 --- a/LuaLibs/WProcessLapJoint.lua +++ b/LuaLibs/WProcessLapJoint.lua @@ -298,7 +298,7 @@ local function GetFacesData( nNewProc, bOpposite, bCalclForBlade, dToolDiam, dTo -- recupero le dimensioni della faccia local _, dLen, dWidth = WL.GetFaceHvRefDim( nNewProc, nFac) -- recupero l'angolo con la faccia precedente - local bAdj, _, _, dAng = EgtSurfTmFacetsContact( nNewProc, nPrecFac, nFac, GDB_ID.ROOT) + local bAdj, ptLocP1, ptLocP2, dAng = EgtSurfTmFacetsContact( nNewProc, nPrecFac, nFac, GDB_ID.ROOT) -- salvo i dati vFace[i] = { Fac = nFac, Cen = ptCen, Norm = vtN, Len = dLen, Width = dWidth, AngPrev = EgtIf( bAdj, dAng, 0)} if bAdj then diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index f8f114e..a6afd02 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -28,7 +28,7 @@ local FreeContour = require( 'WProcessFreeContour') ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle pareti nel pannello *** ------------------------------------------------------------------------------------------------------------- -function WallExec.ProcessWalls( dRawL, dRawW, dRawH, vWall, bMachGroupOk) +function WallExec.ProcessWalls( dRawL, dRawW, dRawH, vWall, bMachGroupOk, bPartOriBL) -- Creazione nuovo gruppo di lavoro if not bMachGroupOk then @@ -84,7 +84,12 @@ function WallExec.ProcessWalls( dRawL, dRawW, dRawH, vWall, bMachGroupOk) end -- inserisco il pezzo nel grezzo EgtDeselectPartObjs( Pz) - local ptPos = Point3d( dRawL - vWall[i].PosX - PartLen, vWall[i].PosZ, ( dRawH - PartHeight) / 2) + local ptPos + if bPartOriBL then + ptPos = Point3d( vWall[i].PosX, vWall[i].PosZ, ( dRawH - PartHeight) / 2) + else + ptPos = Point3d( dRawL - vWall[i].PosX - PartLen, vWall[i].PosZ, ( dRawH - PartHeight) / 2) + end EgtAddPartToRawPart( Pz, ptPos, nRaw) end return true diff --git a/NestProcess.lua b/NestProcess.lua new file mode 100644 index 0000000..6fad1b7 --- /dev/null +++ b/NestProcess.lua @@ -0,0 +1,277 @@ +-- NestProcess.lua by Egaltech s.r.l. 2021/02/13 +-- Gestione nesting automatico pareti + +-- Intestazioni +require( 'EgtBase') +_ENV = EgtProtectGlobal() +EgtEnableDebug( true) + +-- Per test +--NEST = {} +--NEST.FILE = 'c:\\TechnoEssetre7\\EgtData\\Prods\\0010\\Bar_10_1.btl' +--NEST.MACHINE = 'Essetre-90480019_MW' +--NEST.FLAG = 3 + +local sLog = 'BatchProcess : ' .. NEST.FILE .. ', ' .. NEST.MACHINE .. ', ' .. NEST.PANELLEN .. ', ' .. NEST.PANELWIDTH +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 + +-- 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') + +-- Inizializzo contatori errori e avvisi +local nErrCnt = 0 +local nWarnCnt = 0 + +-- inizio nesting automatico +EgtAutoNestStart() + +local OUTLINE = "Outline" +-- creo pannello del materiale +local SheetPartId = EgtGroup(GDB_ID.ROOT) +EgtSetName(SheetPartId, "Sheet") +local SheetLayerId = EgtGroup(SheetPartId) +EgtSetName(SheetLayerId, OUTLINE) +local SheetOutlineId = EgtRectangle2P(SheetLayerId, Point3d(0,0,0), Point3d(NEST.PANELLEN, NEST.PANELWIDTH, 0), GDB_RT.GLOB) +-- EgtModifyCurveThickness(SheetOutlineId, -Material.T_mm) +EgtSetName(SheetOutlineId, OUTLINE) + +-- creo foglio per nesting +EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, 20, 0, 50) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) + +-- ciclo su pezzi per aggiungerli al nesting +for nPartId, nCount in pairs( PART) do + local nOutlineLayer = EgtGetFirstNameInGroup(nPartId, "Outline") + local nOutline = GDB_ID.NULL + local nTrimesh = GDB_ID.NULL + local bFirst = true + local bSecond = false + local bUseBox = false + nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "1-Out") + if not nTrimesh then + nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "2-Out") + end + if not nTrimesh then + nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "3-Out") + end + if not nTrimesh then + nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "4-Out") + end + local nAuxId = EgtGetInfo(nTrimesh, "AUXID", 'i') + nOutline = nTrimesh + nAuxId + + +-- local nIndex = EgtGetFirstInGroup(nOutlineLayer) +-- while nIndex do +-- local nType = EgtGetType(nIndex) +-- if nType == GDB_TY.CRV_COMPO then +-- nOutline = nIndex +-- if bFirst then +-- bFirst = false +-- else +-- bSecond = true +-- end +-- elseif nType == GDB_TY.SRF_MESH then +-- nTrimesh = nIndex +-- end +-- nIndex = EgtGetNext(nIndex) +-- end + -- se c'รจ solo una compo verifico se ha lati inclinati +-- if not bSecond then + local nFacetCount = EgtSurfTmFacetCount(nTrimesh) + for nIndex = 0, nFacetCount - 1 do + local vtNorm = EgtSurfTmFacetNormVersor(nTrimesh, nIndex, GDB_ID.ROOT) + if abs( vtNorm:getZ()) > 10 * GEO.EPS_SMALL then + bUseBox = true + break + end + end +-- else +-- bUseBox = true +-- end + -- se due compo o una e lati inclinati + if bUseBox then + -- calcolo box della trimesh + local b3Outline = EgtGetBBoxGlob(nTrimesh, GDB_BB.IGNORE_TEXT) + local ptP1 = Point3d( b3Outline:getMin():getX(), b3Outline:getMin():getY(), 0) + local ptP2 = Point3d( b3Outline:getMax():getX(), b3Outline:getMax():getY(), 0) + -- creo outline del box + nOutline = EgtRectangle2P(nOutlineLayer, ptP1, ptP2, GDB_RT.GLOB) + EgtSetStatus(nOutline, GDB_ST.OFF) + end + if nOutline then + -- aggiungo pezzo al nesting + EgtAutoNestAddPart( nPartId, nOutline, false, true, 90, 0, nCount) + -- EgtAutoNestAddPart( PartId, OutlineId, bCanFlip, bCanRotate, dRotStep, nPriority, nCount) + end +end + +-- aggiungo offset tra pezzi +EgtAutoNestSetInterpartGap(50) + +-- Impostazione corner di inizio del nesting (NST_CORNER.BL, TL, BR, TR) +EgtAutoNestSetStartCorner( NST_CORNER.BR) + +local nMaxTime = 5 +-- imposto tempo di nesting e lo avvio +EgtAutoNestCompute(true, nMaxTime) + +-- Variabili di calcolo +local nNestedParts, nParts, nSheets, nNestings, dTotFillRatio +-- Attesa fine calcolo +local bOk = true +local nTime = 0 +while bOk do + bOk, nStat = EgtAutoNestGetComputationStatus() + if nStat == 2 or nStat == 3 then + nNestedParts, nParts, nSheets, nNestings, dTotFillRatio = EgtAutoNestGetResults() + --EgtOutText( string.format( 'Parts : %d/%d Filling : %.2f%%', nNestedParts, nParts, 100 * dTotFillRatio)) + end + if nStat == 3 then break end + nTime = nTime + 1 + if EgtProcessEvents( nTime / nMaxTime * 100, 995) == 1 then + bOk = EgtAutoNestCancelComputation() + break + end +end + +-- se nesting andato bene +if bOk then + + -- disposizione sheet e parts + local SheetId = GDB_ID.NULL + local vtAdd = V_NULL() + local nMachGroup = GDB_ID.NULL + local nPartCount = 0 + local Sheet = {PartList = {}} + local bFirstSheet = true + for i = 0, 999 do + local nType, nId, nFlag, dX, dY, dAngRot = EgtAutoNestGetOneResult( i) + if not nType then break end + -- se sheet + if nType > 0 then + -- creo gruppo di lavorazione + local MachGroupName = NewMachGroupName() + nMachGroup = EgtAddMachGroup(MachGroupName, sCurrMachName) + EgtSetInfo(nMachGroup, "PANELLEN", NEST.PANELLEN) + EgtSetInfo(nMachGroup, "PANELWIDTH", NEST.PANELWIDTH) + EgtSetInfo(nMachGroup, "AUTONEST", 1) + nPartCount = 0 + -- altrimenti pezzo + else + local PartId = nId + nPartCount = nPartCount + 1 +-- if nFlag ~= 0 then +-- EgtMirror( PartId, ORIG(), Y_AX(), GDB_RT.GLOB) +-- end +-- EgtRotate( PartId, ORIG(), Z_AX(), dAngRot, GDB_RT.GLOB) +-- EgtMove( PartId, Vector3d( dX, dY, 0) + vtAdd, GDB_RT.GLOB) + -- se c'e' un grezzo valido + if nMachGroup and nMachGroup ~= GDB_ID.NULL then + -- creo pezzo copia + local nPartDuploId = EgtDuploNew(nId) + EgtRotate( nPartDuploId, ORIG(), Z_AX(), dAngRot, GDB_RT.GLOB) + EgtMove( nPartDuploId, Vector3d( dX, dY, 0), GDB_RT.GLOB) + local PartBBox = EgtGetBBoxGlob(nPartDuploId, GDB_BB.STANDARD) +-- local ptPos = Point3d(PartBBox:getMin():getX(), PartBBox:getMin():getY(), 0) + EgtSetInfo(nMachGroup, "PART" .. nPartCount, nPartDuploId .. "," .. PartBBox:getMin():getX() .. "," .. PartBBox:getMin():getY().. "," .. 0 .. "," .. 0) +-- EgtSetInfo(nMachGroup, "PART" .. nPartCount, nId .. "," .. 10 .. "," .. 10 .. "," .. 0 .. "," .. 0) + +-- local PartBBox = EgtGetBBoxGlob(PartId, GDB_BB.STANDARD) +-- local ptPos = Point3d(PartBBox:getMin():getX(), PartBBox:getMin():getY(), 0) +-- local bOk = EgtAddPartToRawPart(PartId, ptPos, nRawId) + end + end + end + + -- creo grezzi per ogni gruppo di lavorazione + _G.WALL = {} + WALL.FILE = NEST.FILE + WALL.MACHINE = NEST.MACHINE + WALL.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 + +end + +EgtResetCurrMachGroup() +-- nascondo rettangolo +EgtErase(SheetPartId) +-- EgtSaveFile("c:\\Temp\\Prova1.nge") + +EgtOutLog( ' +++ NestProcess completed')