diff --git a/Strategies/Standard/STR0003/STR0003.lua b/Strategies/Standard/STR0003/STR0003.lua index 85d32ee..2049cc8 100644 --- a/Strategies/Standard/STR0003/STR0003.lua +++ b/Strategies/Standard/STR0003/STR0003.lua @@ -60,6 +60,51 @@ local function GetCompletionPercentage( Proc, Result) end +-- TODO si può unificare con eguale funzione in STR0004 +local function SortMachiningsBySegment( MachiningA, MachiningB) + if MachiningA.nSegment > MachiningB.nSegment then + return false + elseif MachiningB.nSegment > MachiningA.nSegment then + return true + else + if TOOLS[ MachiningA.nToolIndex].sFamily == 'SAWBLADE' and TOOLS[ MachiningB.nToolIndex].sFamily == 'MORTISE' then + return true + elseif TOOLS[ MachiningA.nToolIndex].sFamily == 'MORTISE' and TOOLS[ MachiningB.nToolIndex].sFamily == 'SAWBLADE' then + return false + else + if MachiningA.sEdgeType == 'Side' and MachiningB.sEdgeType ~= 'Side' then + return true + elseif MachiningB.sEdgeType == 'Side' and MachiningA.sEdgeType ~= 'Side' then + return false + end + end + end +end + + +local function MergeResults( Result) + local SortedResult = {} + + for i = 1, #Result.Side do + if Result.Side[i].bIsApplicable then + table.insert( SortedResult, Result.Side[i]) + end + end + for i = 1, #Result.Bottom do + if Result.Bottom[i].bIsApplicable then + table.insert( SortedResult, Result.Bottom[i]) + end + end + for i = 1, #Result.Opposite do + if Result.Opposite[i].bIsApplicable then + table.insert( SortedResult, Result.Opposite[i]) + end + end + + return SortedResult +end + + local function AddResult( Machining, Result) table.insert( Result, {}) if not Result.Bottom then @@ -85,6 +130,34 @@ local function AddResult( Machining, Result) end +local function AddMachinings( Proc, Machinings, bAddMachining) + local nIsApplicableCount = 0 + local bAreAllMachiningsAdded = true + + for i = 1, #Machinings do + if Machinings[i].bIsApplicable then + nIsApplicableCount = nIsApplicableCount + 1 + if bAddMachining then + local bIsMachiningAdded + if TOOLS[ Machinings[i].nToolIndex].sFamily == 'SAWBLADE' then + Blade.AddMachiningAllSteps( Proc, Machinings[i]) + elseif TOOLS[ Machinings[i].nToolIndex].sFamily == 'MORTISE' then + Chainsaw.AddMachiningAllSteps( Proc, Machinings[i]) + else + error( 'AddMachinings : tool type not supported') + end + if not bIsMachiningAdded then + bAreAllMachiningsAdded = false + end + end + Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Machinings[i].sMessage + end + end + + return bAreAllMachiningsAdded, nIsApplicableCount +end + + function Blade.AddResult( Cutting) AddResult( Cutting, Blade.Result) end @@ -206,61 +279,35 @@ function STR0003.Make( bAddMachining, Proc, Part, CustomParameters) Strategy.Parameters.bNotCompleteWithBladeRadius = false end end - -- lama - aggiunta lavorazioni - local nIsApplicableCount = 0 - local dFinalCompletionPercentage = 100 - local bAreAllMachiningsAdded = true - for i = 1, #Blade.Result.Bottom do - if Blade.Result.Bottom[i].bIsApplicable then - nIsApplicableCount = nIsApplicableCount + 1 - if bAddMachining then - local bIsMachiningAdded = Blade.AddMachiningAllSteps( Proc, Blade.Result.Bottom[i]) - if not bIsMachiningAdded then - bAreAllMachiningsAdded = false - end - end - Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Blade.Result.Bottom[i].sMessage - end + -- lama - lavorazioni raggruppate in unica lista + Blade.Result.Sorted = MergeResults( Blade.Result) + -- lama - aggiunta eventuali lavorazioni splittate + local vFeatureSplittingPoints = FeatureLib.GetFeatureSplittingPoints( Proc, Part) + if #vFeatureSplittingPoints > 0 then + Blade.Result.Sorted = MachiningLib.GetSplitMachinings( Blade.Result.Sorted, vFeatureSplittingPoints, Part) end - for i = 1, #Blade.Result.Side do - if Blade.Result.Side[i].bIsApplicable then - nIsApplicableCount = nIsApplicableCount + 1 - if bAddMachining then - local bIsMachiningAdded = Blade.AddMachiningAllSteps( Proc, Blade.Result.Side[i]) - if not bIsMachiningAdded then - bAreAllMachiningsAdded = false - end - end - Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Blade.Result.Side[i].sMessage - end - end - for i = 1, #Blade.Result.Opposite do - if Blade.Result.Opposite[i].bIsApplicable then - nIsApplicableCount = nIsApplicableCount + 1 - if bAddMachining then - local bIsMachiningAdded = Blade.AddMachiningAllSteps( Proc, Blade.Result.Opposite[i]) - if not bIsMachiningAdded then - bAreAllMachiningsAdded = false - end - end - Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Blade.Result.Opposite[i].sMessage - end - end - if nIsApplicableCount > 0 then - -- TODO sistemare il calcolo completamento - implementare calcolo area lavorata - if not Strategy.Parameters.bNotCompleteWithBladeRadius and Cutting.dCompletionPercentage > 100 - 10 * GEO.EPS_SMALL then - Strategy.Result.sStatus = 'Completed' - else - Strategy.Result.sStatus = 'Not-Completed' - -- TODO al momento si assume che la percentuale di completamento dell'ultima lavorazione sia quella rilevante - dFinalCompletionPercentage = Cutting.dCompletionPercentage - end - else - Strategy.Result.sStatus = 'Not-Applicable' - Strategy.Parameters.bFinishWithChainSaw = false - end - + -- lama - nessuna lavorazione successiva - aggiunta lavorazioni e calcolo risultati if not Strategy.Parameters.bFinishWithChainSaw then + -- ordinamento + table.sort( Blade.Result.Sorted, SortMachiningsBySegment) + + local nIsApplicableCount = 0 + local bAreAllMachiningsAdded = true + local dFinalCompletionPercentage = 100 + bAreAllMachiningsAdded, nIsApplicableCount = AddMachinings( Proc, Blade.Result.Sorted, bAddMachining) + if nIsApplicableCount > 0 then + -- TODO sistemare il calcolo completamento - implementare calcolo area lavorata + if not Strategy.Parameters.bNotCompleteWithBladeRadius and Cutting.dCompletionPercentage > 100 - 10 * GEO.EPS_SMALL then + Strategy.Result.sStatus = 'Completed' + else + Strategy.Result.sStatus = 'Not-Completed' + -- TODO al momento si assume che la percentuale di completamento dell'ultima lavorazione sia quella rilevante + dFinalCompletionPercentage = Cutting.dCompletionPercentage + end + else + Strategy.Result.sStatus = 'Not-Applicable' + Strategy.Parameters.bFinishWithChainSaw = false + end Strategy.Result.nCompletionIndex = FeatureLib.GetFeatureCompletionIndex( dFinalCompletionPercentage) Strategy.Result.nQuality = FeatureLib.GetFeatureQuality( 'Blade') local MRRParametersBlade = { @@ -425,46 +472,29 @@ function STR0003.Make( bAddMachining, Proc, Part, CustomParameters) end end end - -- sega a catena - aggiunta lavorazioni + -- sega a catena - lavorazioni raggruppate in unica lista + Chainsaw.Result.Sorted = MergeResults( Chainsaw.Result) + -- sega a catena - aggiunta eventuali lavorazioni splittate + if #vFeatureSplittingPoints > 0 then + Chainsaw.Result.Sorted = MachiningLib.GetSplitMachinings( Chainsaw.Result.Sorted, vFeatureSplittingPoints, Part) + end + + -- tutte le lavorazioni di tutti gli utensili in unica lista + local Result = {} + for i = 1, #Blade.Result.Sorted do + table.insert( Result, Blade.Result.Sorted[i]) + end + for i = 1, #Chainsaw.Result.Sorted do + table.insert( Result, Chainsaw.Result.Sorted[i]) + end + -- ordinamento + -- TODO aggiungere ordinamento per utensile + table.sort( Result, SortMachiningsBySegment) + -- aggiunta lavorazioni per tutti gli utensili local nIsApplicableCount = 0 - local dFinalCompletionPercentage = 100 local bAreAllMachiningsAdded = true - for i = 1, #Chainsaw.Result.Bottom do - if Chainsaw.Result.Bottom[i].bIsApplicable then - nIsApplicableCount = nIsApplicableCount + 1 - if bAddMachining then - local bIsMachiningAdded = Chainsaw.AddMachiningAllSteps( Proc, Chainsaw.Result.Bottom[i]) - if not bIsMachiningAdded then - bAreAllMachiningsAdded = false - end - end - Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Chainsaw.Result.Bottom[i].sMessage - end - end - for i = 1, #Chainsaw.Result.Side do - if Chainsaw.Result.Side[i].bIsApplicable then - nIsApplicableCount = nIsApplicableCount + 1 - if bAddMachining then - local bIsMachiningAdded = Chainsaw.AddMachiningAllSteps( Proc, Chainsaw.Result.Side[i]) - if not bIsMachiningAdded then - bAreAllMachiningsAdded = false - end - end - Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Chainsaw.Result.Side[i].sMessage - end - end - for i = 1, #Chainsaw.Result.Opposite do - if Chainsaw.Result.Opposite[i].bIsApplicable then - nIsApplicableCount = nIsApplicableCount + 1 - if bAddMachining then - local bIsMachiningAdded = Chainsaw.AddMachiningAllSteps( Proc, Chainsaw.Result.Opposite[i]) - if not bIsMachiningAdded then - bAreAllMachiningsAdded = false - end - end - Strategy.Result.sInfo = Strategy.Result.sInfo .. '\n' .. Chainsaw.Result.Opposite[i].sMessage - end - end + local dFinalCompletionPercentage = 100 + bAreAllMachiningsAdded, nIsApplicableCount = AddMachinings( Proc, Result, bAddMachining) if nIsApplicableCount > 0 then if Mortising.dCompletionPercentage > 100 - 10 * GEO.EPS_SMALL then Strategy.Result.sStatus = 'Completed' @@ -476,6 +506,7 @@ function STR0003.Make( bAddMachining, Proc, Part, CustomParameters) else Strategy.Result.sStatus = 'Not-Applicable' end + -- calcolo risultati Strategy.Result.nCompletionIndex = FeatureLib.GetFeatureCompletionIndex( dFinalCompletionPercentage) Strategy.Result.nQuality = FeatureLib.GetFeatureQuality( 'Chainsaw') local MRRParametersBlade = { diff --git a/Strategies/Standard/STR0004/STR0004.lua b/Strategies/Standard/STR0004/STR0004.lua index d7b0d87..3a9604f 100644 --- a/Strategies/Standard/STR0004/STR0004.lua +++ b/Strategies/Standard/STR0004/STR0004.lua @@ -57,7 +57,7 @@ local function GetCompletionPercentage( Proc, Result) end -local function CompareMachinings( MachiningA, MachiningB) +local function SortMachiningsBySegment( MachiningA, MachiningB) if MachiningA.nSegment > MachiningB.nSegment then return false elseif MachiningB.nSegment > MachiningA.nSegment then @@ -240,7 +240,8 @@ function STR0004.Make( bAddMachining, Proc, Part, CustomParameters) end -- ordinamento - table.sort( Chainsaw.Result.Sorted, CompareMachinings) + -- TODO aggiungere ordinamento per utensile + table.sort( Chainsaw.Result.Sorted, SortMachiningsBySegment) -- aggiunta lavorazioni local nIsApplicableCount = 0