]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Support of attributes-arguments of the filters management
authormpv <mpv@opencascade.com>
Tue, 4 Jun 2019 13:52:29 +0000 (16:52 +0300)
committermpv <mpv@opencascade.com>
Tue, 4 Jun 2019 13:52:29 +0000 (16:52 +0300)
src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp
src/FiltersPlugin/FiltersPlugin_BelongsTo.h
src/FiltersPlugin/FiltersPlugin_Selection.cpp
src/FiltersPlugin/FiltersPlugin_Selection.h
src/ModelAPI/ModelAPI_Filter.h

index 854fc26c9c030dff5d6866a3c4af58a0cdae2b1a..f2c9d88fcc5b4bdcb8f629decbf4ec355fdd15e4 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "FiltersPlugin_BelongsTo.h"
 
 
 #include "FiltersPlugin_BelongsTo.h"
 
+#include <ModelAPI_AttributeSelectionList.h>
+
 bool FiltersPlugin_BelongsTo::isSupported(GeomAPI_Shape::ShapeType theType) const
 {
   return true;
 bool FiltersPlugin_BelongsTo::isSupported(GeomAPI_Shape::ShapeType theType) const
 {
   return true;
@@ -43,4 +45,9 @@ static std::string XMLRepresentation =
 std::string FiltersPlugin_BelongsTo::xmlRepresentation() const
 {
   return XMLRepresentation;
 std::string FiltersPlugin_BelongsTo::xmlRepresentation() const
 {
   return XMLRepresentation;
-}
\ No newline at end of file
+}
+
+void FiltersPlugin_BelongsTo::initAttributes(ModelAPI_FiltersArgs& theArguments)
+{
+  theArguments.initAttribute("Belongs to", ModelAPI_AttributeSelectionList::typeId());
+}
index 197626930d47eeb77ca64865df86658ab9e6f09b..f270103af3de3a1ae24aa02f2f41d6cb9d2d0c8b 100644 (file)
@@ -49,6 +49,9 @@ public:
 
   /// Returns XML string which represents GUI of the filter
   virtual std::string xmlRepresentation() const override;
 
   /// Returns XML string which represents GUI of the filter
   virtual std::string xmlRepresentation() const override;
+
+  /// Initializes arguments of a filter.
+  virtual void initAttributes(ModelAPI_FiltersArgs& theArguments) override;
 };
 
 #endif
\ No newline at end of file
 };
 
 #endif
\ No newline at end of file
index c89e909cc682082ccd1a4450648bfd0f2145eef5..fefedb084edc842ae483316134810cdd7b4329b3 100644 (file)
@@ -34,7 +34,11 @@ void FiltersPlugin_Selection::addFilter(const std::string theFilterID)
       std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(data()->addFloatingAttribute(
         kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), theFilterID));
     aBool->setValue(false); // not reversed by default
       std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(data()->addFloatingAttribute(
         kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), theFilterID));
     aBool->setValue(false); // not reversed by default
-    // TODO: to add attributes related to the filter
+    // to add attributes related to the filter
+    ModelAPI_FiltersArgs anArgs;
+    anArgs.setFeature(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(data()->owner()));
+    anArgs.setFilter(theFilterID);
+    aFilter->initAttributes(anArgs);
   }
 }
 
   }
 }
 
index 2da80a2dc1e67bbed5f3a4959d4e3fb8b5a1c946..46a88089107aba6f9a5b2ec05b2048ec0ddcc068 100644 (file)
@@ -29,7 +29,7 @@
 * \brief An interface for working with filters in the feature. A filters feature must inherit it
 *       in order to allow management of filters in the feature data structure.
 */
 * \brief An interface for working with filters in the feature. A filters feature must inherit it
 *       in order to allow management of filters in the feature data structure.
 */
-class FiltersPlugin_Selection : public ModelAPI_Feature, public ModelAPI_FiltersFeature
+class FiltersPlugin_Selection : public ModelAPI_FiltersFeature
 {
 public:
   /// Extrusion kind
 {
 public:
   /// Extrusion kind
index e313d9f24299eb594aa21ffa695a195ec49bba7f..758ece6485101a22d416b265328ac73b4ce58b03 100644 (file)
 #include "ModelAPI_Attribute.h"
 #include "ModelAPI_Feature.h"
 
 #include "ModelAPI_Attribute.h"
 #include "ModelAPI_Feature.h"
 
+#include "ModelAPI_Data.h"
+
 #include <GeomAPI_Shape.h>
 #include <map>
 
 /// separator between the filter name and the filter attribute ID
 static const std::string kFilterSeparator = "__";
 
 #include <GeomAPI_Shape.h>
 #include <map>
 
 /// separator between the filter name and the filter attribute ID
 static const std::string kFilterSeparator = "__";
 
+/**\class ModelAPI_FiltersFeature
+* \ingroup DataModel
+* \brief An interface for working with filters in the feature. A filters feature must inherit it
+*       in order to allow management of filters in the feature data structure.
+*/
+class ModelAPI_FiltersFeature: public ModelAPI_Feature
+{
+public:
+  /// Adds a filter to the feature. Also initializes arguments of this filter.
+  virtual void addFilter(const std::string theFilterID) = 0;
+
+  /// Removes an existing filter from the feature.
+  virtual void removeFilter(const std::string theFilterID) = 0;
+
+  /// Returns the list of existing filters in the feature.
+  virtual std::list<std::string> filters() const = 0;
+
+  /// Stores the reversed flag for the filter.
+  virtual void setReversed(const std::string theFilterID, const bool theReversed) = 0;
+
+  /// Returns the reversed flag value for the filter.
+  virtual bool isReversed(const std::string theFilterID) = 0;
+
+  /// Returns the ordered list of attributes related to the filter.
+  virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const = 0;
+};
+
+typedef std::shared_ptr<ModelAPI_FiltersFeature> FiltersFeaturePtr;
+
+
 /// definition of arguments of filters: id of the argument to attributes
 class ModelAPI_FiltersArgs {
   /// a map from the FilterID+AttributeID -> attribute
   std::map<std::string, AttributePtr> myMap;
   std::string myCurrentFilter; ///< ID of the filter that will take attributes now
 /// definition of arguments of filters: id of the argument to attributes
 class ModelAPI_FiltersArgs {
   /// a map from the FilterID+AttributeID -> attribute
   std::map<std::string, AttributePtr> myMap;
   std::string myCurrentFilter; ///< ID of the filter that will take attributes now
+  FiltersFeaturePtr myFeature; ///< the feature is stored to minimize initAttribute interface
 public:
   ModelAPI_FiltersArgs() {}
 
 public:
   ModelAPI_FiltersArgs() {}
 
@@ -43,6 +76,11 @@ public:
     myCurrentFilter = theFilterID;
   }
 
     myCurrentFilter = theFilterID;
   }
 
+  /// Sets the current feature
+  void setFeature(const FiltersFeaturePtr theFeature) {
+    myFeature = theFeature;
+  }
+
   /// Appends an argument of a filter
   void add(AttributePtr theAttribute) {
     myMap[theAttribute->id()] = theAttribute;
   /// Appends an argument of a filter
   void add(AttributePtr theAttribute) {
     myMap[theAttribute->id()] = theAttribute;
@@ -52,7 +90,11 @@ public:
   AttributePtr argument(const std::string& theID) {
     return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second;
   }
   AttributePtr argument(const std::string& theID) {
     return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second;
   }
-
+  /// adds an attribute of the filter
+  std::shared_ptr<ModelAPI_Attribute> initAttribute(
+    const std::string& theID, const std::string theAttrType) {
+    return myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter);
+  }
 };
 
 /**\class ModelAPI_ViewFilter
 };
 
 /**\class ModelAPI_ViewFilter
@@ -74,9 +116,13 @@ public:
   virtual bool isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const = 0;
 
   /// Returns XML string which represents GUI of the filter
   virtual bool isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const = 0;
 
   /// Returns XML string which represents GUI of the filter
-  /// By default it retrurns nothing (no GUI)
+  /// By default it returns nothing (no GUI)
   virtual std::string xmlRepresentation() const { return ""; }
 
   virtual std::string xmlRepresentation() const { return ""; }
 
+  /// Initializes arguments of a filter. If a filter has no arguments, this method may be
+  /// not redefined.
+  virtual void initAttributes(ModelAPI_FiltersArgs& theArguments) {}
+
 private:
   bool myIsReverse;
 };
 private:
   bool myIsReverse;
 };
@@ -116,33 +162,4 @@ protected:
   ModelAPI_FiltersFactory() {}
 };
 
   ModelAPI_FiltersFactory() {}
 };
 
-/**\class ModelAPI_FiltersFeature
-* \ingroup DataModel
-* \brief An interface for working with filters in the feature. A filters feature must inherit it
-*       in order to allow management of filters in the feature data structure.
-*/
-class ModelAPI_FiltersFeature
-{
-public:
-  /// Adds a filter to the feature. Also initializes arguments of this filter.
-  virtual void addFilter(const std::string theFilterID) = 0;
-
-  /// Removes an existing filter from the feature.
-  virtual void removeFilter(const std::string theFilterID) = 0;
-
-  /// Returns the list of existing filters in the feature.
-  virtual std::list<std::string> filters() const = 0;
-
-  /// Stores the reversed flag for the filter.
-  virtual void setReversed(const std::string theFilterID, const bool theReversed) = 0;
-
-  /// Returns the reversed flag value for the filter.
-  virtual bool isReversed(const std::string theFilterID) = 0;
-
-  /// Returns the ordered list of attributes related to the filter.
-  virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const = 0;
-};
-
-typedef std::shared_ptr<ModelAPI_FiltersFeature> FiltersFeaturePtr;
-
 #endif
\ No newline at end of file
 #endif
\ No newline at end of file