Salome HOME
Make naming name works on bodies with additional prefixes (extrusion solid in the...
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_AttributeSelectionList.h
4 // Created:     22 Oct 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef Model_AttributeSelectionList_H_
8 #define Model_AttributeSelectionList_H_
9
10 #include "Model.h"
11 #include "Model_AttributeSelection.h"
12 #include <ModelAPI_AttributeSelectionList.h>
13 #include <TDataStd_Integer.hxx>
14 #include <TDataStd_Comment.hxx>
15 #include <vector>
16 #include <map>
17
18 /**\class Model_AttributeSelectionList
19  * \ingroup DataModel
20  * \brief Attribute that contains list of references to the sub-shapes with
21  * possibility to manage them.
22  */
23
24 class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
25 {
26   Handle(TDataStd_Integer) mySize;  ///< Contains size of this list
27   /// Contains current type name (same as selection attribute)
28   Handle(TDataStd_Comment) mySelectionType;
29   std::shared_ptr<Model_AttributeSelection> myTmpAttr; ///< temporary attribute (the last one)
30   /// the cashed shapes to optimize isInList method: from context to set of shapes in this context
31   std::map<ResultPtr, std::list<std::shared_ptr<GeomAPI_Shape> > > myCash;
32   bool myIsCashed; ///< true if cashing is performed
33 public:
34   /// Adds the new reference to the end of the list
35   /// \param theContext object where the sub-shape was selected
36   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
37   /// \param theTemporarily if it is true, do not store and name the added in the data framework
38   ///           (used to remove immideately, without the following updates)
39   MODEL_EXPORT virtual void append(
40     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
41     const bool theTemporarily = false);
42
43   /// Adds the new reference to the end of the list by the naming name of the selected shape
44   /// The type of shape is taken from the current selection type if the given is empty
45   MODEL_EXPORT virtual void append(const std::string theNamingName, const std::string& theType="");
46
47   /// Removes the last element in the list
48   MODEL_EXPORT virtual void removeLast();
49
50   /// Removes the elements from the list.
51   /// \param theIndices a list of indices of elements to be removed
52   MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
53
54   /// Returns the number ofselection attributes in the list
55   MODEL_EXPORT virtual int size();
56
57   /// Returns true if the object with the shape are in list
58   /// \param theContext object where the sub-shape was selected
59   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
60   /// \param theTemporarily if it is true, it checks also the temporary added item
61   /// \returns true if the pair is found in the attirbute
62   MODEL_EXPORT virtual bool isInList(
63     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
64     const bool theTemporarily = false);
65
66   /// The type of all elements selection
67   /// \returns the index of the OCCT enumeration of the type of shape
68   MODEL_EXPORT virtual const std::string selectionType() const;
69
70   /// Sets the type of all elements selection
71   /// \param theType the index of the OCCT enumeration of the type of shape
72   MODEL_EXPORT virtual void setSelectionType(const std::string& theType);
73
74   /// Returns the attribute selection by the index (zero based)
75   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
76
77   /// Returns all attributes
78   MODEL_EXPORT virtual void clear();
79
80   /// Returns true if attribute was  initialized by some value
81   MODEL_EXPORT virtual bool isInitialized();
82
83   /// Starts or stops cashing of the values in the attribute (the cash may become invalid
84   /// on modification of the attribute or sub-elements, so the cash must be enabled only
85   /// during non-modification operations with this attribute)
86   MODEL_EXPORT virtual void cashValues(const bool theEnabled);
87
88 protected:
89   /// Objects are created for features automatically
90   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
91
92   friend class Model_Data;
93 };
94
95 #endif