Salome HOME
updated copyright message
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.h
1 // Copyright (C) 2014-2023  CEA, EDF
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 Model_AttributeSelectionList_H_
21 #define Model_AttributeSelectionList_H_
22
23 #include "Model.h"
24 #include "Model_AttributeSelection.h"
25 #include <ModelAPI_AttributeSelectionList.h>
26 #include <TDataStd_Integer.hxx>
27 #include <TDataStd_Comment.hxx>
28 #include <vector>
29 #include <map>
30
31 /**\class Model_AttributeSelectionList
32  * \ingroup DataModel
33  * \brief Attribute that contains list of references to the sub-shapes with
34  * possibility to manage them.
35  */
36
37 class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
38 {
39   TDF_Label myLab; ///< the main label of this attribute
40   Handle(TDataStd_Integer) mySize;  ///< Contains size of this list
41   /// Contains current type name (same as selection attribute)
42   Handle(TDataStd_Comment) mySelectionType;
43   std::shared_ptr<Model_AttributeSelection> myTmpAttr; ///< temporary attribute (the last one)
44   /// the cashed shapes to optimize isInList method: from context to set of shapes in this context
45   std::map<ObjectPtr, std::list<std::shared_ptr<GeomAPI_Shape> > > myCash;
46   bool myIsCashed; ///< true if cashing is performed
47 public:
48   /// Adds the new reference to the end of the list
49   /// \param theContext object where the sub-shape was selected
50   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
51   /// \param theTemporarily if it is true, do not store and name the added in the data framework
52   ///           (used to remove immediately, without the following updates)
53   MODEL_EXPORT virtual void append(
54     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
55     const bool theTemporarily = false);
56
57   /// Adds the new reference to the end of the list by the naming name of the selected shape
58   /// The type of shape is taken from the current selection type if the given is empty
59   MODEL_EXPORT virtual void append(const std::wstring& theNamingName,
60                                    const std::string& theType="");
61
62   /// Adds the new reference to the end of the list by inner point on the selected shape
63   MODEL_EXPORT virtual void append(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
64                                    const std::string& theType);
65
66   /// Adds the new reference to the end of the list by weak naming index
67   MODEL_EXPORT virtual void append(const std::string& theType,
68                                    const std::wstring& theContextName,
69                                    const int theIndex);
70
71   /// Copy the selection list to the destination attribute
72   MODEL_EXPORT virtual void copyTo(AttributeSelectionListPtr theTarget) const;
73
74   /// Reset temporary stored values
75   virtual void removeTemporaryValues();
76
77   /// Removes the last element in the list
78   MODEL_EXPORT virtual void removeLast();
79
80   /// Removes the elements from the list.
81   /// \param theIndices a list of indices of elements to be removed
82   MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
83
84   /// Returns the number of selection attributes in the list
85   MODEL_EXPORT virtual int size();
86
87   /// Returns true if the object with the shape are in list
88   /// \param theContext object where the sub-shape was selected
89   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
90   /// \param theTemporarily if it is true, it checks also the temporary added item
91   /// \returns true if the pair is found in the attribute
92   MODEL_EXPORT virtual bool isInList(
93     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
94     const bool theTemporarily = false);
95
96   /// The type of all elements selection
97   /// \returns the index of the OCCT enumeration of the type of shape
98   MODEL_EXPORT virtual const std::string selectionType() const;
99
100   /// Sets the type of all elements selection
101   /// \param theType the index of the OCCT enumeration of the type of shape
102   MODEL_EXPORT virtual void setSelectionType(const std::string& theType);
103
104   /// Returns the attribute selection by the index (zero based)
105   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
106
107   /// Returns all attributes
108   MODEL_EXPORT virtual void clear();
109
110   /// Returns true if attribute was  initialized by some value
111   MODEL_EXPORT virtual bool isInitialized();
112
113   /// Starts or stops cashing of the values in the attribute (the cash may become invalid
114   /// on modification of the attribute or sub-elements, so the cash must be enabled only
115   /// during non-modification operations with this attribute)
116   MODEL_EXPORT virtual void cashValues(const bool theEnabled);
117
118   MODEL_EXPORT virtual void setGeometricalSelection(const bool theIsGeometricalSelection) override;
119
120   /// Returns true if is geometrical selection.
121   MODEL_EXPORT virtual bool isGeometricalSelection() const override;
122
123   /// Returns a selection filters feature if it is defined for this selection list
124   MODEL_EXPORT virtual FiltersFeaturePtr filters() const;
125
126   /// Sets a selection filters feature if it is defined for this selection list
127   MODEL_EXPORT virtual void setFilters(FiltersFeaturePtr theFeature);
128
129 protected:
130   /// Objects are created for features automatically
131   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
132   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
133   virtual void reinit();
134
135   /// Tries to merge attributes in this list with the same result shape. Returns true
136   /// if theStart matches with some later attribute and theStart is removed from the list.
137   bool merge(Model_AttributeSelection* theStart);
138
139   friend class Model_Data;
140   friend class Model_AttributeSelection;
141 };
142
143 #endif