diff --git a/LuaLibs/PreSimulationLib.lua b/LuaLibs/PreSimulationLib.lua index a08a3b5..52f3762 100644 --- a/LuaLibs/PreSimulationLib.lua +++ b/LuaLibs/PreSimulationLib.lua @@ -70,14 +70,19 @@ local function GetRestlengthSurfTm( Part, sRestLengthSideForPreSimulation) -- si costruisce il box in globale local b3RestLength - if ( sRestLengthSideForPreSimulation == 'Head') or Part.bIsLastPart then - b3RestLength = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) + if sRestLengthSideForPreSimulation == 'Head' then + local b3PartWithOvermaterial = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) + local ptStartRestLength = Point3d( Part.b3Part:getX():getMax(), Part.b3Part:getMax():getY(), Part.b3Part:getMax():getZ()) + local ptEndRestLength = Point3d( b3PartWithOvermaterial:getX():getMax(), Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + b3RestLength = BBox3d( ptStartRestLength, ptEndRestLength) elseif sRestLengthSideForPreSimulation == 'Tail' then - b3RestLength = BBox3d( Part.b3Part) - local ptPointAtRestLength = Point3d( b3RestLength:getMin():getX() - Part.dRestLength, b3RestLength:getMin():getY(), b3RestLength:getMin():getZ()) - b3RestLength:Add( ptPointAtRestLength) + local b3PartWithOvermaterial = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) + local ptStartRestLength = Point3d( Part.b3Part:getX():getMin(), Part.b3Part:getMax():getY(), Part.b3Part:getMax():getZ()) + local ptEndRestLength = Point3d( b3PartWithOvermaterial:getX():getMin(), Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + b3RestLength = BBox3d( ptStartRestLength, ptEndRestLength) + -- caso non testato, non dovrebbe mai finire qui (il default che arriva da fuori è Tail) else - b3RestLength = BBox3d( Part.b3Part) + b3RestLength = BBox3d() end -- si crea la trimesh dal box @@ -271,7 +276,7 @@ function PreSimulationLib.CheckOutOfStrokeFromGeometry( idGeometry, vtHead, nSCC end ------------------------------------------------------------------------------------------------------------- -local function CheckCollisionPoint( ptToolExitToCheck, vtC, vtHead, PreCollisionData, Part, sRestLengthSideForPreSimulation, bCheckOnlyRestlength) +local function CheckCollisionPoint( ptToolExitToCheck, vtC, vtHead, PreCollisionData, Part, bCannotSplitRestLength, sRestLengthSideForPreSimulation, bCheckOnlyRestlength) local ptPivot = GetGlobalPivot( ptToolExitToCheck, vtC, vtHead, PreCollisionData.vtMovePivot) @@ -302,7 +307,13 @@ local function CheckCollisionPoint( ptToolExitToCheck, vtC, vtHead, PreCollision -- check collisione con pezzo local bCollisionFoundPiece = false if not bCheckOnlyRestlength then - bCollisionFoundPiece = EgtTestSurfaceSurface( Part.idBoxTm, idCollisionSurfTm, BeamData.COLL_SIC) + local idCheckCollisionTm = Part.idBoxTm + -- se testa o coda attaccate, si considerano nella collisione + if bCannotSplitRestLength then + local b3CheckCollision = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) + idCheckCollisionTm = EgtSurfTmBBox( Part.idTempGroup, b3CheckCollision, false, GDB_RT.GLOB) + end + bCollisionFoundPiece = EgtTestSurfaceSurface( idCheckCollisionTm, idCollisionSurfTm, BeamData.COLL_SIC) if not type( bCollisionFoundPiece) == "boolean" then error( 'EgtTestSurfaceSurface fail') end @@ -318,7 +329,7 @@ local function CheckCollisionPoint( ptToolExitToCheck, vtC, vtHead, PreCollision -- check collisione con grezzo restante, se con il pezzo non c'è collisione local bCollisionFoundRestLength = false - if not bCollisionFoundPiece then + if not ( bCollisionFoundPiece or bCannotSplitRestLength) then local idRestLengthSurfFr = GetRestlengthSurfTm( Part, sRestLengthSideForPreSimulation) bCollisionFoundRestLength = EgtTestSurfaceSurface( idRestLengthSurfFr, idCollisionSurfTm, BeamData.COLL_SIC) if not type( bCollisionFoundRestLength) == "boolean" then @@ -385,7 +396,7 @@ local function CheckCollisionWithAxis( sAxis, MachiningParameters, OptionalParam -- se non si trova collisione si ritorna se è necessario separare prima di effettuare la lavorazione (ossia non c'è collisione con il pezzo ma c'è con il grezzo restante) for i = 1, #ToolExitPoints do - local bCollisionFoundPiece, bCollisionFoundRestLength = CheckCollisionPoint( ToolExitPoints[i], vtC, vtHead, PreCollisionData, Part, sRestLengthSideForPreSimulation, bCheckOnlyRestlength) + local bCollisionFoundPiece, bCollisionFoundRestLength = CheckCollisionPoint( ToolExitPoints[i], vtC, vtHead, PreCollisionData, Part, bCannotSplitRestLength, sRestLengthSideForPreSimulation, bCheckOnlyRestlength) -- se trovata collisione con pezzo oppure non possibile separazione, è inutile controllare gli altri punti if bCollisionFoundPiece or ( bCannotSplitRestLength and bCollisionFoundRestLength) then @@ -424,12 +435,22 @@ function PreSimulationLib.CheckCollision( sBladeEngagement, Parameters, Optional -- se cubetti in modalità standard (no DownUp) gli assi AB e C si controllano solo con grezzo (ci sarebbe collisione con il materiale già rimosso controllando AB e C con pezzo) if bIsDicing and ( sBladeEngagement == 'Standard') then bCheckOnlyRestlengthForAxisABC = true - -- se l'elevazione reale (rispetto al pezzo) è maggiore del massimo materiale è sempre collisione - -- TODO funzione + -- se l'elevazione reale (rispetto al pezzo + eventuale materiale in testa/coda) è maggiore del massimo materiale è sempre collisione + -- TODO rifare con funzione else local Edge = Parameters.Edge local vtNFace = Parameters.vtNFace local dDepthToMachine = Parameters.dDepthToMachine + local b3BoxForElevationCheck = BBox3d( Parameters.Part.b3Part) + -- se è un taglio di testa o coda va aggiunto il sovramateriale + if OptionalParametersCheckCollisionWithAxis.bCannotSplitRestLength then + if ( OptionalParametersCheckCollisionWithAxis.sRestLengthSideForPreSimulation == 'Head') or Parameters.Part.bIsLastPart then + b3BoxForElevationCheck = BeamLib.GetPartBoxWithHeadTailOvermaterial( Parameters.Part, OptionalParametersCheckCollisionWithAxis.sRestLengthSideForPreSimulation) + elseif OptionalParametersCheckCollisionWithAxis.sRestLengthSideForPreSimulation == 'Tail' then + local ptPointAtRestLength = Point3d( b3BoxForElevationCheck:getMin():getX() - Parameters.Part.dRestLength, b3BoxForElevationCheck:getMin():getY(), b3BoxForElevationCheck:getMin():getZ()) + b3BoxForElevationCheck:Add( ptPointAtRestLength) + end + end -- trimesh rettangolare con un lato corrispondente al lato da lavorare e larghezza come spessore utensile local idTrimesh = EgtSurfTmRectangle( Parameters.Part.idTempGroup, Edge.ptStart, Edge.ptEnd, Edge.ptEnd + vtNFace * Parameters.Tool.dThickness, GDB_RT.GLOB) local vtNTrimesh = EgtSurfTmFacetNormVersor( idTrimesh, 0, GDB_ID.ROOT) @@ -437,7 +458,7 @@ function PreSimulationLib.CheckCollision( sBladeEngagement, Parameters, Optional if not AreSameVectorApprox( Edge.vtN, vtNTrimesh) then EgtInvertSurf( idTrimesh) end - local dRealElevation = EgtSurfTmFacetElevationInBBox( idTrimesh, 0, Parameters.Part.b3Part, true, GDB_ID.ROOT) + local dRealElevation = EgtSurfTmFacetElevationInBBox( idTrimesh, 0, b3BoxForElevationCheck, true, GDB_ID.ROOT) local dRealDepthToMachine = ( dRealElevation - Parameters.Edge.dElevation + dDepthToMachine) if dRealDepthToMachine > Parameters.Tool.dMaxDepth + 10 * GEO.EPS_SMALL then return true diff --git a/Strategies/Standard/HEADCUT/HEADCUT.lua b/Strategies/Standard/HEADCUT/HEADCUT.lua index 927cbf5..e8f0d55 100644 --- a/Strategies/Standard/HEADCUT/HEADCUT.lua +++ b/Strategies/Standard/HEADCUT/HEADCUT.lua @@ -34,6 +34,8 @@ function HEADCUT.Make( bAddMachining, Proc, Part, CustomParameters) Strategy.Result.sInfo = '' local OptionalParameters = { bForceChainSaw = Strategy.Parameters.bForceChainSaw, bReduceBladePath = Strategy.Parameters.bReduceBladePath, dMaxWasteLength = Strategy.Parameters.dMaxWasteLength, dMaxWasteVolume = Strategy.Parameters.dMaxWasteVolume } + OptionalParameters.sRestLengthSideForPreSimulation = 'Head' + OptionalParameters.bCannotSplitRestLength = true local bAreAllMachiningsAdded = true -- si setta che è taglio di testa @@ -102,6 +104,11 @@ function HEADCUT.Make( bAddMachining, Proc, Part, CustomParameters) OptionalParametersBladeToWaste.bCannotSplitRestLength = true Strategy.Machining, _ = BladeToWaste.Make( Proc, Part, OptionalParametersBladeToWaste) + -- se taglio non riuscito, si riprova con il riduci percorso forzato (collisione possibile in separazione pezzi alti) + if ( not Strategy.Machining) or ( #Strategy.Machining == 0) then + OptionalParametersBladeToWaste.bReduceBladePath = true + Strategy.Machining, _ = BladeToWaste.Make( Proc, Part, OptionalParametersBladeToWaste) + end if Strategy.Machining and #Strategy.Machining > 0 then for i = 1, #Strategy.Machining do local TempList = {} diff --git a/Strategies/Standard/TAILCUT/TAILCUT.lua b/Strategies/Standard/TAILCUT/TAILCUT.lua index 030d573..389f692 100644 --- a/Strategies/Standard/TAILCUT/TAILCUT.lua +++ b/Strategies/Standard/TAILCUT/TAILCUT.lua @@ -34,6 +34,8 @@ function TAILCUT.Make( bAddMachining, Proc, Part, CustomParameters) Strategy.Result.sInfo = '' local OptionalParameters = { bForceChainSaw = Strategy.Parameters.bForceChainSaw, bReduceBladePath = Strategy.Parameters.bReduceBladePath, dMaxWasteLength = Strategy.Parameters.dMaxWasteLength, dMaxWasteVolume = Strategy.Parameters.dMaxWasteVolume } + OptionalParameters.sRestLengthSideForPreSimulation = 'Tail' + OptionalParameters.bCannotSplitRestLength = true local bAreAllMachiningsAdded = true local bExecutePrecutOnly = false @@ -132,6 +134,11 @@ function TAILCUT.Make( bAddMachining, Proc, Part, CustomParameters) OptionalParametersBladeToWaste.bCannotSplitRestLength = true Strategy.Machining, _ = BladeToWaste.Make( Proc, Part, OptionalParametersBladeToWaste) + -- se taglio non riuscito, si riprova con il riduci percorso forzato (collisione possibile in separazione pezzi alti) + if ( not Strategy.Machining) or ( #Strategy.Machining == 0) then + OptionalParametersBladeToWaste.bReduceBladePath = true + Strategy.Machining, _ = BladeToWaste.Make( Proc, Part, OptionalParametersBladeToWaste) + end if Strategy.Machining and #Strategy.Machining > 0 then for i = 1, #Strategy.Machining do local TempList = {} diff --git a/StrategyLibs/SPLITCUT.lua b/StrategyLibs/SPLITCUT.lua index 5d8409e..861acb1 100644 --- a/StrategyLibs/SPLITCUT.lua +++ b/StrategyLibs/SPLITCUT.lua @@ -9,6 +9,7 @@ require( 'EgtBase') -- Carico i dati globali local FeatureLib = require( 'FeatureLib') +local BeamLib = require( 'BeamLib') -- strategie di base local BladeToWaste = require('BLADETOWASTE') @@ -31,7 +32,13 @@ function SPLITCUT.GetMachining( Proc, Part, ParametersFromStrategy) else -- Blade Machining, Result = BladeToWaste.Make( Proc, Part, ParametersFromStrategy) - if Machining and #Machining > 0 then + -- se taglio non riuscito, si riprova con il riduci percorso forzato (collisione possibile in separazione pezzi alti) + if ( not Machining) or ( #Machining == 0) then + local NewParametersFromStrategy = BeamLib.TableCopyDeep( ParametersFromStrategy) + NewParametersFromStrategy.bReduceBladePath = true + Machining, Result = BladeToWaste.Make( Proc, Part, NewParametersFromStrategy) + end + if Machining and ( #Machining > 0) then Machining.sTypeMachining = 'Blade' end -- TODO : casi con motosega da completare