Salome HOME
9a0c58d6744db357455c656b224fc0e6a7912b77
[modules/shaper.git] / src / ModelAPI / ModelAPI_AttributeSelection.h
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModelAPI_AttributeSelection_H_
21 #define ModelAPI_AttributeSelection_H_
22
23 #include "ModelAPI_Attribute.h"
24 #include <ModelAPI_Result.h>
25
26 class GeomAPI_Edge;
27 class GeomAPI_Pnt;
28
29 /**\class ModelAPI_AttributeSelection
30  * \ingroup DataModel
31  * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
32  */
33
34 class ModelAPI_AttributeSelection : public ModelAPI_Attribute
35 {
36  public:
37    /// Type of the center of the circular of elliptic edge
38    enum CenterType {
39      NOT_CENTER, ///< this is not a center
40      CIRCLE_CENTER, ///< center of the circle
41      ELLIPSE_FIRST_FOCUS, ///< first focus point of the ellipse
42      ELLIPSE_SECOND_FOCUS, ///< second focus point of the ellipse
43    };
44
45   /// Defines the result and its selected sub-shape
46   /// \param theContext object where the sub-shape was selected
47   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
48   /// \param theTemporarily if it is true, do not store and name the added in the data framework
49   ///           (used to remove immediately, without the following updates)
50   /// \returns true if attribute was updated
51   virtual bool setValue(
52     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
53     const bool theTemporarily = false) = 0;
54
55   /// Same as SetValue, but it takes an edge (on circular or elliptic curve)
56   /// and stores the vertex of the central point (for ellipse the first or the second focus point)
57   virtual void setValueCenter(
58     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
59     const CenterType theCenterType,
60     const bool theTemporarily = false) = 0;
61
62   /// Makes this selection attribute selects the same as in theSource selection
63   virtual void selectValue(
64     const std::shared_ptr<ModelAPI_AttributeSelection>& theSource) = 0;
65
66   /// Reset temporary stored values
67   virtual void removeTemporaryValues() = 0;
68
69   /// Returns the selected subshape
70   virtual std::shared_ptr<GeomAPI_Shape> value() = 0;
71
72   /// Returns the context of the selection (the whole shape owner)
73   virtual ResultPtr context() = 0;
74
75   /// Returns the context of the selection if the whole feature was selected
76   virtual std::shared_ptr<ModelAPI_Feature> contextFeature() = 0;
77   /// Returns the context of the selection : result or feature
78   virtual std::shared_ptr<ModelAPI_Object> contextObject() = 0;
79
80   /// Updates the selection due to the changes in the referenced objects
81   /// \returns false if update is failed
82   virtual bool update() = 0;
83
84   /// Returns the type of this class of attributes
85   static std::string typeId()
86   {
87     return "Selection";
88   }
89
90   /// Returns the type of this class of attributes, not static method
91   MODELAPI_EXPORT virtual std::string attributeType();
92
93   /// Returns a textual string of the selection
94   /// \param theDefaultValue a value, which is used if the naming name can not be obtained
95   virtual std::wstring namingName(const std::wstring& theDefaultValue = L"") = 0;
96
97   /// Defines an id of the selection
98   virtual void setId(int theID) = 0;
99
100   /// Selects sub-shape by the textual Name
101   virtual void selectSubShape(const std::string& theType, const std::wstring& theSubShapeName) = 0;
102
103   /// Selects sub-shape by its inner point
104   virtual void selectSubShape(const std::string& theType,
105                               const std::shared_ptr<GeomAPI_Pnt>& thePoint) = 0;
106
107   /// Selects sub-shape by weak naming index
108   virtual void selectSubShape(const std::string& theType,
109     const std::wstring& theContextName, const int theIndex) = 0;
110
111   /// Returns true if recompute of selection become impossible
112   virtual bool isInvalid() = 0;
113
114   /// Returns true if is geometrical selection.
115   virtual bool isGeometricalSelection() const = 0;
116
117   /// To virtually destroy the fields of successors
118   MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelection();
119
120   /// Returns the name by context. Adds the part name if the context is located in other document
121   MODELAPI_EXPORT virtual std::wstring contextName(const ResultPtr& theContext) const = 0;
122
123   /// Makes the current local selection becomes all sub-shapes with same base geometry.
124   MODELAPI_EXPORT virtual void combineGeometrical() = 0;
125
126   /// Updates the arguments of selection if something was affected by creation
127   /// or reorder of features upper in the history line.
128   /// Returns theRemove true if this attribute must be removed (become deleted)
129   MODELAPI_EXPORT virtual void updateInHistory(bool& theRemove) = 0;
130
131  protected:
132   /// Objects are created for features automatically
133   MODELAPI_EXPORT ModelAPI_AttributeSelection();
134 };
135
136 //! Pointer on double attribute
137 typedef std::shared_ptr<ModelAPI_AttributeSelection> AttributeSelectionPtr;
138
139 #endif