Files
trimming/EditSyncLines.lua
T
Riccardo Elitropi e44363de3d Trimming 3.1a5 :
- aggiunte tolleranze a livello interfaccia per le curve di bordo.
2026-01-23 17:59:39 +01:00

118 lines
4.7 KiB
Lua

-- EditSyncLines.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_SYNC_CURVES = 'Error in Edit Sync Curves : '
-- 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_SYNC_CURVES .. 'Not a valid Trimming 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_SYNC_CURVES .. 'No Trimming Machining created', 'Error', 'ERROR', 'OK')
return
end
-- Creo/Recupero il Layer di Edit per le curve di Sincronizzazione
local nLayerEditSyncId = GlobVar.GetCurrentEditSyncCurvesLayer( nCurrPartId, nCurrLayerId)
if nLayerEditSyncId ~= nil and nLayerEditSyncId ~= GDB_ID.NULL then
local bClear = EgtOutBox( 'Do you want to delete the edit Layer ?', 'Edit', 'QUESTION', 'YESNO')
if bClear then EgtErase( nLayerEditSyncId)
else
EgtSetCurrPartLayer( nCurrPartId, nLayerEditSyncId)
EgtDraw()
return
end
end
nLayerEditSyncId = GlobVar.CreateEditSyncCurvesLayer( nCurrPartId, nCurrLayerId)
if not nLayerEditSyncId or nLayerEditSyncId == GDB_ID.NULL then
EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Error in creating Edit Layer', 'Error', 'ERROR', 'OK')
return
end
local vIdEdges = {}
nId = EgtGetFirstInGroup( nCurrLayerId)
while nId do
-- verifico che sia una Curva e che sia di Bordo
if EgtGetName( nId) == EDGES_NAME then
-- Verifico che sia una Curva
local nType = EgtGetType( nId)
if nType ~= GDB_TY.CRV_LINE and nType ~= GDB_TY.CRV_ARC and nType ~= GDB_TY.CRV_BEZ and nType ~= GDB_TY.CRV_COMPO then
EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Invalid Curve Selected', 'Error', 'ERROR', 'OK')
return
end
table.insert( vIdEdges, nId)
end
nId = EgtGetNext( nId)
end
-- Se nel gruppo di Edit delle curve non ne ho esattamente 2 di bordo, errore
if #vIdEdges ~= 2 then
EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Not 2 Border Curves detected', 'Error', 'ERROR', 'OK')
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
EgtErase( nLayerEditSyncId)
return
end
-- Chiedo i Parametri all'Utente
local nSyncLinesNumber = EgtGetInfo( nCurrLayerId, KEY_SYNC_LINES_NUMBER, 'i')
local bShowOnCorners = EgtGetInfo( nCurrLayerId, KEY_SYNC_LINES_SHOW_ON_CORNERS, 'b')
local dSyncLinesAngTol = EgtGetInfo( nCurrLayerId, KEY_SYNC_LINES_NUMBER_ANG_TOL, 'd')
if not nSyncLinesNumber or nSyncLinesNumber < 0. then nSyncLinesNumber = SYNC_LINES_NUMBER end
if bShowOnCorners == nil then bShowOnCorners = true end
if bShowAllLines == nil then bShowAllLines = false end
if not dSyncLinesAngTol or dSyncLinesAngTol < 0. then dSyncLinesAngTol = SYNC_LINES_ANG_TOL end
local vsVal = EgtDialogBox( 'Seletion', { 'Show on Corners', 'CK:' .. ( bShowOnCorners and '1' or '0')},
{ 'Angular Tolerance', tostring( dSyncLinesAngTol)},
{ 'Line Number', tostring( nSyncLinesNumber)})
if not vsVal or #vsVal ~= 3 then
EgtErase( nLayerEditSyncId)
EgtSetCurrPartLayer( nCurrPartId, nCurrLayerId)
return
end
bShowOnCorners = ( vsVal[1] == '1')
dSyncLinesAngTol = tonumber( vsVal[2])
nSyncLinesNumber = tonumber( vsVal[3])
EgtSetInfo( nCurrLayerId, KEY_SYNC_LINES_NUMBER, nSyncLinesNumber)
EgtSetInfo( nCurrLayerId, KEY_SYNC_LINES_SHOW_ON_CORNERS, bShowOnCorners)
EgtSetInfo( nCurrLayerId, KEY_SYNC_LINES_NUMBER_ANG_TOL, dSyncLinesAngTol)
-- Recupero le Curve di Sincronizzazione
local nFirstId, nCount
bOk, nFirstId, nCount = EgtTrimmingGetSurfBzSyncPoints( nLayerEditSyncId, vIdEdges[1], vIdEdges[2], dLinTol, dSyncLinesAngTol, nSyncLinesNumber, bShowOnCorners)
if not bOk then
EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Error in Computing Sync Lines', 'Error', 'ERROR', 'OK')
EgtErase( nLayerEditSyncId)
EgtSetCurrPartLayer( nCurrPartId, nCurrLayerId)
return
end
-- Assegno Colore e Name
nId = EgtGetFirstInGroup( nLayerEditSyncId)
while nId do
if nId >= nFirstId then
EgtSetColor( nId, SYNC_LINE_COLOR)
EgtSetName( nId, SYNC_LINE_NAME)
end
nId = EgtGetNext( nId)
end
-- Imposto il gruppo di Edit Corrente
EgtSetCurrPartLayer( nCurrPartId, nLayerEditSyncId)
-- Aggiorno la Grafica
EgtDraw()