From 20de52bf5865608031c63c2e3c4430ba3bc19b92 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Mon, 15 Jun 2026 08:39:46 +0200 Subject: [PATCH] EgtExecutor : - spostate le funzioni di offset. - aggiunta la funzione di offset 3d delle curve. --- EXE_GdbCreateCurve.cpp | 176 +++++++++++++++++++++++++ EXE_GdbGetCurve.cpp | 187 +++++++++++++++++++++++++- EXE_GdbModifyCurve.cpp | 291 +---------------------------------------- LUA_GdbCreateCurve.cpp | 90 +++++++++++++ LUA_GdbGetCurve.cpp | 68 ++++++++++ LUA_GdbModifyCurve.cpp | 126 ------------------ 6 files changed, 523 insertions(+), 415 deletions(-) diff --git a/EXE_GdbCreateCurve.cpp b/EXE_GdbCreateCurve.cpp index 31af62e..858e449 100644 --- a/EXE_GdbCreateCurve.cpp +++ b/EXE_GdbCreateCurve.cpp @@ -20,6 +20,7 @@ #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkGeoCollection.h" #include "/EgtDev/Include/EGkCurveLine.h" #include "/EgtDev/Include/EGkLinePntTgCurve.h" #include "/EgtDev/Include/EGkLinePntPerpCurve.h" @@ -42,9 +43,11 @@ #include "/EgtDev/Include/EGkCurveByApprox.h" #include "/EgtDev/Include/EGkCurveAux.h" #include "/EgtDev/Include/EGkOffsetCurve.h" +#include "/EgtDev/Include/EGkOffsetCurve3d.h" #include "/EgtDev/Include/EGkCurveLocal.h" #include "/EgtDev/Include/EGkSurfTriMesh.h" #include "/EgtDev/Include/EGkDistPointCurve.h" +#include "/EgtDev/Include/EGkProjectCurveSurf.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EgtPointerOwner.h" @@ -2634,3 +2637,176 @@ CalcExtrusion( IGeomDB* pGeomDB, int nParentId, int nRefType) vtExtr.LocToLoc( pGeomDB->GetGridFrame(), frEnt) ; return vtExtr ; } + +//---------------------------------------------------------------------------- +int +ExeOffsetCurveAdv( int nId, double dDist, int nType, int* pnCount, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + // eseguo l'offset + OffsetCurve OffsCrv( dLinTol) ; + bool bOk = OffsCrv.Make( pCurve, dDist, nType) ; + // salvo le curve di offset + int nRefId = nId ; + int nCount = 0 ; + int nFirstId = GDB_ID_NULL ; + PtrOwner pOffs( OffsCrv.GetLongerCurve()) ; + while ( bOk && ! IsNull( pOffs)) { + // inserisco la curva nel DB geometrico + int nNewId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nRefId, GDB_AFTER, Release( pOffs)) ; + // copio gli attributi + pGeomDB->CopyAttributes( nId, nNewId) ; + // aggiorno contatori + if ( nNewId != GDB_ID_NULL) + ++ nCount ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nNewId ; + // aggiorno Id di riferimento per inserimento + if ( nNewId != GDB_ID_NULL) + nRefId = nNewId ; + // passo alla successiva + pOffs.Set( OffsCrv.GetLongerCurve()) ; + } + if ( bOk) + ExeSetModified() ; + else + nCount = - 1 ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + sLua = "EgtOffsetCurveAdv(" + ToString( nId) + "," + + ToString( dDist) + "," + + OffsTypeToString( nType) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + +//---------------------------------------------------------------------------- +int +ExeCurveGetFatCurve( int nId, int nDestGrpId, double dRad, bool bSquareEnds, bool bSquareMids, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + // recupero il riferimento della curva + Frame3d frCrv ; + if ( ! pGeomDB->GetGlobFrame( nId, frCrv)) + return GDB_ID_NULL ; + // recupero il riferimento di destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest)) + return GDB_ID_NULL ; + + // Calcolo la curva ingrossata + ICURVEPOVECTOR vCrv ; + CalcCurveFatCurve( *pCrv, vCrv, dRad, bSquareEnds, bSquareMids) ; + + // inserisco i risultati nel DB geometrico + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + for ( int i = 0 ; i < int( vCrv.size()) ; i++) { + vCrv[i]->LocToLoc( frCrv, frDest) ; + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( vCrv[i])) ; + if ( nId != GDB_ID_NULL) { + nCount ++ ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nId ; + } + } + ExeSetModified() ; + + if ( IsCmdLog()) { + string sLua = "EgtCurveGetFatCurve(" + ToString( nId) + "," + + ToString( nDestGrpId) + ")" + + " FirstId=" + ToString( nFirstId) + " nCurveCount=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + +//---------------------------------------------------------------------------- +int +ExeOffsetCurve3d( int nId, int nSurfId, double dDist, int nType, int* pnCount, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return GDB_ID_NULL ; + // recupero la superficie + const ISurf* pSurf = GetSurf( pGeomDB->GetGeoObj( nSurfId)) ; + if ( pSurf == nullptr) + return GDB_ID_NULL ; + // proietto la curva sulla superficie in modo da ottenere tutte le normali della superficie lungo la curva proiettata + CISURFPVECTOR vpSurf ; + vpSurf.push_back( pSurf) ; + double dMaxSegLen = 2.5 ; + bool bSharpEdges = true ; + PNT5AXVECTOR vPt5ax ; + if ( ! ProjectCurveOnSurf( *pCurve, vpSurf, dLinTol, dMaxSegLen, bSharpEdges, vPt5ax)) + return GDB_ID_NULL ; + PolyLine PL ; + VCT3DVECTOR vOffDir ; + for ( int i = 0 ; i < ssize( vPt5ax) ; ++i) { + PL.AddUPoint( i, vPt5ax[i].ptP) ; + vOffDir.push_back( vPt5ax[i].vtDir1) ; + } + // eseguo l'offset + OffsetCurve3d OffsCrv( dLinTol) ; + bool bOk = OffsCrv.Make( PL, vOffDir, dDist, nType) ; + // salvo le curve di offset + int nRefId = nId ; + int nCount = 0 ; + int nFirstId = GDB_ID_NULL ; + PtrOwner pOffs( OffsCrv.GetLongerCurve()) ; + while ( bOk && ! IsNull( pOffs)) { + // inserisco la curva nel DB geometrico + int nNewId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nRefId, GDB_AFTER, Release( pOffs)) ; + // copio gli attributi + pGeomDB->CopyAttributes( nId, nNewId) ; + // aggiorno contatori + if ( nNewId != GDB_ID_NULL) + ++ nCount ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nNewId ; + // aggiorno Id di riferimento per inserimento + if ( nNewId != GDB_ID_NULL) + nRefId = nNewId ; + // passo alla successiva + pOffs.Set( OffsCrv.GetLongerCurve()) ; + } + if ( bOk) + ExeSetModified() ; + else + nCount = - 1 ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + sLua = "EgtOffsetCurveAdv(" + ToString( nId) + "," + + ToString( dDist) + "," + + OffsTypeToString( nType) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + diff --git a/EXE_GdbGetCurve.cpp b/EXE_GdbGetCurve.cpp index 1a27922..434f635 100644 --- a/EXE_GdbGetCurve.cpp +++ b/EXE_GdbGetCurve.cpp @@ -22,12 +22,13 @@ #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkGeoPoint3d.h" -#include "/EgtDev/Include/EGkGeoPoint3d.h" #include "/EgtDev/Include/EGkCurve.h" +#include "/EgtDev/Include/EGkCurveLocal.h" #include "/EgtDev/Include/EGkCurveArc.h" #include "/EgtDev/Include/EGkCurveBezier.h" #include "/EgtDev/Include/EGkCurveComposite.h" #include "/EgtDev/Include/EGkCurveAux.h" +#include "/EgtDev/Include/EGkMedialAxis.h" #include "/EgtDev/Include/EGkDistPointCurve.h" #include "/EgtDev/Include/EGkIntersCurves.h" #include "/EgtDev/Include/EGkSurfFlatRegion.h" @@ -923,4 +924,188 @@ ExeCopyParamRange( int nCrvId, double dUStart, double dUEnd, int nDestGrpId) ExeSetModified() ; return nSubCrvId ; +} + +//---------------------------------------------------------------------------- +int +ExeCurveMedialAxis( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + // eseguo il calcolo + PolyLine PL ; + if ( ! CurveSimpleMedialAxis( pCurve, PL)) + return GDB_ID_NULL ; + // creo la curva + PtrOwner pCompo( CreateCurveComposite()) ; + if ( IsNull( pCompo) || ! pCompo->FromPolyLine( PL)) + return GDB_ID_NULL ; + // la inserisco nel DB geometrico + int nNewId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_AFTER, Release( pCompo)) ; + // copio gli attributi + pGeomDB->CopyAttributes( nId, nNewId) ; + // notifico la modifica + if ( nNewId != GDB_ID_NULL) + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + sLua = "EgtCurveMedialAxis(" + ToString( nId) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + return nNewId ; +} + +//---------------------------------------------------------------------------- +int +ExeCurveGetVoronoi( const INTVECTOR& vIds, int nDestGrpId, int nBound, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + + if ( vIds.empty()) + return false ; + + // recupero il riferimento della prima curva che sarà utilizzato da Voronoi + Frame3d frCrv ; + if ( ! pGeomDB->GetGlobFrame( vIds[0], frCrv)) + return GDB_ID_NULL ; + // recupero il riferimento di destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest)) + return GDB_ID_NULL ; + + // Calcolo diagramma di Voronoi + ICURVEPOVECTOR vCrv ; + if ( int( vIds.size()) == 1) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( vIds[0])) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + // calcolo + CalcCurveVoronoiDiagram( *pCrv, vCrv, nBound) ; + } + else { + // recupero le curve e le porto in locale al frame della prima curva + CICURVEPVECTOR vOrigCrvs ; + for ( int i = 0 ; i < int( vIds.size()) ; i ++) { + CurveLocal CrvLoc( pGeomDB, vIds[i], frCrv) ; + if ( CrvLoc.Get() == nullptr) { + for ( auto pCrv : vOrigCrvs) + delete( pCrv) ; + return GDB_ID_NULL ; + } + vOrigCrvs.emplace_back( CrvLoc->Clone()) ; + } + // calcolo + CalcCurvesVoronoiDiagram( vOrigCrvs, vCrv, nBound) ; + // libero la memoria + for ( auto pCrv : vOrigCrvs) + delete( pCrv) ; + } + + // inserisco i risultati nel DB geometrico + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + for ( int i = 0 ; i < int( vCrv.size()) ; i++) { + vCrv[i]->LocToLoc( frCrv, frDest) ; + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( vCrv[i])) ; + if ( nId != GDB_ID_NULL) { + nCount ++ ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nId ; + } + } + ExeSetModified() ; + + if ( IsCmdLog()) { + string sLua = "EgtCurveGetVoronoi({" + ToString( vIds) + "}," + + ToString( nDestGrpId) + ")" + + " FirstId=" + ToString( nFirstId) + " nCurveCount=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + +//---------------------------------------------------------------------------- +int +ExeCurveGetMedialAxis( const INTVECTOR& vIds, int nDestGrpId, int nSide, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + + if ( vIds.empty()) + return false ; + + // recupero il riferimento della prima curva che sarà utilizzato da Voronoi + Frame3d frCrv ; + if ( ! pGeomDB->GetGlobFrame( vIds[0], frCrv)) + return GDB_ID_NULL ; + // recupero il riferimento di destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest)) + return GDB_ID_NULL ; + + // Calcolo il Medial Axis + ICURVEPOVECTOR vCrv ; + if ( int( vIds.size()) == 1) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( vIds[0])) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + // calcolo + CalcCurveMedialAxis( *pCrv, vCrv, nSide) ; + } + else { + // recupero le curve e le porto in locale al frame della prima curva + CICURVEPVECTOR vOrigCrvs ; + for ( int i = 0 ; i < int( vIds.size()) ; i ++) { + CurveLocal CrvLoc( pGeomDB, vIds[i], frCrv) ; + if ( CrvLoc.Get() == nullptr) { + for ( auto pCrv : vOrigCrvs) + delete( pCrv) ; + return GDB_ID_NULL ; + } + vOrigCrvs.emplace_back( CrvLoc->Clone()) ; + } + // calcolo + CalcCurvesMedialAxis( vOrigCrvs, vCrv, nSide) ; + // libero la memoria + for ( auto pCrv : vOrigCrvs) + delete( pCrv) ; + } + + // inserisco i risultati nel DB geometrico + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + for ( int i = 0 ; i < int( vCrv.size()) ; i++) { + vCrv[i]->LocToLoc( frCrv, frDest) ; + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( vCrv[i])) ; + if ( nId != GDB_ID_NULL) { + nCount ++ ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nId ; + } + } + ExeSetModified() ; + + if ( IsCmdLog()) { + string sLua = "EgtCurveMedialAxisAdv(" + ToString( vIds[0]) + "," + + ToString( nSide) + "," + + ToString( nDestGrpId) + ")" + + " FirstId=" + ToString( nFirstId) + " nCurveCount=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; } \ No newline at end of file diff --git a/EXE_GdbModifyCurve.cpp b/EXE_GdbModifyCurve.cpp index 3a51ddf..ebaa9e4 100644 --- a/EXE_GdbModifyCurve.cpp +++ b/EXE_GdbModifyCurve.cpp @@ -32,7 +32,6 @@ #include "/EgtDev/Include/EGkSurfLocal.h" #include "/EgtDev/Include/EGkCurveAux.h" #include "/EgtDev/Include/EGkOffsetCurve.h" -#include "/EgtDev/Include/EGkMedialAxis.h" #include "/EgtDev/Include/EGkChainCurves.h" #include "/EgtDev/Include/EGkProjectCurveSurf.h" #include "/EgtDev/Include/EGkSurfFlatRegion.h" @@ -103,90 +102,6 @@ ExeOffsetCurve( int nId, double dDist, int nType) return bOk ; } -//---------------------------------------------------------------------------- -int -ExeOffsetCurveAdv( int nId, double dDist, int nType, int* pnCount, double dLinTol) -{ - IGeomDB* pGeomDB = GetCurrGeomDB() ; - VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) - // recupero la curva - const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; - // eseguo l'offset - OffsetCurve OffsCrv( dLinTol) ; - bool bOk = OffsCrv.Make( pCurve, dDist, nType) ; - // salvo le curve di offset - int nRefId = nId ; - int nCount = 0 ; - int nFirstId = GDB_ID_NULL ; - PtrOwner pOffs( OffsCrv.GetLongerCurve()) ; - while ( bOk && ! IsNull( pOffs)) { - // inserisco la curva nel DB geometrico - int nNewId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nRefId, GDB_AFTER, Release( pOffs)) ; - // copio gli attributi - pGeomDB->CopyAttributes( nId, nNewId) ; - // aggiorno contatori - if ( nNewId != GDB_ID_NULL) - ++ nCount ; - if ( nFirstId == GDB_ID_NULL) - nFirstId = nNewId ; - // aggiorno Id di riferimento per inserimento - if ( nNewId != GDB_ID_NULL) - nRefId = nNewId ; - // passo alla successiva - pOffs.Set( OffsCrv.GetLongerCurve()) ; - } - if ( bOk) - ExeSetModified() ; - else - nCount = - 1 ; - // se richiesto, salvo il comando Lua equivalente - if ( IsCmdLog()) { - string sLua ; - sLua = "EgtOffsetCurveAdv(" + ToString( nId) + "," + - ToString( dDist) + "," + - OffsTypeToString( nType) + ")" + - " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; - LOG_INFO( GetCmdLogger(), sLua.c_str()) ; - } - // restituisco risultato - if ( pnCount != nullptr) - *pnCount = nCount ; - return nFirstId ; -} - -//---------------------------------------------------------------------------- -int -ExeCurveMedialAxis( int nId) -{ - IGeomDB* pGeomDB = GetCurrGeomDB() ; - VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) - // recupero la curva - const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; - // eseguo il calcolo - PolyLine PL ; - if ( ! CurveSimpleMedialAxis( pCurve, PL)) - return GDB_ID_NULL ; - // creo la curva - PtrOwner pCompo( CreateCurveComposite()) ; - if ( IsNull( pCompo) || ! pCompo->FromPolyLine( PL)) - return GDB_ID_NULL ; - // la inserisco nel DB geometrico - int nNewId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_AFTER, Release( pCompo)) ; - // copio gli attributi - pGeomDB->CopyAttributes( nId, nNewId) ; - // notifico la modifica - if ( nNewId != GDB_ID_NULL) - ExeSetModified() ; - // se richiesto, salvo il comando Lua equivalente - if ( IsCmdLog()) { - string sLua ; - sLua = "EgtCurveMedialAxis(" + ToString( nId) + ")" + - " -- Id=" + ToString( nNewId) ; - LOG_INFO( GetCmdLogger(), sLua.c_str()) ; - } - return nNewId ; -} - //------------------------------------------------------------------------------- bool ExeApproxCurve( int nId, int nApprType, double dLinTol, double dMaxSegmLen) @@ -2462,8 +2377,9 @@ MyProjectCurveOnSurf( int nCurveId, const INTVECTOR& vnSurfId, int nDestGrpId, return false ; // recupero il riferimento della prima superficie Frame3d frSurf ; - if ( ! pGeomDB->GetGlobFrame( vnSurfId[0], frSurf)) - return false ; + //if ( ! pGeomDB->GetGlobFrame( vnSurfId[0], frSurf)) + // return false ; + // recupero le superfici e le porto tutte in locale alla prima SURFLOCALVECTOR vSurfL ; vSurfL.reserve( vnSurfId.size()) ; CISURFPVECTOR vpSurf ; vpSurf.reserve( vnSurfId.size()) ; @@ -2785,207 +2701,6 @@ ExeProjectCurveOnSurfExt( int nCurveId, const INTVECTOR& vnSurfId, int nGuideId, return bOk ; } -//---------------------------------------------------------------------------- -int -ExeCurveGetVoronoi( const INTVECTOR& vIds, int nDestGrpId, int nBound, int* pnCount) -{ - IGeomDB* pGeomDB = GetCurrGeomDB() ; - VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) - - if ( vIds.empty()) - return false ; - - // recupero il riferimento della prima curva che sarà utilizzato da Voronoi - Frame3d frCrv ; - if ( ! pGeomDB->GetGlobFrame( vIds[0], frCrv)) - return GDB_ID_NULL ; - // recupero il riferimento di destinazione - Frame3d frDest ; - if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest)) - return GDB_ID_NULL ; - - // Calcolo diagramma di Voronoi - ICURVEPOVECTOR vCrv ; - if ( int( vIds.size()) == 1) { - // recupero la curva - const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( vIds[0])) ; - if ( pCrv == nullptr) - return GDB_ID_NULL ; - // calcolo - CalcCurveVoronoiDiagram( *pCrv, vCrv, nBound) ; - } - else { - // recupero le curve e le porto in locale al frame della prima curva - CICURVEPVECTOR vOrigCrvs ; - for ( int i = 0 ; i < int( vIds.size()) ; i ++) { - CurveLocal CrvLoc( pGeomDB, vIds[i], frCrv) ; - if ( CrvLoc.Get() == nullptr) { - for ( auto pCrv : vOrigCrvs) - delete( pCrv) ; - return GDB_ID_NULL ; - } - vOrigCrvs.emplace_back( CrvLoc->Clone()) ; - } - // calcolo - CalcCurvesVoronoiDiagram( vOrigCrvs, vCrv, nBound) ; - // libero la memoria - for ( auto pCrv : vOrigCrvs) - delete( pCrv) ; - } - - // inserisco i risultati nel DB geometrico - int nFirstId = GDB_ID_NULL ; - int nCount = 0 ; - for ( int i = 0 ; i < int( vCrv.size()) ; i++) { - vCrv[i]->LocToLoc( frCrv, frDest) ; - int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( vCrv[i])) ; - if ( nId != GDB_ID_NULL) { - nCount ++ ; - if ( nFirstId == GDB_ID_NULL) - nFirstId = nId ; - } - } - ExeSetModified() ; - - if ( IsCmdLog()) { - string sLua = "EgtCurveGetVoronoi({" + ToString( vIds) + "}," + - ToString( nDestGrpId) + ")" + - " FirstId=" + ToString( nFirstId) + " nCurveCount=" + ToString( nCount) ; - LOG_INFO( GetCmdLogger(), sLua.c_str()) ; - } - - // restituisco risultati - if ( pnCount != nullptr) - *pnCount = nCount ; - return nFirstId ; -} - -//---------------------------------------------------------------------------- -int -ExeCurveGetMedialAxis( const INTVECTOR& vIds, int nDestGrpId, int nSide, int* pnCount) -{ - IGeomDB* pGeomDB = GetCurrGeomDB() ; - VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) - - if ( vIds.empty()) - return false ; - - // recupero il riferimento della prima curva che sarà utilizzato da Voronoi - Frame3d frCrv ; - if ( ! pGeomDB->GetGlobFrame( vIds[0], frCrv)) - return GDB_ID_NULL ; - // recupero il riferimento di destinazione - Frame3d frDest ; - if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest)) - return GDB_ID_NULL ; - - // Calcolo il Medial Axis - ICURVEPOVECTOR vCrv ; - if ( int( vIds.size()) == 1) { - // recupero la curva - const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( vIds[0])) ; - if ( pCrv == nullptr) - return GDB_ID_NULL ; - // calcolo - CalcCurveMedialAxis( *pCrv, vCrv, nSide) ; - } - else { - // recupero le curve e le porto in locale al frame della prima curva - CICURVEPVECTOR vOrigCrvs ; - for ( int i = 0 ; i < int( vIds.size()) ; i ++) { - CurveLocal CrvLoc( pGeomDB, vIds[i], frCrv) ; - if ( CrvLoc.Get() == nullptr) { - for ( auto pCrv : vOrigCrvs) - delete( pCrv) ; - return GDB_ID_NULL ; - } - vOrigCrvs.emplace_back( CrvLoc->Clone()) ; - } - // calcolo - CalcCurvesMedialAxis( vOrigCrvs, vCrv, nSide) ; - // libero la memoria - for ( auto pCrv : vOrigCrvs) - delete( pCrv) ; - } - - // inserisco i risultati nel DB geometrico - int nFirstId = GDB_ID_NULL ; - int nCount = 0 ; - for ( int i = 0 ; i < int( vCrv.size()) ; i++) { - vCrv[i]->LocToLoc( frCrv, frDest) ; - int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( vCrv[i])) ; - if ( nId != GDB_ID_NULL) { - nCount ++ ; - if ( nFirstId == GDB_ID_NULL) - nFirstId = nId ; - } - } - ExeSetModified() ; - - if ( IsCmdLog()) { - string sLua = "EgtCurveMedialAxisAdv(" + ToString( vIds[0]) + "," + - ToString( nSide) + "," + - ToString( nDestGrpId) + ")" + - " FirstId=" + ToString( nFirstId) + " nCurveCount=" + ToString( nCount) ; - LOG_INFO( GetCmdLogger(), sLua.c_str()) ; - } - - // restituisco risultati - if ( pnCount != nullptr) - *pnCount = nCount ; - return nFirstId ; -} - -//---------------------------------------------------------------------------- -int -ExeCurveGetFatCurve( int nId, int nDestGrpId, double dRad, bool bSquareEnds, bool bSquareMids, int* pnCount) -{ - IGeomDB* pGeomDB = GetCurrGeomDB() ; - VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) - // recupero la curva - const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ; - if ( pCrv == nullptr) - return GDB_ID_NULL ; - // recupero il riferimento della curva - Frame3d frCrv ; - if ( ! pGeomDB->GetGlobFrame( nId, frCrv)) - return GDB_ID_NULL ; - // recupero il riferimento di destinazione - Frame3d frDest ; - if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest)) - return GDB_ID_NULL ; - - // Calcolo la curva ingrossata - ICURVEPOVECTOR vCrv ; - CalcCurveFatCurve( *pCrv, vCrv, dRad, bSquareEnds, bSquareMids) ; - - // inserisco i risultati nel DB geometrico - int nFirstId = GDB_ID_NULL ; - int nCount = 0 ; - for ( int i = 0 ; i < int( vCrv.size()) ; i++) { - vCrv[i]->LocToLoc( frCrv, frDest) ; - int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( vCrv[i])) ; - if ( nId != GDB_ID_NULL) { - nCount ++ ; - if ( nFirstId == GDB_ID_NULL) - nFirstId = nId ; - } - } - ExeSetModified() ; - - if ( IsCmdLog()) { - string sLua = "EgtCurveGetFatCurve(" + ToString( nId) + "," + - ToString( nDestGrpId) + ")" + - " FirstId=" + ToString( nFirstId) + " nCurveCount=" + ToString( nCount) ; - LOG_INFO( GetCmdLogger(), sLua.c_str()) ; - } - - // restituisco risultati - if ( pnCount != nullptr) - *pnCount = nCount ; - return nFirstId ; -} - //---------------------------------------------------------------------------- bool ExeCurveBezierIncreaseDegree( int nCrvId) diff --git a/LUA_GdbCreateCurve.cpp b/LUA_GdbCreateCurve.cpp index 956713a..7cdccc9 100644 --- a/LUA_GdbCreateCurve.cpp +++ b/LUA_GdbCreateCurve.cpp @@ -18,6 +18,7 @@ #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EGkCurve.h" using namespace std ; @@ -1112,6 +1113,92 @@ LuaCreateCirclesAlongCurve( lua_State* L) return 2 ; } +//------------------------------------------------------------------------------- +static int +LuaOffsetCurveAdv( lua_State* L) +{ + // 2 o 3 o 4 parametri : Id, dDist [, nType] [, dLinTol] + int nId ; + LuaCheckParam( L, 1, nId) + double dDist ; + LuaCheckParam( L, 2, dDist) + int nType = ICurve::OFF_FILLET ; + LuaGetParam( L, 3, nType) ; + double dLinTol = 10 * EPS_SMALL ; + LuaGetParam( L, 4, dLinTol) ; + LuaClearStack( L) ; + // offset della curva + int nCount ; + int nNewId = ExeOffsetCurveAdv( nId, dDist, nType, &nCount, dLinTol) ; + if ( nCount >= 0) { + LuaSetParam( L, nNewId) ; + LuaSetParam( L, nCount) ; + } + else { + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + } + return 2 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveGetFatCurve( lua_State* L) +{ + // 4 o 5 parametri : Id, nDestGrpId, dRad, bSquare [, bSquareMids] + int nId ; + LuaCheckParam( L, 1, nId) + int nDestGrpId ; + LuaCheckParam( L, 2, nDestGrpId) + double dRad ; + LuaCheckParam( L, 3, dRad) + bool bSquareEnds ; + LuaCheckParam( L, 4, bSquareEnds) + bool bSquareMids = bSquareEnds ; + LuaGetParam( L, 5, bSquareMids) ; + LuaClearStack( L) ; + // eseguo + int nCount = 0 ; + int nNewId = ExeCurveGetFatCurve( nId, nDestGrpId, dRad, bSquareEnds, bSquareMids, &nCount) ; + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + + return 2 ; +} + +//------------------------------------------------------------------------------- +static int +LuaOffsetCurve3d( lua_State* L) +{ + // 3 o 4 o 5 parametri : Id, SurfId, dDist [, nType] [, dLinTol] + int nId ; + LuaCheckParam( L, 1, nId) + int nSurfId ; + LuaCheckParam( L, 2, nSurfId) + double dDist ; + LuaCheckParam( L, 3, dDist) + int nType = ICurve::OFF_FILLET ; + LuaGetParam( L, 4, nType) ; + double dLinTol = 10 * EPS_SMALL ; + LuaGetParam( L, 5, dLinTol) ; + LuaClearStack( L) ; + // offset della curva + int nCount ; + int nNewId = ExeOffsetCurve3d( nId, nSurfId, dDist, nType, &nCount, dLinTol) ; + if ( nCount >= 0) { + LuaSetParam( L, nNewId) ; + LuaSetParam( L, nCount) ; + } + else { + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + } + return 2 ; +} + //------------------------------------------------------------------------------- bool LuaInstallGdbCreateCurve( LuaMgr& luaMgr) @@ -1157,5 +1244,8 @@ LuaInstallGdbCreateCurve( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtPolygonFromApothem", LuaCreatePolygonFromApothem) ; bOk = bOk && luaMgr.RegisterFunction( "EgtPolygonFromSide", LuaCreatePolygonFromSide) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCirclesAlongCurve", LuaCreateCirclesAlongCurve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtOffsetCurveAdv", LuaOffsetCurveAdv) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveGetFatCurve", LuaCurveGetFatCurve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtOffsetCurve3d", LuaOffsetCurve3d) ; return bOk ; } diff --git a/LUA_GdbGetCurve.cpp b/LUA_GdbGetCurve.cpp index e22d111..c8e415c 100644 --- a/LUA_GdbGetCurve.cpp +++ b/LUA_GdbGetCurve.cpp @@ -673,6 +673,71 @@ LuaCopyParamRange( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaCurveMedialAxis( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // calcolo del Medial Axis della curva + int nNewId = ExeCurveMedialAxis( nId) ; + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveMedialAxisAdv( lua_State* L) +{ + // 2 o 3 parametri : Id/s, nDestGrpId [, nSide] + INTVECTOR vIds ; + LuaCheckParam( L, 1, vIds) + int nDestGrpId ; + LuaCheckParam( L, 2, nDestGrpId) + int nSide = 1 ; // WMAT_LEFT + LuaGetParam( L, 3, nSide) ; + LuaClearStack( L) ; + // eseguo + int nCount = 0 ; + int nNewId = ExeCurveGetMedialAxis( vIds, nDestGrpId, nSide, &nCount) ; + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + + return 2 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveGetVoronoi( lua_State* L) +{ + // 2 o 3 parametri : Id/s, nDestGrpId [, nBound] + INTVECTOR vIds ; + LuaCheckParam( L, 1, vIds) + int nDestGrpId ; + LuaCheckParam( L, 2, nDestGrpId) + int nBound = 3 ; // VORONOI_STD_BOUND + LuaGetParam( L, 3, nBound) ; + LuaClearStack( L) ; + // eseguo + int nCount = 0 ; + int nNewId = ExeCurveGetVoronoi( vIds, nDestGrpId, nBound, &nCount) ; + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + + return 2 ; +} + //------------------------------------------------------------------------------- bool LuaInstallGdbGetCurve( LuaMgr& luaMgr) @@ -711,5 +776,8 @@ LuaInstallGdbGetCurve( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtShowCurveBezierControlPoints", LuaShowCurveBezierControlPoints) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyCompoSubCurve", LuaCopyCompoSubCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyParamRange", LuaCopyParamRange) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveMedialAxis", LuaCurveMedialAxis) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveGetVoronoi", LuaCurveGetVoronoi) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveMedialAxisAdv", LuaCurveMedialAxisAdv) ; return bOk ; } diff --git a/LUA_GdbModifyCurve.cpp b/LUA_GdbModifyCurve.cpp index 04c50a6..2bf8b91 100644 --- a/LUA_GdbModifyCurve.cpp +++ b/LUA_GdbModifyCurve.cpp @@ -56,51 +56,6 @@ LuaOffsetCurve( lua_State* L) return 1 ; } -//------------------------------------------------------------------------------- -static int -LuaOffsetCurveAdv( lua_State* L) -{ - // 2 o 3 o 4 parametri : Id, dDist [, nType] [, dLinTol] - int nId ; - LuaCheckParam( L, 1, nId) - double dDist ; - LuaCheckParam( L, 2, dDist) - int nType = ICurve::OFF_FILLET ; - LuaGetParam( L, 3, nType) ; - double dLinTol = 10 * EPS_SMALL ; - LuaGetParam( L, 4, dLinTol) ; - LuaClearStack( L) ; - // offset della curva - int nCount ; - int nNewId = ExeOffsetCurveAdv( nId, dDist, nType, &nCount, dLinTol) ; - if ( nCount >= 0) { - LuaSetParam( L, nNewId) ; - LuaSetParam( L, nCount) ; - } - else { - LuaSetParam( L) ; - LuaSetParam( L, nCount) ; - } - return 2 ; -} - -//------------------------------------------------------------------------------- -static int -LuaCurveMedialAxis( lua_State* L) -{ - // 1 parametro : Id - int nId ; - LuaCheckParam( L, 1, nId) - LuaClearStack( L) ; - // calcolo del Medial Axis della curva - int nNewId = ExeCurveMedialAxis( nId) ; - if ( nNewId != GDB_ID_NULL) - LuaSetParam( L, nNewId) ; - else - LuaSetParam( L) ; - return 1 ; -} - //------------------------------------------------------------------------------- static int LuaApproxCurve( lua_State* L) @@ -1089,82 +1044,6 @@ LuaProjectCurveOnSurfExt( lua_State* L) return 1 ; } -//---------------------------------------------------------------------------- -static int -LuaCurveGetVoronoi( lua_State* L) -{ - // 2 o 3 parametri : Id/s, nDestGrpId [, nBound] - INTVECTOR vIds ; - LuaCheckParam( L, 1, vIds) - int nDestGrpId ; - LuaCheckParam( L, 2, nDestGrpId) - int nBound = 3 ; // VORONOI_STD_BOUND - LuaGetParam( L, 3, nBound) ; - LuaClearStack( L) ; - // eseguo - int nCount = 0 ; - int nNewId = ExeCurveGetVoronoi( vIds, nDestGrpId, nBound, &nCount) ; - if ( nNewId != GDB_ID_NULL) - LuaSetParam( L, nNewId) ; - else - LuaSetParam( L) ; - LuaSetParam( L, nCount) ; - - return 2 ; -} - -//---------------------------------------------------------------------------- -static int -LuaCurveMedialAxisAdv( lua_State* L) -{ - // 2 o 3 parametri : Id/s, nDestGrpId [, nSide] - INTVECTOR vIds ; - LuaCheckParam( L, 1, vIds) - int nDestGrpId ; - LuaCheckParam( L, 2, nDestGrpId) - int nSide = 1 ; // WMAT_LEFT - LuaGetParam( L, 3, nSide) ; - LuaClearStack( L) ; - // eseguo - int nCount = 0 ; - int nNewId = ExeCurveGetMedialAxis( vIds, nDestGrpId, nSide, &nCount) ; - if ( nNewId != GDB_ID_NULL) - LuaSetParam( L, nNewId) ; - else - LuaSetParam( L) ; - LuaSetParam( L, nCount) ; - - return 2 ; -} - -//---------------------------------------------------------------------------- -static int -LuaCurveGetFatCurve( lua_State* L) -{ - // 4 o 5 parametri : Id, nDestGrpId, dRad, bSquare [, bSquareMids] - int nId ; - LuaCheckParam( L, 1, nId) - int nDestGrpId ; - LuaCheckParam( L, 2, nDestGrpId) - double dRad ; - LuaCheckParam( L, 3, dRad) - bool bSquareEnds ; - LuaCheckParam( L, 4, bSquareEnds) - bool bSquareMids = bSquareEnds ; - LuaGetParam( L, 5, bSquareMids) ; - LuaClearStack( L) ; - // eseguo - int nCount = 0 ; - int nNewId = ExeCurveGetFatCurve( nId, nDestGrpId, dRad, bSquareEnds, bSquareMids, &nCount) ; - if ( nNewId != GDB_ID_NULL) - LuaSetParam( L, nNewId) ; - else - LuaSetParam( L) ; - LuaSetParam( L, nCount) ; - - return 2 ; -} - //---------------------------------------------------------------------------- static int LuaCurveBezierIncreaseDegree( lua_State* L) @@ -1236,8 +1115,6 @@ LuaInstallGdbModifyCurve( LuaMgr& luaMgr) bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtInvertCurve", LuaInvertCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtOffsetCurve", LuaOffsetCurve) ; - bOk = bOk && luaMgr.RegisterFunction( "EgtOffsetCurveAdv", LuaOffsetCurveAdv) ; - bOk = bOk && luaMgr.RegisterFunction( "EgtCurveMedialAxis", LuaCurveMedialAxis) ; bOk = bOk && luaMgr.RegisterFunction( "EgtApproxCurve", LuaApproxCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtProjectCurveOnPlane", LuaProjectCurveOnPlane) ; bOk = bOk && luaMgr.RegisterFunction( "EgtChangeClosedCurveStart", LuaChangeClosedCurveStart) ; @@ -1290,9 +1167,6 @@ LuaInstallGdbModifyCurve( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtProjectCurveOnSurf", LuaProjectCurveOnSurf) ; bOk = bOk && luaMgr.RegisterFunction( "EgtProjectCurveOnSurfDir", LuaProjectCurveOnSurfDir) ; bOk = bOk && luaMgr.RegisterFunction( "EgtProjectCurveOnSurfExt", LuaProjectCurveOnSurfExt) ; - bOk = bOk && luaMgr.RegisterFunction( "EgtCurveGetVoronoi", LuaCurveGetVoronoi) ; - bOk = bOk && luaMgr.RegisterFunction( "EgtCurveMedialAxisAdv", LuaCurveMedialAxisAdv) ; - bOk = bOk && luaMgr.RegisterFunction( "EgtCurveGetFatCurve", LuaCurveGetFatCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveBezierIncreaseDeg", LuaCurveBezierIncreaseDegree) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveBezierDecreaseDeg", LuaCurveBezierDecreaseDegree) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveBezierApproxToNonRat", LuaCurveBezierApproxToNonRat) ;