Salome HOME
d31d0d55f3fb3b83d5af430bb57e2aa6a2d7e97f
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroEllipse.h
1 // Copyright (C) 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 // File:        SketchPlugin_MacroEllipse.h
22 // Created:     26 April 2017
23 // Author:      Artem ZHIDKOV
24
25 #ifndef SketchPlugin_MacroEllipse_H_
26 #define SketchPlugin_MacroEllipse_H_
27
28 #include <ModelAPI_IReentrant.h>
29 #include <SketchPlugin.h>
30 #include <SketchPlugin_SketchEntity.h>
31 #include <GeomAPI_IPresentable.h>
32
33 ////class GeomAPI_Circ2d;
34 class GeomAPI_Pnt2d;
35
36 /**\class SketchPlugin_MacroEllipse
37  * \ingroup Plugins
38  * \brief Feature for creation of the new ellipse in Sketch.
39  */
40 class SketchPlugin_MacroEllipse: public SketchPlugin_SketchEntity,
41                                  public GeomAPI_IPresentable,
42                                  public ModelAPI_IReentrant
43 {
44  public:
45   /// Ellipse feature kind
46   inline static const std::string& ID()
47   {
48     static const std::string ID("SketchMacroEllipse");
49     return ID;
50   }
51
52   /// 2D point - center of the ellipse.
53   inline static const std::string& CENTER_POINT_ID()
54   {
55     static const std::string ID("center_point");
56     return ID;
57   }
58
59   /// Reference for center point selection.
60   inline static const std::string& CENTER_POINT_REF_ID()
61   {
62     static const std::string ID("center_point_ref");
63     return ID;
64   }
65
66   /// 2D point - major axis point of the ellipse.
67   inline static const std::string& MAJOR_AXIS_POINT_ID()
68   {
69     static const std::string ID("major_axis_point");
70     return ID;
71   }
72
73   /// Reference for major axis point selection.
74   inline static const std::string& MAJOR_AXIS_POINT_REF_ID()
75   {
76     static const std::string ID("major_axis_point_ref");
77     return ID;
78   }
79
80   /// 2D point - passed point of the ellipse
81   inline static const std::string& PASSED_POINT_ID()
82   {
83     static const std::string ID("passed_point");
84     return ID;
85   }
86
87   /// Reference for passed point selection.
88   inline static const std::string& PASSED_POINT_REF_ID()
89   {
90     static const std::string ID("passed_point_ref");
91     return ID;
92   }
93
94   /// Major radius of the ellipse
95   inline static const std::string& MAJOR_RADIUS_ID()
96   {
97     static const std::string ID("ellipse_major_radius");
98     return ID;
99   }
100
101   /// Minor radius of the ellipse
102   inline static const std::string& MINOR_RADIUS_ID()
103   {
104     static const std::string ID("ellipse_minor_radius");
105     return ID;
106   }
107
108   /// Returns the kind of a feature
109   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
110   {
111     static std::string MY_KIND = SketchPlugin_MacroEllipse::ID();
112     return MY_KIND;
113   }
114
115   /// \brief Request for initialization of data model of the feature: adding all attributes.
116   SKETCHPLUGIN_EXPORT virtual void initAttributes();
117
118   /// Called on change of any argument-attribute of this object
119   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
120
121   /// Returns the AIS preview
122   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
123
124   /// Creates a new part document if needed
125   SKETCHPLUGIN_EXPORT virtual void execute();
126
127   /// Moves the feature
128   /// \param theDeltaX the delta for X coordinate is moved
129   /// \param theDeltaY the delta for Y coordinate is moved
130   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
131   {}
132
133   /// Reimplemented from ModelAPI_Feature::isMacro().
134   /// \returns true
135   SKETCHPLUGIN_EXPORT virtual bool isMacro() const
136   {return true;}
137
138   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const
139   {return false;}
140
141   /// Apply information of the message to current object. It fills reference object,
142   /// tangent type and tangent point refence in case of tangent arc
143   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
144
145   /// Use plugin manager for features creation
146   SketchPlugin_MacroEllipse();
147
148 private:
149   void constraintsForEllipse(FeaturePtr theEllipseFeature);
150
151   FeaturePtr createEllipseFeature();
152
153 private:
154   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
155   std::shared_ptr<GeomAPI_Pnt2d> myFocus;
156   double                         myMajorRadius;
157   double                         myMinorRadius;
158 };
159
160 #endif