From 2fc0e4994d3a704a7579ec5c317a07946f6f16cf Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Wed, 17 Jul 2024 09:14:03 +0200 Subject: [PATCH] EgtExecutor : - aggiunta del cap alla funzione Bez by extrusion. --- EXE_GdbCreateSurf.cpp | 75 +++++++++++++++++++++++++++++++++++++++++-- EXE_GdbGetSurf.cpp | 1 - LUA_GdbCreateSurf.cpp | 12 ++++--- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/EXE_GdbCreateSurf.cpp b/EXE_GdbCreateSurf.cpp index a3031a3..48efc98 100644 --- a/EXE_GdbCreateSurf.cpp +++ b/EXE_GdbCreateSurf.cpp @@ -2025,7 +2025,7 @@ ExeCreateSurfBzByRegion( int nParentId, const INTVECTOR& vCrvIds, double dLinTol //------------------------------------------------------------------------------- int -ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vector3d& vtExtr, +ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vector3d& vtExtr, bool bCapEnds, double dLinTol, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; @@ -2038,7 +2038,7 @@ ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vecto // recupero le curve in locale CURVELOCALVECTOR vCrvLoc ; vCrvLoc.reserve( vCrvIds.size()) ; - ICURVEPVECTOR vCrvP ; + CICURVEPVECTOR vCrvP ; vCrvP.reserve( vCrvIds.size()) ; for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) { int nId = (( vCrvIds[i] != GDB_ID_SEL) ? vCrvIds[i] : pGeomDB->GetFirstSelectedObj()) ; @@ -2063,6 +2063,47 @@ ExeCreateSurfBzByExtrusion( int nParentId, const INTVECTOR& vCrvIds, const Vecto if ( bOk && nFirstId == GDB_ID_NULL) nFirstId = nNewId ; } + // se richiesta chiusura agli estremi + if ( bCapEnds) { + // verifico che la curva sia chiusa e piatta + Plane3d plPlane ; + double dArea ; + PolyLine plApprox ; + double dAndTolDeg = 5 ; + vCrvP[0]->ApproxWithLines( dLinTol, dAndTolDeg, ICurve::APL_STD, plApprox) ; + if ( plApprox.IsClosedAndFlat( plPlane, dArea, 50 * EPS_SMALL)) { + // componente dell'estrusione perpendicolare al piano della curva + double dOrthoExtr = plPlane.GetVersN() * vtExtr ; + if ( ( abs( dOrthoExtr) > EPS_SMALL)) { + if( vCrvIds.size() == 1) { + PtrOwner pSrfBzTop( CreateSurfBezier()) ; + pSrfBzTop->CreateByFlatContour( plApprox) ; + pSrfBzTop->Translate( vtExtrL) ; + pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzTop)) ; + PtrOwner pSrfBzBottom( CreateSurfBezier()) ; + pSrfBzBottom->CreateByFlatContour( plApprox) ; + pSrfBzBottom->Invert() ; + pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzBottom)) ; + } + else { + // riordino le curve in modo che la prima sia quella esterna e tutte le altre dopo + POLYLINEVECTOR vPL ; + Vector3d vtN ; + if ( ! CalcRegionPolyLines( vCrvP, dLinTol, vPL, vtN)) + return nFirstId ; + PtrOwner pSrfBzTop( CreateSurfBezier()) ; + pSrfBzTop->CreateByRegion( vPL) ; + pSrfBzTop->Translate( vtExtrL) ; + pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzTop)) ; + PtrOwner pSrfBzBottom( CreateSurfBezier()) ; + pSrfBzBottom->CreateByRegion( vPL) ; + pSrfBzBottom->Invert() ; + pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzBottom)) ; + } + } + } + } + ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { @@ -2141,6 +2182,36 @@ ExeCreateSurfBzByRevolve( int nParentId, int nCrvId, Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frLoc) ; // calcolo la superficie ISurfBezier* pSbz = ( bOk ? GetSurfBezierByRevolve( CrvLoc, ptAxL, vtAxL, bCapEnds, dLinTol) : nullptr) ; + //// finché non ho le SurfCompo creo qui i cap + //if ( bCapEnds) { + // // calcola la bbox della superficie + // BBox3d bbox3dSurf ; + // int nDegU, nDegV, nSpanU, nSpanV ; + // bool bTrim, bRat ; + // pSbz->GetInfo( nDegU, nDegV, nSpanU, nSpanV, bTrim, bRat) ; + // int nPointCount = ( nDegU * nSpanU + 1) * ( nDegV * nSpanV + 1) ; + // for ( int p = 0 ; p < nPointCount ; ++p) { + // bool bPointOk = true ; + // Point3d ptCtrl = pSbz->GetControlPoint( p, &bPointOk) ; + // bbox3dSurf.Add( ptCtrl) ; + // } + // // recupero i loop + // ICRVCOMPOPOVECTOR vCCLoop ; + // pSbz->GetLoops( vCCLoop, true) ; + // // devo distinguere tra il loop superiore e quello inferiore + // double dAngTolDeg = 5 ; + // PolyLine plEdge ; vCCLoop[0]->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plEdge) ; + // Plane3d plPlane ; double dArea ; + // bOk = bOk && ! plEdge.IsClosedAndFlat( plPlane, dArea, 50 * EPS_SMALL) ; + // Vector3d vtN = plPlane.GetVersN() ; + // // vedo come questa normale è orientata rispetto alla bbox della superficie + // Point3d ptCen ; vCCLoop[0]->GetCentroid( ptCen) ; + // double dDist = bbox3dSurf.DistFromPoint( ptCen) ; // questa mi dà anche valori negativi????? sennò è inutile + + // PtrOwner pSrfBzTop( CreateSurfBezier()) ; + // pSrfBzTop->CreateByFlatContour( ) + //} + // inserisco la superficie nel DB int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbz) : GDB_ID_NULL) ; ExeSetModified() ; diff --git a/EXE_GdbGetSurf.cpp b/EXE_GdbGetSurf.cpp index d12a755..4451afe 100644 --- a/EXE_GdbGetSurf.cpp +++ b/EXE_GdbGetSurf.cpp @@ -1731,7 +1731,6 @@ ExeShowSurfBezierControlPoints( int nSrfId, int nDestGrpId, int* pnCount) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) - int nParent = pGeomDB->GetParentId( nSrfId) ; // recupero la superficie di bezier IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nSrfId) ; if ( pGeoObj->GetType() != SRF_BEZIER) diff --git a/LUA_GdbCreateSurf.cpp b/LUA_GdbCreateSurf.cpp index bde8c3a..7c5f287 100644 --- a/LUA_GdbCreateSurf.cpp +++ b/LUA_GdbCreateSurf.cpp @@ -1028,22 +1028,24 @@ LuaCreateSurfBzByRegion( lua_State* L) static int LuaCreateSurfBzByExtrusion( lua_State* L) { - // 3 o 4 o 5 parametri : ParentId, CrvIds, vtExtr [, dTol] [, nRefType] + // 4 o 5 o 6 parametri : ParentId, CrvIds, vtExtr, bool bCapEnds [, dTol] [, nRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) INTVECTOR vCrvIds ; LuaCheckParam( L, 2, vCrvIds) Vector3d vtExtr ; LuaCheckParam( L, 3, vtExtr) + bool bCapEnds = false ; + LuaCheckParam( L, 4, bCapEnds) double dLinTol = LIN_TOL_SRF ; int nRefType = RTY_DEFAULT ; - if ( LuaGetParam( L, 4, dLinTol)) - LuaGetParam( L, 5, nRefType) ; + if ( LuaGetParam( L, 5, dLinTol)) + LuaGetParam( L, 6, nRefType) ; else - LuaGetParam( L, 4, nRefType) ; + LuaGetParam( L, 5, nRefType) ; LuaClearStack( L) ; // creo STM estrudendo uno o più percorsi, se piani si possono mettere i tappi - int nId = ExeCreateSurfBzByExtrusion( nParentId, vCrvIds, vtExtr, dLinTol, nRefType) ; + int nId = ExeCreateSurfBzByExtrusion( nParentId, vCrvIds, vtExtr, bCapEnds, dLinTol, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetParam( L, nId) ;