EgtExecutor :

- aggiunta della funzione SurfBzSwept.
This commit is contained in:
Daniele Bariletti
2024-09-30 15:58:15 +02:00
parent 9a6482d4cf
commit f7a8981491
2 changed files with 155 additions and 2 deletions
+119 -2
View File
@@ -2535,8 +2535,125 @@ ExeCreateSurfBzSkinned( int nParentId, const INTVECTOR& vCrvIds, bool bCapEnds,
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfbzByScrewing(" + IdToString( nParentId) + ",{" +
IdListToString( vCrvIds) + "}," +
ToString( dLinTol) + ")" +
IdListToString( vCrvIds) + "}," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateSurfBzSwept( int nParentId, int nSectId, int nGuideId, const Vector3d& vtAx,
bool bCapEnds, double dLinTol, int nRefType)
{
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 CrvSect( pGeomDB, nSectId, frLoc) ;
CurveLocal CrvGuide( pGeomDB, nGuideId, frLoc) ;
// porto in locale vettore asse
Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frLoc) ;
PolyLine plGuide ;
double dAngTolDeg = 15 ;
CrvGuide->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plGuide) ;
Plane3d plPlane ;
bool bFlatGuide = plGuide.IsFlat( plPlane) ;
// calcolo la superficie
PtrOwner<ISurfBezier> pSbz( CreateSurfBezier()) ;
if( bFlatGuide)
pSbz.Set( bOk ? GetSurfBezierSweptInPlane( CrvSect, CrvGuide, vtAxL, bCapEnds, dLinTol) : nullptr ) ;
else
pSbz.Set( bOk ? GetSurfBezierSwept3d( CrvSect, CrvGuide, vtAxL, bCapEnds, dLinTol) : nullptr ) ;
// se richiesto il capping verifico che la superficie abbia il gisto orientamento
bool bOrientedAsGuide = false ;
ICRVCOMPOPOVECTOR vCCLoop ;
if( bCapEnds) {
// controlo se il vettore di start della guida è orientato come la normale della curva o no
Vector3d vtStart ; CrvGuide->GetStartDir( vtStart) ;
Plane3d plPlane ;
double dArea ;
double dOrthoGuide = 0 ;
// verifico che la curva sia chiusa e piatta
PolyLine PL ;
CrvSect->ApproxWithLines(dLinTol, dAngTolDeg, ICurve::APL_STD, PL) ;
if ( PL.IsClosedAndFlat(plPlane, dArea, dLinTol)) {
dOrthoGuide = plPlane.GetVersN() * vtStart ;
// controllo che ci sia una componente dell'estrusione perpendicolare al piano della curva
if( abs( dOrthoGuide) < EPS_SMALL)
return GDB_ID_NULL ;
// recupero i loop
pSbz->GetLoops( vCCLoop, true) ;
// se necessario inverto la superficie
if( dOrthoGuide > EPS_SMALL)
bOrientedAsGuide = true ;
else
pSbz->Invert() ;
}
else
bCapEnds = false ;
}
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ;
// se richiesto aggiungo anche i cap
if ( bCapEnds) {
// controllo se i loop trovati sono validi
bool bValidLoop0 = false ;
bool bValidLoop2 = false ;
if( ! IsNull(vCCLoop[0]) && vCCLoop[0]->IsValid())
bValidLoop0 = true ;
if( ! IsNull(vCCLoop[2]) && vCCLoop[2]->IsValid())
bValidLoop2 = true ;
if( ! IsNull(vCCLoop[0]) && ! vCCLoop[0]->IsValid())
return GDB_ID_NULL ;
if( ! IsNull(vCCLoop[2]) && ! vCCLoop[2]->IsValid())
return GDB_ID_NULL ;
// il getLoops per superfici non trimmate restituisce 1 elemento per ogni lato dello spazio parametrico.
// in questo caso la superficie è chiusa lungo il parametro V, quindi i lati 1 e 3 saranno null.
double dAngTolDeg = 5 ;
PolyLine plEdge0 ;
if( bValidLoop0)
vCCLoop[0]->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plEdge0) ;
PolyLine plEdge2 ;
if( bValidLoop2)
vCCLoop[2]->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plEdge2) ;
PtrOwner<ISurfBezier> pSrfBezStart( CreateSurfBezier()) ;
pSrfBezStart->CreateByFlatContour( plEdge2) ;
// se necessario inverto
if( bOrientedAsGuide) // edge 2, che è la prima riga della matrice dei punti di controllo è orientato nello stesso verso della curva di sezione
pSrfBezStart->Invert() ;
// aggiungo al database
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBezStart)) ;
PtrOwner<ISurfBezier> pSrfBezEnd( CreateSurfBezier()) ;
pSrfBezEnd->CreateByFlatContour( plEdge0) ;
// se necessario inverto
if( bOrientedAsGuide) // edge 0, che è l'ultima riga della matrice dei punti di controllo è orientato in verso opposto alla curva di sezione
pSrfBezEnd->Invert() ;
// aggiungo al database
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBezEnd)) ;
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfbzByScrewing(" + IdToString( nParentId) + "," +
IdToString( nSectId) + "," +
IdToString( nGuideId) + "," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
+36
View File
@@ -1246,6 +1246,41 @@ LuaCreateSurfBzSkinned( lua_State* L)
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaCreateSurfBzSwept( lua_State* L)
{
// 3 o 4 o 5 o 6 o 7 parametri : ParentId, nSectCrvId, nGuideCrvId [, vtAx] [, bCapEnds] [, dTol] [, nRefType]
int nParentId ;
LuaCheckParam( L, 1, nParentId)
int nSectId ;
LuaCheckParam( L, 2, nSectId)
int nGuideId ;
LuaCheckParam( L, 3, nGuideId)
Vector3d vtAx = V_NULL ;
int nPar = 4 ;
if ( LuaGetParam( L, nPar, vtAx))
++ nPar ;
bool bCapEnds = false ;
if ( LuaGetParam( L, nPar, bCapEnds))
++ nPar ;
double dLinTol = LIN_TOL_SRF ;
if ( LuaGetParam( L, nPar, dLinTol))
++ nPar ;
int nRefType = RTY_DEFAULT ;
if ( LuaGetParam( L, nPar, dLinTol))
++ nPar ;
LuaClearStack( L) ;
// creo STM riempiendo un contorno piano
int nId = ExeCreateSurfBzSwept( nParentId, nSectId, nGuideId, vtAx, bCapEnds, dLinTol, nRefType) ;
// restituisco il risultato
if ( nId != GDB_ID_NULL)
LuaSetParam( L, nId) ;
else
LuaSetParam( L) ;
return 1 ;
}
//-------------------------------------------------------------------------------
bool
LuaInstallGdbCreateSurf( LuaMgr& luaMgr)
@@ -1294,5 +1329,6 @@ LuaInstallGdbCreateSurf( LuaMgr& luaMgr)
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzByPointCurve", LuaCreateSurfBzByPointCurve) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzRuled", LuaCreateSurfBzRuled) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzSkinned", LuaCreateSurfBzSkinned) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBzSwept", LuaCreateSurfBzSwept) ;
return bOk ;
}