DataBeam :

- 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.
This commit is contained in:
Dario Sassi
2020-01-25 08:57:52 +00:00
parent a49ce81cb0
commit ccac4c975a
6 changed files with 339 additions and 147 deletions
+242 -73
View File
@@ -1,4 +1,4 @@
-- ProcessScarfJoint.lua by Egaltech s.r.l. 2020/01/21
-- ProcessScarfJoint.lua by Egaltech s.r.l. 2020/01/24
-- Gestione calcolo giunto Gerber per Travi
-- Tabella per definizione modulo
@@ -48,45 +48,80 @@ function ProcessScarfJoint.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
EgtOutLog( sErr)
return false, sErr
end
-- verifico che ci siano almeno due facce (altrimenti non è da lavorare)
-- verifico che ci siano almeno quattro facce (altrimenti non è da lavorare)
local nFacetCnt = EgtSurfTmFacetCount( Proc.Id)
if nFacetCnt < 2 then
return true
if nFacetCnt < 3 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
-- 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 on process ' .. tostring( Proc.Id) .. ', main faces are not parallel(fail btl import)'
EgtOutLog( sErr)
return false, sErr
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
-- 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 on process ' .. tostring( Proc.Id) .. ', 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[vFaceOrd[2]]:getX() > 0)
-- vettore di riferimento per le facce ortogonali all'asse trave
local vtRef = Vector3d( 0, vtN[vFaceOrd[3]]:getY(), vtN[vFaceOrd[3]]:getZ())
local bHead = ( vtN[1]:getX() > 0)
-- normalizzo vettore di riferimento per le facce ortogonali all'asse trave
vtRef:normalize()
-- recupero la lavorazione
local sCutting = ML.FindCutting( 'HeadSide')
if not sCutting then
@@ -102,91 +137,225 @@ function ProcessScarfJoint.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
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 nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef)
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, nOrthoOpposite, nil, BD.CUT_EXTRA, BD.CUT_SIC, 0, 0, nil, b3Raw)
if not bOk then return bOk, sNameOrErr end
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
-- 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]])
-- 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 #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'
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 on cut surfaces of ' .. tostring( Proc.Id) .. ' cut not good'
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
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]])
elseif nGoodFace4 and nGoodFace4 > 0 then
vCuts = DC.GetDice( nAddGrpId, b3Solid, ptC[vFaceOrd[4]], vtN[vFaceOrd[4]], true)
end
if #vCuts > 0 then
-- 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 facce inclinate
local vtRef2 = Vector3d( vtN[vFaceOrd[2]])
-- calcolo secondo riferimento per testa o coda
local vtRef2 = EgtIf( bHead, X_AX(), -X_AX())
-- eseguo
for i = 1, #vCuts do
local nOrthoOpposite
-- local nOrthoOpposite
local vtOrthoO
if i % 2 == 1 then
nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef)
vtOrthoO = Vector3d( vtRef)
else
nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef2)
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, nOrthoOpposite, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
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
-- lavoro la faccia interna in ogni caso
if vFaceOrd[1] ~= 0 then
-- inserisco la lavorazione
local vtOrthoO = Vector3d( vtRef)
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
if not bOk then return bOk, sNameOrErr end
end
-- lavoro la faccia opposta (definita dal parametro P11)
if vFaceOrd[3] ~= 0 then
-- inserisco la lavorazione
local vtOrthoO = Vector3d( vtRef)
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
if not bOk then return bOk, sNameOrErr end
end
else
-- taglio sulla faccia interna
local bIntCut = false
if vFaceOrd[2] ~= 0 then
if vFaceOrd[1] ~= 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)
local vtOrthoO = Vector3d( vtRef)
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, vtOrthoO, 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
-- inserisco la lavorazione
local vtRef2 = vtN[vFaceOrd[2]]
-- taglio sulla faccia intermedia (inclinata)
if vFaceOrd[4] ~= 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[2] - 1)
if DimV <= DimH then
vtRef2 = Vector3d( frHV:getVersY())
else
local frHV, DimH, DimV = BL.GetFaceHvRefDim( Proc.Id, vFaceOrd[4] - 1)
if DimV > DimH then
vtRef2 = Vector3d( frHV:getVersX())
end
end
local nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef2)
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, nOrthoOpposite, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
-- inserisco la lavorazione
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[4] - 1, sCutting, dSawDiam, vtRef2, nil, 0, BD.CUT_SIC, 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)
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, vtOrthoO, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw)
if not bOk then return bOk, sNameOrErr 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()) < BD.OVM_MID + 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 = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[5] - 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
-- 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 = EgtIf( abs( frMor:getVersX():getY()) < abs( frMor:getVersY():getY()), dL, dW)
-- 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)
else
sPocketing = ML.FindPocketing( 'OpenPocket', dDiamMax)
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 EgtApplyMachining( 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