Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroEllipse.h
1 // Copyright (C) 2017-2019  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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SketchPlugin_MacroEllipse_H_
21 #define SketchPlugin_MacroEllipse_H_
22
23 #include <ModelAPI_IReentrant.h>
24 #include <SketchPlugin.h>
25 #include <SketchPlugin_SketchEntity.h>
26 #include <GeomAPI_IPresentable.h>
27
28 ////class GeomAPI_Circ2d;
29 class GeomAPI_Pnt2d;
30
31 /**\class SketchPlugin_MacroEllipse
32  * \ingroup Plugins
33  * \brief Feature for creation of the new ellipse in Sketch.
34  */
35 class SketchPlugin_MacroEllipse: public SketchPlugin_SketchEntity,
36                                  public GeomAPI_IPresentable,
37                                  public ModelAPI_IReentrant
38 {
39  public:
40   /// Ellipse feature kind
41   inline static const std::string& ID()
42   {
43     static const std::string ID("SketchMacroEllipse");
44     return ID;
45   }
46
47   static const std::string& ELLIPSE_TYPE()
48   {
49     static const std::string ID("ellipse_type");
50     return ID;
51   }
52
53   static const std::string& ELLIPSE_TYPE_BY_CENTER_AXIS_POINT()
54   {
55     static const std::string ID("by_center_axis_point");
56     return ID;
57   }
58   static const std::string& ELLIPSE_TYPE_BY_AXIS_AND_POINT()
59   {
60     static const std::string ID("by_major_axis_and_point");
61     return ID;
62   }
63
64   static const std::string& EDIT_ELLIPSE_TYPE()
65   {
66     static const std::string ID("edit_ellipse_type");
67     return ID;
68   }
69
70   /// Attribute for the first point selected during ellipse creation.
71   inline static const std::string& FIRST_POINT_ID()
72   {
73     static const std::string ID("first_point");
74     return ID;
75   }
76
77   /// Reference to the first selected point.
78   inline static const std::string& FIRST_POINT_REF_ID()
79   {
80     static const std::string ID("first_point_ref");
81     return ID;
82   }
83
84   /// Attribute for the second point selected during ellipse creation.
85   inline static const std::string& SECOND_POINT_ID()
86   {
87     static const std::string ID("second_point");
88     return ID;
89   }
90
91   /// Reference to the second selected point.
92   inline static const std::string& SECOND_POINT_REF_ID()
93   {
94     static const std::string ID("second_point_ref");
95     return ID;
96   }
97
98   /// Attribute for the third point selected during ellipse creation.
99   inline static const std::string& PASSED_POINT_ID()
100   {
101     static const std::string ID("passed_point");
102     return ID;
103   }
104
105   /// Reference for passed point selection.
106   inline static const std::string& PASSED_POINT_REF_ID()
107   {
108     static const std::string ID("passed_point_ref");
109     return ID;
110   }
111
112   /// Major radius of the ellipse
113   inline static const std::string& MAJOR_RADIUS_ID()
114   {
115     static const std::string ID("major_radius");
116     return ID;
117   }
118
119   /// Minor radius of the ellipse
120   inline static const std::string& MINOR_RADIUS_ID()
121   {
122     static const std::string ID("minor_radius");
123     return ID;
124   }
125
126   /// Returns the kind of a feature
127   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
128   {
129     static std::string MY_KIND = SketchPlugin_MacroEllipse::ID();
130     return MY_KIND;
131   }
132
133   /// \brief Request for initialization of data model of the feature: adding all attributes.
134   SKETCHPLUGIN_EXPORT virtual void initAttributes();
135
136   /// Called on change of any argument-attribute of this object
137   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
138
139   /// Returns the AIS preview
140   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
141
142   /// Creates a new part document if needed
143   SKETCHPLUGIN_EXPORT virtual void execute();
144
145   /// Reimplemented from ModelAPI_Feature::isMacro().
146   /// \returns true
147   SKETCHPLUGIN_EXPORT virtual bool isMacro() const
148   {return true;}
149
150   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const
151   {return false;}
152
153   /// Apply information of the message to current object. It fills reference object,
154   /// tangent type and tangent point refence in case of tangent arc
155   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
156
157   /// Use plugin manager for features creation
158   SketchPlugin_MacroEllipse();
159
160 private:
161   void constraintsForEllipseByCenterAxisAndPassed(FeaturePtr theEllipseFeature);
162   void constraintsForEllipseByMajoxAxisAndPassed(FeaturePtr theEllipseFeature);
163
164   FeaturePtr createEllipseFeature();
165
166 private:
167   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
168   std::shared_ptr<GeomAPI_Pnt2d> myFocus;
169   double                         myMajorRadius;
170   double                         myMinorRadius;
171 };
172
173 #endif