213 lines
8.4 KiB
Lua
213 lines
8.4 KiB
Lua
-- BLADEKEEPWASTE.lua by Egalware s.r.l. 2025/03/17
|
|
-- Libreria di supporto a strategie con funzioni comune a strategie diverse.
|
|
|
|
-- Tabella per definizione modulo
|
|
local BLADEKEEPWASTE = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
|
|
-- Carico i dati globali
|
|
local FeatureLib = require( 'FeatureLib')
|
|
local FaceData = require( 'FaceData')
|
|
local MachiningLib = require( 'MachiningLib')
|
|
-- strategie di base
|
|
local FaceByBlade = require('FACEBYBLADE')
|
|
|
|
-- tabella per definizione modulo
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
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 SortMachiningsBySegment( MachiningA, MachiningB)
|
|
if MachiningA.nFeatureSegment > MachiningB.nFeatureSegment then
|
|
return false
|
|
elseif MachiningB.nFeatureSegment > MachiningA.nFeatureSegment then
|
|
return true
|
|
-- se segmento uguale, si minimizzano i cambi di lato
|
|
else
|
|
local bIsOddSegment = ( MachiningA.nFeatureSegment % 2 ~= 0)
|
|
if MachiningA.vtToolDirection:getY() < MachiningB.vtToolDirection:getY() - 10 * GEO.EPS_SMALL then
|
|
if bIsOddSegment then
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
elseif MachiningA.vtToolDirection:getY() > MachiningB.vtToolDirection:getY() + 10 * GEO.EPS_SMALL then
|
|
if bIsOddSegment then
|
|
return false
|
|
else
|
|
return true
|
|
end
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
function BLADEKEEPWASTE.Make( Proc, Part, OptionalParameters)
|
|
-- TODO verificare funzionamento con lama da sotto
|
|
-- attenzione perchè se l'inclinazione della faccia la fa finire oltre lo spigolo questo riduce il massimo (come calcolare????)
|
|
-- il FindBlade dovrà restituire di utilizzare sempre la lama sopra se l'angolo lo permette, ma avendo un'altezza massima (da macchina) oltre cui il DownUp non sarà fattibile (evita collisioni tra asse e pezzo)
|
|
|
|
local Result = {}
|
|
local Blade = {}
|
|
Blade.Result = {}
|
|
local Cutting1 = {}
|
|
local Cutting2 = {}
|
|
|
|
-- controlli preventivi
|
|
if Proc.nFct > 3 then
|
|
error( 'BladeKeepWaste : max 3 faces supported')
|
|
elseif Proc.nFct == 2 then
|
|
if Proc.AdjacencyMatrix[1][2] > 10 * GEO.EPS_SMALL or Proc.AdjacencyMatrix[1][2] < -91 then
|
|
error( 'BladeKeepWaste : angle between faces must be concave and >= 90deg')
|
|
end
|
|
elseif Proc.nFct == 3 then
|
|
if Proc.AdjacencyMatrix[1][2] > 10 * GEO.EPS_SMALL or Proc.AdjacencyMatrix[1][2] < -91 then
|
|
error( 'BladeKeepWaste : angle between faces must be concave and >= 90deg')
|
|
end
|
|
if Proc.AdjacencyMatrix[1][3] > 10 * GEO.EPS_SMALL or Proc.AdjacencyMatrix[1][3] < -91 then
|
|
error( 'BladeKeepWaste : angle between faces must be concave and >= 90deg')
|
|
end
|
|
if Proc.AdjacencyMatrix[2][3] > 10 * GEO.EPS_SMALL or Proc.AdjacencyMatrix[2][3] < -91 then
|
|
error( 'BladeKeepWaste : angle between faces must be concave and >= 90deg')
|
|
end
|
|
end
|
|
|
|
-- si trovano le facce da lavorare
|
|
local FaceToMachine = {}
|
|
local LongFaces = {}
|
|
if Proc.nFct == 1 then
|
|
FaceToMachine = Proc.Faces[1]
|
|
else
|
|
if not Proc.MainFaces then
|
|
Proc.MainFaces = FaceData.GetMainFaces( Proc, Part)
|
|
end
|
|
FaceToMachine = Proc.MainFaces.BottomFaces[1]
|
|
LongFaces = Proc.MainFaces.LongFaces
|
|
end
|
|
|
|
|
|
-- si trova il lato da lavorare
|
|
local EdgeToMachine = {}
|
|
local EdgesSorted = {}
|
|
for i = 1, #FaceToMachine.Edges do
|
|
table.insert( EdgesSorted, FaceToMachine.Edges[i])
|
|
end
|
|
table.sort( EdgesSorted, CompareEdges)
|
|
EdgeToMachine = EdgesSorted[1]
|
|
|
|
local dDepthToMachine = EdgeToMachine.dElevation / 2 - OptionalParameters.dStripWidth / 2
|
|
|
|
-- eventuali punti di spezzatura
|
|
local FeatureSplittingPoints = FeatureLib.GetFeatureSplittingPoints( Proc, Part)
|
|
local bIsSplitFeature = false
|
|
if #FeatureSplittingPoints > 0 then
|
|
bIsSplitFeature = true
|
|
end
|
|
|
|
-- calcolo lavorazioni
|
|
-- primo lato
|
|
local OptionalParametersFaceByBlade = { dDepthToMachine = dDepthToMachine, bIsSplitFeature = bIsSplitFeature, dExtendAfterTail = OptionalParameters.dExtendAfterTail}
|
|
Cutting1 = FaceByBlade.Make( Proc, Part, FaceToMachine, EdgeToMachine, OptionalParametersFaceByBlade)
|
|
table.insert( Blade.Result, Cutting1)
|
|
-- secondo lato
|
|
OptionalParametersFaceByBlade.bOppositeToolDirection = true
|
|
Cutting2 = FaceByBlade.Make( Proc, Part, FaceToMachine, EdgeToMachine, OptionalParametersFaceByBlade)
|
|
table.insert( Blade.Result, Cutting2)
|
|
-- eventuali facce di chiusura
|
|
for i = 1, #LongFaces do
|
|
local CuttingLongFace = {}
|
|
OptionalParametersFaceByBlade = { bIsSplitFeature = bIsSplitFeature, dExtendAfterTail = OptionalParameters.dExtendAfterTail}
|
|
CuttingLongFace = FaceByBlade.Make( Proc, Part, Proc.MainFaces.LongFaces[i], Proc.MainFaces.LongFaces[i].MainEdges.BottomEdge, OptionalParametersFaceByBlade)
|
|
table.insert( Blade.Result, CuttingLongFace)
|
|
end
|
|
|
|
-- lavorazioni raggruppate in unica lista
|
|
local Machinings = {}
|
|
for i = 1, #Blade.Result do
|
|
if Blade.Result[i].bIsApplicable then
|
|
table.insert( Machinings, Blade.Result[i])
|
|
end
|
|
end
|
|
|
|
-- aggiunta eventuali lavorazioni splittate
|
|
if bIsSplitFeature then
|
|
Machinings = MachiningLib.GetSplitMachinings( Machinings, FeatureSplittingPoints, Part)
|
|
end
|
|
|
|
-- ordinamento
|
|
table.sort( Machinings, SortMachiningsBySegment)
|
|
|
|
-- calcolo parametri per la stima della velocità di asportazione
|
|
-- TODO non è corretto: come si stima la velocità di asportazione con il codolo? è come se avesse rimosso tutto il volume feature nel tempo di percorrenza
|
|
if Cutting1.bIsApplicable or Cutting2.bIsApplicable then
|
|
MRRParameters1 = {
|
|
dStep = TOOLS[Cutting1.nToolIndex].dThickness,
|
|
dSideStep = min( TOOLS[Cutting1.nToolIndex].dSideStep, dDepthToMachine),
|
|
dFeed = TOOLS[Cutting1.nToolIndex].Feeds.dFeed}
|
|
|
|
MRRParameters2 = {
|
|
dStep = TOOLS[Cutting2.nToolIndex].dThickness,
|
|
dSideStep = min( TOOLS[Cutting2.nToolIndex].dSideStep, dDepthToMachine),
|
|
dFeed = TOOLS[Cutting2.nToolIndex].Feeds.dFeed}
|
|
|
|
local dMRRBlade1 = MachiningLib.GetToolMRR( MRRParameters1)
|
|
local dMRRBlade2 = MachiningLib.GetToolMRR( MRRParameters2)
|
|
Result.dMRR = ( dMRRBlade1 + dMRRBlade2) / 2
|
|
Result.dCompletionPercentage = 0.5 * Cutting1.dCompletionPercentage + 0.5 * Cutting2.dCompletionPercentage
|
|
if Result.dCompletionPercentage > 100 - 10 * GEO.EPS_SMALL then
|
|
Result.sStatus = 'Completed'
|
|
else
|
|
Result.sStatus = 'Not-Completed'
|
|
end
|
|
Result.nCompletionIndex = FeatureLib.GetFeatureCompletionIndex( Result.dCompletionPercentage)
|
|
Result.nQuality = FeatureLib.GetFeatureQuality( 'Blade')
|
|
else
|
|
Result.dMRR = 0
|
|
Result.dCompletionPercentage = 0
|
|
Result.sStatus = 'Not-Applicable'
|
|
Result.nCompletionIndex = FeatureLib.GetFeatureCompletionIndex( Result.dCompletionPercentage)
|
|
Result.nQuality = FeatureLib.GetFeatureQuality( 'Blade')
|
|
end
|
|
|
|
return Machinings, Result
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
|
|
return BLADEKEEPWASTE |