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