Merge remote-tracking branch 'origin/master' into MoreBezier

This commit is contained in:
Daniele Bariletti
2024-10-04 15:34:54 +02:00
5 changed files with 373 additions and 202 deletions
+279 -158
View File
@@ -1872,9 +1872,9 @@ ExeCreateSurfBezierTria2D( int nParentId, int nSurfBzId, int nTextHeight, bool b
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]) ;
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) ;
@@ -1922,7 +1922,8 @@ ExeCreateSurfBezierTria2D( int nParentId, int nSurfBzId, int nTextHeight, bool b
//-------------------------------------------------------------------------------
int
ExeCreateBezierSphere( int nParentId, const Point3d& ptCenter, double dR, int nRefType) {
ExeCreateBezierSphere( int nParentId, const Point3d& ptCenter, double dR, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
@@ -1934,18 +1935,19 @@ ExeCreateBezierSphere( int nParentId, const Point3d& ptCenter, double dR, int nR
Point3d ptCenterLoc = GetPointLocal( pGeomDB, ptCenter, nRefType, frLoc) ;
// Creo la superficie
PtrOwner<ISurfBezier> pSurfBez( GetSurfBezierSphere( ptCenterLoc, dR)) ;
bOk = bOk && ! IsNull( pSurfBez) ;
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSurfBez)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCreateBezierSphere(" + IdToString( nParentId) + "," +
ToString( ptCenter) + "," +
ToString( dR) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
string sLua = "EgtSurfBzSphere(" + IdToString( nParentId) + "," +
ToString( ptCenter) + "," +
ToString( dR) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// resituisco l'identificativo dell'entit creata
// resituisco l'identificativo dell'entità creata
return nId ;
}
@@ -1957,26 +1959,27 @@ ExeCreateSurfBzByFlatContour( int nParentId, int nCrvId, double dLinTol)
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// recupero la curva in locale
// recupero la curva in locale
CurveLocal CrvLoc( pGeomDB, nCrvId, frLoc) ;
bOk = bOk && ( CrvLoc.Get() != nullptr) ;
// calcolo la superficie
ISurfBezier* pSbz = ( bOk ? GetSurfBezierByFlatContour( CrvLoc, dLinTol) : nullptr) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbz) : GDB_ID_NULL) ;
// calcolo la superficie
PtrOwner<ISurfBezier> pSbz( bOk ? GetSurfBezierByFlatContour( CrvLoc, dLinTol) : nullptr) ;
bOk = bOk && ! IsNull( pSbz) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfBzByFlatContour(" + IdToString( nParentId) + "," +
ToString( nCrvId) + "," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
// restituisco l'identificativo della nuova entità
return nNewId ;
}
@@ -2007,17 +2010,17 @@ ExeCreateSurfBzByRegion( int nParentId, const INTVECTOR& vCrvIds, double dLinTol
}
}
// calcolo la superficie
ISurfBezier* pSbz = ( bOk ? GetSurfBezierByRegion( vCrvP, dLinTol) : nullptr) ;
bOk = bOk && ( pSbz != nullptr) ;
PtrOwner<ISurfBezier> pSbz( bOk ? GetSurfBezierByRegion( vCrvP, dLinTol) : nullptr) ;
bOk = bOk && ! IsNull( pSbz) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbz) : GDB_ID_NULL) ;
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfBzByRegion(" + IdToString( nParentId) + ",{" +
IdListToString( vCrvIds) + "}," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
@@ -2033,18 +2036,18 @@ ExeCreateSurfBzByExtrusion( int nParentId, int nCrvId, const Vector3d& vtExtr, b
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
//recupero il riferimento della curva
// recupero il riferimento della curva
Frame3d frCrv ;
bOk = bOk && pGeomDB->GetGlobFrame( nCrvId, frCrv) ;
// recupero la curva in locale
// recupero la curva in locale
const ICurve* pCrvOrig = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
PtrOwner<ICurve> pCrv( pCrvOrig->Clone()) ;
// porto in locale il vettore estrusione
// porto in locale il vettore estrusione
Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr, nRefType, frLoc) ;
// creo la superficie e la inserisco nel DB
// creo la superficie e la inserisco nel DB
int nFirstId = GDB_ID_NULL ;
double dAndTolStdDeg = 15 ;
Plane3d plPlane ;
@@ -2056,17 +2059,18 @@ ExeCreateSurfBzByExtrusion( int nParentId, int nCrvId, const Vector3d& vtExtr, b
dOrthoExtr = plPlane.GetVersN() * vtExtr ;
if ( ( abs( dOrthoExtr) < EPS_SMALL))
return GDB_ID_NULL ;
if( dOrthoExtr < 0)
if ( dOrthoExtr < 0)
pCrv->Invert() ;
}
// creo l'estrusione della curva
ISurfBezier* pSbz = ( bOk ? GetSurfBezierByExtrusion( pCrv, vtExtrL, false, dLinTol) : nullptr ) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbz) : GDB_ID_NULL) ;
// creo l'estrusione della curva
PtrOwner<ISurfBezier> pSbz( bOk ? GetSurfBezierByExtrusion( pCrv, vtExtrL, false, dLinTol) : nullptr ) ;
bOk = bOk && ! IsNull( pSbz) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ;
bOk = bOk && ( nNewId != GDB_ID_NULL) ;
// se richiesta chiusura agli estremi
if ( bCapEnds) {
// se richiesta chiusura agli estremi
if ( bCapEnds && bOk) {
PtrOwner<ISurfBezier> pSrfBzTop( CreateSurfBezier()) ;
pSrfBzTop->CreateByFlatContour( plApprox) ;
pSrfBzTop->Translate( vtExtrL) ;
@@ -2078,17 +2082,18 @@ ExeCreateSurfBzByExtrusion( int nParentId, int nCrvId, const Vector3d& vtExtr, b
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfBzByExtrusion(" + IdToString( nParentId) + "," +
IdToString( nCrvId) + ",{" +
ToString( vtExtr) + "}," +
( bCapEnds ? "true" : "false") + "," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nFirstId) ;
" -- Id=" + ToString( nFirstId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
// restituisco l'identificativo della nuova entità
return nFirstId ;
}
@@ -2101,10 +2106,10 @@ ExeCreateSurfBzByRegionExtrusion( int nParentId, const INTVECTOR& vCrvIds, const
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// recupero le curve in locale
// recupero le curve in locale
CURVELOCALVECTOR vCrvLoc ;
vCrvLoc.reserve( vCrvIds.size()) ;
CICURVEPVECTOR vCrvP ;
@@ -2115,17 +2120,17 @@ ExeCreateSurfBzByRegionExtrusion( int nParentId, const INTVECTOR& vCrvIds, const
vCrvLoc.emplace_back( pGeomDB, nId, frLoc) ;
vCrvP.push_back( const_cast<ICurve*>( vCrvLoc.back().Get())) ;
bOk = bOk && ( vCrvLoc[i].Get() != nullptr) ;
// passo al successivo
// passo al successivo
nId = (( vCrvIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ;
}
}
// porto in locale il vettore estrusione
// porto in locale il vettore estrusione
Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr, nRefType, frLoc) ;
// creo le superfici e le inserisco nel DB
// creo le superfici e le inserisco nel DB
int nFirstId = GDB_ID_NULL ;
double dAndTolStdDeg = 15 ;
// riordino le curve in modo che la prima sia quella esterna e tutte le altre dopo
// riordino le curve in modo che la prima sia quella esterna e tutte le altre dopo
POLYLINEVECTOR vPL ;
for ( int i = 0 ; i < int( vCrvP.size()) ; ++ i) {
vPL.emplace_back() ;
@@ -2138,73 +2143,74 @@ ExeCreateSurfBzByRegionExtrusion( int nParentId, const INTVECTOR& vCrvIds, const
if ( ! CalcRegionPolyLines( vPL, vtN, vnPLIndMat, vbInvert))
return nFirstId ;
// creo una copia delle curve, orientate giuste
// creo una copia delle curve, orientate giuste
ICURVEPOVECTOR vpCrvOr ;
for (int i = 0 ; i < int( vnPLIndMat.size()) ; ++i) {
for ( int j = 0 ; j< int( vnPLIndMat[i].size()) ; ++j) {
vpCrvOr.emplace_back( vCrvP[vnPLIndMat[i][j]]->Clone()) ;
if( vbInvert[vnPLIndMat[i][j]])
if ( vbInvert[vnPLIndMat[i][j]])
vpCrvOr.back()->Invert() ;
}
}
// controlo se il vettore di estrusione è orientato come la normale della curva più grande o no
// controlo se il vettore di estrusione è orientato come la normale della curva più grande o no
bool bOrientedAsExtrusion = false ;
Plane3d plPlane ;
double dArea ;
double dOrthoExtr = 0 ;
// verifico che la curva sia chiusa e piatta
// verifico che la curva sia chiusa e piatta
if ( vPL[0].IsClosedAndFlat(plPlane, dArea, dLinTol)) {
dOrthoExtr = plPlane.GetVersN() * vtExtr ;
// controllo che ci sia una componente dell'estrusione perpendicolare al piano della curva
if( abs( dOrthoExtr) < EPS_SMALL)
// controllo che ci sia una componente dell'estrusione perpendicolare al piano della curva
if ( abs( dOrthoExtr) < EPS_SMALL)
return GDB_ID_NULL ;
if( dOrthoExtr > EPS_SMALL)
if ( dOrthoExtr > EPS_SMALL)
bOrientedAsExtrusion = true ;
}
else
bCapEnds = false ;
// creo l'estrusione delle curve
// creo l'estrusione delle curve
for ( int i = 0 ; i < int( vpCrvOr.size()) ; ++ i) {
// calcolo la superficie
// calcolo la superficie
ISurfBezier* pSbz = ( bOk ? GetSurfBezierByExtrusion( vpCrvOr[i], vtExtrL, false, dLinTol) : nullptr ) ;
if( ! bOrientedAsExtrusion)
if ( ! bOrientedAsExtrusion)
pSbz->Invert() ;
// inserisco la superficie nel DB
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbz) : GDB_ID_NULL) ;
bOk = bOk && ( nNewId != GDB_ID_NULL) ;
if ( bOk && nFirstId == GDB_ID_NULL)
nFirstId = nNewId ;
}
// se richiesta chiusura agli estremi
// se richiesta chiusura agli estremi
if ( bCapEnds) {
PtrOwner<ISurfBezier> pSrfBzTop( CreateSurfBezier()) ;
pSrfBzTop->CreateByRegion( vPL) ;
pSrfBzTop->Translate( vtExtrL) ;
if( ! bOrientedAsExtrusion)
if ( ! bOrientedAsExtrusion)
pSrfBzTop->Invert() ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzTop)) ;
PtrOwner<ISurfBezier> pSrfBzBottom( CreateSurfBezier()) ;
pSrfBzBottom->CreateByRegion( vPL) ;
if( bOrientedAsExtrusion)
if ( bOrientedAsExtrusion)
pSrfBzBottom->Invert() ;
pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSrfBzBottom)) ;
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfBzByExtrusion(" + IdToString( nParentId) + ",{" +
IdListToString( vCrvIds) + "},{" +
ToString( vtExtr) + "}," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nFirstId) ;
string sLua = "EgtSurfBzByRegionExtrusion(" + IdToString( nParentId) + ",{" +
IdListToString( vCrvIds) + "},{" +
ToString( vtExtr) + "}," +
( bCapEnds ? "true" : "false") + "," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nFirstId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
// restituisco l'identificativo della nuova entità
return nFirstId ;
}
@@ -2218,19 +2224,19 @@ ExeCreateSurfBzByScrewing( int nParentId, int nCrvId,
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// recupero la curva in locale
// recupero la curva in locale
CurveLocal CrvLoc( pGeomDB, nCrvId, frLoc) ;
bOk = bOk && ( CrvLoc.Get() != nullptr) ;
// porto in locale punto e vettore asse
// porto in locale punto e vettore asse
Point3d ptAxL = GetPointLocal( pGeomDB, ptAx, nRefType, frLoc) ;
Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frLoc) ;
vtAxL.Normalize() ;
// la curva che fa da sezione alla superficie è chiusa e piana ed è richiesto il capping verifico se la superficie è da invertire
// lo screwing non deve essere una semplice rivoluzione
// la curva che fa da sezione alla superficie è chiusa e piana ed è richiesto il capping verifico se la superficie è da invertire
// lo screwing non deve essere una semplice rivoluzione
bool bOrientedAsScrewing = false ;
Plane3d plPlane ;
double dArea = 0 ;
@@ -2256,17 +2262,18 @@ ExeCreateSurfBzByScrewing( int nParentId, int nCrvId,
else
bCapEnds = false ;
// calcolo la superficie
ISurfBezier* pSbz = ( bOk ? GetSurfBezierByScrewing( CrvLoc, ptAxL, vtAxL, dAngRotDeg, dMove, bCapEnds, dLinTol) : nullptr) ;
if( ! bOrientedAsScrewing && bCapEnds)
// calcolo la superficie
PtrOwner<ISurfBezier> pSbz( bOk ? GetSurfBezierByScrewing( CrvLoc, ptAxL, vtAxL, dAngRotDeg, dMove, bCapEnds, dLinTol) : nullptr) ;
bOk = bOk && ! IsNull( pSbz) ;
if ( ! bOrientedAsScrewing && bCapEnds && bOk)
pSbz->Invert() ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbz) : GDB_ID_NULL) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ;
// se richiesto creo anche i cap
if ( bCapEnds && bOk) {
// se richiesto creo anche i cap
if ( bCapEnds && bOk) {
ISurfBezier* pSbzBase1 = GetSurfBezierByFlatContour(CrvLoc,dLinTol) ;
if( bOrientedAsScrewing)
if ( bOrientedAsScrewing)
pSbzBase1->Invert() ;
bOk = bOk && pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbzBase1) ;
ISurfBezier* pSbzBase2 = GetSurfBezierByFlatContour( CrvLoc,dLinTol) ;
@@ -2277,7 +2284,7 @@ ExeCreateSurfBzByScrewing( int nParentId, int nCrvId,
bOk = bOk && pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSbzBase2) ;
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfbzByScrewing(" + IdToString( nParentId) + "," +
ToString( nCrvId) + ",{" +
@@ -2288,30 +2295,30 @@ ExeCreateSurfBzByScrewing( int nParentId, int nCrvId,
( bCapEnds ? "true" : "false") + "," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
// restituisco l'identificativo della nuova entità
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateSurfBzByRevolve( int nParentId, int nCrvId,
const Point3d& ptAx, const Vector3d& vtAx,
bool bCapEnds, double dLinTol, int nRefType)
const Point3d& ptAx, 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
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// recupero la curva in locale
// recupero la curva in locale
CurveLocal CrvLoc( pGeomDB, nCrvId, frLoc) ;
bOk = bOk && ( CrvLoc.Get() != nullptr) ;
// porto in locale punto e vettore asse
// porto in locale punto e vettore asse
Point3d ptAxL = GetPointLocal( pGeomDB, ptAx, nRefType, frLoc) ;
Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frLoc) ;
// calcolo la superficie
@@ -2333,8 +2340,8 @@ ExeCreateSurfBzByRevolve( int nParentId, int nCrvId,
pSbz->Invert() ;
// finché non ho le SurfCompo creo qui i cap
if ( bCapEnds && ! CrvLoc->IsClosed()) {
// calcola la bbox della superficie
if ( bCapEnds && bOk) {
// calcola il bbox della superficie
BBox3d bbox3dSurf ;
int nDegU, nDegV, nSpanU, nSpanV ;
bool bTrim, bRat ;
@@ -2345,7 +2352,7 @@ ExeCreateSurfBzByRevolve( int nParentId, int nCrvId,
Point3d ptCtrl = pSbz->GetControlPoint( p, &bPointOk) ;
bbox3dSurf.Add( ptCtrl) ;
}
// recupero i loop
// recupero i loop
ICRVCOMPOPOVECTOR vCCLoop ;
pSbz->GetLoops( vCCLoop, true) ;
// controllo se i loop trovati sono validi
@@ -2360,8 +2367,8 @@ ExeCreateSurfBzByRevolve( int nParentId, int nCrvId,
return GDB_ID_NULL ;
if( ! IsNull(vCCLoop[3]) && ! vCCLoop[3]->IsValid() && ! bEndOnAx)
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 0 e 2 saranno 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 0 e 2 saranno null.
double dAngTolDeg = 5 ;
PolyLine plEdge1 ;
if( bValidLoop1)
@@ -2409,16 +2416,16 @@ ExeCreateSurfBzByRevolve( int nParentId, int nCrvId,
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfbzByScrewing(" + IdToString( nParentId) + "," +
ToString( nCrvId) + ",{" +
ToString( ptAx) + "},{" +
ToString( vtAx) + "}," +
( bCapEnds ? "true" : "false") + "," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
string sLua = "EgtSurfBzByRevolve(" + IdToString( nParentId) + "," +
ToString( nCrvId) + ",{" +
ToString( ptAx) + "},{" +
ToString( vtAx) + "}," +
( bCapEnds ? "true" : "false") + "," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
@@ -2433,71 +2440,66 @@ ExeCreateSurfBzRuled( int nParentId, int nCrvId1, int nCrvId2, int nRuledType, b
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// recupero le curve in locale
// 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) ;
// calcolo la superficie
ISurfBezier* pSbz = ( bOk ? GetSurfBezierRuled( CrvLoc1, CrvLoc2, nRuledType, dLinTol) : nullptr) ;
// se le curve sono chiuse e la superficie guarda all'interno del "cilindro" allora inverto la superficie
Vector3d vtRuling ;
if ( CrvLoc1->IsClosed() && CrvLoc2->IsClosed()) {
// calcolo la superficie
PtrOwner<ISurfBezier> pSbz( bOk ? GetSurfBezierRuled( CrvLoc1, CrvLoc2, nRuledType, 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) ;
vtRuling = ptStart2 - ptStart1 ;
double dAngTolDeg = 15 ;
PolyLine plApprox ; CrvLoc1->ApproxWithLines( dLinTol, dAngTolDeg, ICurve::APL_STD, plApprox) ;
Plane3d plPlane ;
double dArea ;
plApprox.IsClosedAndFlat( plPlane, dArea) ;
double dOrtho = plPlane.GetVersN() * vtRuling ;
if( dOrtho < 0)
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, pSbz) : GDB_ID_NULL) ;
// 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 ( bCapEnds && bOk) {
Plane3d plPlane1, plPlane2 ;
if ( CrvLoc1->IsClosed() && CrvLoc1->IsFlat( plPlane1) && CrvLoc2->IsClosed() && CrvLoc2->IsFlat( plPlane2)) {
// costruisco la superficie dalla curva 1
PtrOwner<ISurfBezier> pSbzFlat1( CreateSurfBezier()) ;
double dAngTolDeg = 5 ;
PolyLine pl1 ; CrvLoc1->ApproxWithLines(dLinTol, dAngTolDeg, ICurve::APL_STD, pl1) ;
pSbzFlat1->CreateByFlatContour( pl1) ;
Plane3d plPlane1 ; double dArea1 ;
pl1.IsClosedAndFlat( plPlane1, dArea1) ;
if( plPlane1.GetVersN() * vtRuling > 0)
pSbzFlat1->Invert() ;
// inserisco la superficie nel DB
bOk = bOk && pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbzFlat1)) ;
// costruisco la superficie dalla curva 2
PtrOwner<ISurfBezier> pSbzFlat2( CreateSurfBezier()) ;
PolyLine pl2 ; CrvLoc2->ApproxWithLines(dLinTol, dAngTolDeg, ICurve::APL_STD, pl2) ;
pSbzFlat2->CreateByFlatContour( pl2) ;
Plane3d plPlane2 ; double dArea2 ;
pl2.IsClosedAndFlat( plPlane2, dArea2) ;
if( plPlane2.GetVersN() * vtRuling < 0)
pSbzFlat2->Invert() ;
// inserisco la superficie nel DB
bOk = bOk && pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbzFlat2)) ;
}
// se richiesto inserisco anche il cap
if ( bOk && bWithCaps) {
// costruisco la superficie dalla curva 1
PtrOwner<ISurfBezier> 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<ISurfBezier> 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
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfbzByScrewing(" + IdToString( nParentId) + "," +
ToString( nCrvId1) + "," +
ToString( nCrvId2) + "," +
ToString( nRuledType) + "," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
string sLua = "EgtSurfBzRuled(" + IdToString( nParentId) + "," +
ToString( nCrvId1) + "," +
ToString( nCrvId2) + "," +
ToString( nRuledType) + "," +
( bCapEnds ? "true" : "false") + "," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
@@ -2512,10 +2514,10 @@ ExeCreateSurfBzSkinned( int nParentId, const INTVECTOR& vCrvIds, bool bCapEnds,
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// recupero le curve in locale
// recupero le curve in locale
CURVELOCALVECTOR vCrvLoc ;
vCrvLoc.reserve( vCrvIds.size()) ;
CICURVEPVECTOR vCrvP ;
@@ -2527,20 +2529,139 @@ ExeCreateSurfBzSkinned( int nParentId, const INTVECTOR& vCrvIds, bool bCapEnds,
bOk = bOk && ( vCrvLoc[i].Get() != nullptr) ;
}
// calcolo la superficie
PtrOwner<ISurfBezier> pSbz( bOk ? GetSurfBezierSkinned( vCrvP, dLinTol) : nullptr ) ;
bOk = bOk && ! IsNull( pSbz) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSbz)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfBzSkinned(" + IdToString( nParentId) + ",{" +
IdListToString( vCrvIds) + "}," +
( bCapEnds ? "true" : "false") + "," +
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
ISurfBezier* pSbz = ( bOk ? GetSurfBezierSkinned( vCrvP, dLinTol) : nullptr ) ;
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, pSbz) : GDB_ID_NULL) ;
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) + ",{" +
IdListToString( vCrvIds) + "}," +
string sLua = "EgtSurfbzByScrewing(" + IdToString( nParentId) + "," +
IdToString( nSectId) + "," +
IdToString( nGuideId) + "," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
// restituisco l'identificativo della nuova entità
return nNewId ;
}