Files
databeamnew/StrategyLibs/BLADETOWASTE.lua
T

133 lines
4.4 KiB
Lua

-- BLADETOWASTE.lua by Egalware s.r.l. 2025/01/08
-- Libreria di supporto a strategie con funzioni comune a strategie diverse.
-- Tabella per definizione modulo
local BLADETOWASTE = {}
-- Include
require( 'EgtBase')
-- Carico i dati globali
local BeamData = require( 'BeamData')
local BeamLib = require( 'BeamLib')
local FeatureLib = require( 'FeatureLib')
local MachiningLib = require( 'MachiningLib')
local DiceCut = require( 'DiceCut')
-- strategie di base
local FaceByBlade = require('FACEBYBLADE')
EgtOutLog( ' BLADETOWASTE started', 1)
-------------------------------------------------------------------------------------------------------------
function BLADETOWASTE.Make( Proc, Part, OptionalParameters)
local Result = {}
local dCompletionPercentage = 0
-- controlli preventivi
if Proc.nFct > 2 then
error( 'BladeToWaste : max 2 faces supported')
elseif Proc.nFct == 2 then
if Proc.AdjacencyMatrix[1][2] > 10 * GEO.EPS_SMALL or Proc.AdjacencyMatrix[1][2] < -91 then
error( 'BladeToWaste : angle between faces must be concave and >= 90deg')
end
end
-- parametri opzionali e default
local nToolIndex = OptionalParameters.nToolIndex
local bDropWholeWaste = OptionalParameters.bDropWholeWaste or false
local dMaxWasteVolume = OptionalParameters.dMaxWasteVolume or 0
local dMaxWasteLength = OptionalParameters.dMaxWasteLength or 0
-- dimensioni feature
local dFeatureVolume = FeatureLib.GetFeatureVolume( Proc, Part)
local dFeatureMaxDimension = max( Proc.b3Box:getDimX(), Proc.b3Box:getDimY())
local bIsFeatureSmall = dFeatureVolume < dMaxWasteVolume + 10 * GEO.EPS_SMALL
and dFeatureMaxDimension < dMaxWasteLength + 10 * GEO.EPS_SMALL
-- si taglia tutto lo scarto in una sola lavorazione
if Proc.nFct == 1 and ( bIsFeatureSmall or bDropWholeWaste) then
local Cutting = {}
local EdgeToMachine = {}
local dDepthToMachine = 0
local ToolInfo = {}
-- ricerca utensile
if not nToolIndex then
local ToolSearchParameters = {}
for i = 1, #Proc.Faces[1].Edges do
if ( i == 1) or Proc.Faces[1].Edges[i].dElevation < EdgeToMachine.dElevation - 10 * GEO.EPS_SMALL then
EdgeToMachine = Proc.Faces[1].Edges[i]
end
end
dDepthToMachine = EdgeToMachine.dElevation + BeamData.CUT_EXTRA
ToolSearchParameters.dElevation = dDepthToMachine
ToolSearchParameters.vtToolDirection = EdgeToMachine.vtN
ToolSearchParameters.bAllowTopHead = true
-- TODO bisognerà implementare anche la lama da sotto
ToolSearchParameters.bAllowBottomHead = false
ToolSearchParameters.bForceLongcutBlade = false
ToolInfo = MachiningLib.FindBlade( Proc, ToolSearchParameters)
nToolIndex = ToolInfo.nToolIndex
end
if ToolInfo.dResidualDepth < 10 * GEO.EPS_SMALL then
local OptionalParametersFaceByBlade = { dDepthToMachine = dDepthToMachine, nToolIndex = nToolIndex}
Cutting = FaceByBlade.Make( Proc, Part, Proc.Faces[1], EdgeToMachine, OptionalParametersFaceByBlade)
end
if Cutting.bIsApplicable or bDropWholeWaste then
table.insert( Result, Cutting)
dCompletionPercentage = Cutting.dCompletionPercentage or dCompletionPercentage
end
return Result, dCompletionPercentage
end
-- lavorazione con cubetti
-- se due facce, la faccia principale è la più grande
local Face1 = Proc.Faces[1]
local Face2 = {}
if Proc.nFct == 2 then
Face2 = Proc.Faces[2]
end
-- direzione migliore di lavoro, per la ricerca utensile
local _, dCutH, dCutV = BeamLib.GetFaceHvRefDim( Proc.Id, 0, Part.b3Raw)
-- ricerca utensile
local ToolSearchParameters = {}
ToolSearchParameters.vtToolDirection = EdgeToMachine.vtN
ToolSearchParameters.bAllowTopHead = true
-- TODO bisognerà implementare anche la lama da sotto
ToolSearchParameters.bAllowBottomHead = false
ToolSearchParameters.bForceLongcutBlade = false
ToolInfo = MachiningLib.FindBlade( Proc, ToolSearchParameters)
nToolIndex = ToolInfo.nToolIndex
local vCuts = DiceCut.GetDice( Part, Face1, Face2, OptionalParameters)
-- restituire tabella contenente lavorazioni, già con cloni se necessari
return Result, dCompletionPercentage
end
-------------------------------------------------------------------------------------------------------------
return BLADETOWASTE