Files
DataBeam/LuaLibs/ProcessTenon.lua
T
Dario Sassi 6eaba8a577 DataBeam :
- primo rilascio.
2019-04-01 15:18:51 +00:00

166 lines
6.6 KiB
Lua

-- ProcessTenon.lua by Egaltech s.r.l. 2019/03/23
-- Gestione calcolo tenone per Travi
-- Tabella per definizione modulo
local ProcessTenon = {}
-- Include
require( 'EgtBase')
local BL = require( 'BeamLib')
local Cut = require( 'ProcessCut')
EgtOutLog( ' ProcessTenon started', 1)
-- Dati
local BD = require( 'BeamData')
local Millings = require( 'MillingData')
---------------------------------------------------------------------
local function FindMilling( sType)
for i = 1, #Millings do
local Milling = Millings[i]
if Milling.Type == sType then
return i, Milling.Name
end
end
return 0
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)
-- recupero i dati della faccia top
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT)
-- verifico sia una superficie
if not vtN then
return false
end
-- verifico se il tenone è lavorabile solo da sotto
local bDown = ( vtN:getZ() < - 0.1)
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 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 e del top
local dDepth = abs( EgtCurveThickness( AuxId))
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT)
EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3)
-- verifico che il tenone non sia orientato verso il basso (-5 deg)
if vtN:getZ() < - 0.1 then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' Tenon from bottom impossible'
EgtOutLog( sErr)
return false, sErr
end
-- determino altezza del tenone
local frTen = Frame3d( ptC, vtN)
local b3Ten = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frTen)
local dTenH = b3Ten:getDimZ()
-- determino larghezza massima di svuotatura
local b3Aux = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frTen)
local dPockL = 0.5 * max( b3Ten:getDimX() - b3Aux:getDimX(), b3Ten:getDimY() - b3Aux:getDimY())
-- porto inizio curva il più possibile sul bordo
BL.PutStartNearestToEdge( AuxId, b3Solid)
-- 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 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 nMill, sMilling = FindMilling( 'Tenon')
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 dMillDiam = 20
if EgtMdbSetCurrMachining( sMilling) then
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam
end
end
-- determino il numero di passate concentriche
local nPass = ceil( dPockL / ( 0.5 * dMillDiam))
local dStep = dPockL / 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, 1) .. ';')
local dOffset = ( i - 1) * dStep
EgtSetMachiningParam( MCH_MP.OFFSR, dOffset)
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchFId, 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() - b3Raw:getMin():getX())
end
return true
end
---------------------------------------------------------------------
return ProcessTenon