1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModelAPI_Filter_H_
21 #define ModelAPI_Filter_H_
24 #include "ModelAPI_Attribute.h"
25 #include "ModelAPI_Feature.h"
27 #include <GeomAPI_Shape.h>
30 /// separator between the filter name and the filter attribute ID
31 static const std::string kFilterSeparator = "__";
33 /// definition of arguments of filters: id of the argument to attributes
34 class ModelAPI_FiltersArgs {
35 /// a map from the FilterID+AttributeID -> attribute
36 std::map<std::string, AttributePtr> myMap;
37 std::string myCurrentFilter; ///< ID of the filter that will take attributes now
39 ModelAPI_FiltersArgs() {}
41 /// Sets the current filter ID
42 void setFilter(const std::string& theFilterID) {
43 myCurrentFilter = theFilterID;
46 /// Appends an argument of a filter
47 void add(AttributePtr theAttribute) {
48 myMap[theAttribute->id()] = theAttribute;
51 /// returns the argument of the current filter by the argument id
52 AttributePtr argument(const std::string& theID) {
53 return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second;
58 /**\class ModelAPI_ViewFilter
60 * \brief A general interface class filters definition
65 /// Returns name of the filter to represent it in GUI
66 virtual const std::string& name() const = 0;
68 /// Returns true if the given shape type is supported
69 virtual bool isSupported(GeomAPI_Shape::ShapeType theType) const = 0;
71 /// This method should contain the filter logic. It returns true if the given shape
72 /// is accepted by the filter.
73 /// \param theShape the given shape
74 virtual bool isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const = 0;
80 typedef std::shared_ptr<ModelAPI_Filter> FilterPtr;
83 /**\class ModelAPI_FiltersFactory
85 * \brief Manages registering of filters
87 class ModelAPI_FiltersFactory
90 /// Register an instance of a filter
91 /// \param theID unique identifier of the filter, not necessary equal to the name of filter
92 /// \param theFilter the filter's instance
93 virtual void registerFilter(const std::string& theID, ModelAPI_Filter* theFilter) = 0;
95 /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account
96 /// the Reversed states).
97 /// \param theFiltersFeature feature that contains all information about the filters
98 /// \param theShape the checked shape
99 virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) = 0;
101 /// Returns the filters that support the given shape type
102 virtual std::list<FilterPtr> filters(GeomAPI_Shape::ShapeType theType) = 0;
104 /// Returns a filter by ID
105 virtual FilterPtr filter(std::string theID) = 0;
107 /// Returns a filter ID by the filter pointer
108 virtual std::string id(FilterPtr theFilter) = 0;
111 /// Get instance from Session
112 ModelAPI_FiltersFactory() {}
115 /**\class ModelAPI_FiltersFeature
117 * \brief An interface for working with filters in the feature. A filters feature must inherit it
118 * in order to allow management of filters in the feature data structure.
120 class ModelAPI_FiltersFeature
123 /// Adds a filter to the feature. Also initializes arguments of this filter.
124 virtual void addFilter(const std::string theFilterID) = 0;
126 /// Removes an existing filter from the feature.
127 virtual void removeFilter(const std::string theFilterID) = 0;
129 /// Returns the list of existing filters in the feature.
130 virtual std::list<std::string> filters() const = 0;
132 /// Stores the reversed flag for the filter.
133 virtual void setReversed(const std::string theFilterID, const bool theReversed) = 0;
135 /// Returns the reversed flag value for the filter.
136 virtual bool isReversed(const std::string theFilterID) = 0;
138 /// Returns the ordered list of attributes related to the filter.
139 virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const = 0;
142 typedef std::shared_ptr<ModelAPI_FiltersFeature> FiltersFeaturePtr;