Salome HOME
Fixed crash when attribute External in feature Projection changed.
[modules/shaper.git] / src / ModelAPI / ModelAPI_AttributeSelectionList.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_AttributeSelectionList.h
4 // Created:     22 Oct 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_AttributeSelectionList_H_
8 #define ModelAPI_AttributeSelectionList_H_
9
10 #include "ModelAPI_AttributeSelection.h"
11 #include <ModelAPI_Result.h>
12
13 class GeomAPI_Shape;
14
15 /**\class ModelAPI_AttributeSelectionList
16  * \ingroup DataModel
17  * \brief Attribute that contains list of references to the sub-shapes with
18  * possibility to manage them.
19  */
20
21 class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
22 {
23  public:
24   /// Adds the new reference to the end of the list
25   /// \param theContext object where the sub-shape was selected
26   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
27   /// \param theTemporarily if it is true, do not store and name the added in the data framework
28   ///           (used to remove immediately, without the following updates)
29   virtual void append(const ResultPtr& theContext,
30                       const std::shared_ptr<GeomAPI_Shape>& theSubShape,
31                       const bool theTemporarily = false) = 0;
32
33   /// Adds the new reference to the end of the list by the naming name of the selected shape
34   /// The type of shape is taken from the current selection type if the given is empty
35   virtual void append(const std::string theNamingName, const std::string& theType = "") = 0;
36
37   /// Reset temporary stored values
38   virtual void removeTemporaryValues() = 0;
39
40   /// Removes the last element in the list
41   virtual void removeLast() = 0;
42
43   /// Removes the elements from the list.
44   /// \param theIndices a list of indices of elements to be removed
45   virtual void remove(const std::set<int>& theIndices) = 0;
46
47   /// Returns the number of selection attributes in the list
48   virtual int size() = 0;
49
50   /// Returns true if the object with the shape are in list
51   /// \param theContext object where the sub-shape was selected
52   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
53   /// \param theTemporarily if it is true, it checks also the temporary added item
54   /// \returns true if the pair is found in the attirbute
55   virtual bool isInList(
56     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
57     const bool theTemporarily = false) = 0;
58
59   /// The type of all elements selection
60   /// \returns the index of the enumeration of the type of shape
61   virtual const std::string selectionType() const = 0;
62
63   /// Sets the type of all elements selection
64   /// \param theType the index of the enumeration of the type of shape
65   virtual void setSelectionType(const std::string& theType) = 0;
66
67   /// Returns the attribute selection by the index (zero based)
68   virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
69
70   /// Returns all attributes
71   virtual void clear() = 0;
72
73   /// Starts or stops cashing of the values in the attribute (the cash may become invalid
74   /// on modification of the attribute or sub-elements, so the cash must be enabled only
75   /// during non-modification operations with this attribute)
76   virtual void cashValues(const bool theEnabled) = 0;
77
78   /// Returns the type of this class of attributes
79   static std::string typeId()
80   {
81     return "SelectionList";
82   }
83
84   /// Returns the type of this class of attributes, not static method
85   MODELAPI_EXPORT virtual std::string attributeType();
86
87   /// To virtually destroy the fields of successors
88   MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelectionList();
89
90  protected:
91   /// Objects are created for features automatically
92   MODELAPI_EXPORT ModelAPI_AttributeSelectionList();
93 };
94
95 //! Pointer on double attribute
96 typedef std::shared_ptr<ModelAPI_AttributeSelectionList> AttributeSelectionListPtr;
97
98 #endif