6eaba8a577
- primo rilascio.
219 lines
8.3 KiB
Lua
219 lines
8.3 KiB
Lua
-- ProcessFreeContour.lua by Egaltech s.r.l. 2019/02/23
|
|
-- Gestione calcolo profilo libero per Travi
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessFreeContour = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
|
|
EgtOutLog( ' ProcessFreeContour started', 1)
|
|
|
|
-- Dati
|
|
local BD = require( 'BeamData')
|
|
local Millings = require( 'MillingData')
|
|
|
|
---------------------------------------------------------------------
|
|
-- Riconoscimento della feature
|
|
function ProcessFreeContour.Identify( Proc)
|
|
return ( ( Proc.Grp == 0 or Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 250)
|
|
end
|
|
---------------------------------------------------------------------
|
|
-- Verifica se feature di testa
|
|
function ProcessFreeContour.IsHeadFeature( Proc, b3Raw, dCurrOvmH)
|
|
-- verifico se è in testa
|
|
if Proc.Box:getMax():getX() < b3Raw:getMax():getX() - dCurrOvmH - BD.MAX_DIST_HTFEA then
|
|
return false
|
|
end
|
|
-- la sua lunghezza non deve superare la metà della lunghezza della trave
|
|
if Proc.Box:getDimX() > 0.5 * b3Raw:getDimX() then
|
|
return false
|
|
end
|
|
-- deve occupare la maggior parte dell'area
|
|
if Proc.Box:getDimY() > 0.75 * b3Raw:getDimY() or Proc.Box:getDimZ() > 0.75 * b3Raw:getDimZ() then
|
|
return true
|
|
end
|
|
-- non è di testa
|
|
return false
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Verifica se feature di coda
|
|
function ProcessFreeContour.IsTailFeature( Proc, b3Raw)
|
|
-- verifico se è in coda
|
|
if Proc.Box:getMin():getX() > b3Raw:getMin():getX() + BD.MAX_DIST_HTFEA then
|
|
return false
|
|
end
|
|
-- la sua lunghezza non deve superare la metà della lunghezza della trave
|
|
if Proc.Box:getDimX() > 0.5 * b3Raw:getDimX() then
|
|
return false
|
|
end
|
|
-- deve occupare la maggior parte dell'area
|
|
if Proc.Box:getDimY() > 0.75 * b3Raw:getDimY() or Proc.Box:getDimZ() > 0.75 * b3Raw:getDimZ() then
|
|
return true
|
|
end
|
|
-- non è di coda
|
|
return false
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessFreeContour.Classify( Proc)
|
|
-- se di testa o coda, è indifferente alla posizione
|
|
if Proc.Head or Proc.Tail then
|
|
return true, false
|
|
end
|
|
-- è intermedia, devo verificare la normale del centro
|
|
local nMidFacet = Proc.Fct // 2
|
|
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nMidFacet, GDB_ID.ROOT)
|
|
-- verifico sia una superficie
|
|
if not vtN then
|
|
return false
|
|
end
|
|
-- verifico se la feature è lavorabile solo da sotto
|
|
local bDown = ( vtN:getZ() < - 0.1)
|
|
return true, bDown
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
local function FindMilling( sType)
|
|
for i = 1, #Millings do
|
|
local Milling = Millings[i]
|
|
if Milling.Type == sType then
|
|
return i, Milling.Name
|
|
end
|
|
end
|
|
return 0
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessFreeContour.Make( Proc, nPhase, nRawId, nPartId, dOvmHead)
|
|
-- recupero l'ingombro del grezzo di appartenenza
|
|
local b3Raw = EgtGetRawPartBBox( nRawId)
|
|
-- recupero e verifico l'entità curva
|
|
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0
|
|
if AuxId then AuxId = AuxId + Proc.Id end
|
|
if not AuxId or ( EgtGetType( AuxId) & 256) == 0 then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati della curva e del profilo
|
|
local dDepth = abs( EgtCurveThickness( AuxId))
|
|
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
|
|
local bToolInv = ( vtExtr:getZ() < -0.1)
|
|
-- recupero la lavorazione
|
|
local nMill, sMilling = FindMilling( 'FreeContour')
|
|
if not sMilling then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati dell'utensile
|
|
local dMaxDepth = 0
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth
|
|
end
|
|
end
|
|
-- ne verifico la lunghezza per eventuale spezzatura e lavorazione in doppio
|
|
local nStep = 1
|
|
local dStep = 0
|
|
local dLenMax = min( BD.LONGCUT_MAXLEN, 0.5 * b3Raw:getDimX())
|
|
local b3Aux = EgtGetBBoxGlob( AuxId, GDB_BB.STANDARD)
|
|
if b3Aux:getDimX() > dLenMax then
|
|
local dCrvLen = EgtCurveLength( AuxId)
|
|
nStep = ceil( dCrvLen / dLenMax)
|
|
dStep = dCrvLen / nStep
|
|
EgtOutLog( string.format( 'CrvLen=%.1f StepNbr=%d StepLen=%.1f', dCrvLen, nStep, dStep), 3)
|
|
end
|
|
-- verifiche per affondamento ( possibili lavorazioni in doppio)
|
|
local nDouble = 1
|
|
local bCanDouble = ( abs( vtExtr:getZ()) < 0.5 and abs( vtExtr:getX()) < 0.1 and b3Aux:getDimY() > b3Raw:getDimY() - 1.0)
|
|
if nStep > 1 then
|
|
-- devo lasciare un codolo
|
|
dDepth = dDepth - BD.DIM_STRIP
|
|
else
|
|
-- devo affondare un poco oltre
|
|
dDepth = dDepth + BD.CUT_EXTRA
|
|
end
|
|
if dDepth > dMaxDepth then
|
|
if bCanDouble then
|
|
nDouble = 2
|
|
dDepth = min( 0.5 * dDepth, dMaxDepth)
|
|
else
|
|
dDepth = dMaxDepth
|
|
end
|
|
end
|
|
-- eseguo
|
|
for i = 1, nStep do
|
|
for j = 1, nDouble do
|
|
-- inserisco la lavorazione
|
|
local sName = 'Free_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
|
|
local nMchId = EgtAddMachining( sName, sMilling)
|
|
if not nMchId then
|
|
local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ AuxId, -1}})
|
|
-- eventuale accorciamento di testa
|
|
if ( j == 1 and i > 1) or ( j == 2 and i < nStep) then
|
|
local dStartAddLen = EgtIf( j == 1, - ( i - 1) * dStep, - ( nStep - i) * dStep)
|
|
EgtSetMachiningParam( MCH_MP.STARTADDLEN, dStartAddLen)
|
|
end
|
|
-- eventuale accorciamento di coda
|
|
if ( j == 1 and i < nStep) or ( j == 2 and i > 1) then
|
|
local dEndAddLen = EgtIf( j == 1, - ( nStep - i) * dStep, - ( i - 1) * dStep)
|
|
EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEndAddLen)
|
|
end
|
|
-- se estrusione da sotto, inverto direzione fresa
|
|
if ( j == 1 and bToolInv) or ( j == 2 and not bToolInv) then
|
|
EgtSetMachiningParam( MCH_MP.TOOLINVERT, true)
|
|
end
|
|
-- se seconda passata, inverto direzione di lavoro
|
|
if j == 2 then
|
|
EgtSetMachiningParam( MCH_MP.INVERT, true)
|
|
end
|
|
-- assegno affondamento
|
|
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
|
|
-- assegno lato di lavoro
|
|
if Proc.Grp == 0 then
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.CENTER)
|
|
elseif ( Proc.Grp == 3 and not bToolInv) or ( Proc.Grp == 4 and bToolInv) then
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT)
|
|
elseif ( Proc.Grp == 3 and bToolInv) or ( Proc.Grp == 4 and not bToolInv) then
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT)
|
|
end
|
|
-- posizione braccio porta testa
|
|
if Proc.Head then
|
|
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_XP)
|
|
elseif Proc.Tail then
|
|
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_XM)
|
|
elseif AreSameOrOppositeVectorApprox( vtExtr, Z_AX()) then
|
|
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP)
|
|
end
|
|
-- eseguo
|
|
if not EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchId, false)
|
|
return false, 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 ProcessFreeContour
|