From 889476a8d5e5937261aae3933825bd733cdaa835 Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 3 Jan 2011 10:31:56 +0000 Subject: [PATCH] CCAR: development to implement notification mechanism between study manager and GUI (object browser). This implementation uses the Observer CORBA interface defined in KERNEL module --- src/SUIT/SUIT_DataBrowser.cxx | 21 +++ src/SUIT/SUIT_DataBrowser.h | 3 + src/SUIT/SUIT_DataObject.cxx | 21 +++ src/SUIT/SUIT_DataObject.h | 5 + src/SUIT/SUIT_TreeModel.cxx | 180 ++++++++++++++++++++++-- src/SUIT/SUIT_TreeModel.h | 14 +- src/SalomeApp/SalomeApp_Application.cxx | 10 ++ src/SalomeApp/SalomeApp_DataModel.cxx | 19 ++- src/SalomeApp/SalomeApp_DataObject.cxx | 24 +++- src/SalomeApp/SalomeApp_DataObject.h | 7 + src/SalomeApp/SalomeApp_Study.cxx | 159 ++++++++++++++++++++- src/SalomeApp/SalomeApp_Study.h | 3 + 12 files changed, 449 insertions(+), 17 deletions(-) diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index d4ec696a8..bae8d0ce8 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -116,6 +116,27 @@ void SUIT_DataBrowser::setAutoUpdate( const bool on ) m->setAutoUpdate( on ); } +/*! + \brief Get 'updateModified' flag value. + \return 'updateModified' flag value +*/ +bool SUIT_DataBrowser::updateModified() const +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + return m ? m->updateModified() : false; +} + +/*! + \brief Set 'updateModified' flag value. + \param on 'updateModified' flag value +*/ +void SUIT_DataBrowser::setUpdateModified( const bool on ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + if ( m ) + m->setUpdateModified( on ); +} + /*! \brief Update object browser starting from the object \obj; open all branches automatically if \a autoOpen is \c true. diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index 1c8e8d958..92ba03b8e 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -47,6 +47,9 @@ public: bool autoUpdate() const; void setAutoUpdate( const bool ); + bool updateModified() const; + void setUpdateModified( const bool ); + void updateTree( SUIT_DataObject* = 0, const bool = true ); int updateKey() const; diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 96f91e7d7..8716401c2 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -282,6 +282,19 @@ void SUIT_DataObject::insertChild( SUIT_DataObject* obj, int position ) signal()->emitInserted( obj, this ); } +/*! + \brief Insert new child object into the list of the children (faster version of insertChild without signal). + \param obj child object being added + \param position child position +*/ +void SUIT_DataObject::insertChildAtPos( SUIT_DataObject* obj, int position ) +{ + if ( !obj )return; + int pos = position < 0 ? myChildren.count() : position; + myChildren.insert( qMin( pos, (int)myChildren.count() ), obj ); + obj->assignParent( this ); +} + /*! \brief Remove the specified child object reference. \param obj child object being removed @@ -375,6 +388,14 @@ void SUIT_DataObject::setParent( SUIT_DataObject* p ) parent()->appendChild( this ); } +void SUIT_DataObject::assignParent( SUIT_DataObject* p ) +{ + if ( p == myParent ) + return; + + myParent = p; +} + /*! \brief Get data object name. diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 796620248..c44155817 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -95,6 +95,10 @@ public: virtual SUIT_DataObject* parent() const; virtual void setParent( SUIT_DataObject* ); + virtual void assignParent( SUIT_DataObject* ); + void insertChildAtPos( SUIT_DataObject* obj, int position ); + bool modified(){return _modified;}; + void setModified(bool modified){_modified = modified;}; virtual QString name() const; virtual QString text( const int = NameId ) const; @@ -140,6 +144,7 @@ private: bool myCheck; bool myAutoDel; DataObjectList myChildren; + bool _modified; static Signal* mySignal; diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 71211f3ca..8e53c621b 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -68,6 +68,7 @@ public: SUIT_DataObject* dataObject() const; TreeItem* parent() const; int position() const; + void setPosition(int position) {_position=position;}; int childCount() const; TreeItem* child( const int i ); QList children() const; @@ -78,6 +79,7 @@ private: TreeItem* myParent; QList myChildren; SUIT_DataObject* myObj; + int _position; }; /*! @@ -91,7 +93,8 @@ SUIT_TreeModel::TreeItem::TreeItem( SUIT_DataObject* obj, SUIT_TreeModel::TreeItem* parent, SUIT_TreeModel::TreeItem* after ) : myParent( parent ), - myObj( obj ) + myObj( obj ), + _position(-1) { // Add to the parent's children list if ( myParent ) @@ -126,7 +129,7 @@ void SUIT_TreeModel::TreeItem::insertChild( SUIT_TreeModel::TreeItem* child, if ( !child ) return; - int index = after ? myChildren.indexOf( after ) + 1 : 0; + int index = after ? after->position() + 1 : 0; myChildren.insert( index, child ); } @@ -169,7 +172,7 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::TreeItem::parent() const */ int SUIT_TreeModel::TreeItem::position() const { - return myParent ? myParent->myChildren.indexOf( (TreeItem*)this ) : -1; + return _position; } /*! @@ -439,7 +442,8 @@ SUIT_TreeModel::SUIT_TreeModel( QObject* parent ) myRoot( 0 ), myRootItem( 0 ), myAutoDeleteTree( false ), - myAutoUpdate( true ) + myAutoUpdate( true ), + myUpdateModified( false ) { initialize(); } @@ -454,7 +458,8 @@ SUIT_TreeModel::SUIT_TreeModel( SUIT_DataObject* root, QObject* parent ) myRoot( root ), myRootItem( 0 ), myAutoDeleteTree( false ), - myAutoUpdate( true ) + myAutoUpdate( true ), + myUpdateModified( false ) { initialize(); } @@ -1019,6 +1024,22 @@ void SUIT_TreeModel::setAutoUpdate( const bool on ) } } +/*! + \brief Get 'updateModified' flag value. + \return 'updateModified' flag value +*/ +bool SUIT_TreeModel::updateModified() const +{ + return myUpdateModified; +} +/*! + \brief Set 'updateModified' flag value. + \param on 'updateModified' flag value +*/ +void SUIT_TreeModel::setUpdateModified(const bool on) +{ + myUpdateModified=on; +} /*! \brief Check if the specified column supports custom sorting. @@ -1073,6 +1094,68 @@ void SUIT_TreeModel::updateTree( const QModelIndex& index ) updateTree( object( index ) ); } + +void SUIT_TreeModel::updateTreeModel(SUIT_DataObject* obj,TreeItem* item) +{ + int kobj=0; + int kitem=0; + int nobjchild=obj->childCount(); + SUIT_DataObject* sobj=obj->childObject(kobj); + TreeItem* sitem = item->child(kitem); + + while(kobj < nobjchild) + { + if(sitem==0) + { + //end of item list + if(kitem==0) + sitem=createItemAtPos(sobj,item,0); + else + sitem=createItemAtPos(sobj,item,kitem); + updateTreeModel(sobj,sitem); + kobj++; + kitem++; + sobj=obj->childObject(kobj); + sitem = item->child(kitem); + } + else if(sitem->dataObject() != sobj) + { + if(treeItem(sobj)) + { + // item : to remove + removeItem(sitem); + sitem = item->child(kitem); + } + else + { + // obj : new object + createItemAtPos(sobj,item,kitem); + kobj++; + kitem++; + sobj=obj->childObject(kobj); + sitem = item->child(kitem); + } + } + else + { + //obj and item are synchronised : go to next ones + updateTreeModel(sobj,sitem); + if(sobj->modified()) updateItem(sitem); + if( sobj ) sobj->update(); + kobj++; + kitem++; + sobj=obj->childObject(kobj); + sitem = item->child(kitem); + } + } + //remove remaining items + for(int i = item->childCount(); i > kitem;i--) + { + sitem = item->child(i-1); + removeItem(sitem); + } +} + /*! \brief Update tree model. @@ -1091,9 +1174,16 @@ void SUIT_TreeModel::updateTree( SUIT_DataObject* obj ) else if ( obj->root() != root() ) return; - synchronize( obj, - treeItem( obj ), - SUIT_TreeModel::TreeSync( this ) ); + if(updateModified()) + { + updateTreeModel(obj,treeItem( obj )); + } + else + { + synchronize( obj, + treeItem( obj ), + SUIT_TreeModel::TreeSync( this ) ); + } emit modelUpdated(); } @@ -1196,11 +1286,51 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItem( SUIT_DataObject* obj, myItems[ obj ] = new TreeItem( obj, parent, after ); + for(int pos=row;pos < parent->childCount();pos++) + parent->child(pos)->setPosition(pos); + endInsertRows(); + obj->setModified(false); + return myItems[ obj ]; } +/*! + \brief Create an item corresponding to the data object. + \param obj source data object + \param parent parent tree item + \param pos tree item position into which new item should be inserted + \return created tree item or 0 if item could not be created +*/ +SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItemAtPos( SUIT_DataObject* obj, + SUIT_TreeModel::TreeItem* parent, + int pos ) +{ + if ( !obj ) + return 0; + + SUIT_DataObject* parentObj = object( parent ); + QModelIndex parentIdx = index( parentObj ); + + int row = pos ; + SUIT_TreeModel::TreeItem* after = pos>0 ? parent->child(pos-1) : 0 ; + + beginInsertRows( parentIdx, row, row ); + + SUIT_TreeModel::TreeItem* item = new TreeItem( obj, parent, after ); + myItems[ obj ] = item; + + for(int pos=row;pos < parent->childCount();pos++) + parent->child(pos)->setPosition(pos); + + endInsertRows(); + + obj->setModified(false); + + return item; +} + /*! \brief Update tree item. \param item tree item to be updated @@ -1218,6 +1348,7 @@ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item ) QModelIndex firstIdx = index( obj, 0 ); QModelIndex lastIdx = index( obj, columnCount() - 1 ); emit dataChanged( firstIdx, lastIdx ); + obj->setModified(false); } /*! @@ -1239,7 +1370,8 @@ void SUIT_TreeModel::removeItem( SUIT_TreeModel::TreeItem* item ) // Warning! obj can be deleted at this point! - SUIT_DataObject* parentObj = object( item->parent() ); + TreeItem* parent=item->parent(); + SUIT_DataObject* parentObj = object( parent ); QModelIndex parentIdx = index( parentObj, 0 ); int row = item->position(); @@ -1248,8 +1380,12 @@ void SUIT_TreeModel::removeItem( SUIT_TreeModel::TreeItem* item ) if ( obj == root() ) setRoot( 0 ); - else if ( item->parent() ) - item->parent()->removeChild( item ); + else if ( parent ) + { + parent->removeChild( item ); + for(int pos=row;pos < parent->childCount();pos++) + parent->child(pos)->setPosition(pos); + } delete item; @@ -1412,6 +1548,28 @@ bool SUIT_ProxyModel::autoUpdate() const return treeModel() ? treeModel()->autoUpdate() : false; } +/*! + \brief Get 'updateModified' flag value. + \return 'updateModified' flag value +*/ +bool SUIT_ProxyModel::updateModified() const +{ + return treeModel() ? treeModel()->updateModified() : false; +} +/*! + \brief Set 'updateModified' flag value. + + If this flag is set to \c true (default=false), the model is updated by updateTreeModel that + uses the isModified flag to update only modified objects + + \param on 'updateModified' flag value +*/ +void SUIT_ProxyModel::setUpdateModified( const bool on ) +{ + if ( treeModel() ) + treeModel()->setUpdateModified( on ); +} + /*! \brief Set 'auto-update tree' flag value. diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index adc728c2d..1163e8745 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -57,6 +57,8 @@ public: virtual void setAutoDeleteTree( const bool ) = 0; virtual bool autoUpdate() const = 0; virtual void setAutoUpdate( const bool ) = 0; + virtual bool updateModified() const = 0; + virtual void setUpdateModified( const bool ) = 0; virtual QAbstractItemDelegate* delegate() const = 0; virtual bool customSorting( const int ) const = 0; virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const = 0; @@ -138,11 +140,16 @@ public: bool autoUpdate() const; void setAutoUpdate( const bool ); + bool updateModified() const; + void setUpdateModified( const bool ); + virtual bool customSorting( const int ) const; virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const; QAbstractItemDelegate* delegate() const; + virtual void updateTreeModel(SUIT_DataObject*,TreeItem*); + public slots: virtual void updateTree( const QModelIndex& ); virtual void updateTree( SUIT_DataObject* = 0 ); @@ -159,6 +166,7 @@ private: SUIT_DataObject* object( const TreeItem* ) const; TreeItem* createItem( SUIT_DataObject*, TreeItem* = 0, TreeItem* = 0 ); + TreeItem* createItemAtPos( SUIT_DataObject*, TreeItem* = 0, int pos=0 ); void updateItem( TreeItem* ); void removeItem( TreeItem* ); @@ -182,6 +190,7 @@ private: ItemMap myItems; bool myAutoDeleteTree; bool myAutoUpdate; + bool myUpdateModified; QVector myColumns; friend class SUIT_TreeModel::TreeSync; @@ -208,7 +217,10 @@ public: bool autoUpdate() const; void setAutoUpdate( const bool ); - + + bool updateModified() const; + void setUpdateModified( const bool ); + bool isSortingEnabled() const; bool customSorting( const int ) const; diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 6f049d5f6..aa203c523 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -97,6 +97,9 @@ #include +//To activate update of Object Browser with SALOMEDS::Observer uncomment following line +#define WITH_SALOMEDS_OBSERVER + /*!Internal class that updates object browser item properties */ // temporary commented /*class SalomeApp_Updater : public OB_Updater @@ -852,6 +855,13 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) // temporary commented //ob->setUpdater( new SalomeApp_Updater() ); +#ifdef WITH_SALOMEDS_OBSERVER + //do not activate the automatic update of Qt tree through signal/slot + ob->setAutoUpdate(false); + //activate update of modified objects only + ob->setUpdateModified(true); +#endif + connect( ob, SIGNAL( doubleClicked( SUIT_DataObject* ) ), this, SLOT( onDblClick( SUIT_DataObject* ) ) ); QString diff --git a/src/SalomeApp/SalomeApp_DataModel.cxx b/src/SalomeApp/SalomeApp_DataModel.cxx index a1a8f02d9..5462099f2 100644 --- a/src/SalomeApp/SalomeApp_DataModel.cxx +++ b/src/SalomeApp/SalomeApp_DataModel.cxx @@ -38,6 +38,9 @@ #include #include CORBA_SERVER_HEADER(SALOME_Exception) +//To activate update of Object Browser with SALOMEDS::Observer uncomment following line +#define WITH_SALOMEDS_OBSERVER + typedef _PTR(SObject) kerPtr; typedef SUIT_DataObject* suitPtr; @@ -348,12 +351,24 @@ SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SComponent )& sob } } +#ifdef WITH_SALOMEDS_OBSERVER + SalomeApp_RootObject* root=dynamic_cast(study->root()); + if(!(root->toSynchronize())) + return suitObj; +#endif + SalomeApp_DataModelSync sync( study->studyDS(), study->root() ); if( !suitObj || dynamic_cast( suitObj ) ) - return ::synchronize( sobj, suitObj, sync ); + suitObj= ::synchronize( sobj, suitObj, sync ); else - return 0; + suitObj= 0; + +#ifdef WITH_SALOMEDS_OBSERVER + root->setToSynchronize(false); +#endif + + return suitObj; } /*! diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index 28ac15f0e..ad7910208 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -557,6 +557,27 @@ QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const return val; } +void SalomeApp_DataObject::insertChildAtTag(SalomeApp_DataObject* obj,int tag) +{ + int pos=0; + int npos=std::min(tag-1,childCount()); + for (int i=npos;i>0;i--) + { + if((dynamic_cast(childObject(i-1)))->object()->Tag() < tag) + { + pos=i-1; + break; + } + } + insertChildAtPos(obj,pos+1); +} + +void SalomeApp_DataObject::updateItem() +{ + if(modified())return; + setModified(true); +} + /*! \class SalomeApp_ModuleObject \brief This class is used for optimized access to the SALOMEDS-based @@ -660,7 +681,8 @@ SalomeApp_RootObject::SalomeApp_RootObject( LightApp_Study* study ) : CAM_DataObject( 0 ), LightApp_DataObject( 0 ), SalomeApp_DataObject( 0 ), - LightApp_RootObject( study ) + LightApp_RootObject( study ), + _toSynchronize(true) { } diff --git a/src/SalomeApp/SalomeApp_DataObject.h b/src/SalomeApp/SalomeApp_DataObject.h index 7e2fa1cb2..9487a6fe8 100644 --- a/src/SalomeApp/SalomeApp_DataObject.h +++ b/src/SalomeApp/SalomeApp_DataObject.h @@ -69,6 +69,9 @@ public: virtual bool customSorting( const int = NameId ) const; virtual bool compare( const QVariant&, const QVariant&, const int = NameId ) const; + virtual void insertChildAtTag( SalomeApp_DataObject*, int ); + virtual void updateItem(); + private: QString ior( const _PTR(SObject)& ) const; QString entry( const _PTR(SObject)& ) const; @@ -105,6 +108,10 @@ public: QPixmap icon( const int = NameId ) const; QColor color( const ColorRole, const int = NameId ) const; QString toolTip( const int = NameId ) const; + void setToSynchronize(bool value){_toSynchronize=value;}; + bool toSynchronize() const {return _toSynchronize;}; +protected: + bool _toSynchronize; }; class SALOMEAPP_EXPORT SalomeApp_SavePointObject : public virtual LightApp_DataObject diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 7a0008783..1e5da9d55 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -28,6 +28,8 @@ #include "SalomeApp_Application.h" #include "SalomeApp_Engine_i.hxx" #include "SalomeApp_VisualState.h" +#include "SUIT_TreeModel.h" +#include "SUIT_DataBrowser.h" // temporary commented //#include @@ -45,6 +47,139 @@ using namespace std; +//To activate update of Object Browser with SALOMEDS::Observer uncomment following line +#define WITH_SALOMEDS_OBSERVER + +class Observer_i : public virtual POA_SALOMEDS::Observer +{ + public: + + Observer_i(_PTR(Study) aStudyDS, SalomeApp_Study* aStudy) + { + myStudyDS=aStudyDS; + myStudy=aStudy; + } + + virtual void notifyObserverID(const char* theID, ::CORBA::Long event) + { + SalomeApp_DataObject* suit_obj; + + if (event == 1) // add sobject + { + if (entry2SuitObject.count(theID)>0) + { + std::cerr << "entry " << theID << " is already added. Problem ??" << std::endl; + return; + } + _PTR(SObject) obj = myStudyDS->FindObjectID( theID ); + std::string entry_str = theID; + int last2Pnt_pos = entry_str.rfind(":"); + std::string parent_id=entry_str.substr(0,last2Pnt_pos); + std::string pos_in_parent=entry_str.substr(last2Pnt_pos+1); + + if(parent_id.length() == 3 ) + { + //It's probably a SComponent + _PTR(SComponent) aSComp=obj->GetFatherComponent(); + if( aSComp->GetID() == entry_str ) + suit_obj=new SalomeApp_ModuleObject(aSComp,0); + else + suit_obj=new SalomeApp_DataObject(obj,0); + } + else + suit_obj=new SalomeApp_DataObject(obj,0); + + if (entry2SuitObject.count(parent_id)>0) + { + SalomeApp_DataObject* father=entry2SuitObject[parent_id]; + int tag=atoi(pos_in_parent.c_str()); + father->insertChildAtTag(suit_obj,tag); + } + else + { + if(parent_id.length() == 3 ) + { + // This should be for a module + SUIT_DataObject* father=myStudy->root(); + father->appendChild(suit_obj); + } + else + { + //Try to find the SalomeApp_DataObject object parent + std::string root_id=parent_id.substr(0,4); + std::string obj_id=parent_id.substr(4); + + std::string anID; + string::size_type debut =0; + string::size_type fin; + SalomeApp_DataObject* anObj=dynamic_cast(myStudy->root()); + while(1) + { + fin=obj_id.find_first_of(':',debut); + if(fin == std::string::npos) + { + //last id + anObj = dynamic_cast(anObj->childObject(atoi(obj_id.substr(debut).c_str())-1)); + entry2SuitObject[parent_id]=anObj; + break; + } + anID=root_id+obj_id.substr(0,fin); + if (entry2SuitObject.count(anID) == 0) + { + //the ID is not known in entry2SuitObject + anObj = dynamic_cast(anObj->childObject(atoi(obj_id.substr(debut,fin-debut).c_str())-1)); + entry2SuitObject[anID]=anObj; + } + else + anObj=entry2SuitObject[anID]; + debut=fin+1; + } + int tag=atoi(pos_in_parent.c_str()); + anObj->insertChildAtTag(suit_obj,tag); + } + } + entry2SuitObject[theID]=suit_obj; + } + else if (event == 2) // remove sobject + { + if (entry2SuitObject.count(theID)>0) + { + suit_obj= entry2SuitObject[theID]; + SUIT_DataObject* father=suit_obj->parent(); + if(father) + father->removeChild(suit_obj); + entry2SuitObject.erase(theID); + } + else + { + MESSAGE("Want to remove an unknown object" << theID); + } + } + else if (event == 0) //modify sobject + { + if (entry2SuitObject.count(theID)>0) + { + suit_obj= entry2SuitObject[theID]; + suit_obj->updateItem(); + } + else + { + MESSAGE("Want to modify an unknown object" << theID); + } + } + else + { + MESSAGE("Unknown event: " << event); + } + } + + private: + _PTR(Study) myStudyDS; + SalomeApp_Study* myStudy; + map entry2SuitObject; +}; + + /*! Constructor. */ @@ -103,7 +238,7 @@ _PTR(Study) SalomeApp_Study::studyDS() const */ bool SalomeApp_Study::createDocument( const QString& theStr ) { - MESSAGE( "openDocument" ); + MESSAGE( "createDocument" ); // initialize myStudyDS, read HDF file QString aName = newStudyName(); @@ -115,11 +250,19 @@ bool SalomeApp_Study::createDocument( const QString& theStr ) setStudyName( aName ); // create myRoot - setRoot( new SalomeApp_RootObject( this ) ); + SalomeApp_RootObject* aRoot=new SalomeApp_RootObject( this ); + aRoot->setToSynchronize(false); + setRoot( aRoot ); bool aRet = CAM_Study::createDocument( theStr ); emit created( this ); +#ifdef WITH_SALOMEDS_OBSERVER + Observer_i* myObserver_i = new Observer_i(myStudyDS,this); + //attach an observer to the study with notification of modifications + myStudyDS->attach(myObserver_i->_this(),true); +#endif + return aRet; } @@ -152,6 +295,12 @@ bool SalomeApp_Study::openDocument( const QString& theFileName ) // but tree that corresponds to not-loaded data models will be updated any way. ((SalomeApp_Application*)application())->updateObjectBrowser( false ); +#ifdef WITH_SALOMEDS_OBSERVER + Observer_i* myObserver_i = new Observer_i(myStudyDS,this); + //attach an observer to the study with notification of modifications + myStudyDS->attach(myObserver_i->_this(),true); +#endif + bool res = CAM_Study::openDocument( theFileName ); emit opened( this ); @@ -200,6 +349,12 @@ bool SalomeApp_Study::loadDocument( const QString& theStudyName ) // but tree that corresponds to not-loaded data models will be updated any way. ((SalomeApp_Application*)application())->updateObjectBrowser( false ); +#ifdef WITH_SALOMEDS_OBSERVER + Observer_i* myObserver_i = new Observer_i(myStudyDS,this); + //attach an observer to the study with notification of modifications + myStudyDS->attach(myObserver_i->_this(),true); +#endif + bool res = CAM_Study::openDocument( theStudyName ); emit opened( this ); diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index e63decf93..de95f130d 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -106,6 +106,9 @@ private: private: _PTR(Study) myStudyDS; + +private: + SALOMEDS::Observer_var myObserver; }; #ifdef WIN32 -- 2.39.2