-- InterpolateSyncLines.lua by Egalware s.r.l. 2026/02/18 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 il Layer di Edit local nLayerEditId = GlobVar.GetCurrentEditSyncCurvesLayer( nCurrPartId, nCurrLayerId) if ( not nLayerEditId or nLayerEditId == GDB_ID.NULL) then EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Not a valid Edit mode created', 'Error', 'ERROR', 'OK') return end -- Recupero le Info local dEdgeLinTol = EgtGetInfo( nCurrLayerId, KEY_LIN_TOL_EDGES, 'd') local dEdgeAngTol = EgtGetInfo( nCurrLayerId, KEY_ANG_TOL_EDGES, 'd') local bOk = ( dEdgeLinTol ~= nil and dEdgeAngTol ~= nil) if not bOk then EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'No Trimming Machining created', 'Error', 'ERROR', 'OK') return end -- Recupero le due curve linee di sincronizzazione local nFirstSync = EgtGetFirstSelectedObj() local nSecondSync = EgtGetNextSelectedObj() if not nFirstSync or not nSecondSync or nFirstSync == GDB_ID.NULL or nSecondSync == GDB_ID.NULL then EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Not two Sync Lines Selected', 'Error', 'ERROR', 'OK') return end local nFirstType = EgtGetType( nFirstSync) local nSecondType = EgtGetType( nSecondSync) if nFirstType ~= GDB_TY.CRV_LINE and nFirstSync ~= GDB_TY.CRV_COMPO and nSecondType ~= GDB_TY.CRV_LINE and nSecondType ~= GDB_TY.CRV_COMPO then EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Not two Sync Lines Selected', 'Error', 'ERROR', 'OK') return end -- Recupero le Curve di Bordo presenti nel Layer di Trimming corrente local nId = EgtGetFirstInGroup( nCurrLayerId) local vnBzCrvId = {} while nId do local sName = EgtGetName( nId) if sName == EDGES_NAME then table.insert( vnBzCrvId, nId) end nId = EgtGetNext( nId) end if #vnBzCrvId ~= 2 then EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'No Borders found', 'Error', 'ERROR', 'OK') return end -- Inserisco le linee di Sincronizzazione Interpolate local nFirstId = GDB_ID.NULL local nCount = 0 bOk, nFirstId, nCount = EgtTrimmingInterpolateSyncLines( nLayerEditId, nFirstSync, nSecondSync, vnBzCrvId[1], vnBzCrvId[2], dEdgeLinTol, dEdgeAngTol) if not bOk then EgtOutBox( ERROR_EDIT_SYNC_CURVES .. 'Invalid Interpolation', 'Error', 'ERROR', 'OK') return end -- Cambio il colore alle due Linee di Sincronizzaione selezionate e alle nuove calcolate EgtSetColor( nFirstSync, SYNC_LINE_INTERP_COLOR) EgtSetColor( nSecondSync, SYNC_LINE_INTERP_COLOR) if nFirstId ~= GDB_ID.NULL and nCount > 0 then local vNewIds = {} for i = 0, nCount do EgtSetColor( nFirstId + i, SYNC_LINE_INTERP_COLOR) EgtSetName( nFirstId + i, SYNC_LINE_NAME) table.insert( vNewIds, nFirstId + i) end -- Memorizzo gli Id delle curve inserite EgtSetInfo( nLayerEditId, KEY_SYNC_LINES_INTERPOLATION_IDS, vNewIds) end -- Metto il Focus sul Layer di Sincronizzazione delle curve EgtSetCurrPartLayer( nCurrPartId, nLayerEditId) -- Aggiorno la Grafica EgtDraw()