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;
76 /// Returns XML string which represents GUI of the filter
77 /// By default it retrurns nothing (no GUI)
78 virtual std::string xmlRepresentation() const { return ""; }
84 typedef std::shared_ptr<ModelAPI_Filter> FilterPtr;
87 /**\class ModelAPI_FiltersFactory
89 * \brief Manages registering of filters
91 class ModelAPI_FiltersFactory
94 /// Register an instance of a filter
95 /// \param theID unique identifier of the filter, not necessary equal to the name of filter
96 /// \param theFilter the filter's instance
97 virtual void registerFilter(const std::string& theID, ModelAPI_Filter* theFilter) = 0;
99 /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account
100 /// the Reversed states).
101 /// \param theFiltersFeature feature that contains all information about the filters
102 /// \param theShape the checked shape
103 virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) = 0;
105 /// Returns the filters that support the given shape type
106 virtual std::list<FilterPtr> filters(GeomAPI_Shape::ShapeType theType) = 0;
108 /// Returns a filter by ID
109 virtual FilterPtr filter(std::string theID) = 0;
111 /// Returns a filter ID by the filter pointer
112 virtual std::string id(FilterPtr theFilter) = 0;
115 /// Get instance from Session
116 ModelAPI_FiltersFactory() {}
119 /**\class ModelAPI_FiltersFeature
121 * \brief An interface for working with filters in the feature. A filters feature must inherit it
122 * in order to allow management of filters in the feature data structure.
124 class ModelAPI_FiltersFeature
127 /// Adds a filter to the feature. Also initializes arguments of this filter.
128 virtual void addFilter(const std::string theFilterID) = 0;
130 /// Removes an existing filter from the feature.
131 virtual void removeFilter(const std::string theFilterID) = 0;
133 /// Returns the list of existing filters in the feature.
134 virtual std::list<std::string> filters() const = 0;
136 /// Stores the reversed flag for the filter.
137 virtual void setReversed(const std::string theFilterID, const bool theReversed) = 0;
139 /// Returns the reversed flag value for the filter.
140 virtual bool isReversed(const std::string theFilterID) = 0;
142 /// Returns the ordered list of attributes related to the filter.
143 virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const = 0;
146 typedef std::shared_ptr<ModelAPI_FiltersFeature> FiltersFeaturePtr;