]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
CCAR: development to implement notification mechanism between study manager
authorcaremoli <caremoli>
Mon, 3 Jan 2011 10:31:56 +0000 (10:31 +0000)
committercaremoli <caremoli>
Mon, 3 Jan 2011 10:31:56 +0000 (10:31 +0000)
and GUI (object browser). This implementation uses the Observer CORBA interface
defined in KERNEL module

12 files changed:
src/SUIT/SUIT_DataBrowser.cxx
src/SUIT/SUIT_DataBrowser.h
src/SUIT/SUIT_DataObject.cxx
src/SUIT/SUIT_DataObject.h
src/SUIT/SUIT_TreeModel.cxx
src/SUIT/SUIT_TreeModel.h
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_DataModel.cxx
src/SalomeApp/SalomeApp_DataObject.cxx
src/SalomeApp/SalomeApp_DataObject.h
src/SalomeApp/SalomeApp_Study.cxx
src/SalomeApp/SalomeApp_Study.h

index d4ec696a8feec3acdcf1daf4f2e3d4bc6411ff11..bae8d0ce806cf29294d6ff9a60b87a6f3d80be06 100644 (file)
@@ -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<SUIT_ProxyModel*>( 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<SUIT_ProxyModel*>( 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.
index 1c8e8d9582750513b3870c88eff81a3912f2c549..92ba03b8ebd90ca541e23a23908645c83dddce07 100644 (file)
@@ -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;
index 96f91e7d7ade73f71e8cb8ee7c5786b90c31976d..8716401c29178320bbcaf523232d09e81b9fbe89 100755 (executable)
@@ -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.
 
index 7966202486e6c90c067788bb6debc29a3e8e40be..c44155817406d21d7952bd66164cdcb62543e49f 100755 (executable)
@@ -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;
 
index 71211f3ca17996b773fe0347be35019045665c07..8e53c621b2ec941785672fe7208eaa6f4b3250f1 100755 (executable)
@@ -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<TreeItem*>      children() const;
@@ -78,6 +79,7 @@ private:
   TreeItem*             myParent;
   QList<TreeItem*>      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 <this> 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<ObjPtr,ItemPtr,SUIT_TreeModel::TreeSync>( obj, 
-                                                        treeItem( obj ), 
-                                                        SUIT_TreeModel::TreeSync( this ) );
+  if(updateModified())
+    {
+      updateTreeModel(obj,treeItem( obj ));
+    }
+  else
+    {
+      synchronize<ObjPtr,ItemPtr,SUIT_TreeModel::TreeSync>( 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.
 
index adc728c2d091ca99bd0c9f02999886fc669311e9..1163e8745e9de451c1b01478a65b989d18fbfeb5 100755 (executable)
@@ -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<ColumnInfo> 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;
 
index 6f049d5f6501269c93b9b562dab39dcd7b823436..aa203c52337f7660970749f731f850a4328cff32 100644 (file)
@@ -97,6 +97,9 @@
 
 #include <vector>
 
+//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
index a1a8f02d9461475d17806994059dcd2ffc9a58b5..5462099f2b0f3889f628fd1055cce19b74310bfa 100644 (file)
@@ -38,6 +38,9 @@
 #include <SALOMEconfig.h>
 #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<SalomeApp_RootObject*>(study->root());
+  if(!(root->toSynchronize()))
+    return suitObj;
+#endif
+
   SalomeApp_DataModelSync sync( study->studyDS(), study->root() );
 
   if( !suitObj || dynamic_cast<SalomeApp_DataObject*>( suitObj ) )
-    return ::synchronize<kerPtr,suitPtr,SalomeApp_DataModelSync>( sobj, suitObj, sync );
+    suitObj= ::synchronize<kerPtr,suitPtr,SalomeApp_DataModelSync>( sobj, suitObj, sync );
   else
-    return 0;
+    suitObj= 0;
+
+#ifdef WITH_SALOMEDS_OBSERVER
+  root->setToSynchronize(false);
+#endif
+
+  return suitObj;
 }
 
 /*!
index 28ac15f0e419e8c46b31ad77f5e477d2d2746923..ad79102085560ffaf165b4710d01e396d33a85f3 100644 (file)
@@ -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<SalomeApp_DataObject*>(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)
 {
 }
 
index 7e2fa1cb219307eec3e58d3509547b92cd511896..9487a6fe855790a8b38bda3d235cdc0110c9a18d 100644 (file)
@@ -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
index 7a00087838b447cfdbf016d9e6024a1df6fc49ca..1e5da9d5586ef36720e3ff5a2870e15a65bef555 100644 (file)
@@ -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 <OB_Browser.h>
 
 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<SalomeApp_DataObject*>(myStudy->root());
+                    while(1)
+                      {
+                        fin=obj_id.find_first_of(':',debut);
+                        if(fin == std::string::npos)
+                          {
+                            //last id
+                            anObj = dynamic_cast<SalomeApp_DataObject*>(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<SalomeApp_DataObject*>(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<string,SalomeApp_DataObject*> 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 );
 
index e63decf93416589ac777fd626624c0e7cb769d64..de95f130d865fa5977b0a45dd3da94961cc3fc06 100644 (file)
@@ -106,6 +106,9 @@ private:
 
 private:
   _PTR(Study)         myStudyDS;
+
+private:
+  SALOMEDS::Observer_var            myObserver;
 };
 
 #ifdef WIN32