diff --git a/LuaLibs/WProcessLapJoint.lua b/LuaLibs/WProcessLapJoint.lua index 4b1bc55..380f8a5 100644 --- a/LuaLibs/WProcessLapJoint.lua +++ b/LuaLibs/WProcessLapJoint.lua @@ -1362,8 +1362,10 @@ local function IsMachiningDamagingOtherParts( Proc, dMillDiameter, nRawId) b3ProcExtended:Add( ptMax) local nPartId = EgtGetFirstPartInRawPart( nRawId) while nPartId do - local b3Part = EgtGetBBoxGlob( nPartId or GDB_ID.NULL, GDB_BB.STANDARD) - if ( nPartId ~= Proc.PartId) and OverlapsXY( b3ProcExtended, b3Part) then + local nBoxSolidId = EgtGetFirstNameInGroup( nPartId, 'Box') + local b3Solid = EgtGetBBoxGlob( nBoxSolidId or GDB_ID.NULL, GDB_BB.STANDARD) + b3Solid:expand( - 10 * GEO.EPS_SMALL) + if ( nPartId ~= Proc.PartId) and OverlapsXY( b3ProcExtended, b3Solid) then bIsMachiningDamagingOtherParts = true end nPartId = EgtGetNextPartInRawPart( nPartId) @@ -2220,6 +2222,97 @@ local function MakeSideGrooveByMill( Proc, nFacet, nRawId, b3Raw, sCustomMach, d return true, sWarn end +--------------------------------------------------------------------- +local function VerifyPocket( Proc, dMaxDiameter, dElev, nRawId, dH, dV) + local dStartDiameter = dMaxDiameter + if Proc.AffectedFaces.Front then + dMaxDiameter = min( dMaxDiameter, Proc.DistanceToNearestParts.Front) + end + if Proc.AffectedFaces.Back then + dMaxDiameter = min( dMaxDiameter, Proc.DistanceToNearestParts.Back) + end + if Proc.AffectedFaces.Left then + dMaxDiameter = min( dMaxDiameter, Proc.DistanceToNearestParts.Left) + end + if Proc.AffectedFaces.Right then + dMaxDiameter = min( dMaxDiameter, Proc.DistanceToNearestParts.Right) + end + + local bForceClosedPocket = false + -- recupero la lavorazione + local bUseDElevToFindPocketing = true + local sPocketing = WM.FindPocketing( 'Pocket', dMaxDiameter, dElev) + -- se tasca troppo profonda cerco senza elevazione e limiterò la profondità + if not sPocketing then + bUseDElevToFindPocketing = false + sPocketing = WM.FindPocketing( 'Pocket', dMaxDiameter) + end + local dMillDiam = 20 + local dMaxDepth = 0 + local dThDiam = 100 + local sTuuid + -- se lavorazione trovata verifico eventuale doppio, raccolgo i dati utensile e verifico collisioni dell'utensile con altre parti + if sPocketing then + -- se doppio cerco una lavorazione adatta + if Proc.Double and Proc.Double == 2 then + local sPocketingBackup = sPocketing + sPocketing = WM.FindPocketing( 'Pocket', dMaxDiameter, EgtIf( bUseDElevToFindPocketing, dElev, nil), nil, 'H1') + if not IsMachiningOkForDouble( sPocketing) then + Proc.Double = 0 + sPocketing = sPocketingBackup + end + end + -- recupero diametro utensile + if EgtMdbSetCurrMachining( sPocketing) then + sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam + end + end + -- verifico se la lavorazione (o il suo eventuale doppio) potrebbe danneggiare le parti limitrofe e devo quindi forzare una tasca chiusa + if WD.AVOID_DAMAGING_OTHER_PARTS then + if IsMachiningDamagingOtherParts( Proc, dMillDiam, nRawId) or + Proc.Double and Proc.Double > 0 and IsMachiningDamagingOtherParts( Proc.Mirror, dMillDiam, nRawId) then + bForceClosedPocket = true + end + end + -- altrimenti diametro utensile troppo piccolo: devo forzare tasca chiusa + else + bForceClosedPocket = true + end + + -- se tasca chiusa cerco lavorazione con diametro massimo pari a dimensione tasca e riverifico per eventuale doppio + if bForceClosedPocket then + dMaxDiameter = min( dH, dV) + bUseDElevToFindPocketing = true + sPocketing = WM.FindPocketing( 'Pocket', dMaxDiameter, dElev) + if not sPocketing then + bUseDElevToFindPocketing = false + sPocketing = WM.FindPocketing( 'Pocket', dMaxDiameter) + end + -- se doppio cerco una lavorazione adatta + if Proc.Double and Proc.Double == 2 then + local sPocketingBackup = sPocketing + sPocketing = WM.FindPocketing( 'Pocket', dMaxDiameter, EgtIf( bUseDElevToFindPocketing, dElev, nil), nil, 'H1') + if not IsMachiningOkForDouble( sPocketing) then + Proc.Double = 0 + sPocketing = sPocketingBackup + end + end + end + + -- recupero dati utensile + if EgtMdbSetCurrMachining( sPocketing) then + sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam + dMaxDepth = EgtIf( WD.MILL_MAX_DEPTH_AS_MAT, EgtTdbGetCurrToolParam( MCH_TP.MAXMAT), EgtTdbGetCurrToolMaxDepth()) or dMaxDepth + dThDiam = EgtTdbGetCurrToolThDiam() or dThDiam + end + end + + return sPocketing, bForceClosedPocket, sTuuid, dMillDiam, dMaxDepth, dThDiam +end --------------------------------------------------------------------- local function MakeByPocketing( Proc, nFacet, nRawId, b3Raw, bCheckQPar) -- dati della faccia @@ -2260,51 +2353,14 @@ local function MakeByPocketing( Proc, nFacet, nRawId, b3Raw, bCheckQPar) elseif Proc.Fct >= 4 then dDiam = min( dDiam, WD.MAXDIAM_POCK_CORNER or 1000) end - -- recupero la lavorazione - local bUseDElevToFindPocketing = true - local sPocketing = WM.FindPocketing( 'Pocket', dDiam, dElev) + + local sPocketing, bForceClosedPocket, sTuuid, dMillDiam, dMaxDepth, dThDiam = VerifyPocket( Proc, dDiam, dElev, nRawId, dH, dV) if not sPocketing then - bUseDElevToFindPocketing = false - sPocketing = WM.FindPocketing( 'Pocket', dDiam) - if not sPocketing then - local sErr = 'Error : pocketing not found in library' - EgtOutLog( sErr) - return false, sErr - end - end - if Proc.Double and Proc.Double == 2 then - local sPocketingBackup = sPocketing - sPocketing = WM.FindPocketing( 'Pocket', dDiam, EgtIf( bUseDElevToFindPocketing, dElev, nil), nil, 'H1') - if not IsMachiningOkForDouble( sPocketing) then - Proc.Double = 0 - sPocketing = sPocketingBackup - end - end - -- recupero i dati dell'utensile - local dMillDiam = 20 - local dMaxDepth = 0 - local dThDiam = 100 - local sTuuid - if EgtMdbSetCurrMachining( sPocketing) then - sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam - dMaxDepth = EgtIf( WD.MILL_MAX_DEPTH_AS_MAT, EgtTdbGetCurrToolParam( MCH_TP.MAXMAT), EgtTdbGetCurrToolMaxDepth()) or dMaxDepth - dThDiam = EgtTdbGetCurrToolThDiam() or dThDiam - end - end - -- verifico se la lavorazione (o il suo eventuale doppio) potrebbe danneggiare le parti limitrofe e devo quindi forzare una tasca chiusa - local bForceClosedPocket = false - if WD.AVOID_DAMAGING_OTHER_PARTS then - if IsMachiningDamagingOtherParts( Proc, dMillDiam, nRawId) then - bForceClosedPocket = true - end - if Proc.Double and Proc.Double > 0 then - if IsMachiningDamagingOtherParts( Proc.Mirror, dMillDiam, nRawId) then - bForceClosedPocket = true - end - end + local sErr = 'Error : pocketing not found in library' + EgtOutLog( sErr) + return false, sErr end + -- inserisco la lavorazione di svuotatura local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchFId = WM.AddMachining( Proc, sName, sPocketing) diff --git a/LuaLibs/WallLib.lua b/LuaLibs/WallLib.lua index d78e493..ac1b5b7 100644 --- a/LuaLibs/WallLib.lua +++ b/LuaLibs/WallLib.lua @@ -453,40 +453,42 @@ function WallLib.GetProcessDistanceToNearestParts( Proc) local nPartId = EgtGetFirstPartInRawPart( nRawId) while nPartId do if Proc.PartId ~= nPartId then - local b3Part = EgtGetBBoxGlob( nPartId or GDB_ID.NULL, GDB_BB.STANDARD) - local ptMinPart = b3Part:getMin() - local ptMaxPart = b3Part:getMax() + local nBoxSolidId = EgtGetFirstNameInGroup( nPartId, 'Box') + local b3Solid = EgtGetBBoxGlob( nBoxSolidId or GDB_ID.NULL, GDB_BB.STANDARD) + b3Solid:expand( - 10 * GEO.EPS_SMALL) + local ptMinPart = b3Solid:getMin() + local ptMaxPart = b3Solid:getMax() if Proc.AffectedFaces.Front then - if OverlapsXY( b3Proc, b3Part) then + if OverlapsXY( b3Proc, b3Solid) then vtDistances.Front = 0 - elseif OverlapsX( b3Proc, b3Part) then + elseif OverlapsX( b3Proc, b3Solid) then if ptMaxPart:getY() < ptMinProc:getY() + 100 * GEO.EPS_SMALL then vtDistances.Front = min( vtDistances.Front, max( 0, ptMinProc:getY() - ptMaxPart:getY())) end end end if Proc.AffectedFaces.Back then - if OverlapsXY( b3Proc, b3Part) then + if OverlapsXY( b3Proc, b3Solid) then vtDistances.Back = 0 - elseif OverlapsX( b3Proc, b3Part) then + elseif OverlapsX( b3Proc, b3Solid) then if ptMaxProc:getY() < ptMinPart:getY() + 100 * GEO.EPS_SMALL then vtDistances.Back = min( vtDistances.Back, max( 0, ptMinPart:getY() - ptMaxProc:getY())) end end end if Proc.AffectedFaces.Left then - if OverlapsXY( b3Proc, b3Part) then + if OverlapsXY( b3Proc, b3Solid) then vtDistances.Left = 0 - elseif OverlapsY( b3Proc, b3Part) then + elseif OverlapsY( b3Proc, b3Solid) then if ptMaxPart:getX() < ptMinProc:getX() + 100 * GEO.EPS_SMALL then vtDistances.Left = min( vtDistances.Left, max( 0, ptMinProc:getX() - ptMaxPart:getX())) end end end if Proc.AffectedFaces.Right then - if OverlapsXY( b3Proc, b3Part) then + if OverlapsXY( b3Proc, b3Solid) then vtDistances.Right = 0 - elseif OverlapsY( b3Proc, b3Part) then + elseif OverlapsY( b3Proc, b3Solid) then if ptMaxProc:getX() < ptMinPart:getX() + 100 * GEO.EPS_SMALL then vtDistances.Right = min( vtDistances.Right, max( 0, ptMinPart:getX() - ptMaxProc:getX())) end