diff --git a/EXE_GdbCreateSurf.cpp b/EXE_GdbCreateSurf.cpp index 3af6883..24c7cf2 100644 --- a/EXE_GdbCreateSurf.cpp +++ b/EXE_GdbCreateSurf.cpp @@ -2668,6 +2668,88 @@ ExeCreateSurfBzRuled( int nParentId, int nCrvId1, int nCrvId2, int nRuledType, b return nNewId ; } +//------------------------------------------------------------------------------- +int +ExeCreateSurfBzRuledGuided( int nParentId, int nCrvId1, int nCrvId2, int nLayGuides, bool bCapEnds, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nParentId = AdjustId( nParentId) ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // recupero le curve in locale + CurveLocal CrvLoc1( pGeomDB, nCrvId1, frLoc) ; + bOk = bOk && ( CrvLoc1.Get() != nullptr) ; + CurveLocal CrvLoc2( pGeomDB, nCrvId2, frLoc) ; + bOk = bOk && ( CrvLoc2.Get() != nullptr) ; + ICURVEPOVECTOR vCrv ; + int nId = pGeomDB->GetFirstInGroup( nLayGuides) ; + while( nId != GDB_ID_NULL && bOk) { + CurveLocal CrvLocGuide( pGeomDB, nId, frLoc) ; + bOk = bOk && ( CrvLocGuide.Get() != nullptr) ; + vCrv.emplace_back( CrvLocGuide.Get()->Clone()) ; + nId = pGeomDB->GetNext( nId) ; + } + + // calcolo la superficie + PtrOwner pSbz( bOk ? GetSurfBezierRuledGuided( CrvLoc1, CrvLoc2, vCrv, dLinTol) : nullptr) ; + bOk = bOk && ! IsNull( pSbz) ; + // verifiche per orientamento se con tappi + bool bWithCaps = false ; + bool bStdOrient = true ; + Plane3d plPlane1, plPlane2 ; + double dArea1, dArea2 ; + if ( bOk && bCapEnds && + CrvLoc1->IsClosed() && CrvLoc2->IsClosed() && CrvLoc1->GetArea( plPlane1, dArea1) && CrvLoc2->GetArea( plPlane2, dArea2)) { + bWithCaps = true ; + Point3d ptStart1 ; CrvLoc1->GetStartPoint( ptStart1) ; + Point3d ptStart2 ; CrvLoc2->GetStartPoint( ptStart2) ; + Vector3d vtRuling = ptStart2 - ptStart1 ; + bStdOrient = ( vtRuling * plPlane1.GetVersN() > 0) ; + if ( ! bStdOrient) + pSbz->Invert() ; + } + + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ; + + // se richiesto inserisco anche il cap + if ( bOk && bWithCaps) { + // costruisco la superficie dalla curva 1 + PtrOwner pSbzFlat1( CreateSurfBezier()) ; + double dAngTolDeg = 5 ; + PolyLine pl1 ; CrvLoc1->ApproxWithLines(dLinTol, dAngTolDeg, ICurve::APL_STD, pl1) ; + pSbzFlat1->CreateByFlatContour( pl1) ; + if ( bStdOrient) + pSbzFlat1->Invert() ; + // inserisco la superficie nel DB + bOk = bOk && pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbzFlat1)) ; + // costruisco la superficie dalla curva 2 + PtrOwner pSbzFlat2( CreateSurfBezier()) ; + PolyLine pl2 ; CrvLoc2->ApproxWithLines(dLinTol, dAngTolDeg, ICurve::APL_STD, pl2) ; + pSbzFlat2->CreateByFlatContour( pl2) ; + if ( ! bStdOrient) + pSbzFlat2->Invert() ; + // inserisco la superficie nel DB + bOk = bOk && pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbzFlat2)) ; + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfBzRuledGuided(" + IdToString( nParentId) + "," + + ToString( nCrvId1) + "," + + ToString( nCrvId2) + "," + + ( bCapEnds ? "true" : "false") + "," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + //------------------------------------------------------------------------------- int ExeCreateSurfBzSkinned( int nParentId, const INTVECTOR& vCrvIds, bool bCapEnds, double dLinTol) diff --git a/LUA_GdbCreateSurf.cpp b/LUA_GdbCreateSurf.cpp index a96b2c0..38e6fcf 100644 --- a/LUA_GdbCreateSurf.cpp +++ b/LUA_GdbCreateSurf.cpp @@ -1349,7 +1349,7 @@ LuaCreateSurfBzRuled( lua_State* L) double dLinTol = LIN_TOL_SRF ; LuaGetParam( L, nPar, dLinTol) ; LuaClearStack( L) ; - // creo STM riempiendo un contorno piano + // creo una surf bezier come rigata tra le due curve passate int nId = ExeCreateSurfBzRuled( nParentId, nCrvId1, nCrvId2, nRuledType, bCapEnds, dLinTol) ; // restituisco il risultato if ( nId != GDB_ID_NULL) @@ -1359,6 +1359,36 @@ LuaCreateSurfBzRuled( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaCreateSurfBzRuledGuided( lua_State* L) +{ + // 4 o 5 o 6 parametri : ParentId, CrvId1, CrvId2 nLayGuides [, bCapEnds] [, dTol] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nCrvId1 ; + LuaCheckParam( L, 2, nCrvId1) + int nCrvId2 ; + LuaCheckParam( L, 3, nCrvId2) + int nLayGuides ; + LuaCheckParam( L, 4, nLayGuides) + bool bCapEnds = false ; + int nPar = 5 ; + if ( LuaGetParam( L, nPar, bCapEnds)) + ++ nPar ; + double dLinTol = LIN_TOL_SRF ; + LuaGetParam( L, nPar, dLinTol) ; + LuaClearStack( L) ; + // creo una surf bezier come rigata tra le due curve passate, usando le isocurve nel layer nLayIso + int nId = ExeCreateSurfBzRuledGuided( nParentId, nCrvId1, nCrvId2, nLayGuides, bCapEnds, dLinTol) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaCreateSurfBzSkinned( lua_State* L) @@ -1472,6 +1502,7 @@ LuaInstallGdbCreateSurf( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzByRevolve", LuaCreateSurfBzByRevolve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzByPointCurve", LuaCreateSurfBzByPointCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzRuled", LuaCreateSurfBzRuled) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzRuledGuided", LuaCreateSurfBzRuledGuided) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzSkinned", LuaCreateSurfBzSkinned) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzSwept", LuaCreateSurfBzSwept) ; return bOk ;