diff --git a/LuaLibs/BeamLib.lua b/LuaLibs/BeamLib.lua index 20fb632..34baa4c 100644 --- a/LuaLibs/BeamLib.lua +++ b/LuaLibs/BeamLib.lua @@ -66,39 +66,60 @@ function BeamLib.AddPartEndFace( PartId, b3Solid) end ------------------------------------------------------------------------------------------------------------- -function BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sSide) +function BeamLib.GetPartBoxWithHeadTail( Part, sSide) local _sSide = sSide or '' - -- il box del grezzo contiene sempre il sovramateriale di testa + -- si può usare il box del grezzo che contiene sempre il sovramateriale di testa if _sSide == 'Head' then local b3WithHead = BBox3d( Part.b3Raw) return b3WithHead - -- per aggiungere il materiale di coda si aggiunge il box dell'eventuale grezzo successivo + -- se è l'ultimo pezzo della barra si aggiunge il box dell'eventuale grezzo successivo + -- se non lo è, si estende il box del pezzo fino alla fine della barra elseif _sSide == 'Tail' then local b3WithTail = BBox3d( Part.b3Part) - local nNextRawId = EgtGetNextRawPart( Part.idRaw) - if nNextRawId then - local b3Tail = EgtGetRawPartBBox( nNextRawId) - b3WithTail:Add( b3Tail) + if Part.bIsLastPart then + local nNextRawId = EgtGetNextRawPart( Part.idRaw) + if nNextRawId then + local b3Tail = EgtGetRawPartBBox( nNextRawId) + b3WithTail:Add( b3Tail) + end + else + -- per il punto di inizio barra si parte dal box del grezzo perchè contiene già il sovramateriale spessore lama/catena in coda (la restLength non lo comprende) + local ptXMin = Point3d( Part.b3Raw:getMin():getX() - Part.dRestLength, Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + b3WithTail:Add( ptXMin) end return b3WithTail -- per aggiungere entrambi si procede come per la coda ma partendo dal box del grezzo, che già contiene la testa - else + elseif sSide == 'HeadTail' then local b3WithHeadTail = BBox3d( Part.b3Raw) - local nNextRawId = EgtGetNextRawPart( Part.idRaw) - if nNextRawId then - local b3Tail = EgtGetRawPartBBox( nNextRawId) - b3WithHeadTail:Add( b3Tail) + if Part.bIsLastPart then + local nNextRawId = EgtGetNextRawPart( Part.idRaw) + if nNextRawId then + local b3Tail = EgtGetRawPartBBox( nNextRawId) + b3WithHeadTail:Add( b3Tail) + end + else + -- per il punto di inizio barra si parte dal box del grezzo perchè contiene già il sovramateriale spessore lama/catena in coda (la restLength non lo comprende) + local ptXMin = Point3d( Part.b3Raw:getMin():getX() - Part.dRestLength, Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + b3WithHeadTail:Add( ptXMin) end return b3WithHeadTail + -- sSide non definito, si restituisce il box del pezzo con l'aggiunta dello spessore lama/catena in coda + else + local b3WithSplit = BBox3d( Part.b3Part) + -- per il punto di inizio barra si parte dal box del grezzo perchè contiene già il sovramateriale spessore lama/catena in coda (la restLength non lo comprende) + local ptXMin = Point3d( Part.b3Raw:getMin():getX(), Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + b3WithSplit:Add( ptXMin) + + return b3WithSplit end end diff --git a/LuaLibs/LeadInOutLib.lua b/LuaLibs/LeadInOutLib.lua index 6e70d3f..bc62cf2 100644 --- a/LuaLibs/LeadInOutLib.lua +++ b/LuaLibs/LeadInOutLib.lua @@ -112,7 +112,6 @@ function LeadInOutLib.CalculateLeadInOut( sLeadInOutType, Parameters, OptionalPa -- parametri opzionali local sRestLengthSideForPreSimulation = OptionalParameters.sRestLengthSideForPreSimulation or 'Tail' local bCannotSplitRestLength = OptionalParameters.bCannotSplitRestLength or false - local bMoveAfterSplit = OptionalParameters.bMoveAfterSplit or false local LeadInOut = {} local bIsStartClosed = not Edge.bIsStartOpen @@ -165,15 +164,10 @@ function LeadInOutLib.CalculateLeadInOut( sLeadInOutType, Parameters, OptionalPa local ptEndBladeCenter = ptEndAtDepth + Edge.vtN * Tool.dDiameter / 2 -- box per calcolo uscita lama - -- se è un taglio di testa o coda oppure se di coda e non si sposta dopo separazione va aggiunto il sovramateriale + -- se è un taglio di testa o coda va aggiunto il sovramateriale local b3BoxPartExpanded = BBox3d( Part.b3Part) - if bCannotSplitRestLength or ( not bMoveAfterSplit) then - if ( sRestLengthSideForPreSimulation == 'Head') or Part.bIsLastPart then - b3BoxPartExpanded = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) - elseif sRestLengthSideForPreSimulation == 'Tail' then - local ptPointAtRestLength = Point3d( b3BoxPartExpanded:getMin():getX() - Part.dRestLength, b3BoxPartExpanded:getMin():getY(), b3BoxPartExpanded:getMin():getZ()) - b3BoxPartExpanded:Add( ptPointAtRestLength) - end + if bCannotSplitRestLength then + b3BoxPartExpanded = BeamLib.GetPartBoxWithHeadTail( Part, sRestLengthSideForPreSimulation) end -- il box si espande in tutte le direzioni per contemplare la sicurezza CUT_SIC b3BoxPartExpanded:expand( BeamData.CUT_SIC) diff --git a/LuaLibs/PreSimulationLib.lua b/LuaLibs/PreSimulationLib.lua index 7b43359..b67a9b3 100644 --- a/LuaLibs/PreSimulationLib.lua +++ b/LuaLibs/PreSimulationLib.lua @@ -65,28 +65,27 @@ local function LogOutstroke( ptOnToolTipCenter, vtHead, OptionalParameters) end ------------------------------------------------------------------------------------------------------------- --- costruzione trimesh del grezzo restante in testa o in coda (con leggera sovrapposizione) -local function GetRestlengthSurfTm( Part, sRestLengthSideForPreSimulation) +-- costruzione trimesh del grezzo restante in testa o in coda +local function GetRestlengthSurfTm( Part, sSide) -- si costruisce il box in globale local b3RestLength - if sRestLengthSideForPreSimulation == 'Head' then - local b3PartWithOvermaterial = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) + if sSide == 'Head' then + local b3PartWithOvermaterial = BeamLib.GetPartBoxWithHeadTail( Part, sSide) local ptStartRestLength = Point3d( Part.b3Part:getMax():getX(), Part.b3Part:getMax():getY(), Part.b3Part:getMax():getZ()) local ptEndRestLength = Point3d( b3PartWithOvermaterial:getMax():getX(), Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) b3RestLength = BBox3d( ptStartRestLength, ptEndRestLength) - elseif sRestLengthSideForPreSimulation == 'Tail' then - local b3PartWithOvermaterial = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) - local ptXMin = b3PartWithOvermaterial:getMin():getX() - if not Part.bIsLastPart then - ptXMin = Part.b3Part:getMin():getX() - 2000 - end + elseif sSide == 'Tail' then + local b3PartWithOvermaterial = BeamLib.GetPartBoxWithHeadTail( Part, sSide) + local dXMin = b3PartWithOvermaterial:getMin():getX() + -- si evita sempre di lavorare col motore dietro la coda della barra (potrebbe succedere con barra restante molto corta): in quel caso si deve sempre separare prima + dXMin = min( dXMin, Part.b3Part:getMin():getX() - 2000) local ptStartRestLength = Point3d( Part.b3Part:getMin():getX(), Part.b3Part:getMax():getY(), Part.b3Part:getMax():getZ()) - local ptEndRestLength = Point3d( ptXMin, Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + local ptEndRestLength = Point3d( dXMin, 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() + return nil end -- si crea la trimesh dal box @@ -312,14 +311,14 @@ local function CheckCollisionPoint( ptToolExitToCheck, vtC, vtHead, PreCollision local bCollisionFoundPiece = false if not bCheckOnlyRestlength then local idCheckCollisionTm = Part.idBoxTm - -- se testa o coda attaccate, si considerano nella collisione + -- se testa o coda attaccate, si considerano nella superficie di collisione if bCannotSplitRestLength then - local b3CheckCollision = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, sRestLengthSideForPreSimulation) + local b3CheckCollision = BeamLib.GetPartBoxWithHeadTail( Part, sRestLengthSideForPreSimulation) idCheckCollisionTm = EgtSurfTmBBox( Part.idTempGroup, b3CheckCollision, false, GDB_RT.GLOB) end - bCollisionFoundPiece = EgtTestSurfaceSurface( idCheckCollisionTm, idCollisionSurfTm, BeamData.COLL_SIC) + bCollisionFoundPiece = EgtCDeSolidSolid( idCheckCollisionTm, idCollisionSurfTm, BeamData.COLL_SIC) if not type( bCollisionFoundPiece) == "boolean" then - error( 'EgtTestSurfaceSurface fail') + error( 'Presimulation fail') end if EgtGetDebugLevel() >= 3 and bCollisionFoundPiece then EgtSetColor( idCollisionSurfTm, RED()) @@ -331,16 +330,18 @@ local function CheckCollisionPoint( ptToolExitToCheck, vtC, vtHead, PreCollision end end - -- check collisione con grezzo restante, se con il pezzo non c'è collisione + -- check collisione con grezzo restante, se con il pezzo non c'è collisione e non è un taglio di testa o coda local bCollisionFoundRestLength = false if not ( bCollisionFoundPiece or bCannotSplitRestLength) then local idRestLengthSurfFr = GetRestlengthSurfTm( Part, sRestLengthSideForPreSimulation) - bCollisionFoundRestLength = EgtTestSurfaceSurface( idRestLengthSurfFr, idCollisionSurfTm, BeamData.COLL_SIC) - if not type( bCollisionFoundRestLength) == "boolean" then - error( 'EgtTestSurfaceSurface fail') - end - if EgtGetDebugLevel() >= 3 and bCollisionFoundRestLength then - EgtSetColor( idCollisionSurfTm, ORANGE()) + if idRestLengthSurfFr then + bCollisionFoundRestLength = EgtCDeSolidSolid( idRestLengthSurfFr, idCollisionSurfTm, BeamData.COLL_SIC) + if not type( bCollisionFoundRestLength) == "boolean" then + error( 'Presimulation fail') + end + if EgtGetDebugLevel() >= 3 and bCollisionFoundRestLength then + EgtSetColor( idCollisionSurfTm, ORANGE()) + end end end @@ -448,12 +449,7 @@ function PreSimulationLib.CheckCollision( sBladeEngagement, Parameters, Optional 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 + b3BoxForElevationCheck = BeamLib.GetPartBoxWithHeadTail( Parameters.Part, OptionalParametersCheckCollisionWithAxis.sRestLengthSideForPreSimulation) 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) diff --git a/Strategies/Standard/HEADCUT/HEADCUT.lua b/Strategies/Standard/HEADCUT/HEADCUT.lua index e8f0d55..99575c8 100644 --- a/Strategies/Standard/HEADCUT/HEADCUT.lua +++ b/Strategies/Standard/HEADCUT/HEADCUT.lua @@ -45,8 +45,12 @@ function HEADCUT.Make( bAddMachining, Proc, Part, CustomParameters) if Strategy.Parameters.bExecutePreCut then Strategy.SplitStrategy, Strategy.Result = SPLITCUT.GetMachining( Proc, Part, OptionalParameters) -- se non faccio tagli PRECUT, imposto tabella Result direttamente. Non serve verificare che riesca a rimuovere il materiale extra - if not Strategy.SplitStrategy or #Strategy.SplitStrategy == 0 then - Strategy.Result.sInfo = 'PreCut on head not possible' + -- if not Strategy.SplitStrategy or #Strategy.SplitStrategy == 0 then + -- Strategy.Result.sInfo = 'PreCut on head not possible' + -- end + if Strategy.Result.sStatus ~= 'Completed' then + Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( 'Precut Head not possible') + return false, Strategy.Result end end @@ -94,9 +98,14 @@ function HEADCUT.Make( bAddMachining, Proc, Part, CustomParameters) end if not bExecutePrecutOnly then - local OptionalParametersBladeToWaste = {} - OptionalParametersBladeToWaste.b3BoxDicing = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, 'Head') + -- si recuperano gli estremi del box del materiale di testa da togliere + local b3PartWithHead = BeamLib.GetPartBoxWithHeadTail( Part, 'Head') + local ptStartRestLength = Point3d( Part.b3Part:getMax():getX(), Part.b3Part:getMax():getY(), Part.b3Part:getMax():getZ()) + local ptEndRestLength = Point3d( b3PartWithHead:getMax():getX(), Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + + local OptionalParametersBladeToWaste = {} + OptionalParametersBladeToWaste.b3BoxDicing = BBox3d( ptStartRestLength, ptEndRestLength) OptionalParametersBladeToWaste.dMaxWasteVolume = Strategy.Parameters.dMaxWasteVolume OptionalParametersBladeToWaste.dMaxWasteLength = Strategy.Parameters.dMaxWasteLength OptionalParametersBladeToWaste.bReduceBladePath = Strategy.Parameters.bReduceBladePath @@ -115,6 +124,9 @@ function HEADCUT.Make( bAddMachining, Proc, Part, CustomParameters) TempList = Strategy.Machining[i] table.insert( MachiningsToAdd, TempList) end + else + Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( 'Head machining not possible') + return false, Strategy.Result end end diff --git a/Strategies/Standard/TAILCUT/TAILCUT.lua b/Strategies/Standard/TAILCUT/TAILCUT.lua index 937fb13..f887e56 100644 --- a/Strategies/Standard/TAILCUT/TAILCUT.lua +++ b/Strategies/Standard/TAILCUT/TAILCUT.lua @@ -51,6 +51,11 @@ function TAILCUT.Make( bAddMachining, Proc, Part, CustomParameters) OptionalParameters.bDisableDicing = true Strategy.SplitStrategy, Strategy.Result = SPLITCUT.GetMachining( Proc, Part, OptionalParameters) + if Strategy.Result.sStatus ~= 'Completed' then + Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( 'Split not possible') + return false, Strategy.Result + end + -- se devo rimuovere tutto il restante else -- se abilitato, faccio tagli di PRECUT a zero (come SPLIT) @@ -66,6 +71,12 @@ function TAILCUT.Make( bAddMachining, Proc, Part, CustomParameters) end OptionalParameters.bDisableDicing = true Strategy.SplitStrategy, Strategy.Result = SPLITCUT.GetMachining( Proc, Part, OptionalParameters) + + if Strategy.Result.sStatus ~= 'Completed' then + Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( 'Precut Tail not possible') + return false, Strategy.Result + end + -- se non faccio tagli PRECUT, imposto tabella Result direttamente. Non serve verificare che riesca a rimuovere il materiale extra else Strategy.Result.sStatus = 'Completed' @@ -126,9 +137,14 @@ function TAILCUT.Make( bAddMachining, Proc, Part, CustomParameters) end if not bExecutePrecutOnly then - local OptionalParametersBladeToWaste = {} - OptionalParametersBladeToWaste.b3BoxDicing = BeamLib.GetPartBoxWithHeadTailOvermaterial( Part, 'Tail') + -- si recuperano gli estremi del box del materiale di coda da rimuovere + local b3PartWithTail = BeamLib.GetPartBoxWithHeadTail( Part, 'Tail') + local ptStartRestLength = Point3d( Part.b3Part:getMin():getX(), Part.b3Part:getMax():getY(), Part.b3Part:getMax():getZ()) + local ptEndRestLength = Point3d( b3PartWithTail:getMin():getX(), Part.b3Part:getMin():getY(), Part.b3Part:getMin():getZ()) + + local OptionalParametersBladeToWaste = {} + OptionalParametersBladeToWaste.b3BoxDicing = BBox3d( ptStartRestLength, ptEndRestLength) OptionalParametersBladeToWaste.dMaxWasteVolume = Strategy.Parameters.dMaxWasteVolume OptionalParametersBladeToWaste.dMaxWasteLength = Strategy.Parameters.dMaxWasteLength OptionalParametersBladeToWaste.bReduceBladePath = Strategy.Parameters.bReduceBladePath @@ -153,6 +169,9 @@ function TAILCUT.Make( bAddMachining, Proc, Part, CustomParameters) end table.insert( MachiningsToAdd, TempList) end + else + Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( 'Tail machining not possible') + return false, Strategy.Result end end end diff --git a/StrategyLibs/FACEBYBLADE.lua b/StrategyLibs/FACEBYBLADE.lua index 389b2aa..9afe10f 100644 --- a/StrategyLibs/FACEBYBLADE.lua +++ b/StrategyLibs/FACEBYBLADE.lua @@ -51,22 +51,23 @@ local function GetLeadInOut( Machining, EdgeToMachine, bIsSplitFeature) end -- in caso di percorso ridotto gli attacchi vanno adeguati + --TODO VEDERE SE IL CALCOLO E' CORRETTO if Machining.sEdgeUsage == 'Guillotine' then local dGuillotineLengthToMachine = 1 LeadIn.dStartAddLength = ( - EdgeToMachine.dLength + dGuillotineLengthToMachine) / 2 LeadOut.dEndAddLength = ( - EdgeToMachine.dLength + dGuillotineLengthToMachine) / 2 - LeadIn.dPerpDistance = EdgeToMachine.dElevation + BeamData.CUT_SIC - Machining.dRadialOffset + LeadIn.dPerpDistance = LeadIn.dPerpDistance - Machining.dRadialOffset LeadIn.dTangentDistance = 0 - LeadOut.dPerpDistance = EdgeToMachine.dElevation + BeamData.CUT_SIC - Machining.dRadialOffset + LeadOut.dPerpDistance = LeadOut.dPerpDistance - Machining.dRadialOffset LeadOut.dTangentDistance = 0 LeadIn.dTotalLength = sqrt( LeadIn.dPerpDistance ^ 2 + LeadIn.dTangentDistance ^ 2) LeadOut.dTotalLength = sqrt( LeadOut.dPerpDistance ^ 2 + LeadOut.dTangentDistance ^ 2) elseif Machining.sEdgeUsage == 'Reduced' then LeadIn.dStartAddLength = - FACEBYBLADE.GetPathReductionLength( Machining.nToolIndex, Machining.dMaxRadialOffset) LeadOut.dEndAddLength = - FACEBYBLADE.GetPathReductionLength( Machining.nToolIndex, Machining.dMaxRadialOffset) - LeadIn.dPerpDistance = EdgeToMachine.dElevation + BeamData.CUT_SIC - Machining.dRadialOffset + LeadIn.dPerpDistance = LeadIn.dPerpDistance - Machining.dRadialOffset LeadIn.dTangentDistance = 0 - LeadOut.dPerpDistance = EdgeToMachine.dElevation + BeamData.CUT_SIC - Machining.dRadialOffset + LeadOut.dPerpDistance = LeadOut.dPerpDistance - Machining.dRadialOffset LeadOut.dTangentDistance = 0 LeadIn.dTotalLength = sqrt( LeadIn.dPerpDistance ^ 2 + LeadIn.dTangentDistance ^ 2) LeadOut.dTotalLength = sqrt( LeadOut.dPerpDistance ^ 2 + LeadOut.dTangentDistance ^ 2)