Files
databeamnew/Strategies/STR0003/STR0003.lua
T
luca.mazzoleni 7165db47f6 - modifiche per aggiunta strategia BladePlusChain
- in BeamExec versione  primordiale di FindBlade
2024-05-17 18:45:36 +02:00

757 lines
32 KiB
Lua

-- Strategia: STR0003
-- Descrizione
-- Lama + motosega per slot
-- Feature: tipo lapjoint
-- carico librerie
local BeamLib = require( 'BeamLib')
local BeamData = require( 'BeamData')
local MachiningLib = require( 'MachiningLib')
local FeatureData = require( 'FeatureData')
-- Tabella per definizione modulo
local STR0003 = {}
local Strategy = {}
local Blade = {}
local Chainsaw = {}
-------------------------------------------------------------------------------------------------------------
local function IsTopologyOk( Proc)
if Proc.TopologyLongName == 'Pocket-Blind-RightAngles-Parallel-5' or
Proc.TopologyLongName == 'Groove-Through-RightAngles-Parallel-3' or
Proc.TopologyLongName == 'Groove-Blind-RightAngles-Parallel-4' or
Proc.TopologyLongName == 'Tunnel-Through-RightAngles-Parallel-4' then
return true
else
return false
end
end
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
end
end
return Tool
end
function CalculateLeadInOut( Machining, EdgeToMachine)
-- TODO implementare le funzioni di Tool Collision Avoidance (vedi wiki e FacesBysaw -> CalcLeadInOutPerpGeom)
-- si determina l'eventuale riduzione da applicare in caso di inizio o fine chiusi
local bIsMortising = ( Machining.Type == MCH_OY.MORTISING)
local dAddLengthToReduce = 0
if bIsMortising then
dAddLengthToReduce = Machining.Tool.Diameter / 2
else
dAddLengthToReduce = sqrt( Machining.Depth * Machining.Tool.Diameter - Machining.Depth * Machining.Depth)
end
if Machining.Invert then
Machining.IsStartClosed, Machining.IsEndClosed = Machining.IsEndClosed, Machining.IsStartClosed
end
local LeadIn = {}
local LeadOut = {}
LeadIn.StartAddLength = 0
LeadOut.EndAddLength = 0
if not bIsMortising then
LeadIn.Type = MCH_MILL_LI.LINEAR
LeadOut.Type = MCH_MILL_LI.LINEAR
LeadIn.TangentDistance = 0
LeadOut.TangentDistance = 0
if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then
LeadIn.PerpDistance = EdgeToMachine.Elevation + BeamData.CUT_SIC
LeadOut.PerpDistance = EdgeToMachine.Elevation + BeamData.CUT_SIC
else
LeadIn.PerpDistance = BeamData.CUT_SIC
LeadOut.PerpDistance = BeamData.CUT_SIC
end
LeadIn.Elevation = 0
LeadOut.Elevation = 0
LeadIn.CompLength = 0
LeadOut.CompLength = 0
if Machining.IsStartClosed and Machining.IsEndClosed then
LeadIn.StartAddLength = -dAddLengthToReduce
LeadOut.EndAddLength = -dAddLengthToReduce
elseif Machining.IsStartClosed then
LeadIn.StartAddLength = -dAddLengthToReduce
-- eventuale correzione per accorciamento maggiore di larghezza tasca
LeadOut.EndAddLength = max( -LeadIn.StartAddLength - EdgeToMachine.Length + 10 * BeamData.CUT_EXTRA, BeamData.CUT_EXTRA)
elseif Machining.IsEndClosed then
LeadOut.EndAddLength = -dAddLengthToReduce
-- eventuale correzione per accorciamento maggiore di larghezza tasca
LeadIn.StartAddLength = max( -LeadOut.EndAddLength - EdgeToMachine.Length + 10 * BeamData.CUT_EXTRA, BeamData.CUT_EXTRA)
else
LeadIn.StartAddLength = BeamData.CUT_EXTRA
LeadOut.EndAddLength = BeamData.CUT_EXTRA
end
else
if Machining.IsStartClosed then
LeadIn.StartAddLength = -dAddLengthToReduce
else
LeadIn.StartAddLength = BeamData.CUT_EXTRA
end
if Machining.IsEndClosed then
LeadOut.EndAddLength = -dAddLengthToReduce
else
LeadOut.EndAddLength = BeamData.CUT_EXTRA
end
end
return LeadIn, LeadOut
end
function ApplyMachining( Machining, b3Raw)
local sErr = ''
local nOperationId = EgtAddMachining( Machining.OperationName, Machining.Name)
if not nOperationId then
sErr = 'Error adding machining ' .. Machining.OperationName .. '-' .. Machining.Name
EgtOutLog( sErr)
return false, sErr
end
-- impostazione parametri lavorazione
local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES)
EgtSetMachiningGeometry( Machining.Geometry)
EgtSetMachiningParam( MCH_MP.FACEUSE, Machining.Faceuse)
EgtSetMachiningParam( MCH_MP.SCC, Machining.SCC)
EgtSetMachiningParam( MCH_MP.INVERT, Machining.Invert)
EgtSetMachiningParam( MCH_MP.WORKSIDE, Machining.Workside)
EgtSetMachiningParam( MCH_MP.TOOLINVERT, Machining.ToolInvert)
EgtSetMachiningParam( MCH_MP.OFFSR, Machining.RadialOffset)
EgtSetMachiningParam( MCH_MP.OFFSL, Machining.LongitudinalOffset)
if Machining.Type ~= MCH_OY.MORTISING then
EgtSetMachiningParam( MCH_MP.LEADINTYPE, Machining.LeadIn.Type)
EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, Machining.LeadOut.Type)
EgtSetMachiningParam( MCH_MP.LITANG, Machining.LeadIn.TangentDistance)
EgtSetMachiningParam( MCH_MP.LOTANG, Machining.LeadOut.TangentDistance)
EgtSetMachiningParam( MCH_MP.LIPERP, Machining.LeadIn.PerpDistance)
EgtSetMachiningParam( MCH_MP.LOPERP, Machining.LeadOut.PerpDistance)
EgtSetMachiningParam( MCH_MP.LIELEV, Machining.LeadIn.Elevation)
EgtSetMachiningParam( MCH_MP.LOELEV, Machining.LeadOut.Elevation)
EgtSetMachiningParam( MCH_MP.LICOMPLEN, Machining.LeadIn.CompLength)
EgtSetMachiningParam( MCH_MP.LOCOMPLEN, Machining.LeadOut.CompLength)
end
EgtSetMachiningParam( MCH_MP.STARTADDLEN, Machining.LeadIn.StartAddLength)
EgtSetMachiningParam( MCH_MP.ENDADDLEN, Machining.LeadOut.EndAddLength)
if Machining.Steps then
if Machining.Steps.StepType then
EgtSetMachiningParam( MCH_MP.STEPTYPE, Machining.Steps.StepType)
end
if Machining.Steps.StepLength then
EgtSetMachiningParam( MCH_MP.STEP, Machining.Steps.StepLength)
end
end
EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, BeamLib.GetBlockedAxis( Machining.Name, Machining.BlockedAxis.Orientation, b3Raw, Machining.BlockedAxis.VtN, Machining.BlockedAxis.VtOut))
if Machining.Type == MCH_OY.MORTISING then
EgtSetMachiningParam( MCH_MP.INITANGS, BeamLib.GetChainSawInitAngs( Machining.SuggestedAngles.VtN, Machining.SuggestedAngles.VtOrtho, Machining.SuggestedAngles.Index))
end
EgtSetMachiningParam( MCH_MP.OVERL, Machining.Overlap)
EgtSetMachiningParam( MCH_MP.STARTPOS, max( Machining.StartSafetyLength, EgtGetMachiningParam( MCH_MP.STARTPOS)))
if Machining.MaxElev then
sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', Machining.MaxElev)
end
EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes)
local bIsApplyOk = MachiningLib.ApplyMachining( true, false)
if not bIsApplyOk then
local nErr
nErr, sErr = EgtGetLastMachMgrError()
-- se mortasatura e l'errore è compatibile (Axes values not calculable) si prova con l'altra configurazione dell'asse bloccato
-- TODO valutare se c'è modo di capire preventivamente la configurazione dell'asse bloccato e quindi rimuovere questa parte di codice
if Machining.Type == MCH_OY.MORTISING and nErr == 2507 then
if Machining.BlockedAxis.Orientation == 'perpendicular' then
Machining.BlockedAxis.Orientation = 'parallel'
else
Machining.BlockedAxis.Orientation = 'perpendicular'
end
EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, BeamLib.GetBlockedAxis( Machining.Name, Machining.BlockedAxis.Orientation, b3Raw, Machining.BlockedAxis.VtN, Machining.BlockedAxis.VtOut))
if Machining.SuggestedAngles.Index == 1 then
Machining.SuggestedAngles.Index = 2
else
Machining.SuggestedAngles.Index = 1
end
EgtSetMachiningParam( MCH_MP.INITANGS, BeamLib.GetChainSawInitAngs( Machining.SuggestedAngles.VtN, Machining.SuggestedAngles.VtOrtho, Machining.SuggestedAngles.Index))
sErr = ''
bIsApplyOk = EgtApplyMachining( true, false)
end
if not bIsApplyOk then
nErr, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nOperationId, false)
return false, sErr
end
end
return true, sErr
end
function Blade.GetSCC( vtMachiningDirection)
-- TODO implementare SCC come per FacesBySaw
local nSCC = MCH_SCC.NONE
if AreSameVectorApprox( vtMachiningDirection, Z_AX()) then
nSCC = MCH_SCC.ADIR_ZP
elseif AreOppositeVectorApprox( vtMachiningDirection, Z_AX()) then
nSCC = MCH_SCC.ADIR_ZM
elseif AreSameVectorApprox( vtMachiningDirection, Y_AX()) then
nSCC = MCH_SCC.ADIR_YP
elseif AreOppositeVectorApprox( vtMachiningDirection, Y_AX()) then
nSCC = MCH_SCC.ADIR_YM
elseif AreSameVectorApprox( vtMachiningDirection, X_AX()) then
nSCC = MCH_SCC.ADIR_XP
elseif AreOppositeVectorApprox( vtMachiningDirection, X_AX()) then
nSCC = MCH_SCC.ADIR_XM
end
return nSCC
end
function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine)
local Cutting = {}
Cutting.CanApply = true
Cutting.Message = ''
Cutting.ProcId = Proc.id
local dPocketHeight = 0
if Proc.Topology == 'Tunnel' then
dPocketHeight = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Height
else
if FaceToMachine.Type == 'Long' then
dPocketHeight = Proc.MainFaces.BottomFace.Edges.SideEdges[1].Length
elseif FaceToMachine.Type == 'Side' then
dPocketHeight = Proc.MainFaces.BottomFace.Edges.LongEdges[1].Length
end
end
-- ricerca utensile
local ToolSearchParameters = {}
ToolSearchParameters.dElevation = EdgeToMachine.Elevation
ToolSearchParameters.vtToolDirection = EdgeToMachine.ToolDirection
ToolSearchParameters.bAllowTopHead = true
ToolSearchParameters.bAllowBottomHead = false
ToolSearchParameters.bForceLongcutBlade = Strategy.Parameters.bForceLongcutBlade
Cutting.Tool = MachiningLib.FindBlade( Proc, ToolSearchParameters)
if not Cutting.Name then
Cutting.Message = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable - saw blade not found'
Cutting.CanApply = false
EgtOutLog( Cutting.Message)
return Cutting
end
Cutting.Type = MCH_OY.MILLING
Cutting.Tool = GetToolFromMachining( Cutting.Name)
-- verifica dimensioni tasca compatibili
-- se tasca meno spessa della lama la strategia non è applicabile
if Cutting.Tool.Thickness > dPocketHeight + 10 * GEO.EPS_SMALL then
Cutting.Message = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable - pocket too narrow for saw blade thickness'
Cutting.CanApply = false
EgtOutLog( Cutting.Message)
return Cutting
end
if #( Proc.MainFaces.SideFaces) > 1 then
-- se tasca più stretta della lama la strategia non è applicabile
if Cutting.Tool.Diameter > EdgeToMachine.Length + 10 * GEO.EPS_SMALL then
Cutting.Message = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable - pocket too narrow for saw blade diameter'
Cutting.CanApply = false
EgtOutLog( Cutting.Message)
return Cutting
end
end
-- parametri della lavorazione
-- inizio e fine aperti o chiusi
Cutting.IsStartClosed = not EdgeToMachine.IsStartOpen
Cutting.IsEndClosed = not EdgeToMachine.IsEndOpen
-- lato di lavoro e inversioni
if Cutting.Tool.IsCCW then
Cutting.Workside = MCH_MILL_WS.RIGHT
Cutting.Invert = true
else
Cutting.Workside = MCH_MILL_WS.LEFT
Cutting.Invert = false
end
if EdgeToMachine.Elevation < -10 * GEO.EPS_SMALL then
Cutting.Invert = not Cutting.Invert
end
-- TODO gestire lama da sotto e lama downUp
if FaceToMachine.VtN:getZ() < - 10 * GEO.EPS_SMALL then
Cutting.ToolInvert = true
Cutting.Invert = not Cutting.Invert
else
Cutting.ToolInvert = false
end
-- profondità e offset radiale
if Cutting.Tool.MaxDepth > abs( EdgeToMachine.Elevation) - 10 * GEO.EPS_SMALL then
-- TODO la depth dovrebbe essere quella del machining
Cutting.Depth = abs( EdgeToMachine.Elevation)
if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then
Cutting.RadialOffset = 0
else
Cutting.RadialOffset = EdgeToMachine.Elevation
end
else
Cutting.Depth = Cutting.Tool.MaxDepth - 1
if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then
Cutting.RadialOffset = EdgeToMachine.Elevation - Cutting.Depth
else
Cutting.RadialOffset = -Cutting.Depth
end
if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL and Strategy.Parameters.bApplyOnlyBlade then
Cutting.Message = 'Feature '.. Proc.idFeature .. ' : sawblade elevation (' .. EgtNumToString( EdgeToMachine.Elevation, 1) .. ') bigger than max tool depth (' .. EgtNumToString( Cutting.Depth, 1) .. ')'
EgtOutLog( Cutting.Message)
end
end
-- step verticale e offset longitudinale
Cutting.Steps = MachiningLib.GetMachiningSteps( dPocketHeight, Cutting.Tool.Thickness)
Cutting.Steps.StepType = MCH_MILL_ST.ONEWAY
Cutting.MaxElev = Cutting.Steps.StepLength * Cutting.Steps.Count - 10 * GEO.EPS_SMALL
if Cutting.ToolInvert and Cutting.Steps.Count > 1 then
Cutting.LongitudinalOffset = - dPocketHeight
else
Cutting.LongitudinalOffset = 0
end
-- distanza di sicurezza
Cutting.StartSafetyLength = 10
-- overlap
Cutting.Overlap = 0
-- faceuse
if EdgeToMachine.Elevation > - 10 * GEO.EPS_SMALL then
Cutting.Faceuse = BeamLib.GetNearestOrthoOpposite( EdgeToMachine.ToolDirection)
else
Cutting.Faceuse = BeamLib.GetNearestOrthoOpposite( -EdgeToMachine.ToolDirection)
end
-- SCC
Cutting.SCC = Blade.GetSCC( EdgeToMachine.ToolDirection)
-- asse bloccato
Cutting.BlockedAxis = {}
Cutting.BlockedAxis.Orientation = 'perpendicular'
Cutting.BlockedAxis.VtN = FaceToMachine.VtN
Cutting.BlockedAxis.VtOut = EgtIf( FaceToMachine.VtN:getX() > 0, X_AX(), -X_AX())
-- approccio e retrazione
Cutting.LeadIn, Cutting.LeadOut = CalculateLeadInOut( Cutting, EdgeToMachine)
-- eventuale step orizzontale
Cutting.HorizontalSteps = {}
if Cutting.Tool.SideStep then
Cutting.HorizontalSteps = MachiningLib.GetMachiningSteps( Cutting.Depth, Cutting.Tool.SideStep)
else
Cutting.HorizontalSteps.Count = 1
Cutting.HorizontalSteps.StepLength = 0
end
-- geometria
Cutting.Geometry = {{Proc.id, FaceToMachine.id}}
-- nome operazione
Cutting.OperationName = 'Cut_' .. ( EgtGetName( Cutting.ProcId) or tostring( Cutting.ProcId)) .. '_' .. tostring( FaceToMachine.id + 1)
-- eventuale avviso di danneggiamento pezzo successivo
-- TODO da sostituire con check se si riesce a separare e il grezzo dietro è lungo a sufficienza
local dOffsideLength = max( Cutting.LeadIn.StartAddLength, Cutting.LeadOut.EndAddLength) + Cutting.Tool.Diameter / 2 + 10 * GEO.EPS_SMALL
if ( not Proc.Tail or Proc.AdvTail) and Proc.AffectedFaces.Left and ( Proc.DistanceToNextPart < dOffsideLength) then
local sDamageNextPieceMessage = 'Feature '.. Proc.idFeature .. ' : sawblade can damage next piece.'
if #Cutting.Message > 0 then
Cutting.Message = Cutting.Message .. '\n' .. sDamageNextPieceMessage
else
Cutting.Message = sDamageNextPieceMessage
end
EgtOutLog( sDamageNextPieceMessage)
end
return Cutting
end
function Blade.ApplyAllSteps( Cutting, b3Raw)
local bIsCuttingOk = false
local sCuttingApplyMessage = ''
local dOriginalRadialOffset = Cutting.RadialOffset
local dOriginalLeadInPerpDistance = Cutting.LeadIn.PerpDistance
local dOriginalLeadOutPerpDistance = Cutting.LeadOut.PerpDistance
for i = Cutting.HorizontalSteps.Count, 1, -1 do
Cutting.RadialOffset = dOriginalRadialOffset + Cutting.HorizontalSteps.StepLength * ( i - 1)
-- update distanza perpendicolare attacco per contemplare l'offset applicato
Cutting.LeadIn.PerpDistance = dOriginalLeadInPerpDistance - Cutting.RadialOffset
Cutting.LeadOut.PerpDistance = dOriginalLeadOutPerpDistance - Cutting.RadialOffset
-- applicazione lavorazione
bIsCuttingOk, sCuttingApplyMessage = ApplyMachining( Cutting, b3Raw)
-- update messaggi
if sCuttingApplyMessage and #sCuttingApplyMessage > 0 then
sCuttingApplyMessage = sCuttingApplyMessage .. 'Apply : ' .. sCuttingApplyMessage .. '\n'
end
end
return bIsCuttingOk, sCuttingApplyMessage
end
function Chainsaw.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine)
local Mortising = {}
Mortising.CanApply = true
Mortising.Message = ''
Mortising.ProcId = Proc.id
local bNeedToMachineOtherSide = false
-- TODO da sostituire con flag da passare a Find che sa già il raggio
local dTestCornerRadius = 43
-- OneSide | OneSideAndExtend | BothSides | BothSidesAndExtend
local sMortisingType
local dPocketHeight = 0
if Proc.Topology == 'Tunnel' then
dPocketHeight = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Height
else
if FaceToMachine.Type == 'Long' then
dPocketHeight = Proc.MainFaces.BottomFace.Edges.SideEdges[1].Length
elseif FaceToMachine.Type == 'Side' then
dPocketHeight = Proc.MainFaces.BottomFace.Edges.LongEdges[1].Length
end
end
-- ricerca lavorazione
-- TODO da sostituire con ricerca utensile
if Proc.Topology == 'Tunnel' then
Mortising.Name = ML.FindSawing( 'Sawing', abs( EdgeToMachine.Elevation) + dTestCornerRadius + BeamData.CUT_EXTRA_MIN)
sMortisingType = 'OneSideAndExtend'
if not Mortising.Name then
Mortising.Name = ML.FindSawing( 'Sawing', abs( EdgeToMachine.Elevation) / 2 + dTestCornerRadius + BeamData.CUT_EXTRA_MIN)
sMortisingType = 'BothSidesAndExtend'
end
elseif EdgeToMachine.Type == 'Side' and #( Proc.MainFaces.SideFaces) == 0 then
Mortising.Name = ML.FindSawing( 'Sawing', abs( EdgeToMachine.Elevation) / 2 + dTestCornerRadius + BeamData.CUT_EXTRA_MIN)
sMortisingType = 'BothSidesAndExtend'
else
Mortising.Name = ML.FindSawing( 'Sawing', abs( EdgeToMachine.Elevation))
sMortisingType = 'OneSide'
end
if not Mortising.Name then
Mortising.Name = ML.FindSawing( 'Sawing', nil, nil, 'Longest')
if sMortisingType == 'BothSidesAndExtend' then
sMortisingType = 'BothSides'
elseif sMortisingType == 'OneSideAndExtend' then
sMortisingType = 'OneSide'
end
end
if not Mortising.Name then
Mortising.Message = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable - chainsaw not found'
Mortising.CanApply = false
EgtOutLog( Mortising.Message)
return Mortising, false
end
Mortising.Type = MCH_OY.MORTISING
Mortising.Tool = GetToolFromMachining( Mortising.Name)
-- verifica dimensioni tasca compatibili
-- se tasca meno spessa della sega a catena la strategia non è applicabile
if Mortising.Tool.Thickness > dPocketHeight + 10 * GEO.EPS_SMALL then
Mortising.Message = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable - pocket too narrow for chainsaw thickness'
Mortising.CanApply = false
EgtOutLog( Mortising.Message)
return Mortising, false
end
if #( Proc.MainFaces.SideFaces) > 1 then
-- se tasca più stretta della sega a catena la strategia non è applicabile
if Mortising.Tool.Width > EdgeToMachine.Length + 10 * GEO.EPS_SMALL then
Mortising.Message = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable - pocket too narrow for chainsaw width'
Mortising.CanApply = false
EgtOutLog( Mortising.Message)
return Mortising, false
end
end
-- parametri della lavorazione
-- inizio e fine aperti o chiusi
Mortising.IsStartClosed = not EdgeToMachine.IsStartOpen
Mortising.IsEndClosed = not EdgeToMachine.IsEndOpen
-- lato di lavoro e inversioni
Mortising.Invert = false
if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then
Mortising.Workside = MCH_MILL_WS.RIGHT
Mortising.ToolInvert = false
else
Mortising.Workside = MCH_MILL_WS.LEFT
Mortising.ToolInvert = true
end
-- profondità e offset longitudinale
if sMortisingType == 'OneSide' then
Mortising.Depth = abs( EdgeToMachine.Elevation)
elseif sMortisingType == 'OneSideAndExtend' then
Mortising.Depth = abs( EdgeToMachine.Elevation) + Mortising.Tool.CornerRadius + BeamData.CUT_EXTRA_MIN
elseif sMortisingType == 'BothSides' then
Mortising.Depth = abs( EdgeToMachine.Elevation) / 2
bNeedToMachineOtherSide = true
elseif sMortisingType == 'BothSidesAndExtend' then
Mortising.Depth = abs( EdgeToMachine.Elevation) / 2 + Mortising.Tool.CornerRadius + BeamData.CUT_EXTRA_MIN
bNeedToMachineOtherSide = true
end
if Mortising.Tool.MaxMat > Mortising.Depth - 10 * GEO.EPS_SMALL then
if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then
Mortising.LongitudinalOffset = 0
else
Mortising.LongitudinalOffset = abs( EdgeToMachine.Elevation) - Mortising.Depth
end
else
Mortising.Depth = Mortising.Tool.MaxMat - 1
if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then
Mortising.LongitudinalOffset = EdgeToMachine.Elevation - Mortising.Depth
else
Mortising.LongitudinalOffset = 0
end
Mortising.Message = 'Feature '.. Proc.idFeature .. ' : chainsaw elevation (' .. EgtNumToString( EdgeToMachine.Elevation, 1) .. ') bigger than max tool depth (' .. EgtNumToString( Mortising.Depth, 1) .. ')'
EgtOutLog( Mortising.Message)
end
-- offset radiale
Mortising.RadialOffset = 0
-- distanza di sicurezza
Mortising.StartSafetyLength = EdgeToMachine.Elevation
-- overlap
Mortising.Overlap = 0
-- faceuse
if EdgeToMachine.Elevation > - 10 * GEO.EPS_SMALL then
Mortising.Faceuse = BeamLib.GetNearestParalOpposite( EdgeToMachine.ToolDirection)
else
Mortising.Faceuse = BeamLib.GetNearestParalOpposite( -EdgeToMachine.ToolDirection)
end
-- SCC
Mortising.SCC = MCH_SCC.NONE
-- asse bloccato e angoli suggeriti
Mortising.BlockedAxis = {}
Mortising.BlockedAxis.Orientation = 'perpendicular'
Mortising.BlockedAxis.VtN = FaceToMachine.VtN
Mortising.SuggestedAngles = {}
Mortising.SuggestedAngles.Index = 1
Mortising.SuggestedAngles.VtN = FaceToMachine.VtN
Mortising.SuggestedAngles.VtOrthO = EdgeToMachine.ToolDirection
-- approccio e retrazione
Mortising.LeadIn, Mortising.LeadOut = CalculateLeadInOut( Mortising, EdgeToMachine)
-- eventuale step verticale
Mortising.VerticalSteps = MachiningLib.GetMachiningSteps( dPocketHeight, Mortising.Tool.Thickness)
-- geometria
Mortising.Geometry = {{Proc.id, FaceToMachine.id}}
-- nome operazione
Mortising.OperationName = 'Chainsaw_' .. ( EgtGetName( Mortising.ProcId) or tostring( Mortising.ProcId)) .. '_' .. tostring( FaceToMachine.id + 1)
-- eventuale avviso di danneggiamento pezzo successivo
local dOffsideLength = max( Mortising.LeadIn.StartAddLength, Mortising.LeadOut.EndAddLength) + Mortising.Tool.Width / 2 + 10 * GEO.EPS_SMALL
if ( not Proc.Tail or Proc.AdvTail) and Proc.AffectedFaces.Left and ( Proc.DistanceToNextPart < dOffsideLength) then
local sDamageNextPieceMessage = 'Feature '.. Proc.idFeature .. ' : chainsaw can damage next piece.'
if #Mortising.Message > 0 then
Mortising.Message = Mortising.Message .. '\n' .. sDamageNextPieceMessage
else
Mortising.Message = sDamageNextPieceMessage
end
EgtOutLog( sDamageNextPieceMessage)
end
return Mortising, bNeedToMachineOtherSide
end
function Chainsaw.ApplyAllSteps( Mortising, b3Raw)
local bIsMortisingOk = false
local sMortisingApplyMessage = ''
local dOriginalRadialOffsetMortising = Mortising.RadialOffset
for i = Mortising.VerticalSteps.Count, 1, -1 do
Mortising.RadialOffset = dOriginalRadialOffsetMortising + Mortising.VerticalSteps.StepLength * ( i - 1)
-- applicazione lavorazione
bIsMortisingOk, sMortisingApplyMessage = ApplyMachining( Mortising, b3Raw)
-- update messaggi
if sMortisingApplyMessage and #sMortisingApplyMessage > 0 then
Mortising.Message = Mortising.Message .. '\n' .. 'Apply : ' .. sMortisingApplyMessage
end
end
return bIsMortisingOk, sMortisingApplyMessage
end
function STR0003.Make( AddMachining, Proc, Part, CustomParameters)
-- carico parametri da default e li aggiorno con quelli passati dal chiamante (potrebbero non essere congruenti)
local StrategyLib = {}
StrategyLib.Config = require( 'STR0003\\STR0003Config')
Strategy.sName = StrategyLib.Config.sStrategyId
CustomParameters = BeamLib.GetUpdateCustomParameters( CustomParameters, StrategyLib.Config.Parameters)
Strategy.Parameters = BeamLib.LoadCustomParametersInStrategy( CustomParameters)
Strategy.RatingResult = {}
Strategy.Saw = {}
Strategy.Chainsaw = {}
local b3Raw = EgtGetRawPartBBox( Part.idRaw)
-- TODO per implementare la strategia con lapjoint lunghe bisogna prima riconoscere le topologie che arrivano
if Proc.IsSplittedLapJoint then
local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not implemented for long lapjoint'
EgtOutLog( sErr)
return false, sErr
end
if not IsTopologyOk( Proc) then
local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not implemented'
EgtOutLog( sErr)
return false, sErr
end
-- se tasca su faccia sotto la strategia non è applicabile (la sega a catena in generale non può lavorare da sotto)
-- TODO se OnlySaw questo test è da rimuovere ma bisogna considerare anche la lama da sotto
if Proc.AffectedFaces.Bottom and ( Proc.Fct > 3 or not Proc.AffectedFaces.Top) then
local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not applicable - pocket on bottom face'
EgtOutLog( sErr)
return false, sErr
end
-- lama
-- lavorazione di lama - fondo della tasca o fino a massimo materiale se tunnel
local Cutting = {}
if Proc.Topology == 'Tunnel' then
Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.OppositeEdges[1])
else
Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.BottomEdge)
end
local bIsCuttingOk = false
if Cutting.CanApply then
bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw)
end
if not bIsCuttingOk then
return bIsCuttingOk, Cutting.Message
end
local dBottomDepthToMachine = Cutting.RadialOffset
-- lato opposto del tunnel
if Proc.Topology == 'Tunnel' then
Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.OppositeEdges[2])
bIsCuttingOk = false
if Cutting.CanApply then
bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw)
end
if not bIsCuttingOk then
return bIsCuttingOk, Cutting.Message
end
else
-- se la lama non è arrivata sul fondo e c'è almeno un lato aperto va lavorato
if Cutting.RadialOffset > 10 * GEO.EPS_SMALL then
-- eventuale lavorazione di lama - lato della tasca da cui inizia la lavorazione
if Proc.MainFaces.LongFace.Edges.BottomEdge.IsStartOpen then
Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.SideEdges.StartEdge)
bIsCuttingOk = false
if Cutting.CanApply then
bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw)
end
if not bIsCuttingOk then
return bIsCuttingOk, Cutting.Message
end
end
-- eventuale lavorazione di lama - lato della tasca in cui finisce la lavorazione
if Proc.MainFaces.LongFace.Edges.BottomEdge.IsEndOpen then
Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.SideEdges.EndEdge)
bIsCuttingOk = false
if Cutting.CanApply then
bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw)
end
if not bIsCuttingOk then
return bIsCuttingOk, Cutting.Message
end
end
-- la lama è arrivata sul fondo e tasca passante, non servono ulteriori lavorazioni
elseif #( Proc.MainFaces.SideFaces) == 0 then
Strategy.Parameters.bApplyOnlyBlade = true
end
end
if Strategy.Parameters.bApplyOnlyBlade then
return bIsCuttingOk, Cutting.Message
end
-- sega a catena
-- parametri lavorazione con sega a catena - fondo della tasca o tunnel
local Mortising = {}
local bNeedToMachineOtherSide = false
if Proc.Topology == 'Tunnel' then
Mortising, bNeedToMachineOtherSide = Chainsaw.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.OppositeEdges[1])
else
Mortising = Chainsaw.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.BottomEdge)
-- si lavora solo quanto non lavorato dalla lama
Mortising.MaxElev = dBottomDepthToMachine + BeamData.CUT_EXTRA
end
local bIsMortisingOk = false
if Mortising.CanApply then
bIsMortisingOk, Mortising.Message = Chainsaw.ApplyAllSteps( Mortising, b3Raw)
end
-- lato opposto del tunnel
if Proc.Topology == 'Tunnel' and bNeedToMachineOtherSide then
Mortising = Chainsaw.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.OppositeEdges[2])
bIsMortisingOk = false
if Mortising.CanApply then
bIsMortisingOk, Mortising.Message = Chainsaw.ApplyAllSteps( Mortising, b3Raw)
end
if not bIsMortisingOk then
return bIsMortisingOk, Mortising.Message
end
else
-- se la sega a catena non è arrivata sul fondo e c'è almeno un lato aperto va lavorato
if Mortising.LongitudinalOffset > 10 * GEO.EPS_SMALL then
-- eventuale lavorazione di sega a catena - lato della tasca da cui inizia la lavorazione
if Proc.MainFaces.LongFace.Edges.BottomEdge.IsStartOpen then
Mortising = Chainsaw.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.SideEdges.StartEdge)
bIsMortisingOk = false
if Mortising.CanApply then
bIsMortisingOk, Mortising.Message = Chainsaw.ApplyAllSteps( Mortising, b3Raw)
end
if not bIsMortisingOk then
return bIsMortisingOk, Mortising.Message
end
end
-- eventuale lavorazione di sega a catena - lato della tasca in cui finisce la lavorazione
if Proc.MainFaces.LongFace.Edges.BottomEdge.IsEndOpen then
Mortising = Chainsaw.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.SideEdges.EndEdge)
bIsMortisingOk = false
if Mortising.CanApply then
bIsMortisingOk, Mortising.Message = Chainsaw.ApplyAllSteps( Mortising, b3Raw)
end
if not bIsMortisingOk then
return bIsMortisingOk, Mortising.Message
end
end
end
end
local sFinalMessage = ''
if #Cutting.Message > 0 or #Mortising.Message > 0 then
sFinalMessage = Cutting.Message .. '\n' .. Mortising.Message
end
return bIsMortisingOk, sFinalMessage
end
-------------------------------------------------------------------------------------------------------------
return STR0003