From 95f6f3ecdf383cc92b9749b2d84db7d4fbdda5a2 Mon Sep 17 00:00:00 2001 From: jfa Date: Wed, 14 Feb 2007 09:50:36 +0000 Subject: [PATCH] Improve data owners comparison to avoid problems with local selection in OCC viewer (in debug mode). --- src/LightApp/LightApp_DataOwner.cxx | 34 +++++++------------------- src/LightApp/LightApp_DataOwner.h | 5 ++-- src/LightApp/LightApp_DataSubOwner.cxx | 14 +++++------ src/LightApp/LightApp_DataSubOwner.h | 6 +++-- src/SUIT/SUIT_DataOwner.cxx | 30 +++++++++++++++-------- src/SUIT/SUIT_DataOwner.h | 6 ++--- 6 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/LightApp/LightApp_DataOwner.cxx b/src/LightApp/LightApp_DataOwner.cxx index dea72f88c..111714dd1 100644 --- a/src/LightApp/LightApp_DataOwner.cxx +++ b/src/LightApp/LightApp_DataOwner.cxx @@ -16,6 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "LightApp_DataOwner.h" #include "LightApp_DataObject.h" @@ -31,16 +32,14 @@ #include /*!Constructor. Initialize by \a theEntry.*/ -LightApp_DataOwner -::LightApp_DataOwner( const QString& theEntry ): +LightApp_DataOwner::LightApp_DataOwner( const QString& theEntry ): myEntry( theEntry ) { } #ifndef DISABLE_SALOMEOBJECT /*!Constructor. Initialize by \a SALOME_InteractiveObject.*/ -LightApp_DataOwner -::LightApp_DataOwner( const Handle(SALOME_InteractiveObject)& theIO ): +LightApp_DataOwner::LightApp_DataOwner( const Handle(SALOME_InteractiveObject)& theIO ): myEntry(!theIO.IsNull()? theIO->getEntry(): ""), myIO(theIO) { @@ -48,40 +47,25 @@ LightApp_DataOwner #endif /*!Destructor. Do nothing.*/ -LightApp_DataOwner -::~LightApp_DataOwner() -{ -} - -/*!Checks: Is current data owner equal \a obj.*/ -bool -LightApp_DataOwner -::isEqual( const SUIT_DataOwner& obj ) const +LightApp_DataOwner::~LightApp_DataOwner() { - const LightApp_DataOwner* other = dynamic_cast( &obj ); - - return other && entry() == other->entry(); } -bool LightApp_DataOwner::operator<( const SUIT_DataOwner& obj ) const +/*!Gets key string, used for data owners comparison.*/ +QString LightApp_DataOwner::keyString() const { - const LightApp_DataOwner* other = dynamic_cast( &obj ); - return entry() < other->entry(); + return myEntry; } /*!Gets entry.*/ -QString -LightApp_DataOwner -::entry() const +QString LightApp_DataOwner::entry() const { return myEntry; } #ifndef DISABLE_SALOMEOBJECT /*!Gets SALOME_InteractiveObject.*/ -const Handle(SALOME_InteractiveObject)& -LightApp_DataOwner -::IO() const +const Handle(SALOME_InteractiveObject)& LightApp_DataOwner::IO() const { return myIO; } diff --git a/src/LightApp/LightApp_DataOwner.h b/src/LightApp/LightApp_DataOwner.h index 7fd43eedc..39d48dacc 100644 --- a/src/LightApp/LightApp_DataOwner.h +++ b/src/LightApp/LightApp_DataOwner.h @@ -39,8 +39,9 @@ public: LightApp_DataOwner( const QString& ); virtual ~LightApp_DataOwner(); - virtual bool isEqual( const SUIT_DataOwner& ) const; - virtual bool operator<( const SUIT_DataOwner& ) const; + // *** jfa: The below line has been put here 14.02.2007. + // *** It cancels modifications from branch BR_Dev_For_4_0 + virtual QString keyString() const; #ifndef DISABLE_SALOMEOBJECT const Handle(SALOME_InteractiveObject)& IO() const; diff --git a/src/LightApp/LightApp_DataSubOwner.cxx b/src/LightApp/LightApp_DataSubOwner.cxx index aaf1d3613..17fa8b80c 100644 --- a/src/LightApp/LightApp_DataSubOwner.cxx +++ b/src/LightApp/LightApp_DataSubOwner.cxx @@ -36,14 +36,12 @@ LightApp_DataSubOwner::~LightApp_DataSubOwner() { } -/*!Checks: Is current data sub owner equal \a obj.*/ -bool LightApp_DataSubOwner::isEqual( const SUIT_DataOwner& obj ) const -{ - if (LightApp_DataOwner::isEqual(obj)) { - const LightApp_DataSubOwner* other = dynamic_cast( &obj ); - return other && index() == other->index(); - } - return false; +/*!Gets key string, used for data owners comparison.*/ +QString LightApp_DataSubOwner::keyString() const +{ + QString aKey = LightApp_DataOwner::keyString(); + aKey += QString("_%1").arg(index()); + return aKey; } /*!Gets index.*/ diff --git a/src/LightApp/LightApp_DataSubOwner.h b/src/LightApp/LightApp_DataSubOwner.h index 0bd219c42..7e8e7f3ea 100644 --- a/src/LightApp/LightApp_DataSubOwner.h +++ b/src/LightApp/LightApp_DataSubOwner.h @@ -32,8 +32,10 @@ public: LightApp_DataSubOwner( const QString&, const int ); virtual ~LightApp_DataSubOwner(); - virtual bool isEqual( const SUIT_DataOwner& ) const; - int index() const; + // *** jfa: The below line has been put here 14.02.2007. + // *** It cancels modifications from branch BR_Dev_For_4_0 + virtual QString keyString() const; + int index() const; private: int myIndex; diff --git a/src/SUIT/SUIT_DataOwner.cxx b/src/SUIT/SUIT_DataOwner.cxx index d97a249d3..139bc9cdf 100755 --- a/src/SUIT/SUIT_DataOwner.cxx +++ b/src/SUIT/SUIT_DataOwner.cxx @@ -16,6 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "SUIT_DataOwner.h" #ifndef WNT @@ -40,14 +41,31 @@ SUIT_DataOwner::~SUIT_DataOwner() bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 ) { if ( !p1.isNull() && !p2.isNull() ) - return (p1->isEqual( *p2 ) && p2->isEqual( *p1 )); + return (p1->keyString() == p2->keyString()); return p1.isNull() && p2.isNull(); } +// *** jfa: The below function has been put here 14.02.2007 from branch BR_Dev_For_4_0 +// *** and also improved for better comparison of DataOwners with DataSubOwners. +// *** This comment is to be removed after merging with BR_Dev_For_4_0. +/*! Operator < allows to order suit data owners for map */ +bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 ) +{ + if ( p1.isNull() && p2.isNull() ) + return false; + else if ( p1.isNull() ) + return true; + else if ( p2.isNull() ) + return false; + + return (p1->keyString() < p2->keyString()); +} +// *** end + /*! \class SUIT_DataOwnerPtrList implements value list with unique items (uniqueness is - provided by operator==()) + provided by operator==() and operator<()) */ /*! @@ -156,11 +174,3 @@ uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x ) myMap.remove(x); return QValueList::remove( x ); } - -/*! - Operator < allows to order suit data owners for map -*/ -bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 ) -{ - return p1->operator<( *p2 ); -} diff --git a/src/SUIT/SUIT_DataOwner.h b/src/SUIT/SUIT_DataOwner.h index 81fe710b8..7e88c58ff 100755 --- a/src/SUIT/SUIT_DataOwner.h +++ b/src/SUIT/SUIT_DataOwner.h @@ -40,9 +40,9 @@ class SUIT_EXPORT SUIT_DataOwner : public RefCount public: SUIT_DataOwner();//!< constructor virtual ~SUIT_DataOwner();//!< destructor - //! compare function - virtual bool isEqual( const SUIT_DataOwner& ) const = 0; - virtual bool operator<( const SUIT_DataOwner& ) const = 0; + // *** jfa: The below line has been put here 14.02.2007. + // *** It cancels modifications from branch BR_Dev_For_4_0 + virtual QString keyString() const = 0;//!< used for comparison }; /*! \typedef SUIT_DataOwnerPtr -- 2.39.2