Salome HOME
bc387acd518e7703401f9372f2f7af52163cf2bc
[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 "SketchPlugin.h"
11
12 #include "SketchPlugin_Sketch.h"
13 #include "SketchPlugin_SketchEntity.h"
14
15 #include <GeomAPI_IPresentable.h>
16 #include <GeomAPI_Pnt2d.h>
17 #include <GeomAPI_Circ2d.h>
18
19 /**\class SketchPlugin_MacroCircle
20  * \ingroup Plugins
21  * \brief Feature for creation of the new circle in Sketch.
22  */
23 class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity,
24                                 public GeomAPI_IPresentable
25 {
26  public:
27   /// Circle feature kind
28   inline static const std::string& ID()
29   {
30     static const std::string ID("SketchMacroCircle");
31     return ID;
32   }
33
34   inline static const std::string& CIRCLE_TYPE()
35   {
36     static const std::string ID("circle_type");
37     return ID;
38   }
39
40   /// Creation method by center and passed point.
41   inline static const std::string& CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()
42   {
43     static const std::string ID("circle_type_by_center_and_passed_points");
44     return ID;
45   }
46
47   /// Creation method by three points.
48   inline static const std::string& CIRCLE_TYPE_BY_THREE_POINTS()
49   {
50     static const std::string ID("circle_type_by_three_points");
51     return ID;
52   }
53
54   /// 2D point - center of the circle.
55   inline static const std::string& CENTER_POINT_ID()
56   {
57     static const std::string ID("center_point");
58     return ID;
59   }
60
61   /// Reference for center point selection.
62   inline static const std::string& CENTER_POINT_REF_ID()
63   {
64     static const std::string ID("center_point_ref");
65     return ID;
66   }
67
68   /// 2D point - passed point of the circle
69   inline static const std::string& PASSED_POINT_ID()
70   {
71     static const std::string ID("passed_point");
72     return ID;
73   }
74
75   /// Reference for passed point selection.
76   inline static const std::string& PASSED_POINT_REF_ID()
77   {
78     static const std::string ID("passed_point_ref");
79     return ID;
80   }
81
82   /// First point id.
83   inline static const std::string& FIRST_POINT_ID()
84   {
85     static const std::string ID("first_point");
86     return ID;
87   }
88
89   /// Reference for first point selection.
90   inline static const std::string& FIRST_POINT_REF_ID()
91   {
92     static const std::string ID("first_point_ref");
93     return ID;
94   }
95
96   /// Second point id.
97   inline static const std::string& SECOND_POINT_ID()
98   {
99     static const std::string ID("second_point");
100     return ID;
101   }
102
103   /// Reference for second point selection.
104   inline static const std::string& SECOND_POINT_REF_ID()
105   {
106     static const std::string ID("second_point_ref");
107     return ID;
108   }
109
110   /// Third point id.
111   inline static const std::string& THIRD_POINT_ID()
112   {
113     static const std::string ID("third_point");
114     return ID;
115   }
116
117   /// Reference for third point selection.
118   inline static const std::string& THIRD_POINT_REF_ID()
119   {
120     static const std::string ID("third_point_ref");
121     return ID;
122   }
123
124   /// Radius of the circle
125   inline static const std::string& CIRCLE_RADIUS_ID()
126   {
127     static const std::string ID("circle_radius");
128     return ID;
129   }
130
131   /// Returns the kind of a feature
132   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
133   {
134     static std::string MY_KIND = SketchPlugin_MacroCircle::ID();
135     return MY_KIND;
136   }
137
138   /// \brief Request for initialization of data model of the feature: adding all attributes.
139   SKETCHPLUGIN_EXPORT virtual void initAttributes();
140
141   /// Called on change of any argument-attribute of this object
142   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
143
144   /// Returns the AIS preview
145   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
146
147   /// Creates a new part document if needed
148   SKETCHPLUGIN_EXPORT virtual void execute();
149
150   /// Moves the feature
151   /// \param theDeltaX the delta for X coordinate is moved
152   /// \param theDeltaY the delta for Y coordinate is moved
153   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
154   {};
155
156   /// Reimplemented from ModelAPI_Feature::isMacro().
157   /// \returns true
158   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
159
160   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
161
162   /// Use plugin manager for features creation
163   SketchPlugin_MacroCircle();
164
165 private:
166   void resetAttribute(const std::string& theId);
167
168   void createCircleByCenterAndPassed();
169   void createCircleByThreePoints();
170
171   FeaturePtr createCircleFeature(const std::shared_ptr<GeomAPI_Circ2d>& theCircle);
172
173 private:
174   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
175   double myRadius;
176 };
177
178 #endif