DataBeam :
- primo rilascio.
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
-- ProcessSimpleScarf.lua by Egaltech s.r.l. 2018/11/04
|
||||
-- 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 Cuttings = require( 'CutData')
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- 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
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function FindCutting( sType)
|
||||
for i = 1, #Cuttings do
|
||||
local Cutting = Cuttings[i]
|
||||
if Cutting.Type == sType then
|
||||
return i, Cutting.Name
|
||||
end
|
||||
end
|
||||
return 0
|
||||
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
|
||||
return true
|
||||
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 = ( 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())
|
||||
vtRef:normalize()
|
||||
-- recupero la lavorazione
|
||||
local _, sCutting = 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 nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef)
|
||||
local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[1] - 1, sCutting, dSawDiam, nOrthoOpposite, BD.CUT_EXTRA, BD.CUT_SIC, 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]])
|
||||
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))
|
||||
end
|
||||
end
|
||||
-- calcolo secondo riferimento per facce inclinate
|
||||
local vtRef2 = Vector3d( vtN[vFaceOrd[2]])
|
||||
-- eseguo
|
||||
for i = 1, #vCuts do
|
||||
local nOrthoOpposite
|
||||
if i % 2 == 1 then
|
||||
nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef)
|
||||
else
|
||||
nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef2)
|
||||
end
|
||||
-- lavoro la faccia
|
||||
for j = 1, #vCuts[i] do
|
||||
local bOk, sErr = BL.MakeOneFaceBySaw( vCuts[i][j], 0, sCutting, dSawDiam, nOrthoOpposite, 0, BD.CUT_SIC, 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, 0, BD.CUT_SIC, 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]]
|
||||
if not bIntCut then
|
||||
local frHV, DimH, DimV = BL.GetFaceHvRefDim( Proc.Id, vFaceOrd[2] - 1)
|
||||
if DimV <= DimH then
|
||||
vtRef2 = Vector3d( frHV:getVersY())
|
||||
else
|
||||
vtRef2 = Vector3d( frHV:getVersX())
|
||||
end
|
||||
end
|
||||
local nOrthoOpposite = BL.GetNearestOrthoOpposite( vtRef2)
|
||||
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, vFaceOrd[3] - 1, sCutting, dSawDiam, nOrthoOpposite, 0, BD.CUT_SIC, 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 = BL.GetFaceBox( Proc.Id, vFaceOrd[1] - 1)
|
||||
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 = BL.GetFaceBox( Proc.Id, vFaceOrd[1] - 1)
|
||||
if b3Fac1 then dTCI = b3Fac1:getMax():getX() - b3Raw:getMin():getX() end
|
||||
else
|
||||
dTCI = Proc.Box:getMax():getX() - b3Raw:getMin():getX()
|
||||
end
|
||||
BL.UpdateTCING( nRawId, dTCI)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
return ProcessSimpleScarf
|
||||
Reference in New Issue
Block a user