]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_MacroCircle.h
Salome HOME
d5b45c59f738152d187c5f5234b76360f65c010d
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroCircle.h
1 // Copyright (C) 2014-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_MacroCircle_H_
21 #define SketchPlugin_MacroCircle_H_
22
23 #include <ModelAPI_IReentrant.h>
24
25 #include "SketchPlugin.h"
26
27 #include "SketchPlugin_SketchEntity.h"
28
29 #include <GeomAPI_IPresentable.h>
30
31 class GeomAPI_Circ2d;
32 class GeomAPI_Pnt2d;
33
34 /**\class SketchPlugin_MacroCircle
35  * \ingroup Plugins
36  * \brief Feature for creation of the new circle in Sketch.
37  */
38 class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity,
39                                 public GeomAPI_IPresentable,
40                                 public ModelAPI_IReentrant
41 {
42  public:
43   /// Circle feature kind
44   inline static const std::string& ID()
45   {
46     static const std::string ID("SketchMacroCircle");
47     return ID;
48   }
49
50   inline static const std::string& CIRCLE_TYPE()
51   {
52     static const std::string ID("circle_type");
53     return ID;
54   }
55
56   inline static const std::string& EDIT_CIRCLE_TYPE()
57   {
58     static const std::string ID("edit_circle_type");
59     return ID;
60   }
61
62   /// Creation method by center and passed point.
63   inline static const std::string& CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()
64   {
65     static const std::string ID("circle_type_by_center_and_passed_points");
66     return ID;
67   }
68
69   /// Creation method by three points.
70   inline static const std::string& CIRCLE_TYPE_BY_THREE_POINTS()
71   {
72     static const std::string ID("circle_type_by_three_points");
73     return ID;
74   }
75
76   /// 2D point - center of the circle.
77   inline static const std::string& CENTER_POINT_ID()
78   {
79     static const std::string ID("center_point");
80     return ID;
81   }
82
83   /// Reference for center point selection.
84   inline static const std::string& CENTER_POINT_REF_ID()
85   {
86     static const std::string ID("center_point_ref");
87     return ID;
88   }
89
90   /// 2D point - center of the circle.
91   inline static const std::string& ROTATE_POINT_ID()
92   {
93     static const std::string ID("rotate_point");
94     return ID;
95   }
96
97   /// Reference for center point selection.
98   inline static const std::string& ROTATE_POINT_REF_ID()
99   {
100     static const std::string ID("rotate_point_ref");
101     return ID;
102   }
103   /// 2D point - passed point of the circle
104   inline static const std::string& PASSED_POINT_ID()
105   {
106     static const std::string ID("passed_point");
107     return ID;
108   }
109
110   /// Reference for passed point selection.
111   inline static const std::string& PASSED_POINT_REF_ID()
112   {
113     static const std::string ID("passed_point_ref");
114     return ID;
115   }
116
117   /// First point id.
118   inline static const std::string& FIRST_POINT_ID()
119   {
120     static const std::string ID("first_point");
121     return ID;
122   }
123
124   /// Reference for first point selection.
125   inline static const std::string& FIRST_POINT_REF_ID()
126   {
127     static const std::string ID("first_point_ref");
128     return ID;
129   }
130
131   /// Second point id.
132   inline static const std::string& SECOND_POINT_ID()
133   {
134     static const std::string ID("second_point");
135     return ID;
136   }
137
138   /// Reference for second point selection.
139   inline static const std::string& SECOND_POINT_REF_ID()
140   {
141     static const std::string ID("second_point_ref");
142     return ID;
143   }
144
145   /// Third point id.
146   inline static const std::string& THIRD_POINT_ID()
147   {
148     static const std::string ID("third_point");
149     return ID;
150   }
151
152   /// Reference for third point selection.
153   inline static const std::string& THIRD_POINT_REF_ID()
154   {
155     static const std::string ID("third_point_ref");
156     return ID;
157   }
158
159   /// Radius of the circle
160   inline static const std::string& CIRCLE_RADIUS_ID()
161   {
162     static const std::string ID("circle_radius");
163     return ID;
164   }
165
166   /// Rotate angle of the circle
167   inline static const std::string& CIRCLE_ROTATE_ANGLE_ID()
168   {
169     static const std::string ID("circle_angle");
170     return ID;
171   }
172
173   /// Attribute name of the version of Circle feature
174   /// Need for compability with old way of creating circle
175   inline static const std::string& VERSION_ID()
176   {
177     static const std::string MY_VERSION_ID("version");
178     return MY_VERSION_ID;
179   }
180
181   /// Returns the kind of a feature
182   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
183   {
184     static std::string MY_KIND = SketchPlugin_MacroCircle::ID();
185     return MY_KIND;
186   }
187
188   /// \brief Request for initialization of data model of the feature: adding all attributes.
189   SKETCHPLUGIN_EXPORT virtual void initAttributes();
190
191   /// Called on change of any argument-attribute of this object
192   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
193
194   /// Returns the AIS preview
195   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
196
197   /// Creates a new part document if needed
198   SKETCHPLUGIN_EXPORT virtual void execute();
199
200   /// Reimplemented from ModelAPI_Feature::isMacro().
201   /// \returns true
202   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
203
204   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
205
206   /// Apply information of the message to current object. It fills reference object,
207   /// tangent type and tangent point refence in case of tangent arc
208   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
209
210   /// Use plugin manager for features creation
211   SketchPlugin_MacroCircle();
212
213 private:
214   void fillByCenterAndPassed();
215   void fillByThreePoints();
216   /// set fields if only two of three points is initialized
217   void fillByTwoPassedPoints();
218
219   void constraintsForCircleByCenterAndPassed(FeaturePtr theCircleFeature);
220   void constraintsForCircleByThreePoints(FeaturePtr theCircleFeature);
221
222   void computeNewAngle(std::shared_ptr<GeomAPI_Circ2d>& theCircle);
223
224   FeaturePtr createCircleFeature();
225
226 private:
227   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
228   std::shared_ptr<GeomAPI_Pnt2d> myRotPoint;
229   double                         myRadius;
230   double                         myAngle;
231 };
232
233 #endif