Files
DataBeam/LuaLibs/ProcessMortise.lua
T
Dario Sassi c0bb72e816 DataBeam :
- aggiunta gestione feature SawCut (0/3/4-013-X)
- elevazione del tenone diminuita di 0.1 per evitare poi problemi con arrotondamenti.
2020-01-29 16:32:16 +00:00

269 lines
11 KiB
Lua

-- ProcessMortise.lua by Egaltech s.r.l. 2019/11/10
-- Gestione calcolo mortase per Travi
-- Tabella per definizione modulo
local ProcessMortise = {}
-- Include
require( 'EgtBase')
local BL = require( 'BeamLib')
EgtOutLog( ' ProcessMortise started', 1)
-- Dati
local BD = require( 'BeamData')
local ML = require( 'MachiningLib')
---------------------------------------------------------------------
-- Riconoscimento della feature
function ProcessMortise.Identify( Proc)
return ( (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 50) or
(( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 51) or
(( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 53))
end
---------------------------------------------------------------------
-- Classificazione della feature: decide se la feature è in una posizione che per lavorala
-- deve essere ribaltata o no
function ProcessMortise.Classify( Proc)
-- recupero e verifico il percorso supplementare
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
if AuxId then AuxId = AuxId + Proc.Id end
-- recupero versore estrusione della curva supplementare e non più della superficie
-- perché quest'ultima potrebbe non avere il fondo e dare quindi un risultato non corretto
local vtExtr = EgtCurveExtrusion( AuxId or GDB_ID.NULL, GDB_ID.ROOT)
-- recupero i dati della faccia di fondo
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
-- verifico sia una superficie
if not vtExtr then
return false
end
if not vtN then
return false
end
local bDown
-- Confronto le 2 direzioni Z dei versori
-- se differiscono allora la faccetta 0 della superficie non è il fondo della mortasa+
-- e quindi la mortasa è passante
if abs( vtExtr:getZ() - vtN:getZ()) > GEO.EPS_SMALL then
bDown = false
else -- se è chiusa
-- verifico se la mortasa è lavorabile solo da sotto
bDown = ( vtN:getZ() < - 0.1)
end
return true, bDown
end
---------------------------------------------------------------------
-- Applicazione della lavorazione
function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId)
-- recupero e verifico l'entità curva
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
local bForceOneSide
local bRevertSide
if AuxId then
AuxId = AuxId + Proc.Id
end
if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry'
EgtOutLog( sErr)
return false, sErr
end
-- se curva aperta la allungo e chiudo
if not EgtCurveIsClosed( AuxId) then
local _, nCount = EgtCurveDomain( AuxId)
EgtCloseCurveCompo( AuxId)
EgtSetInfo( AuxId, 'OPEN', nCount)
end
-- recupero versore estrusione della curva supplementare e confronto la direzione Z
-- del versore della componente Z della superficie
local vtExtr = EgtCurveExtrusion( AuxId, GDB_ID.ROOT)
-- recupero i dati del bottom
local frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT)
local ptC = frMor:getOrigin()
local vtN = frMor:getVersZ()
local bNotExistBtm
-- Confronto le 2 direzioni Z dei versori
-- se differiscono allora la faccetta 0 della superficie non è il fondo della mortasa+
-- e quindi la mortasa è passante
if abs( vtExtr:getZ() - vtN:getZ()) > GEO.EPS_SMALL then
-- creo superficie chiusa
local nFlat = EgtSurfTmByFlatContour( EgtGetParent(AuxId), AuxId, 0.02)
if nFlat then
frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( nFlat, 0, GDB_ID.ROOT)
ptC = frMor:getOrigin()
vtN = frMor:getVersZ()
-- verifico se copiare la geometria lungo l'asse Z
local b3Aux = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frMor)
local bxMax = b3Aux:getMax()
local b3Mor = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frMor)
local bxMin = b3Mor:getMin()
local dMove = bxMin:getZ()-bxMax:getZ()
-- se il percorso ausiliario è esterno al grezzo, lo riavvicino
if abs( dMove) > GEO.EPS_SMALL then
AuxId = EgtCopyGlob( AuxId, BL.GetAddGroup(nPartId))
EgtMove( AuxId, Vector3d(0,0,-dMove))
EgtMove( nFlat, Vector3d(0,0,-dMove))
frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( nFlat, 0, GDB_ID.ROOT)
ptC = frMor:getOrigin()
vtN = frMor:getVersZ()
end
-- cancello le prove del misfatto (superficie piana)
EgtErase(nFlat)
-- setto il flag che indica che non c'è il fondo
bNotExistBtm = true
end
end
-- scrivo info nel log
EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3)
if not bNotExistBtm then
-- verifico che la mortasa non sia orientata verso il basso (limite -5 deg)
if vtN:getZ() < - 0.1 then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' Mortise from bottom impossible'
EgtOutLog( sErr)
return false, sErr
end
else -- se mortasa passante
-- determino se la mortasa da lavorare sul lato opposto sia di angolo inferiore a quello consentito
if abs(vtN:getZ()) > 0.1 then
bForceOneSide = true
end
-- determino se è meglio lavorare la mortasa nel lato opposto
if vtN:getZ() < -GEO.EPS_SMALL then
bRevertSide = true
end
end
-- determino altezza della mortasa
local b3Mor = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frMor)
local dMorH = b3Mor:getDimZ()
-- elevazione del punto centro
local _, dCenElev = BL.GetPointDirDepth( nPartId, ptC, vtN)
dMorH = max( dMorH, dCenElev or 0)
-- determino larghezza della mortasa
if dL < dW then dL, dW = dW, dL end
-- recupero la lavorazione
local sPocketing = ML.FindPocketing( 'Pocket', dW)
if not sPocketing then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' pocketing not found in library'
EgtOutLog( sErr)
return false, sErr
end
-- recupero i dati dell'utensile
local dMillDiam = 20
local dMaxDepth = 0
if EgtMdbSetCurrMachining( sPocketing) then
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam
dMaxDepth = ( EgtTdbGetCurrToolMaxDepth() or dMaxDepth)
end
end
-- inserisco la lavorazione di svuotatura
local sName = 'Mort_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
local nMchFId = EgtAddMachining( sName, sPocketing)
if not nMchFId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing
EgtOutLog( sErr)
return false, sErr
end
-- verifico se invertire versore estrusione geometria
if bRevertSide then
EgtModifyCurveExtrusion( AuxId, -vtExtr, GDB_ID.ROOT)
end
-- aggiungo geometria
EgtSetMachiningGeometry( {{ AuxId, -1}})
-- imposto posizione braccio porta testa
if vtN:getY() < GEO.EPS_SMALL then
if bRevertSide then
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP)
else
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM)
end
else
if bRevertSide then
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM)
else
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP)
end
end
local sWarn
local nDepthMin
-- se la mortasa è passante e non è forzata a un solo lato, riduco l'affondamento a metà profondità
if bNotExistBtm and not bForceOneSide then
dMorH = dMorH * 0.5
end
-- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente
if dMorH > dMaxDepth + 10 * GEO.EPS_SMALL then
sWarn = 'Warning in mortise : elevation (' .. EgtNumToString( dMorH,1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth,1) .. ')'
if not bRevertSide then -- se non ho invertito la direzione di estrusione
nDepthMin = dMaxDepth - EgtIf( bNotExistBtm and not bForceOneSide, dMorH*2, dMorH)
else
nDepthMin = dMaxDepth
end
EgtSetMachiningParam( MCH_MP.DEPTH, nDepthMin)
dMorH = dMaxDepth
EgtOutLog( sWarn .. ' (process ' .. tostring( Proc.Id) .. ')')
else
if bNotExistBtm and not bForceOneSide then -- se mortasa passante setto metà profondità
nDepthMin = -dMorH
EgtSetMachiningParam( MCH_MP.DEPTH, nDepthMin)
end
end
-- imposto elevazione
EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dMorH, 1) .. ';')
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchFId, false)
return false, sErr
end
-- ESPERIMENTO:
-- se non c'è il fondo e la lavorazione non ha lavorato tutta la superficie per limite altezza utensile
-- inserisco una ulteriore lavorazione contraria
if bNotExistBtm and not bForceOneSide and nDepthMin and abs(nDepthMin) > 0 then
-- inserisco la lavorazione di svuotatura opposta
sName = 'Mort_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_Oppo'
nMchFId = EgtAddMachining( sName, sPocketing)
if not nMchFId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing
EgtOutLog( sErr)
return false, sErr
end
-- faccio la copia e la metto nel layer dedicato alle geometrie aggiunte
local AuxId_oppo = EgtCopyGlob( AuxId, BL.GetAddGroup(nPartId))
-- inverto la direzione estrusione di questa
EgtModifyCurveExtrusion( AuxId_oppo, - vtExtr, GDB_ID.ROOT)
-- aggiungo geometria
EgtSetMachiningGeometry( {{ AuxId_oppo, -1}})
-- imposto posizione braccio porta testa
if vtN:getY() < GEO.EPS_SMALL then
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP)
else
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM)
end
-- se altezza mortasa differente da altezza massima lavorabile
if abs(dMorH - dMaxDepth) > GEO.EPS_SMALL then
nDepthMin = -dMorH
else -- se sono uguali setto
nDepthMin = -(dMorH - BD.CUT_EXTRA)
end
-- setto profondità
EgtSetMachiningParam( MCH_MP.DEPTH, -nDepthMin+BD.CUT_EXTRA)
-- imposto elevazione
EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( (-nDepthMin+BD.CUT_EXTRA), 1) .. ';')
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchFId, false)
return false, sErr
end
end
return true, sWarn
end
---------------------------------------------------------------------
return ProcessMortise