6eaba8a577
- primo rilascio.
204 lines
7.7 KiB
Lua
204 lines
7.7 KiB
Lua
-- ProcessDrill.lua by Egaltech s.r.l. 2019/03/29
|
|
-- Gestione calcolo doppi tagli di lama per Travi
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessDoubleCut = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
local DC = require( 'DiceCut')
|
|
|
|
EgtOutLog( ' ProcessDoubleCut started', 1)
|
|
|
|
-- Dati
|
|
local BD = require( 'BeamData')
|
|
local Cuttings = require( 'CutData')
|
|
|
|
---------------------------------------------------------------------
|
|
-- Riconoscimento della feature
|
|
function ProcessDoubleCut.Identify( Proc)
|
|
return ( ( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 11)
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessDoubleCut.Classify( Proc)
|
|
-- numero delle facce
|
|
local nFacetCnt = EgtSurfTmFacetCount( Proc.Id)
|
|
-- se due facce, verifico se convesso
|
|
local bConvex = true
|
|
if nFacetCnt == 2 then
|
|
local _, _, _, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT)
|
|
bConvex = ( dAng > 0)
|
|
end
|
|
-- verifico le normali delle facce
|
|
for i = 1, nFacetCnt do
|
|
local vtN = EgtSurfTmFacetNormVersor( Proc.Id, i-1, GDB_ID.ROOT)
|
|
if not bConvex and vtN:getZ() < - 0.72 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 ProcessDoubleCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
|
|
-- ingombro del grezzo
|
|
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
|
|
-- dati delle facce
|
|
local ptC = {}
|
|
local vtN = {}
|
|
ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
|
|
ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT)
|
|
-- normale media per capire se taglio di testa o di coda
|
|
local vtNm = ( vtN[1] + vtN[2]) ; vtNm:normalize()
|
|
local bHead = ( vtNm:getX() > 0)
|
|
-- angolo diedro per stabilire se taglio convesso
|
|
local _, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT)
|
|
local vtDir = ptP1 - ptP2 ; vtDir:normalize()
|
|
local bOnY = abs( vtDir:getZ()) > 0.5 and ( abs( vtDir:getZ()) + abs( vtDir:getX()) > abs( vtDir:getY()))
|
|
local bConvex = ( dAng > 0)
|
|
local dLen = dist( ptP1, ptP2)
|
|
local ptPs = ( ptP1 + ptP2) / 2
|
|
-- determino quale faccia è più grande
|
|
local dSqDim1 = ( ptC[1] - ptPs):sqlen()
|
|
local dSqDim2 = ( ptC[2] - ptPs):sqlen()
|
|
local nBigInd = EgtIf( dSqDim1 >= dSqDim2, 1, 2)
|
|
local nSmaInd = 3 - nBigInd
|
|
-- recupero la lavorazione
|
|
local _, sCutting = FindCutting( EgtIf( bHead, 'HeadSide', 'TailSide'))
|
|
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
|
|
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
|
|
-- verifico se necessari tagli supplementari
|
|
local vCuts = DC.GetDice( EgtGetParent( Proc.Id), b3Solid, ptC[nBigInd], vtN[nBigInd], false, ptC[nSmaInd], vtN[nSmaInd])
|
|
--DC.PrintOrderCut( vCuts)
|
|
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
|
|
-- eseguo
|
|
for i = 1, #vCuts do
|
|
-- determino il modo di tagliare
|
|
local k, l = nBigInd, nSmaInd
|
|
if ( i % 2 == 1) == ( not bConvex) then
|
|
k, l = l, k
|
|
end
|
|
local nOrthoOpposite
|
|
if bOnY then
|
|
local bFront = ( ptC[k]:getY() < ptPs:getY())
|
|
nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT)
|
|
else
|
|
if bConvex then
|
|
if dLen < dMaxDepth then
|
|
local bFront = ( vtN[k]:getY() < 0.02)
|
|
nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT)
|
|
else
|
|
local bOver = ( ptC[k]:getZ() > ptC[l]:getZ())
|
|
nOrthoOpposite = EgtIf( bOver, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_TOP)
|
|
end
|
|
else
|
|
local bOver = ( ptC[k]:getZ() > ptC[l]:getZ())
|
|
nOrthoOpposite = EgtIf( bOver, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_TOP)
|
|
end
|
|
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
|
|
end
|
|
-- se non ci sono tagli supplementari o convesso, tagli diretti delle facce
|
|
if #vCuts == 0 or bConvex then
|
|
-- imposto eventuale affondamento aggiuntivo
|
|
local dExtraCut = EgtIf( bConvex, BD.CUT_EXTRA, 0)
|
|
-- eseguo sulle due facce
|
|
for j = 1, 2 do
|
|
-- determino ordine dei tagli
|
|
local i = j
|
|
if not bOnY and ptC[1]:getZ() > ptC[2]:getZ() then
|
|
i = 3 - j
|
|
end
|
|
-- lavoro la faccia
|
|
local nOrthoOpposite
|
|
if bOnY then
|
|
local bFront = ( ptC[i]:getY() < ptPs:getY())
|
|
nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT)
|
|
else
|
|
if bConvex then
|
|
if dLen < dMaxDepth then
|
|
local bFront = ( vtN[i]:getY() < 0.02)
|
|
nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT)
|
|
else
|
|
nOrthoOpposite = MCH_MILL_FU.ORTHO_DOWN
|
|
end
|
|
else
|
|
local bOver = ( ptC[i]:getZ() > ptC[3-i]:getZ())
|
|
nOrthoOpposite = EgtIf( bOver, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_TOP)
|
|
end
|
|
end
|
|
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, i - 1, sCutting, dSawDiam, nOrthoOpposite, dExtraCut, BD.CUT_SIC, 0, nil, b3Raw)
|
|
if not bOk then
|
|
return bOk, sErr
|
|
end
|
|
end
|
|
end
|
|
-- eventuale segnalazione ingombro di testa o coda
|
|
if Proc.Head then
|
|
BL.UpdateHCING( nRawId, b3Raw:getMax():getX() - dOvmHead - Proc.Box:getMin():getX())
|
|
elseif Proc.Tail then
|
|
BL.UpdateTCING( nRawId, Proc.Box:getMax():getX() - b3Raw:getMin():getX())
|
|
end
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return ProcessDoubleCut
|