Files
DataBeam/LuaLibs/ProcessProfCamb.lua
T
Dario Sassi 9d4336a8a9 DataBeam :
- altri miglioramenti alle lavorazioni dei profili.
2019-04-11 13:20:45 +00:00

265 lines
10 KiB
Lua

-- ProcessProfCamb.lua by Egaltech s.r.l. 2019/04/10
-- Gestione calcolo profilo caudato per Travi
-- Tabella per definizione modulo
local ProcessProfCamb = {}
-- Include
require( 'EgtBase')
local BL = require( 'BeamLib')
local Cut = require( 'ProcessCut')
EgtOutLog( ' ProcessProfCamb started', 1)
-- Dati
local BD = require( 'BeamData')
local Millings = require( 'MillingData')
---------------------------------------------------------------------
-- Riconoscimento della feature
function ProcessProfCamb.Identify( Proc)
return (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 103)
end
---------------------------------------------------------------------
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
---------------------------------------------------------------------
local function GetSawCutData( AuxId, vtNF)
-- comincio con la normale a 45deg
local vtNP = Vector3d( vtNF)
for i = 1, 3 do
if vtNP[i] > GEO.EPS_SMALL then
vtNP[i] = 1
elseif vtNP[i] < -GEO.EPS_SMALL then
vtNP[i] = -1
end
end
vtNP:normalize()
-- assegno un punto di passaggio
local ptStart = EgtSP( AuxId, GDB_ID.ROOT) + vtNP * 5.0
-- determino asse di rotazione
local vtRot = - Y_AX()
if vtNF:getX() < 0 then vtRot = - vtRot end
if vtNF:getZ() < -0.1 then
vtRot = - vtRot
elseif vtNF:getY() < -0.1 then
vtRot:rotate( X_AX(), 90)
elseif vtNF:getY() > 0.1 then
vtRot:rotate( X_AX(), -90)
end
-- miglioro l'inclinazione (ripartendo da faccia perpendicolare asse trave)
vtNP[2] = 0 vtNP[3] = 0
local dRot = 45
for i = 1, 4 do
local vtNP2 = Vector3d( vtNP)
vtNP2:rotate( vtRot, dRot)
local frRef = Frame3d( ptStart, vtNP2)
local b3Box = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frRef)
if b3Box:getMax():getZ() < -3 then
vtNP = Vector3d( vtNP2)
end
dRot = dRot / 2
end
-- restituisco i dati del piano
return ptStart, vtNP
end
---------------------------------------------------------------------
-- Applicazione della lavorazione
function ProcessProfCamb.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH)
-- ingombro del grezzo
local b3Raw = EgtGetRawPartBBox( nRawId)
-- 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 dProfDepth = abs( EgtCurveThickness( AuxId))
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
local nLastFacet = EgtSurfTmFacetCount( Proc.Id) - 1 -- ultima faccia
local nRefFacet = nLastFacet - 1 -- penultima faccia
local vtNF = EgtSurfTmFacetNormVersor( Proc.Id, nLastFacet, GDB_ID.ROOT)
local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nRefFacet, GDB_ID.ROOT)
-- verifico se in testa o coda
local bHead = ( vtNF:getX() > 0)
EgtOutLog( 'vtN=' .. tostring( vtN), 3)
-- verifico se profilo orientato verso l'alto (1), il basso (-1) o di fianco (0)
local nSide = 0
if vtN:getZ() > 0.1 then
nSide = 1
elseif vtN:getZ() < -0.1 then
nSide = -1
end
-- 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
-- aggiungo taglio di lama di sgrossatura e lo lavoro
local ptStart, vtNP = GetSawCutData( AuxId, vtNF)
local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD)
local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptStart, vtNP, b3Solid, GDB_RT.GLOB)
if AddId then
EgtRelocate( AddId, nAddGrpId)
EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id))
-- applico la 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
-- recupero la lavorazione
local nMill, sMilling = FindMilling( 'Prof')
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 dToolMaxDepth = 0
if EgtMdbSetCurrMachining( sMilling) then
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
dToolMaxDepth = EgtTdbGetCurrToolMaxDepth()
end
end
-- verifico se necessario lavorare in doppio
local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth)
local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP)
-- inserisco la lavorazione
local sName = 'Prof_' .. ( 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}})
-- se lavorazione da sopra o da sotto
if nSide ~= 0 then
-- se lavorazione a destra di fronte o sinistra da dietro, inverto
if ( bHead and vtExtr:getY() < -0.1) or
( not bHead and vtExtr:getY() > 0.1) then
EgtSetMachiningParam( MCH_MP.TOOLINVERT, true)
EgtSetMachiningParam( MCH_MP.INVERT, true)
end
-- altrimenti lavorazione dal davanti o dal dietro
else
-- se fresa verso il basso, la porto verso l'alto
if vtExtr:getZ() < 0 then
EgtSetMachiningParam( MCH_MP.TOOLINVERT, true)
EgtSetMachiningParam( MCH_MP.INVERT, true)
end
-- se lavorazione a destra da dietro o sinistra di fronte, inverto
if ( bHead and vtNF:getY() > 0.1) or
( not bHead and vtNF:getY() < -0.1) then
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT)
EgtSetMachiningParam( MCH_MP.INVERT, true)
end
end
-- se in doppio, imposto l'affondamento
if bDouble then
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
end
-- posizione braccio porta testa
EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM))
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchId, false)
return false, sErr
end
-- se lavorazione da due parti, aggiungo la seconda
if bDouble then
-- inserisco la lavorazione
local sName = 'ProfB_' .. ( 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}})
-- sempre lavorazione da sopra o da sotto
-- se lavorazione a destra di fronte o sinistra da dietro, inverto
if ( bHead and vtExtr:getY() > 0.1) or
( not bHead and vtExtr:getY() < -0.1) then
EgtSetMachiningParam( MCH_MP.TOOLINVERT, true)
EgtSetMachiningParam( MCH_MP.INVERT, true)
end
-- imposto l'affondamento
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
-- posizione braccio porta testa
EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM))
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchId, false)
return false, sErr
end
end
-- se non da sotto, inserisco lavorazione finitura angolo
if nSide ~= -1 then
sName = 'ProfV_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
local nMchVId = EgtAddMachining( sName, sMilling)
if not nMchVId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling
EgtOutLog( sErr)
return false, sErr
end
-- aggiungo geometria
EgtSetMachiningGeometry( {{ Proc.Id, nLastFacet}})
-- aggiusto i parametri
EgtSetMachiningParam( MCH_MP.INVERT, true)
EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH')
EgtSetMachiningParam( MCH_MP.STEP, 0)
EgtSetMachiningParam( MCH_MP.OFFSR, -0.5)
-- imposto tipo uso faccia
local nFaceUse = MCH_MILL_FU.ORTHO_DOWN
if nSide ~= 1 then
nFaceUse = EgtIf( vtN:getY() > 0.1, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_BACK)
end
EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse)
-- imposto posizione braccio porta testa
local nSCC = MCH_SCC.ADIR_YM
if vtN:getY() > 100 * GEO.EPS_ZERO then
nSCC = MCH_SCC.ADIR_YP
end
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchVId, false)
return false, sErr
end
end
-- aggiorno ingombro testa o coda per presa
if nSide == 0 then
if bHead then
BL.UpdateHCING( nRawId, b3Raw:getMax():getX() - dCurrOvmH - Proc.Box:getMin():getX())
else
BL.UpdateTCING( nRawId, Proc.Box:getMax():getX() - b3Raw:getMin():getX())
end
end
return true
end
---------------------------------------------------------------------
return ProcessProfCamb