Salome HOME
Update tree branch individually
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 11 Apr 2014 12:13:01 +0000 (16:13 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 11 Apr 2014 12:13:01 +0000 (16:13 +0400)
src/Event/Event_Message.h
src/Model/Model_Events.h
src/XGUI/XGUI_DataTreeModel.h
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_PartDataModel.h
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_SelectionMgr.h
src/XGUI/XGUI_Workshop.cpp

index e07621af75f692e7045c558d065d88706bbd7164..0c2702072962c479e0ad55d341d5a98dbdbdc4b8 100644 (file)
@@ -51,7 +51,7 @@ public:
   const Event_ID& eventID() const {return myEventId;}
 
   //! Returns sender of the message or NULL if it is anonymous message
-  void* sender() {return mySender;}
+  void* sender() const {return mySender;}
 };
 
 #endif
index 0fc4f329c0efefbb302b0a02a73091d9cea15561..c4af9f5279248d6423bec10de83b7d63eb638cfc 100644 (file)
@@ -32,9 +32,9 @@ public:
     const Event_ID& theEvent);
 
   /// Returns the feature that has been updated
-  std::shared_ptr<ModelAPI_Feature> feature() {return myFeature;}
+  std::shared_ptr<ModelAPI_Feature> feature() const {return myFeature;}
   /// Returns the document that has been updated
-  std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
+  std::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
 };
 
 /// Message that feature was deleted (used for Object Browser update)
@@ -50,10 +50,10 @@ public:
   static const Event_ID messageId();
 
   /// Returns the feature that has been updated
-  std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
+  std::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
 
   /// Returns the group where the feature was deleted
-  const std::string& group() {return myGroup;}
+  const std::string& group() const {return myGroup;}
 };
 
 #endif
index 3be26bd2a53c0f1200c99c7e84cd8c5efaff32c1..8f0ffd8d32303cf2a29cc6229b070d21a520f14b 100644 (file)
@@ -22,6 +22,9 @@ public:
   //! Returns 0 if the given index is not index of a feature
   virtual FeaturePtr feature(const QModelIndex& theIndex) const = 0;
 
+  //! Returns parent index of the given feature
+  virtual QModelIndex findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
+
 protected:
   std::shared_ptr<ModelAPI_Document> myDocument;
 };
@@ -37,7 +40,10 @@ public:
   XGUI_PartModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent):
       XGUI_FeaturesModel(theDocument, theParent) {}
 
-      void setPartId(int theId) { myId = theId; }
+  void setPartId(int theId) { myId = theId; }
+
+  //! Returns true if the given document is a sub-document of this tree
+  virtual bool hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const = 0;
 
 protected:
   //! Id of the current part object in the document
index 1e53953f7a9af85c3e650f02ed1cbf91144f804d..a17b618eedc163ca2113eac9ab8e63c634398e74 100644 (file)
@@ -40,13 +40,47 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
 void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage)
 {
   if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) {
-    // Add a new part
-    int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size();
-    beginInsertRows(QModelIndex(), aStart, aStart + 1);
-    XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this);
-    aModel->setPartId(myPartModels.count());
-    myPartModels.append(aModel);
-    endInsertRows();
+    const ModelAPI_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
+    std::shared_ptr<ModelAPI_Document> aDoc = aUpdMsg->document();
+    std::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
+
+    if (aDoc == myDocument) {
+      if (aFeature->getGroup().compare(PARTS_GROUP) == 0) {
+        // Add a new part
+        int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size();
+        beginInsertRows(QModelIndex(), aStart, aStart + 1);
+        XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this);
+        aModel->setPartId(myPartModels.count());
+        myPartModels.append(aModel);
+        endInsertRows();
+      } else {
+        QModelIndex aIndex = myModel->findParent(aFeature);
+        int aStart = myModel->rowCount(aIndex);
+        aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
+        beginInsertRows(aIndex, aStart-1, aStart);
+        endInsertRows();
+        if (aStart == 1) // Update parent if this is a first child in order to update node decoration
+          emit dataChanged(aIndex, aIndex);
+      }
+    } else {
+      XGUI_PartModel* aPartModel = 0;
+      QList<XGUI_PartModel*>::const_iterator aIt;
+      for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) {
+        if ((*aIt)->hasDocument(aDoc)) {
+          aPartModel = (*aIt);
+          break;
+        }
+      }
+      if (aPartModel) {
+        QModelIndex aIndex = aPartModel->findParent(aFeature);
+        int aStart = aPartModel->rowCount(aIndex);
+        aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
+        beginInsertRows(aIndex, aStart-1, aStart);
+        endInsertRows();
+        if (aStart == 1) // Update parent if this is a first child in order to update node decoration
+          emit dataChanged(aIndex, aIndex);
+      }
+    }
   } else {
     // Reset whole tree
     beginResetModel();
index f68b5fc4a0bc80549363786452244953ecbde345..e58d06ef0206a69e733f21d4d36f8451a9614aae 100644 (file)
@@ -30,14 +30,16 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
     case ParamObject:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       } 
     case ConstructFolder:
         return tr("Constructions");
     case ConstructObject:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     }
     break;
@@ -139,6 +141,18 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
 }
 
 
+QModelIndex XGUI_TopDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+  QString aGroup(theFeature->getGroup().c_str());
+
+  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+    return createIndex(0, 0, (quintptr) ParamsFolder);
+  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+    return createIndex(1, 0, (quintptr) ConstructFolder);
+  return QModelIndex();
+}
+
+
 //******************************************************************
 //******************************************************************
 //******************************************************************
@@ -161,7 +175,8 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     case MyRoot:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     case ParamsFolder:
       return tr("Parameters");
@@ -171,13 +186,15 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = 
           featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     case ConstructObject:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = 
           featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     }
     break;
@@ -294,3 +311,20 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
   }
   return 0;
 }
+
+bool XGUI_PartDataModel::hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const
+{
+  return (featureDocument() == theDoc);
+}
+
+
+QModelIndex XGUI_PartDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+  QString aGroup(theFeature->getGroup().c_str());
+
+  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+    return createIndex(0, 0, (quintptr) ParamsFolder);
+  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+    return createIndex(1, 0, (quintptr) ConstructFolder);
+  return QModelIndex();
+}
\ No newline at end of file
index 559f007329ec32dbb8c2037854234aa73c65492a..1b3b069bf1c1d152cf9a85c41f4d30d3a579a57d 100644 (file)
@@ -35,6 +35,8 @@ public:
   //! Returns 0 if the given index is not index of a feature
   virtual FeaturePtr feature(const QModelIndex& theIndex) const;
 
+  virtual QModelIndex findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
+
 private:
   //! Types of QModelIndexes
   enum DataIds {
@@ -78,6 +80,12 @@ public:
   //! Returns 0 if the given index is not index of a feature
   virtual FeaturePtr feature(const QModelIndex& theIndex) const;
 
+  //! Returns true if the given document is a sub-document of this tree
+  virtual bool hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const;
+
+  //! Returns parent index of the given feature
+  virtual QModelIndex findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
+
 private: 
   std::shared_ptr<ModelAPI_Document> featureDocument() const;
 
index cbff6377398b64164fa5c3d27defa3bfa5d0195d..510fb1b4062b2776e50862ecd83e4f812ef8044f 100644 (file)
 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
   QObject(theParent), myWorkshop(theParent)
 {
-  XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->mainWindow()->objectBrowser();
-
-  connect(aObjBrowser, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
 }
 
+void XGUI_SelectionMgr::connectObjectBrowser(XGUI_ObjectsBrowser* theOB)
+{
+  myObjectBrowser = theOB;
+  connect(myObjectBrowser, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+}
 
 XGUI_SelectionMgr::~XGUI_SelectionMgr()
 {
index 58af58ea0515878ba974481329f58e539ec0a8f4..23849befe8930785c3c23d381e1c0990badff671 100644 (file)
@@ -5,6 +5,7 @@
 #include <QObject>
 
 class XGUI_Workshop;
+class XGUI_ObjectsBrowser;
 
 /**\class XGUI_SelectionMgr
  * \ingroup GUI
@@ -21,6 +22,8 @@ public:
   //! Returns list of currently selected objects
   QFeatureList selectedData() const { return mySelectedData; }
 
+  void connectObjectBrowser(XGUI_ObjectsBrowser* theOB);
+
 signals:
   //! Emited when selection in a one of viewers was changed
   void selectionChanged();
@@ -30,6 +33,7 @@ public slots:
 
 private:
   XGUI_Workshop* myWorkshop;
+  XGUI_ObjectsBrowser* myObjectBrowser;
 
   //! List of selected features
   QFeatureList mySelectedData;
index 6ff419ecf47d15b95119e5bb89382974e945abdc..284332eed3ceefd757fcb002492adcdd67e66812 100644 (file)
@@ -252,8 +252,10 @@ void XGUI_Workshop::onExit()
 void XGUI_Workshop::onNew()
 {
   QApplication::setOverrideCursor(Qt::WaitCursor);
-  if (myMainWindow->objectBrowser() == 0)
+  if (myMainWindow->objectBrowser() == 0) {
     myMainWindow->createDockWidgets();
+    mySelector->connectObjectBrowser(myMainWindow->objectBrowser());
+  }
   myMainWindow->showObjectBrowser();
   myMainWindow->showPythonConsole();
   QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();