1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_AttributeSelectionList.h
4 // Created: 22 Oct 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef Model_AttributeSelectionList_H_
8 #define Model_AttributeSelectionList_H_
11 #include "Model_AttributeSelection.h"
12 #include <ModelAPI_AttributeSelectionList.h>
13 #include <TDataStd_Integer.hxx>
14 #include <TDataStd_Comment.hxx>
18 /**\class Model_AttributeSelectionList
20 * \brief Attribute that contains list of references to the sub-shapes with
21 * possibility to manage them.
24 class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
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;
33 /// Adds the new reference to the end of the list
34 /// \param theContext object where the sub-shape was selected
35 /// \param theSubShape selected sub-shape (if null, the whole context is selected)
36 /// \param theTemporarily if it is true, do not store and name the added in the data framework
37 /// (used to remove immideately, without the following updates)
38 MODEL_EXPORT virtual void append(
39 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
40 const bool theTemporarily = false);
42 /// Adds the new reference to the end of the list by the naming name of the selected shape
43 /// The type of shape is taken from the current selection type if the given is empty
44 MODEL_EXPORT virtual void append(const std::string theNamingName, const std::string& theType="");
46 /// Removes the last element in the list
47 MODEL_EXPORT virtual void removeLast();
49 /// Removes the elements from the list.
50 /// \param theIndices a list of indices of elements to be removed
51 MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
53 /// Returns the number ofselection attributes in the list
54 MODEL_EXPORT virtual int size();
56 /// Returns true if the object with the shape are in list
57 /// \param theContext object where the sub-shape was selected
58 /// \param theSubShape selected sub-shape (if null, the whole context is selected)
59 /// \returns true if the pair is found in the attirbute
60 MODEL_EXPORT virtual bool isInList(
61 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
62 const bool theTemporarily = false);
64 /// The type of all elements selection
65 /// \returns the index of the OCCT enumeration of the type of shape
66 MODEL_EXPORT virtual const std::string selectionType() const;
68 /// Sets the type of all elements selection
69 /// \param theType the index of the OCCT enumeration of the type of shape
70 MODEL_EXPORT virtual void setSelectionType(const std::string& theType);
72 /// Returns the attribute selection by the index (zero based)
73 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
75 /// Returns all attributes
76 MODEL_EXPORT virtual void clear();
78 /// Returns true if attribute was initialized by some value
79 MODEL_EXPORT virtual bool isInitialized();
81 /// Starts or stops cashing of the values in the attribute (the cash may become invalid
82 /// on modification of the attribute or sub-elements, so the cash must be enabled only
83 /// during non-modification operations with this attribute)
84 MODEL_EXPORT virtual void cashValues(const bool theEnabled);
87 /// Objects are created for features automatically
88 MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
90 friend class Model_Data;