diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index e211963..7001d8a 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -661,6 +661,7 @@ end ------------------------------------------------------------------------------------------------------------- -- ritorna l'indice della strategia migliore, tra le due passate local function GetIndexBestStrategyFromComparison( AvailableStrategies, nIndex1, nIndex2) + -- TODO tra nCompletionIndex e dCompletionPercentage ne serve uno solo, valutare se ammettere entrambi così la strategia può scegliere quale restituire local dChosenIndex = 0 -- controllo indici if nIndex1 == 0 and nIndex2 == 0 then @@ -723,18 +724,15 @@ local function GetBestStrategy( vProcSingleRot, Part) if CurrentStrategy.Config and CurrentStrategy.Script then local bStrategyOk -- eseguo la strategia solo come calcolo fattibilità e voto. Non si applicano le lavorazioni. Si passa la Proc e i parametri personalizzati - bStrategyOk, Proc.AvailableStrategies[nIndexCurrentStrategy].Result = CurrentStrategy.Script.Make( false, Proc, Part, Proc.AvailableStrategies[nIndexCurrentStrategy].Parameters) - -- se la strategia è andata a buon fine - if bStrategyOk then - -- scelgo la migliore strategia tra le due - nIndexBestStrategy = GetIndexBestStrategyFromComparison( Proc.AvailableStrategies, nIndexCurrentStrategy, nIndexBestStrategy) + _, Proc.AvailableStrategies[nIndexCurrentStrategy].Result = CurrentStrategy.Script.Make( false, Proc, Part, Proc.AvailableStrategies[nIndexCurrentStrategy].Parameters) + -- scelgo la migliore strategia tra le due + nIndexBestStrategy = GetIndexBestStrategyFromComparison( Proc.AvailableStrategies, nIndexCurrentStrategy, nIndexBestStrategy) - -- se scelta strategia standard, esco subito alla prima che trovo completa - -- TODO serve paraemtro da Beam&Wall ( oppure da confirgurazione) !!!!!!!! - if BEAM.GetFirstCompletedStrategy and nIndexBestStrategy > 0 then - if Proc.AvailableStrategies[nIndexBestStrategy].Result.sStatus == 'Complete' then - break - end + -- se scelta strategia standard, esco subito alla prima che trovo completa + -- TODO serve paraemtro da Beam&Wall ( oppure da confirgurazione) !!!!!!!! + if BEAM.GetFirstCompletedStrategy and nIndexBestStrategy > 0 then + if Proc.AvailableStrategies[nIndexBestStrategy].Result.sStatus == 'Complete' then + break end end diff --git a/Strategies/STR0003/STR0003.lua b/Strategies/STR0003/STR0003.lua index d11ce45..7ca01d7 100644 --- a/Strategies/STR0003/STR0003.lua +++ b/Strategies/STR0003/STR0003.lua @@ -17,8 +17,6 @@ local Chainsaw = {} ------------------------------------------------------------------------------------------------------------- - - local function IsTopologyOk( Proc) if Proc.Topology.sName == 'Pocket-5-Blind' or Proc.Topology.sName == 'Groove-3-Through' or @@ -31,36 +29,25 @@ local function IsTopologyOk( Proc) end end --- TODO da eliminare -function GetToolFromMachining( sMachiningName) - local Tool = {} - if EgtMdbSetCurrMachining( sMachiningName) then - local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - Tool.Name = EgtTdbGetCurrToolParam( MCH_TP.NAME) - Tool.IsCCW = ( EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) < 0) - Tool.Type = EgtTdbGetCurrToolParam( MCH_TP.TYPE) - Tool.Diameter = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or 0 - -- lama - if Tool.Type == MCH_TY.SAW_STD or Tool.Type == MCH_TY.SAW_FLAT then - Tool.Thickness = EgtTdbGetCurrToolParam(MCH_TP.THICK) or 0 - Tool.MaxDepth = EgtTdbGetCurrToolMaxDepth() or 0 - Tool.SideStep = EgtTdbGetCurrToolValInNotes( MCH_TP.USERNOTES, 'SIDESTEP', 'd') - -- sega a catena - elseif Tool.Type == MCH_TY.MORTISE_STD then - Tool.Length = EgtTdbGetCurrToolParam( MCH_TP.LEN) or 0 - Tool.MaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or 0 - Tool.Width = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or 0 - Tool.Thickness = EgtTdbGetCurrToolParam( MCH_TP.THICK) or 0 - Tool.CornerRadius = EgtTdbGetCurrToolParam( MCH_TP.CORNRAD) or 0 - -- altri utensili al momento non previsti - else - error( 'Wrong tool type') - end + +local function GetCompletionPercentage( Proc, Result) + local dNotMachinedArea = 0 + local dCompletionPercentage = 0 + + if Proc.Topology.sName == 'Tunnel' then + dNotMachinedArea = Proc.MainFaces.LongFaces[1].MainEdges.OppositeEdges[1].dLength * ( Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[1].dLength - Result[1].dDepthMachined - Result[2].dDepthMachined) + else + if #Result == 1 then + dNotMachinedArea = Proc.MainFaces.LongFaces[1].MainEdges.BottomEdge.dLength * ( Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[1].dLength - Result[1].dDepthMachined) + elseif #Result == 2 then + dNotMachinedArea = ( Proc.MainFaces.LongFaces[1].MainEdges.BottomEdge.dLength - Result[2].dDepthMachined) * ( Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[1].dLength - Result[1].dDepthMachined) + elseif #Result == 3 then + dNotMachinedArea = ( Proc.MainFaces.LongFaces[1].MainEdges.BottomEdge.dLength - Result[2].dDepthMachined - Result[3].dDepthMachined) * ( Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[1].dLength - Result[1].dDepthMachined) end end + dCompletionPercentage = 100 - dNotMachinedArea / Proc.MainFaces.LongFaces[1].dArea * 100 - return Tool + return dCompletionPercentage end @@ -134,12 +121,7 @@ end local function AddNewMachining( Machining, b3Raw) local sErr = '' - local nOperationId = EgtAddMachining( Machining.sOperationName, Machining.Nsame) - if not nOperationId then - sErr = 'Error adding machining ' .. Machining.sOperationName .. '-' .. Machining.sName - EgtOutLog( sErr) - return false, sErr - end + local nOperationId = EgtCreateMachining( Machining.sOperationName, Machining.nType, TOOLS[Machining.nToolIndex].sName) -- impostazione parametri lavorazione local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) @@ -616,6 +598,7 @@ function STR0003.Make( bAddMachining, Proc, Part, CustomParameters) CustomParameters = BeamLib.GetUpdateCustomParameters( CustomParameters, StrategyLib.Config.Parameters) Strategy.Parameters = BeamLib.LoadCustomParametersInStrategy( CustomParameters) Strategy.Result = {} + Strategy.Result.sInfo = '' Blade.Result = {} Chainsaw.Result = {} @@ -649,40 +632,45 @@ function STR0003.Make( bAddMachining, Proc, Part, CustomParameters) end Blade.Result[#Blade.Result].bCanApply = Cutting.bCanApply Blade.Result[#Blade.Result].sMessage = Cutting.sMessage + Blade.Result[#Blade.Result].dDepthMachined = Cutting.dDepthToMachine if bAddMachining and Cutting.bCanApply then Blade.Result[#Blade.Result].bIsApplyOk, Blade.Result[#Blade.Result].sApplyMessage = Blade.AddMachiningAllSteps( Cutting, b3Raw) end local dBottomDepthToMachine = dResidualDepth -- lato opposto del tunnel if Proc.Topology.sFamily == 'Tunnel' then + Cutting, dResidualDepth = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFaces[1], Proc.MainFaces.LongFaces[1].MainEdges.OppositeEdges[2]) table.insert( Blade.Result, {}) - Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFaces[1], Proc.MainFaces.LongFaces[1].MainEdges.OppositeEdges[2]) Blade.Result[#Blade.Result].sType = 'Tunnel' Blade.Result[#Blade.Result].bCanApply = Cutting.bCanApply Blade.Result[#Blade.Result].sMessage = Cutting.sMessage + Blade.Result[#Blade.Result].dDepthMachined = Cutting.dDepthToMachine if bAddMachining and Cutting.bCanApply then Blade.Result[#Blade.Result].bIsApplyOk, Blade.Result[#Blade.Result].sApplyMessage = Blade.AddMachiningAllSteps( Cutting, b3Raw) end else -- se la lama non è arrivata sul fondo e c'è almeno un lato aperto va lavorato if dResidualDepth > 10 * GEO.EPS_SMALL then - table.insert( Blade.Result, {}) -- eventuale lavorazione di lama - lato della tasca da cui inizia la lavorazione if Proc.MainFaces.LongFaces[1].MainEdges.BottomEdge.IsStartOpen then - Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFaces[1], Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[1]) + Cutting, dResidualDepth = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFaces[1], Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[1]) + table.insert( Blade.Result, {}) Blade.Result[#Blade.Result].sType = 'Side' Blade.Result[#Blade.Result].bCanApply = Cutting.bCanApply Blade.Result[#Blade.Result].sMessage = Cutting.sMessage + Blade.Result[#Blade.Result].dDepthMachined = Cutting.dDepthToMachine if bAddMachining and Cutting.bCanApply then Blade.Result[#Blade.Result].bIsApplyOk, Blade.Result[#Blade.Result].sApplyMessage = Blade.AddMachiningAllSteps( Cutting, b3Raw) end end -- eventuale lavorazione di lama - lato della tasca in cui finisce la lavorazione if Proc.MainFaces.LongFaces[1].MainEdges.BottomEdge.IsEndOpen then - Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFaces, Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[2]) + Cutting, dResidualDepth = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFaces, Proc.MainFaces.LongFaces[1].MainEdges.SideEdges[2]) + table.insert( Blade.Result, {}) Blade.Result[#Blade.Result].sType = 'Side' Blade.Result[#Blade.Result].bCanApply = Cutting.bCanApply Blade.Result[#Blade.Result].sMessage = Cutting.sMessage + Blade.Result[#Blade.Result].dDepthMachined = Cutting.dDepthToMachine if bAddMachining and Cutting.bCanApply then Blade.Result[#Blade.Result].bIsApplyOk, Blade.Result[#Blade.Result].sApplyMessage = Blade.AddMachiningAllSteps( Cutting, b3Raw) end @@ -694,21 +682,37 @@ function STR0003.Make( bAddMachining, Proc, Part, CustomParameters) end if Strategy.Parameters.bApplyOnlyBlade then - -- TODO da rivedere - Strategy.Result.sInfo = Cutting.Message - Strategy.Result.bIsApplyOk = true - if dResidualDepth > 10 * GEO.EPS_SMALL then - Strategy.Result.sStatus = 'Not-Completed' - else - Strategy.Result.sStatus = 'Completed' + local bAreAllApplyOk + local nApplyOkCount = 0 + for i = 1, #Blade.Result do + Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Blade.Result[i].sMessage .. '\n' .. ( Blade.Result[i].sApplyMessage or '') + if Blade.Result[i].bIsApplyOk then + nApplyOkCount = nApplyOkCount + 1 + end end - return Strategy.Result + if bAddMachining then + bAreAllApplyOk = ( nApplyOkCount == #Blade.Result) + end + if not Strategy.Parameters.bContinueOnFailedApply and ( bAreAllApplyOk == false) then + Strategy.Result.sStatus = 'Not-Applicable' + else + Strategy.Result.dCompletionPercentage = GetCompletionPercentage( Proc, Blade.Result) + if Strategy.Result.dCompletionPercentage > 99 + 10 * GEO.EPS_SMALL then + Strategy.Result.sStatus = 'Completed' + else + Strategy.Result.sStatus = 'Not-Completed' + end + end + Strategy.Result.nCompletionIndex = FeatureData.GetFeatureCompletionIndex( Strategy.Result.dCompletionPercentage) + Strategy.Result.nQuality = FeatureData.GetFeatureQuality( 'Blade') + Strategy.Result.dMRR = FeatureData.GetFeatureMRR( TOOLS[Cutting.nToolIndex].dThickness, TOOLS[Cutting.nToolIndex].dSideStep, TOOLS[Cutting.nToolIndex].Feeds.dFeed) + + return bAreAllApplyOk, Strategy.Result end -- sega a catena -- parametri lavorazione con sega a catena - fondo della tasca o tunnel local Mortising = {} - local dResidualDepth = 0 if Proc.Topology == 'Tunnel' then Mortising, dResidualDepth = Chainsaw.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFaces[1], Proc.MainFaces.LongFaces[1].MainEdges.OppositeEdges[1]) else diff --git a/Strategies/STR0003/STR0003Config.lua b/Strategies/STR0003/STR0003Config.lua index 9eac4a6..c357384 100644 --- a/Strategies/STR0003/STR0003Config.lua +++ b/Strategies/STR0003/STR0003Config.lua @@ -3,8 +3,9 @@ local STR0003Data = { sStrategyId = 'STR0003', Parameters = { - { sName = 'bApplyOnlyBlade', sValue = 'false', sDescriptionShort = 'Blade only', sDescriptionLong = 'Machining with blade only and avoid chainsaw', sType = 'b', sMessageId = '', sMinUserLevel = '1'}, - { sName = 'bForceLongcutBlade', sValue = 'false', sDescriptionShort = 'Force ripping blade', sDescriptionLong = 'Force the use of ripping blade, designed for cuts parallel to the grain', sType = 'b', sMessageId = '', sMinUserLevel = '1'} + { sName = 'bApplyOnlyBlade', sValue = 'true', sDescriptionShort = 'Blade only', sDescriptionLong = 'Machining with blade only and avoid chainsaw', sType = 'b', sMessageId = '', sMinUserLevel = '1'}, + { sName = 'bForceLongcutBlade', sValue = 'false', sDescriptionShort = 'Force ripping blade', sDescriptionLong = 'Force the use of ripping blade, designed for cuts parallel to the grain', sType = 'b', sMessageId = '', sMinUserLevel = '1'}, + { sName = 'bContinueOnFailedApply', sValue = 'true', sDescriptionShort = 'Continue to next machining on failed apply', sDescriptionLong = 'If one machining of the strategy fails to apply continue with the others', sType = 'b', sMessageId = '', sMinUserLevel = '9'} } }