Salome HOME
Simplification and refactoring of unit tests for SketchPlugin
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroCircle.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_MacroCircle.h
4 // Created:     26 May 2014
5 // Author:      Artem ZHIDKOV
6
7 #ifndef SketchPlugin_MacroCircle_H_
8 #define SketchPlugin_MacroCircle_H_
9
10 #include <ModelAPI_IReentrant.h>
11
12 #include "SketchPlugin.h"
13
14 #include "SketchPlugin_SketchEntity.h"
15
16 #include <GeomAPI_IPresentable.h>
17
18 class GeomAPI_Circ2d;
19 class GeomAPI_Pnt2d;
20
21 /**\class SketchPlugin_MacroCircle
22  * \ingroup Plugins
23  * \brief Feature for creation of the new circle in Sketch.
24  */
25 class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity,
26                                 public GeomAPI_IPresentable,
27                                 public ModelAPI_IReentrant
28 {
29  public:
30   /// Circle feature kind
31   inline static const std::string& ID()
32   {
33     static const std::string ID("SketchMacroCircle");
34     return ID;
35   }
36
37   inline static const std::string& CIRCLE_TYPE()
38   {
39     static const std::string ID("circle_type");
40     return ID;
41   }
42
43   inline static const std::string& EDIT_CIRCLE_TYPE()
44   {
45     static const std::string ID("edit_circle_type");
46     return ID;
47   }
48
49   /// Creation method by center and passed point.
50   inline static const std::string& CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()
51   {
52     static const std::string ID("circle_type_by_center_and_passed_points");
53     return ID;
54   }
55
56   /// Creation method by three points.
57   inline static const std::string& CIRCLE_TYPE_BY_THREE_POINTS()
58   {
59     static const std::string ID("circle_type_by_three_points");
60     return ID;
61   }
62
63   /// 2D point - center of the circle.
64   inline static const std::string& CENTER_POINT_ID()
65   {
66     static const std::string ID("center_point");
67     return ID;
68   }
69
70   /// Reference for center point selection.
71   inline static const std::string& CENTER_POINT_REF_ID()
72   {
73     static const std::string ID("center_point_ref");
74     return ID;
75   }
76
77   /// 2D point - passed point of the circle
78   inline static const std::string& PASSED_POINT_ID()
79   {
80     static const std::string ID("passed_point");
81     return ID;
82   }
83
84   /// Reference for passed point selection.
85   inline static const std::string& PASSED_POINT_REF_ID()
86   {
87     static const std::string ID("passed_point_ref");
88     return ID;
89   }
90
91   /// First point id.
92   inline static const std::string& FIRST_POINT_ID()
93   {
94     static const std::string ID("first_point");
95     return ID;
96   }
97
98   /// Reference for first point selection.
99   inline static const std::string& FIRST_POINT_REF_ID()
100   {
101     static const std::string ID("first_point_ref");
102     return ID;
103   }
104
105   /// Second point id.
106   inline static const std::string& SECOND_POINT_ID()
107   {
108     static const std::string ID("second_point");
109     return ID;
110   }
111
112   /// Reference for second point selection.
113   inline static const std::string& SECOND_POINT_REF_ID()
114   {
115     static const std::string ID("second_point_ref");
116     return ID;
117   }
118
119   /// Third point id.
120   inline static const std::string& THIRD_POINT_ID()
121   {
122     static const std::string ID("third_point");
123     return ID;
124   }
125
126   /// Reference for third point selection.
127   inline static const std::string& THIRD_POINT_REF_ID()
128   {
129     static const std::string ID("third_point_ref");
130     return ID;
131   }
132
133   /// Radius of the circle
134   inline static const std::string& CIRCLE_RADIUS_ID()
135   {
136     static const std::string ID("circle_radius");
137     return ID;
138   }
139
140   /// Returns the kind of a feature
141   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
142   {
143     static std::string MY_KIND = SketchPlugin_MacroCircle::ID();
144     return MY_KIND;
145   }
146
147   /// \brief Request for initialization of data model of the feature: adding all attributes.
148   SKETCHPLUGIN_EXPORT virtual void initAttributes();
149
150   /// Called on change of any argument-attribute of this object
151   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
152
153   /// Returns the AIS preview
154   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
155
156   /// Creates a new part document if needed
157   SKETCHPLUGIN_EXPORT virtual void execute();
158
159   /// Moves the feature
160   /// \param theDeltaX the delta for X coordinate is moved
161   /// \param theDeltaY the delta for Y coordinate is moved
162   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
163   {};
164
165   /// Reimplemented from ModelAPI_Feature::isMacro().
166   /// \returns true
167   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
168
169   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
170
171   /// Apply information of the message to current object. It fills reference object,
172   /// tangent type and tangent point refence in case of tangent arc
173   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
174
175   /// Use plugin manager for features creation
176   SketchPlugin_MacroCircle();
177
178 private:
179   void fillByCenterAndPassed();
180   void fillByThreePoints();
181   /// set fields if only two of three points is initialized
182   void fillByTwoPassedPoints();
183
184   void constraintsForCircleByCenterAndPassed(FeaturePtr theCircleFeature);
185   void constraintsForCircleByThreePoints(FeaturePtr theCircleFeature);
186
187   FeaturePtr createCircleFeature();
188
189 private:
190   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
191   double                         myRadius;
192 };
193
194 #endif