Files
databeamnew/Strategies/STR0002/STR0002.lua
T
andrea.villa 69f97362b9 - MachiningLib scrittura parametri di sistema
- Piccola correzione STR0002 per uniformare a nuovi nomi parametri
2024-05-22 09:26:33 +02:00

197 lines
9.0 KiB
Lua

-- Strategia: STR0002
-- Descrizione
-- Svuotatura tasca
-- Feature:
-- Slot
-- FrontSlot
-- IsRidgeLap
-- IsLapJoint
-- IsNotchRabbet
-- IsNotch
-- IsPocket
-- Topology: 'Pocket-5-Blind'
-- 'Groove-4-Blind'
-- carico librerie
local BeamLib = require( 'BeamLib')
local BeamData = require( 'BeamData')
local MachiningLib = require( 'MachiningLib')
local FeatureData = require( 'FeatureData')
-- Tabella per definizione modulo
local STR0002 = {}
local Strategy = {}
-------------------------------------------------------------------------------------------------------------
local function IsTopologyOk( Proc)
if Proc.Topology.sName == 'Pocket-5-Blind' or Proc.Topology.sName == 'Groove-4-Blind' then
return true
else
return false
end
end
-------------------------------------------------------------------------------------------------------------
function STR0002.Make( AddMachining, 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')
Strategy.sName = StrategyLib.Config.sStrategyId
CustomParameters = BeamLib.GetUpdateCustomParameters( CustomParameters, StrategyLib.Config.Parameters)
Strategy.Parameters = BeamLib.LoadCustomParametersInStrategy( CustomParameters)
Strategy.RatingResult = {}
if not IsTopologyOk( Proc) then
local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.Config.sStrategyId .. ' not implemented'
EgtOutLog( sErr)
return false, sErr
end
local ToolInfo = {}
local Pocketing = {}
Pocketing.Steps = {}
Pocketing.LeadIn = {}
Pocketing.LeadOut = {}
-- serve utensile che possa lavorare di testa
local ToolSearchParameters = {}
ToolSearchParameters.sType = 'MILL_STD'
ToolSearchParameters.sMillShape = 'STANDARD'
ToolSearchParameters.dMaxToolDiameter = min( Strategy.Parameters.dMaxCornerRadius * 2, Proc.MainFaces.BottomFace.dHeight, Proc.MainFaces.BottomFace.dWidth)
ToolSearchParameters.dElevation = Proc.MainFaces.BottomFace.dElevation
ToolSearchParameters.vtToolDir = Proc.MainFaces.BottomFace.vtN
-- cerco utensile
ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters)
if ToolInfo.nToolIndex and TOOLS[ToolInfo.nToolIndex].sName then
if ToolInfo.dMaxMatReduction < 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.dRating = FeatureData.GetFeatureRating( 'Mill', Strategy.RatingResult.dCompletionIndex)
Strategy.RatingResult.sInfo = ''
-- se richiesto applico lavorazione
if AddMachining 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
-- recupero gruppo per geometria aggiuntiva
local nAddGrpId = BeamLib.GetAddGroup( Part.idPart)
local vAddId = {}
local bStartLeft, bStartRight
-- se feature inizia al di sotto del limite sinistro
if Proc.b3Box:getMin():getX() < Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN then
bStartLeft = true
end
-- se feature inizia al di sotto del limite destro
if Proc.b3Box:getMax():getX() > Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN then
bStartRight = true
end
-- salvo valori
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.iod, nAddGrpId) or GDB_ID.NULL
dNewMinX = max( ( Proc.b3Box:getMin():getX() + TOOLS[ToolInfo.nToolIndex].dDiameter * 2), Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN)
local ptOn = Point3d( dNewMinX, 0, 0)
dNewRest = abs( dNewMaxX - dNewMinX)
-- taglio della superficie lato sinistro
EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB)
-- eseguo inserimento
table.insert( vAddId, AddId)
end
-- creo spezzone sulla destra
if bStartRight then
local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL
dNewMaxX = min( ( Proc.b3Box:getMax():getX() - TOOLS[ToolInfo.nToolIndex].dDiameter * 2), Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN)
local ptOn = Point3d( dNewMaxX, 0, 0)
dNewRest = abs( dNewMaxX - dNewMinX)
-- taglio della superficie lato destro
EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB)
-- eseguo inserimento
table.insert( vAddId, EgtIf( BeamData.RIGHT_LOAD, 2, 1),AddId)
end
-- lavoro il restante
local nSplitParts = max( ceil( dNewRest / BeamData.LONGCUT_MAXLEN + 10 * GEO.EPS_SMALL), 2)
local dSplitPartsLen = dNewRest / nSplitParts
for i = 1, nSplitParts do
local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL
local ptOn
-- 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)
end
-- eseguo trim destro
dNewMaxX = dNewMinX + dSplitPartsLen
if i ~= nSplitParts or bStartRight then
ptOn = Point3d( dNewMaxX, 0, 0)
-- taglio della superficie lato destro
EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB)
end
-- il nuovo minimo è il punto massimo del precedente
dNewMinX = dNewMaxX
-- eseguo inserimento in modo da ordinare da X- a X+
table.insert( vAddId, EgtIf( BeamData.RIGHT_LOAD, 1+i, EgtIf( bStartLeft, 1, 2)), AddId)
end
-- si applicano le lavorazioni
for i = 1, #vAddId do
Pocketing.nToolIndex = ToolInfo.nToolIndex
Pocketing.nType = MCH_OY.POCKETING
Pocketing.Steps.dStep = TOOLS[ToolInfo.nToolIndex].dStep
Pocketing.dDepth = min( 0, -ToolInfo.dResidualDepth)
Pocketing.Steps.dSideStep = TOOLS[ToolInfo.nToolIndex].dSideStep
Pocketing.nSubType = MCH_POCK_SUB.SPIRALOUT
Pocketing.LeadIn.nType = MCH_POCK_LI.ZIGZAG
Pocketing.LeadIn.dTangentDistance = TOOLS[ToolInfo.nToolIndex].dDiameter/2
Pocketing.LeadIn.dElevation = TOOLS[ToolInfo.nToolIndex].dDiameter/2
-- TODO settare parametro per indicare qual è lo spezzone che deve essere fatto dopo il taglio di separazione
for j=1, Proc.nFct do
local vtNSplitFace
_, vtNSplitFace = EgtSurfTmFacetCenter( vAddId[i], j - 1, GDB_ID.ROOT)
if vtNSplitFace and AreSameVectorExact( vtNSplitFace, Proc.MainFaces.BottomFace.vtN) then
Pocketing.idFaceToMachine = j - 1
Pocketing.idProc = vAddId[i]
MachiningLib.AddNewMachining( Pocketing)
break
end
end
end
else
Pocketing.nToolIndex = ToolInfo.nToolIndex
Pocketing.nType = MCH_OY.POCKETING
Pocketing.Steps.dStep = TOOLS[ToolInfo.nToolIndex].dStep
Pocketing.dDepth = min( 0, -ToolInfo.dResidualDepth)
Pocketing.Steps.dSideStep = TOOLS[ToolInfo.nToolIndex].dSideStep
Pocketing.nSubType = MCH_POCK_SUB.SPIRALOUT
Pocketing.LeadIn.nType = MCH_POCK_LI.ZIGZAG
Pocketing.LeadIn.dTangentDistance = TOOLS[ToolInfo.nToolIndex].dDiameter/2
Pocketing.LeadIn.dElevation = TOOLS[ToolInfo.nToolIndex].dDiameter/2
Pocketing.idFaceToMachine = Proc.MainFaces.BottomFace.id
Pocketing.idProc = Proc.id
MachiningLib.AddNewMachining( Pocketing)
end
end
else
Strategy.RatingResult.sStatus = 'Not-Applicable'
Strategy.RatingResult.dCompletionIndex = 0
Strategy.RatingResult.dRating = 0
Strategy.RatingResult.sInfo = 'Mill not found'
end
return Strategy.RatingResult
end
-------------------------------------------------------------------------------------------------------------
return STR0002