DataWall :
- aggiunta gestione Mortise, DtMortise, Mark e Text.
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
-- WProcessMortise.lua by Egaltech s.r.l. 2021/04/20
|
||||
-- Gestione calcolo mortase per Pareti
|
||||
|
||||
-- Tabella per definizione modulo
|
||||
local WPM = {}
|
||||
|
||||
-- Include
|
||||
require( 'EgtBase')
|
||||
local WL = require( 'WallLib')
|
||||
|
||||
EgtOutLog( ' WProcessMortise started', 1)
|
||||
|
||||
-- Dati
|
||||
local WD = require( 'WallData')
|
||||
local WM = require( 'WMachiningLib')
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Riconoscimento della feature
|
||||
function WPM.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 == 53))
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Classificazione della feature: decide se la feature è in una posizione che per lavorala
|
||||
-- deve essere ribaltata o no
|
||||
function WPM.Classify( Proc, b3Raw)
|
||||
-- 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
|
||||
-- Confronto le direzioni Z dei 2 versori : se diverse la faccia 0 non è il fondo => mortasa passante
|
||||
if abs( vtExtr:getZ() - vtN:getZ()) > 10 * GEO.EPS_SMALL then
|
||||
return true
|
||||
-- altrimenti è chiusa
|
||||
else
|
||||
-- verifico se la mortasa è lavorabile da sopra
|
||||
return ( vtN:getZ() > WD.NZ_MINA)
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Applicazione della lavorazione
|
||||
function WPM.Make( Proc, nRawId, b3Raw)
|
||||
-- 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 : missing profile geometry'
|
||||
EgtOutLog( sErr)
|
||||
return false, sErr
|
||||
end
|
||||
-- recupero versore estrusione della curva supplementare
|
||||
local vtExtr = EgtCurveExtrusion( AuxId, GDB_ID.ROOT)
|
||||
-- Se curva di contorno aperta
|
||||
if not EgtCurveIsClosed( AuxId) then
|
||||
local NewId, nCount = EgtExtractSurfTmFacetLoops( Proc.Id, 0, EgtGetParent( Proc.Id))
|
||||
if NewId then
|
||||
-- elimino eventuali loop interni (non dovrebbero comunque esserci)
|
||||
for i = 1, nCount - 1 do
|
||||
EgtErase( NewId + i)
|
||||
end
|
||||
-- sostituisco il loop esterno alla curva originale
|
||||
EgtModifyCurveExtrusion( NewId, vtExtr, GDB_ID.ROOT)
|
||||
EgtRelocate( NewId, AuxId, GDB_IN.AFTER)
|
||||
EgtErase( AuxId)
|
||||
EgtChangeId( NewId, AuxId)
|
||||
-- sistemo i lati aperti
|
||||
local vFacAdj = EgtSurfTmFacetAdjacencies( Proc.Id, 0)[1]
|
||||
if vFacAdj then
|
||||
local sOpen = ''
|
||||
for i = 1, #vFacAdj do
|
||||
if vFacAdj[i] < 0 then
|
||||
sOpen = sOpen .. EgtIf( #sOpen > 0, ',', '') .. tostring( i - 1)
|
||||
end
|
||||
end
|
||||
if #sOpen > 0 then
|
||||
EgtSetInfo( AuxId, 'OPEN', sOpen)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- recupero i dati della faccia di fondo
|
||||
local frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT)
|
||||
local ptC = ORIG()
|
||||
local vtN = V_NULL()
|
||||
if frMor then
|
||||
ptC = frMor:getOrigin()
|
||||
vtN = frMor:getVersZ()
|
||||
end
|
||||
-- Confronto le direzioni dei 2 versori : se diverse la faccia 0 non è il fondo => mortasa passante
|
||||
local bOpenBtm = not AreSameVectorApprox( vtExtr, vtN)
|
||||
if bOpenBtm then
|
||||
-- creo superficie chiusa
|
||||
local nFlat = EgtSurfTmByFlatContour( EgtGetParent( AuxId), AuxId, 0.05)
|
||||
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, WL.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)
|
||||
end
|
||||
end
|
||||
-- scrivo info nel log
|
||||
EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3)
|
||||
-- Se mortasa chiusa
|
||||
if not bOpenBtm then
|
||||
-- verifico che la mortasa non sia orientata verso il basso (limite -5 deg)
|
||||
if vtN:getZ() < WD.NZ_MINA then
|
||||
local sErr = 'Error : Mortise from bottom impossible'
|
||||
EgtOutLog( sErr)
|
||||
return false, sErr
|
||||
end
|
||||
-- altrimenti passante
|
||||
else
|
||||
-- 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 = WL.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
|
||||
if Proc.Prc ~= 53 then
|
||||
sPocketing = WM.FindPocketing( 'Mortise', dW)
|
||||
end
|
||||
if not sPocketing then
|
||||
sPocketing = WM.FindPocketing( 'Pocket', dW)
|
||||
end
|
||||
if not sPocketing then
|
||||
local sErr = 'Error : Mortise or Pocket not found in library'
|
||||
EgtOutLog( sErr)
|
||||
return false, sErr
|
||||
end
|
||||
-- recupero i dati dell'utensile
|
||||
local dMillDiam = 20
|
||||
local dMaxDepth = 0
|
||||
local bCW = true
|
||||
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)
|
||||
local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0
|
||||
bCW = ( dSpeed >= 0)
|
||||
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}})
|
||||
-- sistemo la direzione di lavoro
|
||||
EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false))
|
||||
-- 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 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) .. ')'
|
||||
-- se non ho invertito la direzione di estrusione
|
||||
if not bRevertSide then
|
||||
nDepthMin = dMaxDepth - EgtIf( bOpenBtm 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 bOpenBtm 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
|
||||
|
||||
return true, sWarn
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
return WPM
|
||||
Reference in New Issue
Block a user