]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_AttributeSelectionList.h
Salome HOME
Implementation of the task #3109 : Feature Copy
[modules/shaper.git] / src / ModelAPI / ModelAPI_AttributeSelectionList.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModelAPI_AttributeSelectionList_H_
21 #define ModelAPI_AttributeSelectionList_H_
22
23 #include "ModelAPI_AttributeSelection.h"
24 #include <ModelAPI_Result.h>
25 #include <ModelAPI_Filter.h>
26
27 class GeomAPI_Pnt;
28 class GeomAPI_Shape;
29
30 /**\class ModelAPI_AttributeSelectionList
31  * \ingroup DataModel
32  * \brief Attribute that contains list of references to the sub-shapes with
33  * possibility to manage them.
34  */
35
36 class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
37 {
38   /// Flag that indicates that the whole result selection is allowed while the selection type
39   /// may be sub-objects, so, it is the same as all sub-shapes are selected (#3005). It is "false"
40   /// by default.
41   bool myIsWholeResultAllowed;
42   /// Flag that indicates that update in history must check the copy-features
43   /// and make a copy of selection for them.
44   bool myMakeCopy;
45 public:
46   /// Adds the new reference to the end of the list
47   /// \param theContext object where the sub-shape was selected
48   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
49   /// \param theTemporarily if it is true, do not store and name the added in the data framework
50   ///           (used to remove immediately, without the following updates)
51   virtual void append(const ObjectPtr& theContext,
52                       const std::shared_ptr<GeomAPI_Shape>& theSubShape,
53                       const bool theTemporarily = false) = 0;
54
55   /// Adds the new reference to the end of the list by the naming name of the selected shape
56   /// The type of shape is taken from the current selection type if the given is empty
57   virtual void append(const std::string& theNamingName, const std::string& theType = "") = 0;
58
59   /// Adds the new reference to the end of the list by inner point on the selected shape
60   virtual void append(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
61                       const std::string& theType) = 0;
62
63   /// Adds the new reference to the end of the list by weak naming index
64   virtual void append(const std::string& theType, const std::string& theContextName,
65                       const int theIndex) = 0;
66
67   /// Reset temporary stored values
68   virtual void removeTemporaryValues() = 0;
69
70   /// Removes the last element in the list
71   virtual void removeLast() = 0;
72
73   /// Removes the elements from the list.
74   /// \param theIndices a list of indices of elements to be removed
75   virtual void remove(const std::set<int>& theIndices) = 0;
76
77   /// Returns the number of selection attributes in the list
78   virtual int size() = 0;
79
80   /// Returns true if the object with the shape are in list
81   /// \param theContext object where the sub-shape was selected
82   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
83   /// \param theTemporarily if it is true, it checks also the temporary added item
84   /// \returns true if the pair is found in the attribute
85   virtual bool isInList(
86     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
87     const bool theTemporarily = false) = 0;
88
89   /// The type of all elements selection
90   /// \returns the index of the enumeration of the type of shape
91   virtual const std::string selectionType() const = 0;
92
93   /// Sets the type of all elements selection
94   /// \param theType the index of the enumeration of the type of shape
95   virtual void setSelectionType(const std::string& theType) = 0;
96
97   /// Returns the attribute selection by the index (zero based)
98   virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
99
100   /// Removes all attributes of the list.
101   virtual void clear() = 0;
102
103   /// Starts or stops cashing of the values in the attribute (the cash may become invalid
104   /// on modification of the attribute or sub-elements, so the cash must be enabled only
105   /// during non-modification operations with this attribute)
106   virtual void cashValues(const bool theEnabled) = 0;
107
108   virtual void setGeometricalSelection(const bool theIsGeometricalSelection) = 0;
109
110   /// Returns true if is geometrical selection.
111   virtual bool isGeometricalSelection() const = 0;
112
113   /// Returns the type of this class of attributes
114   static std::string typeId()
115   {
116     return "SelectionList";
117   }
118
119   /// Returns the type of this class of attributes, not static method
120   MODELAPI_EXPORT virtual std::string attributeType();
121
122   /// To virtually destroy the fields of successors
123   MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelectionList();
124
125   /// Returns a selection filters feature if it is defined for this selection list
126   MODELAPI_EXPORT virtual FiltersFeaturePtr filters() const = 0;
127
128   /// Sets a selection filters feature if it is defined for this selection list
129   MODELAPI_EXPORT virtual void setFilters(FiltersFeaturePtr theFeature) = 0;
130
131   /// Returns true if the whole result selection corresponds to selection of all sub-shapes.
132   MODELAPI_EXPORT virtual const bool isWholeResultAllowed() const {
133     return myIsWholeResultAllowed;
134   }
135
136   /// Sets whether the whole result selection corresponds to selection of all sub-shapes.
137   MODELAPI_EXPORT virtual void setWholeResultAllowed(const bool theFlag)  {
138     myIsWholeResultAllowed = theFlag;
139   }
140
141   /// Returns true if a copy features must be used in update in history.
142   MODELAPI_EXPORT virtual const bool isMakeCopy() const {
143     return myMakeCopy;
144   }
145
146   /// Sets true if a copy features must be used in update in history.
147   MODELAPI_EXPORT virtual void setMakeCopy(const bool theFlag)  {
148     myMakeCopy = theFlag;
149   }
150
151 protected:
152   /// Default constructor
153   MODELAPI_EXPORT ModelAPI_AttributeSelectionList() : ModelAPI_Attribute()
154   {myIsWholeResultAllowed = false; myMakeCopy = false;}
155
156 };
157
158 //! Pointer on double attribute
159 typedef std::shared_ptr<ModelAPI_AttributeSelectionList> AttributeSelectionListPtr;
160
161 #endif