dfa187838b
- 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.
143 lines
5.0 KiB
Lua
143 lines
5.0 KiB
Lua
-- EditBezierBorders.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_EDIT_CURVE = 'Error in Edit Borders : '
|
|
|
|
-- Recupero il Part e Layer di Trimming corrente ( o di riferimento)
|
|
local nCurrPartId = EgtGetCurrPart()
|
|
local nCurrLayerId = GlobVar.GetTrimmingLayerRefId( EgtGetCurrLayer())
|
|
if not GlobVar.IsTrimmingLayer( nCurrLayerId) then
|
|
EgtOutBox( ERROR_EDIT_CURVE .. 'Not a valid Trimming Layer', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
|
|
-- Creo un Layer di Edit ( o Recupero quello corrente) per le curve di Bordo
|
|
local nLayerEditId = GlobVar.GetCurrentEditLayer( nCurrPartId)
|
|
if not nLayerEditId or nLayerEditId == GDB_ID.NULL then
|
|
nLayerEditId = GlobVar.CreateEditCurvesLayer( nCurrPartId, nCurrLayerId)
|
|
else
|
|
local bClear = EgtOutBox( 'Do you want to delete the edit Layer ?', 'Edit', 'QUESTION', 'YESNO')
|
|
if bClear then
|
|
EgtErase( nLayerEditId)
|
|
EgtSetCurrPartLayer( nCurrPartId, nCurrLayerId)
|
|
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
|
|
EgtDraw()
|
|
end
|
|
return
|
|
end
|
|
if not nLayerEditId or nLayerEditId == GDB_ID.NULL then
|
|
EgtOutBox( ERROR_EDIT_CURVE .. 'Error in creating Edit Layer', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
|
|
-- Recupero le Info
|
|
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_EDIT_CURVE .. 'No Trimming Machining created', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
|
|
-- Rendo Invisibili gli altri Layer di Trimming
|
|
nId = EgtGetFirstInGroup( nCurrPartId)
|
|
while nId do
|
|
if GlobVar.IsTrimmingLayer( nId) then
|
|
-- Se altro Layer di Trimming, allora diventa invisibile
|
|
if nId ~= nCurrLayerId then EgtSetStatus( nId, GDB_ST.OFF)
|
|
-- Se Layer di Trimming corrente, lascio visibili solo le Superfici di Selezione
|
|
else
|
|
local nObjId = EgtGetFirstInGroup( nId)
|
|
while nObjId do
|
|
local sName = EgtGetName( nObjId)
|
|
if sName ~= SELECTION_SURF_NAME then EgtSetStatus( nObjId, GDB_ST.OFF) end
|
|
nObjId = EgtGetNext( nObjId)
|
|
end
|
|
end
|
|
end
|
|
nId = EgtGetNext( nId)
|
|
end
|
|
|
|
-- Copio Gli Edge di Bezier nel gruppo di Edit ( l'utente vede sia la Surf che gli Edge)
|
|
local nId = EgtGetFirstInGroup( nCurrLayerId)
|
|
local vnBzCrvId = {}
|
|
while nId do
|
|
local sName = EgtGetName( nId)
|
|
if sName == EDGES_NAME then table.insert( vnBzCrvId, EgtCopyGlob( nId, nLayerEditId))
|
|
-- Rendo Visibili eventuali Superfici di Selezione
|
|
elseif sName == SELECTION_SURF_NAME then EgtSetStatus( nId, GDB_ST.ON) end
|
|
nId = EgtGetNext( nId)
|
|
end
|
|
-- Se non ho trovato curve, errore
|
|
if #vnBzCrvId == 0 then
|
|
EgtOutBox( ERROR_EDIT_CURVE .. 'No Borders found', 'Error', 'ERROR', 'OK')
|
|
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
|
|
EgtErase( nLayerEditId)
|
|
return
|
|
end
|
|
|
|
-- Imposto come Layer corrente quello di Edit
|
|
EgtSetCurrPartLayer( nCurrPartId, nLayerEditId)
|
|
|
|
-- Imposto visibili Tutti gli Oggetti nel Layer di Edit
|
|
local nEditObjId = EgtGetFirstInGroup( nLayerEditId)
|
|
while nEditObjId do
|
|
EgtSetStatus( nEditObjId, GDB_ST.ON)
|
|
nEditObjId = EgtGetNext( nEditObjId)
|
|
end
|
|
|
|
-- Chiedo la tipologia di riconoscimento per le due curve di bordo
|
|
local vsVal = EgtDialogBox( 'Edit Edges', { 'Type', 'CB:*Automatic,Manual,Thickness'},
|
|
{ 'Thickness', '0.0'},
|
|
{ 'Thickness Tolerance', '0.0'})
|
|
if not vsVal or #vsVal ~= 3 then return end
|
|
local dThick = 0.
|
|
local dThickTol = 0.
|
|
-- Se Modalità Manuale, esco
|
|
if vsVal[1] == 'Manual' then EgtDraw() return end
|
|
-- Se Modalità Thickness, recupero lo Spessore e la Tolleranza
|
|
if vsVal[1] == 'Thickness' then
|
|
dThick = tonumber( vsVal[2])
|
|
dThickTol = tonumber( vsVal[3])
|
|
end
|
|
|
|
-- Recupero le Curve di Bordo ( rimuovendo le copie fatte precedentemente)
|
|
local nFirstId, nCount
|
|
bOk, nFirstId, nCount = EgtTrimmingGetFinalBorders( nLayerEditId, vnBzCrvId, dLinTol, dAngTol, {}, dThick, dThickTol)
|
|
if not bOk then
|
|
EgtOutBox( ERROR_EDIT_CURVE .. 'Error in Computing Edges', 'Error', 'ERROR', 'OK')
|
|
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
|
|
EgtErase( nLayerEditId)
|
|
return
|
|
end
|
|
|
|
-- Assegno Colore e Name e cancello le copie create precedentemente
|
|
nId = EgtGetFirstInGroup( nLayerEditId)
|
|
local vIdToErase = {}
|
|
while nId do
|
|
if nId < nFirstId then
|
|
table.insert( vIdToErase, nId)
|
|
else
|
|
bOk = EgtSetColor( nId, EDGES_COLOR) and EgtSetName( nId, EDGES_NAME)
|
|
if not bOk then
|
|
EgtOutBox( ERROR_EDIT_CURVE .. 'Assign Raw Edges Properties failed', 'Error', 'ERROR', 'OK')
|
|
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
|
|
EgtErase( nLayerEditId)
|
|
return
|
|
end
|
|
end
|
|
nId = EgtGetNext( nId)
|
|
end
|
|
EgtErase( vIdToErase)
|
|
|
|
-- Aggiorno la Grafica
|
|
EgtDraw()
|