Files
DataBeam/LuaLibs/ProcessCut.lua
T
Dario Sassi 6eaba8a577 DataBeam :
- primo rilascio.
2019-04-01 15:18:51 +00:00

165 lines
5.9 KiB
Lua

-- ProcessCut.lua by Egaltech s.r.l. 2019/03/23
-- Gestione calcolo singoli tagli di lama per Travi
-- Tabella per definizione modulo
local ProcessCut = {}
-- Include
require( 'EgtBase')
local BL = require( 'BeamLib')
local DC = require( 'DiceCut')
EgtOutLog( ' ProcessCut started', 1)
-- Dati
local BD = require( 'BeamData')
local Cuttings = require( 'CutData')
---------------------------------------------------------------------
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
---------------------------------------------------------------------
-- Riconoscimento della feature
function ProcessCut.Identify( Proc)
return ( ( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 10)
end
---------------------------------------------------------------------
-- Applicazione della lavorazione
function ProcessCut.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 geometrici del taglio
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
local bDownCut = (vtN:getZ() <= - 0.5)
-- se taglio di testa
if Proc.Head then
-- se coincide con il taglio di separazione precedente, non va fatto
if AreSameVectorApprox( vtN, X_AX()) and abs( ptC:getX() - b3Raw:getMax():getX() + dOvmHead) < 10 * GEO.EPS_SMALL then
return true
end
-- altrimenti taglio di coda
else
-- se coincide con taglio di separazione, non va fatto
if AreSameVectorApprox( vtN, - X_AX()) and abs( ptC:getX() - b3Raw:getMin():getX()) < BD.OVM_MID + 10 * GEO.EPS_SMALL then
return true
end
end
-- recupero la lavorazione
local _, sCutting = FindCutting( EgtIf( Proc.Head, '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
-- determino la direzione di taglio preferenziale
local _, dCutH, dCutV = BL.GetFaceHvRefDim( Proc.Id, 0)
local bHorizCut = (( dCutV < dMaxDepth + 10 * GEO.EPS_SMALL and dCutH > dCutV + 10 * GEO.EPS_SMALL) and not bDownCut)
-- verifico se necessari tagli supplementari
local vCuts = DC.GetDice( EgtGetParent( Proc.Id), b3Solid, ptC, vtN, true)
--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
-- recupero la normale dei tagli ortogonali
local vtO
for i = 1, #vCuts, 2 do
for j = 1, #vCuts[i] do
_, vtO = EgtSurfTmFacetCenter( vCuts[i][j], 0, GDB_ID.ROOT)
break
end
if vtO then break end
end
-- eseguo
for i = 1, #vCuts do
-- determino il modo di tagliare
local nOrthoOpposite
if vtO then
if i % 2 == 1 then
nOrthoOpposite = BL.GetNearestOrthoOpposite( vtN)
else
nOrthoOpposite = BL.GetNearestOrthoOpposite( vtO)
end
else
if bHorizCut then
nOrthoOpposite = MCH_MILL_FU.ORTHO_DOWN
elseif vtN:getY() > -0.02 then
nOrthoOpposite = MCH_MILL_FU.ORTHO_FRONT
else
nOrthoOpposite = MCH_MILL_FU.ORTHO_BACK
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
-- altrimenti tagli diretti della faccia
else
-- lavoro la faccia
local nOrthoOpposite
if bHorizCut then
nOrthoOpposite = MCH_MILL_FU.ORTHO_DOWN
elseif vtN:getY() > -0.02 then
nOrthoOpposite = MCH_MILL_FU.ORTHO_FRONT
else
nOrthoOpposite = MCH_MILL_FU.ORTHO_BACK
end
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, 0, sCutting, dSawDiam, nOrthoOpposite, BD.CUT_EXTRA, BD.CUT_SIC, 0, nil, b3Raw)
if not bOk then
return bOk, sErr
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 ProcessCut