diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 544a4d5..c262acd 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -68,8 +68,12 @@ local function IsToolOk( Tool) if Tool.sFamily == 'DRILLBIT' then return true -- altrimenti controllo dati aggiuntivi altre famiglie di utensili + elseif Tool.sFamily == 'MORTISE' then + if Tool.dCornerRadius then + return true + end else - if Tool.dThick then + if Tool.dThickness then return true end end @@ -128,7 +132,7 @@ function BeamExec.GetToolsFromDB() -- lettura parametri non comuni ( famiglia DRILLBIT non ha parametri specifici) if sToolFamily ~= 'DRILLBIT' then - Tool.dThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) + Tool.dThickness = EgtTdbGetCurrToolParam( MCH_TP.THICK) Tool.dLongitudinalOffset = EgtTdbGetCurrToolParam( MCH_TP.LONOFFSET) Tool.dRadialOffset = EgtTdbGetCurrToolParam( MCH_TP.RADOFFSET) -- recupero parametri propri delle frese @@ -146,7 +150,7 @@ function BeamExec.GetToolsFromDB() -- recupero parametri propri delle lame elseif sToolFamily == 'SAWBLADE' then Tool.bIsUsedForLongCut = EgtGetValInNotes( Tool.sUserNotes, 'LONGCUT') == 1 or false -- false coem valore di default - Tool.dStep = EgtGetValInNotes( Tool.sUserNotes, 'STEP') or Tool.dThick -- se non settato nell'utensile, considero lo spessore lama + Tool.dStep = EgtGetValInNotes( Tool.sUserNotes, 'STEP') or Tool.dThickness -- se non settato nell'utensile, considero lo spessore lama Tool.dSideStep = EgtGetValInNotes( Tool.sUserNotes, 'SIDESTEP') or floor( Tool.dDiameter / 4) -- se non settato nell'utensile, considero un quarto del diametro -- recupero parametri propri delle motoseghe elseif sToolFamily == 'MORTISE' then @@ -154,7 +158,9 @@ function BeamExec.GetToolsFromDB() Tool.bIsMortise = EgtGetValInNotes( Tool.sUserNotes, 'MORTISE') == 1 Tool.bIsChainSaw = not Tool.bIsMortise Tool.dStep = EgtGetValInNotes( Tool.sUserNotes, 'STEP') or floor( Tool.dMaxMaterial / 3) -- se non settato nell'utensile, considero un terzo della lunghezza - Tool.dSideStep = EgtGetValInNotes( Tool.sUserNotes, 'SIDESTEP') or ( Tool.dThick - 1) -- se non settato nell'utensile, considero spessore catena meno 1mm di sicurezza + Tool.dSideStep = EgtGetValInNotes( Tool.sUserNotes, 'SIDESTEP') or ( Tool.dThickness - 1) -- se non settato nell'utensile, considero spessore catena meno 1mm di sicurezza + Tool.dCornerRadius = EgtTdbGetCurrToolParam( MCH_TP.CORNRAD) + Tool.dWidth = Tool.dDiameter end end diff --git a/LuaLibs/MachiningLib.lua b/LuaLibs/MachiningLib.lua index 449b305..95495b0 100644 --- a/LuaLibs/MachiningLib.lua +++ b/LuaLibs/MachiningLib.lua @@ -14,11 +14,10 @@ local BeamData = require( 'BeamData') EgtOutLog( ' MachiningLib started', 1) --------------------------------------------------------------------- ---- ----@param Proc table la feature ----@param vtTool Vector3d il vettore direzione utensile ----@return number dAngle angolo tra la faccia d'ingresso e la direzione utensile +-- TODO da considerare solo angolo 2D?? local function GetToolEntryAngle( Proc, vtTool) + local Angle = {} + local dSinAngle = -10 * GEO.EPS_SMALL local vtNorm if Proc.AffectedFaces.bTop then @@ -48,9 +47,17 @@ local function GetToolEntryAngle( Proc, vtTool) local dCosAngle = sqrt( 1 - sqr( dSinAngle)) local dAngle = acos( dCosAngle) + local dTanAngle + if dAngle ~= 0 and dAngle ~= 90 then + dTanAngle = sqrt( 1 - dCosAngle * dCosAngle) / dCosAngle + end - return dAngle + Angle.dValue = dAngle + Angle.dSin = dSinAngle + Angle.dCos = dCosAngle + Angle.dTan = dTanAngle + return Angle end ------------------------------------------------------------------------------------------------------------- @@ -71,65 +78,72 @@ end function MachiningLib.FindMill( Proc, ToolSearchParameters) local ToolInfo = {} - for nCurrIndex=1, #TOOLS do + local nBestToolIndex + local dBestToolResidualDepth = 0 + for i = 1, #TOOLS do -- prima verifico che utensile sia compatibile - local bCompatibleTool = true - if TOOLS[nCurrIndex].sType ~= ToolSearchParameters.sType then - bCompatibleTool = false - elseif TOOLS[nCurrIndex].dDiameter > ToolSearchParameters.dMaxToolDiameter then - bCompatibleTool = false - elseif ToolSearchParameters.sMillShape == 'STANDARD' and ( TOOLS[nCurrIndex].dSideAngle ~= 0 or TOOLS[nCurrIndex].bIsPen) then - bCompatibleTool = false - elseif ToolSearchParameters.sMillShape == 'DOVETAIL' and not TOOLS[nCurrIndex].bIsDoveTail then - bCompatibleTool = false - elseif ToolSearchParameters.sMillShape == 'TSHAPEMILL' and not TOOLS[nCurrIndex].bIsTMill then - bCompatibleTool = false - elseif ToolSearchParameters.sMillShape == 'PEN' and not TOOLS[nCurrIndex].bIsPen then - bCompatibleTool = false + local bIsToolCompatible = true + if TOOLS[i].sType ~= ToolSearchParameters.sType then + bIsToolCompatible = false + elseif TOOLS[i].dDiameter > ToolSearchParameters.dMaxToolDiameter then + bIsToolCompatible = false + elseif ToolSearchParameters.sMillShape == 'STANDARD' and ( TOOLS[i].dSideAngle ~= 0 or TOOLS[i].bIsPen) then + bIsToolCompatible = false + elseif ToolSearchParameters.sMillShape == 'DOVETAIL' and not TOOLS[i].bIsDoveTail then + bIsToolCompatible = false + elseif ToolSearchParameters.sMillShape == 'TSHAPEMILL' and not TOOLS[i].bIsTMill then + bIsToolCompatible = false + elseif ToolSearchParameters.sMillShape == 'PEN' and not TOOLS[i].bIsPen then + bIsToolCompatible = false -- TODO controllare montaggio e verificare se direzione utensile raggiungibile. Serve funzione in BeamData end -- scelgo il migliore - if bCompatibleTool then + if bIsToolCompatible then -- calcolo riduzione del massimo materiale utilizzabile - local dToolEntryAngle = GetToolEntryAngle( Proc, ToolSearchParameters.vtToolDir) + local ToolEntryAngle = GetToolEntryAngle( Proc, ToolSearchParameters.vtToolDir) -- se ToolHolder più grande dell'utensile, il primo oggetto in collisione è il ToolHolder. Altrimenti il motore. - local dDimObjToCheck = EgtIf( TOOLS[nCurrIndex].ToolHolder.dDiameter > TOOLS[nCurrIndex].dDiameter, TOOLS[nCurrIndex].ToolHolder.dDiameter, BeamData.C_SIMM_ENC) - local dCurrMaxMatReduction = BeamData.COLL_SIC or 5 + local dDimObjToCheck = EgtIf( TOOLS[i].ToolHolder.dDiameter > TOOLS[i].dDiameter, TOOLS[i].ToolHolder.dDiameter, BeamData.C_SIMM_ENC) + local dCurrentMaxMatReduction = BeamData.COLL_SIC or 5 + -- TODO implementare le funzioni di Tool Collision Avoidance (vedi wiki e FacesBysaw -> CalcLeadInOutPerpGeom) + -- TODO considerare anche il caso in cui lo stelo sia più grande del diametro utensile + -- TODO nei confronti tra valori gestire tolleranze -- calcolo riduzione per non toccare con ToolHolder / Motore - if dToolEntryAngle > 0 and dToolEntryAngle < 90 then - dCurrMaxMatReduction = dCurrMaxMatReduction / cos( 90 - dToolEntryAngle) + ( ( dDimObjToCheck - TOOLS[nCurrIndex].dDiameter) / 2) / tan( dToolEntryAngle) + if ToolEntryAngle.dValue > 0 and ToolEntryAngle.dValue < 90 then + dCurrentMaxMatReduction = dCurrentMaxMatReduction / ToolEntryAngle.dSin + ( ( dDimObjToCheck - TOOLS[i].dDiameter) / 2) / ToolEntryAngle.dTan end -- dCurrMachReduction = negativo -> limitare, positivo -> mm extra disponibili - local dCurrMachReduction = TOOLS[nCurrIndex].dMaxDepth - ToolSearchParameters.dElevation - dCurrMaxMatReduction + local dCurrentResidualDepth = ToolSearchParameters.dElevation + dCurrentMaxMatReduction - TOOLS[i].dMaxDepth -- se non ancora trovato, oppure se completo e il migliore fino ad ora non è completo: corrente è il migliore - if not ToolInfo.nToolIndex or ( ToolInfo.dMaxMatReduction <= 0 and dCurrMachReduction > 0) then - ToolInfo.nToolIndex = nCurrIndex - ToolInfo.dMaxMatReduction = dCurrMachReduction + if not nBestToolIndex or ( dBestToolResidualDepth > 0 and dCurrentResidualDepth <= 0) then + nBestToolIndex = i + dBestToolResidualDepth = dCurrentResidualDepth -- altrimenti scelgo il migliore else -- se entrambi completi - if ToolInfo.dMaxMatReduction > 0 and dCurrMachReduction > 0 then + if dBestToolResidualDepth <= 0 and dCurrentResidualDepth <= 0 then -- scelgo utensile con rapporto lunghezza / diametro minore - if ( TOOLS[nCurrIndex].dLength / pow( TOOLS[nCurrIndex].dDiameter, 1.5)) < ( TOOLS[ToolInfo.nToolIndex].dLength / pow( TOOLS[ToolInfo.nToolIndex].dDiameter, 1.5)) then - ToolInfo.nToolIndex = nCurrIndex - ToolInfo.dMaxMatReduction = dCurrMachReduction + if ( TOOLS[i].dLength / pow( TOOLS[i].dDiameter, 1.5)) < ( TOOLS[nBestToolIndex].dLength / pow( TOOLS[nBestToolIndex].dDiameter, 1.5)) then + nBestToolIndex = i + dBestToolResidualDepth = dCurrentResidualDepth end -- se entrambi incompleti - elseif ToolInfo.dMaxMatReduction < 0 and dCurrMachReduction < 0 then + elseif dBestToolResidualDepth > 0 and dCurrentResidualDepth > 0 then --scelgo quello che lavora di più - if dCurrMachReduction > ToolInfo.dMaxMatReduction then - ToolInfo.nToolIndex = nCurrIndex - ToolInfo.dMaxMatReduction = dCurrMachReduction + if dCurrentResidualDepth > dBestToolResidualDepth then + nBestToolIndex = i + dBestToolResidualDepth = dCurrentResidualDepth end end end end - end + ToolInfo.nToolIndex = nBestToolIndex + ToolInfo.dResidualDepth = dBestToolResidualDepth + return ToolInfo end @@ -137,7 +151,7 @@ end -- funzione per cercare utensile tipo LAMA con certe caratteristiche -- TODO da completare function MachiningLib.FindBlade( Proc, ToolSearchParameters) - local Tool = {} + local ToolInfo = {} -- parametri obbligatori if type( ToolSearchParameters.vtToolDirection) ~= 'table' then @@ -157,7 +171,7 @@ function MachiningLib.FindBlade( Proc, ToolSearchParameters) ToolSearchParameters.dElevation = ToolSearchParameters.dElevation or 0 ToolSearchParameters.bForceLongcutBlade = ToolSearchParameters.bForceLongcutBlade or false - local nChosenToolIndex + local nBestToolIndex for i = 1, #TOOLS do local bIsToolCompatible = true @@ -168,14 +182,14 @@ function MachiningLib.FindBlade( Proc, ToolSearchParameters) end if bIsToolCompatible then - nChosenToolIndex = i + nBestToolIndex = i break end end - Tool = TOOLS[nChosenToolIndex] + ToolInfo.nToolIndex = nBestToolIndex - return Tool + return ToolInfo end ------------------------------------------------------------------------------------------------------------- @@ -185,9 +199,77 @@ function MachiningLib.FindDrill() end ------------------------------------------------------------------------------------------------------------- --- funzione per cercare utensile tipo PUNTA A FORARE con certe caratteristiche --- TODO da fare -function MachiningLib.FindChainSaw() +-- funzione per cercare utensile tipo SEGA A CATENA con certe caratteristiche +-- TODO da completare +-- TODO implementare sorting in base a sSortingCriterion +function MachiningLib.FindChainSaw( Proc, ToolSearchParameters) + local ToolInfo = {} + + -- parametri obbligatori + if type( ToolSearchParameters.vtToolDirection) ~= 'table' then + error( 'FindBlade : missing tool direction') + end + if type( ToolSearchParameters.bAllowTopHead) ~= 'boolean' then + error( 'FindBlade : missing top head info') + end + if type( ToolSearchParameters.bAllowBottomHead) ~= 'boolean' then + error( 'FindBlade : missing bottom head info') + end + if not ToolSearchParameters.bAllowTopHead and not ToolSearchParameters.bAllowBottomHead then + error( 'FindBlade : wrong head info') + end + + -- parametri opzionali + ToolSearchParameters.dElevation = ToolSearchParameters.dElevation or 0 + ToolSearchParameters.bExtendWithCornerRadius = ToolSearchParameters.bExtendWithCornerRadius or false + ToolSearchParameters.sSortingCriterion = ToolSearchParameters.sSortingCriterion or 'Standard' + + local nBestToolIndex + local dBestToolResidualDepth = 0 + for i = 1, #TOOLS do + local bIsToolCompatible = true + + if ToolSearchParameters.bAllowTopHead and not ToolSearchParameters.bAllowBottomHead then + bIsToolCompatible = TOOLS[i].bIsTopHead + elseif ToolSearchParameters.bAllowBottomHead and not ToolSearchParameters.bAllowTopHead then + bIsToolCompatible = TOOLS[i].bIsBottomHead + end + + -- TODO nei confronti tra valori gestire tolleranze + if bIsToolCompatible then + if ToolSearchParameters.dElevation > 10 * GEO.EPS_SMALL and ToolSearchParameters.bExtendWithCornerRadius then + ToolSearchParameters.dElevation = ToolSearchParameters.dElevation + TOOLS[i].dCornerRadius + end + -- TODO gestire accorciamento massimo materiale per inclinazione + local dCurrentResidualDepth = ToolSearchParameters.dElevation - TOOLS[i].dMaxDepth + -- se non ancora trovato, oppure se completo e il migliore fino ad ora non è completo: corrente è il migliore + if not nBestToolIndex or ( dBestToolResidualDepth > 0 and dCurrentResidualDepth <= 0) then + nBestToolIndex = i + dBestToolResidualDepth = dCurrentResidualDepth + -- altrimenti scelgo il migliore + else + -- se entrambi completi + if dBestToolResidualDepth <= 0 and dCurrentResidualDepth <= 0 then + -- scelgo utensile con rapporto lunghezza / diametro minore + if ( TOOLS[i].dLength / pow( TOOLS[i].dDiameter, 1.5)) < ( TOOLS[nBestToolIndex].dLength / pow( TOOLS[nBestToolIndex].dDiameter, 1.5)) then + nBestToolIndex = i + dBestToolResidualDepth = dCurrentResidualDepth + end + -- se entrambi incompleti + elseif dBestToolResidualDepth > 0 and dCurrentResidualDepth > 0 then + --scelgo quello che lavora di più + if dCurrentResidualDepth > dBestToolResidualDepth then + nBestToolIndex = i + dBestToolResidualDepth = dCurrentResidualDepth + end + end + end + end + end + + ToolInfo.nToolIndex = nBestToolIndex + + return ToolInfo end ------------------------------------------------------------------------------------------------------------- diff --git a/Strategies/STR0002/STR0002.lua b/Strategies/STR0002/STR0002.lua index 4fd7db4..38f33bf 100644 --- a/Strategies/STR0002/STR0002.lua +++ b/Strategies/STR0002/STR0002.lua @@ -32,7 +32,7 @@ local function IsTopologyOk( Proc) end ------------------------------------------------------------------------------------------------------------- -function STR0002.Make( AddMachining, Proc, Part, CustomParameters) +function STR0002.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 = require( 'STR0002\\STR0002Config') @@ -61,17 +61,17 @@ function STR0002.Make( AddMachining, Proc, Part, CustomParameters) ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters) if ToolInfo.nToolIndex and TOOLS[ToolInfo.nToolIndex].sName then - if ToolInfo.dMaxMatReduction < 0 then + if ToolInfo.dResidualDepth > 0 then Strategy.RatingResult.sStatus = 'Not-Completed' else Strategy.RatingResult.sStatus = 'Completed' end - Strategy.RatingResult.dCompletionIndex = min( 100, ( ( Proc.MainFaces.BottomFace.dElevation + ToolInfo.dMaxMatReduction) / Proc.MainFaces.BottomFace.dElevation) * 100) + Strategy.RatingResult.dCompletionIndex = min( 100, ( ( Proc.MainFaces.BottomFace.dElevation - ToolInfo.dResidualDepth) / Proc.MainFaces.BottomFace.dElevation) * 100) Strategy.RatingResult.dRating = FeatureData.GetFeatureRating( 'Mill', Strategy.RatingResult.dCompletionIndex) Strategy.RatingResult.sInfo = '' -- se richiesto applico lavorazione - if AddMachining then + if bAddMachining then -- TODO gestione spezzatura da completare -- le lunghezza richiede spezzatura if ( Proc.b3Box:getDimX() > BeamData.LONGCUT_MAXLEN) or ( Proc.b3Box:getDimX() > 0.7 * Part.b3Solid:getDimX() and Proc.b3Box:getDimX() > BeamData.LONGCUT_ENDLEN) then @@ -143,7 +143,7 @@ function STR0002.Make( AddMachining, Proc, Part, CustomParameters) for i = 1, #vAddId do EgtCreateMachining( 'Svuotatura', MCH_OY.POCKETING, TOOLS[ToolInfo.nToolIndex].sName) EgtSetMachiningParam( MCH_MP.STEP, TOOLS[ToolInfo.nToolIndex].dStep) - EgtSetMachiningParam( MCH_MP.DEPTH, min( 0, ToolInfo.dMaxMatReduction)) + EgtSetMachiningParam( MCH_MP.DEPTH, min( 0, -ToolInfo.dResidualDepth)) EgtSetMachiningParam( MCH_MP.SIDESTEP, TOOLS[ToolInfo.nToolIndex].dSideStep) EgtSetMachiningParam( MCH_MP.SUBTYPE, MCH_POCK_SUB.SPIRALOUT) EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_POCK_LI.ZIGZAG) @@ -162,7 +162,7 @@ function STR0002.Make( AddMachining, Proc, Part, CustomParameters) else EgtCreateMachining( 'Svuotatura', MCH_OY.POCKETING, TOOLS[ToolInfo.nToolIndex].sName) EgtSetMachiningParam( MCH_MP.STEP, TOOLS[ToolInfo.nToolIndex].dStep) - EgtSetMachiningParam( MCH_MP.DEPTH, min( 0, ToolInfo.dMaxMatReduction)) + EgtSetMachiningParam( MCH_MP.DEPTH, min( 0, -ToolInfo.dResidualDepth)) EgtSetMachiningParam( MCH_MP.SIDESTEP, TOOLS[ToolInfo.nToolIndex].dSideStep) EgtSetMachiningParam( MCH_MP.SUBTYPE, MCH_POCK_SUB.SPIRALOUT) EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_POCK_LI.ZIGZAG) diff --git a/Strategies/STR0003/STR0003.lua b/Strategies/STR0003/STR0003.lua index 2675a4d..608a126 100644 --- a/Strategies/STR0003/STR0003.lua +++ b/Strategies/STR0003/STR0003.lua @@ -63,7 +63,7 @@ function GetToolFromMachining( sMachiningName) end -function CalculateLeadInOut( Machining, EdgeToMachine) +local 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 @@ -131,7 +131,7 @@ function CalculateLeadInOut( Machining, EdgeToMachine) end -function ApplyMachining( Machining, b3Raw) +local function AddNewMachining( Machining, b3Raw) local sErr = '' local nOperationId = EgtAddMachining( Machining.OperationName, Machining.Name) if not nOperationId then @@ -256,25 +256,28 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) -- ricerca utensile local ToolSearchParameters = {} - ToolSearchParameters.dElevation = EdgeToMachine.Elevation + ToolSearchParameters.dElevation = abs( EdgeToMachine.Elevation) ToolSearchParameters.vtToolDirection = EdgeToMachine.ToolDirection ToolSearchParameters.bAllowTopHead = true ToolSearchParameters.bAllowBottomHead = false ToolSearchParameters.bForceLongcutBlade = Strategy.Parameters.bForceLongcutBlade - - Cutting.Tool = MachiningLib.FindBlade( Proc, ToolSearchParameters) + local ToolInfo = MachiningLib.FindBlade( Proc, ToolSearchParameters) + if not ToolInfo.nToolIndex then + ToolSearchParameters.dElevation = 0 + ToolInfo = MachiningLib.FindBlade( Proc, ToolSearchParameters) + end 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.nToolIndex = ToolInfo.nToolIndex 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 + if Cutting.TOOLS[Cutting.nToolIndex].dThickness > 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) @@ -282,7 +285,7 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) 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 + if Cutting.TOOLS[Cutting.nToolIndex].dDiameter > 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) @@ -295,7 +298,7 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) Cutting.IsStartClosed = not EdgeToMachine.IsStartOpen Cutting.IsEndClosed = not EdgeToMachine.IsEndOpen -- lato di lavoro e inversioni - if Cutting.Tool.IsCCW then + if Cutting.TOOLS[Cutting.nToolIndex].bIsCCW then Cutting.Workside = MCH_MILL_WS.RIGHT Cutting.Invert = true else @@ -313,7 +316,7 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) Cutting.ToolInvert = false end -- profondità e offset radiale - if Cutting.Tool.MaxDepth > abs( EdgeToMachine.Elevation) - 10 * GEO.EPS_SMALL then + if Cutting.TOOLS[Cutting.nToolIndex].dMaxDepth > 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 @@ -322,7 +325,7 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) Cutting.RadialOffset = EdgeToMachine.Elevation end else - Cutting.Depth = Cutting.Tool.MaxDepth - 1 + Cutting.Depth = Cutting.TOOLS[Cutting.nToolIndex].MaxDepth - 1 if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then Cutting.RadialOffset = EdgeToMachine.Elevation - Cutting.Depth else @@ -334,7 +337,7 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) end end -- step verticale e offset longitudinale - Cutting.Steps = MachiningLib.GetMachiningSteps( dPocketHeight, Cutting.Tool.Thickness) + Cutting.Steps = MachiningLib.GetMachiningSteps( dPocketHeight, Cutting.TOOLS[Cutting.nToolIndex].dThickness) 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 @@ -363,8 +366,8 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) 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) + if Cutting.TOOLS[Cutting.nToolIndex].dSideStep then + Cutting.HorizontalSteps = MachiningLib.GetMachiningSteps( Cutting.Depth, Cutting.TOOLS[Cutting.nToolIndex].dSideStep) else Cutting.HorizontalSteps.Count = 1 Cutting.HorizontalSteps.StepLength = 0 @@ -376,7 +379,7 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) -- 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 + local dOffsideLength = max( Cutting.LeadIn.StartAddLength, Cutting.LeadOut.EndAddLength) + Cutting.TOOLS[Cutting.nToolIndex].dDiameter / 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 @@ -391,7 +394,7 @@ function Blade.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachine) end -function Blade.ApplyAllSteps( Cutting, b3Raw) +function Blade.AddMachiningAllSteps( Cutting, b3Raw) local bIsCuttingOk = false local sCuttingApplyMessage = '' @@ -404,7 +407,7 @@ function Blade.ApplyAllSteps( Cutting, b3Raw) Cutting.LeadIn.PerpDistance = dOriginalLeadInPerpDistance - Cutting.RadialOffset Cutting.LeadOut.PerpDistance = dOriginalLeadOutPerpDistance - Cutting.RadialOffset -- applicazione lavorazione - bIsCuttingOk, sCuttingApplyMessage = ApplyMachining( Cutting, b3Raw) + bIsCuttingOk, sCuttingApplyMessage = AddNewMachining( Cutting, b3Raw) -- update messaggi if sCuttingApplyMessage and #sCuttingApplyMessage > 0 then sCuttingApplyMessage = sCuttingApplyMessage .. 'Apply : ' .. sCuttingApplyMessage .. '\n' @@ -421,8 +424,6 @@ function Chainsaw.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachi 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 @@ -437,42 +438,56 @@ function Chainsaw.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachi end end - -- ricerca lavorazione - -- TODO da sostituire con ricerca utensile + -- ricerca utensile + local ToolSearchParameters = {} + local ToolInfo = {} + ToolSearchParameters.vtToolDirection = EdgeToMachine.ToolDirection + ToolSearchParameters.bAllowTopHead = true + ToolSearchParameters.bAllowBottomHead = false 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) + ToolSearchParameters.bExtendWithCornerRadius = true + ToolSearchParameters.dElevation = abs( EdgeToMachine.Elevation) + BeamData.CUT_EXTRA + ToolInfo = MachiningLib.FindChainSaw( Proc, ToolSearchParameters) + if not TOOLS[ToolInfo.nToolIndex].sName then sMortisingType = 'BothSidesAndExtend' + ToolSearchParameters.dElevation = abs( EdgeToMachine.Elevation) / 2 + BeamData.CUT_EXTRA_MIN + ToolInfo = MachiningLib.FindChainSaw( Proc, ToolSearchParameters) 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' + ToolSearchParameters.bExtendWithCornerRadius = true + ToolSearchParameters.dElevation = abs( EdgeToMachine.Elevation) / 2 + BeamData.CUT_EXTRA_MIN + ToolInfo = MachiningLib.FindChainSaw( Proc, ToolSearchParameters) else - Mortising.Name = ML.FindSawing( 'Sawing', abs( EdgeToMachine.Elevation)) sMortisingType = 'OneSide' + ToolSearchParameters.bExtendWithCornerRadius = false + ToolSearchParameters.dElevation = abs( EdgeToMachine.Elevation) + BeamData.CUT_EXTRA + ToolInfo = MachiningLib.FindChainSaw( Proc, ToolSearchParameters) end - if not Mortising.Name then - Mortising.Name = ML.FindSawing( 'Sawing', nil, nil, 'Longest') + if not TOOLS[ToolInfo.nToolIndex].sName then if sMortisingType == 'BothSidesAndExtend' then sMortisingType = 'BothSides' elseif sMortisingType == 'OneSideAndExtend' then sMortisingType = 'OneSide' end + ToolSearchParameters.bExtendWithCornerRadius = false + ToolSearchParameters.dElevation = nil + ToolSearchParameters.sSortingCriterion = 'Longest' + ToolInfo = MachiningLib.FindChainSaw( Proc, ToolSearchParameters) end - if not Mortising.Name then + if not TOOLS[ToolInfo.nToolIndex].sName 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.nToolIndex = ToolInfo.nToolIndex 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 + if Mortising.TOOLS[Mortising.nToolIndex].dThickness > 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) @@ -480,7 +495,7 @@ function Chainsaw.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachi 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 + if Mortising.TOOLS[Mortising.nToolIndex].dWidth > 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) @@ -505,22 +520,22 @@ function Chainsaw.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachi 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 + Mortising.Depth = abs( EdgeToMachine.Elevation) + Mortising.TOOLS[Mortising.nToolIndex].dCornerRadius + 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 + Mortising.Depth = abs( EdgeToMachine.Elevation) / 2 + Mortising.TOOLS[Mortising.nToolIndex].dCornerRadius + BeamData.CUT_EXTRA_MIN bNeedToMachineOtherSide = true end - if Mortising.Tool.MaxMat > Mortising.Depth - 10 * GEO.EPS_SMALL then + if Mortising.TOOLS[Mortising.nToolIndex].dMaxMat > 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 + Mortising.Depth = Mortising.TOOLS[Mortising.nToolIndex].dMaxMat - 1 if EdgeToMachine.Elevation > -10 * GEO.EPS_SMALL then Mortising.LongitudinalOffset = EdgeToMachine.Elevation - Mortising.Depth else @@ -554,14 +569,14 @@ function Chainsaw.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachi -- approccio e retrazione Mortising.LeadIn, Mortising.LeadOut = CalculateLeadInOut( Mortising, EdgeToMachine) -- eventuale step verticale - Mortising.VerticalSteps = MachiningLib.GetMachiningSteps( dPocketHeight, Mortising.Tool.Thickness) + Mortising.VerticalSteps = MachiningLib.GetMachiningSteps( dPocketHeight, Mortising.TOOLS[Mortising.nToolIndex].dThickness) -- 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 + local dOffsideLength = max( Mortising.LeadIn.StartAddLength, Mortising.LeadOut.EndAddLength) + Mortising.TOOLS[Mortising.nToolIndex].dWidth / 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 @@ -576,7 +591,7 @@ function Chainsaw.CalculateMachiningParameters( Proc, FaceToMachine, EdgeToMachi end -function Chainsaw.ApplyAllSteps( Mortising, b3Raw) +function Chainsaw.AddMachiningAllSteps( Mortising, b3Raw) local bIsMortisingOk = false local sMortisingApplyMessage = '' @@ -584,7 +599,7 @@ function Chainsaw.ApplyAllSteps( Mortising, b3Raw) for i = Mortising.VerticalSteps.Count, 1, -1 do Mortising.RadialOffset = dOriginalRadialOffsetMortising + Mortising.VerticalSteps.StepLength * ( i - 1) -- applicazione lavorazione - bIsMortisingOk, sMortisingApplyMessage = ApplyMachining( Mortising, b3Raw) + bIsMortisingOk, sMortisingApplyMessage = AddNewMachining( Mortising, b3Raw) -- update messaggi if sMortisingApplyMessage and #sMortisingApplyMessage > 0 then Mortising.Message = Mortising.Message .. '\n' .. 'Apply : ' .. sMortisingApplyMessage @@ -595,7 +610,7 @@ function Chainsaw.ApplyAllSteps( Mortising, b3Raw) end -function STR0003.Make( AddMachining, Proc, Part, CustomParameters) +function STR0003.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 = require( 'STR0003\\STR0003Config') @@ -609,7 +624,7 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) local b3Raw = EgtGetRawPartBBox( Part.idRaw) - -- TODO per implementare la strategia con lapjoint lunghe bisogna prima riconoscere le topologie che arrivano + -- TODO implementare gestione lapjoint lunghe if Proc.IsSplittedLapJoint then local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.sName .. ' not implemented for long lapjoint' EgtOutLog( sErr) @@ -639,7 +654,7 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.BottomEdge) end local bIsCuttingOk = false - if Cutting.CanApply then + if bAddMachining and Cutting.CanApply then bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw) end if not bIsCuttingOk then @@ -650,7 +665,7 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) if Proc.Topology == 'Tunnel' then Cutting = Blade.CalculateMachiningParameters( Proc, Proc.MainFaces.LongFace, Proc.MainFaces.LongFace.Edges.OppositeEdges[2]) bIsCuttingOk = false - if Cutting.CanApply then + if bAddMachining and Cutting.CanApply then bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw) end if not bIsCuttingOk then @@ -663,7 +678,7 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) 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 + if bAddMachining and Cutting.CanApply then bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw) end if not bIsCuttingOk then @@ -674,7 +689,7 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) 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 + if bAddMachining and Cutting.CanApply then bIsCuttingOk, Cutting.Message = Blade.ApplyAllSteps( Cutting, b3Raw) end if not bIsCuttingOk then @@ -703,14 +718,14 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) Mortising.MaxElev = dBottomDepthToMachine + BeamData.CUT_EXTRA end local bIsMortisingOk = false - if Mortising.CanApply then + if bAddMachining and 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 + if bAddMachining and Mortising.CanApply then bIsMortisingOk, Mortising.Message = Chainsaw.ApplyAllSteps( Mortising, b3Raw) end if not bIsMortisingOk then @@ -723,7 +738,7 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) 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 + if bAddMachining and Mortising.CanApply then bIsMortisingOk, Mortising.Message = Chainsaw.ApplyAllSteps( Mortising, b3Raw) end if not bIsMortisingOk then @@ -734,7 +749,7 @@ function STR0003.Make( AddMachining, Proc, Part, CustomParameters) 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 + if bAddMachining and Mortising.CanApply then bIsMortisingOk, Mortising.Message = Chainsaw.ApplyAllSteps( Mortising, b3Raw) end if not bIsMortisingOk then