diff --git a/Strategies/STR0002/STR0002.lua b/Strategies/STR0002/STR0002.lua index 206f9f6..4182971 100644 --- a/Strategies/STR0002/STR0002.lua +++ b/Strategies/STR0002/STR0002.lua @@ -47,25 +47,37 @@ local function CalcMachinedPercentage( Proc, Machining) return 0 end - local dPercentage = 0 + local dTotalPercentage = 0 + local dPercentageBottom = 0 if Machining[1].bIsApplicable then - dPercentage = ( Machining[1].dElevation - Machining[1].ToolInfo.dResidualDepth) / Machining[1].dElevation + dTotalPercentage = ( Machining[1].dElevation - Machining[1].ToolInfo.dResidualDepth) / Machining[1].dElevation + dPercentageBottom = dTotalPercentage end if Machining[2].bIsApplicable then local dAbsPercentage = ( Machining[2].dElevation - Machining[2].ToolInfo.dResidualDepth) / Machining[2].dElevation - dPercentage = dPercentage + ( 1 - dPercentage) * dAbsPercentage + dTotalPercentage = dTotalPercentage + ( 1 - dTotalPercentage) * dAbsPercentage end if Machining[3].bIsApplicable then - local dAbsPercentage = ( Machining[3].dElevation - Machining[3].ToolInfo.dResidualDepth) / Machining[3].dElevation - dPercentage = dPercentage + ( 1 - dPercentage) * dAbsPercentage + local dAbsPercentage + if Machining[3].bMachAppliedToTunnelFace then + dAbsPercentage = ( Machining[3].dElevation - Machining[3].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation) / Machining[3].dElevation + else + dAbsPercentage = ( Machining[3].dElevation - Machining[3].ToolInfo.dResidualDepth) / Machining[3].dElevation + end + dTotalPercentage = dTotalPercentage + ( 1 - dPercentageBottom) * dAbsPercentage end if Machining[4].bIsApplicable then - local dAbsPercentage = ( Machining[4].dElevation - Machining[4].ToolInfo.dResidualDepth) / Machining[4].dElevation - dPercentage = dPercentage + ( 1 - dPercentage) * dAbsPercentage + local dAbsPercentage + if Machining[3].bMachAppliedToTunnelFace then + dAbsPercentage = ( Machining[4].dElevation - Machining[4].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation) / Machining[4].dElevation + else + dAbsPercentage = ( Machining[4].dElevation - Machining[4].ToolInfo.dResidualDepth) / Machining[4].dElevation + end + dTotalPercentage = dTotalPercentage + ( 1 - dPercentageBottom) * dAbsPercentage end - return dPercentage * 100 + return dTotalPercentage * 100 end ------------------------------------------------------------------------------------------------------------- @@ -178,6 +190,7 @@ local function GetBestPocketingStrategy( Proc) Milling.idFaceToMachine = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].id Milling.idProc = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.id Milling.dElevation = ( Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP + Milling.bMachAppliedToTunnelFace = true end Milling.ToolInfo = {} Milling.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters) @@ -194,7 +207,7 @@ local function GetBestPocketingStrategy( Proc) Milling = {} Milling.bIsApplicable = false if Proc.Topology.sName ~= 'Pocket-5-Blind' and Proc.Topology.sName ~= 'Groove-4-Blind' then - if Proc.Topology.sName == 'Tunnel-4-Through' or Proc.Topology.sName == 'Groove-3-Through' or Proc.Topology.sName == 'Rabbet-2-Through' then + if Proc.MainFaces.TunnelAddedFaces then -- Tunnel-4-Through, Groove-3-Through, Rabbet-2-Through -- se lavoro di fianco, devo comunque rispettare il raggio massimo ToolSearchParameters.dMaxToolDiameter = min( ToolSearchParameters.dMaxToolDiameter, Strategy.Parameters.dMaxCornerRadius * 2) ToolSearchParameters.dElevation = ( Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP @@ -204,6 +217,7 @@ local function GetBestPocketingStrategy( Proc) Milling.idProc = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.id Milling.dElevation = ( Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP Milling.bToolInvert = true + Milling.bMachAppliedToTunnelFace = true else -- 'Groove-3-Blind' ToolSearchParameters.dElevation = Proc.MainFaces.SideFaces[1].dElevation ToolSearchParameters.vtToolDirection = Proc.MainFaces.SideFaces[1].vtN @@ -291,32 +305,33 @@ local function GetBestPocketingStrategy( Proc) end Strategy.Result.sStatus = 'Not-Completed' + Strategy.Result.dMRR = 0 if Machining[1].bIsApplicable then Machining.sTypeMachining = 'Bottom' Strategy.Result.dMRR = Machining[1].dMRR end if Machining[2].bIsApplicable then Machining.sTypeMachining = EgtIf( Machining.sTypeMachining == 'None', 'Bottom2', Machining.sTypeMachining .. '-Bottom2') - Strategy.Result.dMRR = Machining[1].dMRR + Strategy.Result.dMRR = ( Strategy.Result.dMRR + Machining[2].dMRR) / EgtIf( Strategy.Result.dMRR == 0, 1, 2) end if Machining[3].bIsApplicable then if Proc.MainFaces.TunnelAddedFaces then Machining[3].ToolInfo.dResidualDepth = Machining[3].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation + BeamData.MILL_OVERLAP end Machining.sTypeMachining = EgtIf( Machining.sTypeMachining == 'None', 'Side1', Machining.sTypeMachining .. '-Side1') - Strategy.Result.dMRR = Machining[1].dMRR + Strategy.Result.dMRR = ( Strategy.Result.dMRR + Machining[3].dMRR) / EgtIf( Strategy.Result.dMRR == 0, 1, 2) end if Machining[4].bIsApplicable then if Proc.MainFaces.TunnelAddedFaces then Machining[4].ToolInfo.dResidualDepth = Machining[4].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation + BeamData.MILL_OVERLAP end Machining.sTypeMachining = EgtIf( Machining.sTypeMachining == 'None', 'Side2', Machining.sTypeMachining .. '-Side2') - Strategy.Result.dMRR = Machining[1].dMRR + Strategy.Result.dMRR = ( Strategy.Result.dMRR + Machining[4].dMRR) / EgtIf( Strategy.Result.dMRR == 0, 1, 2) end local dMachinedPrercentage = CalcMachinedPercentage( Proc, Machining) Strategy.Result.nCompletionIndex = FeatureData.GetFeatureCompletionIndex( dMachinedPrercentage) - Strategy.Result.sInfo = 'Machining not complete, left ' .. tostring( 100 - dMachinedPrercentage) .. '%' + Strategy.Result.sInfo = 'Machining not complete, left ' .. tostring( 100 - ceil( dMachinedPrercentage)) .. '%' -- se non ho trovato neanche una lavorazione if Machining.sTypeMachining == 'None' then @@ -333,6 +348,7 @@ end ------------------------------------------------------------------------------------------------------------- local function VerifySplitMachiningNeeded( Proc, Part) local vAddId = {} + local vAddIdTunnel = {} local bSplit -- la lunghezza richiede spezzatura @@ -347,6 +363,10 @@ local function VerifySplitMachiningNeeded( Proc, Part) -- recupero gruppo per geometria aggiuntiva local nAddGrpId = BeamLib.GetAddGroup( Part.id) local bStartLeft, bStartRight + local nIdTunnel = nil + if Proc.MainFaces.TunnelAddedFaces then + nIdTunnel = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.id + end -- se feature inizia al di sotto del limite sinistro (coda) if Proc.b3Box:getMin():getX() < Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN then @@ -368,9 +388,13 @@ local function VerifySplitMachiningNeeded( Proc, Part) local dNewMinX = Proc.b3Box:getMin():getX() local dNewMaxX = Proc.b3Box:getMax():getX() local dNewRest = Proc.b3Box:getDimX() + -- creo primo spezzone sulla sinistra if bStartLeft then local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL + -- copio faccia tunnel + local AddIdTunnel = EgtCopyGlob( nIdTunnel, nAddGrpId) or GDB_ID.NULL + -- decido punto spezzatura verso la coda if Proc.b3Box:getDimX() > BeamData.LONGCUT_ENDLEN * 2 then dNewMinX = max( Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN, Proc.b3Box:getMin():getX() + dMaxDiam * 3) @@ -387,12 +411,16 @@ local function VerifySplitMachiningNeeded( Proc, Part) dNewRest = abs( dNewMaxX - dNewMinX) -- taglio della superficie lato sinistro EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, X_AX(), true, GDB_RT.GLOB) -- eseguo inserimento table.insert( vAddId, AddId) + table.insert( vAddIdTunnel, AddIdTunnel) end -- creo spezzone sulla destra if bStartRight then local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL + -- copio faccia tunnel + local AddIdTunnel = EgtCopyGlob( nIdTunnel, nAddGrpId) or GDB_ID.NULL dNewMaxX = min( ( Proc.b3Box:getMax():getX() - dMaxDiam * 3), Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN) if dNewMaxX - dNewMinX < 500 * GEO.EPS_SMALL then dNewMaxX = dNewMinX - BeamData.MILL_OVERLAP @@ -403,8 +431,10 @@ local function VerifySplitMachiningNeeded( Proc, Part) local ptOn = Point3d( dNewMaxX, 0, 0) -- taglio della superficie lato destro EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, -X_AX(), true, GDB_RT.GLOB) -- eseguo inserimento - table.insert( vAddId, 1,AddId) + table.insert( vAddId, 1, AddId) + table.insert( vAddIdTunnel, AddIdTunnel) end -- lavoro il restante if dNewRest > 0 then @@ -412,21 +442,26 @@ local function VerifySplitMachiningNeeded( Proc, Part) local dSplitPartsLen = dNewRest / nSplitParts for i = 1, nSplitParts do local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL + -- copio faccia tunnel + local AddIdTunnel = EgtCopyGlob( nIdTunnel, nAddGrpId) or GDB_ID.NULL local ptOn -- se un solo spezzone, prendo punto massimo e minimo if nSplitParts == 1 then ptOn = Point3d( dNewMinX, 0, 0) -- taglio della superficie lato sinistro EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, -X_AX(), true, GDB_RT.GLOB) ptOn = Point3d( dNewMaxX, 0, 0) -- taglio della superficie lato destro EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, X_AX(), true, GDB_RT.GLOB) else -- eseguo trim sinistro if i ~= 1 or bStartLeft then ptOn = Point3d( dNewMinX, 0, 0) -- taglio della superficie lato sinistro EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, -X_AX(), true, GDB_RT.GLOB) end -- eseguo trim destro dNewMaxX = dNewMinX + dSplitPartsLen @@ -434,12 +469,14 @@ local function VerifySplitMachiningNeeded( Proc, Part) ptOn = Point3d( dNewMaxX, 0, 0) -- taglio della superficie lato destro EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, X_AX(), true, GDB_RT.GLOB) end -- il nuovo minimo è il punto massimo del precedente dNewMinX = dNewMaxX end -- eseguo inserimento in modo da ordinare da X- a X+ - table.insert( vAddId, EgtIf( #vAddId == 0, 1, 2), AddId) + table.insert( vAddId, EgtIf( #vAddId == 0 or not bStartRight, 1, 2), AddId) + table.insert( vAddIdTunnel, EgtIf( #vAddIdTunnel == 0 or not bStartRight, 1, 2), AddIdTunnel) end end else @@ -447,9 +484,9 @@ local function VerifySplitMachiningNeeded( Proc, Part) table.insert( vAddId, Proc.id) end - return vAddId + return vAddId, vAddIdTunnel end - + ------------------------------------------------------------------------------------------------------------- function STR0002.Make( bAddMachining, Proc, Part, CustomParameters) -- carico parametri de default e li aggiorno con quelli passati dal chiamante (potrebbero non essere congruenti) @@ -479,7 +516,7 @@ function STR0002.Make( bAddMachining, Proc, Part, CustomParameters) Strategy.Machining = GetBestPocketingStrategy( Proc) if bAddMachining and Strategy.Result.sStatus ~= 'Not-Applicable' then - local vAddId = VerifySplitMachiningNeeded( Proc, Part) + local vAddId, vAddIdTunnel = VerifySplitMachiningNeeded( Proc, Part) -- si applicano le lavorazioni for i = 1, #vAddId do @@ -491,7 +528,6 @@ function STR0002.Make( bAddMachining, Proc, Part, CustomParameters) Pocketing.nType = MCH_OY.POCKETING Pocketing.nSubType = EgtIf( Proc.Topology.sName == 'Pocket-5-Blind', MCH_POCK_SUB.SPIRALOUT, MCH_POCK_SUB.SPIRALIN) Pocketing.LeadIn.nType = MCH_POCK_LI.ZIGZAG - Pocketing.idProc = Proc.id Pocketing.Steps.dStep = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dStep Pocketing.Steps.dSideStep = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dSideStep Pocketing.nToolIndex = Strategy.Machining[j].ToolInfo.nToolIndex @@ -510,9 +546,10 @@ function STR0002.Make( bAddMachining, Proc, Part, CustomParameters) -- TODO settare parametro per indicare qual è lo spezzone che deve essere fatto dopo il taglio di separazione for k = 1, Proc.nFct do local vtNSplitFace - _, vtNSplitFace = EgtSurfTmFacetCenter( vAddId[i], k - 1, GDB_ID.ROOT) - if vtNSplitFace and AreSameVectorApprox( vtNSplitFace, Strategy.Machining[j].vtFaceNormal) then - Pocketing.Geometry = {{ vAddId[i], k - 1}} + local dIdTm = EgtIf( Strategy.Machining[j].bMachAppliedToTunnelFace, vAddIdTunnel[i], vAddId[i]) + _, vtNSplitFace = EgtSurfTmFacetCenter( dIdTm, k - 1, GDB_ID.ROOT) + if vtNSplitFace and AreSameVectorApprox( vtNSplitFace * EgtIf( Pocketing.bToolInvert, -1, 1), Strategy.Machining[j].vtFaceNormal) then + Pocketing.Geometry = {{ dIdTm, k - 1}} bAreAllApplyOk = bAreAllApplyOk and MachiningLib.AddNewMachining( Proc, Pocketing) break end