Salome HOME
2b8b43283e9e5568fead8bec9ac28b42cbed23d4
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroEllipticArc.h
1 // Copyright (C) 2017-2024  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_MacroEllipticArc_H_
21 #define SketchPlugin_MacroEllipticArc_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 class GeomAPI_Shape;
30
31 /**\class SketchPlugin_MacroEllipticArc
32  * \ingroup Plugins
33  * \brief Feature for creation of the new elliptic arc in Sketch.
34  */
35 class SketchPlugin_MacroEllipticArc: public SketchPlugin_SketchEntity,
36                                      public GeomAPI_IPresentable,
37                                      public ModelAPI_IReentrant
38 {
39 public:
40   /// Elliptic arc feature kind
41   inline static const std::string& ID()
42   {
43     static const std::string ID("SketchMacroEllipticArc");
44     return ID;
45   }
46
47   /// Attribute for the central point selected during elliptic arc creation.
48   inline static const std::string& CENTER_ID()
49   {
50     static const std::string ID("center");
51     return ID;
52   }
53
54   /// Reference to the first selected point (center of ellipse).
55   inline static const std::string& CENTER_REF_ID()
56   {
57     static const std::string ID("center_ref");
58     return ID;
59   }
60
61   /// Attribute for the point on major semi-axis selected during elliptic arc creation.
62   inline static const std::string& MAJOR_AXIS_POINT_ID()
63   {
64     static const std::string ID("major_axis_point");
65     return ID;
66   }
67
68   /// Reference to the second selected point (major semi-axis of the ellipse).
69   inline static const std::string& MAJOR_AXIS_POINT_REF_ID()
70   {
71     static const std::string ID("major_axis_point_ref");
72     return ID;
73   }
74
75   /// Attribute for the start point of the elliptic arc selected during creation.
76   inline static const std::string& START_POINT_ID()
77   {
78     static const std::string ID("start_point");
79     return ID;
80   }
81
82   /// Reference for the start point selection.
83   inline static const std::string& START_POINT_REF_ID()
84   {
85     static const std::string ID("start_point_ref");
86     return ID;
87   }
88
89   /// Attribute for the end point of the elliptic arc selected during creation.
90   inline static const std::string& END_POINT_ID()
91   {
92     static const std::string ID("end_point");
93     return ID;
94   }
95
96   /// Reference for the end point selection.
97   inline static const std::string& END_POINT_REF_ID()
98   {
99     static const std::string ID("end_point_ref");
100     return ID;
101   }
102
103   /// Major radius of the ellipse
104   inline static const std::string& MAJOR_RADIUS_ID()
105   {
106     static const std::string ID("major_radius");
107     return ID;
108   }
109
110   /// Minor radius of the ellipse
111   inline static const std::string& MINOR_RADIUS_ID()
112   {
113     static const std::string ID("minor_radius");
114     return ID;
115   }
116
117   /// Flag the arc is reversed
118   inline static const std::string& REVERSED_ID()
119   {
120     static const std::string ID("reversed");
121     return ID;
122   }
123
124   /// Returns the kind of a feature
125   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
126   {
127     static std::string MY_KIND = SketchPlugin_MacroEllipticArc::ID();
128     return MY_KIND;
129   }
130
131   /// \brief Request for initialization of data model of the feature: adding all attributes.
132   SKETCHPLUGIN_EXPORT virtual void initAttributes();
133
134   /// Called on change of any argument-attribute of this object
135   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
136
137   /// Returns the AIS preview
138   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
139
140   /// Creates a new part document if needed
141   SKETCHPLUGIN_EXPORT virtual void execute();
142
143   /// Reimplemented from ModelAPI_Feature::isMacro().
144   /// \returns true
145   SKETCHPLUGIN_EXPORT virtual bool isMacro() const
146   {return true;}
147
148   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const
149   {return false;}
150
151   /// Apply information of the message to current object. It fills reference object,
152   /// tangent type and tangent point refence in case of tangent arc
153   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
154
155   /// Use plugin manager for features creation
156   SketchPlugin_MacroEllipticArc();
157
158 private:
159   std::shared_ptr<GeomAPI_Shape> getArcShape();
160
161   FeaturePtr createEllipticArcFeature();
162   void constraintsForEllipticArc(FeaturePtr theEllipticArc);
163
164 private:
165   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
166   std::shared_ptr<GeomAPI_Pnt2d> myMajorAxis;
167   std::shared_ptr<GeomAPI_Pnt2d> myStartPnt;
168   std::shared_ptr<GeomAPI_Pnt2d> myEndPnt;
169   double myMajorRadius;
170   double myMinorRadius;
171   double myParamDelta;
172 };
173
174 #endif