Files
DataBeam/LuaLibs/ProcessRoundArch.lua
T
Dario Sassi 72b0e7f4a4 DataBeam :
- modifiche per sola macchina Scm-Oikos.
2025-05-27 19:56:51 +02:00

275 lines
11 KiB
Lua

-- ProcessRoundArch.lua by Egaltech s.r.l. 2023/12/07
-- Gestione calcolo archi per Travi
-- Tabella per definizione modulo
local ProcessRoundArch = {}
-- Include
require( 'EgtBase')
local BL = require( 'BeamLib')
EgtOutLog( ' ProcessRoundArch started', 1)
-- Dati
local BD = require( 'BeamData')
local ML = require( 'MachiningLib')
-- variabili assegnazione parametri Q
local Q_DIM_STRIP = 'Q02' -- d
---------------------------------------------------------------------
-- Riconoscimento della feature
function ProcessRoundArch.Identify( Proc)
return ( Proc.Grp == 4 and Proc.Prc == 104)
end
---------------------------------------------------------------------
-- Verifica se feature di testa
function ProcessRoundArch.IsHeadFeature( Proc, b3Raw, dCurrOvmH)
-- verifico se è in testa
if Proc.Box:getMax():getX() < b3Raw:getMax():getX() - dCurrOvmH - BD.MAX_DIST_HTFEA then
return false
end
-- la sua lunghezza non deve superare la metà della lunghezza della trave
if Proc.Box:getDimX() > 0.5 * b3Raw:getDimX() then
return false
end
-- deve occupare la maggior parte dell'area
if Proc.Box:getDimY() > 0.75 * b3Raw:getDimY() or Proc.Box:getDimZ() > 0.75 * b3Raw:getDimZ() then
return true
end
-- non è di testa
return false
end
---------------------------------------------------------------------
-- Verifica se feature di coda
function ProcessRoundArch.IsTailFeature( Proc, b3Raw)
-- verifico se è in coda
if Proc.Box:getMin():getX() > b3Raw:getMin():getX() + BD.MAX_DIST_HTFEA then
return false
end
-- la sua lunghezza non deve superare la metà della lunghezza della trave
if Proc.Box:getDimX() > 0.5 * b3Raw:getDimX() then
return false
end
-- deve occupare la maggior parte dell'area
if Proc.Box:getDimY() > 0.75 * b3Raw:getDimY() or Proc.Box:getDimZ() > 0.75 * b3Raw:getDimZ() then
return true
end
-- non è di coda
return false
end
---------------------------------------------------------------------
-- Classificazione della feature
function ProcessRoundArch.Classify( Proc)
-- se di testa o coda, è indifferente alla posizione
if Proc.Head or Proc.Tail then
return true, false
end
-- è intermedia, devo verificare la normale del centro
local nMidFacet = Proc.Fct // 2
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nMidFacet, GDB_ID.ROOT)
-- verifico sia una superficie
if not vtN then
return false
end
-- verifico se la feature è lavorabile solo da sotto
--local bDown = ( vtN:getZ() < - 0.1)
local bDown = false
return true, bDown
end
---------------------------------------------------------------------
-- Applicazione della lavorazione
function ProcessRoundArch.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
-- recupero l'ingombro del grezzo di appartenenza
local b3Raw = EgtGetRawPartBBox( nRawId)
-- ingombro del pezzo
local Ls = EgtGetFirstNameInGroup( nPartId, 'Box')
local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD)
if not b3Solid then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' part box not found'
EgtOutLog( sErr)
return false, sErr
end
-- normale alla superficie nel mezzo
local vtN = EgtSurfTmFacetNormVersor( Proc.Id, Proc.Fct // 2, GDB_RT.GLOB)
-- recupero e verifico l'entità curva
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
if AuxId then AuxId = AuxId + Proc.Id end
if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry'
EgtOutLog( sErr)
return false, sErr
end
-- recupero i dati della curva e del profilo
local dDepth = abs( EgtCurveThickness( AuxId))
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
local b3Aux = EgtGetBBoxGlob( AuxId, GDB_BB.STANDARD)
local bToolInv = ( vtExtr:getZ() < -0.1)
local bDown = ( b3Aux:getMin():getZ() < b3Raw:getMin():getZ() + 5)
-- recupero la lavorazione
local sMilling = ML.FindMilling( 'FreeContour')
if not sMilling then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library'
EgtOutLog( sErr)
return false, sErr
end
-- recupero i dati dell'utensile
local dMaxDepth = 0
local bCW = true
if EgtMdbSetCurrMachining( sMilling) then
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth
local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0
bCW = ( dSpeed >= 0)
end
end
-- ne verifico la lunghezza per eventuale spezzatura e lavorazione in doppio
local nStep = 1
local dStep = 0
local dLenMax = BD.LONGCUT_ENDLEN
if b3Aux:getDimX() > dLenMax then
local dCrvLen = EgtCurveLength( AuxId)
nStep = ceil( dCrvLen / dLenMax)
dStep = dCrvLen / nStep
EgtOutLog( string.format( 'CrvLen=%.1f StepNbr=%d StepLen=%.1f', dCrvLen, nStep, dStep), 3)
end
-- verifiche per affondamento ( possibili lavorazioni in doppio)
local bCross = false
if abs( vtExtr:getY()) > 0.707 then
if b3Aux:getDimY() > b3Raw:getDimY() - 1.0 then
bCross = true
dDepth = min( dDepth, b3Raw:getDimY())
end
elseif abs( vtExtr:getZ()) > 0.707 then
if b3Aux:getDimZ() > b3Raw:getDimZ() - 1.0 then
bCross = true
dDepth = min( dDepth, b3Raw:getDimZ())
end
end
local nDouble = 1
local bCanDouble = ( abs( vtExtr:getY()) > 0.707 and bCross)
local dDimStrip = BD.DIM_STRIP
if dDimStrip < 0 then
dDimStrip = EgtGetInfo( Proc.Id, Q_DIM_STRIP, 'd') or 0
end
local bStripOnSide = false
if bCross then
if dDimStrip > 10 * GEO.EPS_SMALL and ( nStep > 1 or ( bDown and b3Aux:getDimX() > 0.5 * b3Raw:getDimX())) then
-- devo lasciare un codolo
dDepth = dDepth - dDimStrip
bStripOnSide = true
else
-- devo affondare un poco oltre
dDepth = dDepth + BD.CUT_EXTRA
end
end
-- se parametro beamdata forza codolo in centro e lavorazione orizzontale e se larghezza trave è sufficientemente larga
if BD.DIM_TO_CENTER_STRIP and BD.DIM_TO_CENTER_STRIP > 10 * GEO.EPS_SMALL and nStep > 1 and
bCanDouble and b3Raw:getDimY() > BD.DIM_TO_CENTER_STRIP - 0.1 then
nDouble = 2
dDepth = min( ( b3Raw:getDimY() - dDimStrip) * 0.5, dMaxDepth)
else
-- se altezza geometria supera capacità taglio utensile ed è orizzontale setto per eseguire codolo in centro
if dDepth > dMaxDepth then
if bCanDouble then
nDouble = 2
dDepth = min( 0.5 * dDepth, dMaxDepth)
else
dDepth = dMaxDepth
end
end
end
-- se lavorazione in doppio senza codolo, aggiungo sovrapposizione
if nDouble == 2 and dDimStrip < 10 * GEO.EPS_SMALL then
dDepth = dDepth + BD.MILL_OVERLAP / 2
end
-- se utensile orizzontale verso Y+, non in doppio e codolo da lasciare, devo invertire per lavorare sempre da Y-
if vtExtr:getY() > 0.707 and nDouble == 1 and bStripOnSide then
bToolInv = true
end
-- eseguo
for i = 1, nStep do
for j = 1, nDouble do
-- inserisco la lavorazione
local sName = 'Arch_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
local nMchId = EgtAddMachining( sName, sMilling)
if not nMchId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling
EgtOutLog( sErr)
return false, sErr
end
-- aggiungo geometria
EgtSetMachiningGeometry( {{ AuxId, -1}})
-- eventuale accorciamento di testa
if ( j == 1 and i > 1) or ( j == 2 and i < nStep) then
local dStartAddLen = EgtIf( j == 1, - ( i - 1) * dStep, - ( nStep - i) * dStep)
EgtSetMachiningParam( MCH_MP.STARTADDLEN, dStartAddLen)
end
-- eventuale accorciamento di coda
if ( j == 1 and i < nStep) or ( j == 2 and i > 1) then
local dEndAddLen = EgtIf( j == 1, - ( nStep - i) * dStep, - ( i - 1) * dStep)
EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEndAddLen)
end
-- se estrusione da sotto, inverto direzione fresa
if ( j == 1 and bToolInv) or ( j == 2 and not bToolInv) then
EgtSetMachiningParam( MCH_MP.TOOLINVERT, true)
end
-- se seconda passata, inverto direzione di lavoro
if ( j == 1 and not bToolInv) or ( j == 2 and bToolInv) then
EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false))
else
EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, false, true))
end
-- assegno affondamento
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
-- assegno lato di lavoro (per avere lavorazione climb)
EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bCW, MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT))
-- posizione braccio porta testa
local nSCC = MCH_SCC.NONE
if not BD.C_SIMM and not BD.TURN then
nSCC = MCH_SCC.ADIR_XP
if Proc.Head then
nSCC = MCH_SCC.ADIR_XP
elseif Proc.Tail then
nSCC = MCH_SCC.ADIR_XM
elseif AreSameOrOppositeVectorApprox( vtExtr, Z_AX()) then
nSCC = MCH_SCC.ADIR_YP
end
elseif BD.TURN == 2 then
nSCC = MCH_SCC.ADIR_ZP
elseif BD.TURN then
if vtN:getZ() > 0.707 then
nSCC = MCH_SCC.ADIR_ZP
elseif vtN:getZ() < -0.707 then
nSCC = MCH_SCC.ADIR_ZM
elseif vtN:getY() > 0.707 then
nSCC = MCH_SCC.ADIR_YP
elseif vtN:getY() < -0.707 then
nSCC = MCH_SCC.ADIR_YM
end
end
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
-- eseguo
if not ML.ApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchId, false)
return false, sErr
end
end
end
-- eventuale segnalazione ingombro di testa o coda
if Proc.Head then
BL.UpdateHCING( nRawId, b3Raw:getMax():getX() - dOvmHead - Proc.Box:getMin():getX())
elseif Proc.Tail then
BL.UpdateTCING( nRawId, Proc.Box:getMax():getX() - b3Solid:getMin():getX())
end
return true
end
---------------------------------------------------------------------
return ProcessRoundArch