Salome HOME
Merge branch 'Pre_2.8.0_development'
[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
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 elliptical 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 immideately, without the following updates)
50   virtual void setValue(
51     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
52     const bool theTemporarily = false) = 0;
53
54   /// Same as SetValue, but it takes an edge (on circular or elliptical curve)
55   /// and stores the vertex of the central point (for ellipse the first or the second focus point)
56   virtual void setValueCenter(
57     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
58     const CenterType theCenterType,
59     const bool theTemporarily = false) = 0;
60
61   /// Reset temporary stored values
62   virtual void removeTemporaryValues() = 0;
63
64   /// Returns the selected subshape
65   virtual std::shared_ptr<GeomAPI_Shape> value() = 0;
66
67   /// Returns the context of the selection (the whole shape owner)
68   virtual ResultPtr context() = 0;
69
70   /// Updates the underlied selection due to the changes in the referenced objects
71   /// \returns false if update is failed
72   virtual bool update() = 0;
73
74   /// Returns the type of this class of attributes
75   static std::string typeId()
76   {
77     return "Selection";
78   }
79
80   /// Returns the type of this class of attributes, not static method
81   MODELAPI_EXPORT virtual std::string attributeType();
82
83   /// Returns a textual string of the selection
84   /// \param theDefaultValue a value, which is used if the naming name can not be obtained
85   virtual std::string namingName(const std::string& theDefaultValue = "") = 0;
86
87   /// Returns an id of the selection
88   virtual int Id() = 0;
89
90   /// Defines an id of the selection
91   virtual void setId(int theID) = 0;
92
93   /// Selects sub-shape by the textual Name
94   virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0;
95
96   /// Returns true if recompute of selection become impossible
97   virtual bool isInvalid() = 0;
98
99   /// To virtually destroy the fields of successors
100   MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelection();
101
102  protected:
103   /// Objects are created for features automatically
104   MODELAPI_EXPORT ModelAPI_AttributeSelection();
105 };
106
107 //! Pointer on double attribute
108 typedef std::shared_ptr<ModelAPI_AttributeSelection> AttributeSelectionPtr;
109
110 #endif