3dd65a606d
- varie correzioni e migliorie.
226 lines
9.2 KiB
Lua
226 lines
9.2 KiB
Lua
-- ProcessMortise.lua by Egaltech s.r.l. 2020/03/19
|
|
-- Gestione calcolo mortase a coda di rondice per Travi
|
|
|
|
-- Tabella per definizione modulo
|
|
local ProcessDtMortise = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
|
|
EgtOutLog( ' ProcessDtMortise started', 1)
|
|
|
|
-- Dati
|
|
local BL = require( 'BeamLib')
|
|
local BD = require( 'BeamData')
|
|
local ML = require( 'MachiningLib')
|
|
|
|
-- settaggi interni ( poi andrà utilizzato parametro ACTIVE_AS proveniente da parametri utente di TechnoEssetre)
|
|
local bMakeAntiSplitPath = true
|
|
|
|
---------------------------------------------------------------------
|
|
-- Riconoscimento della feature
|
|
function ProcessDtMortise.Identify( Proc)
|
|
return ( (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 55) or
|
|
(( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 56))
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Verifica se feature di coda
|
|
function ProcessDtMortise.IsTailFeature( Proc, b3Raw)
|
|
-- verifico se è in coda
|
|
if Proc.Box:getMin():getX() > b3Raw:getMin():getX() + BD.MAX_DIST_HTFEA then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Classificazione della feature
|
|
function ProcessDtMortise.Classify( Proc)
|
|
-- recupero i dati della curva di contorno della faccia di fondo
|
|
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
|
|
if not AuxId then return false end
|
|
AuxId = AuxId + Proc.Id
|
|
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
|
|
-- verifico se la mortasa è lavorabile solo da sotto
|
|
local bDown = ( vtExtr:getZ() < - 0.1)
|
|
return true, bDown
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId)
|
|
-- recupero e verifico l'entità curva
|
|
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
|
|
if AuxId then AuxId = AuxId + Proc.Id end
|
|
if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then
|
|
local sErr = 'Missing profile geometry : Error on DtMortise ' .. tostring( Proc.Id)
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero i dati della curva e del top
|
|
local dDepth = abs( EgtCurveThickness( AuxId))
|
|
local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
|
|
-- verifico che la mortasa non sia orientata verso il basso (-5 deg)
|
|
if vtExtr:getZ() < - 0.1 then
|
|
local sErr = 'Machining from bottom impossible : Error on DtMortise ' .. tostring( Proc.Id)
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero la lavorazione
|
|
local sMilling = ML.FindMilling( 'DtMortise')
|
|
if not sMilling then
|
|
local sErr = 'Milling not found in library : Error on DtMortise ' .. tostring( Proc.Id)
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- recupero il diametro dell'utensile
|
|
local dToolDiam = 100
|
|
local dMaxMat = 30
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam
|
|
dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat
|
|
end
|
|
end
|
|
-- se parametro interno abilitato e il percorso non è chiuso, aggiungo percorso e lavorazione antischeggia
|
|
if bMakeAntiSplitPath and not EgtCurveIsClosed( AuxId) then
|
|
-- recupero punto iniziale e finale del percorso
|
|
local pStartP = EgtSP( AuxId, GDB_RT.GLOB)
|
|
local pEndP = EgtEP( AuxId, GDB_RT.GLOB)
|
|
if pStartP and pEndP 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
|
|
|
|
local pMid = ( pStartP + pEndP) / 2
|
|
local dDistMid = dist( pStartP, pMid)
|
|
local pMidArc
|
|
local bGoodArc
|
|
local nDiv = 2
|
|
local nId1
|
|
-- ciclo fino ad individuare arco compativile con l'utensile
|
|
while not bGoodArc do
|
|
-- linea dal punto medio alla fine
|
|
nId1 = EgtLine( nAddGrpId, pMid, pEndP, GDB_RT.GLOB)
|
|
-- se è stata creata setto il piano e l'accorcio
|
|
if nId1 then
|
|
-- EgtModifyCurveExtrusion( nId1, vtExtr, GDB_RT.GLOB)
|
|
-- accorcio la seconda linea al valore impostato, partendo dal divisore 2
|
|
EgtTrimExtendCurveByLen( nId1, -( dDistMid * ( 1 - ( 1 / nDiv))), pEndP, GDB_RT.GLOB)
|
|
-- ruoto di -90 gradi
|
|
EgtRotate( nId1, pMid, vtExtr, -90, GDB_RT.GLOB)
|
|
-- prendo il punto finale dell'entità ruotata
|
|
pMidArc = EgtEP( nId1, GDB_RT.GLOB)
|
|
-- cancello linea
|
|
EgtErase(nId1)
|
|
-- creo arco per 3 punti
|
|
nId1 = EgtArc3P( nAddGrpId, pStartP, pMidArc, pEndP, GDB_RT.GLOB)
|
|
if nId1 then
|
|
EgtModifyCurveExtrusion( nId1, vtExtr, GDB_RT.GLOB)
|
|
-- recupero il raggio e lo comparo con il raggio utensile,
|
|
-- se è maggiore del raggio utensile esco dal cliclo
|
|
local dRad = EgtArcRadius( nId1)
|
|
if dRad > 0 and dRad > dToolDiam then
|
|
bGoodArc = true
|
|
else
|
|
-- cancello l'arco e incremento il componente del divisore
|
|
EgtErase(nId1)
|
|
nDiv = nDiv + 1
|
|
end
|
|
else
|
|
bGoodArc = true
|
|
end
|
|
else
|
|
bGoodArc = true
|
|
end
|
|
end
|
|
if not nId1 then
|
|
local sErr = 'Wrong geometry : Error on DtMortise ' .. tostring( Proc.Id)
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- inserisco la lavorazione di contornatura anti splint
|
|
local sNameF = 'DtMtAS_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
|
|
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( {{ nId1, -1}})
|
|
-- dichiaro non si generano sfridi per VMill
|
|
local sUserNotes = 'MaxElev='.. EgtNumToString( dMaxMat - 0.1, 1) .. 'VMRS=0;'
|
|
EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes)
|
|
-- eseguo
|
|
if not EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
else
|
|
local sErr = 'Wrong geometry : Error on DtMortise ' .. tostring( Proc.Id)
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
end
|
|
dToolDiam = max( dToolDiam, 10)
|
|
-- verifico se raggio troppo piccolo per l'utensile
|
|
local nSt, nEnd = EgtCurveDomain( AuxId)
|
|
for i = nSt, nEnd - 1 do
|
|
local dRad = EgtCurveCompoRadius( AuxId, i)
|
|
if dRad > 0 and dRad < dToolDiam / 2 then
|
|
local sErr = 'Radius too small : Error on DtMortise ' .. tostring( Proc.Id)
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
end
|
|
-- verifico se necessarie più passate (distanza all'imbocco ortogonale all'asse)
|
|
local vtDiff = EgtEP( AuxId, GDB_RT.GLOB) - EgtSP( AuxId, GDB_RT.GLOB)
|
|
local vtAx = EgtEV( AuxId, GDB_RT.GLOB) - EgtSV( AuxId, GDB_RT.GLOB)
|
|
vtAx:normalize()
|
|
local vtOrtDiff = vtDiff - vtDiff * vtAx * vtAx
|
|
local dDist = vtOrtDiff:len()
|
|
if dDist < dToolDiam + 0.5 then
|
|
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' Dt mortise too narrow'
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
local nPass = ceil( dDist / ( 1.9 * dToolDiam))
|
|
local dStep = ( dDist - 0.95 * dToolDiam) / ( 2 * nPass)
|
|
for i = nPass, 1, -1 do
|
|
-- inserisco la lavorazione di contornatura
|
|
local sNameF = 'DtMt_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nPass)
|
|
local nMchFId = EgtAddMachining( sNameF, sMilling)
|
|
if not nMchFId then
|
|
local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
-- imposto offset
|
|
local dOffs = ( i - 1) * dStep
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, dOffs)
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ AuxId, -1}})
|
|
-- dichiaro non si generano sfridi per VMill
|
|
local sUserNotes = 'MaxElev='.. EgtNumToString( dMaxMat - 0.1, 1) .. 'VMRS=0;'
|
|
EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes)
|
|
-- eseguo
|
|
if not EgtApplyMachining( true, false) then
|
|
local _, sErr = EgtGetLastMachMgrError()
|
|
EgtSetOperationMode( nMchFId, false)
|
|
return false, sErr
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
return ProcessDtMortise
|