59b7b9d44e
- in taglio lama per tenoni da sotto solo se non eccede MaxMat in altezza - migliorato controllo DtMortise in coda - in lavorazione BlckHausHalfLap si favorisce fresa BH di fianco se possibile.
291 lines
13 KiB
Lua
291 lines
13 KiB
Lua
-- ProcessDtMortise.lua by Egaltech s.r.l. 2020/06/20
|
|
-- 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
|
|
local bMakeAsByArc = 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)
|
|
-- la mortasa di fronte è già stata classificata nel chiamante
|
|
-- controllo la mortasa standard
|
|
if Proc.Box:getMin():getX() > b3Raw:getMin():getX() + BD.MAX_DIST_HTFEA then
|
|
-- recupero la curva di profilo
|
|
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
|
|
if not AuxId then return false end
|
|
AuxId = AuxId + Proc.Id
|
|
local vtStart = EgtSV( AuxId, GDB_ID.ROOT)
|
|
local vtEnd = EgtEV( AuxId, GDB_ID.ROOT)
|
|
local vtDir = -vtStart + vtEnd ; vtDir:normalize()
|
|
return ( vtDir:getX() < -0.5)
|
|
end
|
|
return false
|
|
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
|
|
|
|
---------------------------------------------------------------------
|
|
local function CalcTopPath( nProcId, AuxId, nAddGrpId, dAltMort, dSideAng, b3Solid)
|
|
-- copio la curva di base
|
|
local NewAuxId = EgtCopyGlob( AuxId, nAddGrpId)
|
|
if not NewAuxId then return end
|
|
-- ne allungo gli estremi
|
|
EgtExtendCurveStartByLen( NewAuxId, 100)
|
|
EgtExtendCurveEndByLen( NewAuxId, 100)
|
|
-- eseguo traslazione e offset per portarla sul top
|
|
local vtMove = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) * ( dAltMort - 10 * GEO.EPS_SMALL)
|
|
EgtMove( NewAuxId, vtMove, GDB_RT.GLOB)
|
|
local dOffset = dAltMort * tan( dSideAng)
|
|
if not EgtOffsetCurve( NewAuxId, dOffset) then return end
|
|
-- la limito entro la trave
|
|
local refBox = Frame3d( b3Solid:getMin())
|
|
local vtBoxDiag = b3Solid:getMax() - b3Solid:getMin()
|
|
local nCount
|
|
NewAuxId, nCount = EgtTrimFlatCurveWithBox( NewAuxId, refBox, vtBoxDiag, true, true, GDB_RT.GLOB)
|
|
-- se divisa in più parti, le unisco congiungendole con segmenti
|
|
if nCount > 1 then
|
|
if EgtGetType( NewAuxId) ~= GDB_TY.CRV_COMPO then
|
|
NewAuxId = EgtCurveCompo( nAddGrpId, NewAuxId)
|
|
end
|
|
for i = 2, nCount do
|
|
local CrvId = NewAuxId + i - 1
|
|
local ptStart = EgtSP( CrvId, GDB_ID.ROOT)
|
|
EgtAddCurveCompoLine( NewAuxId, ptStart, GDB_RT.GLOB)
|
|
EgtAddCurveCompoCurve( NewAuxId, CrvId)
|
|
end
|
|
end
|
|
return NewAuxId
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
-- Applicazione della lavorazione
|
|
function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId)
|
|
-- ingombro del pezzo
|
|
local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') 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
|
|
-- 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 e l'angolo di spoglia
|
|
local dToolDiam = 100
|
|
local dMaxMat = 30
|
|
local dSideAng = 0
|
|
local bCW = true
|
|
if EgtMdbSetCurrMachining( sMilling) then
|
|
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
|
|
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
|
|
dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam
|
|
dToolDiam = max( dToolDiam, 10)
|
|
dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat
|
|
dSideAng = EgtTdbGetCurrToolParam( MCH_TP.SIDEANG) or dSideAng
|
|
local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0
|
|
bCW = ( dSpeed >= 0)
|
|
end
|
|
end
|
|
-- 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
|
|
-- se parametro interno abilitato e il percorso non è chiuso, aggiungo percorso e lavorazione antischeggia
|
|
if bMakeAntiSplitPath and not EgtCurveIsClosed( AuxId) then
|
|
-- recupero il riferimento della faccia di fondo
|
|
local rfFac0 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT)
|
|
-- ottengo il box con la normale della faccia 0
|
|
local bBoxF0 = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, rfFac0)
|
|
-- recupero l'altezza della mortasa
|
|
local dAltMort = bBoxF0:getDimZ()
|
|
-- 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
|
|
-- calcolo il percorso top mortise
|
|
local nAuxId1 = CalcTopPath( Proc.Id, AuxId, nAddGrpId, dAltMort, dSideAng, b3Solid)
|
|
-- se esiste il percorso
|
|
if nAuxId1 then
|
|
-- creo percorso sulla parte alta della mortasa
|
|
local dToolRadDelta = dAltMort * tan( dSideAng)
|
|
local dTopDiam = dToolDiam + 2 * dToolRadDelta
|
|
-- recupero punto iniziale e finale del percorso
|
|
local ptStart = EgtSP( nAuxId1, GDB_RT.GLOB)
|
|
local ptEnd = EgtEP( nAuxId1, GDB_RT.GLOB)
|
|
if ptStart and ptEnd then
|
|
local nId1
|
|
-- se richiesti due segmenti di linea
|
|
if not bMakeAsByArc then
|
|
-- determino il punto comune dei due segmenti
|
|
local vtDelta = ( ptEnd - ptStart) / 4
|
|
vtDelta:rotate( vtExtr, -90)
|
|
local ptMid = ( ptStart + ptEnd) / 2 + vtDelta
|
|
-- creo la spezzata formata dai due segmenti
|
|
nId1 = EgtCurveCompoFromPoints( nAddGrpId, { ptStart, ptMid, ptEnd}, GDB_RT.GLOB)
|
|
-- altrimenti richiesto arco
|
|
else
|
|
-- direzione del segmento
|
|
local vtDir = ptEnd - ptStart ;
|
|
local dLen = vtDir:len()
|
|
vtDir:normalize()
|
|
-- direzioni tangenti iniziale e finale
|
|
local vtStart = EgtSV( nAuxId1, GDB_RT.GLOB)
|
|
local vtEnd = EgtEV( nAuxId1, GDB_RT.GLOB)
|
|
-- angoli
|
|
local dAngStart = acos( vtStart * vtDir)
|
|
local dAngEnd = acos( vtEnd * vtDir)
|
|
local dMaxAng = min( 30, dAngStart, dAngEnd)
|
|
if dLen < dTopDiam then
|
|
dMaxAng = min( dMaxAng, asin( dLen / dTopDiam))
|
|
end
|
|
local vtTg = vtDir ; vtTg:rotate( vtExtr, -dMaxAng)
|
|
-- creo l'arco
|
|
nId1 = EgtArc2PV( nAddGrpId, ptStart, ptEnd, vtTg, GDB_RT.GLOB)
|
|
end
|
|
if not nId1 then
|
|
local sErr = 'Wrong geometry : Error on DtMortise ' .. tostring( Proc.Id)
|
|
EgtOutLog( sErr)
|
|
return false, sErr
|
|
end
|
|
EgtModifyCurveExtrusion( nId1, vtExtr, GDB_RT.GLOB)
|
|
-- 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}})
|
|
-- setto affondamento pari all'altezza della mortsasa
|
|
EgtSetMachiningParam( MCH_MP.DEPTH, dAltMort)
|
|
-- setto offset radiale con aggiunto un ulteriore allargamento di 1mm
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, dToolRadDelta - 1)
|
|
-- sistemo il lato e la direzione di lavoro
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bCW, MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT))
|
|
EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, false, true))
|
|
-- dichiaro non si generano sfridi per VMill
|
|
local sUserNotes = 'MaxElev='.. EgtNumToString( dAltMort, 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
|
|
else
|
|
local sErr = 'Wrong geometry : 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()
|
|
-- calcolo le passate
|
|
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
|
|
-- aggiungo geometria
|
|
EgtSetMachiningGeometry( {{ AuxId, -1}})
|
|
-- imposto offset
|
|
local dOffs = ( i - 1) * dStep
|
|
EgtSetMachiningParam( MCH_MP.OFFSR, dOffs)
|
|
-- sistemo il lato e la direzione di lavoro
|
|
EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bCW, MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT))
|
|
EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, false, true))
|
|
-- 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
|