diff --git a/CurveAux.cpp b/CurveAux.cpp index b8d9ff4..8ab4271 100644 --- a/CurveAux.cpp +++ b/CurveAux.cpp @@ -211,24 +211,24 @@ CurveDump( const ICurve& crvC, string& sOut, const char* szNewLine) } //---------------------------------------------------------------------------- -bool -ArcToBezierCurve( const ICurve* pCrv, ICurve*& pCrvNew) +ICurve* +ArcToBezierCurve( const ICurve* pCrv) { // verifico sia un arco const ICurveArc* pArc = GetCurveArc( pCrv) ; if ( pArc == nullptr) - return false ; + return nullptr ; // se angolo al centro sotto il limite, basta una curva if ( fabs( pArc->GetAngCenter()) <= BEZARC_ANG_CEN_MAX) { // creo la curva di Bezier PtrOwner pCrvBez( CreateCurveBezier()) ; if ( ! IsValid( pCrvBez)) - return false ; + return nullptr ; if ( ! pCrvBez->FromArc( *pArc)) - return false ; + return nullptr ; // restituisco la curva - pCrvNew = Release( pCrvBez) ; + return Release( pCrvBez) ; } // altrimenti curva composita di Bezier @@ -236,15 +236,13 @@ ArcToBezierCurve( const ICurve* pCrv, ICurve*& pCrvNew) // creo la curva composita PtrOwner pCrvCompo( CreateCurveComposite()) ; if ( ! IsValid( pCrvCompo)) - return false ; + return nullptr ; if ( ! pCrvCompo->AddCurve( *pArc) || ! pCrvCompo->ArcsToBezierCurves()) - return false ; + return nullptr ; // restituisco la curva - pCrvNew = Release( pCrvCompo) ; + return Release( pCrvCompo) ; } - - return true ; } //---------------------------------------------------------------------------- @@ -274,17 +272,17 @@ NurbsCurveCanonicalize( CNurbsData& cnData) } //---------------------------------------------------------------------------- -bool -NurbsToBezierCurve( const CNurbsData& cnData, ICurve*& pCrvNew) +ICurve* +NurbsToBezierCurve( const CNurbsData& cnData) { // la curva Nurbs deve essere in forma canonica if ( cnData.bPeriodic || cnData.bExtraKnotes) - return false ; + return nullptr ; // numero dei nodi int nU = int( cnData.vCP.size()) + cnData.nDeg - 1 ; // controllo relazione nodi - punti di controllo if ( nU != int( cnData.vU.size())) - return false ; + return nullptr ; // numero degli intervalli int nInt = nU - 2 * cnData.nDeg + 1 ; @@ -293,29 +291,28 @@ NurbsToBezierCurve( const CNurbsData& cnData, ICurve*& pCrvNew) // creo la curva di Bezier PtrOwner pCrvBez( CreateCurveBezier()) ; if ( ! IsValid( pCrvBez)) - return false ; + return nullptr ; // la inizializzo if ( ! pCrvBez->Init( cnData.nDeg, cnData.bRat)) - return false ; + return nullptr ; for ( int i = 0 ; i <= cnData.nDeg ; ++ i) { if ( ! cnData.bRat) { if ( ! pCrvBez->SetControlPoint( i, cnData.vCP[i])) - return false ; + return nullptr ; } else { if ( ! pCrvBez->SetControlPoint( i, cnData.vCP[i], cnData.vW[i])) - return false ; + return nullptr ; } } // restituisco la curva - pCrvNew = Release( pCrvBez) ; - return true ; + return Release( pCrvBez) ; } // altrimenti è equivalente ad una curva composita, la creo PtrOwner pCrvCompo( CreateCurveComposite()) ; if ( ! IsValid( pCrvCompo)) - return false ; + return nullptr ; // vettore dei punti di controllo della curva di Bezier PNTVECTOR vBC ; @@ -376,25 +373,25 @@ NurbsToBezierCurve( const CNurbsData& cnData, ICurve*& pCrvNew) // costruisco la curva di Bezier e la inserisco nella curva composita PtrOwner pCrvBez( CreateCurveBezier()) ; if ( ! IsValid( pCrvBez)) - return false ; + return nullptr ; // la inizializzo if ( ! pCrvBez->Init( cnData.nDeg, cnData.bRat)) - return false ; + return nullptr ; if ( ! cnData.bRat) { for ( int i = 0 ; i <= cnData.nDeg ; ++ i) { if ( ! pCrvBez->SetControlPoint( i, vBC[i])) - return false ; + return nullptr ; } } else { for ( int i = 0 ; i <= cnData.nDeg ; ++ i) { if ( ! pCrvBez->SetControlPoint( i, vBC[i] / vBW[i], vBW[i])) - return false ; + return nullptr ; } } // la aggiungo alla curva composita if ( ! pCrvCompo->AddCurve( Release( pCrvBez))) - return false ; + return nullptr ; // inizializzazioni per la prossima curva di Bezier if ( b < nU - 1) { @@ -420,6 +417,5 @@ NurbsToBezierCurve( const CNurbsData& cnData, ICurve*& pCrvNew) } // restituisco la curva composita - pCrvNew = Release( pCrvCompo) ; - return true ; + return Release( pCrvCompo) ; } \ No newline at end of file diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 2d4656f..1c8ffb6 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/FontNfe.cpp b/FontNfe.cpp index 038b3a3..702c128 100644 --- a/FontNfe.cpp +++ b/FontNfe.cpp @@ -273,8 +273,8 @@ NfeFont::GetOutline( const string& sText, int nInsPos, ICURVEPLIST& lstPC) if ( m_bItalic) { // se arco, devo trasformarlo in curva di Bezier (semplice o composta) if ( pCopyCrv->GetType() == CRV_ARC) { - ICurve* pCrvNew ; - if ( ! ArcToBezierCurve( pCopyCrv, pCrvNew)) + ICurve* pCrvNew = ArcToBezierCurve( pCopyCrv) ; + if ( pCrvNew == nullptr) return false ; // elimino l'arco e lo sostituisco con la curva di Bezier delete pCopyCrv ; diff --git a/GdbExecutor.cpp b/GdbExecutor.cpp index cfcf456..a6f145e 100644 --- a/GdbExecutor.cpp +++ b/GdbExecutor.cpp @@ -309,14 +309,18 @@ GdbExecutor::ExecuteVector( const string& sCmd2, const STRVECTOR& vsParams) else if ( sCmd2 == "SPHE" || sCmd2 == "FROMSPHERICAL") { return VectorFromSpherical( vsParams) ; } - // definizione come differenza di due punti - else if ( sCmd2 == "D" || sCmd2 == "DIFF") { - return VectorDifference( vsParams) ; - } // definizione come prodotto vettoriale di due vettori else if ( sCmd2 == "CP" || sCmd2 == "CROSSPROD") { return VectorCrossProduct( vsParams) ; } + // definizione con punto base e vettore + else if ( sCmd2 == "BV" || sCmd2 == "BASEVECTOR") { + return VectorBaseVector( vsParams) ; + } + // definizione come differenza di due punti (il primo diventa base) + else if ( sCmd2 == "D" || sCmd2 == "DIFF") { + return VectorDifference( vsParams) ; + } // impostazione del punto di base else if ( sCmd2 == "B" || sCmd2 == "BASE") { return VectorModifyBase( vsParams) ; @@ -385,40 +389,6 @@ GdbExecutor::VectorFromSpherical( const STRVECTOR& vsParams) return AddGeoObj( vsParams[0], vsParams[1], pGVect) ; } -//---------------------------------------------------------------------------- -bool -GdbExecutor::VectorDifference( const STRVECTOR& vsParams) -{ - // 4 o 5 parametri : Id, IdParent, ptP1, ptP2 [, bNorm] - if ( vsParams.size() != 4 && vsParams.size() != 5) - return false ; - // recupero il riferimento in cui è immerso - Frame3d frVect ; - if ( ! m_pGDB->GetGroupGlobFrame( GetIdParam( vsParams[1]), frVect)) - return false ; - // recupero il primo punto - Point3d ptP1 ; - if ( ! GetPointParam( vsParams[2], frVect, ptP1)) - return false ; - // recupero il secondo punto - Point3d ptP2 ; - if ( ! GetPointParam( vsParams[3], frVect, ptP2)) - return false ; - // flag di normalizzazione - bool bNorm = false ; - if ( vsParams.size() >= 5) - bNorm = ( vsParams[4] == "N") ; - // creo il vettore - IGeoVector3d* pGVect = CreateGeoVector3d() ; - if ( pGVect == nullptr) - return false ; - Vector3d vtV = ptP2 - ptP1 ; - if ( bNorm) - vtV.Normalize() ; - pGVect->Set( vtV) ; - return AddGeoObj( vsParams[0], vsParams[1], pGVect) ; -} - //---------------------------------------------------------------------------- bool GdbExecutor::VectorCrossProduct( const STRVECTOR& vsParams) @@ -453,6 +423,72 @@ GdbExecutor::VectorCrossProduct( const STRVECTOR& vsParams) return AddGeoObj( vsParams[0], vsParams[1], pGVect) ; } +//---------------------------------------------------------------------------- +bool +GdbExecutor::VectorDifference( const STRVECTOR& vsParams) +{ + // 4 o 5 parametri : Id, IdParent, ptP1, ptP2 [, bNorm] + if ( vsParams.size() != 4 && vsParams.size() != 5) + return false ; + // recupero il riferimento in cui è immerso + Frame3d frVect ; + if ( ! m_pGDB->GetGroupGlobFrame( GetIdParam( vsParams[1]), frVect)) + return false ; + // recupero il primo punto + Point3d ptP1 ; + if ( ! GetPointParam( vsParams[2], frVect, ptP1)) + return false ; + // recupero il secondo punto + Point3d ptP2 ; + if ( ! GetPointParam( vsParams[3], frVect, ptP2)) + return false ; + // flag di normalizzazione + bool bNorm = false ; + if ( vsParams.size() >= 5) + bNorm = ( vsParams[4] == "N") ; + // creo il vettore + IGeoVector3d* pGVect = CreateGeoVector3d() ; + if ( pGVect == nullptr) + return false ; + Vector3d vtV = ptP2 - ptP1 ; + if ( bNorm) + vtV.Normalize() ; + pGVect->Set( vtV, ptP1) ; + return AddGeoObj( vsParams[0], vsParams[1], pGVect) ; +} + +//---------------------------------------------------------------------------- +bool +GdbExecutor::VectorBaseVector( const STRVECTOR& vsParams) +{ + // 4 o 5 parametri : Id, IdParent, PtBase, Vettore [, ScaleFactor] + if ( vsParams.size() != 4 && vsParams.size() != 5) + return false ; + // recupero il riferimento in cui è immerso + Frame3d frVect ; + if ( ! m_pGDB->GetGroupGlobFrame( GetIdParam( vsParams[1]), frVect)) + return false ; + // recupero il punto base + Point3d ptBase ; + if ( ! GetPointParam( vsParams[2], frVect, ptBase)) + return false ; + // recupero i tre componenti + Vector3d Vect ; + if ( ! GetVectorParam( vsParams[3], frVect, Vect)) + return false ; + // recupero l'eventuale fattore di scala + double dScale = 1 ; + if ( vsParams.size() == 5 && ! FromString( vsParams[4], dScale)) + return false ; + // creo il vettore + IGeoVector3d* pGVect = CreateGeoVector3d() ; + if ( pGVect == nullptr) + return false ; + pGVect->Set( Vect * dScale, ptBase) ; + return AddGeoObj( vsParams[0], vsParams[1], pGVect) ; +} + + //---------------------------------------------------------------------------- bool GdbExecutor::VectorModifyBase( const STRVECTOR& vsParams) diff --git a/GdbExecutor.h b/GdbExecutor.h index 23a3acc..6a20128 100644 --- a/GdbExecutor.h +++ b/GdbExecutor.h @@ -55,6 +55,7 @@ class GdbExecutor : public IGdbExecutor bool ExecutePoint( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteVector( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool VectorMake( const STRVECTOR& vsParams) ; + bool VectorBaseVector( const STRVECTOR& vsParams) ; bool VectorFromSpherical( const STRVECTOR& vsParams) ; bool VectorDifference( const STRVECTOR& vsParams) ; bool VectorCrossProduct( const STRVECTOR& vsParams) ; diff --git a/GdbGeo.cpp b/GdbGeo.cpp index b12a3e4..6835494 100644 --- a/GdbGeo.cpp +++ b/GdbGeo.cpp @@ -243,8 +243,8 @@ GdbGeo::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoe if ( m_pGeoObj->GetType() == CRV_ARC && (fabs( dCoeffX - dCoeffY) > EPS_SMALL || fabs( dCoeffX - dCoeffZ) > EPS_SMALL)) { // trasformo in curva di Bezier (semplice o composta) - ICurve* pCrvNew ; - if ( ! ArcToBezierCurve( GetCurve( m_pGeoObj), pCrvNew)) + ICurve* pCrvNew = ArcToBezierCurve( GetCurve( m_pGeoObj)) ; + if ( pCrvNew == nullptr) return false ; // elimino l'arco e lo sostituisco con la curva di Bezier delete m_pGeoObj ; @@ -281,8 +281,8 @@ GdbGeo::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDi ! ( AreSameVectorExact( pArc->GetNormVersor(), vtNorm) || AreOppositeVectorExact( pArc->GetNormVersor(), vtNorm))) { // trasformo in curva di Bezier (semplice o composta) - ICurve* pCrvNew ; - if ( ! ArcToBezierCurve( GetCurve( m_pGeoObj), pCrvNew)) + ICurve* pCrvNew = ArcToBezierCurve( GetCurve( m_pGeoObj)) ; + if ( pCrvNew == nullptr) return false ; // elimino l'arco e lo sostituisco con la curva di Bezier delete m_pGeoObj ; diff --git a/GdbIterator.h b/GdbIterator.h index 848ee8f..1540e85 100644 --- a/GdbIterator.h +++ b/GdbIterator.h @@ -22,7 +22,7 @@ class GdbIterator : public IGdbIterator public : virtual ~GdbIterator( void) ; virtual bool SetGDB( IGeomDB* pGDB) ; - virtual GeomDB* GetGDB( void) + virtual GeomDB* GetGDB( void) const { return m_pGDB ; } virtual bool GoTo( int nId) ; virtual bool GoToFirstInGroup( int nIdGroup) ; diff --git a/GeomDB.cpp b/GeomDB.cpp index 5ca3cf8..e77b98c 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -618,9 +618,9 @@ GeomDB::GetGlobalBBox( int nId, BBox3d& b3Glob, int nFlag) const if ( ( pGdbObj = GetGdbObj( nId)) == nullptr) return false ; - // recupero il riferimento globale del gruppo cui appartiene + // se non è la radice, recupero il riferimento globale del gruppo cui appartiene Frame3d frGlob ; - if ( ! GetGroupGlobFrame( pGdbObj->GetParentId(), frGlob)) + if ( nId != GDB_ID_ROOT && ! GetGroupGlobFrame( pGdbObj->GetParentId(), frGlob)) return false ; // eseguo l'operazione diff --git a/PolyLine.cpp b/PolyLine.cpp index 56db9f0..843ef1e 100644 --- a/PolyLine.cpp +++ b/PolyLine.cpp @@ -423,7 +423,7 @@ PolyLine::NewellPlane( Plane3d& plPlane, double& dArea) const //---------------------------------------------------------------------------- bool -PolyLine::IsPlanar( Plane3d& plPlane, double& dArea, double dToler) const +PolyLine::IsFlat( Plane3d& plPlane, double& dArea, double dToler) const { // Compute a representative plane for the polygon if ( ! NewellPlane( plPlane, dArea)) diff --git a/SurfTriMesh.cpp b/SurfTriMesh.cpp index ef6ecc6..5f797f6 100644 --- a/SurfTriMesh.cpp +++ b/SurfTriMesh.cpp @@ -224,6 +224,32 @@ SurfTriMesh::GetNextVertex( int nId, Point3d& ptP) const return nId ; } +//---------------------------------------------------------------------------- +int +SurfTriMesh::GetFirstTriangle( int nIdVert[3]) const +{ + return GetNextTriangle( SVT_NULL, nIdVert) ; +} + +//---------------------------------------------------------------------------- +int +SurfTriMesh::GetNextTriangle( int nId, int nIdVert[3]) const +{ + // cerco il primo successivo valido + do { + nId ++ ; + } while ( nId < GetTriangleSize() && m_vTria[nId].nIdVert[0] == SVT_DEL) ; + // se oltrepassata fine + if ( nId >= GetTriangleSize()) + return SVT_NULL ; + // recupero i dati + nIdVert[0] = m_vTria[nId].nIdVert[0] ; + nIdVert[1] = m_vTria[nId].nIdVert[1] ; + nIdVert[2] = m_vTria[nId].nIdVert[2] ; + // ritorno indice triangolo corrente + return nId ; +} + //---------------------------------------------------------------------------- int SurfTriMesh::GetFirstTriangle( Triangle3d& Tria) const @@ -315,7 +341,7 @@ SurfTriMesh::GetTriangleSmoothNormal( int nT, int nV, Vector3d& vtN) const vtN.Normalize() ; return true ; - } +} //---------------------------------------------------------------------------- SurfTriMesh* diff --git a/SurfTriMesh.h b/SurfTriMesh.h index cf9fe85..f59b091 100644 --- a/SurfTriMesh.h +++ b/SurfTriMesh.h @@ -125,6 +125,8 @@ class SurfTriMesh : public ISurfTriMesh, public IGeoObjRW { return m_dSmoothAng ; } virtual int GetFirstVertex( Point3d& ptP) const ; virtual int GetNextVertex( int nId, Point3d& ptP) const ; + virtual int GetFirstTriangle( int nIdVert[3]) const ; + virtual int GetNextTriangle( int nId, int nIdVert[3]) const ; virtual int GetFirstTriangle( Triangle3d& Tria) const ; virtual int GetNextTriangle( int nId, Triangle3d& Tria) const ; virtual bool GetTriangleSmoothNormals( int nId, TriNormals3d& TNrms) const ; diff --git a/Triangulate.cpp b/Triangulate.cpp index 4b5ee73..517ae70 100644 --- a/Triangulate.cpp +++ b/Triangulate.cpp @@ -33,7 +33,7 @@ Triangulate::Make( const PolyLine& PL, PNTVECTOR& vPt, INTVECTOR& vTr) // calcolo il piano medio del poligono double dArea ; Plane3d plPlane ; - if ( ! PL.IsPlanar( plPlane, dArea, 50 * EPS_SMALL)) + if ( ! PL.IsFlat( plPlane, dArea, 50 * EPS_SMALL)) return false ; bool bCCW ; if ( fabs( plPlane.vtN.z) >= fabs( plPlane.vtN.x) &&