d585a45b18
- in Tenoni DT angolo limite per testa sotto portato a +10 gradi - in LapJoint migliorato controllo diametro frese per svuotature, con testa sotto non si controlla vtNz per cambiare faccia, migliorata scelta utensile per svuotatura.
325 lines
13 KiB
Lua
325 lines
13 KiB
Lua
-- ProcessTenon.lua by Egaltech s.r.l. 2021/03/01
|
|
-- Gestione calcolo tenone a coda di rondine per Travi
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessDtTenon = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
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 ProcessDtTenon.Identify( Proc)
|
|
return ( ( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 55)
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessDtTenon.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
|
|
|
|
---------------------------------------------------------------------
|
|
local function ApplyPocket( Proc, sPocketing, nStep, dSurfStep, nIdSurf, vtExtr)
|
|
|
|
-- inserisco la lavorazione di svuotatura
|
|
local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. nStep
|
|
local nMchFId = EgtAddMachining( sName, sPocketing)
|
|
if not nMchFId then
|
|
local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ nIdSurf, -1}})
|
|
-- imposto uso faccia
|
|
EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_CONT)
|
|
if dSurfStep > 0 then
|
|
-- imposto elevazione
|
|
local sNotes = 'MaxElev=' .. EgtNumToString( dSurfStep, 2) .. ';'
|
|
EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes)
|
|
end
|
|
-- imposto posizione braccio porta testa
|
|
local nSCC = MCH_SCC.NONE
|
|
if not BD.C_SIMM then
|
|
nSCC = EgtIf( vtExtr:getX() < GEO.EPS_SMALL, MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP)
|
|
end
|
|
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
|
|
-- eseguo
|
|
if not EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessDtTenon.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 on process ' .. tostring( Proc.Id) .. ' part box not found'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- 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
|
|
local dDepth = abs( EgtCurveThickness( AuxId))
|
|
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
|
|
local ptBC = EgtGP( AuxId, GDB_RT.GLOB)
|
|
-- verifico che il tenone non sia orientato verso il basso
|
|
if not VerifyOrientation( Proc, vtExtr, b3Raw) then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' DtTenon from bottom impossible'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- determino altezza del tenone
|
|
local frDtTen = Frame3d( ptBC, vtExtr)
|
|
local b3DtTen = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frDtTen)
|
|
local dDtTenH = b3DtTen:getDimZ()
|
|
-- assegno centro e normale della faccia top
|
|
local vtN = vtExtr
|
|
local ptC = ptBC + vtN * dDtTenH
|
|
EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3)
|
|
-- porto inizio curva a Zmax
|
|
BL.PutStartOnTop( AuxId)
|
|
-- se tenone inclinato o non esattamente alle estremità, necessario taglio di lama sulla testa
|
|
if 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 on process ' .. tostring( Proc.Id) .. ' 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 e piano inclinato attorno a Z applico svuotatura
|
|
if b3Solid:getDimX() < BD.LEN_SHORT_PART and vtExtr:getX() < 0 and abs( vtExtr:getY()) > 0.173 then
|
|
local sPocketing = ML.FindPocketing( 'OpenPocket')
|
|
local dMaxDepth = 100
|
|
local dStep = 30
|
|
local nSurfStep
|
|
-- acquisisco i dati necessari dall'utensile
|
|
if EgtMdbSetCurrMachining( sPocketing) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
dStep = EgtMdbGetCurrMachiningParam( MCH_MP.STEP) or dStep
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth
|
|
end
|
|
end
|
|
-- acquisisco elevazione
|
|
local dElev = BL.GetFaceElevation( AddId, 0, nPartId)
|
|
nSurfStep = ceil( dElev / dMaxDepth)
|
|
dSurfStep = dElev / nSurfStep
|
|
local bOk = true
|
|
local sErr
|
|
-- copio superfice al passo superfice e ci applico la lavorazione
|
|
for i = nSurfStep, 2, -1 do
|
|
local nAddIdTmp = EgtSurfTmPlaneInBBox( nAddGrpId, ptC+((dSurfStep*(i-1))*vtN), vtN, b3Solid, GDB_RT.GLOB)
|
|
if nAddIdTmp then
|
|
EgtSetName( nAddIdTmp, 'AddCut_' .. tostring( Proc.Id))
|
|
EgtSetInfo( nAddIdTmp, 'TASKID', Proc.TaskId)
|
|
-- aggiungo lavorazione
|
|
bOk, sErr = ApplyPocket( Proc, sPocketing, i, (dSurfStep + 0), nAddIdTmp, vtExtr)
|
|
if not bOk then
|
|
break
|
|
end
|
|
end
|
|
end
|
|
if not bOk then
|
|
return false, sErr
|
|
end
|
|
-- faccio ultima superfice
|
|
bOk, sErr = ApplyPocket( Proc, sPocketing, 1, EgtIf( nSurfStep > 1, ( dSurfStep + 0), 0), AddId, vtExtr)
|
|
if not bOk then
|
|
return false, sErr
|
|
end
|
|
-- altrimenti applico taglio di lama
|
|
else
|
|
local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = Proc.Box, Fct = Proc.Fct, Flg = Proc.Flg,
|
|
Head = Proc.Head, Tail = Proc.Tail, CutId = Proc.CutId, TaskId = Proc.TaskId}
|
|
local bFromBottom = ( b3Solid:getDimX() < BD.LEN_SHORT_PART and vtExtr:getZ() > 0.25)
|
|
local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, dOvmHead, bFromBottom)
|
|
if not bOk then return bOk, sErr end
|
|
end
|
|
end
|
|
end
|
|
-- abilitazione lavorazione da sotto
|
|
local bMillUp = ( BD.DOWN_HEAD and vtExtr:getZ() > -0.259)
|
|
local bMillDown = ( BD.DOWN_HEAD and vtExtr:getZ() < 0.174)
|
|
-- recupero la lavorazione
|
|
local sMillType = 'DtTenon'
|
|
local sMilling = ML.FindMilling( sMillType .. EgtIf( bMillDown, '_H2', ''))
|
|
if not sMilling and bMillUp then
|
|
sMilling = ML.FindMilling( sMillType)
|
|
end
|
|
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 dTDiam = 50
|
|
local bCW = true
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dTDiam
|
|
local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0
|
|
bCW = ( dSpeed >= 0)
|
|
end
|
|
end
|
|
-- calcolo distanza massima della curva dal punto più lontano della base tenone Dt (facet 0)
|
|
local dMaxDist = 0
|
|
local nLoopId, nLoopCnt = EgtExtractSurfTmFacetLoops( Proc.Id, 0, EgtGetParent( Proc.Id))
|
|
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 > dMaxDist then
|
|
dMaxDist = dDist
|
|
end
|
|
end
|
|
for i = 1, nLoopCnt do
|
|
EgtErase( nLoopId + i - 1)
|
|
end
|
|
else
|
|
local b3DtAux = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frDtTen)
|
|
dMaxDist = 2 * ( b3DtTen:getRadius() - b3DtAux:getRadius())
|
|
end
|
|
EgtOutLog( 'MaxDist=' .. EgtNumToString( dMaxDist, 3), 3)
|
|
-- Cicli di lavorazione (max 6)
|
|
local MAX_PASS = 6
|
|
local nStep = min( ceil( dMaxDist / ( 0.7 * dTDiam)), MAX_PASS)
|
|
local dStep = min( dMaxDist, 0.7 * dTDiam * MAX_PASS) / nStep
|
|
for i = nStep, 1, -1 do
|
|
-- inserisco la passata di lavorazione
|
|
local sNameR = 'DtTn_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i)
|
|
local nMchRId = EgtAddMachining( sNameR, sMilling)
|
|
if not nMchRId then
|
|
local sErr = 'Error adding machining ' .. sNameR .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ AuxId, -1}})
|
|
-- sistemo i parametri
|
|
local dOffs = ( i - 1) * dStep
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, dOffs)
|
|
EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dDtTenH, 1) .. ';')
|
|
-- 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))
|
|
-- imposto posizione braccio porta testa
|
|
local nSCC = MCH_SCC.NONE
|
|
if not BD.C_SIMM 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 EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchRId, 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()
|
|
if abs( vtN:getY()) < 0.1 and vtN:getZ() > 0.5 then
|
|
dOffs = dOffs / 2
|
|
end
|
|
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 = dOffs / 2
|
|
end
|
|
BL.UpdateTCING( nRawId, dOffs)
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return ProcessDtTenon
|