From 063b0f5cc435016ef9cf09854c09a8a454ec59f5 Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Fri, 15 May 2026 18:03:54 +0200 Subject: [PATCH 1/5] EgtExecutor (5AxTrimming) : - prima versione per Linee di Direzione Utensile. --- EXE_Trimming.cpp | 534 ++++++++++++++++++++++++++++++++++++++++++++++- Lua_Trimming.cpp | 77 +++++++ 2 files changed, 610 insertions(+), 1 deletion(-) diff --git a/EXE_Trimming.cpp b/EXE_Trimming.cpp index 62514b2..ec55512 100644 --- a/EXE_Trimming.cpp +++ b/EXE_Trimming.cpp @@ -16,6 +16,8 @@ #include "DllExchange.h" #include "GeoTools.h" #include "AuxTools.h" +#include "/EgtDev/Include/EGkGeoVector3d.h" +#include "/EgtDev/Include/EGkCurveAux.h" #include "/EgtDev/Include/EgtNumUtils.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EgtPointerOwner.h" @@ -24,9 +26,12 @@ #include "/EgtDev/Include/EGkTrimming.h" #include "/EgtDev/Include/EGkStmFromTriangleSoup.h" #include "/EgtDev/Include/EGkDistPointCurve.h" +#include "/EgtDev/Include/EGkDistPointSurfBz.h" +#include "/EgtDev/Include/EGkSbzFromCurves.h" #include #include + using namespace std ; // --------------------------------------------------------------------------- @@ -867,11 +872,538 @@ ExeTrimmingGetSurfBzSyncPoints( int nParentId, int nEdge1Id, int nEdge2Id, doubl return bOk ; } +// --------------------------------------------------------------------------- +bool +ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEdgeId, int nSyncLayerId, int nLineSId, int nLineEId, + double dThetaStart, double dPhiStart, double dThetaEnd, double dPhiEnd, double dInterpLenS, + double dInterpLenE, double dLinTol, + int& nInterpStartId, int& nStartId, int& nEndId, int& nInterpEndId) +{ + // Verifica database geometrico + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + + // Imposto i parametri di ritorno + nInterpStartId = GDB_ID_NULL, nStartId = GDB_ID_NULL, nEndId = GDB_ID_NULL, nInterpEndId = GDB_ID_NULL ; + + // Se necessario aggiusto le tolleranze + double dMyLinTol = Clamp( dLinTol, EPS_SMALL, 1e5 * EPS_SMALL) ; + const double TOL = dMyLinTol ; + // Definisco costanti per interpolazione + const double INTERPOLATION_DIST = 0.5 ; // alzare + const double ISO_PAR_SAMPLE = 20.0 ; + + // Recupero il riferimento del gruppo di destinazione + Frame3d frDest ; + bool bOk = ( pGeomDB->GetGlobFrame( nParentId, frDest)) ; + + // Recupero le due Curve di bordo + const ICurve* pCrvMainEdge = GetCurve( pGeomDB->GetGeoObj( nMainEdgeId)) ; + const ICurve* pCrvOtherEdge = GetCurve( pGeomDB->GetGeoObj( nOtherEdgeId)) ; + bOk = bOk && ( pCrvMainEdge != nullptr && pCrvMainEdge->IsValid() && pCrvOtherEdge != nullptr && pCrvOtherEdge->IsValid()) ; + + // Verifico che le curve siano entrambe Aperte o entrambe Chiuse e memorizzo il risultato + bOk = bOk && ( pCrvMainEdge->IsClosed() == pCrvOtherEdge->IsClosed()) ; + bool bBorderClosed = ( pCrvMainEdge->IsClosed()) ; + + // Recupero le Linee di Sincronizzazione iniziali e finali e verifico che giacciano sulle Curve di Bordo + ICurve* pCrvSyncS = GetCurve( pGeomDB->GetGeoObj( nLineSId)) ; + ICurve* pCrvSyncE = GetCurve( pGeomDB->GetGeoObj( nLineEId)) ; + bOk = bOk && ( pCrvSyncS != nullptr && pCrvSyncS->IsValid() && pCrvSyncE != nullptr && pCrvSyncE->IsValid()) ; + BIPOINT Line1, Line2 ; + bOk = bOk && ( pCrvSyncS->GetStartPoint( Line1.first)) && ( pCrvSyncS->GetEndPoint( Line1.second)) ; + bOk = bOk && ( pCrvSyncE->GetStartPoint( Line2.first)) && ( pCrvSyncE->GetEndPoint( Line2.second)) ; + // --- se necessario oriento le linee di Sync in modo che inizino entrambe dal Bordo Main + if ( bOk) { + if ( pCrvMainEdge->IsPointOn( Line1.first, TOL)) + bOk = ( pCrvOtherEdge->IsPointOn( Line1.second, TOL)) ; + else if ( pCrvOtherEdge->IsPointOn( Line1.first, TOL)) { + bOk = ( pCrvMainEdge->IsPointOn( Line1.second, TOL)) ; + if ( bOk) { + swap( Line1.first, Line1.second) ; + pCrvSyncS->Invert() ; + } + } + else + bOk = false ; + } + if ( bOk) { + if ( pCrvMainEdge->IsPointOn( Line2.first, TOL)) + bOk = ( pCrvOtherEdge->IsPointOn( Line2.second, TOL)) ; + else if ( pCrvOtherEdge->IsPointOn( Line2.first, TOL)) { + bOk = ( pCrvMainEdge->IsPointOn( Line2.second, TOL)) ; + if ( bOk) { + swap( Line2.first, Line2.second) ; + pCrvSyncE->Invert() ; + } + } + else bOk = false ; + } + // Il percorso selezionato è il minore tra le due possibilità di percorrenza + if ( bOk && bBorderClosed) { + double dParS = 0. ; + PtrOwner pCompoMainCL( ConvertCurveToComposite( pCrvMainEdge->Clone())) ; + bOk = ( ! IsNull( pCompoMainCL) && pCompoMainCL->IsValid() && + pCompoMainCL->GetParamAtPoint( Line1.first, dParS, TOL)) ; + if ( bOk) { + pCompoMainCL->ChangeStartPoint( dParS) ; + double dLenE = 0., dLenMain = 0. ; + bOk = ( pCompoMainCL->GetLengthAtPoint( Line2.first, dLenE, TOL) && + pCompoMainCL->GetLength( dLenMain)) ; + if ( dLenE > dLenMain / 2. + EPS_SMALL) { + swap( Line1, Line2) ; + swap( pCrvSyncS, pCrvSyncE) ; + } + } + } + + // Calcolo la lunghezza delle due curve di Bordo + double dLenMain = 0., dLenOther = 0. ; + bOk = bOk && ( pCrvMainEdge->GetLength( dLenMain) && pCrvOtherEdge->GetLength( dLenOther) && + dLenMain > 2. * TOL + dInterpLenS + dInterpLenE + EPS_SMALL && + dLenOther > 2. * TOL + dInterpLenS + dInterpLenE + EPS_SMALL) ; + + // Recupero i punti di sincronizzazione (se presenti) + BIPNTVECTOR vSyncPoints ; vSyncPoints.reserve( pGeomDB->GetGroupObjs( nSyncLayerId)) ; + int nLineId = pGeomDB->GetFirstInGroup( nSyncLayerId) ; + while ( bOk && nLineId != GDB_ID_NULL) { + // Recupero la Curva + const ICurve* pLine = GetCurve( pGeomDB->GetGeoObj( nLineId)) ; + bOk = bOk && ( pLine != nullptr && pLine->IsValid()) ; + if ( bOk) { + // Recupero gli Estremi + Point3d ptStart ; pLine->GetStartPoint( ptStart) ; + Point3d ptEnd ; pLine->GetEndPoint( ptEnd) ; + // Mi assicuro che gli estremi siano sulle curve di Bordo e orientati correttamente ( nel caso inverto) + double dDistS1 = INFINITO ; + if ( ! DistPointCurve( ptStart, *pCrvMainEdge).GetDist( dDistS1)) { + nLineId = pGeomDB->GetNext( nLineId) ; + continue ; + } + if ( dDistS1 < dLinTol) { + double dDistE2 = INFINITO ; + if ( ! DistPointCurve( ptEnd, *pCrvOtherEdge).GetDist( dDistE2) || dDistE2 > dLinTol) { + nLineId = pGeomDB->GetNext( nLineId) ; + continue ; + } + } + else { + double dDistS2 = INFINITO ; + if ( ! DistPointCurve( ptStart, *pCrvMainEdge).GetDist( dDistS2) || dDistS2 > dLinTol) { + nLineId = pGeomDB->GetNext( nLineId) ; + continue ; + } + double dDistE1 = INFINITO ; + if ( ! DistPointCurve( ptEnd, *pCrvOtherEdge).GetDist( dDistE1) || dDistE1 > dLinTol) { + nLineId = pGeomDB->GetNext( nLineId) ; + continue ; + } + swap( ptStart, ptEnd) ; + } + vSyncPoints.emplace_back( make_pair( ptStart, ptEnd)) ; + } + nLineId = pGeomDB->GetNext( nLineId) ; + } + + // Recupero la superficie Bezier rigata + PtrOwner pSurfBzRuled ; + if ( bOk) { + // Se non ho linee di sincronizzazione + if ( vSyncPoints.empty()) + pSurfBzRuled.Set( GetSurfBezierRuledSmooth( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, ISO_PAR_SAMPLE)) ; + // Se ho linee di sincronizzazione + else + pSurfBzRuled.Set( GetSurfBezierRuledGuided( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, dMyLinTol)) ; + bOk = bOk && ( ! IsNull( pSurfBzRuled) && pSurfBzRuled->IsValid()) ; + } + + // --- Calcolo delle Linee di Orientamento --- + if ( bOk) { + + // Rotazione delle curve di Bordo rispetto al Bordo Main + double dLenS ; pCrvSyncS->GetLength( dLenS) ; + Line1.second = Line1.first + FromSpherical( dLenS, dThetaStart, dPhiStart) ; + double dLenE ; pCrvSyncE->GetLength( dLenE) ; + Line2.second = Line2.first + FromSpherical( dLenE, dThetaEnd, dPhiEnd) ; + + // --- Eventuale Interpolazione Lineare di Raccordo all'Inizio --- + if ( dInterpLenS > TOL) { + double dExtension = dInterpLenS ; + double dLen = -1. ; pCrvMainEdge->GetLengthAtPoint( Line1.first, dLen, TOL) ; + if ( bBorderClosed) { + dLen -= dInterpLenS ; + if ( dLen < EPS_SMALL) + dLen = dLenMain + dLen ; + } + else { + if ( dLen < dInterpLenS - EPS_SMALL) { + dExtension = dLen ; + dLen = 0 ; + } + } + double dU = - 1; + bOk = pCrvMainEdge->GetParamAtLength( dLen, dU) ; + if ( bOk) { + // Definisco la linea si sincronizzazione + Point3d ptInterpS ; double dParU, dParV ; + PtrOwner pCompoIso( nullptr) ; + BIPOINT LineInterpS ; + bOk = ( pCrvMainEdge->GetPointD1D2( dU, ICurve::FROM_MINUS, ptInterpS) && + DistPointSurfBz( ptInterpS, *pSurfBzRuled).GetParamsAtMinDistPoint( dParU, dParV) && + pCompoIso.Set( pSurfBzRuled->GetCurveOnV( dParU)) && + pCompoIso->IsValid() && + pCompoIso->GetStartPoint( LineInterpS.first) && + pCompoIso->GetEndPoint( LineInterpS.second)) ; + if ( bOk) { + bool bFirst = true ; + // Interpolo + double dLenLineInterpS = Dist( LineInterpS.first, LineInterpS.second) ; + double dLenLine1 = Dist( Line1.first, Line1.second) ; + int nStep = max( 1, int( ceil( dExtension / INTERPOLATION_DIST))) ; + Vector3d vtInterpStart = ( LineInterpS.second - LineInterpS.first) ; vtInterpStart.Normalize() ; + Vector3d vtInterpEnd = ( Line1.second - Line1.first) ; vtInterpEnd.Normalize() ; + Vector3d vtDiff = vtInterpEnd - vtInterpStart ; + for ( int i = 0 ; bOk && i < ( nStep - 1) ; ++ i) { // ( nStep - 1) per evitare sovrapposizione con la Copia del vettore + double dI = double( i) ; + Vector3d vtInterp = vtInterpStart + ( dI / ( nStep - 1)) * vtDiff ; + double dUInterpMain = 0. ; Point3d ptInterpOnMain ; + double dCurrLen = dLen + ( dI * dExtension / ( nStep - 1)) ; + if ( dCurrLen > dLenMain) + dCurrLen -= dLenMain ; + bOk = ( pCrvMainEdge->GetParamAtLength( dCurrLen, dUInterpMain) && + pCrvMainEdge->GetPointD1D2( dUInterpMain, ICurve::FROM_MINUS, ptInterpOnMain)) ; + if ( bOk) { + double dMagnitude = dLenLineInterpS + ( dI / ( nStep - 1)) * ( dLenLine1 - dLenLineInterpS) ; + PtrOwner pLine( CreateCurveLine()) ; + bOk = ( ! IsNull( pLine) && pLine->Set( ptInterpOnMain, ptInterpOnMain + vtInterp * dMagnitude)) ; + if ( bOk) { + int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) ; + bOk = ( nNewId != GDB_ID_NULL) ; + if ( bOk) { + if ( bFirst) { + nInterpStartId = nNewId ; + bFirst = false ; + } + } + } + } + } + } + } + } + + // --- Interpolazione tra le due Linee di Sincronizzazione --- + if ( bOk) { + double dLenS = -1., dLenE = -1 ; + bOk = ( pCrvMainEdge->GetLengthAtPoint( Line1.first, dLenS, TOL) && + pCrvMainEdge->GetLengthAtPoint( Line2.first, dLenE, TOL)) ; + if ( bOk) { + double dToTDist = 0. ; + if ( dLenS < dLenE) + dToTDist = dLenE - dLenS ; + else + dToTDist = ( dLenMain - dLenS) + dLenE ; + if ( dToTDist > TOL) { + bool bFirst = true ; + // Interpolo + double dLenLine1 = Dist( Line1.first, Line1.second) ; + double dLenLine2 = Dist( Line2.first, Line2.second) ; + int nStep = max( 1, int( ceil( dToTDist / INTERPOLATION_DIST))) ; + Vector3d vtLineS = ( Line1.second - Line1.first) ; vtLineS.Normalize() ; + Vector3d vtLineE = ( Line2.second - Line2.first) ; vtLineE.Normalize() ; + Vector3d vtDiff = ( vtLineE - vtLineS) ; + for ( int i = 0 ; bOk && i <= nStep ; ++ i) { + double dI = double( i) ; + Vector3d vtInterp = vtLineS + ( dI / nStep) * vtDiff ; + double dUInterpMain = 0. ; Point3d ptInterpOnMain ; + double dCurrLen = dLenS + ( dI * dToTDist / nStep) ; + if ( dCurrLen > dLenMain) + dCurrLen -= dLenMain ; + bOk = ( pCrvMainEdge->GetParamAtLength( dCurrLen, dUInterpMain) && + pCrvMainEdge->GetPointD1D2( dUInterpMain, ICurve::FROM_MINUS, ptInterpOnMain)) ; + if ( bOk) { + double dMagnitude = dLenLine1 + ( dI / nStep) * ( dLenLine2 - dLenLine1) ; + PtrOwner pLine( CreateCurveLine()) ; + bOk = ( ! IsNull( pLine) && pLine->Set( ptInterpOnMain, ptInterpOnMain + vtInterp * dMagnitude)) ; + if ( bOk) { + int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) ; + bOk = ( nNewId != GDB_ID_NULL) ; + if ( bOk) { + if ( bFirst) { + nStartId = nNewId ; + bFirst = false ; + } + nEndId = nNewId ; + } + } + } + } + } + } + } + + // --- Eventuale Interpolazione Lineare di Raccordo alla Fine --- + if ( bOk && dInterpLenE > TOL) { + double dExtension = dInterpLenE ; + double dLen = -1. ; pCrvMainEdge->GetLengthAtPoint( Line2.first, dLen, TOL) ; + if ( bBorderClosed) { + dLen += dInterpLenE ; + if ( dLen > dLenMain - EPS_SMALL) + dLen -= dLenMain ; + } + else { + if ( dLen > dLenMain - dInterpLenE - EPS_SMALL) { + dExtension = dLenMain - dLen ; + dLen = dLenMain ; + } + } + double dU = - 1 ; + bOk = pCrvMainEdge->GetParamAtLength( dLen, dU) ; + if ( bOk) { + // Definisco la linea si sincronizzazione + Point3d ptInterpE ; double dParU, dParV ; + PtrOwner pCompoIso( nullptr) ; + BIPOINT LineInterpE ; + bOk = ( pCrvMainEdge->GetPointD1D2( dU, ICurve::FROM_MINUS, ptInterpE) && + DistPointSurfBz( ptInterpE, *pSurfBzRuled).GetParamsAtMinDistPoint( dParU, dParV) && + pCompoIso.Set( pSurfBzRuled->GetCurveOnV( dParU)) && + pCompoIso->IsValid() && + pCompoIso->GetStartPoint( LineInterpE.first) && + pCompoIso->GetEndPoint( LineInterpE.second)) ; + if ( bOk) { + // Interpolo + double dLenLineInterpE = Dist( LineInterpE.first, LineInterpE.second) ; + double dLenLine2 = Dist( Line2.first, Line2.second) ; + int nStep = max( 1, int( ceil( dExtension / INTERPOLATION_DIST))) ; + Vector3d vtInterpStart = ( Line2.second - Line2.first) ; vtInterpStart.Normalize() ; + Vector3d vtInterpEnd = ( LineInterpE.second - LineInterpE.first) ; vtInterpEnd.Normalize() ; + Vector3d vtDiff = vtInterpEnd - vtInterpStart ; + for ( int i = 1 ; bOk && i < nStep ; ++ i) { // i = 1 per evitare la sopvrapposizione con la Copia del vettore + double dI = double( i) ; + Vector3d vtInterp = vtInterpStart + ( dI / ( nStep - 1)) * vtDiff ; + double dUInterpMain = 0. ; Point3d ptInterpOnMain ; + double dCurrLen = ( dLen - dExtension) + ( dI * dExtension / ( nStep - 1)) ; + if ( dCurrLen > dLenMain) + dCurrLen -= dLenMain ; + bOk = ( pCrvMainEdge->GetParamAtLength( dCurrLen, dUInterpMain) && + pCrvMainEdge->GetPointD1D2( dUInterpMain, ICurve::FROM_MINUS, ptInterpOnMain)) ; + if ( bOk) { + double dMagnitude = dLenLine2 + ( dI / ( nStep - 1)) * ( dLenLineInterpE - dLenLine2) ; + PtrOwner pLine( CreateCurveLine()) ; + bOk = ( ! IsNull( pLine) && pLine->Set( ptInterpOnMain, ptInterpOnMain + vtInterp * dMagnitude)) ; + if ( bOk) { + int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) ; + bOk = ( nNewId != GDB_ID_NULL) ; + if ( bOk) + nInterpEndId = nNewId ; + } + } + } + } + } + } + } + + ExeSetModified() ; + // Se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTrimmingGetToolOrientationLines(" + ToString( nParentId) + "," + + ToString( nMainEdgeId) + "," + + ToString( nOtherEdgeId) + "," + + ToString( nLineSId) + "," + + ToString( nLineEId) + "," + + ToString( dThetaStart) + "," + + ToString( dPhiStart) + "," + + ToString( dThetaEnd) + "," + + ToString( dPhiEnd) + "," + + ToString( dLinTol) + "," + + ToString( dInterpLenS) + "," + + ToString( dInterpLenE) + "," + + " -- bOk=" + ToString( bOk) + + " -- nInterpStartId=" + ToString( nInterpStartId) + ", nStartId=" + ToString( nStartId) + + ", nEndId=" + ToString( nEndId) + ", nInterpEndId=" + ToString( nInterpEndId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + + return bOk ; +} + +// --------------------------------------------------------------------------- +struct TrimmingInterval { + double dLenStart ; + double dLenEnd ; + Vector3d vtStart ; + Vector3d vtEnd ; + TrimmingInterval() + : dLenStart( - EPS_SMALL), dLenEnd( - EPS_SMALL), vtStart( V_INVALID), vtEnd( V_INVALID) {} ; + TrimmingInterval( double dLenS, double dLenE, const Vector3d& vtS, const Vector3d& vtE) + : dLenStart( dLenS), dLenEnd( dLenE), vtStart( vtS), vtEnd( vtE) {} ; +} ; +typedef vector TRIMMINGINTERVALVECTOR ; +// --------------------------------------------------------------------------- +bool +GetTrimmingInterval( const IGeomDB* pGeomDB, const ICurveComposite* pCompo, const Frame3d& frCompo, int nIdS, int nIdE, TrimmingInterval& TrimmingInt) +{ + // Verifico validità dei parametri + VERIFY_GEOMDB( pGeomDB, false) + if ( pCompo == nullptr || ! pCompo->IsValid() || ! frCompo.IsValid()) + return false ; + + // Recupero le linee di Orienting + const ICurve* pGeoCrvS = GetCurve( pGeomDB->GetGeoObj( nIdS)) ; + const ICurve* pGeoCrvE = GetCurve( pGeomDB->GetGeoObj( nIdE)) ; + if ( pGeoCrvS != nullptr && pGeoCrvE != nullptr && pGeoCrvS->IsValid() && pGeoCrvE->IsValid()) { + // Recupero i punti base e i vettori direzioni ( sono ICurveLine*, ma le tratto come ICurve* generiche) + Point3d ptS = P_INVALID ; pGeoCrvS->GetStartPoint( ptS) ; // Line1.ptStart + Point3d ptE = P_INVALID ; pGeoCrvE->GetStartPoint( ptE) ; // Line2.ptStart + Vector3d vtS = V_INVALID ; pGeoCrvS->GetStartDir( vtS) ; // Line1.vtStart + Vector3d vtE = V_INVALID ; pGeoCrvE->GetStartDir( vtE) ; // Line2.vtStart + if ( ptS.IsValid() && ptE.IsValid() && vtS.IsValid() && vtE.IsValid()) { + // Recupero il Frame delle Linee + Frame3d frCrv1, frCrv2 ; + if ( ! pGeomDB->GetGlobFrame( nIdS, frCrv1) || ! pGeomDB->GetGlobFrame( nIdE, frCrv2)) + return false ; + // Porto Tali valori nel riferimento dalla Composita + Point3d ptSLoc = GetLocToLoc( ptS, frCrv1, frCompo) ; + Point3d ptELoc = GetLocToLoc( ptE, frCrv2, frCompo) ; + Vector3d vtSLoc = GetLocToLoc( vtS, frCrv1, frCompo) ; + Vector3d vtELoc = GetLocToLoc( vtE, frCrv2, frCompo) ; + // Recupero il parametro sulla curva + double dParS = - EPS_PARAM, dParE = - EPS_PARAM ; + int nFlag = 0 ; + if ( DistPointCurve( ptSLoc, *pCompo).GetParamAtMinDistPoint( EPS_SMALL, dParS, nFlag) && + DistPointCurve( ptELoc, *pCompo).GetParamAtMinDistPoint( EPS_SMALL, dParE, nFlag)) { + // Recupero la lunghezza su tale curva + double dLenS = - EPS_SMALL, dLenE = - EPS_SMALL ; + if ( pCompo->GetLengthAtParam( dParS, dLenS) && pCompo->GetLengthAtParam( dParE, dLenE)) { + TrimmingInt = TrimmingInterval( dLenS, dLenE, vtSLoc, vtELoc) ; + return true ; + } + } + } + } + + return false ; +} +// --------------------------------------------------------------------------- +bool +Exe5AxTrimmingModifyToolDir( int nCrvId, int nPathId, int nTrimLayId, const INTVECTOR& vnOrientingId, const INTVECTOR& vnOrientingISId, + const INTVECTOR& vnOrientingSId, const INTVECTOR& vnOrientingEId, const INTVECTOR& vnOrientingIEId) +{ + // Verifica database geometrico + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + + // Verifico validità dei parametri + bool bOk = ( nCrvId != GDB_ID_NULL && nPathId != GDB_ID_NULL && nTrimLayId != GDB_ID_NULL && + ssize( vnOrientingId) == ssize( vnOrientingISId) && ssize( vnOrientingISId) == ssize( vnOrientingSId) && + ssize( vnOrientingSId) == ssize( vnOrientingEId) && ssize( vnOrientingEId) == ssize( vnOrientingIEId)) ; + + // Recupero la curva di Bordo e la sua composit associata + const ICurve* pCrvBorder = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ; + bOk = bOk && ( pCrvBorder != nullptr && pCrvBorder->IsValid()) ; + PtrOwner pCompoBorder( nullptr) ; + if ( bOk) + bOk = ( pCompoBorder.Set( ConvertCurveToComposite( pCrvBorder->Clone())) && pCompoBorder->IsValid()) ; + double dLen = - EPS_SMALL ; + if ( bOk) + bOk = pCompoBorder->GetLength( dLen) ; + + // Recupero il Frame della curva corrente + Frame3d frCompo ; + bOk = bOk && ( pGeomDB->GetGlobFrame( nCrvId, frCompo)) ; + + // Recupero i versori di interpolazione e creo dei gruppi + TRIMMINGINTERVALVECTOR vInterval ; vInterval.reserve( 3 * ssize( vnOrientingId)) ; + for ( int i = 0 ; bOk && i < ssize( vnOrientingId) ; ++ i) { + // Se presente Interpolazione iniziale + if ( vnOrientingISId[i] != GDB_ID_NULL && vnOrientingSId[i] != GDB_ID_NULL) { + TrimmingInterval myTrimInt ; + if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingISId[i], vnOrientingSId[i], myTrimInt)) + vInterval.emplace_back( myTrimInt) ; + } + // Interpolazione ( deve essere sempre presente, ma per scrupolo si controlla lo stesso) + if ( vnOrientingSId[i] != GDB_ID_NULL && vnOrientingEId[i] != GDB_ID_NULL) { + TrimmingInterval myTrimInt ; + if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingSId[i], vnOrientingEId[i], myTrimInt)) + vInterval.emplace_back( myTrimInt) ; + } + // Se presente Interpolazione finale + if ( vnOrientingEId[i] != GDB_ID_NULL && vnOrientingIEId[i] != GDB_ID_NULL) { + TrimmingInterval myTrimInt ; + if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingEId[i], vnOrientingIEId[i], myTrimInt)) + vInterval.emplace_back( myTrimInt) ; + } + } + + // Se ho degli intervalli di Interpolazione + if ( ! vInterval.empty()) { + // Scorro i vettori presenti nel Layer ausiliario della lavorazione + int nId = pGeomDB->GetFirstInGroup( nPathId) ; + while ( bOk && nId != GDB_ID_NULL) { + IGeoVector3d* vGeo = GetGeoVector3d( pGeomDB->GetGeoObj( nId)) ; + if ( vGeo != nullptr && vGeo->IsValid()) { + // Recupero i parametri di tale vettore + Point3d ptBase = vGeo->GetBase() ; + Vector3d vtDirV = V_INVALID ; ; + if ( pGeomDB->GetInfo( nId, "DirV", vtDirV) && vtDirV.IsValid()) { + // Recupero la lunghezza associata al Punto di Base sulla Compo + double dCurrPar = - EPS_SMALL ; + int nFlag = 0 ; + if ( DistPointCurve( ptBase, *pCompoBorder).GetParamAtMinDistPoint( 0., dCurrPar, nFlag)) { + double dCurrLen = - EPS_SMALL ; + if ( pCompoBorder->GetLengthAtParam( dCurrPar, dCurrLen)) { + for ( const TrimmingInterval& CurrInterval : vInterval) { + // Controlli per Intervalli a cavallo dei punti iniziali e finali della curva + double dLenA = CurrInterval.dLenStart ; + double dLenB = CurrInterval.dLenEnd ; + double dLenC = dCurrLen ; + if ( dLenA > dLenB) { + dLenB += dLen ; + if ( dLenC < CurrInterval.dLenStart - EPS_SMALL) + dLenC += dLen ; + } + // Se l'intervallo non è troppo piccolo e se sono all'interno di tale Intervallo + if ( dLenB - dLenA > 10. * EPS_SMALL && /* bastava anche 2 * EPS_SMALL */ + dLenA + EPS_SMALL < dLenC && dLenC < dLenB + EPS_SMALL /* estremi esclusi, va bene ? */) { + // Media pesata dei due vettori + double dMeanPar = ( dLenC - dLenA) / ( dLenB - dLenA) ; + Vector3d vtMean = Media( CurrInterval.vtStart, CurrInterval.vtEnd, dMeanPar) ; + // Assegno la Info a tale vettore + pGeomDB->SetInfo( nId, "DirV", vtMean) ; + break ; // non controllo altri intervalli + } + } + } + } + } + } + nId = pGeomDB->GetNext( nId) ; + } + } + + ExeSetModified() ; + // Se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTrimmingGetToolOrientationLines(" + ToString( nCrvId) + "," + + ToString( nPathId) + "," + + ToString( nTrimLayId) + "," + + ToString( vnOrientingId) + "," + + ToString( vnOrientingISId) + "," + + ToString( vnOrientingSId) + "," + + ToString( vnOrientingEId) + "," + + ToString( vnOrientingIEId) + "," + + " -- bOk=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + + return bOk ; +} + // --------------------------------------------------------------------------- int ExeRegolarizeSurfaceLocally( int nParentId, int nSurfId, int nSyncStartId, int nSyncEndId, double dLinTol, int nType) { - bool bOk = true ; // Verifica database geometrico IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) diff --git a/Lua_Trimming.cpp b/Lua_Trimming.cpp index 8f24b60..657fef5 100644 --- a/Lua_Trimming.cpp +++ b/Lua_Trimming.cpp @@ -283,6 +283,80 @@ LuaTrimmingGetSurfBzSyncPoints( lua_State* L) return 3 ; } +//------------------------------------------------------------------------------- +static int +LuaTrimmingGetToolOrientationLines( lua_State* L) +{ + // 13 parametri : nParentId, nMainEdgeId, nOtherEdgeId, nSyncLayerId, nLineSId, nLineEId, + // dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nMainEdgeId ; + LuaCheckParam( L, 2, nMainEdgeId) + int nOtherEdgeId ; + LuaCheckParam( L, 3, nOtherEdgeId) + int nLineSId ; + LuaCheckParam( L, 4, nLineSId) + int nLineEId ; + LuaCheckParam( L, 5, nLineEId) + int nSyncLayerId ; + LuaCheckParam( L, 6, nSyncLayerId) + double dThetaStart ; + LuaCheckParam( L, 7, dThetaStart) + double dPhiStart ; + LuaCheckParam( L, 8, dPhiStart) + double dThetaEnd ; + LuaCheckParam( L, 9, dThetaEnd) + double dPhiEnd ; + LuaCheckParam( L, 10, dPhiEnd) ; + double dInterpLenS ; + LuaCheckParam( L, 11, dInterpLenS) + double dInterpLenE ; + LuaCheckParam( L, 12, dInterpLenE) + double dLinTol ; + LuaCheckParam( L, 13, dLinTol) + LuaClearStack( L) ; + // Inserisco i tratti lineari associati calcolati lungo il percorso + int nInterpStartId = GDB_ID_NULL, nStartId = GDB_ID_NULL, nEndId = GDB_ID_NULL, nInterpEndId = GDB_ID_NULL ; + bool bOk = ExeTrimmingGetToolOrientationLines( nParentId, nMainEdgeId, nOtherEdgeId, nSyncLayerId, nLineSId, nLineEId, + dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol, + nInterpStartId, nStartId, nEndId, nInterpEndId) ; + LuaSetParam( L, bOk) ; + LuaSetParam( L, nInterpStartId) ; + LuaSetParam( L, nStartId) ; + LuaSetParam( L, nEndId) ; + LuaSetParam( L, nInterpEndId) ; + return 5 ; +} + +//------------------------------------------------------------------------------- +static int +Lua5AxTrimmingModifyToolDir( lua_State* L) +{ + // 8 parametri : nCrvId, nAuxId, nTrimLayId, vnOrientingId, vnOrientingISId, vnOrientingSId, vnOrientingEId, vnOrientingIEId + int nCrvId ; + LuaCheckParam( L, 1, nCrvId) + int nPathId ; + LuaCheckParam( L, 2, nPathId) + int nTrimLayId ; + LuaCheckParam( L, 3, nTrimLayId) + INTVECTOR vnOrientingId ; + LuaCheckParam( L, 4, vnOrientingId) + INTVECTOR vnOrientingISId ; + LuaCheckParam( L, 5, vnOrientingISId) + INTVECTOR vnOrientingSId ; + LuaCheckParam( L, 6, vnOrientingSId) + INTVECTOR vnOrientingEId ; + LuaCheckParam( L, 7, vnOrientingEId) + INTVECTOR vnOrientingIEId ; + LuaCheckParam( L, 8, vnOrientingIEId) ; + LuaClearStack( L) ; + // Modifico le Direzioni utensile + bool bOk = Exe5AxTrimmingModifyToolDir( nCrvId, nPathId, nTrimLayId, vnOrientingId, vnOrientingISId, vnOrientingSId, vnOrientingEId, vnOrientingIEId) ; + LuaSetParam( L, bOk) ; + return true ; +} + //------------------------------------------------------------------------------- static int LuaRegolarizeSurfaceLocally( lua_State* L) @@ -324,6 +398,9 @@ LuaInstallTrimming( LuaMgr& luaMgr) // --- Recupero linee di sincronizzazione bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingInterpolateSyncLines", LuaTrimmingInterpolateSyncLines) ; bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingGetSurfBzSyncPoints", LuaTrimmingGetSurfBzSyncPoints) ; + // --- Recupero linee di Orientamento dell'Utensile e Modifica della lavorazione 5Ax + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingGetToolOrientationLines", LuaTrimmingGetToolOrientationLines) ; + bOk = bOk && luaMgr.RegisterFunction( "Egt5AxTrimmingModifyToolDir", Lua5AxTrimmingModifyToolDir) ; // --- Modifica della superficie bOk = bOk && luaMgr.RegisterFunction( "EgtRegolarizeSurfaceLocally", LuaRegolarizeSurfaceLocally) ; return bOk ; From edb45ce149006c659561cd8eaac3d207e9316348 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Mon, 18 May 2026 17:12:14 +0200 Subject: [PATCH 2/5] EgtExecutor : - piccola correzione. --- EXE_Trimming.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXE_Trimming.cpp b/EXE_Trimming.cpp index ec55512..232fa8e 100644 --- a/EXE_Trimming.cpp +++ b/EXE_Trimming.cpp @@ -907,8 +907,8 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd bool bBorderClosed = ( pCrvMainEdge->IsClosed()) ; // Recupero le Linee di Sincronizzazione iniziali e finali e verifico che giacciano sulle Curve di Bordo - ICurve* pCrvSyncS = GetCurve( pGeomDB->GetGeoObj( nLineSId)) ; - ICurve* pCrvSyncE = GetCurve( pGeomDB->GetGeoObj( nLineEId)) ; + PtrOwner pCrvSyncS( GetCurve( pGeomDB->GetGeoObj( nLineSId))->Clone()) ; + PtrOwner pCrvSyncE( GetCurve( pGeomDB->GetGeoObj( nLineEId))->Clone()) ; bOk = bOk && ( pCrvSyncS != nullptr && pCrvSyncS->IsValid() && pCrvSyncE != nullptr && pCrvSyncE->IsValid()) ; BIPOINT Line1, Line2 ; bOk = bOk && ( pCrvSyncS->GetStartPoint( Line1.first)) && ( pCrvSyncS->GetEndPoint( Line1.second)) ; From 56973037ab2b3173e7f13d46a36dcc7d856ec89e Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Tue, 19 May 2026 15:35:25 +0200 Subject: [PATCH 3/5] EgtExecutor : - piccole correzioni e migliorie a trimming. --- EXE_Trimming.cpp | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/EXE_Trimming.cpp b/EXE_Trimming.cpp index 232fa8e..998ee3e 100644 --- a/EXE_Trimming.cpp +++ b/EXE_Trimming.cpp @@ -974,7 +974,7 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd // Recupero gli Estremi Point3d ptStart ; pLine->GetStartPoint( ptStart) ; Point3d ptEnd ; pLine->GetEndPoint( ptEnd) ; - // Mi assicuro che gli estremi siano sulle curve di Bordo e orientati correttamente ( nel caso inverto) + // Mi assicuro che gli estremi siano sulle curve di Bordo ( in un verso o nell'altro, mantengo il verso) double dDistS1 = INFINITO ; if ( ! DistPointCurve( ptStart, *pCrvMainEdge).GetDist( dDistS1)) { nLineId = pGeomDB->GetNext( nLineId) ; @@ -989,16 +989,15 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd } else { double dDistS2 = INFINITO ; - if ( ! DistPointCurve( ptStart, *pCrvMainEdge).GetDist( dDistS2) || dDistS2 > dLinTol) { + if ( ! DistPointCurve( ptStart, *pCrvOtherEdge).GetDist( dDistS2) || dDistS2 > dLinTol) { nLineId = pGeomDB->GetNext( nLineId) ; continue ; } double dDistE1 = INFINITO ; - if ( ! DistPointCurve( ptEnd, *pCrvOtherEdge).GetDist( dDistE1) || dDistE1 > dLinTol) { + if ( ! DistPointCurve( ptEnd, *pCrvMainEdge).GetDist( dDistE1) || dDistE1 > dLinTol) { nLineId = pGeomDB->GetNext( nLineId) ; continue ; } - swap( ptStart, ptEnd) ; } vSyncPoints.emplace_back( make_pair( ptStart, ptEnd)) ; } @@ -1242,7 +1241,7 @@ struct TrimmingInterval { typedef vector TRIMMINGINTERVALVECTOR ; // --------------------------------------------------------------------------- bool -GetTrimmingInterval( const IGeomDB* pGeomDB, const ICurveComposite* pCompo, const Frame3d& frCompo, int nIdS, int nIdE, TrimmingInterval& TrimmingInt) +GetTrimmingInterval( const IGeomDB* pGeomDB, const ICurveComposite* pCompo, const Frame3d& frCompo, int nIdS, int nIdE, bool bInvert, TrimmingInterval& TrimmingInt) { // Verifico validità dei parametri VERIFY_GEOMDB( pGeomDB, false) @@ -1253,9 +1252,17 @@ GetTrimmingInterval( const IGeomDB* pGeomDB, const ICurveComposite* pCompo, cons const ICurve* pGeoCrvS = GetCurve( pGeomDB->GetGeoObj( nIdS)) ; const ICurve* pGeoCrvE = GetCurve( pGeomDB->GetGeoObj( nIdE)) ; if ( pGeoCrvS != nullptr && pGeoCrvE != nullptr && pGeoCrvS->IsValid() && pGeoCrvE->IsValid()) { - // Recupero i punti base e i vettori direzioni ( sono ICurveLine*, ma le tratto come ICurve* generiche) - Point3d ptS = P_INVALID ; pGeoCrvS->GetStartPoint( ptS) ; // Line1.ptStart - Point3d ptE = P_INVALID ; pGeoCrvE->GetStartPoint( ptE) ; // Line2.ptStart + // Recupero i punti base ches stanno sulla pCompo e i vettori direzioni ( sono ICurveLine*, ma le tratto come ICurve* generiche) + Point3d ptS = P_INVALID ; + Point3d ptE = P_INVALID ; + if ( ! bInvert) { + pGeoCrvS->GetStartPoint( ptS) ; // Line1.ptStart + pGeoCrvE->GetStartPoint( ptE) ; // Line2.ptStart + } + else { + pGeoCrvS->GetEndPoint( ptS) ; + pGeoCrvE->GetEndPoint( ptE) ; + } Vector3d vtS = V_INVALID ; pGeoCrvS->GetStartDir( vtS) ; // Line1.vtStart Vector3d vtE = V_INVALID ; pGeoCrvE->GetStartDir( vtE) ; // Line2.vtStart if ( ptS.IsValid() && ptE.IsValid() && vtS.IsValid() && vtE.IsValid()) { @@ -1313,25 +1320,34 @@ Exe5AxTrimmingModifyToolDir( int nCrvId, int nPathId, int nTrimLayId, const INTV Frame3d frCompo ; bOk = bOk && ( pGeomDB->GetGlobFrame( nCrvId, frCompo)) ; + bool bInvert = false ; + if ( ssize( vnOrientingISId) > 0 && vnOrientingISId[0] != GDB_ID_NULL) { + const ICurve* pGeoCrvS = GetCurve( pGeomDB->GetGeoObj( vnOrientingISId[0])) ; + Point3d ptS ; pGeoCrvS->GetStartPoint( ptS) ; + double dDist = 1 ; + if ( DistPointCurve( ptS, *pCompoBorder).GetDist( dDist) && dDist > EPS_SMALL) + bInvert = true ; + } + // Recupero i versori di interpolazione e creo dei gruppi TRIMMINGINTERVALVECTOR vInterval ; vInterval.reserve( 3 * ssize( vnOrientingId)) ; for ( int i = 0 ; bOk && i < ssize( vnOrientingId) ; ++ i) { // Se presente Interpolazione iniziale if ( vnOrientingISId[i] != GDB_ID_NULL && vnOrientingSId[i] != GDB_ID_NULL) { TrimmingInterval myTrimInt ; - if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingISId[i], vnOrientingSId[i], myTrimInt)) + if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingISId[i], vnOrientingSId[i], bInvert, myTrimInt)) vInterval.emplace_back( myTrimInt) ; } // Interpolazione ( deve essere sempre presente, ma per scrupolo si controlla lo stesso) if ( vnOrientingSId[i] != GDB_ID_NULL && vnOrientingEId[i] != GDB_ID_NULL) { TrimmingInterval myTrimInt ; - if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingSId[i], vnOrientingEId[i], myTrimInt)) + if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingSId[i], vnOrientingEId[i], bInvert, myTrimInt)) vInterval.emplace_back( myTrimInt) ; } // Se presente Interpolazione finale if ( vnOrientingEId[i] != GDB_ID_NULL && vnOrientingIEId[i] != GDB_ID_NULL) { TrimmingInterval myTrimInt ; - if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingEId[i], vnOrientingIEId[i], myTrimInt)) + if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingEId[i], vnOrientingIEId[i], bInvert, myTrimInt)) vInterval.emplace_back( myTrimInt) ; } } From a2c87979307fb1dd8e0877ed15b54d912e621d11 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Tue, 19 May 2026 17:31:07 +0200 Subject: [PATCH 4/5] EgtExecutor : - gestito l'ordine delle curve di bordo nella TrimmingGetToolOrientationLines. --- EXE_Trimming.cpp | 24 +++++++++++++++++------- Lua_Trimming.cpp | 26 ++++++++++++++------------ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/EXE_Trimming.cpp b/EXE_Trimming.cpp index 998ee3e..d63a883 100644 --- a/EXE_Trimming.cpp +++ b/EXE_Trimming.cpp @@ -874,7 +874,7 @@ ExeTrimmingGetSurfBzSyncPoints( int nParentId, int nEdge1Id, int nEdge2Id, doubl // --------------------------------------------------------------------------- bool -ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEdgeId, int nSyncLayerId, int nLineSId, int nLineEId, +ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEdgeId, bool bMainIsFirstBorder, int nSyncLayerId, int nLineSId, int nLineEId, double dThetaStart, double dPhiStart, double dThetaEnd, double dPhiEnd, double dInterpLenS, double dInterpLenE, double dLinTol, int& nInterpStartId, int& nStartId, int& nEndId, int& nInterpEndId) @@ -1007,12 +1007,22 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd // Recupero la superficie Bezier rigata PtrOwner pSurfBzRuled ; if ( bOk) { - // Se non ho linee di sincronizzazione - if ( vSyncPoints.empty()) - pSurfBzRuled.Set( GetSurfBezierRuledSmooth( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, ISO_PAR_SAMPLE)) ; - // Se ho linee di sincronizzazione - else - pSurfBzRuled.Set( GetSurfBezierRuledGuided( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, dMyLinTol)) ; + if ( bMainIsFirstBorder) { + // Se non ho linee di sincronizzazione + if ( vSyncPoints.empty()) + pSurfBzRuled.Set( GetSurfBezierRuledSmooth( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, ISO_PAR_SAMPLE)) ; + // Se ho linee di sincronizzazione + else + pSurfBzRuled.Set( GetSurfBezierRuledGuided( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, dMyLinTol)) ; + } + else { + // Se non ho linee di sincronizzazione + if ( vSyncPoints.empty()) + pSurfBzRuled.Set( GetSurfBezierRuledSmooth( pCrvOtherEdge, pCrvMainEdge, vSyncPoints, ISO_PAR_SAMPLE)) ; + // Se ho linee di sincronizzazione + else + pSurfBzRuled.Set( GetSurfBezierRuledGuided( pCrvOtherEdge, pCrvMainEdge, vSyncPoints, dMyLinTol)) ; + } bOk = bOk && ( ! IsNull( pSurfBzRuled) && pSurfBzRuled->IsValid()) ; } diff --git a/Lua_Trimming.cpp b/Lua_Trimming.cpp index 657fef5..a12aad1 100644 --- a/Lua_Trimming.cpp +++ b/Lua_Trimming.cpp @@ -287,7 +287,7 @@ LuaTrimmingGetSurfBzSyncPoints( lua_State* L) static int LuaTrimmingGetToolOrientationLines( lua_State* L) { - // 13 parametri : nParentId, nMainEdgeId, nOtherEdgeId, nSyncLayerId, nLineSId, nLineEId, + // 14 parametri : nParentId, nMainEdgeId, nOtherEdgeId, bMainIsFirstBorder, nSyncLayerId, nLineSId, nLineEId, // dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol int nParentId ; LuaCheckParam( L, 1, nParentId) @@ -295,30 +295,32 @@ LuaTrimmingGetToolOrientationLines( lua_State* L) LuaCheckParam( L, 2, nMainEdgeId) int nOtherEdgeId ; LuaCheckParam( L, 3, nOtherEdgeId) + bool bMainIsFirstBorder ; + LuaCheckParam( L, 4, bMainIsFirstBorder) int nLineSId ; - LuaCheckParam( L, 4, nLineSId) + LuaCheckParam( L, 5, nLineSId) int nLineEId ; - LuaCheckParam( L, 5, nLineEId) + LuaCheckParam( L, 6, nLineEId) int nSyncLayerId ; - LuaCheckParam( L, 6, nSyncLayerId) + LuaCheckParam( L, 7, nSyncLayerId) double dThetaStart ; - LuaCheckParam( L, 7, dThetaStart) + LuaCheckParam( L, 8, dThetaStart) double dPhiStart ; - LuaCheckParam( L, 8, dPhiStart) + LuaCheckParam( L, 9, dPhiStart) double dThetaEnd ; - LuaCheckParam( L, 9, dThetaEnd) + LuaCheckParam( L, 10, dThetaEnd) double dPhiEnd ; - LuaCheckParam( L, 10, dPhiEnd) ; + LuaCheckParam( L, 11, dPhiEnd) ; double dInterpLenS ; - LuaCheckParam( L, 11, dInterpLenS) + LuaCheckParam( L, 12, dInterpLenS) double dInterpLenE ; - LuaCheckParam( L, 12, dInterpLenE) + LuaCheckParam( L, 13, dInterpLenE) double dLinTol ; - LuaCheckParam( L, 13, dLinTol) + LuaCheckParam( L, 14, dLinTol) LuaClearStack( L) ; // Inserisco i tratti lineari associati calcolati lungo il percorso int nInterpStartId = GDB_ID_NULL, nStartId = GDB_ID_NULL, nEndId = GDB_ID_NULL, nInterpEndId = GDB_ID_NULL ; - bool bOk = ExeTrimmingGetToolOrientationLines( nParentId, nMainEdgeId, nOtherEdgeId, nSyncLayerId, nLineSId, nLineEId, + bool bOk = ExeTrimmingGetToolOrientationLines( nParentId, nMainEdgeId, nOtherEdgeId, bMainIsFirstBorder, nSyncLayerId, nLineSId, nLineEId, dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol, nInterpStartId, nStartId, nEndId, nInterpEndId) ; LuaSetParam( L, bOk) ; From 60e7f9040a233a62a30fe04f8529129235ae7fa3 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Fri, 22 May 2026 10:44:43 +0200 Subject: [PATCH 5/5] EgtExecutor : - aggiunto check per la scelta del lato a cui appliare l'interpolazione delle direzioni di lavorazione - corretta gestione delle direzioni rispetto al bordo scelto per l'operazione di interpolazione. --- EXE_Trimming.cpp | 13 ++++++++++--- Lua_Trimming.cpp | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/EXE_Trimming.cpp b/EXE_Trimming.cpp index d63a883..7688b52 100644 --- a/EXE_Trimming.cpp +++ b/EXE_Trimming.cpp @@ -874,7 +874,8 @@ ExeTrimmingGetSurfBzSyncPoints( int nParentId, int nEdge1Id, int nEdge2Id, doubl // --------------------------------------------------------------------------- bool -ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEdgeId, bool bMainIsFirstBorder, int nSyncLayerId, int nLineSId, int nLineEId, +ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEdgeId, bool bMainIsFirstBorder, int nSyncLayerId, + int nLineSId, int nLineEId, bool bShorterSide, double dThetaStart, double dPhiStart, double dThetaEnd, double dPhiEnd, double dInterpLenS, double dInterpLenE, double dLinTol, int& nInterpStartId, int& nStartId, int& nEndId, int& nInterpEndId) @@ -890,7 +891,7 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd double dMyLinTol = Clamp( dLinTol, EPS_SMALL, 1e5 * EPS_SMALL) ; const double TOL = dMyLinTol ; // Definisco costanti per interpolazione - const double INTERPOLATION_DIST = 0.5 ; // alzare + const double INTERPOLATION_DIST = 2 ; const double ISO_PAR_SAMPLE = 20.0 ; // Recupero il riferimento del gruppo di destinazione @@ -950,9 +951,11 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd double dLenE = 0., dLenMain = 0. ; bOk = ( pCompoMainCL->GetLengthAtPoint( Line2.first, dLenE, TOL) && pCompoMainCL->GetLength( dLenMain)) ; - if ( dLenE > dLenMain / 2. + EPS_SMALL) { + if ( dLenE > dLenMain / 2. + EPS_SMALL && bShorterSide) { swap( Line1, Line2) ; swap( pCrvSyncS, pCrvSyncE) ; + swap( dThetaStart, dThetaEnd) ; + swap( dPhiStart, dPhiEnd) ; } } } @@ -1063,6 +1066,8 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd pCompoIso->IsValid() && pCompoIso->GetStartPoint( LineInterpS.first) && pCompoIso->GetEndPoint( LineInterpS.second)) ; + if ( ! bMainIsFirstBorder) + swap( LineInterpS.first, LineInterpS.second) ; if ( bOk) { bool bFirst = true ; // Interpolo @@ -1179,6 +1184,8 @@ ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEd pCompoIso->IsValid() && pCompoIso->GetStartPoint( LineInterpE.first) && pCompoIso->GetEndPoint( LineInterpE.second)) ; + if ( ! bMainIsFirstBorder) + swap( LineInterpE.first, LineInterpE.second) ; if ( bOk) { // Interpolo double dLenLineInterpE = Dist( LineInterpE.first, LineInterpE.second) ; diff --git a/Lua_Trimming.cpp b/Lua_Trimming.cpp index a12aad1..dd60487 100644 --- a/Lua_Trimming.cpp +++ b/Lua_Trimming.cpp @@ -287,7 +287,7 @@ LuaTrimmingGetSurfBzSyncPoints( lua_State* L) static int LuaTrimmingGetToolOrientationLines( lua_State* L) { - // 14 parametri : nParentId, nMainEdgeId, nOtherEdgeId, bMainIsFirstBorder, nSyncLayerId, nLineSId, nLineEId, + // 15 parametri : nParentId, nMainEdgeId, nOtherEdgeId, bMainIsFirstBorder, nSyncLayerId, nLineSId, nLineEId, bShorterSide // dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol int nParentId ; LuaCheckParam( L, 1, nParentId) @@ -301,26 +301,28 @@ LuaTrimmingGetToolOrientationLines( lua_State* L) LuaCheckParam( L, 5, nLineSId) int nLineEId ; LuaCheckParam( L, 6, nLineEId) + bool bShorterSide ; + LuaCheckParam( L, 7, bShorterSide) int nSyncLayerId ; - LuaCheckParam( L, 7, nSyncLayerId) + LuaCheckParam( L, 8, nSyncLayerId) double dThetaStart ; - LuaCheckParam( L, 8, dThetaStart) + LuaCheckParam( L, 9, dThetaStart) double dPhiStart ; - LuaCheckParam( L, 9, dPhiStart) + LuaCheckParam( L, 10, dPhiStart) double dThetaEnd ; - LuaCheckParam( L, 10, dThetaEnd) + LuaCheckParam( L, 11, dThetaEnd) double dPhiEnd ; - LuaCheckParam( L, 11, dPhiEnd) ; + LuaCheckParam( L, 12, dPhiEnd) ; double dInterpLenS ; - LuaCheckParam( L, 12, dInterpLenS) + LuaCheckParam( L, 13, dInterpLenS) double dInterpLenE ; - LuaCheckParam( L, 13, dInterpLenE) + LuaCheckParam( L, 14, dInterpLenE) double dLinTol ; - LuaCheckParam( L, 14, dLinTol) + LuaCheckParam( L, 15, dLinTol) LuaClearStack( L) ; // Inserisco i tratti lineari associati calcolati lungo il percorso int nInterpStartId = GDB_ID_NULL, nStartId = GDB_ID_NULL, nEndId = GDB_ID_NULL, nInterpEndId = GDB_ID_NULL ; - bool bOk = ExeTrimmingGetToolOrientationLines( nParentId, nMainEdgeId, nOtherEdgeId, bMainIsFirstBorder, nSyncLayerId, nLineSId, nLineEId, + bool bOk = ExeTrimmingGetToolOrientationLines( nParentId, nMainEdgeId, nOtherEdgeId, bMainIsFirstBorder, nSyncLayerId, nLineSId, nLineEId, bShorterSide, dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol, nInterpStartId, nStartId, nEndId, nInterpEndId) ; LuaSetParam( L, bOk) ;