-- EditSyncLines.lua by Egalware s.r.l. 2026/05/12 require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- Carico le costanti di Trimming EgtAddToPackagePath( EgtGetSourceDir() .. '?.lua') local GlobVar = require( 'TrimmingLib') -- Costante di Errore local ERROR_ORIENTING_CURVES = 'Error in Edit Orienting 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_ORIENTING_CURVES .. 'Not a valid Trimming Layer', 'Error', 'ERROR', 'OK') return end -- Recupero le Info local dLinTol = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_LIN_TOL, 'd') local dAngTol = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ANG_TOL, 'd') local dAngFaceTol = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_SURF_ANG_TOL, 'd') local bOk = ( dLinTol ~= nil and dAngTol ~= nil and dAngFaceTol ~= nil) if not bOk then EgtOutBox( ERROR_ORIENTING_CURVES .. 'No Trimming Machining created', 'Error', 'ERROR', 'OK') return end -- Creo un nuovo Layer per le Orienting Curves local nLayerEditOrientingId = GlobVar.CreateEditOrientationCurvesLayer( nCurrPartId, nCurrLayerId) if not nLayerEditOrientingId or nLayerEditOrientingId == GDB_ID.NULL then EgtOutBox( ERROR_ORIENTING_CURVES .. 'Error in creating Orienting Layer', 'Error', 'ERROR', 'OK') return end -- Verifico che siano state create le due curve di Bordo, altrimenti Errore local vIdEdges = {} nId = EgtGetFirstInGroup( nCurrLayerId) while nId do -- verifico che sia una Curva e che sia di Bordo if EgtGetName( nId) == MCH_TRIMMING.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_ORIENTING_CURVES .. 'Invalid Border Curves', 'Error', 'ERROR', 'OK') return end table.insert( vIdEdges, nId) end nId = EgtGetNext( nId) end if #vIdEdges ~= 2 then EgtOutBox( ERROR_ORIENTING_CURVES .. 'Not 2 Border Curves detected', 'Error', 'ERROR', 'OK') EgtSetStatus( nCurrLayerId, GDB_ST.ON) EgtErase( nLayerEditOrientingId) return end -- Verifico che ci siano selezionati 3 elementi : 2 Linee di Sincronizzazione e Una Curva di Bordo local nFirstSyncLineId = GDB_ID.NULL local nSecondSyncLineId = GDB_ID.NULL local nBorderMainId = GDB_ID.NULL local nSelObj = EgtGetSelectedObjCount() bOk = ( nSelObj == 3) if bOk then local nId = EgtGetFirstSelectedObj() while bOk and nId do 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 bOk = false else local sName = EgtGetName( nId) if sName == MCH_TRIMMING.EDGES_NAME then nBorderMainId = nId elseif nFirstSyncLineId == GDB_ID.NULL then nFirstSyncLineId = nId else nSecondSyncLineId = nId end end nId = EgtGetNextSelectedObj() end end if not bOk or nFirstSyncLineId == GDB_ID.NULL or nSecondSyncLineId == GDB_ID.NULL or nBorderMainId == GDB_ID.NULL then EgtOutBox( ERROR_ORIENTING_CURVES .. 'Select 2 SyncLines and a Border', 'Error', 'ERROR', 'OK') EgtSetStatus( nCurrLayerId, GDB_ST.ON) EgtErase( nLayerEditOrientingId) return end local nMainEdgeId = GDB_ID.NULL local nOtherEdgeId = GDB_ID.NULL if nBorderMainId == vIdEdges[1] then nMainEdgeId = vIdEdges[1] nOtherEdgeId = vIdEdges[2] elseif nBorderMainId == vIdEdges[2] then nMainEdgeId = vIdEdges[2] nOtherEdgeId = vIdEdges[1] end if nMainEdgeId == GDB_ID.NULL or nOtherEdgeId == GDB_ID.NULL then EgtOutBox( ERROR_ORIENTING_CURVES .. 'Select 2 SyncLines and a Border', 'Error', 'ERROR', 'OK') EgtSetStatus( nCurrLayerId, GDB_ST.ON) EgtErase( nLayerEditOrientingId) end -- Recupero eventuale gruppo contenente le Linee di Sincronizzazione local nLayerSynEditId = GlobVar.GetCurrentEditSyncCurvesLayer( nCurrPartId, nCurrLayerId) if not nLayerSynEditId then nLayerSynEditId = GDB_ID.NULL end -- -- Recupero le Informazioni di Orienting Curves utilizzate precedentemente -- local dThetaStart = ORIENTING_LINES_THETA_START -- local dStoredThetaStart = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_THETA_START, 'd') -- if dStoredThetaStart ~= nil then dThetaStart = dStoredThetaStart end -- local dPhiStart = ORIENTING_LINES_PHI_START -- local dStoredPhiStart = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_PHI_START, 'd') -- if dStoredPhiStart ~= nil then dPhiStart = dStoredPhiStart end -- local dThetaEnd = ORIENTING_LINES_THETA_END -- local dStoredThetaEnd = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_THETA_END, 'd') -- if dStoredThetaEnd ~= nil then dThetaEnd = dStoredThetaEnd end -- local dPhiEnd = ORIENTING_LINES_PHI_END -- local dStoredPhiEnd = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_PHI_END, 'd') -- if dStoredPhiEnd ~= nil then dPhiEnd = dStoredPhiEnd end -- -- come valori di default metto gli angoli delle curve selezionate local vtFirstDir = EgtSV( nFirstSyncLineId) local vtSecondDir = EgtSV( nSecondSyncLineId) -- oriento le direzioni in modo che la direzione delle isocurve di riferimento sia a partire dal bordo selezionato local ptSFirst = EgtSP(nFirstSyncLineId) local ptSSecond = EgtSP(nSecondSyncLineId) if not EgtCurveParamAtPoint( nMainEdgeId, ptSFirst, 10 * GEO.EPS_SMALL) then vtFirstDir = - vtFirstDir end if not EgtCurveParamAtPoint( nMainEdgeId, ptSSecond, 10 * GEO.EPS_SMALL) then vtSecondDir = - vtSecondDir end local dLenS, dThetaStart, dPhiStart = SphericalFromVector( vtFirstDir) local dLenE, dThetaEnd, dPhiEnd = SphericalFromVector( vtSecondDir) local dStartLen = ORIENTING_LINES_START_LEN local dStoredStartLen = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_LINES_START_LEN, 'd') if dStoredStartLen ~= nil then dStartLen = dStoredStartLen end local dEndLen = ORIENTING_LINES_END_LEN local dStoredEndLen = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_LINES_END_LEN, 'd') if dStoredEndLen ~= nil then dEndLen = dStoredEndLen end -- Chiedo i Parametri all'Utente local vsVal = EgtDialogBox( 'Orienting Curves', { 'Vertical Start Angle [0°-180°]', EgtNumToString( dThetaStart)}, { 'Orizontal Start Angle [0°-360°]', EgtNumToString( dPhiStart)}, { 'Vertical End Angle [0°-180°]', EgtNumToString( dThetaEnd)}, { 'Orizontal End Angle [0°-360°]', EgtNumToString( dPhiEnd)}, { 'Smooth Start Length', EgtNumToString( dStartLen)}, { 'Smooth End Length', EgtNumToString( dEndLen)}, { 'Shorter Side', 'CK:1'}) if not vsVal or #vsVal ~= 7 then EgtErase( nLayerEditOrientingId) EgtSetCurrPartLayer( nCurrPartId, nCurrLayerId) return end dThetaStart = tonumber( vsVal[1]) dPhiStart = tonumber( vsVal[2]) dThetaEnd = tonumber( vsVal[3]) dPhiEnd = tonumber( vsVal[4]) dStartLen = tonumber( vsVal[5]) dEndLen = tonumber( vsVal[6]) local bShorterSide = true if vsVal[7] == "0" then bShorterSide = false end EgtSetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_THETA_START, dThetaStart) EgtSetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_PHI_START, dPhiStart) EgtSetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_THETA_END, dThetaEnd) EgtSetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_PHI_END, dPhiEnd) EgtSetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_LINES_START_LEN, dStartLen) EgtSetInfo( nCurrLayerId, MCH_TRIMMING.KEY_ORIENTING_LINES_END_LEN, dEndLen) local sInfoBorder = EgtGetInfo( nMainEdgeId, MCH_TRIMMING.KEY_BORDER_ORDER) if sInfoBorder == nil then EgtOutBox( ORIENTING_LINES_END_LEN .. 'Error : Borders order has not been established', 'Error', 'ERROR', 'OK') EgtErase( nLayerEditOrientingId) EgtSetCurrPartLayer( nCurrPartId, nCurrLayerId) return end local bMainIsFirstBorder = (sInfoBorder == MCH_TRIMMING.KEY_FIRST_BORDER) -- Recupero le Curve di Orienting local nInterpStartId, nStartId, nEndId, nInterpEndId bOk, nInterpStartId, nStartId, nEndId, nInterpEndId = EgtTrimmingGetToolOrientationLines( nLayerEditOrientingId, nMainEdgeId, nOtherEdgeId, bMainIsFirstBorder, nFirstSyncLineId, nSecondSyncLineId, bShorterSide, nLayerSynEditId, dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dStartLen, dEndLen, dLinTol) if not bOk then EgtOutBox( ERROR_ORIENTING_CURVES .. 'Error in Computing Orienting Lines', 'Error', 'ERROR', 'OK') EgtErase( nLayerEditOrientingId) EgtSetCurrPartLayer( nCurrPartId, nCurrLayerId) return end local vtDirS = EgtSV( nFirstSyncLineId) local vtNewDirS = EgtSV( nStartId) local bInvert = vtDirS * vtNewDirS < 0 -- Assegno Colore e Name ( per i Vettori rappresentativi, uso il colore Rosso) local LineColor = ORIENTATION_LINE_COLOR local SpecialLineColor = Color3d( 255, 0, 0) nId = EgtGetFirstInGroup( nLayerEditOrientingId) while nId do if nId == nInterpStartId or nId == nStartId or nId == nEndId or nId == nInterpEndId then EgtSetColor( nId, SpecialLineColor) else EgtSetColor( nId, LineColor) end EgtSetName( nId, MCH_TRIMMING.ORIENTATION_LINE_NAME) if bInvert then EgtInvertCurve(nId) end nId = EgtGetNext( nId) end -- Assegno alle curve di bordo ricavate in precedenza le costanti di riferimento per le lavorazioni di Trimming -- Layer di Trimming Generale ( sempre comune a tutti) EgtSetInfo( vIdEdges[1], MCH_TRIMMING.TR_LAYER, nCurrLayerId) EgtSetInfo( vIdEdges[2], MCH_TRIMMING.TR_LAYER, nCurrLayerId) -- Layer di Orienting ( da aggiungere alla lista) local vOrientingLayerId = EgtGetInfo( vIdEdges[1], MCH_TRIMMING.OR_LAYER, 'vi') if not vOrientingLayerId then vOrientingLayerId = { nLayerEditOrientingId } else table.insert( vOrientingLayerId, nLayerEditOrientingId) end EgtSetInfo( vIdEdges[1], MCH_TRIMMING.OR_LAYER, vOrientingLayerId) EgtSetInfo( vIdEdges[2], MCH_TRIMMING.OR_LAYER, vOrientingLayerId) -- Aggiungo i Vettori rappresentativi -- Interpolation Start local vOrientingISId = EgtGetInfo( vIdEdges[1], MCH_TRIMMING.OR_IS, 'vi') if not vOrientingISId then vOrientingISId = { nInterpStartId} else table.insert( vOrientingISId, nInterpStartId) end EgtSetInfo( vIdEdges[1], MCH_TRIMMING.OR_IS, vOrientingISId) EgtSetInfo( vIdEdges[2], MCH_TRIMMING.OR_IS, vOrientingISId) -- Start local vOrientingSId = EgtGetInfo( vIdEdges[1], MCH_TRIMMING.OR_S, 'vi') if not vOrientingSId then vOrientingSId = { nStartId} else table.insert( vOrientingSId, nStartId) end EgtSetInfo( vIdEdges[1], MCH_TRIMMING.OR_S, vOrientingSId) EgtSetInfo( vIdEdges[2], MCH_TRIMMING.OR_S, vOrientingSId) -- End local vOrientingEId = EgtGetInfo( vIdEdges[1], MCH_TRIMMING.OR_E, 'vi') if not vOrientingEId then vOrientingEId = { nEndId} else table.insert( vOrientingEId, nEndId) end EgtSetInfo( vIdEdges[1], MCH_TRIMMING.OR_E, vOrientingEId) EgtSetInfo( vIdEdges[2], MCH_TRIMMING.OR_E, vOrientingEId) -- Interpolation End local vOrientingIEId = EgtGetInfo( vIdEdges[1], MCH_TRIMMING.OR_IE, 'vi') if not vOrientingIEId then vOrientingIEId = { nInterpEndId} else table.insert( vOrientingIEId, nInterpEndId) end EgtSetInfo( vIdEdges[1], MCH_TRIMMING.OR_IE, vOrientingIEId) EgtSetInfo( vIdEdges[2], MCH_TRIMMING.OR_IE, vOrientingIEId) -- Imposto il gruppo di Edit Corrente EgtSetCurrPartLayer( nCurrPartId, nLayerEditOrientingId) -- Aggiorno la Grafica EgtDraw()