]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Process step nodes for Field Result object
authorvsv <vsv@opencascade.com>
Wed, 22 Aug 2018 09:54:46 +0000 (12:54 +0300)
committervsv <vsv@opencascade.com>
Wed, 22 Aug 2018 09:55:03 +0000 (12:55 +0300)
src/PartSet/PartSet_TreeNodes.cpp
src/PartSet/PartSet_TreeNodes.h
src/XGUI/XGUI_DataModel.cpp

index fad5c0c9d45016990061e58778a2fbbc6e3b1e90..515f7cb0314b8bebbdec69ea7f2e4f815a07f720 100644 (file)
@@ -187,37 +187,84 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
   return NoneState;
 }
 
-void PartSet_ObjectNode::update()
+int PartSet_ObjectNode::numberOfSubs() const
+{
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
+  if (aCompRes.get())
+   return aCompRes->numberOfSubs(true);
+  else {
+    CompositeFeaturePtr aCompFeature =
+      std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
+    if (aCompFeature.get())
+      return aCompFeature->numberOfSubs(true);
+    else {
+      ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
+      if (aFieldRes.get())
+        return aFieldRes->stepsSize();
+    }
+  }
+  return 0;
+}
+
+
+ObjectPtr PartSet_ObjectNode::subObject(int theId) const
 {
-  CompositeFeaturePtr aCompFeature;
   ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
-  int aNb = 0;
   if (aCompRes.get())
-    aNb = aCompRes->numberOfSubs(true);
+    return aCompRes->subResult(theId, true);
   else {
-    aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
+    CompositeFeaturePtr aCompFeature =
+      std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
     if (aCompFeature.get())
-      aNb = aCompFeature->numberOfSubs(true);
+      return aCompFeature->subFeature(theId, true);
   }
+  return ObjectPtr();
+}
 
+void PartSet_ObjectNode::update()
+{
+  int aNb = numberOfSubs();
   if (aNb > 0) {
+    ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
+
+    // If the object is a field result then delete extra sub-objects
+    if (aFieldRes.get()) {
+      while (myChildren.size() > aNb) {
+        ModuleBase_ITreeNode* aNode = myChildren.last();
+        myChildren.removeAll(aNode);
+        delete aNode;
+      }
+    }
+
     ModuleBase_ITreeNode* aNode;
     ObjectPtr aBody;
     int i;
     for (i = 0; i < aNb; i++) {
-      if (aCompRes.get())
-        aBody = aCompRes->subResult(i, true);
-      else
-        aBody = aCompFeature->subFeature(i, true);
-
-      if (i < myChildren.size()) {
-        aNode = myChildren.at(i);
-        if (aNode->object() != aBody) {
-          ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+      aBody = subObject(i);
+      if (aBody.get()) {
+        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);
+        }
+      }
+      else if (aFieldRes.get()) {
+        ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+        if (i < myChildren.size()) {
+          PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
+          if (aStepNode->entity() != aStep) {
+            aStepNode->setEntity(aStep);
+          }
+        }
+        else {
+          aNode = new PartSet_StepNode(aStep, this);
+          myChildren.append(aNode);
         }
-      } else {
-        aNode = new PartSet_ObjectNode(aBody, this);
-        myChildren.append(aNode);
       }
     }
     // Delete extra objects
@@ -237,39 +284,41 @@ void PartSet_ObjectNode::update()
 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
 {
   QTreeNodesList aResult;
-
-  CompositeFeaturePtr aCompFeature;
-  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
-  int aNb = 0;
-  if (aCompRes.get())
-    aNb = aCompRes->numberOfSubs(true);
-  else {
-    aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
-    if (aCompFeature.get())
-      aNb = aCompFeature->numberOfSubs(true);
-  }
-
+  int aNb = numberOfSubs();
   if (aNb > 0) {
     ModuleBase_ITreeNode* aNode;
+    ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
     ObjectPtr aBody;
     int i;
     for (i = 0; i < aNb; i++) {
-      if (aCompRes.get())
-        aBody = aCompRes->subResult(i, true);
-      else
-        aBody = aCompFeature->subFeature(i, true);
-
-      if (i < myChildren.size()) {
-        aNode = myChildren.at(i);
-        if (aNode->object() != aBody) {
-          ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+      aBody = subObject(i);
+      if (aBody.get()) {
+        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);
+          aNode->update();
+        }
+      }
+      else {
+        ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+        if (i < myChildren.size()) {
+          PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
+          if (aStepNode->entity() != aStep) {
+            aStepNode->setEntity(aStep);
+          }
+        }
+        else {
+          aNode = new PartSet_StepNode(aStep, this);
+          myChildren.append(aNode);
         }
-      } else {
-        aNode = new PartSet_ObjectNode(aBody, this);
-        myChildren.append(aNode);
-        aResult.append(aNode);
-        aNode->update();
       }
     }
     foreach(ModuleBase_ITreeNode* aNode, myChildren) {
@@ -283,17 +332,7 @@ QTreeNodesList PartSet_ObjectNode::objectsDeleted(
   const DocumentPtr& theDoc, const QString& theGroup)
 {
   QTreeNodesList aResult;
-  CompositeFeaturePtr aCompFeature;
-  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
-  int aNb = 0;
-  if (aCompRes.get())
-    aNb = aCompRes->numberOfSubs(true);
-  else {
-    aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
-    if (aCompFeature.get())
-      aNb = aCompFeature->numberOfSubs(true);
-  }
-
+  int aNb = numberOfSubs();
   if (aNb > 0) {
     ModuleBase_ITreeNode* aNode;
     // Delete extra objects
@@ -308,11 +347,7 @@ QTreeNodesList PartSet_ObjectNode::objectsDeleted(
     int i = 0;
     ObjectPtr aBody;
     foreach(ModuleBase_ITreeNode* aNode, myChildren) {
-      if (aCompRes.get())
-        aBody = aCompRes->subResult(i, true);
-      else
-        aBody = aCompFeature->subFeature(i, true);
-
+      aBody = subObject(i);
       ((PartSet_ObjectNode*)aNode)->setObject(aBody);
       aResult.append(aNode->objectsDeleted(theDoc, theGroup));
       i++;
@@ -1050,3 +1085,17 @@ void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast)
   theFirst = aDoc->index(aFirstFeatureInFolder);
   theLast = aDoc->index(aLastFeatureInFolder);
 }
+
+
+//////////////////////////////////////////////////////////////////////////////////
+QVariant PartSet_StepNode::data(int theColumn, int theRole) const
+{
+  if ((theColumn == 1) && (theRole == Qt::DisplayRole)) {
+    ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
+      dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>(myEntity);
+
+    return "Step " + QString::number(aStep->id() + 1) + " " +
+      aStep->field()->textLine(aStep->id()).c_str();
+  }
+  return PartSet_TreeNode::data(theColumn, theRole);
+}
index 8a78317eac626aa37308f876ca2f3fd074eb01c7..37e6d54db359eb9dd8f8154e5c2033dda85287f0 100644 (file)
@@ -86,6 +86,11 @@ public:
   /// \param theGroup a name of group where objects were deleted
   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
 
+  /// Returns number of sub-objects of the current object
+  virtual int numberOfSubs() const;
+
+  virtual ObjectPtr subObject(int theId) const;
+
 protected:
   ObjectPtr myObject;
 };
@@ -334,32 +339,33 @@ private:
 * \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);
-//
-//};
+class PartSet_StepNode : public PartSet_TreeNode
+{
+public:
+  PartSet_StepNode(ModelAPI_Entity* theEnt, ModuleBase_ITreeNode* theParent) :
+    PartSet_TreeNode(theParent), myEntity(theEnt) {}
+
+  static std::string typeId()
+  {
+    static std::string myType = "FieldStep";
+    return myType;
+  }
+
+  virtual std::string type() const { return typeId(); }
+
+  /// Returns the node representation according to theRole.
+  virtual QVariant data(int theColumn, int theRole) const;
+
+  ModelAPI_Entity* entity() const {
+    return myEntity;
+  }
+
+  void setEntity(ModelAPI_Entity* theEnt) {
+    myEntity = theEnt;
+  }
+
+private:
+  ModelAPI_Entity* myEntity;
+};
 
 #endif
index 5cfb093044560a612438d04079886a28c6f99257..31cb8d3822dc3527e489f8b418a3d10a215d09c7 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModuleBase_ITreeNode.h>
 
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ResultField.h>
 
 #include <Config_FeatureMessage.h>
 
@@ -47,6 +48,7 @@ XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParen
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_ORDER_UPDATED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
 
 XGUI_DataModel::~XGUI_DataModel()
@@ -59,7 +61,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
 {
   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
     QObjectPtrList aCreated;
     std::set<ObjectPtr>::const_iterator aIt;
@@ -81,14 +83,14 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
     }
   }
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
-      std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
-          std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
-      const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>& aMsgGroups =
-        aUpdMsg->groups();
-      std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator aIt;
-      for (aIt = aMsgGroups.cbegin(); aIt != aMsgGroups.cend(); aIt++)
-        QTreeNodesList aList = myRoot->objectsDeleted(aIt->first, aIt->second.c_str());
-      rebuildDataTree();
+    std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
+      std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
+    const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>& aMsgGroups =
+      aUpdMsg->groups();
+    std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator aIt;
+    for (aIt = aMsgGroups.cbegin(); aIt != aMsgGroups.cend(); aIt++)
+      QTreeNodesList aList = myRoot->objectsDeleted(aIt->first, aIt->second.c_str());
+    rebuildDataTree();
   }
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
@@ -114,12 +116,24 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
     if (aRebuildAll) {
       myRoot->update();
       rebuildDataTree();
-    } else {
+    }
+    else {
       foreach(ObjectPtr aObj, aCreated) {
         ModuleBase_ITreeNode* aNode = myRoot->subNode(aObj);
         if (aNode) {
+          int aOldNb = aNode->childrenCount();
+          aNode->update();
+          int aNewNb = aNode->childrenCount();
+
           QModelIndex aFirstIdx = getIndex(aNode, 0);
           QModelIndex aLastIdx = getIndex(aNode, 2);
+
+          if (aNewNb > aOldNb) {
+            insertRows(aOldNb - 1, aNewNb - aOldNb, aFirstIdx);
+          }
+          else if (aNewNb < aOldNb) {
+            removeRows(aNewNb - 1, aOldNb - aNewNb, aFirstIdx);
+          }
           dataChanged(aFirstIdx, aLastIdx);
         }
       }
@@ -145,6 +159,40 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
       updateSubTree(aRoot);
     }
   }
+  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
+    std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+    std::set<ObjectPtr> aObjects = aUpdMsg->objects();
+
+    QObjectPtrList aCreated;
+    std::set<ObjectPtr>::const_iterator aIt;
+    bool aRebuildAll = false;
+    for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
+      ObjectPtr aObj = (*aIt);
+      if (aObj->groupName() == ModelAPI_ResultField::group()) {
+        aCreated.append(aObj);
+      }
+    }
+    foreach(ObjectPtr aObj, aCreated) {
+      ModuleBase_ITreeNode* aNode = myRoot->subNode(aObj);
+      if (aNode) {
+        int aOldNb = aNode->childrenCount();
+        aNode->update();
+        int aNewNb = aNode->childrenCount();
+
+        QModelIndex aFirstIdx = getIndex(aNode, 0);
+        QModelIndex aLastIdx = getIndex(aNode, 2);
+
+        if (aNewNb > aOldNb) {
+          insertRows(aOldNb - 1, aNewNb - aOldNb, aFirstIdx);
+        }
+        else if (aNewNb < aOldNb) {
+          removeRows(aNewNb - 1, aOldNb - aNewNb, aFirstIdx);
+        }
+        dataChanged(aFirstIdx, aLastIdx);
+      }
+    }
+  }
 }
 
 //******************************************************