-- Strategia: STR0010 -- Descrizione -- fresatura perpendicolare -- Feature: cut, longcut, ... -- carico librerie local BeamLib = require( 'BeamLib') local BeamData = require( 'BeamData') local MachiningLib = require( 'MachiningLib') local FeatureLib = require( 'FeatureLib') -- strategie di base local FaceByMill = require('FACEBYMILL') -- Tabella per definizione modulo local STR0010 = {} local Strategy = {} ------------------------------------------------------------------------------------------------------------- local function GetStrategyCompletionPercentage( Machinings) local dCompletionPercentage = 0 local dCompletionPercentageNumerator = 0 local dCompletionPercentageDenominator = 0 local nWeightsCount = 0 for i = 1, #Machinings do local Machining = Machinings[i] local dWeight = Machining.dResultWeight if not dWeight or ( dWeight < 10 * GEO.EPS_SMALL) then dWeight = 1 else nWeightsCount = nWeightsCount + 1 end -- il peso deve essere settato in tutte le lavorazioni o in nessuna if nWeightsCount ~= 0 and nWeightsCount ~= i then error( 'GetWeightedCompletionPercentage : inconsistent weights') end local dWeightedCompletionPercentage = Machining.dCompletionPercentage / 100 * dWeight if Machining.bIsApplicable then dCompletionPercentageNumerator = dCompletionPercentageNumerator + dWeightedCompletionPercentage end dCompletionPercentageDenominator = dCompletionPercentageDenominator + dWeight end dCompletionPercentage = min( 100 * dCompletionPercentageNumerator / dCompletionPercentageDenominator, 100) return dCompletionPercentage end ------------------------------------------------------------------------------------------------------------- local function CompareEdges( EdgeA, EdgeB) -- prima i lati orientati lungo X if abs( EdgeA.vtN:getX()) < abs( EdgeB.vtN:getX()) - 10 * GEO.EPS_SMALL then return true elseif abs( EdgeA.vtN:getX()) > abs( EdgeB.vtN:getX()) + 10 * GEO.EPS_SMALL then return false -- se stessa X si preferiscono i lati più lunghi (nel caso di 5 lati è quello non spezzato) else if EdgeA.dLength > EdgeB.dLength + 10 * GEO.EPS_SMALL then return true elseif EdgeA.dLength < EdgeB.dLength - 10 * GEO.EPS_SMALL then return false -- se stessa lunghezza si preferiscono i lati più in basso -- TODO qui dipenderà dalla lama scelta else if EdgeA.vtN:getZ() > EdgeB.vtN:getZ() + 10 * GEO.EPS_SMALL then return true elseif EdgeA.vtN:getZ() < EdgeB.vtN:getZ() - 10 * GEO.EPS_SMALL then return false -- se stessa Z si preferiscono i lati verso il fronte della trave else if EdgeA.vtN:getY() > EdgeB.vtN:getY() + 10 * GEO.EPS_SMALL then return true elseif EdgeA.vtN:getY() < EdgeB.vtN:getY() - 10 * GEO.EPS_SMALL then return false else return false end end end end end ------------------------------------------------------------------------------------------------------------- local function IsTopologyOk( Proc) if Proc.Topology.sFamily == 'Bevel' then return true else return false end end ------------------------------------------------------------------------------------------------------------- -- TODO modificare funzione e verificare pinzaggio con regioni e area outline local function IsPositionOK( Proc, Part) local bIsFeatureLong = FeatureLib.IsMachiningLong( Proc.b3Box:getDimX(), Part, { dMaxSegmentLength = BeamData.LONGCUT_ENDLEN}) -- se impatta su faccia retro o sotto, controllo fattibilità if Proc.AffectedFaces.bBack then if ( bIsFeatureLong and Proc.b3Box:getDimZ() > Part.dHeight / 2) or ( not bIsFeatureLong and Proc.b3Box:getDimZ() > Part.dHeight / 2) then return false end end if Proc.AffectedFaces.bBottom then if ( bIsFeatureLong and Proc.b3Box:getDimY() > Part.dHeight / 2) or ( not bIsFeatureLong and Proc.b3Box:getDimY() > Part.dHeight / 2) then return false end end -- altrimenti fattibile return true end ------------------------------------------------------------------------------------------------------------- function STR0010.Make( bAddMachining, Proc, Part, CustomParameters) -- carico parametri da default e li aggiorno con quelli passati dal chiamante (potrebbero non essere congruenti) local StrategyLib = {} StrategyLib.Config = STRATEGIES_CONFIG[CustomParameters.sStrategyId] Strategy.sName = StrategyLib.Config.sStrategyId Strategy.Parameters = BeamLib.LoadCustomParametersInStrategy( Proc, CustomParameters, StrategyLib.Config) Strategy.Machinings = {} Strategy.Result = {} -- controllo su topologia if not IsTopologyOk( Proc) then Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( 'Strategy ' .. StrategyLib.Config.sStrategyId .. ' not implemented') return false, Strategy.Result end -- controllo dimensioni if not IsPositionOK( Proc, Part) then Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( 'Feature not machinable in this position') return false, Strategy.Result end -- volume della feature local dFeatureVolume = FeatureLib.GetFeatureVolume( Proc, Part) -- TODO taglio su eventuali facce di chiusura -- eventuali punti di spezzatura local FeatureSplittingPoints = FeatureLib.GetFeatureSplittingPoints( Proc, Part) local bIsSplitFeature = false if #FeatureSplittingPoints > 0 then bIsSplitFeature = true end local dExtendAfterTail = Strategy.Parameters.dExtendAfterTail or max( Part.dDistanceToNextPiece - BeamData.CUT_EXTRA, 0) if MachiningLib.CanExtendAfterTail( Strategy.Parameters.sCanDamageNextPiece, Part) then dExtendAfterTail = 10000 end -- si trova il lato della faccia di fondo da lavorare local BottomEdgesSorted = {} for i = 1, #Proc.MainFaces.BottomFaces[1].Edges do table.insert( BottomEdgesSorted, Proc.MainFaces.BottomFaces[1].Edges[i]) end table.sort( BottomEdgesSorted, CompareEdges) -- lavorazione faccia bottom con fresa local bAreAllMachiningsAdded = true local dDepthToMachine = BottomEdgesSorted[1].dElevation + 5 local OptionalParametersFaceByMill = { dDepthToMachine = dDepthToMachine, bIsSplitFeature = bIsSplitFeature, dExtendAfterTail = dExtendAfterTail} -- primo lato local Milling = {} Milling = FaceByMill.Make( Proc, Part, Proc.MainFaces.BottomFaces[1], BottomEdgesSorted[1], OptionalParametersFaceByMill) if Milling.bIsApplicable then -- lavorazioni da applicare spostate in lista finale table.insert( Strategy.Machinings, Milling) -- calcolo completamento, serve la lista di lavorazioni che comprende le non applicabili Strategy.Result.dCompletionPercentage = GetStrategyCompletionPercentage( Strategy.Machinings) Strategy.Result.nCompletionIndex = FeatureLib.GetFeatureCompletionIndex( Strategy.Result.dCompletionPercentage) local MachiningResult = MachiningLib.GetSplitMachinings( Strategy.Machinings, FeatureSplittingPoints, Part) Strategy.Result.nQuality = FeatureLib.GetStrategyQuality( MachiningResult) Strategy.Result.dTimeToMachine = FeatureLib.GetStrategyTimeToMachine( MachiningResult) Strategy.Result.dMRR = ( dFeatureVolume / Strategy.Result.dTimeToMachine) / pow( 10, 6) if Strategy.Result.dCompletionPercentage > 100 - 10 * GEO.EPS_SMALL then Strategy.Result.sStatus = 'Completed' else Strategy.Result.sStatus = 'Not-Completed' end -- aggiunta lavorazioni if bAddMachining and Strategy.Result.sStatus ~= 'Not-Applicable' then -- aggiunge lavorazione for j = 1, #MachiningResult do bAreAllMachiningsAdded = MachiningLib.AddMachinings( Proc, MachiningResult[j]) end end else Strategy.Result = FeatureLib.GetStrategyResultNotApplicable() end return bAreAllMachiningsAdded, Strategy.Result end ------------------------------------------------------------------------------------------------------------- return STR0010