EgtExecutor :
- aggiunta della funzione per disegnare i triangoli nello spazio parametrico di una superifcie Bezier - aggiunto il calcolo dei punti di polo nelle funzioni che creano superfici di Bezier.
This commit is contained in:
@@ -1640,6 +1640,8 @@ ExeCreateSurfBezier( int nParentId, int nDegU, int nDegV, int nSpanU, int nSpanV
|
||||
if ( ! pSurfBez->SetControlPoint( i, ptCtrl))
|
||||
bOk = false ;
|
||||
}
|
||||
// calcolo eventuali poli
|
||||
pSurfBez->CalcPoles() ;
|
||||
// se superficie nulla (ovvero ridotta a punto), errore
|
||||
bOk = bOk && ! pSurfBez->IsAPoint() ;
|
||||
// inserisco la superficie nel DB
|
||||
@@ -1692,6 +1694,8 @@ ExeCreateSurfBezierRational( int nParentId, int nDegU, int nDegV, int nSpanU, in
|
||||
if ( ! pSurfBez->SetControlPoint( i, ptCtrl, vPntW[i].second))
|
||||
bOk = false ;
|
||||
}
|
||||
// calcolo eventuali poli
|
||||
pSurfBez->CalcPoles() ;
|
||||
// se superficie nulla (ovvero ridotta a punto), errore
|
||||
bOk = bOk && ! pSurfBez->IsAPoint() ;
|
||||
// inserisco la superficie nel DB
|
||||
@@ -1785,6 +1789,74 @@ ExeCreateSurfBezierLeaves( int nParentId, int nSurfBzId, int nTextHeight, bool b
|
||||
return nFirstId ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
int
|
||||
ExeCreateSurfBezierTria2D( int nParentId, int nSurfBzId, int nTextHeight, bool bShowTrim, int* pnCount)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
nParentId = AdjustId( nParentId) ;
|
||||
// recupero la superficie
|
||||
const ISurfBezier* pSurfBez = GetSurfBezier( pGeomDB->GetGeoObj( nSurfBzId)) ;
|
||||
if ( pSurfBez == nullptr)
|
||||
return GDB_ID_NULL ;
|
||||
// disegno i triangoli
|
||||
vector<tuple<int,Point3d,Point3d,Point3d>> vTria2D ;
|
||||
pSurfBez->GetTriangles2D( vTria2D) ;
|
||||
int nFirstId = GDB_ID_NULL ;
|
||||
int nCount = 0 ;
|
||||
bool bOk = true ;
|
||||
for ( int k = 0 ; k < (int)vTria2D.size() ; ++ k) {
|
||||
PtrOwner<ISurfTriMesh> pStm( CreateSurfTriMesh()) ;
|
||||
bOk = bOk && ! IsNull( pStm) ;
|
||||
Point3d ptP1L = get<1>(vTria2D[k]) ;
|
||||
Point3d ptP2L = get<2>(vTria2D[k]) ;
|
||||
Point3d ptP3L = get<3>(vTria2D[k]) ;
|
||||
// assegno il triangolo
|
||||
if ( bOk) {
|
||||
pStm->Init( 3, 1, 1) ;
|
||||
int vV[3]{ pStm->AddVertex( ptP1L),
|
||||
pStm->AddVertex( ptP2L),
|
||||
pStm->AddVertex( ptP3L)} ;
|
||||
bOk = ( pStm->AddTriangle( vV) != SVT_NULL) && pStm->AdjustTopology() ;
|
||||
}
|
||||
// inserisco la superficie nel DB
|
||||
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pStm)) : GDB_ID_NULL) ;
|
||||
if ( nNewId == GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
if ( nFirstId == GDB_ID_NULL)
|
||||
nFirstId = nNewId ;
|
||||
++ nCount ;
|
||||
|
||||
// creo il testo e lo riempio
|
||||
string sText = ToString( get<0>( vTria2D[k])) ;
|
||||
Point3d ptCenter( ( ptP1L + ptP2L + ptP3L) / 3) ;
|
||||
PtrOwner<IExtText> pTXT( CreateExtText()) ;
|
||||
if ( IsNull( pTXT) || ! pTXT->Set( ptCenter, Z_AX, X_AX, sText, "", false, nTextHeight))
|
||||
return GDB_ID_NULL ;
|
||||
// inserisco il testo nel DB
|
||||
int nTxtId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pTXT)) ;
|
||||
if ( nTxtId == GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
++ nCount ;
|
||||
}
|
||||
// se richiesto disegno la regione di trim
|
||||
const ISurfFlatRegion* pSfr = pSurfBez->GetTrimRegion() ;
|
||||
if ( bShowTrim && pSfr != nullptr) {
|
||||
PtrOwner<ISurfFlatRegion> pTrimReg( pSfr->Clone()) ;
|
||||
if ( ! IsNull( pTrimReg)) {
|
||||
int nTrimId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pTrimReg)) ;
|
||||
if ( nTrimId == GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
++ nCount ;
|
||||
}
|
||||
}
|
||||
// restituisco i risultati
|
||||
if ( pnCount != nullptr)
|
||||
*pnCount = nCount ;
|
||||
return nFirstId ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
int
|
||||
ExeCreateBezierSphere( int nParentId, const Point3d& ptCenter, double dR, int nRefType) {
|
||||
@@ -1799,6 +1871,7 @@ ExeCreateBezierSphere( int nParentId, const Point3d& ptCenter, double dR, int nR
|
||||
Point3d ptCenterLoc = GetPointLocal( pGeomDB, ptCenter, nRefType, frLoc) ;
|
||||
// Creo la superficie
|
||||
PtrOwner<ISurfBezier> pSurfBez( CreateBezierSphere( ptCenterLoc, dR)) ;
|
||||
pSurfBez->CalcPoles() ;
|
||||
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSurfBez)) : GDB_ID_NULL) ;
|
||||
ExeSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
|
||||
@@ -903,6 +903,39 @@ LuaCreateSurfBezierLeaves( lua_State* L)
|
||||
return 2 ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
static int
|
||||
LuaCreateSurfBezierTria2D( lua_State* L)
|
||||
{
|
||||
// 2, 3 o 4 parametri : ParentId, nId [, nTextHeight] [, bShowTrim]
|
||||
int nParentId ;
|
||||
LuaCheckParam( L, 1, nParentId)
|
||||
int nSurfBzId ;
|
||||
LuaCheckParam( L, 2, nSurfBzId)
|
||||
int nTextHeight = 50 ;
|
||||
bool bShowTrim = false ;
|
||||
if ( LuaGetParam( L, 3, nTextHeight))
|
||||
LuaGetParam( L, 4, bShowTrim) ;
|
||||
else
|
||||
LuaGetParam( L, 3, bShowTrim) ;
|
||||
LuaClearStack( L) ;
|
||||
// creo la superficie
|
||||
int nCount = 0 ;
|
||||
int nId = ExeCreateSurfBezierTria2D( nParentId, nSurfBzId, nTextHeight, bShowTrim, &nCount) ;
|
||||
// restituisco il risultato
|
||||
if ( nId != GDB_ID_NULL) {
|
||||
LuaSetParam( L, nId) ;
|
||||
LuaSetParam( L, nCount) ;
|
||||
}
|
||||
else {
|
||||
LuaSetParam( L) ;
|
||||
LuaSetParam( L) ;
|
||||
}
|
||||
return 2 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
static int
|
||||
LuaCreateBezierSphere( lua_State* L)
|
||||
@@ -968,6 +1001,7 @@ LuaInstallGdbCreateSurf( LuaMgr& luaMgr)
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezier", LuaCreateSurfBezier) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierRat", LuaCreateSurfBezierRational) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierLeaves", LuaCreateSurfBezierLeaves) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierTria2D", LuaCreateSurfBezierTria2D) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtCreateBezierSphere", LuaCreateBezierSphere) ;
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user