1b6f8b3be4
- in Tenon se inclinati solo verticalmente e macchine tipo PF (BD.PRESS_ROLLER) si riduce l'ingombro di testa o coda - in LapJoint con 3 o più facce e principale verso il basso modificato criterio possibilità di lavorare su seconda faccia possibile.
312 lines
14 KiB
Lua
312 lines
14 KiB
Lua
-- ProcessTenon.lua by Egaltech s.r.l. 2022/12/12
|
|
-- Gestione calcolo tenone per Travi
|
|
-- 2021/10/04 Corretto calcolo HCING per pezzi piccoli.
|
|
-- 2022/02/15 Aggiornata VerifyOrientation per macchine con testa da sotto.
|
|
-- 2022/05/18 Migliorata gestione attacco.
|
|
-- 2022/05/28 Spostato calcolo svuotatura in modulo di libreria.
|
|
-- 2022/09/20 Migliorato il calcolo delle passate laterali; ora considera la reale distanza tra contorno del tenone e estremi della faccia
|
|
-- 2022/11/03 Corretto uso di bH2 (da sotto solo se anche bMillDown vero).
|
|
-- 2022/12/12 Su macchine con rulli pressori e pinze separate si riduce di meno l'ingombro con tenoni inclinati.
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessTenon = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
local Fbp = require( 'FaceByPocket')
|
|
local Cut = require( 'ProcessCut')
|
|
|
|
EgtOutLog( ' ProcessTenon started', 1)
|
|
|
|
-- Dati
|
|
local BD = require( 'BeamData')
|
|
local ML = require( 'MachiningLib')
|
|
|
|
|
|
---------------------------------------------------------------------
|
|
local function VerifyOrientation( Proc, vtN, b3Raw)
|
|
-- se PF con testa da sotto, ammessa qualunque orientazione
|
|
if BD.C_SIMM and BD.DOWN_HEAD then
|
|
return true
|
|
end
|
|
-- se trave molto bassa
|
|
if b3Raw:getDimZ() <= 120 then
|
|
-- se tenone praticamente in asse, accetto fino a -45 deg
|
|
if abs( vtN:getY()) < 0.04 then
|
|
return ( vtN:getZ() >= -0.7072)
|
|
-- altrimenti accetto fino a -30deg
|
|
else
|
|
return ( vtN:getZ() >= -0.51)
|
|
end
|
|
-- se trave bassa
|
|
elseif b3Raw:getDimZ() <= 200 then
|
|
-- se tenone praticamente in asse, accetto fino a -30 deg
|
|
if abs( vtN:getY()) < 0.04 then
|
|
return ( vtN:getZ() >= -0.51)
|
|
-- altrimenti accetto fino a -20deg
|
|
else
|
|
return ( vtN:getZ() >= -0.343)
|
|
end
|
|
-- se trave media
|
|
elseif b3Raw:getDimZ() <= 300 then
|
|
-- se tenone praticamente in asse, accetto fino a -20 deg
|
|
if abs( vtN:getY()) < 0.04 then
|
|
return ( vtN:getZ() >= -0.343)
|
|
-- altrimenti, accetto fino a -10 deg
|
|
else
|
|
return ( vtN:getZ() >= -0.174)
|
|
end
|
|
-- altrimenti
|
|
else
|
|
-- accetto fino a -5deg
|
|
return ( vtN:getZ() >= -0.088)
|
|
end
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Riconoscimento della feature
|
|
function ProcessTenon.Identify( Proc)
|
|
return ( (( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 50) or
|
|
(( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 52))
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessTenon.Classify( Proc, b3Raw)
|
|
-- recupero i dati della curva di contorno della faccia top
|
|
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
|
|
if not AuxId then return false end
|
|
AuxId = AuxId + Proc.Id
|
|
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
|
|
-- verifico se il tenone è lavorabile solo da sotto
|
|
local bDown = not VerifyOrientation( Proc, vtExtr, b3Raw)
|
|
return true, bDown
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessTenon.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
|
|
-- ingombro del grezzo
|
|
local b3Raw = EgtGetRawPartBBox( nRawId)
|
|
-- ingombro del pezzo
|
|
local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD)
|
|
if not b3Solid then
|
|
local sErr = 'Error : part box not found'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
local bShortPart = ( b3Solid:getDimX() < BD.LEN_SHORT_PART)
|
|
-- 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 : missing profile geometry'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati della curva di contorno della faccia top
|
|
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
|
|
local ptBC = EgtGP( AuxId, GDB_RT.GLOB)
|
|
local bClosed = EgtCurveIsClosed( AuxId)
|
|
-- verifico che il tenone non sia orientato troppo verso il basso
|
|
if not VerifyOrientation( Proc, vtExtr, b3Raw) then
|
|
local sErr = 'Error : Tenon from bottom impossible'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- determino altezza del tenone
|
|
local frTen = Frame3d( ptBC, vtExtr)
|
|
local b3Ten = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frTen)
|
|
local dTenH = b3Ten:getDimZ()
|
|
-- assegno centro e normale della faccia top
|
|
local vtN = vtExtr
|
|
local ptC = ptBC + vtN * dTenH
|
|
EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3)
|
|
-- determino larghezza svuotatura per calcolare il numero di passate laterali
|
|
-- ricavo i contorni della faccia principale
|
|
local nLoopId, nLoopCnt = EgtExtractSurfTmFacetLoops( Proc.Id, 0, EgtGetParent( Proc.Id))
|
|
local dPockL = 0
|
|
-- ricavo la massima distanza tra gli estremi della faccia e la curva del tenone
|
|
if nLoopId then
|
|
local dUmin, dUmax = EgtCurveDomain( nLoopId)
|
|
for dU = dUmin, dUmax do
|
|
local ptP = EgtUP( nLoopId, dU, GDB_ID.ROOT)
|
|
local ptNear = EgtNP( AuxId, ptP, GDB_ID.ROOT)
|
|
local dDist = dist( ptP, ptNear)
|
|
if dDist > dPockL then
|
|
dPockL = dDist
|
|
end
|
|
end
|
|
-- cancello i contorni dopo averli analizzati
|
|
for i = 1, nLoopCnt do
|
|
EgtErase( nLoopId + i - 1)
|
|
end
|
|
else
|
|
-- se il metodo sopra non funziona uso il metodo semplice (distanza tra gli angoli retti della curva tenone e faccia principale)
|
|
local b3Aux = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frTen)
|
|
local dPockX = max( b3Ten:getMax():getX() - b3Aux:getMax():getX(), b3Aux:getMin():getX() - b3Ten:getMin():getX())
|
|
local dPockY = max( b3Ten:getMax():getY() - b3Aux:getMax():getY(), b3Aux:getMin():getY() - b3Ten:getMin():getY())
|
|
dPockL = sqrt( dPockX * dPockX + dPockY * dPockY)
|
|
end
|
|
-- abilitazione lavorazione da sotto
|
|
local bMillUp = ( BD.DOWN_HEAD and vtExtr:getZ() > -0.259)
|
|
local bMillDown = ( BD.DOWN_HEAD and vtExtr:getZ() < 0.1)
|
|
-- se vero tenone inclinato o non esattamente alle estremità, necessario taglio di lama sulla testa
|
|
if Proc.Prc ~= 52 and
|
|
( not AreSameOrOppositeVectorApprox( vtN, X_AX()) or
|
|
( Proc.Box:getMax():getX() < b3Raw:getMax():getX() - dOvmHead - 100 * GEO.EPS_SMALL and
|
|
Proc.Box:getMin():getX() > b3Raw:getMin():getX() + 100 * GEO.EPS_SMALL)) then
|
|
-- recupero gruppo per geometria addizionale
|
|
local nAddGrpId = BL.GetAddGroup( nPartId)
|
|
if not nAddGrpId then
|
|
local sErr = 'Error : missing AddGroup'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- creo piano di taglio sulla testa del tenone e lo lavoro
|
|
local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC, vtN, b3Solid, GDB_RT.GLOB)
|
|
if AddId then
|
|
EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id))
|
|
EgtSetInfo( AddId, 'TASKID', Proc.TaskId)
|
|
-- se pezzo piccolo, in coda, con piano inclinato verso il basso e macchina con testa da sotto applico svuotatura
|
|
if bShortPart and vtExtr:getX() < 0 and vtExtr:getZ() < -0.09 and BD.DOWN_HEAD then
|
|
-- recupero la lavorazione
|
|
local sPockType = EgtIf( bMillDown, 'OpenPocket_H2', 'OpenPocket')
|
|
local sPocketing = ML.FindPocketing( sPockType, nil, nil, nil, not bMillDown, bMillDown)
|
|
if not sPocketing then
|
|
local sErr = 'Error : pocketing '..sPockType..' not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- eseguo le svuotature necessarie
|
|
local bOk, sErr = Fbp.Make( Proc, AddId, 0, sPocketing, nPartId, b3Solid)
|
|
if not bOk then
|
|
return false, sErr
|
|
end
|
|
-- altrimenti applico taglio di lama
|
|
else
|
|
local b3Cut = EgtGetBBoxGlob( AddId or GDB_ID.NULL, GDB_BB.STANDARD)
|
|
local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = b3Cut, Fct = 1, Flg = Proc.Flg,
|
|
Head = Proc.Head, Tail = Proc.Tail, CutId = Proc.CutId, TaskId = Proc.TaskId}
|
|
local bFromBottom = ( bShortPart and vtExtr:getZ() > 0.25)
|
|
local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, dOvmHead, bFromBottom)
|
|
if not bOk then
|
|
return false, sErr
|
|
end
|
|
end
|
|
end
|
|
end
|
|
-- recupero la lavorazione
|
|
local sMillType = 'Tenon'
|
|
local sMilling, _, _, bH2 = ML.FindMilling( sMillType, dTenH, nil, nil, nil, bMillUp, bMillDown)
|
|
if not sMilling then
|
|
sMilling, _, _, bH2 = ML.FindMilling( sMillType, nil, nil, nil, nil, bMillUp, bMillDown)
|
|
end
|
|
if not sMilling then
|
|
local sErr = 'Error : milling not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati dell'utensile
|
|
local dMillDiam = 20
|
|
local dMaxDepth = 0
|
|
local bCW = true
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam
|
|
dMaxDepth = ( EgtTdbGetCurrToolMaxDepth() or dMaxDepth)
|
|
local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0
|
|
bCW = ( dSpeed >= 0)
|
|
end
|
|
end
|
|
-- massimo numero di passate e coefficiente di sovrapposizione ta passate
|
|
local MAX_PASS = 6
|
|
local OVERLAP_COEFF = 0.7
|
|
-- porto inizio curva il più possibile sul bordo in alto o in basso
|
|
local dMaxDist = OVERLAP_COEFF * dMillDiam * MAX_PASS
|
|
local bMyShortPart = ( bShortPart and vtN:getX() < 0 and abs( vtN:getX()) < 0.999 and abs( vtN:getY()) < 0.259)
|
|
BL.PutStartNearestToEdge( AuxId, b3Solid, dMaxDist, EgtIf( bH2 and bMillDown, not bMyShortPart, bMyShortPart))
|
|
-- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente
|
|
local sWarn
|
|
local dDepth = 0
|
|
if dTenH > dMaxDepth + 10 * GEO.EPS_SMALL then
|
|
sWarn = 'Warning in tenon : elevation (' .. EgtNumToString( dTenH, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')'
|
|
dDepth = dMaxDepth - dTenH
|
|
dTenH = dMaxDepth
|
|
EgtOutLog( sWarn .. ' (process ' .. tostring( Proc.Id) .. ')')
|
|
end
|
|
-- determino il numero di passate concentriche (max 6)
|
|
local nPass = min( ceil( dPockL / ( OVERLAP_COEFF * dMillDiam)), MAX_PASS)
|
|
local dStep = min( dPockL, OVERLAP_COEFF * dMillDiam * MAX_PASS) / nPass
|
|
for i = nPass, 1, -1 do
|
|
-- inserisco la passata finale della lavorazione
|
|
local sNameF = 'TenF_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
|
|
local nMchFId = EgtAddMachining( sNameF, sMilling)
|
|
if not nMchFId then
|
|
local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ AuxId, -1}})
|
|
-- sistemo i parametri
|
|
EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dTenH - 100 * GEO.EPS_SMALL, 1) .. ';')
|
|
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
|
|
local dOffset = ( i - 1) * dStep
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, dOffset)
|
|
-- sistemo il lato e la direzione di lavoro
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bCW, MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT))
|
|
EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false))
|
|
-- se contorno aperto, cambio parametri di attacco/uscita
|
|
if not bClosed then
|
|
EgtSetMachiningParam( MCH_MP.LITANG, 0.7 * dMillDiam)
|
|
EgtSetMachiningParam( MCH_MP.LIPERP, 0)
|
|
EgtSetMachiningParam( MCH_MP.LOTANG, 0.7 * dMillDiam)
|
|
EgtSetMachiningParam( MCH_MP.LOPERP, 0)
|
|
end
|
|
-- imposto posizione braccio porta testa
|
|
local nSCC = MCH_SCC.NONE
|
|
if not BD.C_SIMM and not BD.TURN then
|
|
nSCC = MCH_SCC.ADIR_YM
|
|
if abs( vtExtr:getY()) > 0.088 then
|
|
nSCC = EgtIf( vtExtr:getX() < GEO.EPS_SMALL, MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP)
|
|
end
|
|
end
|
|
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
|
|
-- eseguo
|
|
if not ML.ApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
end
|
|
-- eventuale segnalazione ingombro di testa o coda
|
|
if abs( vtN:getY()) > 0.1 or ( b3Raw:getDimZ() - Proc.Box:getDimZ()) < BD.MIN_HEIGHT then
|
|
if Proc.Head then
|
|
local dOffs = b3Raw:getMax():getX() - dOvmHead - Proc.Box:getMin():getX()
|
|
local dDelta = 0
|
|
if abs( vtN:getY()) < 0.1 and vtN:getZ() > 0.5 then
|
|
dDelta = - EgtIf( BD.PRESS_ROLLER, 0.7, 0.5) * dOffs
|
|
end
|
|
if bShortPart and b3Raw:getDimZ() < BD.VICE_MINH and abs( vtN:getZ()) > 0.575 then
|
|
local b3Base = EgtSurfTmGetFacetBBoxGlob( Proc.Id, 0, GDB_BB.STANDARD)
|
|
dDelta = min( dDelta, - 0.825 * b3Base:getDimX())
|
|
end
|
|
dOffs = dOffs + dDelta
|
|
BL.UpdateHCING( nRawId, dOffs)
|
|
elseif Proc.Tail then
|
|
local dOffs = Proc.Box:getMax():getX() - b3Solid:getMin():getX()
|
|
if abs( vtN:getY()) < 0.1 and vtN:getZ() > 0.5 then
|
|
dOffs = EgtIf( BD.PRESS_ROLLER, 0.3, 0.5) * dOffs
|
|
end
|
|
BL.UpdateTCING( nRawId, dOffs)
|
|
end
|
|
end
|
|
return true, sWarn
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return ProcessTenon
|