From 2272de4179731e4841f6d6ca8b7f33ec67bd0d4e Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 4 Jun 2019 16:52:29 +0300 Subject: [PATCH] Support of attributes-arguments of the filters management --- src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp | 9 ++- src/FiltersPlugin/FiltersPlugin_BelongsTo.h | 3 + src/FiltersPlugin/FiltersPlugin_Selection.cpp | 6 +- src/FiltersPlugin/FiltersPlugin_Selection.h | 2 +- src/ModelAPI/ModelAPI_Filter.h | 79 +++++++++++-------- 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp index 854fc26c9..f2c9d88fc 100644 --- a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp +++ b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp @@ -19,6 +19,8 @@ #include "FiltersPlugin_BelongsTo.h" +#include + 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; -} \ No newline at end of file +} + +void FiltersPlugin_BelongsTo::initAttributes(ModelAPI_FiltersArgs& theArguments) +{ + theArguments.initAttribute("Belongs to", ModelAPI_AttributeSelectionList::typeId()); +} diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.h b/src/FiltersPlugin/FiltersPlugin_BelongsTo.h index 197626930..f270103af 100644 --- a/src/FiltersPlugin/FiltersPlugin_BelongsTo.h +++ b/src/FiltersPlugin/FiltersPlugin_BelongsTo.h @@ -49,6 +49,9 @@ public: /// 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 diff --git a/src/FiltersPlugin/FiltersPlugin_Selection.cpp b/src/FiltersPlugin/FiltersPlugin_Selection.cpp index c89e909cc..fefedb084 100644 --- a/src/FiltersPlugin/FiltersPlugin_Selection.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Selection.cpp @@ -34,7 +34,11 @@ void FiltersPlugin_Selection::addFilter(const std::string theFilterID) std::dynamic_pointer_cast(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(data()->owner())); + anArgs.setFilter(theFilterID); + aFilter->initAttributes(anArgs); } } diff --git a/src/FiltersPlugin/FiltersPlugin_Selection.h b/src/FiltersPlugin/FiltersPlugin_Selection.h index 2da80a2dc..46a880891 100644 --- a/src/FiltersPlugin/FiltersPlugin_Selection.h +++ b/src/FiltersPlugin/FiltersPlugin_Selection.h @@ -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. */ -class FiltersPlugin_Selection : public ModelAPI_Feature, public ModelAPI_FiltersFeature +class FiltersPlugin_Selection : public ModelAPI_FiltersFeature { public: /// Extrusion kind diff --git a/src/ModelAPI/ModelAPI_Filter.h b/src/ModelAPI/ModelAPI_Filter.h index e313d9f24..758ece648 100644 --- a/src/ModelAPI/ModelAPI_Filter.h +++ b/src/ModelAPI/ModelAPI_Filter.h @@ -24,17 +24,50 @@ #include "ModelAPI_Attribute.h" #include "ModelAPI_Feature.h" +#include "ModelAPI_Data.h" + #include #include /// 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 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 filterArgs(const std::string theFilterID) const = 0; +}; + +typedef std::shared_ptr FiltersFeaturePtr; + + /// definition of arguments of filters: id of the argument to attributes class ModelAPI_FiltersArgs { /// a map from the FilterID+AttributeID -> attribute std::map 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() {} @@ -43,6 +76,11 @@ public: 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; @@ -52,7 +90,11 @@ public: AttributePtr argument(const std::string& theID) { return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second; } - + /// adds an attribute of the filter + std::shared_ptr initAttribute( + const std::string& theID, const std::string theAttrType) { + return myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter); + } }; /**\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 - /// By default it retrurns nothing (no GUI) + /// By default it returns nothing (no GUI) 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; }; @@ -116,33 +162,4 @@ protected: 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 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 filterArgs(const std::string theFilterID) const = 0; -}; - -typedef std::shared_ptr FiltersFeaturePtr; - #endif \ No newline at end of file -- 2.39.2