603 lines
25 KiB
Lua
603 lines
25 KiB
Lua
-- ProcessScarfJoint.lua by Egaltech s.r.l. 2022/09/30
|
|
-- Gestione calcolo giunto Gerber per Travi
|
|
-- 2021/06/28 Aggiunto extra-taglio alle lamate orizzontali.
|
|
-- 2022/06/10 Aggiunto il parametro dOvmTail per gestire sovramateriali in coda diversi da OVM_MID (sezioni alte e larghe)
|
|
-- 2022/07/12 Aggiunta gestione PF1250 e TURN.
|
|
-- 2023/02/14 Gestite le rotazioni di 90 deg nell'aggiornamento del grezzo.
|
|
-- 2024/09/03 In ApplyDiceCut, se possibile, i tagli paralleli sono fatti con un unico passaggio di fianco.
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessScarfJoint = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
local Fbs = require( 'FacesBySaw')
|
|
local DC = require( 'DiceCut')
|
|
|
|
EgtOutLog( ' ProcessScarfJoint started', 1)
|
|
|
|
-- Dati
|
|
local BD = require( 'BeamData')
|
|
local ML = require( 'MachiningLib')
|
|
|
|
---------------------------------------------------------------------
|
|
-- Riconoscimento della feature
|
|
function ProcessScarfJoint.Identify( Proc)
|
|
return (( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 71)
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessScarfJoint.Classify( Proc)
|
|
-- se PF con testa da sotto o TURN, ammessa qualunque orientazione
|
|
if ( BD.C_SIMM and BD.DOWN_HEAD) or BD.TURN then
|
|
return true
|
|
end
|
|
-- verifico le normali delle facce
|
|
local nFacetCnt = EgtSurfTmFacetCount( Proc.Id)
|
|
for i = 1, nFacetCnt do
|
|
local vtN = EgtSurfTmFacetNormVersor( Proc.Id, i-1, GDB_ID.ROOT)
|
|
if vtN:getZ() < - 0.5 and Proc.Box:getDimX() / abs( vtN:getZ()) > BD.MAX_DIM_DICE then
|
|
return true, true
|
|
end
|
|
end
|
|
return true, false
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- lavorazione smussi
|
|
local function MakeChamfer( Proc, nPhase, nRawId, nPartId, dOvmHead)
|
|
-- verifico che lo smusso sia richiesto
|
|
local dDepth = EgtGetInfo( Proc.Id, 'Q02', 'd') or 0
|
|
if dDepth < 0.1 then return true end
|
|
-- ingombro del grezzo
|
|
local b3Raw = EgtGetRawPartBBox( nRawId)
|
|
-- recupero e verifico l'entità curva associata
|
|
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 e del profilo
|
|
local dWidth = abs( EgtCurveThickness( AuxId))
|
|
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
|
|
-- eseguo lo smusso solo se direzione orizzontale (non propago la segnalazione a TS3)
|
|
if abs( vtExtr:getZ()) > 0.1 then
|
|
local sWarn = 'Warning : skipped not horizontal chamfer'
|
|
EgtOutLog( sWarn)
|
|
return true
|
|
end
|
|
-- eseguo lo smusso solo se feature larga come la trave
|
|
if dWidth < b3Raw:getDimY() - 1 then
|
|
local sWarn = 'Warning : skipped chamfer (feature smaller than beam)'
|
|
EgtOutLog( sWarn)
|
|
return true, sWarn
|
|
end
|
|
local dExtra = 2
|
|
-- recupero la lavorazione
|
|
local sMilling = ML.FindMilling( 'Mark')
|
|
if not sMilling then
|
|
local sErr = 'Error : milling not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- Inserisco la lavorazione del lato standard
|
|
local sName1 = 'SJN_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
|
|
local nMch1Id = EgtAddMachining( sName1, sMilling)
|
|
if not nMch1Id then
|
|
local sErr = 'Error adding machining ' .. sName1 .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ AuxId, -1}})
|
|
-- assegno affondamento e offset radiale
|
|
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth + dExtra)
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, dExtra)
|
|
-- assegno lato di lavoro
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT)
|
|
-- eseguo
|
|
if not ML.ApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMch1Id, false)
|
|
return false, sErr
|
|
end
|
|
-- Inserisco la lavorazione del lato opposto
|
|
local sName2 = 'SJN_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
|
|
local nMch2Id = EgtAddMachining( sName2, sMilling)
|
|
if not nMch2Id then
|
|
local sErr = 'Error adding machining ' .. sName2 .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ AuxId, -1}})
|
|
-- inverto direzione utensile
|
|
EgtSetMachiningParam( MCH_MP.TOOLINVERT, true)
|
|
-- assegno affondamento e offset radiale
|
|
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth + dExtra)
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, dExtra)
|
|
-- assegno lato di lavoro
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT)
|
|
-- eseguo
|
|
if not ML.ApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMch2Id, false)
|
|
return false, sErr
|
|
end
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
local function ApplyDiceCut( vFaceOrd, nGoodFace1, nGoodFace4, nAddGrpId, b3Solid, ptC, vtN, Proc, vtRef, bHead, sCutting, dSawDiam, b3Raw, dNewDiceDim)
|
|
|
|
local bOk = true
|
|
local bOk2 = true
|
|
local sErr = ''
|
|
local sErr2 = ''
|
|
|
|
local vCuts = {}
|
|
if nGoodFace1 and nGoodFace4 and nGoodFace1 > 0 and nGoodFace4 > 0 then
|
|
-- lavoro solo la faccia inclinata perché la faccia tappo completa la lavoro successivamente
|
|
-- questo evita di lavorare due volte la faccia tappo
|
|
vCuts = DC.GetDice( nAddGrpId, b3Solid, ptC[vFaceOrd[4]], vtN[vFaceOrd[4]], false, ptC[vFaceOrd[1]], vtN[vFaceOrd[1]], nil, dNewDiceDim)
|
|
elseif nGoodFace4 and nGoodFace4 > 0 then
|
|
vCuts = DC.GetDice( nAddGrpId, b3Solid, ptC[vFaceOrd[4]], vtN[vFaceOrd[4]], true, nil, nil, nil, dNewDiceDim)
|
|
end
|
|
|
|
local dVzLimDwnUp = EgtIf( vtRef:getZ() < -0.017, -2, nil)
|
|
|
|
if #vCuts > 0 then
|
|
-- sistemo posizione nel DB e nome
|
|
for i = 1, #vCuts do
|
|
for j = 1, #vCuts[i] do
|
|
EgtSetName( vCuts[i][j], 'AddCut_' .. tostring( Proc.Id))
|
|
EgtSetInfo( vCuts[i][j], 'TASKID', Proc.TaskId)
|
|
end
|
|
end
|
|
-- calcolo secondo riferimento per testa o coda
|
|
local vtRef2 = EgtIf( bHead, X_AX(), -X_AX())
|
|
-- eseguo
|
|
for i = 1, #vCuts do
|
|
local vtOrthoO
|
|
if i % 2 == 1 then
|
|
vtOrthoO = Vector3d( vtRef)
|
|
else
|
|
if #vCuts[i-1] > 0 then
|
|
vtOrthoO = Vector3d( EgtIf( vtRef2, vtRef2, vtRef))
|
|
else
|
|
local vtO
|
|
for j = 1, #vCuts[i-1] do
|
|
_, vtO = EgtSurfTmFacetCenter( vCuts[i-1][j], 0, GDB_ID.ROOT)
|
|
break
|
|
end
|
|
if vtO then
|
|
vtOrthoO = Vector3d( vtO)
|
|
else
|
|
if vtN[vFaceOrd[4]]:getZ() < 0.1 then
|
|
vtOrthoO = Z_AX()
|
|
else
|
|
vtOrthoO = Y_AX()
|
|
end
|
|
end
|
|
end
|
|
end
|
|
-- extra taglio
|
|
local dExtraCut = EgtIf( i % 2 == 1, 0, BD.CUT_EXTRA)
|
|
-- lavoro la faccia
|
|
local dMaxDepth = 0
|
|
if EgtMdbSetCurrMachining( sCutting) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth
|
|
end
|
|
end
|
|
|
|
-- controllo per eseguire solo un taglio ottimizzato
|
|
local bExecJustOneCut = false
|
|
local dDiceFaceDim = GEO.INFINITO
|
|
if ( i % 2) == 0 then
|
|
for cont = 1, #vCuts[i] do
|
|
local _, dDiceFaceH, dDiceFaceV = BL.GetFaceHvRefDim( vCuts[i][cont], 0)
|
|
-- se feature verso Z, si ammette anche lavorazione in doppio
|
|
if AreSameVectorApprox( vtRef, Z_AX()) then
|
|
if dMaxDepth * 2 > dDiceFaceH + BD.CUT_EXTRA then
|
|
bExecJustOneCut = true
|
|
dDiceFaceDim = dDiceFaceH
|
|
break
|
|
end
|
|
elseif AreSameVectorApprox( vtRef, Y_AX()) or AreSameVectorApprox( vtRef, -Y_AX()) then
|
|
if dMaxDepth > dDiceFaceV + BD.CUT_EXTRA then
|
|
bExecJustOneCut = true
|
|
dDiceFaceDim = dDiceFaceV
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
-- se si può fare, faccio unico taglio parallelo
|
|
if bExecJustOneCut then
|
|
local bDoubleCut = false
|
|
local dCutExtra = BD.CUT_EXTRA
|
|
if dMaxDepth < dDiceFaceDim then
|
|
bDoubleCut = true
|
|
end
|
|
local nSurfToCut = EgtSurfTmBySewing( nAddGrpId, vCuts[i], false)
|
|
|
|
local nFaceUseCut1, nFaceUseCut2
|
|
-- se feature rivolta verso alto setto direzione taglio davanti e dietro
|
|
if AreSameVectorApprox( vtRef, Z_AX()) then
|
|
nFaceUseCut1, nFaceUseCut2 = MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT
|
|
-- altrimenti taglio da sopra
|
|
else
|
|
nFaceUseCut2 = MCH_MILL_FU.ORTHO_DOWN
|
|
end
|
|
|
|
if Proc.Tail and AreSameVectorApprox( vtRef, Z_AX()) then
|
|
nFaceUseCut1, nFaceUseCut2 = nFaceUseCut2, nFaceUseCut1
|
|
end
|
|
if bDoubleCut then
|
|
bOk, sErr = Fbs.MakeOne( nSurfToCut, 0, sCutting, dSawDiam, nFaceUseCut1, nil, dCutExtra, BD.CUT_SIC, 0, 0, 0, '', b3Raw, true)
|
|
if not bOk then return false, sErr end
|
|
end
|
|
bOk2, sErr2 = Fbs.MakeOne( nSurfToCut, 0, sCutting, dSawDiam, nFaceUseCut2, nil, dCutExtra, BD.CUT_SIC, 0, 0, 0, '', b3Raw)
|
|
if not bOk2 then return false, sErr2 end
|
|
else
|
|
for j = 1, #vCuts[i] do
|
|
bOk, sErr = Fbs.MakeOne( vCuts[i][j], 0, sCutting, dSawDiam, vtOrthoO, dVzLimDwnUp, dExtraCut, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sErr end
|
|
end
|
|
end
|
|
end
|
|
-- lavoro la faccia interna in ogni caso
|
|
if vFaceOrd[1] ~= 0 then
|
|
-- inserisco la lavorazione
|
|
local vtOrthoO = Vector3d( vtRef)
|
|
bOk, sErr = Fbs.MakeOne( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, vtOrthoO, dVzLimDwnUp, 0, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sErr end
|
|
end
|
|
-- lavoro la faccia opposta (definita dal parametro P11)
|
|
if vFaceOrd[3] ~= 0 then
|
|
-- inserisco la lavorazione
|
|
local vtOrthoO = Vector3d( vtRef)
|
|
bOk, sErr = Fbs.MakeOne( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, vtOrthoO, dVzLimDwnUp, 0, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sErr end
|
|
end
|
|
end
|
|
|
|
return bOk, sErr, vCuts
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessScarfJoint.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, dOvmTail)
|
|
-- sovramateriale di coda
|
|
dOvmTail = dOvmTail or BD.OVM_MID
|
|
-- recupero l'ingombro del grezzo di appartenenza
|
|
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 : part box not found'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
|
|
-- verifico che ci siano almeno quattro facce (altrimenti non è da lavorare)
|
|
local nFacetCnt = EgtSurfTmFacetCount( Proc.Id)
|
|
if nFacetCnt < 3 then
|
|
local sErr = 'Error : number of faces not enough'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
|
|
-- dati delle facce
|
|
local ptC = {}
|
|
local vtN = {}
|
|
for i = 1, nFacetCnt do
|
|
ptC[i], vtN[i] = EgtSurfTmFacetCenter( Proc.Id, i-1, GDB_ID.ROOT)
|
|
end
|
|
|
|
-- ordino le facce in base al loro numero e al parallelismo delle due facce principali
|
|
-- faccia 1: superficie tappo
|
|
-- faccia 2: superficie principale di fondo
|
|
-- faccia 3: superficie opposta alla faccia 1
|
|
-- faccia 4: superficie principale superiore
|
|
-- faccia 5: superficie di testa
|
|
local vtRef
|
|
local vFaceOrd = { 0, 0, 0, 0, 0}
|
|
if nFacetCnt == 5 then -- se ho 5 facce controllo il parallelismo della faccia 2 e 4
|
|
if not AreSameVectorApprox( vtN[2], vtN[4]) then
|
|
local sErr = 'Error : main faces are not parallel (btl import problems)'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- carico gli id delle facce
|
|
for i = 1, nFacetCnt do
|
|
vFaceOrd[i] = i
|
|
end
|
|
-- vettore di riferimento per le facce ortogonali all'asse trave
|
|
vtRef = Vector3d( 0, vtN[vFaceOrd[4]]:getY(), vtN[vFaceOrd[4]]:getZ())
|
|
elseif nFacetCnt == 4 then -- se ho 4 facce
|
|
if AreSameVectorApprox( vtN[1], vtN[3]) then -- sono nel caso in cui manca la faccia 1
|
|
for i = 1, nFacetCnt do
|
|
vFaceOrd[i+1] = i
|
|
end
|
|
elseif AreSameVectorApprox( vtN[2], vtN[4]) then -- sono nel caso in cui manca la faccia 5
|
|
for i = 1, nFacetCnt do
|
|
vFaceOrd[i] = i
|
|
end
|
|
else -- altrimenti ho una condizione di facce non previsto e do errore
|
|
local sErr = 'Error : crazy faces(4)'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- vettore di riferimento per le facce ortogonali all'asse trave
|
|
vtRef = Vector3d( 0, vtN[vFaceOrd[4]]:getY(), vtN[vFaceOrd[4]]:getZ())
|
|
elseif nFacetCnt == 3 then -- se ho 3 facce
|
|
if AreSameVectorApprox( vtN[1], vtN[3]) then -- sono nel caso in cui manca la faccia 1
|
|
for i = 1, nFacetCnt do
|
|
vFaceOrd[i+1] = i
|
|
end
|
|
-- vettore di riferimento per le facce ortogonali all'asse trave
|
|
vtRef = Vector3d( 0, vtN[vFaceOrd[4]]:getY(), vtN[vFaceOrd[4]]:getZ())
|
|
else
|
|
for i = 1, nFacetCnt do
|
|
vFaceOrd[i] = i
|
|
end
|
|
-- vettore di riferimento per le facce ortogonali all'asse trave
|
|
vtRef = Vector3d( 0, vtN[vFaceOrd[2]]:getY(), vtN[vFaceOrd[2]]:getZ())
|
|
end
|
|
end
|
|
|
|
-- determino se di testa o di coda
|
|
local bHead = ( vtN[1]:getX() > 0)
|
|
|
|
-- normalizzo vettore di riferimento per le facce ortogonali all'asse trave
|
|
vtRef:normalize()
|
|
|
|
-- inserimento smussi
|
|
local bOkc, sErrC = MakeChamfer( Proc, nPhase, nRawId, nPartId, dOvmHead)
|
|
if not bOkc then return bOkc, sErrC end
|
|
|
|
-- abilitazione lavorazione da sotto (testa da sotto e direzione normale sotto -20deg)
|
|
local bDownHead = ( BD.DOWN_HEAD and vtRef:getZ() < -0.01)
|
|
local bTopHead = ( BD.DOWN_HEAD and ( vtRef:getZ() > -0.01 or not bDownHead))
|
|
|
|
-- recupero la lavorazione
|
|
local sCutting = ML.FindCutting( 'HeadSide', bTopHead, bDownHead)
|
|
if not sCutting then
|
|
local sErr = 'Error : cutting not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati dell'utensile
|
|
local dSawDiam = 400
|
|
local dMaxDepth = 0
|
|
if EgtMdbSetCurrMachining( sCutting) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam
|
|
dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth
|
|
end
|
|
end
|
|
|
|
-- 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 superfici partendo da punto e versore delle facce 4 (inclinata) e 1 (tappo)
|
|
local nFace1
|
|
local nFace4
|
|
local nGoodFace1
|
|
local nGoodFace4
|
|
if vtN[vFaceOrd[4]] then
|
|
nFace4 = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vFaceOrd[4]], vtN[vFaceOrd[4]], b3Solid, GDB_ID.ROOT)
|
|
end
|
|
if vtN[vFaceOrd[1]] then
|
|
nFace1 = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vFaceOrd[1]], vtN[vFaceOrd[1]], b3Solid, GDB_ID.ROOT)
|
|
end
|
|
if nFace4 and nFace1 then
|
|
-- taglio la superficie di tappo e quella inclinata per capire se per il taglio a cubetti si devono considerare una o due superfici
|
|
local bOk = EgtCutSurfTmPlane( nFace1, ptC[vFaceOrd[4]], -vtN[vFaceOrd[4]], false, GDB_ID.ROOT)
|
|
bOk = bOk and EgtCutSurfTmPlane( nFace4, ptC[vFaceOrd[1]], -vtN[vFaceOrd[1]], false, GDB_ID.ROOT)
|
|
|
|
if not bOk then
|
|
local sErr = 'Error : wrong cut surfaces'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- se esistono faccia interna ed intermedia, verifico se richiedono taglio a cubetti
|
|
nGoodFace1 = EgtSurfTmFacetCount( nFace1)
|
|
nGoodFace4 = EgtSurfTmFacetCount( nFace4)
|
|
elseif nFace4 then
|
|
nGoodFace4 = EgtSurfTmFacetCount( nFace4)
|
|
elseif nFace1 then
|
|
nGoodFace1 = EgtSurfTmFacetCount( nFace1)
|
|
end
|
|
|
|
-- per macchina TURN aggiusto massima dimensione cubetto
|
|
local dNewDiceDim
|
|
if BD.TURN and nGoodFace4 and nGoodFace4 > 0 then
|
|
local dDimRef = EgtIf( abs( vtN[vFaceOrd[4]]:getZ()) < 0.1, b3Raw:getDimZ(), b3Raw:getDimY())
|
|
if dDimRef + BD.CUT_EXTRA < dMaxDepth then
|
|
dNewDiceDim = - ( dMaxDepth - BD.CUT_EXTRA)
|
|
end
|
|
end
|
|
|
|
local bOkd, sErrD, vCuts = ApplyDiceCut( vFaceOrd, nGoodFace1, nGoodFace4, nAddGrpId, b3Solid, ptC, vtN, Proc, vtRef, bHead, sCutting, dSawDiam, b3Raw, dNewDiceDim)
|
|
if not bOkd then return bOkd, sErrD end
|
|
|
|
if #vCuts == 0 then
|
|
-- se ho la faccia intermedia, per prima cosa verifico se ho intersezione con la faccia tappo
|
|
if nGoodFace4 ~= 0 then
|
|
-- se non ho intersezione con la faccia tappo posso fare il taglio sul fianco
|
|
if not nGoodFace1 or nGoodFace1 == 0 then
|
|
-- inserisco la lavorazione
|
|
local vtRef2 = EgtIf( abs(vtRef:getZ()) < GEO.EPS_SMALL, Z_AX(), EgtIf( bHead, Y_AX(), -Y_AX()))
|
|
bOkd, sErrD = Fbs.MakeOne( nFace4, nGoodFace4 - 1, sCutting, dSawDiam, vtRef2, nil, 0, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOkd then return bOkd, sErrD end
|
|
-- lavoro la faccia opposta (definita dal parametro P11)
|
|
if vFaceOrd[3] ~= 0 then
|
|
-- inserisco la lavorazione
|
|
local vtOrthoO = Vector3d( vtRef)
|
|
bOkd, sErrD = Fbs.MakeOne( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOkd then return bOkd, sErrD end
|
|
end
|
|
-- altrimenti se ho intersezione forzo il DiceCut ad essere eseguito con distanze più piccole
|
|
else
|
|
-- definisco la nuova dimensione massima del dice cut
|
|
local dNewDiceDim = EgtIf( abs(vtRef:getZ()) < GEO.EPS_SMALL, b3Raw:getDimZ(), b3Raw:getDimY())
|
|
bOkd, sErrD = ApplyDiceCut( vFaceOrd, nGoodFace1, nGoodFace4, nAddGrpId, b3Solid, ptC, vtN, Proc, vtRef, bHead, sCutting, dSawDiam, b3Raw, dNewDiceDim)
|
|
if not bOkd then return bOkd, sErrD end
|
|
end
|
|
-- taglio sulla faccia interna
|
|
if vFaceOrd[1] ~= 0 then
|
|
-- inserisco la lavorazione
|
|
local vtOrthoO = Vector3d( vtRef)
|
|
bOkd, sErrD = Fbs.MakeOne( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOkd then return bOkd, sErrD end
|
|
end
|
|
else
|
|
-- taglio sulla faccia interna
|
|
if vFaceOrd[1] ~= 0 then
|
|
-- inserisco la lavorazione
|
|
local vtOrthoO = Vector3d( vtRef)
|
|
bOkd, sErrD = Fbs.MakeOne( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOkd then return bOkd, sErrD end
|
|
end
|
|
-- lavoro la faccia opposta (definita dal parametro P11)
|
|
if vFaceOrd[3] ~= 0 then
|
|
-- inserisco la lavorazione
|
|
local vtOrthoO = Vector3d( vtRef)
|
|
bOkd, sErrD = Fbs.MakeOne( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOkd then return bOkd, sErrD end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- taglio sulla faccia esterna
|
|
if vFaceOrd[5] ~= 0 then
|
|
-- in generale va fatto
|
|
local bCut = true
|
|
-- se di testa e coincide con inizio grezzo, non va fatto
|
|
if bHead and AreSameVectorApprox( vtN[vFaceOrd[5]], X_AX()) and abs( ptC[vFaceOrd[5]]:getX() - b3Raw:getMax():getX() + dOvmHead) < 10 * GEO.EPS_SMALL then
|
|
bCut = false
|
|
end
|
|
-- se di coda e coincide con taglio di separazione, non va fatto
|
|
if not bHead and AreSameVectorApprox( vtN[vFaceOrd[5]], - X_AX()) and abs( ptC[vFaceOrd[5]]:getX() - b3Raw:getMin():getX()) < dOvmTail + 10 * GEO.EPS_SMALL then
|
|
bCut = false
|
|
end
|
|
-- se va fatto, inserisco la lavorazione
|
|
if bCut then
|
|
local vtOrthoO
|
|
local frHV, DimH, DimV = BL.GetFaceHvRefDim( Proc.Id, vFaceOrd[5] - 1)
|
|
if DimV > DimH then
|
|
vtOrthoO = Vector3d( frHV:getVersX())
|
|
else
|
|
vtOrthoO = Vector3d( vtRef)
|
|
end
|
|
local bOk, sNameOrErr = Fbs.MakeOne( Proc.Id, vFaceOrd[5] - 1, sCutting, dSawDiam, vtOrthoO, nil, BD.CUT_EXTRA, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sNameOrErr end
|
|
end
|
|
end
|
|
|
|
-- lavoro superficie principale di fondo con una svuotatura
|
|
if vFaceOrd[2] ~= 0 then
|
|
|
|
local frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( Proc.Id, vFaceOrd[2]-1, GDB_ID.ROOT)
|
|
-- calcolo la dimensione da passare
|
|
local dDiamMax
|
|
-- se normale verso Y (in orizzontale)
|
|
if abs(vtRef:getY()) > 0.866 then
|
|
dDiamMax = EgtIf( abs( frMor:getVersX():getZ()) < abs( frMor:getVersY():getY()), dL, dW)
|
|
else
|
|
dDiamMax = EgtIf( abs( frMor:getVersX():getY()) < abs( frMor:getVersY():getY()), dL, dW)
|
|
end
|
|
-- determino la distanza tra le due facce inclinate
|
|
local dDistFaces
|
|
if vFaceOrd[4] ~= 0 then
|
|
dDistFaces = abs((ptC[vFaceOrd[2]]-ptC[vFaceOrd[4]])*vtN[vFaceOrd[2]])
|
|
end
|
|
-- recupero la lavorazione. considerando l dimensione del lato e l'affondamento
|
|
local sPocketing
|
|
if dDistFaces then
|
|
sPocketing = ML.FindPocketing( 'OpenPocket', dDiamMax, dDistFaces, nil, bTopHead, bDownHead)
|
|
else
|
|
sPocketing = ML.FindPocketing( 'OpenPocket', dDiamMax, nil, nil, bTopHead, bDownHead)
|
|
end
|
|
|
|
if not sPocketing then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' pocketing not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati dell'utensile
|
|
local dMillDiam = 20
|
|
local dMaxDepth = 0
|
|
if EgtMdbSetCurrMachining( sPocketing) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam
|
|
dMaxDepth = ( EgtTdbGetCurrToolMaxDepth() or dMaxDepth)
|
|
end
|
|
end
|
|
-- inserisco la lavorazione di svuotatura
|
|
local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
|
|
local nMchFId = EgtAddMachining( sName, sPocketing)
|
|
if not nMchFId then
|
|
local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ Proc.Id, vFaceOrd[2]-1}})
|
|
-- imposto elevazione
|
|
if dDistFaces then
|
|
EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dDistFaces, 1) .. ';')
|
|
end
|
|
-- eseguo
|
|
if not ML.ApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
end
|
|
|
|
-- aggiornamento ingombro di testa o coda
|
|
if Proc.Head then
|
|
local dHCI = 0
|
|
if abs( vtRef:getZ()) > 0.1 and not BD.ROT90 then
|
|
local b3Fac1 = EgtSurfTmGetFacetBBoxGlob( Proc.Id, vFaceOrd[1] - 1, GDB_BB.STANDARD)
|
|
if b3Fac1 then dHCI = b3Raw:getMax():getX() - dOvmHead - b3Fac1:getMin():getX() end
|
|
dHCI = 0.75 * dHCI
|
|
else
|
|
dHCI = b3Raw:getMax():getX() - dOvmHead - Proc.Box:getMin():getX()
|
|
end
|
|
BL.UpdateHCING( nRawId, dHCI)
|
|
elseif Proc.Tail then
|
|
local dTCI = 0
|
|
if abs( vtRef:getZ()) > 0.1 and not BD.ROT90 then
|
|
local b3Fac1 = EgtSurfTmGetFacetBBoxGlob( Proc.Id, vFaceOrd[1] - 1, GDB_BB.STANDARD)
|
|
if b3Fac1 then dTCI = b3Fac1:getMax():getX() - b3Solid:getMin():getX() end
|
|
dTCI = 0.75 * dTCI
|
|
else
|
|
dTCI = Proc.Box:getMax():getX() - b3Solid:getMin():getX()
|
|
end
|
|
BL.UpdateTCING( nRawId, dTCI)
|
|
end
|
|
|
|
return true, sErrC
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return ProcessScarfJoint
|