diff --git a/Attribs.cpp b/Attribs.cpp index 2bdc1c1..898605f 100644 --- a/Attribs.cpp +++ b/Attribs.cpp @@ -240,6 +240,19 @@ Attribs::GetName( string& sName) const return false ; } +//---------------------------------------------------------------------------- +bool +Attribs::ExistsName( void) const +{ + // può essere solo la prima stringa + STRLIST::const_iterator iIter ; + if ( ( iIter = m_slInfo.begin()) != m_slInfo.end() && + FindKey( *iIter, NAME)) + return true ; + + return false ; +} + //---------------------------------------------------------------------------- bool Attribs::RemoveName( void) @@ -306,6 +319,24 @@ Attribs::GetInfo( const string& sKey, string& sVal) const return false ; } +//---------------------------------------------------------------------------- +bool +Attribs::ExistsInfo( const string& sKey) const +{ + // se chiave non valida, esco con errore + if ( ! IsValidString( sKey)) + return false ; + + // cerco una stringa con la chiave + STRLIST::const_iterator iIter ; + for ( iIter = m_slInfo.begin() ; iIter != m_slInfo.end() ; ++ iIter) { + if ( FindKey( *iIter, sKey)) + return true ; + } + + return false ; +} + //---------------------------------------------------------------------------- bool Attribs::RemoveInfo( const string& sKey) diff --git a/Attribs.h b/Attribs.h index 84ec669..07e390e 100644 --- a/Attribs.h +++ b/Attribs.h @@ -82,9 +82,11 @@ class Attribs { return m_Color ; } bool SetName( const std::string& sName) ; bool GetName( std::string& sName) const ; + bool ExistsName( void) const ; bool RemoveName( void) ; bool SetInfo( const std::string& sKey, const std::string& sVal) ; bool GetInfo( const std::string& sKey, std::string& sVal) const ; + bool ExistsInfo( const std::string& sKey) const ; bool RemoveInfo( const std::string& sKey) ; private : diff --git a/CurveArc.cpp b/CurveArc.cpp index b603f78..86a9a79 100644 --- a/CurveArc.cpp +++ b/CurveArc.cpp @@ -95,6 +95,7 @@ CurveArc::Set( const Point3d& ptCen, const Vector3d& vtN, double dRad) // assegno e calcolo i dati m_PtCen = ptCen ; m_VtN = vtN ; + m_VtN.Normalize() ; Frame3d frF ; if ( ! frF.Set( ORIG, vtN)) return false ; diff --git a/CurveComposite.cpp b/CurveComposite.cpp index 4dc5251..c5f801e 100644 --- a/CurveComposite.cpp +++ b/CurveComposite.cpp @@ -280,9 +280,10 @@ CurveComposite::FromPointBulgeVector( const UPNTVECTOR& vUPnt, const Vector3d& v return false ; // Creo le diverse curve semplici e le inserisco in quella composita + int iPrev = 0 ; for ( int i = 1 ; i < int( vUPnt.size()) ; ++i) { // se i punti della coppia coincidono, passo alla coppia successiva - if ( AreSamePointNear( vUPnt[i-1].second, vUPnt[i].second)) + if ( AreSamePointNear( vUPnt[iPrev].second, vUPnt[i].second)) continue ; // se retta if ( fabs( vUPnt[i-1].first) < EPS_SMALL) { @@ -291,7 +292,7 @@ CurveComposite::FromPointBulgeVector( const UPNTVECTOR& vUPnt, const Vector3d& v if ( ! ::IsValid( pCrvLine)) return false ; // setto la linea - if ( ! pCrvLine->Set( vUPnt[i-1].second, vUPnt[i].second)) + if ( ! pCrvLine->Set( vUPnt[iPrev].second, vUPnt[i].second)) return false ; // inserisco la linea nella curva composta if ( ! AddSimpleCurve( ::Release( pCrvLine))) @@ -304,12 +305,14 @@ CurveComposite::FromPointBulgeVector( const UPNTVECTOR& vUPnt, const Vector3d& v if ( ! ::IsValid( pCrvArc)) return false ; // setto l'arco - if ( ! pCrvArc->Set2PNB( vUPnt[i-1].second, vUPnt[i].second, vtN, vUPnt[i-1].first)) + if ( ! pCrvArc->Set2PNB( vUPnt[iPrev].second, vUPnt[i].second, vtN, vUPnt[i-1].first)) return false ; // inserisco l'arco nella curva composta if ( ! AddSimpleCurve( Release( pCrvArc))) return false ; } + // aggiorno indice punto ultimo inserito + iPrev = i ; } return true ; diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index b0ef58a..82ec3a5 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/GdbIterator.cpp b/GdbIterator.cpp index f2a10df..30d66a8 100644 --- a/GdbIterator.cpp +++ b/GdbIterator.cpp @@ -303,6 +303,21 @@ GdbIterator::GetGroupGlobFrame( Frame3d& frGlob) const return pGdbGroup->GetGlobFrame( frGlob) ; } +//---------------------------------------------------------------------------- +int +GdbIterator::GetGroupObjs( void) const +{ + if ( m_pGDB == nullptr || m_pCurrObj == nullptr) + return 0 ; + + GdbGroup* pGdbGroup ; + if ( ( pGdbGroup = GetGdbGroup( m_pCurrObj)) == nullptr) + return 0 ; + + // restituisco il numero di nodi (figli) + return pGdbGroup->GetObjCount() ; +} + //---------------------------------------------------------------------------- int GdbIterator::GetId( void) const @@ -683,6 +698,17 @@ GdbIterator::GetName( string& sName) const return m_pCurrObj->GetName( sName) ; } +//---------------------------------------------------------------------------- +bool +GdbIterator::ExistsName( void) const +{ + if ( m_pGDB == nullptr || m_pCurrObj == nullptr) + return false ; + + // verifico esistenza del nome + return m_pCurrObj->ExistsName() ; +} + //---------------------------------------------------------------------------- bool GdbIterator::RemoveName( void) @@ -716,6 +742,17 @@ GdbIterator::GetInfo( const string& sKey, string& sInfo) const return m_pCurrObj->GetInfo( sKey, sInfo) ; } +//---------------------------------------------------------------------------- +bool +GdbIterator::ExistsInfo( const string& sKey) const +{ + if ( m_pGDB == nullptr || m_pCurrObj == nullptr) + return false ; + + // verifico l'esistenza dell'Info + return m_pCurrObj->ExistsInfo( sKey) ; +} + //---------------------------------------------------------------------------- bool GdbIterator::RemoveInfo( const string& sKey) diff --git a/GdbIterator.h b/GdbIterator.h index ac69182..9208e98 100644 --- a/GdbIterator.h +++ b/GdbIterator.h @@ -39,6 +39,7 @@ class GdbIterator : public IGdbIterator virtual IGeoFrame3d* GetGeoFrame( void) ; virtual bool GetGroupFrame( Frame3d& frGlob) const ; virtual bool GetGroupGlobFrame( Frame3d& frGlob) const ; + virtual int GetGroupObjs( void) const ; virtual int GetId( void) const ; virtual int GetParentId( void) const ; virtual bool GetGlobFrame( Frame3d& frGlob) const ; @@ -72,9 +73,11 @@ class GdbIterator : public IGdbIterator virtual bool GetCalcMaterial( Color& cCol) const ; virtual bool SetName( const std::string& sName) ; virtual bool GetName( std::string& sName) const ; + virtual bool ExistsName( void) const ; virtual bool RemoveName( void) ; virtual bool SetInfo( const std::string& sKey, const std::string& sInfo) ; virtual bool GetInfo( const std::string& sKey, std::string& sInfo) const ; + virtual bool ExistsInfo( const std::string& sKey) const ; virtual bool RemoveInfo( const std::string& sKey) ; public : diff --git a/GdbObj.cpp b/GdbObj.cpp index 416ce9a..db3b1c2 100644 --- a/GdbObj.cpp +++ b/GdbObj.cpp @@ -664,6 +664,18 @@ GdbObj::GetName( string& sName) const return m_pAttribs->GetName( sName) ; } +//---------------------------------------------------------------------------- +bool +GdbObj::ExistsName( void) const +{ + // se non ci sono attributi + if ( m_pAttribs == nullptr) + return false ; + + // restituisco il nome + return m_pAttribs->ExistsName() ; +} + //---------------------------------------------------------------------------- bool GdbObj::RemoveName( void) @@ -684,7 +696,7 @@ GdbObj::SetInfo( const string& sKey, const string& sInfo) if ( GetSafeAttribs() == nullptr) return false ; - // assegno il nome + // assegno l'Info return m_pAttribs->SetInfo( sKey, sInfo) ; } @@ -696,10 +708,22 @@ GdbObj::GetInfo( const string& sKey, string& sInfo) const if ( m_pAttribs == nullptr) return false ; - // restituisco il nome + // restituisco l'Info return m_pAttribs->GetInfo( sKey, sInfo) ; } +//---------------------------------------------------------------------------- +bool +GdbObj::ExistsInfo( const string& sKey) const +{ + // se non ci sono attributi + if ( m_pAttribs == nullptr) + return false ; + + // verifico l'esistenza dell'Info + return m_pAttribs->ExistsInfo( sKey) ; +} + //---------------------------------------------------------------------------- bool GdbObj::RemoveInfo( const string& sKey) @@ -708,6 +732,6 @@ GdbObj::RemoveInfo( const string& sKey) if ( m_pAttribs == nullptr) return false ; - // cancello il nome + // cancello l'Info return m_pAttribs->RemoveInfo( sKey) ; } diff --git a/GdbObj.h b/GdbObj.h index 7c6df13..2389d08 100644 --- a/GdbObj.h +++ b/GdbObj.h @@ -80,9 +80,11 @@ class GdbObj bool GetCalcMaterial( Color& cCol) const ; bool SetName( const std::string& sName) ; bool GetName( std::string& sName) const ; + bool ExistsName( void) const ; bool RemoveName( void) ; bool SetInfo( const std::string& sKey, const std::string& sInfo) ; bool GetInfo( const std::string& sKey, std::string& sInfo) const ; + bool ExistsInfo( const std::string& sKey) const ; bool RemoveInfo( const std::string& sKey) ; public : diff --git a/GeomDB.cpp b/GeomDB.cpp index dfb8302..ff090cf 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -183,7 +183,7 @@ GeomDB::LoadOneObj( NgeReader& ngeIn, bool& bEnd) // se lettura dati e inserimento nel DB vanno bene int nParentId ; if ( pGdbObj->Load( nKey, ngeIn, nParentId) && - AddToGeomDB( pGdbObj, nParentId)) + InsertInGeomDB( pGdbObj, nParentId, GDB_SON)) return true ; // altrimenti errore else { @@ -306,7 +306,7 @@ GeomDB::GetGdbObj( int nId) const //---------------------------------------------------------------------------- bool -GeomDB::AddToGeomDB( GdbObj* pGObj, int nParentId) +GeomDB::InsertInGeomDB( GdbObj* pGObj, int nRefId, int nSonBeforeAfter) { // verifico validità oggetto puntato if ( pGObj == nullptr) @@ -316,13 +316,30 @@ GeomDB::AddToGeomDB( GdbObj* pGObj, int nParentId) if ( pGObj->m_nId <= GDB_ID_ROOT || ExistsObj( pGObj->m_nId)) return false ; - // cerco il padre - GdbGroup* pGroup = GetGdbGroup( nParentId) ; - if ( pGroup == nullptr) + // cerco il riferimento + GdbObj* pGRef = GetGdbObj( nRefId) ; + if ( pGRef == nullptr) return false ; - // inserisco in coda alla lista del padre - if ( ! pGObj->AddTail( pGroup)) - return false ; + + // inserisco prima del riferimento + if ( nSonBeforeAfter <= GDB_BEFORE) { + if ( ! pGObj->InsertBefore( pGRef)) + return false ; + } + // inserisco dopo il riferimento + else if ( nSonBeforeAfter >= GDB_AFTER) { + if ( ! pGObj->InsertAfter( pGRef)) + return false ; + } + // inserisco come figlio, in coda alla lista del padre + else { + GdbGroup* pGroup = dynamic_cast ( pGRef) ; + if ( pGroup == nullptr) + return false ; + // inserisco in coda alla lista del padre + if ( ! pGObj->AddTail( pGroup)) + return false ; + } // inserisco in mappa Id return m_IdManager.AddObj( pGObj->m_nId, pGObj) ; @@ -332,11 +349,15 @@ GeomDB::AddToGeomDB( GdbObj* pGObj, int nParentId) int GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame) { - GdbGroup* pGdbGroup ; + return InsertGroup( nId, nParentId, GDB_SON, frFrame) ; +} - - // verifico validità ParentId - if ( nParentId < GDB_ID_ROOT) +//---------------------------------------------------------------------------- +int +GeomDB::InsertGroup( int nId, int nRefId, int nSonBeforeAfter, const Frame3d& frFrame) +{ + // verifico validità apparente RefId + if ( nRefId < GDB_ID_ROOT) return GDB_ID_NULL ; // verifico validità Id if ( nId <= GDB_ID_ROOT) @@ -344,7 +365,7 @@ GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame) if ( ExistsObj( nId)) return GDB_ID_NULL ; // alloco gruppo Gdb - pGdbGroup = new(nothrow) GdbGroup ; + GdbGroup* pGdbGroup = new(nothrow) GdbGroup ; if ( pGdbGroup == nullptr) return GDB_ID_NULL ; // assegno identificativo @@ -352,7 +373,7 @@ GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame) // assegno riferimento pGdbGroup->m_gfrFrame.Set( frFrame) ; // inserisco nel DB - if ( ! AddToGeomDB( pGdbGroup, nParentId)) { + if ( ! InsertInGeomDB( pGdbGroup, nRefId, nSonBeforeAfter)) { delete pGdbGroup ; return GDB_ID_NULL ; } @@ -364,9 +385,13 @@ GeomDB::AddGroup( int nId, int nParentId, const Frame3d& frFrame) int GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) { - GdbGeo* pGdbGeo ; - + return InsertGeoObj( nId, nParentId, GDB_SON, pGeoObj) ; +} +//---------------------------------------------------------------------------- +int +GeomDB::InsertGeoObj( int nId, int nRefId, int nBeforeAfter, IGeoObj* pGeoObj) +{ // assegno GeoObj a gestore puntatore con rilascio automatico PtrOwner pRPGeoObj( pGeoObj) ; // verifico validità identificativo @@ -378,7 +403,7 @@ GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) if ( ! IsValid( pRPGeoObj) || ! pRPGeoObj->IsValid()) return GDB_ID_NULL ; // alloco oggetto Gdb - pGdbGeo = new(nothrow) GdbGeo ; + GdbGeo* pGdbGeo = new(nothrow) GdbGeo ; if ( pGdbGeo == nullptr) return GDB_ID_NULL ; // assegno identificativo @@ -386,7 +411,7 @@ GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) // assegno dati pGdbGeo->m_pGeoObj = Release( pRPGeoObj) ; // inserisco nel DB - if ( ! AddToGeomDB( pGdbGeo, nParentId)) { + if ( ! InsertInGeomDB( pGdbGeo, nRefId, nBeforeAfter)) { delete pGdbGeo ; return GDB_ID_NULL ; } @@ -394,14 +419,78 @@ GeomDB::AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) return nId ; } +//---------------------------------------------------------------------------- +int +GeomDB::GetFirstInGroup( int nIdGroup) const +{ + // recupero il gruppo + const GdbGroup* pGdbGroup = GetGdbGroup( nIdGroup) ; + if ( pGdbGroup == nullptr) + return GDB_ID_NULL ; + + // recupero il primo oggetto del gruppo + const GdbObj* pGdbO = pGdbGroup->GetFirstObj() ; + if ( pGdbO == nullptr) + return GDB_ID_NULL ; + + return ( pGdbO->m_nId) ; +} + +//---------------------------------------------------------------------------- +int +GeomDB::GetNext( int nId) const +{ + // recupero l'oggetto + const GdbObj* pGdbObj = GetGdbObj( nId) ; + if ( pGdbObj == nullptr) + return GDB_ID_NULL ; + // recupero il successivo + const GdbObj* pGdbNext = pGdbObj->GetNext() ; + if ( pGdbNext == nullptr) + return GDB_ID_NULL ; + + return ( pGdbNext->m_nId) ; +} + +//---------------------------------------------------------------------------- +int +GeomDB::GetLastInGroup( int nIdGroup) const +{ + // recupero il gruppo + const GdbGroup* pGdbGroup = GetGdbGroup( nIdGroup) ; + if ( pGdbGroup == nullptr) + return GDB_ID_NULL ; + + // recupero l'ultimo oggetto del gruppo + const GdbObj* pGdbO = pGdbGroup->GetLastObj() ; + if ( pGdbO == nullptr) + return GDB_ID_NULL ; + + return ( pGdbO->m_nId) ; +} + +//---------------------------------------------------------------------------- +int +GeomDB::GetPrev( int nId) const +{ + // recupero l'oggetto + const GdbObj* pGdbObj = GetGdbObj( nId) ; + if ( pGdbObj == nullptr) + return GDB_ID_NULL ; + // recupero il precedente + const GdbObj* pGdbPrev = pGdbObj->GetPrev() ; + if ( pGdbPrev == nullptr) + return GDB_ID_NULL ; + + return ( pGdbPrev->m_nId) ; +} + //---------------------------------------------------------------------------- int GeomDB::GetGdbType( int nId) const { - const GdbObj* pGdbObj ; - - // recupero l'oggetto + const GdbObj* pGdbObj ; if ( ( pGdbObj = GetGdbObj( nId)) == nullptr) return GDB_TY_NONE ; @@ -568,7 +657,7 @@ GeomDB::Copy( int nIdSou, int nIdDest, int nParentIdDest) return GDB_ID_NULL ; // inserisco nel DB - if ( ! AddToGeomDB( pGdODest, nParentIdDest)) { + if ( ! InsertInGeomDB( pGdODest, nParentIdDest, GDB_SON)) { delete pGdODest ; return GDB_ID_NULL ; } @@ -613,7 +702,7 @@ GeomDB::CopyGlob( int nIdSou, int nIdDest, int nParentIdDest) } // inserisco nel DB - if ( ! AddToGeomDB( pGdODest, nParentIdDest)) { + if ( ! InsertInGeomDB( pGdODest, nParentIdDest, GDB_SON)) { delete pGdODest ; return GDB_ID_NULL ; } @@ -1670,6 +1759,19 @@ GeomDB::GetName( int nId, string& sName) const return pGdbObj->GetName( sName) ; } +//---------------------------------------------------------------------------- +bool +GeomDB::ExistsName( int nId) const +{ + // recupero l'oggetto + const GdbObj* pGdbObj ; + if ( ( pGdbObj = GetGdbObj( nId)) == nullptr) + return false ; + + // recupero il nome + return pGdbObj->ExistsName() ; +} + //---------------------------------------------------------------------------- bool GeomDB::RemoveName( int nId) @@ -1709,6 +1811,19 @@ GeomDB::GetInfo( int nId, const string& sKey, string& sInfo) const return pGdbObj->GetInfo( sKey, sInfo) ; } +//---------------------------------------------------------------------------- +bool +GeomDB::ExistsInfo( int nId, const string& sKey) const +{ + // recupero l'oggetto + const GdbObj* pGdbObj ; + if ( ( pGdbObj = GetGdbObj( nId)) == nullptr) + return false ; + + // verifico l'esistenza dell'Info + return pGdbObj->ExistsInfo( sKey) ; +} + //---------------------------------------------------------------------------- bool GeomDB::RemoveInfo( int nId, const string& sKey) diff --git a/GeomDB.h b/GeomDB.h index 83ee371..0059bb5 100644 --- a/GeomDB.h +++ b/GeomDB.h @@ -35,7 +35,13 @@ class GeomDB : public IGeomDB virtual bool Save( const std::string& sFileOut, bool bBinary = true) const ; virtual bool ExistsObj( int nId) const ; virtual int AddGroup( int nId, int nParentId, const Frame3d& frFrame) ; + virtual int InsertGroup( int nId, int nRefId, int nSonBeforeAfter, const Frame3d& frFrame) ; virtual int AddGeoObj( int nId, int nParentId, IGeoObj* pGeoObj) ; + virtual int InsertGeoObj( int nId, int nRefId, int nSonBeforeAfter, IGeoObj* pGeoObj) ; + virtual int GetFirstInGroup( int nIdGroup) const ; + virtual int GetNext( int nId) const ; + virtual int GetLastInGroup( int nIdGroup) const ; + virtual int GetPrev( int nId) const ; virtual int GetGdbType( int nId) const ; virtual IGeoObj* GetGeoObj( int nId) ; virtual IGeoFrame3d* GetGeoFrame( int nId) ; @@ -117,9 +123,11 @@ class GeomDB : public IGeomDB virtual bool GetCalcMaterial( int nId, Color& cCol) const ; virtual bool SetName( int nId, const std::string& sName) ; virtual bool GetName( int nId, std::string& sName) const ; + virtual bool ExistsName( int nId) const ; virtual bool RemoveName( int nId) ; virtual bool SetInfo( int nId, const std::string& sKey, const std::string& sInfo) ; virtual bool GetInfo( int nId, const std::string& sKey, std::string& sInfo) const ; + virtual bool ExistsInfo( int nId, const std::string& sKey) const ; virtual bool RemoveInfo( int nId, const std::string& sKey) ; // material library virtual int AddMaterial( const std::string& sName, const Material& matM) ; @@ -147,7 +155,7 @@ class GeomDB : public IGeomDB { return dynamic_cast( GetGdbObj( nId)) ; } const GdbGroup* GetGdbGroup( int nId) const { return dynamic_cast( GetGdbObj( nId)) ; } - bool AddToGeomDB( GdbObj* pGObj, int nParentId) ; + bool InsertInGeomDB( GdbObj* pGObj, int nRefId, int nSonBeforeAfter) ; bool Relocate( int nId, int nNewParentId, bool bGlob) ; bool Erase( GdbObj* pGObj) ; bool LoadHeader( NgeReader& ngeIn) ; diff --git a/PointGrid3d.cpp b/PointGrid3d.cpp index 2802628..b2d3742 100644 --- a/PointGrid3d.cpp +++ b/PointGrid3d.cpp @@ -22,7 +22,8 @@ using namespace std ; bool PointGrid3d::Init( int nBuckets, double dCellDim) { - m_dCellDim = dCellDim ; + m_dCellDim = max( dCellDim, EPS_SMALL) ; + m_dInvCellDim = 1 / m_dCellDim ; try { m_MMap.rehash( nBuckets) ;} catch(...) { return false ;} return true ; @@ -101,7 +102,7 @@ PointGrid3d::Find( const Point3d& ptTest, double dTol, int& nId) int PointGrid3d::Get1dCellNbr( double dCoord) { - return static_cast( floor( dCoord / m_dCellDim)) ; + return static_cast( floor( dCoord * m_dInvCellDim)) ; } //---------------------------------------------------------------------------- diff --git a/SurfTriMesh.cpp b/SurfTriMesh.cpp index 9822b2b..ee02109 100644 --- a/SurfTriMesh.cpp +++ b/SurfTriMesh.cpp @@ -112,7 +112,7 @@ SurfTriMesh::SetVertex( int nInd, const StmVert& vV) int SurfTriMesh::AddTriangle( const int nIdVert[3]) { - // verifico che i tre indici diano diversi + // verifico che i tre indici siano diversi if ( nIdVert[0] == nIdVert[1] || nIdVert[1] == nIdVert[2] || nIdVert[2] == nIdVert[0])