Salome HOME
Compsolid nodes added
authorvsv <vsv@opencascade.com>
Tue, 24 Jul 2018 09:14:06 +0000 (12:14 +0300)
committervsv <vsv@opencascade.com>
Tue, 24 Jul 2018 09:14:06 +0000 (12:14 +0300)
src/PartSet/PartSet_TreeNodes.cpp
src/PartSet/PartSet_TreeNodes.h
src/XGUI/XGUI_DataModel.cpp

index 0e5b92ecf6a75148086179023a9fc4eed152fc28..38a8e6e2b1b4fbf0eb3e9543bec5207125ebbad8 100644 (file)
@@ -249,6 +249,14 @@ Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
   return aDefaultFlag;
 }
 
+ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
+{
+  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
+  if (aCompRes.get())
+    return new PartSet_CompsolidNode(theObj, this);
+  return new PartSet_ObjectNode(theObj, this);
+}
+
 void PartSet_FolderNode::update()
 {
   DocumentPtr aDoc = document();
@@ -275,14 +283,18 @@ void PartSet_FolderNode::update()
     ObjectPtr aObj = aDoc->object(aGroup, i, true);
     if (i < myChildren.size()) {
       if (myChildren.at(i)->object() != aObj) {
-        PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
+        ModuleBase_ITreeNode* aNode = createNode(aObj);
         myChildren.insert(i, aNode);
       }
     } else {
-      PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
+      ModuleBase_ITreeNode* aNode = createNode(aObj);
       myChildren.append(aNode);
     }
   }
+
+  foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+    aNode->update();
+  }
 }
 
 std::string PartSet_FolderNode::groupName() const
@@ -316,7 +328,7 @@ QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObject
       if (aIdx != -1) {
         bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
         if (!aHasObject) {
-          PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
+          ModuleBase_ITreeNode* aNode = createNode(aObj);
           aResult.append(aNode);
           if (aIdx < myChildren.size())
             myChildren.insert(aIdx, aNode);
@@ -326,6 +338,9 @@ QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObject
       }
     }
   }
+  foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+    aResult.append(aNode->objectCreated(theObjects));
+  }
   return aResult;
 }
 
@@ -351,6 +366,10 @@ QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
     }
     if (aRemoved)
       aResult.append(this);
+
+    foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+      aResult.append(aNode->objectsDeleted(theDoc, theGroup));
+    }
   }
   return aResult;
 }
@@ -360,13 +379,9 @@ QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& th
 {
   QTreeNodesList aResult;
   // Process all folders
-  ModuleBase_ITreeNode* aFoder = 0;
   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
-    if ((aNode->type() == PartSet_FolderNode::typeId()) ||
-      (aNode->type() == PartSet_PartRootNode::typeId())) { // aFolder node
-      QTreeNodesList aList = aNode->objectCreated(theObjects);
-      if (aList.size() > 0)
-        aResult.append(aList);
+    if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
+      aResult.append(aNode->objectCreated(theObjects));
     }
   }
   // Process the root sub-objects
@@ -880,3 +895,81 @@ void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast)
   theFirst = aDoc->index(aFirstFeatureInFolder);
   theLast = aDoc->index(aLastFeatureInFolder);
 }
+
+
+//////////////////////////////////////////////////////////////////////////////////
+PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
+  ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
+{
+  update();
+}
+
+void PartSet_CompsolidNode::update()
+{
+  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+  int aNb = aCompRes->numberOfSubs(true);
+  ModuleBase_ITreeNode* aNode;
+  ResultBodyPtr aBody;
+  int i;
+  for (i = 0; i < aNb; i++) {
+    aBody = aCompRes->subResult(i, true);
+    if (i < myChildren.size()) {
+      aNode = myChildren.at(i);
+      if (aNode->object() != aBody) {
+        ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+      }
+    } else {
+      aNode = new PartSet_ObjectNode(aBody, this);
+      myChildren.append(aNode);
+    }
+  }
+  // Delete extra objects
+  while (myChildren.size() > aNb) {
+    aNode = myChildren.takeLast();
+    delete aNode;
+  }
+}
+
+QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
+{
+  QTreeNodesList aResult;
+
+  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+  int aNb = aCompRes->numberOfSubs(true);
+  ModuleBase_ITreeNode* aNode;
+  ResultBodyPtr aBody;
+  int i;
+  for (i = 0; i < aNb; i++) {
+    aBody = aCompRes->subResult(i, true);
+    if (i < myChildren.size()) {
+      aNode = myChildren.at(i);
+      if (aNode->object() != aBody) {
+        ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+        aResult.append(aNode);
+      }
+    } else {
+      aNode = new PartSet_ObjectNode(aBody, this);
+      myChildren.append(aNode);
+      aResult.append(aNode);
+    }
+  }
+  return aResult;
+}
+
+QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
+{
+  QTreeNodesList aResult;
+  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+  int aNb = aCompRes->numberOfSubs(true);
+  ModuleBase_ITreeNode* aNode;
+  // Delete extra objects
+  bool isDeleted = false;
+  while (myChildren.size() > aNb) {
+    aNode = myChildren.takeLast();
+    delete aNode;
+    isDeleted = true;
+  }
+  if (isDeleted)
+    aResult.append(this);
+  return aResult;
+}
\ No newline at end of file
index 56aada4d8b9ded7b89e33a67254e6ea1df247c64..7ab9337ad70781455ec2ca568749791e0070202a 100644 (file)
@@ -67,6 +67,10 @@ public:
   /// Returns object referenced by the node (can be null)
   virtual ObjectPtr object() const { return myObject; }
 
+  /// Sets an object to the node
+  /// theObj a new object
+  void setObject(ObjectPtr theObj) { myObject = theObj; }
+
   /// Updates sub-nodes of the node
   virtual void update() {}
 
@@ -137,6 +141,8 @@ public:
 private:
   std::string groupName() const;
 
+  ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
+
   FolderType myType;
 };
 
@@ -312,4 +318,38 @@ private:
   void getFirstAndLastIndex(int& theFirst, int& theLast) const;
 };
 
-#endif
\ No newline at end of file
+
+/////////////////////////////////////////////////////////////////////
+/**
+* \ingroup Modules
+* Implementation of a node for compsolid representation
+*/
+class PartSet_CompsolidNode : public PartSet_ObjectNode
+{
+public:
+  PartSet_CompsolidNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
+
+  static std::string typeId()
+  {
+    static std::string myType = "CompSolid";
+    return myType;
+  }
+
+  virtual std::string type() const { return typeId(); }
+
+  /// Updates sub-nodes of the node
+  virtual void update();
+
+  /// Process creation of objects.
+  /// \param theObjects a list of created objects
+  /// \return a list of nodes which corresponds to the created objects
+  virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
+
+  /// Process deletion of objects.
+  /// \param theDoc a document where objects were deleted
+  /// \param theGroup a name of group where objects were deleted
+  virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
+
+};
+
+#endif
index d677b8d9409f1aa3f4b45495c28ee408b9d92a4b..5cfb093044560a612438d04079886a28c6f99257 100644 (file)
@@ -70,12 +70,14 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
     QTreeNodesList aNodes = myRoot->objectCreated(aCreated);
     ModuleBase_ITreeNode* aParent;
     int aRow = 0;
-    QModelIndex aParentIndex;
+    QModelIndex aParentIndex1, aParentIndex2;
     foreach(ModuleBase_ITreeNode* aNode, aNodes) {
       aParent = aNode->parent();
       aRow = aParent->nodeRow(aNode);
-      aParentIndex = getParentIndex(aNode, 0);
-      insertRows(aRow, 1, aParentIndex);
+      aParentIndex1 = getParentIndex(aNode, 0);
+      aParentIndex2 = getParentIndex(aNode, 2);
+      insertRows(aRow, 1, aParentIndex1);
+      dataChanged(aParentIndex1, aParentIndex2);
     }
   }
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {