Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroEllipse.h
1 // Copyright (C) 2017-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 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_Pnt2d;
29
30 /**\class SketchPlugin_MacroEllipse
31  * \ingroup Plugins
32  * \brief Feature for creation of the new ellipse in Sketch.
33  */
34 class SketchPlugin_MacroEllipse: public SketchPlugin_SketchEntity,
35                                  public GeomAPI_IPresentable,
36                                  public ModelAPI_IReentrant
37 {
38  public:
39   /// Ellipse feature kind
40   inline static const std::string& ID()
41   {
42     static const std::string ID("SketchMacroEllipse");
43     return ID;
44   }
45
46   static const std::string& ELLIPSE_TYPE()
47   {
48     static const std::string ID("ellipse_type");
49     return ID;
50   }
51
52   static const std::string& ELLIPSE_TYPE_BY_CENTER_AXIS_POINT()
53   {
54     static const std::string ID("by_center_axis_point");
55     return ID;
56   }
57   static const std::string& ELLIPSE_TYPE_BY_AXIS_AND_POINT()
58   {
59     static const std::string ID("by_major_axis_and_point");
60     return ID;
61   }
62
63   static const std::string& EDIT_ELLIPSE_TYPE()
64   {
65     static const std::string ID("edit_ellipse_type");
66     return ID;
67   }
68
69   /// Attribute for the first point selected during ellipse creation.
70   inline static const std::string& CENTER_POINT_ID()
71   {
72     static const std::string ID("first_point");
73     return ID;
74   }
75
76   /// Reference to the first selected point.
77   inline static const std::string& CENTER_POINT_REF_ID()
78   {
79     static const std::string ID("first_point_ref");
80     return ID;
81   }
82
83   /// Attribute for the second point selected during ellipse creation.
84   inline static const std::string& MAJOR_AXIS_POINT_ID()
85   {
86     static const std::string ID("second_point");
87     return ID;
88   }
89
90   /// Reference to the second selected point.
91   inline static const std::string& MAJOR_AXIS_POINT_REF_ID()
92   {
93     static const std::string ID("second_point_ref");
94     return ID;
95   }
96
97   /// Attribute for the third point selected during ellipse creation.
98   inline static const std::string& PASSED_POINT_ID()
99   {
100     static const std::string ID("passed_point");
101     return ID;
102   }
103
104   /// Reference for passed point selection.
105   inline static const std::string& PASSED_POINT_REF_ID()
106   {
107     static const std::string ID("passed_point_ref");
108     return ID;
109   }
110
111   /// Attribute for the first point selected during ellipse creation.
112   inline static const std::string& MAJOR_AXIS_START_ID()
113   {
114     static const std::string ID("first_point_1");
115     return ID;
116   }
117
118   /// Reference to the first selected point.
119   inline static const std::string& MAJOR_AXIS_START_REF_ID()
120   {
121     static const std::string ID("first_point_ref_1");
122     return ID;
123   }
124
125   /// Attribute for the second point selected during ellipse creation.
126   inline static const std::string& MAJOR_AXIS_END_ID()
127   {
128     static const std::string ID("second_point_1");
129     return ID;
130   }
131
132   /// Reference to the second selected point.
133   inline static const std::string& MAJOR_AXIS_END_REF_ID()
134   {
135     static const std::string ID("second_point_ref_1");
136     return ID;
137   }
138
139   /// Attribute for the third point selected during ellipse creation.
140   inline static const std::string& PASSED_POINT_1_ID()
141   {
142     static const std::string ID("passed_point_1");
143     return ID;
144   }
145
146   /// Reference for passed point selection.
147   inline static const std::string& PASSED_POINT_1_REF_ID()
148   {
149     static const std::string ID("passed_point_ref_1");
150     return ID;
151   }
152
153   /// Major radius of the ellipse
154   inline static const std::string& MAJOR_RADIUS_ID()
155   {
156     static const std::string ID("major_radius");
157     return ID;
158   }
159
160   /// Minor radius of the ellipse
161   inline static const std::string& MINOR_RADIUS_ID()
162   {
163     static const std::string ID("minor_radius");
164     return ID;
165   }
166
167   /// Returns the kind of a feature
168   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
169   {
170     static std::string MY_KIND = SketchPlugin_MacroEllipse::ID();
171     return MY_KIND;
172   }
173
174   /// \brief Request for initialization of data model of the feature: adding all attributes.
175   SKETCHPLUGIN_EXPORT virtual void initAttributes();
176
177   /// Called on change of any argument-attribute of this object
178   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
179
180   /// Returns the AIS preview
181   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
182
183   /// Creates a new part document if needed
184   SKETCHPLUGIN_EXPORT virtual void execute();
185
186   /// Reimplemented from ModelAPI_Feature::isMacro().
187   /// \returns true
188   SKETCHPLUGIN_EXPORT virtual bool isMacro() const
189   {return true;}
190
191   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const
192   {return false;}
193
194   /// Apply information of the message to current object. It fills reference object,
195   /// tangent type and tangent point refence in case of tangent arc
196   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
197
198   /// Use plugin manager for features creation
199   SketchPlugin_MacroEllipse();
200
201 private:
202   void constraintsForEllipseByCenterAxisAndPassed(FeaturePtr theEllipseFeature);
203   void constraintsForEllipseByMajoxAxisAndPassed(FeaturePtr theEllipseFeature);
204
205   FeaturePtr createEllipseFeature();
206
207 private:
208   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
209   std::shared_ptr<GeomAPI_Pnt2d> myFocus;
210   double                         myMajorRadius;
211   double                         myMinorRadius;
212 };
213
214 #endif