-- Strategia: STR0009 -- Descrizione -- Feature tipo ScarfJoint -- carico librerie local BeamLib = require( 'BeamLib') local BeamData = require( 'BeamDataNew') local MachiningLib = require( 'MachiningLib') local FeatureLib = require( 'FeatureLib') -- strategie di base local BladeToWaste = require( 'BLADETOWASTE') local FaceByMill = require( 'FACEBYMILL') local FaceByBlade = require( 'FACEBYBLADE') local AntiSplintOnFace = require( 'ANTISPLINTONFACE') -- Tabella per definizione modulo local STR0009 = {} local Strategy = {} ------------------------------------------------------------------------------------------------------------- local function GetFacesIdOrder( Proc, Part) local Faces = {} if Proc.nFct == 5 then -- carico gli id delle facce for i = 1, Proc.nFct do Faces[#Faces + 1] = BeamLib.TableCopyDeep( Proc.Faces[i]) end elseif Proc.nFct == 4 then local vtN1 = Proc.Faces[1].vtN local vtN2 = Proc.Faces[2].vtN local nIndex = EgtIf( abs( vtN1:getX()) > abs( vtN2:getX()), 1, 2) for i = nIndex, Proc.nFct do Faces[#Faces + 1] = BeamLib.TableCopyDeep( Proc.Faces[i]) end -- TODO manca il caso in cui mancano facce 4 e 5 else -- Proc.nFct == 3 for i = 2, Proc.nFct do Faces[#Faces + 1] = BeamLib.TableCopyDeep( Proc.Faces[i]) end end return Faces end ------------------------------------------------------------------------------------------------------------- local function GetEdgeToMachine( ClosingFace, idBottomFace) local EdgeToMachine for i = 1, #ClosingFace.Edges do if ClosingFace.Edges[i].idAdjacentFace == idBottomFace then EdgeToMachine = ClosingFace.Edges[i] break end end return EdgeToMachine end ------------------------------------------------------------------------------------------------------------- local function GetScarfJointStrategy( Proc, Part) -- ordino le facce in base al loro numero e al parallelismo delle due facce principali -- faccia 0: superficie tappo (*potrebbe non esserci) -- faccia 1: superficie principale di fondo -- faccia 2: superficie opposta alla faccia 1 -- faccia 3: superficie principale superiore -- faccia 4: superficie di testa (*potrebbe non esserci) -- creo una tabella unica contenente tutte le lavorazioni local Result = {} local Cutting = { Machinings = {}, Result = {}} local AntiSplints = {} local Pocketing = {} Result.dTimeToMachine = 0 local Faces = GetFacesIdOrder( Proc) -- taglio su faccia 4 if Faces[4] and Faces[4].vtN then -- recupero gruppo per geometria addizionale local nAddGrpId = BeamLib.GetAddGroup( Part.id) -- TODO la nuova faccia creata sulla 4 può tagliare faccia 1. In caso tagliasse faccia 1, bisogna calcolare i cubetti con 2 facce Strategy.idFeatureCutPlane = EgtSurfTmPlaneInBBox( nAddGrpId, Faces[4].ptCenter, Faces[4].vtN, Part.b3Part, GDB_RT.GLOB) Cutting.Machinings, Cutting.Result = BladeToWaste.Make( Strategy.idFeatureCutPlane, Part) if Cutting.Result.sStatus == 'Completed' then Cutting.Machinings.bIsApplicable = true end end -- antischeggia facce 1 e 3 local bAreAllAntisplintsApplicable = true if Strategy.Parameters.bAntiSplint then AntiSplints = AntiSplintOnFace.Make( Proc, Part, Faces[2]) for k = 1, #AntiSplints do if not AntiSplints[k].bIsApplicable then bAreAllAntisplintsApplicable = false break end end end -- svuotatura faccia 2 if Faces[2] then local frPock, dL, dW = EgtSurfTmFacetMinAreaRectangle( Proc.id, Faces[2].id, GDB_ID.ROOT) local ToolSearchParameters = {} ToolSearchParameters.sMillShape = 'STANDARD' ToolSearchParameters.vtToolDirection = Faces[2].vtN ToolSearchParameters.dElevation = abs( ( Faces[2].ptCenter - Faces[4].ptCenter) * Faces[2].vtN) ToolSearchParameters.dMaxToolDiameter = min( dL, dW) ToolSearchParameters.ToolInfo = {} ToolSearchParameters.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters) if ToolSearchParameters.ToolInfo.nToolIndex then local Machining = MachiningLib.InitMachiningParameters( MCH_MY.POCKETING) Machining.Geometry = {{ Proc.id, Faces[2].id}} Machining.dElevation = ToolSearchParameters.dElevation Machining.dMaxElev = Machining.dElevation Machining.vtToolDirection = ToolSearchParameters.vtToolDirection Machining.nSubType = MCH_POCK_SUB.SPIRALIN Machining.LeadIn.nType = MCH_POCK_LI.ZIGZAG Machining.Steps.dStep = TOOLS[ToolSearchParameters.ToolInfo.nToolIndex].dStep Machining.Steps.dSideStep = TOOLS[ToolSearchParameters.ToolInfo.nToolIndex].dSideStep Machining.nToolIndex = ToolSearchParameters.ToolInfo.nToolIndex Machining.LeadIn.dTangentDistance = TOOLS[ToolSearchParameters.ToolInfo.nToolIndex].dDiameter / 2 Machining.LeadIn.dElevation = TOOLS[ToolSearchParameters.ToolInfo.nToolIndex].dDiameter / 2 Machining.sDepth = 0 Machining.dResidualDepth = ToolSearchParameters.ToolInfo.dResidualDepth -- TODO vedere se questo parametro con svuotature nuove si può rimuovere Machining.dOpenMinSafe = Strategy.Parameters.dOpenMinSafe Machining.dTimeToMachine = MachiningLib.GetTimeToMachineAllStepsWithLeadInOut( Machining, Part) Result.dTimeToMachine = Result.dTimeToMachine + Machining.dTimeToMachine table.insert( Pocketing, Machining) Pocketing.bIsApplicable = true -- se non sono stati fatti i passaggi antischeggia si verifica che le facce siano a 90°, altrimenti serve passaggio con fresa if not Strategy.Parameters.bAntiSplint or not bAreAllAntisplintsApplicable then local dAngleBetweenFaces = Proc.AdjacencyMatrix[1][2] or 0 -- si fa passaggio con fresa if dAngleBetweenFaces > -90 then local EdgeToMachine = GetEdgeToMachine( Faces[1], Faces[2].id) local CuttingClosingFace = FaceByBlade.Make( Proc, Part, Faces[1], EdgeToMachine) if CuttingClosingFace.bIsApplicable then table.insert( AntiSplints, CuttingClosingFace) end end end end end -- se manca taglio principale, feature non eseguibile if not Cutting.Machinings.bIsApplicable then local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable' EgtOutLog( sErr) Result = FeatureLib.GetStrategyResultNotApplicable( sErr) else local dCompletionPercentage = 100 -- completa se svuotatura eseguita e antisplit eseguiti (o non richiesti) if Pocketing.bIsApplicable and ( bAreAllAntisplintsApplicable or not Strategy.Parameters.bAntiSplint) then Result.sStatus = 'Completed' if bAreAllAntisplintsApplicable then Result.dQuality = FeatureLib.GetStrategyQuality( 'FINE') else Result.dQuality = FeatureLib.GetStrategyQuality( 'STD') end -- altrimenti non completa else Result.dQuality = FeatureLib.GetStrategyQuality( 'STD') Result.sStatus = 'Not-Completed' -- se fa solo svuotatura if Pocketing.bIsApplicable then dCompletionPercentage = 90 Result.sInfo = 'Anti-Split not executed' elseif Strategy.Parameters.bAntiSplint and bAreAllAntisplintsApplicable then dCompletionPercentage = 75 Result.sInfo = 'Pocketing not executed' else dCompletionPercentage = 50 Result.sInfo = 'Only the cut has been executed' end end Result.dCompletionIndex = FeatureLib.GetFeatureCompletionIndex( dCompletionPercentage) end -- creo una tabella unica contenente tutte le lavorazioni local Machinings = {} EgtJoinTables( Machinings, Cutting.Machinings) EgtJoinTables( Machinings, AntiSplints) EgtJoinTables( Machinings, Pocketing) return Machinings, Result end ------------------------------------------------------------------------------------------------------------- function STR0009.Make( bAddMachining, Proc, Part, CustomParameters) -- carico parametri de 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, Part, CustomParameters, StrategyLib.Config) Strategy.Machinings = {} Strategy.Result = {} local bAreAllMachiningsAdded = true -- controlli preliminari if Proc.nFct < 3 or Proc.nFct > 5 then local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. StrategyLib.Config.sStrategyId .. ' not applicable' EgtOutLog( sErr) Strategy.Result = FeatureLib.GetStrategyResultNotApplicable( sErr) return false, Strategy.Result end Strategy.Machinings, Strategy.Result = GetScarfJointStrategy( Proc, Part) -- aggiunta lavorazioni if #Strategy.Machinings > 0 then if bAddMachining and Strategy.Result.sStatus ~= 'Not-Applicable' then -- aggiunge lavorazione for j = 1, #Strategy.Machinings do if Proc.AffectedFaces.bLeft then Strategy.Machinings[j].sStage = 'AfterTail' end bAreAllMachiningsAdded = MachiningLib.AddMachinings( Proc, Strategy.Machinings[j]) end end else Strategy.Result = FeatureLib.GetStrategyResultNotApplicable() end return bAreAllMachiningsAdded, Strategy.Result end ------------------------------------------------------------------------------------------------------------- return STR0009