ccac4c975a
- corretto calcolo attacchi e uscite per lame su facce - ora nei tagli di testa e coda si tiene conto dell'effettiva capacità di lavorazione della lama - completata lavorazione ScarfJoint - corretta lavorazione SimpleScarf.
236 lines
9.0 KiB
Lua
236 lines
9.0 KiB
Lua
-- ProcessSimpleScarf.lua by Egaltech s.r.l. 2019/10/02
|
|
-- Gestione calcolo giunto Gerber per Travi
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessSimpleScarf = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
local DC = require( 'DiceCut')
|
|
|
|
EgtOutLog( ' ProcessSimpleScarf started', 1)
|
|
|
|
-- Dati
|
|
local BD = require( 'BeamData')
|
|
local ML = require( 'MachiningLib')
|
|
|
|
---------------------------------------------------------------------
|
|
-- Riconoscimento della feature
|
|
function ProcessSimpleScarf.Identify( Proc)
|
|
return (( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 70)
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessSimpleScarf.Classify( Proc)
|
|
-- 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
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessSimpleScarf.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
|
|
-- 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 on process ' .. tostring( Proc.Id) .. ' part box not found'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- verifico che ci siano almeno due facce (altrimenti non è da lavorare)
|
|
local nFacetCnt = EgtSurfTmFacetCount( Proc.Id)
|
|
if nFacetCnt < 2 then
|
|
local sErr = 'Not executed ' .. tostring( Proc.Id) .. ' 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 (1=esterna, 2=interna, 3=intermedia)
|
|
local vFaceOrd = { 0, 0, 0}
|
|
for i = 1, nFacetCnt do
|
|
if abs( vtN[i]:getY()) > 0.1 or abs( vtN[i]:getZ()) > 0.1 then
|
|
vFaceOrd[3] = i
|
|
break
|
|
end
|
|
end
|
|
if vFaceOrd[3] == 0 then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing intermediate face'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
for i = 1, nFacetCnt do
|
|
if i ~= vFaceOrd[3] then
|
|
local bTouch, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, i - 1, vFaceOrd[3] - 1, GDB_ID.ROOT)
|
|
if bTouch and dAng > 0 then
|
|
vFaceOrd[1] = i
|
|
elseif bTouch and dAng < 0 then
|
|
vFaceOrd[2] = i
|
|
end
|
|
end
|
|
end
|
|
-- determino se di testa o di coda
|
|
local bHead
|
|
if vtN[vFaceOrd[2]] then
|
|
bHead = ( vtN[vFaceOrd[2]]:getX() > 0)
|
|
else
|
|
bHead = ( vtN[vFaceOrd[1]]:getX() > 0)
|
|
end
|
|
-- vettore di riferimento per le facce ortogonali all'asse trave
|
|
local vtRef = Vector3d( 0, vtN[vFaceOrd[3]]:getY(), vtN[vFaceOrd[3]]:getZ())
|
|
vtRef:normalize()
|
|
-- recupero la lavorazione
|
|
local sCutting = ML.FindCutting( 'HeadSide')
|
|
if not sCutting then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' cutting not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati dell'utensile
|
|
local dSawDiam = 400
|
|
if EgtMdbSetCurrMachining( sCutting) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam
|
|
end
|
|
end
|
|
-- taglio sulla faccia esterna
|
|
if vFaceOrd[1] ~= 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[1]], X_AX()) and abs( ptC[vFaceOrd[1]]: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[1]], - X_AX()) and abs( ptC[vFaceOrd[1]]:getX() - b3Raw:getMin():getX()) < BD.OVM_MID + 10 * GEO.EPS_SMALL then
|
|
bCut = false
|
|
end
|
|
-- se va fatto, inserisco la lavorazione
|
|
if bCut then
|
|
local vtOrthoO = Vector3d( vtRef)
|
|
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, vtOrthoO, nil, BD.CUT_EXTRA, BD.CUT_SIC, 0, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sNameOrErr end
|
|
end
|
|
end
|
|
-- se esistono faccia interna ed intermedia, verifico se richiedono taglio a cubetti
|
|
local vCuts = {}
|
|
if vFaceOrd[2] ~= 0 and vFaceOrd[3] ~= 0 then
|
|
vCuts = DC.GetDice( EgtGetParent( Proc.Id), b3Solid, ptC[vFaceOrd[3]], vtN[vFaceOrd[3]], false, ptC[vFaceOrd[2]], vtN[vFaceOrd[2]])
|
|
elseif vFaceOrd[3] ~= 0 then
|
|
vCuts = DC.GetDice( EgtGetParent( Proc.Id), b3Solid, ptC[vFaceOrd[3]], vtN[vFaceOrd[3]], true)
|
|
end
|
|
if #vCuts > 0 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
|
|
-- sistemo posizione nel DB e nome
|
|
for i = 1, #vCuts do
|
|
for j = 1, #vCuts[i] do
|
|
EgtRelocateGlob( vCuts[i][j], nAddGrpId)
|
|
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
|
|
vtOrthoO = Y_AX()
|
|
end
|
|
end
|
|
end
|
|
-- lavoro la faccia
|
|
for j = 1, #vCuts[i] do
|
|
local bOk, sErr = BL.MakeOneFaceBySaw( vCuts[i][j], 0, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
|
|
if not bOk then
|
|
return bOk, sErr
|
|
end
|
|
end
|
|
end
|
|
else
|
|
-- taglio sulla faccia interna
|
|
local bIntCut = false
|
|
if vFaceOrd[2] ~= 0 then
|
|
-- inserisco la lavorazione
|
|
local nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef)
|
|
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[2] - 1, sCutting, dSawDiam, nOrthoOpposite, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sNameOrErr end
|
|
if #sNameOrErr > 0 then bIntCut = true end
|
|
end
|
|
-- taglio sulla faccia intermedia
|
|
if vFaceOrd[3] ~= 0 then
|
|
-- calcolo secondo testa o coda
|
|
local vtRef2 = EgtIf( bHead, X_AX(), -X_AX())
|
|
-- se non ho il taglio sulla faccia interna
|
|
if not bIntCut then
|
|
local frHV, DimH, DimV = BL.GetFaceHvRefDim( Proc.Id, vFaceOrd[3] - 1)
|
|
if DimV > DimH then
|
|
vtRef2 = Vector3d( frHV:getVersX())
|
|
end
|
|
end
|
|
-- inserisco la lavorazione
|
|
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, vtRef2, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sErr end
|
|
end
|
|
end
|
|
-- aggiornamento ingombro di testa o coda
|
|
if Proc.Head then
|
|
local dHCI = 0
|
|
if abs( vtRef:getZ()) > 0.1 then
|
|
local b3Fac1 = EgtSurfTmGetFacetBBoxGlob( Proc.Id, vFaceOrd[1] - 1, GDB_BB.STANDARD)
|
|
if b3Fac1 then dHCI = b3Raw:getMax():getX() - dOvmHead - b3Fac1:getMin():getX() end
|
|
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 then
|
|
local b3Fac1 = EgtSurfTmGetFacetBBoxGlob( Proc.Id, vFaceOrd[1] - 1, GDB_BB.STANDARD)
|
|
if b3Fac1 then dTCI = b3Fac1:getMax():getX() - b3Solid:getMin():getX() end
|
|
else
|
|
dTCI = Proc.Box:getMax():getX() - b3Solid:getMin():getX()
|
|
end
|
|
BL.UpdateTCING( nRawId, dTCI)
|
|
end
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return ProcessSimpleScarf
|