Salome HOME
Issue #2167: error when create circle
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroArc.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_MacroArc.h
4 // Created:     26 May 2014
5 // Author:      Artem ZHIDKOV
6
7 #ifndef SketchPlugin_MacroArc_H_
8 #define SketchPlugin_MacroArc_H_
9
10 #include <ModelAPI_IReentrant.h>
11
12 #include "SketchPlugin.h"
13 #include "SketchPlugin_SketchEntity.h"
14
15 #include <GeomAPI_IPresentable.h>
16
17 class GeomAPI_Circ2d;
18 class GeomAPI_Pnt2d;
19
20 /**\class SketchPlugin_MacroArc
21  * \ingroup Plugins
22  * \brief Feature for creation of the new arc of circle in PartSet.
23  * The visualization of this object is separated in two parts. The first one is an AIS object
24  * calculated when there is non-initialized attributes of the arc. The second is a result and
25  * it is calculated if all attributes are initialized.
26  */
27 class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity,
28                              public GeomAPI_IPresentable,
29                              public ModelAPI_IReentrant
30 {
31  public:
32   /// Arc feature kind
33   inline static const std::string& ID()
34   {
35     static const std::string ID("SketchMacroArc");
36     return ID;
37   }
38
39   inline static const std::string& ARC_TYPE()
40   {
41     static const std::string ID("arc_type");
42     return ID;
43   }
44
45   static const std::string& ARC_TYPE_BY_CENTER_AND_POINTS()
46   {
47     static const std::string ID("by_center_and_points");
48     return ID;
49   }
50   static const std::string& ARC_TYPE_BY_THREE_POINTS()
51   {
52     static const std::string ID("by_three_points");
53     return ID;
54   }
55
56   inline static const std::string& ARC_TYPE_BY_TANGENT_EDGE()
57   {
58     static const std::string ID("by_tangent_edge");
59     return ID;
60   }
61
62   /// Central 2D point of the circle which contains the arc
63   inline static const std::string& CENTER_POINT_ID()
64   {
65     static const std::string ID = "center_point";
66     return ID;
67   }
68
69   inline static const std::string& CENTER_POINT_REF_ID()
70   {
71     static const std::string ID = "center_point_ref";
72     return ID;
73   }
74
75   /// Start 2D point of the arc
76   inline static const std::string& START_POINT_1_ID()
77   {
78     static const std::string ID = "start_point_1";
79     return ID;
80   }
81
82   /// Start 2D point of the arc
83   inline static const std::string& START_POINT_2_ID()
84   {
85     static const std::string ID = "start_point_2";
86     return ID;
87   }
88
89   inline static const std::string& START_POINT_REF_ID()
90   {
91     static const std::string ID = "start_point_ref";
92     return ID;
93   }
94
95   /// End 2D point of the arc
96   inline static const std::string& END_POINT_1_ID()
97   {
98     static const std::string ID = "end_point_1";
99     return ID;
100   }
101
102   /// End 2D point of the arc
103   inline static const std::string& END_POINT_2_ID()
104   {
105     static const std::string ID = "end_point_2";
106     return ID;
107   }
108
109   /// End 2D point of the arc
110   inline static const std::string& END_POINT_3_ID()
111   {
112     static const std::string ID = "end_point_3";
113     return ID;
114   }
115
116   inline static const std::string& END_POINT_REF_ID()
117   {
118     static const std::string ID = "end_point_ref";
119     return ID;
120   }
121
122   /// Passed point of the arc.
123   static const std::string& PASSED_POINT_ID()
124   {
125     static const std::string ID("passed_point");
126     return ID;
127   }
128
129   static const std::string& PASSED_POINT_REF_ID()
130   {
131     static const std::string ID("passed_point_ref");
132     return ID;
133   }
134
135   static const std::string& TANGENT_POINT_ID()
136   {
137     static const std::string ID("tangent_point");
138     return ID;
139   }
140
141   /// Reversed flag
142   inline static const std::string& REVERSED_ID()
143   {
144     static const std::string ID("reversed");
145     return ID;
146   }
147
148   /// Arc radius.
149   static const std::string& RADIUS_ID()
150   {
151     static const std::string ID("radius");
152     return ID;
153   }
154
155   /// Arc angle.
156   static const std::string& ANGLE_ID()
157   {
158     static const std::string ID("angle");
159     return ID;
160   }
161
162   /// Arc angle.
163   static const std::string& EDIT_ARC_TYPE_ID()
164   {
165     static const std::string ID("edit_arc_type");
166     return ID;
167   }
168
169   /// Returns the kind of a feature
170   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
171   {
172     static std::string MY_KIND = SketchPlugin_MacroArc::ID();
173     return MY_KIND;
174   }
175
176   /// \brief Request for initialization of data model of the feature: adding all attributes.
177   SKETCHPLUGIN_EXPORT virtual void initAttributes();
178
179   /// Called on change of any argument-attribute of this object
180   /// \param theID identifier of changed attribute
181   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
182
183   /// Returns the AIS preview
184   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
185
186   /// Creates an arc-shape
187   SKETCHPLUGIN_EXPORT virtual void execute();
188
189   /// Moves the feature
190   /// \param theDeltaX the delta for X coordinate is moved
191   /// \param theDeltaY the delta for Y coordinate is moved
192   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
193   {
194   };
195
196   /// Reimplemented from ModelAPI_Feature::isMacro().
197   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
198
199   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
200
201   /// Apply information of the message to current object. It fills reference object,
202   /// tangent type and tangent point refence in case of tangent arc
203   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
204
205   /// Use plugin manager for features creation.
206   SketchPlugin_MacroArc();
207
208   /// Returns shape of arc.
209   /// \param isBound  if true prepare arc, otherwice create circle containing this arc
210   GeomShapePtr getArcShape(bool isBound = true);
211
212 private:
213   /// Set fields for center, start and end points
214   void fillByCenterAndTwoPassed();
215   /// Set fields for center, start and end points by selected passed points
216   void fillByThreePassedPoints();
217   /// Set fields for center, start and end points by selected tangent edge
218   void fillByTangentEdge();
219
220   FeaturePtr createArcFeature();
221
222   void recalculateReversedFlagByEnd(const GeomAPI_Circ2d& theCurrentCircular);
223   void recalculateReversedFlagByPassed(const GeomAPI_Circ2d& theCurrentCircular);
224
225 private:
226   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
227   std::shared_ptr<GeomAPI_Pnt2d> myStart;
228   std::shared_ptr<GeomAPI_Pnt2d> myEnd;
229
230   /// To define in which direction draw arc.
231   double myParamBefore;
232 };
233
234 #endif