Files
trimming/CalcBezierEdges.lua
T
Riccardo Elitropi dfa187838b Trimming 3.1a4 :
- aggiunta memorizzazione dell'ulltimo tipo selezionato nella modalità selezione
- se le superfici di selezione generano più di 2 curve di bordo allora vengono definiti degli altri layer di trimming
- semplificazione gestione dei layer di sincronizzazione delle curve
- aggiunta funzionalità di rimozione delle superfici di Bezier in un layer di trimmatura
- miglioramento nella selezione delle curve di sincronizzazione nel caso di curve di bordo chiuse o aperte.
2026-01-22 19:21:28 +01:00

166 lines
6.5 KiB
Lua

-- CalcBezierEdges.lua by Egalware s.r.l. 2026/01/05
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
-- Carico le costanti di Trimming
EgtAddToPackagePath( EgtGetSourceDir() .. '?.lua')
local GlobVar = require( 'TrimmingLib')
-- Costante di Errore
local ERROR_EDGE_CREATION = 'Error in Edges Creation : '
-- Recupero il Part e Layer di Trimming corrente
local nCurrPartId = EgtGetCurrPart()
local nCurrLayerId = EgtGetCurrLayer()
if not GlobVar.IsTrimmingLayer( nCurrLayerId) then
EgtOutBox( ERROR_EDGE_CREATION .. 'Not a valid Trimming Layer', 'Error', 'ERROR', 'OK')
return
end
-- Recupero le Tolleranze Impostate
local dLinTol = EgtGetInfo( nCurrLayerId, KEY_LIN_TOL, 'd')
local dAngTol = EgtGetInfo( nCurrLayerId, KEY_ANG_TOL, 'd')
local dAngFaceTol = EgtGetInfo( nCurrLayerId, KEY_SURF_ANG_TOL, 'd')
local bOk = ( dLinTol ~= nil and dAngTol ~= nil and dAngFaceTol ~= nil)
if not bOk then
EgtOutBox( ERROR_EDGE_CREATION .. 'No Trimming Machining created', 'Error', 'ERROR', 'OK')
return
end
local dEdgeLinTol = EgtGetInfo( nCurrLayerId, KEY_LIN_TOL_EDGES, 'd')
local dEdgeThick = EgtGetInfo( nCurrLayerId, KEY_THICK_EDGES, 'd')
-- Determino il Tipo di Estrazione degli Edges
local dLinTolForEdges = dLinTol
local dThickForEdges = 5.0
if dEdgeLinTol then dLinTolForEdges = dEdgeLinTol end
if dEdgeThick then dThickForEdges = dEdgeThick end
local vsVal = EgtDialogBox( 'Edge Extraction', { 'Type', 'CB:*Extract Edges,Edges from Normals'},
{ 'Linear Tolerance', tostring( dLinTolForEdges)},
{ 'Thickness', tostring( dThickForEdges)})
if not vsVal or #vsVal ~= 3 then return end
-- Rendo invisibili gli altri Layer di Trimmatura e tutti i Layer Temporanei
-- NB. Il focus va sul Layer corrente
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
nId = EgtGetFirstInGroup( nCurrPartId)
while nId do
if nId ~= nCurrLayerId and
( GlobVar.IsTrimmingLayer( nId) or GlobVar.IsEditSyncCurvesLayer( nId)) then EgtSetStatus( nId, GDB_ST.OFF) end
nId = EgtGetNext( nId)
end
-- Rimuovo Tutte le Entità ad Eccezione delle Superfici Selezionate ( nel caso Le rendo Visibili)
-- [NB. La Creazione deli Edges cancella tutti i risutati fatti fino ad adesso]
local vIdToErase = {}
local nId = EgtGetFirstInGroup( nCurrLayerId)
while nId do
local sName = EgtGetName( nId)
if sName ~= SELECTION_SURF_NAME then table.insert( vIdToErase, nId)
else EgtSetStatus( nId, GDB_ST.ON) end
nId = EgtGetNext( nId)
end
EgtErase( vIdToErase)
-- Scorro le superfici di Selezione presenti e recupero il vettore di Selezione {nSurf, nFace}
local vSel = {}
local nSelSurfId = EgtGetFirstNameInGroup( nCurrLayerId, SELECTION_SURF_NAME)
while nSelSurfId do
-- Verifico che sia una Superficie TriMesh o Bezier
local nType = EgtGetType( nSelSurfId)
if nType ~= GDB_TY.SRF_BEZ and nType ~= GDB_TY.SRF_MESH then
EgtOutBox( ERROR_RAW_EDGE_CREATION .. 'Invalid Surface Selected. The Surface must be a TriMesh or a Bezier', 'Error', 'ERROR', 'OK')
return
end
table.insert( vSel, { nSelSurfId, -1})
nSelSurfId = EgtGetNextName( nSelSurfId, SELECTION_SURF_NAME)
end
-- Se non ho superfici di Selezione errore
if #vSel == 0 then
EgtOutBox( ERROR_RAW_EDGE_CREATION .. 'No Selected Surf', 'Error', 'ERROR', 'OK')
return
end
local nFirstId, nCount
--------------------------------- Estrazione degli Edges ---------------------------------
if vsVal[1] == 'Extract Edges' then
-- Recupero la tolleranza lineare per l'estrazione degli Edges
dEdgeLinTol = tonumber( vsVal[2])
-- La memorizzo come Info per recuperla successivamente
EgtSetInfo( nCurrLayerId, KEY_LIN_TOL_EDGES, dEdgeLinTol)
-- Recupero i Bordi
bOk, nFirstId, nCount = EgtTrimmingGetBorders( nCurrLayerId, vSel, dEdgeLinTol, dAngTol)
if not bOk then
EgtOutBox( ERROR_EDGE_CREATION .. 'Error in Computing Edges', 'Error', 'ERROR', 'OK')
return
end
-- Assegno Colore e Name
for i = 0, nCount - 1 do
bOk = EgtSetColor( nFirstId + i, EDGES_COLOR) and
EgtSetName( nFirstId + i, EDGES_NAME)
if not bOk then
EgtOutBox( ERROR_EDGE_CREATION .. 'Assign Raw Edges Properties failed', 'Error', 'ERROR', 'OK')
return
end
end
--------------------------------- Calcolo Edges per normali ---------------------------------
else
-- Recupero la tolleranza lineare per l'estrazione degli Edges e la Thickness
dEdgeLinTol = tonumber( vsVal[2])
local dThickness = tonumber( vsVal[3])
-- Le Memorizzo per recuperale successivamente
EgtSetInfo( nCurrLayerId, KEY_LIN_TOL_EDGES, dEdgeLinTol)
EgtSetInfo( nCurrLayerId, KEY_THICK_EDGES, dEdgeThick)
-- Calcolo i Bordi
bOk, nFirstId, nCount = EgtTrimmingGetBordersByNormals( nCurrLayerId, vSel, dEdgeLinTol, dAngTol, dThickness)
if not bOk then
EgtOutBox( ERROR_EDGE_CREATION .. 'Error in Computing Edges', 'Error', 'ERROR', 'OK')
return
end
end
-- Assegno Colore e Name
for i = 0, nCount - 1 do
bOk = EgtSetColor( nFirstId + i, EDGES_COLOR) and
EgtSetName( nFirstId + i, EDGES_NAME)
if not bOk then
EgtOutBox( ERROR_EDGE_CREATION .. 'Assign Raw Edges Properties failed', 'Error', 'ERROR', 'OK')
return
end
end
-- Se più di due curve, definisco dei nuovi Layer di Trimming
if nCount > 2 then
for i = 2, nCount - 1, 2 do
-- Definisco un nuovo Layer di trimming
local nNewTrimmingLayer = GlobVar.CreateTrimmingLayer( nCurrPartId)
if nCurrLayerId == GDB_ID.NULL then
EgtOutBox( ERROR_CREATING_NEW_TRIMMING .. 'Defining Layer failed', 'Error', 'ERROR', 'OK')
return
end
-- Copio proprietà
bOk = EgtSetInfo( nNewTrimmingLayer, KEY_LIN_TOL, dLinTol) and
EgtSetInfo( nNewTrimmingLayer, KEY_ANG_TOL, dAngTol) and
EgtSetInfo( nNewTrimmingLayer, KEY_SURF_ANG_TOL, dAngFaceTol) and
EgtSetInfo( nNewTrimmingLayer, KEY_LIN_TOL_EDGES, dEdgeLinTol)
if not bOk then
EgtOutBox( ERROR_CREATING_NEW_TRIMMING .. 'Saving Tolerances failed', 'Error', 'ERROR', 'OK')
EgtErase( nNewTrimmingLayer)
return
end
-- Copio tutte le entità di tale gruppo ( ad eccezzione delle curve)
local nOldId = EgtGetFirstInGroup( nCurrLayerId)
while nOldId do
local sName = EgtGetName( nOldId)
if sName ~= EDGES_NAME then
local nNewId = EgtCopyGlob( nOldId, nNewTrimmingLayer)
end
nOldId = EgtGetNext( nOldId)
end
EgtRelocate( nFirstId + i, nNewTrimmingLayer)
EgtRelocate( nFirstId + i + 1, nNewTrimmingLayer)
end
end
-- Aggiorno la Grafica
EgtDraw()