From 60ffe9da73ec40e90a26d23768dd31d6cbdcabe1 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Wed, 30 Apr 2025 14:46:20 +0200 Subject: [PATCH] - in BLADETOWASTE refactoring e aggiunta funzione CutWithDicing --- StrategyLibs/BLADETOWASTE.lua | 112 ++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 46 deletions(-) diff --git a/StrategyLibs/BLADETOWASTE.lua b/StrategyLibs/BLADETOWASTE.lua index 0029878..0487a58 100644 --- a/StrategyLibs/BLADETOWASTE.lua +++ b/StrategyLibs/BLADETOWASTE.lua @@ -135,7 +135,10 @@ local function GetBestBlade( Proc, Part, Face, OptionalParameters) local nChosenToolIndex local sChosenBladeType - -- parametri opzionali + -- parametri opzionali e default + if not OptionalParameters then + OptionalParameters = {} + end local dMinNzTopBladeIfEqual = OptionalParameters.dMinNzTopBlade or sin(-5) local dMaxNyTopBlade = OptionalParameters.dMaxNyTopBlade or sin(1) local dShortPartLength = OptionalParameters.dShortPartLength or BeamData.LEN_SHORT_PART @@ -309,59 +312,16 @@ local function CutWholeWaste( Proc, Part, OptionalParameters) end -function BLADETOWASTE.Make( ProcOrId, Part, OptionalParameters) - Machinings = {} +local function CutWithDicing( Proc, Part, OptionalParameters) local Result = {} - -- disambiguazione feature vs id trimesh - local Proc = {} - if type( ProcOrId) == "table" then - Proc = ProcOrId - elseif type( ProcOrId) == "number" then - Proc = FeatureLib.GetProcFromTrimesh( ProcOrId, Part) - else - error( 'BLADETOWASTE : Only feature or trimesh supported') - end - - -- controlli preventivi - if Proc.nFct > 2 then - error( 'BladeToWaste : max 2 faces supported') - elseif Proc.nFct == 2 then - if Proc.AdjacencyMatrix[1][2] > 10 * GEO.EPS_SMALL or Proc.AdjacencyMatrix[1][2] < -91 then - error( 'BladeToWaste : angle between faces must be concave and >= 90deg') - end - end - -- parametri opzionali e default if not OptionalParameters then OptionalParameters = {} end local nToolIndex = OptionalParameters.nToolIndex - local dMaxWasteVolume = OptionalParameters.dMaxWasteVolume or 0 - local dMaxWasteLength = OptionalParameters.dMaxWasteLength or 0 local dExtendAfterTail = OptionalParameters.dExtendAfterTail or 10000 - local bSaveAddedGeometries = OptionalParameters.bSaveAddedGeometries - if bSaveAddedGeometries == nil then - bSaveAddedGeometries = true - end - -- dimensioni feature - FeatureInfo.dFeatureVolume = FeatureLib.GetFeatureVolume( Proc, Part) - FeatureInfo.dFeatureMaxDimension = max( Proc.b3Box:getDimX(), Proc.b3Box:getDimY()) - FeatureInfo.bIsFeatureSmall = FeatureInfo.dFeatureVolume < dMaxWasteVolume + 10 * GEO.EPS_SMALL - and FeatureInfo.dFeatureMaxDimension < dMaxWasteLength + 10 * GEO.EPS_SMALL - - -- si taglia tutto lo scarto in una sola lavorazione - -- TODO qui si deve entrare anche se lo spessore lama è maggiore dell'elevazione delle faccia - if Proc.nFct == 1 and FeatureInfo.bIsFeatureSmall then - Machinings, Result = CutWholeWaste( Proc, Part, OptionalParameters) - if Result.sStatus == 'Completed' then - return Machinings, Result - end - end - - -- TODO la lavorazione con cubetti va messa in una funzione - -- lavorazione con cubetti -- scelta faccia da lavorare -- se due facce, la faccia principale Face1 è la più grande local Face1 = Proc.Faces[1] @@ -376,11 +336,13 @@ function BLADETOWASTE.Make( ProcOrId, Part, OptionalParameters) -- scelta lama da sopra o da sotto local sChosenBladeType = '' if not nToolIndex then - nToolIndex, sChosenBladeType = GetBestBlade( Proc, Part, Face1, OptionalParameters) + nToolIndex, sChosenBladeType = GetBestBlade( Proc, Part, Face1) end -- se non trovata lama la lavorazione non è fattibile if not nToolIndex then + Result = FeatureLib.GetStrategyResultNotApplicable( 'Blade not found') + return Machinings, Result end @@ -560,6 +522,64 @@ function BLADETOWASTE.Make( ProcOrId, Part, OptionalParameters) return Machinings, Result end + +function BLADETOWASTE.Make( ProcOrId, Part, OptionalParameters) + Machinings = {} + local Result = {} + + -- disambiguazione feature vs id trimesh + local Proc = {} + if type( ProcOrId) == "table" then + Proc = ProcOrId + elseif type( ProcOrId) == "number" then + Proc = FeatureLib.GetProcFromTrimesh( ProcOrId, Part) + else + error( 'BLADETOWASTE : Only feature or trimesh supported') + end + + -- controlli preventivi + if Proc.nFct > 2 then + error( 'BladeToWaste : max 2 faces supported') + elseif Proc.nFct == 2 then + if Proc.AdjacencyMatrix[1][2] > 10 * GEO.EPS_SMALL or Proc.AdjacencyMatrix[1][2] < -91 then + error( 'BladeToWaste : angle between faces must be concave and >= 90deg') + end + end + + -- parametri opzionali e default + if not OptionalParameters then + OptionalParameters = {} + end + local nToolIndex = OptionalParameters.nToolIndex + local dMaxWasteVolume = OptionalParameters.dMaxWasteVolume or 0 + local dMaxWasteLength = OptionalParameters.dMaxWasteLength or 0 + local dExtendAfterTail = OptionalParameters.dExtendAfterTail or 10000 + local bSaveAddedGeometries = OptionalParameters.bSaveAddedGeometries + if bSaveAddedGeometries == nil then + bSaveAddedGeometries = true + end + + -- dimensioni feature + FeatureInfo.dFeatureVolume = FeatureLib.GetFeatureVolume( Proc, Part) + FeatureInfo.dFeatureMaxDimension = max( Proc.b3Box:getDimX(), Proc.b3Box:getDimY()) + FeatureInfo.bIsFeatureSmall = FeatureInfo.dFeatureVolume < dMaxWasteVolume + 10 * GEO.EPS_SMALL + and FeatureInfo.dFeatureMaxDimension < dMaxWasteLength + 10 * GEO.EPS_SMALL + + -- si taglia tutto lo scarto in una sola lavorazione + -- TODO qui si deve entrare anche se lo spessore lama è maggiore dell'elevazione delle faccia + if Proc.nFct == 1 and FeatureInfo.bIsFeatureSmall then + Machinings, Result = CutWholeWaste( Proc, Part, OptionalParameters) + if Result.sStatus == 'Completed' then + return Machinings, Result + end + end + + -- lavorazione con cubetti + Machinings, Result = CutWithDicing( Proc, Part, OptionalParameters) + + return Machinings, Result +end + ------------------------------------------------------------------------------------------------------------- return BLADETOWASTE \ No newline at end of file