e2b324fe9d
- aggiunta gestione svuotature con lati aperti in LapJoint e assimilate.
211 lines
8.3 KiB
Lua
211 lines
8.3 KiB
Lua
-- ProcessTenon.lua by Egaltech s.r.l. 2019/10/08
|
|
-- 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 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
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessDtTenon.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
|
|
-- ingombro del grezzo
|
|
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
|
|
-- 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) & 256) == 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 b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD)
|
|
local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC, vtN, b3Solid, GDB_RT.GLOB)
|
|
if AddId then
|
|
EgtRelocate( AddId, nAddGrpId)
|
|
EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id))
|
|
-- applico lavorazione
|
|
local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = Proc.Box, Fct = Proc.Fct, Flg = Proc.Flg}
|
|
local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, 0)
|
|
if not bOk then return bOk, sErr end
|
|
end
|
|
end
|
|
-- recupero la lavorazione
|
|
local sMilling = ML.FindMilling( 'DtTenon')
|
|
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
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dTDiam
|
|
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 4)
|
|
local MAX_PASS = 4
|
|
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 sgrossatura della 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) .. ';')
|
|
-- 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 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 ProcessDtTenon
|