Salome HOME
Split circle. Remain coincidence with newly created arc (issue #1725)
[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   TDF_Label myLab; ///< the main label of this attribute
27   Handle(TDataStd_Integer) mySize;  ///< Contains size of this list
28   /// Contains current type name (same as selection attribute)
29   Handle(TDataStd_Comment) mySelectionType;
30   std::shared_ptr<Model_AttributeSelection> myTmpAttr; ///< temporary attribute (the last one)
31   /// the cashed shapes to optimize isInList method: from context to set of shapes in this context
32   std::map<ResultPtr, std::list<std::shared_ptr<GeomAPI_Shape> > > myCash;
33   bool myIsCashed; ///< true if cashing is performed
34 public:
35   /// Adds the new reference to the end of the list
36   /// \param theContext object where the sub-shape was selected
37   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
38   /// \param theTemporarily if it is true, do not store and name the added in the data framework
39   ///           (used to remove immideately, without the following updates)
40   MODEL_EXPORT virtual void append(
41     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
42     const bool theTemporarily = false);
43
44   /// Adds the new reference to the end of the list by the naming name of the selected shape
45   /// The type of shape is taken from the current selection type if the given is empty
46   MODEL_EXPORT virtual void append(const std::string theNamingName, const std::string& theType="");
47
48   /// Removes the last element in the list
49   MODEL_EXPORT virtual void removeLast();
50
51   /// Removes the elements from the list.
52   /// \param theIndices a list of indices of elements to be removed
53   MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
54
55   /// Returns the number ofselection attributes in the list
56   MODEL_EXPORT virtual int size();
57
58   /// Returns true if the object with the shape are in list
59   /// \param theContext object where the sub-shape was selected
60   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
61   /// \param theTemporarily if it is true, it checks also the temporary added item
62   /// \returns true if the pair is found in the attirbute
63   MODEL_EXPORT virtual bool isInList(
64     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
65     const bool theTemporarily = false);
66
67   /// The type of all elements selection
68   /// \returns the index of the OCCT enumeration of the type of shape
69   MODEL_EXPORT virtual const std::string selectionType() const;
70
71   /// Sets the type of all elements selection
72   /// \param theType the index of the OCCT enumeration of the type of shape
73   MODEL_EXPORT virtual void setSelectionType(const std::string& theType);
74
75   /// Returns the attribute selection by the index (zero based)
76   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
77
78   /// Returns all attributes
79   MODEL_EXPORT virtual void clear();
80
81   /// Returns true if attribute was  initialized by some value
82   MODEL_EXPORT virtual bool isInitialized();
83
84   /// Starts or stops cashing of the values in the attribute (the cash may become invalid
85   /// on modification of the attribute or sub-elements, so the cash must be enabled only
86   /// during non-modification operations with this attribute)
87   MODEL_EXPORT virtual void cashValues(const bool theEnabled);
88
89 protected:
90   /// Objects are created for features automatically
91   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
92   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
93   virtual void reinit();
94
95   friend class Model_Data;
96 };
97
98 #endif