Salome HOME
2b92f7f2aad55a8b81abc0b590e2f22ca8cb2388
[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_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& FIRST_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& FIRST_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& SECOND_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& SECOND_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   /// Major radius of the ellipse
112   inline static const std::string& MAJOR_RADIUS_ID()
113   {
114     static const std::string ID("major_radius");
115     return ID;
116   }
117
118   /// Minor radius of the ellipse
119   inline static const std::string& MINOR_RADIUS_ID()
120   {
121     static const std::string ID("minor_radius");
122     return ID;
123   }
124
125   /// Returns the kind of a feature
126   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
127   {
128     static std::string MY_KIND = SketchPlugin_MacroEllipse::ID();
129     return MY_KIND;
130   }
131
132   /// \brief Request for initialization of data model of the feature: adding all attributes.
133   SKETCHPLUGIN_EXPORT virtual void initAttributes();
134
135   /// Called on change of any argument-attribute of this object
136   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
137
138   /// Returns the AIS preview
139   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
140
141   /// Creates a new part document if needed
142   SKETCHPLUGIN_EXPORT virtual void execute();
143
144   /// Reimplemented from ModelAPI_Feature::isMacro().
145   /// \returns true
146   SKETCHPLUGIN_EXPORT virtual bool isMacro() const
147   {return true;}
148
149   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const
150   {return false;}
151
152   /// Apply information of the message to current object. It fills reference object,
153   /// tangent type and tangent point refence in case of tangent arc
154   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
155
156   /// Use plugin manager for features creation
157   SketchPlugin_MacroEllipse();
158
159 private:
160   void constraintsForEllipseByCenterAxisAndPassed(FeaturePtr theEllipseFeature);
161   void constraintsForEllipseByMajoxAxisAndPassed(FeaturePtr theEllipseFeature);
162
163   FeaturePtr createEllipseFeature();
164
165   void createAuxiliaryPoint(const AttributePtr& theEllipsePoint);
166   void createAuxiliaryAxis(const AttributePtr& theStartPoint, const AttributePtr& theEndPoint);
167
168   void createInternalConstraint(const AttributePtr& thePoint1, const AttributePtr& thePoint2);
169
170 private:
171   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
172   std::shared_ptr<GeomAPI_Pnt2d> myFocus;
173   double                         myMajorRadius;
174   double                         myMinorRadius;
175 };
176
177 #endif