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