From b469723114936b2424fb009dd83f8e8417ce7740 Mon Sep 17 00:00:00 2001 From: "daniele.nicoli" Date: Tue, 5 May 2026 17:14:01 +0200 Subject: [PATCH] Aggiunta ScrapRemove definibile da nota utente. Aggiornata ExecScrapRemove() in mlpe come da ultime macchine (90580012) - da correggere controllo alla riga 496 .mlpe --- Essetre-WALL_XS.mlpe | 139 +++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 46 deletions(-) diff --git a/Essetre-WALL_XS.mlpe b/Essetre-WALL_XS.mlpe index ec29cb3..1225500 100644 --- a/Essetre-WALL_XS.mlpe +++ b/Essetre-WALL_XS.mlpe @@ -282,7 +282,8 @@ function OnSimulMachiningStart() -- recupero alcuni dati della lavorazione EMT.MCHNAME = EgtGetOperationName( EMT.MCHID) EMT.MCHTYPE = EgtGetMachiningParam( MCH_MP.TYPE) - local sNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) + EMT.MCHWS = EgtGetMachiningParam( MCH_MP.WORKSIDE) or 0 + EMT.MCHUSERNOTES = EgtGetMachiningParam( MCH_MP.USERNOTES) EMT.VMRS = false -- recupero CUTID e TASKID della feature lavorata local vId = EgtGetMachiningGeometry() @@ -295,15 +296,15 @@ function OnSimulMachiningStart() EMT.TASKID = 0 end -- eventuale pausa per rimozione sfridi - if EMT.SCRAPFIRST then - if ( EMT.HEAD == 'H3' and string.sub( EMT.MCHNAME, 1, 5) == 'Csaw_') or EgtExistsInfo( EMT.MCHID, 'MOVE_AFTER') then - EMT.SCRAPFIRST = false - EgtOutText( 'Pause for Scrap Remove') - ParkForScrapRemove() - ExecScrapRemove() - EgtPause( 500) - EgtOutText( '') - end + local bSystemSR = ( EMT.SCRAPFIRST and (( EMT.HEAD == 'H3' and string.sub( EMT.MCHNAME, 1, 5) == 'Csaw_') or EgtExistsInfo( EMT.MCHID, 'MOVE_AFTER'))) + local bUserSR = ( EgtGetValInNotes( EMT.MCHUSERNOTES, 'ScrapRemove', 'i') == 1) + if bSystemSR or bUserSR then + if bSystemSR then EMT.SCRAPFIRST = false end + EgtOutText( 'Pause for Scrap Remove') + ParkForScrapRemove() + ExecScrapRemove() + EgtPause( 500) + EgtOutText( '') end -- non ancora iniziata la lavorazione EMT.MCHFIRST = true @@ -433,12 +434,20 @@ function ExecScrapRemove() -- box e area local b3Part = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) local dPartArea = b3Part:getDimX() * b3Part:getDimY() + local nOlEntId = EgtGetFirstInGroup( EgtGetFirstNameInGroup( nPartId, 'Outline') or GDB_ID.NULL) + while nOlEntId do + if EgtGetType( nOlEntId) == GDB_TY.SRF_FRGN and EgtSurfFrNormVersor( nOlEntId, GDB_ID.ROOT):getZ() > 0.8 then + dPartArea = EgtSurfArea( nOlEntId) + break + end + nOlEntId = EgtGetNext( nOlEntId) + end -- box espanso local b3PartExp = BBox3d( b3Part) b3PartExp:Add( b3PartExp:getMin() - Vector3d( 10, 10, 0)) b3PartExp:Add( b3PartExp:getMax() + Vector3d( 10, 10, 0)) -- salvo i dati - table.insert( vPart, { Box = b3Part, BoxExp = b3PartExp, Area = dPartArea}) + table.insert( vPart, { Box = b3Part, BoxExp = b3PartExp, Area = dPartArea, Outline = nOlEntId}) -- passo al successivo nPartId = EgtGetNextPartInRawPart( nPartId) end @@ -455,6 +464,25 @@ function ExecScrapRemove() -- salvo i dati table.insert( vVmPart, { Box = b3VmPart, BoxExp = b3VmPartExp, Area = dVmPartArea}) end + -- se presente squadratura, tengo tutti i pezzi all'interno + local nRawId = EgtGetFirstRawPart() + local SquaringEntities = {} + SquaringEntities = EgtGetNameInGroup( nRawId, 'SquaringGeometry') + local b3SquaringBox = nil + if SquaringEntities then + for i = 1, #SquaringEntities do + if i == 1 then + b3SquaringBox = EgtGetBBoxGlob( SquaringEntities[i], GDB_BB.STANDARD) + else + if b3SquaringBox then + b3SquaringBox:Add( EgtGetBBoxGlob( SquaringEntities[i], GDB_BB.STANDARD)) + end + end + end + if b3SquaringBox then + b3SquaringBox:expand( 50) + end + end -- Tengo solo le parti del Vmill che contengono almeno un box di un pezzo o che interferiscono e sono abbastanza grandi local nValidCnt = 0 for i = #vVmPart, 1, -1 do @@ -462,20 +490,23 @@ function ExecScrapRemove() local bToRemove = true -- se area abbastanza grande, allora da verificare if vVmPart[i].Area > 1e4 then - -- verifico se sono sicuramente valide (i due box si equivalgono entro la tolleranza) - for j = 1, #vPart do - if EnclosesXY( vVmPart[i].BoxExp, vPart[j].Box) and EnclosesXY( vPart[j].BoxExp, vVmPart[i].Box) then - bToRemove = false - vVmPart[i].Part = j - nValidCnt = nValidCnt + 1 - break + if not b3SquaringBox or EnclosesXY( b3SquaringBox, vVmPart[i].Box) then + -- verifico se sono sicuramente valide (i due box si equivalgono entro la tolleranza) + for j = 1, #vPart do + if ( vPart[j].Outline and vVmPart[i].Area > 0.95 * vPart[j].Area and vVmPart[i].Area < 1.05 * vPart[j].Area) or + ( EnclosesXY( vVmPart[i].BoxExp, vPart[j].Box) and EnclosesXY( vPart[j].BoxExp, vVmPart[i].Box)) then + bToRemove = false + vVmPart[i].Part = j + nValidCnt = nValidCnt + 1 + break + end end - end - -- verifico se sono molto probabilmente valide - for j = 1, #vPart do - if bToRemove and ( OverlapsXY( vVmPart[i].Box, vPart[j].Box) and vVmPart[i].Area > 0.25 * vPart[j].Area) then - bToRemove = false - break + -- verifico se sono molto probabilmente valide + for j = 1, #vPart do + if bToRemove and ( OverlapsXY( vVmPart[i].Box, vPart[j].Box) and vVmPart[i].Area > 0.25 * vPart[j].Area) then + bToRemove = false + break + end end end end @@ -485,10 +516,6 @@ function ExecScrapRemove() table.remove( vVmPart, i) end end - -- Se il numero delle parti non supera il numero dei pezzi, ho finito - if #vVmPart <= #vPart then - return - end -- Se il numero delle parti sicuramente valide uguaglia il numero dei pezzi, elimino le altre ed ho finito if nValidCnt == #vPart then for i = #vVmPart, 1, -1 do @@ -511,8 +538,14 @@ function ExecScrapRemove() local ptC = ptP + Y_AX() * (( vIntDist[j] + vIntDist[j + 1]) / 2) local nPart = EgtVolZmapGetPartMinDist( EMT.VMILL, ptC, GDB_RT.GLOB) if nPart == i - 1 then - vVmPart[i].Cen = ptC - break + if not vVmPart[i].Cen then + vVmPart[i].Cen = ptC + elseif not vVmPart[i].Cen2 then + vVmPart[i].Cen2 = ptC + else + vVmPart[i].Cen3 = ptC + break + end end end end @@ -521,24 +554,38 @@ function ExecScrapRemove() end -- Verifico le parti di Vmill non già dichiarate valide for i = #vVmPart, 1, -1 do - if not vVmPart[i].Part and vVmPart[i].Cen then + if not vVmPart[i].Part then local bToRemove = true - for j = 1, #vPart do - if EnclosesPointXY( vPart[j].Box, vVmPart[i].Cen) then - bToRemove = false - break - end - end - for j = 1, #vVmPart do - if j ~= i then - local vExpBox = BBox3d( vVmPart[j].Box) - -- lo espando in XY per sicurezza - vExpBox:Add( vExpBox:getMin() - Vector3d( 100, 100, 0)) - vExpBox:Add( vExpBox:getMax() + Vector3d( 100, 100, 0)) - -- verifico contenimento - if EnclosesXY( vExpBox, vVmPart[i].Box) then - bToRemove = true + if vVmPart[i].Cen then + for j = 1, #vPart do + if EnclosesPointXY( vPart[j].Box, vVmPart[i].Cen) then + bToRemove = false break + elseif vVmPart[i].Cen2 and EnclosesPointXY( vPart[j].Box, vVmPart[i].Cen2) then + bToRemove = false + break + elseif vVmPart[i].Cen3 and EnclosesPointXY( vPart[j].Box, vVmPart[i].Cen3) then + bToRemove = false + break + end + -- controllo per gestire squadratura inserita manualmente da operatore + -- verifico se il box del part è completamente incluso nel box del VM, allora non posso cancellarlo + if Encloses( vVmPart[i].BoxExp, vPart[j].Box) then + bToRemove = false + break + end + end + for k = 1, #vVmPart do + if k ~= i then + local vExpBox = BBox3d( vVmPart[k].Box) + -- lo espando in XY per sicurezza + vExpBox:Add( vExpBox:getMin() - Vector3d( 100, 100, 0)) + vExpBox:Add( vExpBox:getMax() + Vector3d( 100, 100, 0)) + -- verifico contenimento + if EnclosesXY( vExpBox, vVmPart[i].Box) then + bToRemove = true + break + end end end end