Salome HOME
Fixed crash on when creating circle by 3 points.
[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   /// Reset temporary stored values
49   virtual void removeTemporaryValues();
50
51   /// Removes the last element in the list
52   MODEL_EXPORT virtual void removeLast();
53
54   /// Removes the elements from the list.
55   /// \param theIndices a list of indices of elements to be removed
56   MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
57
58   /// Returns the number ofselection attributes in the list
59   MODEL_EXPORT virtual int size();
60
61   /// Returns true if the object with the shape are in list
62   /// \param theContext object where the sub-shape was selected
63   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
64   /// \param theTemporarily if it is true, it checks also the temporary added item
65   /// \returns true if the pair is found in the attirbute
66   MODEL_EXPORT virtual bool isInList(
67     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
68     const bool theTemporarily = false);
69
70   /// The type of all elements selection
71   /// \returns the index of the OCCT enumeration of the type of shape
72   MODEL_EXPORT virtual const std::string selectionType() const;
73
74   /// Sets the type of all elements selection
75   /// \param theType the index of the OCCT enumeration of the type of shape
76   MODEL_EXPORT virtual void setSelectionType(const std::string& theType);
77
78   /// Returns the attribute selection by the index (zero based)
79   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
80
81   /// Returns all attributes
82   MODEL_EXPORT virtual void clear();
83
84   /// Returns true if attribute was  initialized by some value
85   MODEL_EXPORT virtual bool isInitialized();
86
87   /// Starts or stops cashing of the values in the attribute (the cash may become invalid
88   /// on modification of the attribute or sub-elements, so the cash must be enabled only
89   /// during non-modification operations with this attribute)
90   MODEL_EXPORT virtual void cashValues(const bool theEnabled);
91
92 protected:
93   /// Objects are created for features automatically
94   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
95   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
96   virtual void reinit();
97
98   friend class Model_Data;
99 };
100
101 #endif