8dee1a0c97
- correzioni e migliorie varie.
254 lines
9.8 KiB
Lua
254 lines
9.8 KiB
Lua
-- ProcessLongCut.lua by Egaltech s.r.l. 2019/07/25
|
|
-- Gestione calcolo taglio longitudinale per Travi
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessLongCut = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
|
|
EgtOutLog( ' ProcessLongCut started', 1)
|
|
|
|
-- Dati
|
|
local BD = require( 'BeamData')
|
|
local ML = require( 'MachiningLib')
|
|
|
|
---------------------------------------------------------------------
|
|
-- Riconoscimento della feature
|
|
function ProcessLongCut.Identify( Proc)
|
|
return (( Proc.Grp == 0 or Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 10)
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessLongCut.Classify( Proc)
|
|
-- se una sola faccia non ci sono limiti
|
|
if Proc.Fct == 1 then
|
|
return true, false
|
|
end
|
|
-- verifico la normale della faccia principale
|
|
local vtN = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT)
|
|
if vtN:getZ() < - 0.5 then
|
|
return true, true
|
|
end
|
|
return true, false
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId)
|
|
-- dati della faccia
|
|
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
|
|
local dLen = Proc.Box:getDimX()
|
|
local dWidth = sqrt( Proc.Box:getDimY() * Proc.Box:getDimY() + Proc.Box:getDimZ() * Proc.Box:getDimZ())
|
|
-- limitazioni su inizio e fine derivanti da altre facce
|
|
local bLimXmin = false
|
|
local bLimXmax = false
|
|
if Proc.Fct >= 3 then
|
|
bLimXmin = true
|
|
bLimXmax = true
|
|
elseif Proc.Fct >= 2 then
|
|
local ptC1, vtN1 = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT)
|
|
if vtN1:getX() > 0 then
|
|
bLimXmin = true
|
|
else
|
|
bLimXmax = true
|
|
end
|
|
end
|
|
-- Verifico se lavorazione da sotto
|
|
local nSide = 1
|
|
if vtN:getZ() < - 0.5 then nSide = -1 end
|
|
|
|
-- Se non è sotto : lavorazione Long2Cut
|
|
if nSide ~= - 1 then
|
|
-- recupero la lavorazione
|
|
local sMilling = ML.FindMilling( 'Long2Cut')
|
|
if not sMilling then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero il diametro dell'utensile
|
|
local dToolDiam = 0
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam
|
|
end
|
|
end
|
|
local dStartDist = 0
|
|
if ( bLimXmin and vtN:getY() < 0) or ( bLimXmax and vtN:getY() > 0) then
|
|
dStartDist = dToolDiam / 2
|
|
end
|
|
local dEndDist = 0
|
|
if ( bLimXmin and vtN:getY() > 0) or ( bLimXmax and vtN:getY()< 0) then
|
|
dEndDist = dToolDiam / 2
|
|
end
|
|
-- determino numero di parti
|
|
local nC = ceil( ( dLen - 2 * BD.LONGCUT_ENDLEN) / BD.LONGCUT_MAXLEN)
|
|
local dC = ( dLen - 2 * BD.LONGCUT_ENDLEN) / nC
|
|
local dAccDist = BD.LONGCUT_ENDLEN
|
|
if nC > 0 then
|
|
nC = nC + 2
|
|
else
|
|
nC = EgtIf( dLen > BD.LONGCUT_ENDLEN, 2, 1)
|
|
dAccDist = EgtIf( nC == 2, dLen / 2, 0)
|
|
end
|
|
-- si percorre il lato basso della faccia
|
|
local nM = 0
|
|
for i = 1, nC do
|
|
-- ciclo sulle passate
|
|
local nO = 1
|
|
local dStep = 0
|
|
if dWidth + 2 * BD.CUT_EXTRA > dToolDiam then
|
|
nO = ceil(( dWidth + 2 * BD.CUT_EXTRA) / dToolDiam)
|
|
if nO > 1 then
|
|
dStep = ( dWidth + 2 * BD.CUT_EXTRA - dToolDiam) / ( nO - 1)
|
|
end
|
|
end
|
|
for k = nO, 1, -1 do
|
|
-- inserisco le parti di lavorazione
|
|
nM = nM + 1
|
|
local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM)
|
|
local nMchFId = EgtAddMachining( sNameF, sMilling)
|
|
if not nMchFId then
|
|
local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ Proc.Id, 0}})
|
|
-- limito opportunamente la lavorazione
|
|
local dSal = EgtIf( i == 1, -dStartDist, - dAccDist - ( i - 2) * dC)
|
|
EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal)
|
|
local dEal = EgtIf( i == nC, -dEndDist, - dAccDist - ( nC - i - 1) * dC)
|
|
EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal)
|
|
-- imposto offset radiale (nullo se concavo)
|
|
if k >1 then
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, ( k - 1) * dStep)
|
|
else
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, - BD.CUT_EXTRA)
|
|
end
|
|
-- eseguo
|
|
if not EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
end
|
|
end
|
|
-- se ci sono le facce limitanti
|
|
for i = 1, Proc.Fct - 1 do
|
|
-- inserisco la lavorazione
|
|
local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i)
|
|
local nMchFId = EgtAddMachining( sNameF, sMilling)
|
|
if not nMchFId then
|
|
local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ Proc.Id, i}})
|
|
-- lato di lavoro e inversione
|
|
EgtSetMachiningParam( MCH_MP.INVERT, true)
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT)
|
|
-- uso della faccia
|
|
EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN)
|
|
-- attacco e uscita
|
|
EgtSetMachiningParam( MCH_MP.LIPERP, 0)
|
|
EgtSetMachiningParam( MCH_MP.LITANG, dToolDiam / 2 + 30)
|
|
EgtSetMachiningParam( MCH_MP.LOPERP, 0)
|
|
EgtSetMachiningParam( MCH_MP.LOTANG, dToolDiam / 2 + 30)
|
|
-- eseguo
|
|
if not EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
end
|
|
|
|
-- altrimenti è sotto : lavorazione Long2CutDown
|
|
else
|
|
-- recupero la lavorazione
|
|
local sMilling = ML.FindMilling( 'Long2CutDown')
|
|
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 dToolDiam = 0
|
|
local dMaxDepth = 0
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam
|
|
dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth
|
|
end
|
|
end
|
|
-- larghezza faccia
|
|
local _, _, dWidth = BL.GetFaceHvRefDim( Proc.Id, 0)
|
|
-- aggiuntivo sull'affondamento
|
|
local dAgg = BD.CUT_EXTRA
|
|
-- determino il numero di parti in cui dividere la lavorazione
|
|
local dEndLen = BD.LONGCUT_ENDLEN
|
|
if dLen < 2 * dEndLen + BD.LONGCUT_MAXLEN then
|
|
dEndLen = dLen / 3
|
|
end
|
|
local nC = ceil( ( dLen - 2 * dEndLen) / BD.LONGCUT_MAXLEN)
|
|
local dC = 0
|
|
if nC > 0 then dC = ( dLen - 2 * dEndLen) / nC end
|
|
nC = nC + 2
|
|
-- ciclo sulle parti
|
|
local nM = 0
|
|
for j = 1, nC do
|
|
-- Limitazioni della lavorazione
|
|
local nPos = EgtIf( vtN:getY() < 0, j, nC - j + 1)
|
|
local dSal = EgtIf( nPos == 1, 0, - dEndLen - ( nPos - 2) * dC)
|
|
local dEal = EgtIf( nPos == nC, 0, - dEndLen - ( nC - nPos - 1) * dC)
|
|
-- Posizione braccio portatesta
|
|
local nSCC
|
|
if vtN:getY() < 0 then
|
|
nSCC = EgtIf( ( j == 1 or j == nC - 1), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP)
|
|
else
|
|
nSCC = EgtIf( ( j == 1 or j == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)
|
|
end
|
|
-- inserisco le parti di lavorazione
|
|
nM = nM + 1
|
|
local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM)
|
|
local nMchFId = EgtAddMachining( sNameF, sMilling)
|
|
if not nMchFId then
|
|
local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ Proc.Id, 0}})
|
|
-- limito opportunamente la lavorazione
|
|
EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal)
|
|
EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal)
|
|
-- imposto posizione braccio porta testa per non ingombrare agli estremi
|
|
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
|
|
-- imposto uso faccia
|
|
EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN)
|
|
-- imposto lato di lavoro e inversione
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT)
|
|
EgtSetMachiningParam( MCH_MP.INVERT, true)
|
|
local dDepth = min( dMaxDepth, dWidth + dAgg)
|
|
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
|
|
-- eseguo
|
|
if not EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
end
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return ProcessLongCut
|