Salome HOME
93ad948d584751b277e1e7daac3128061dfdf0f6
[modules/shaper.git] / src / ModelAPI / ModelAPI_AttributeSelection.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModelAPI_AttributeSelection_H_
22 #define ModelAPI_AttributeSelection_H_
23
24 #include "ModelAPI_Attribute.h"
25 #include <ModelAPI_Result.h>
26
27 class GeomAPI_Edge;
28 class GeomAPI_Pnt;
29
30 /**\class ModelAPI_AttributeSelection
31  * \ingroup DataModel
32  * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
33  */
34
35 class ModelAPI_AttributeSelection : public ModelAPI_Attribute
36 {
37  public:
38    /// Type of the center of the circular of elliptical edge
39    enum CenterType {
40      NOT_CENTER, ///< this is not a center
41      CIRCLE_CENTER, ///< center of the circle
42      ELLIPSE_FIRST_FOCUS, ///< first focus point of the ellipse
43      ELLIPSE_SECOND_FOCUS, ///< second focus point of the ellipse
44    };
45
46   /// Defines the result and its selected sub-shape
47   /// \param theContext object where the sub-shape was selected
48   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
49   /// \param theTemporarily if it is true, do not store and name the added in the data framework
50   ///           (used to remove immediately, without the following updates)
51   /// \returns true if attribute was updated
52   virtual bool setValue(
53     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
54     const bool theTemporarily = false) = 0;
55
56   /// Same as SetValue, but it takes an edge (on circular or elliptical curve)
57   /// and stores the vertex of the central point (for ellipse the first or the second focus point)
58   virtual void setValueCenter(
59     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
60     const CenterType theCenterType,
61     const bool theTemporarily = false) = 0;
62
63   /// Makes this selection attribute selects the same as in theSource selection
64   virtual void selectValue(
65     const std::shared_ptr<ModelAPI_AttributeSelection>& theSource) = 0;
66
67   /// Reset temporary stored values
68   virtual void removeTemporaryValues() = 0;
69
70   /// Returns the selected subshape
71   virtual std::shared_ptr<GeomAPI_Shape> value() = 0;
72
73   /// Returns the context of the selection (the whole shape owner)
74   virtual ResultPtr context() = 0;
75
76   /// Returns the context of the selection if the whole feature was selected
77   virtual std::shared_ptr<ModelAPI_Feature> contextFeature() = 0;
78   /// Returns the context of the selection : result or feature
79   virtual std::shared_ptr<ModelAPI_Object> contextObject() = 0;
80
81   /// Updates the selection due to the changes in the referenced objects
82   /// \returns false if update is failed
83   virtual bool update() = 0;
84
85   /// Returns the type of this class of attributes
86   static std::string typeId()
87   {
88     return "Selection";
89   }
90
91   /// Returns the type of this class of attributes, not static method
92   MODELAPI_EXPORT virtual std::string attributeType();
93
94   /// Returns a textual string of the selection
95   /// \param theDefaultValue a value, which is used if the naming name can not be obtained
96   virtual std::string namingName(const std::string& theDefaultValue = "") = 0;
97
98   /// Returns an id of the selection
99   virtual int Id() = 0;
100
101   /// Defines an id of the selection
102   virtual void setId(int theID) = 0;
103
104   /// Selects sub-shape by the textual Name
105   virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0;
106
107   /// Selects sub-shape by its inner point
108   virtual void selectSubShape(const std::string& theType,
109                               const std::shared_ptr<GeomAPI_Pnt>& thePoint) = 0;
110
111   /// Selects sub-shape by weak naming index
112   virtual void selectSubShape(const std::string& theType,
113     const std::string& theContextName, const int theIndex) = 0;
114
115   /// Returns true if recompute of selection become impossible
116   virtual bool isInvalid() = 0;
117
118   /// Returns true if is geometrical selection.
119   virtual bool isGeometricalSelection() const = 0;
120
121   /// To virtually destroy the fields of successors
122   MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelection();
123
124   /// Returns the name by context. Adds the part name if the context is located in other document
125   MODELAPI_EXPORT virtual std::string contextName(const ResultPtr& theContext) const = 0;
126
127
128  protected:
129   /// Objects are created for features automatically
130   MODELAPI_EXPORT ModelAPI_AttributeSelection();
131 };
132
133 //! Pointer on double attribute
134 typedef std::shared_ptr<ModelAPI_AttributeSelection> AttributeSelectionPtr;
135
136 #endif