Salome HOME
Make step as Object
authorvsv <vsv@opencascade.com>
Mon, 24 Jun 2019 13:17:49 +0000 (16:17 +0300)
committervsv <vsv@opencascade.com>
Mon, 24 Jun 2019 13:17:49 +0000 (16:17 +0300)
src/Model/Model_ResultField.cpp
src/Model/Model_ResultField.h
src/ModelAPI/ModelAPI_ResultField.cpp
src/ModelAPI/ModelAPI_ResultField.h
src/PartSet/PartSet_TreeNodes.cpp
src/PartSet/PartSet_TreeNodes.h
src/XGUI/XGUI_ObjectsBrowser.cpp

index 7eaa8b2b47a65364aa87b2705d42ea7795798d2b..f345f733f66fc0063438647bff2e2a90fe47be01 100644 (file)
@@ -37,7 +37,7 @@ Model_ResultField::Model_ResultField(std::shared_ptr<ModelAPI_Data> theOwnerData
 Model_ResultField::~Model_ResultField()
 {
   while(mySteps.size() > 0) {
-    delete mySteps.back();
+    //delete mySteps.back();
     mySteps.pop_back();
   }
 }
@@ -106,11 +106,11 @@ void Model_ResultField::updateSteps()
   int aNbSteps = stepsSize();
   if (mySteps.size() != aNbSteps) {
     while(mySteps.size() > aNbSteps) {
-      delete mySteps.back();
+      //delete mySteps.back();
       mySteps.pop_back();
     }
     while(mySteps.size() < aNbSteps) {
-      mySteps.push_back(new Model_ResultField::Model_FieldStep(this, int(mySteps.size())));
+      mySteps.push_back(FieldStepPtr(new Model_ResultField::Model_FieldStep(this, int(mySteps.size()))));
     }
   }
 }
@@ -143,7 +143,7 @@ std::string Model_ResultField::textLine(int theLine) const
 
 // used by GUI only
 // LCOV_EXCL_START
-ModelAPI_ResultField::ModelAPI_FieldStep* Model_ResultField::step(int theId) const
+std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> Model_ResultField::step(int theId) const
 {
   if (theId < mySteps.size()) {
     return mySteps[theId];
index 52d0b82aac4a3e87df59b928066c8ad24d27b16c..307861c3494978eb85c1528b03ed151e88cf1ab5 100644 (file)
@@ -39,12 +39,14 @@ public:
   {
   public:
     Model_FieldStep(ModelAPI_ResultField* theParent, int theId)
-      : myParent(theParent), myId(theId) {};
+      : ModelAPI_ResultField::ModelAPI_FieldStep(), myParent(theParent), myId(theId) {};
 
     virtual ModelAPI_ResultField* field() const { return myParent; }
 
     virtual int id() const { return myId; }
 
+    virtual std::shared_ptr<ModelAPI_Document> document() const { return myParent->document(); }
+
   private:
     ModelAPI_ResultField* myParent;
     int myId;
@@ -66,7 +68,7 @@ public:
 
   /// Returns step object
   /// \param theId an id of the object
-  MODEL_EXPORT virtual ModelAPI_ResultField::ModelAPI_FieldStep* step(int theId) const;
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> step(int theId) const;
 
   /// Removes the stored builders
   MODEL_EXPORT virtual ~Model_ResultField();
@@ -80,7 +82,7 @@ protected:
 private:
   void updateSteps();
 
-  std::vector<ModelAPI_FieldStep*> mySteps;
+  std::vector<FieldStepPtr> mySteps;
 };
 
 #endif
index 760887376fbac9b4462f4abef223ce1d9c00931b..15f8bba963bff391a695ee70a96309779458d1f2 100644 (file)
@@ -18,6 +18,8 @@
 //
 
 #include "ModelAPI_ResultField.h"
+#include "ModelAPI_Events.h"
+#include <Events_Loop.h>
 
 ModelAPI_ResultField::~ModelAPI_ResultField()
 {
@@ -28,3 +30,12 @@ std::string ModelAPI_ResultField::groupName()
 {
   return group();
 }
+
+void ModelAPI_ResultField::ModelAPI_FieldStep::setDisplayed(const bool theDisplay)
+{
+  myIsDisplayed = theDisplay;
+  //static Events_Loop* aLoop = Events_Loop::loop();
+  //static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  //static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+  //aECreator->sendUpdated(FieldStepPtr(this), EVENT_DISP);
+}
index eb9d4a7b61931ffe2fba531025efe8a701ad5325..2393be2bf5e6ad716c0396cf7e1d282b7e686e69 100644 (file)
@@ -35,12 +35,45 @@ class ModelAPI_ResultField : public ModelAPI_Result
 {
 public:
 
-  class ModelAPI_FieldStep : public ModelAPI_Entity
+  class ModelAPI_FieldStep : public ModelAPI_Object
   {
   public:
     virtual ModelAPI_ResultField* field() const = 0;
 
     virtual int id() const = 0;
+
+    /// Returns the group identifier of this result
+    inline static std::string group()
+    {
+      static std::string MY_GROUP = "FieldRersultStep";
+      return MY_GROUP;
+    }
+
+    /// Returns the group identifier of this object
+    virtual std::string groupName() { return group(); }
+
+    /// Request for initialization of data model of the object: adding all attributes
+    virtual void initAttributes() {}
+
+    /// Returns the feature is disabled or not.
+    virtual bool isDisabled() { return false; }
+
+    /// Returns true if object must be displayed in the viewer: flag is stored in the
+    /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
+    /// the original state in the current transaction.
+    virtual bool isDisplayed() { return myIsDisplayed; }
+
+    /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
+    /// signal.
+    MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
+
+  protected:
+    /// This method is called just after creation of the object: it must initialize
+    /// all fields, normally initialized in the constructor
+    MODELAPI_EXPORT virtual void init() {}
+
+  private:
+    bool myIsDisplayed;
   };
 
   MODELAPI_EXPORT virtual ~ModelAPI_ResultField();
@@ -70,7 +103,7 @@ public:
 
   /// Returns step object
   /// \param theId an id of the object
-  virtual ModelAPI_FieldStep* step(int theId) const = 0;
+  virtual std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> step(int theId) const = 0;
 };
 
 //! Pointer on feature object
index c08539925ec34de2a67ea6c9985c940525bc0739..b49acbb10ec811917d19510e29b8c50fdb1684ba 100644 (file)
@@ -273,11 +273,11 @@ void PartSet_ObjectNode::update()
         }
       }
       else if (aFieldRes.get()) {
-        ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+        FieldStepPtr 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);
+          if (aStepNode->object() != aStep) {
+            aStepNode->setObject(aStep);
           }
         }
         else {
@@ -327,11 +327,11 @@ QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObject
         }
       }
       else {
-        ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+        FieldStepPtr 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);
+          if (aStepNode->object() != aStep) {
+            aStepNode->setObject(aStep);
           }
         }
         else {
@@ -1194,11 +1194,24 @@ QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDo
 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);
+    FieldStepPtr aStep =
+      std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(myObject);
 
     return "Step " + QString::number(aStep->id() + 1) + " " +
       aStep->field()->textLine(aStep->id()).c_str();
   }
-  return PartSet_TreeNode::data(theColumn, theRole);
+  return PartSet_ObjectNode::data(theColumn, theRole);
+}
+
+ModuleBase_ITreeNode::VisibilityState PartSet_StepNode::visibilityState() const
+{
+  Qt::ItemFlags aFlags = flags(1);
+  if (aFlags == Qt::ItemFlags())
+    return NoneState;
+
+  ModuleBase_IWorkshop* aWork = workshop();
+  if (aWork->isVisible(myObject))
+    return Visible;
+  else
+    return Hidden;
 }
index 014c5895d4d0bb8cd9f28ff61f7247335c9cb34f..9167859c1d0d0e2d6dceef3866df93890aa063a8 100644 (file)
@@ -333,11 +333,11 @@ public:
 * \ingroup Modules
 * Implementation of a node for compsolid representation
 */
-class PartSet_StepNode : public PartSet_TreeNode
+class PartSet_StepNode : public PartSet_ObjectNode
 {
 public:
-  PartSet_StepNode(ModelAPI_Entity* theEnt, ModuleBase_ITreeNode* theParent) :
-    PartSet_TreeNode(theParent), myEntity(theEnt) {}
+  PartSet_StepNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent) :
+    PartSet_ObjectNode(theObj, theParent) {}
 
   static std::string typeId()
   {
@@ -350,16 +350,7 @@ public:
   /// 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;
+  virtual VisibilityState visibilityState() const;
 };
 
 #endif
index 82f6e74e434f22212eaf1d9bc54833910d107d69..e3dfb0935340a7b421e246d423425bd58f461229 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultField.h>
 
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_ITreeNode.h>
@@ -252,6 +253,24 @@ void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex)
       Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
       update(theIndex);
     }
+    else {
+      FieldStepPtr aStep =
+        std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
+      if (aStep.get()) {
+        // Only one step from a field can be visible at once
+        int aId = aStep->id();
+        ModelAPI_ResultField* aField = aStep->field();
+        aField->setDisplayed(false);
+        for (int i = 0; i < aField->stepsSize(); i++) {
+          aField->step(i)->setDisplayed(i == aId);
+          static Events_Loop* aLoop = Events_Loop::loop();
+          static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+          static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+          aECreator->sendUpdated(aField->step(i), EVENT_DISP);
+        }
+        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+      }
+    }
     // Update list of selected objects because this event happens after
     // selection event in object browser
     if (aObjBrowser) {