]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_MacroArc.h
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_ID()
75   {
76     static const std::string ID = "start_point";
77     return ID;
78   }
79
80   inline static const std::string& START_POINT_REF_ID()
81   {
82     static const std::string ID = "start_point_ref";
83     return ID;
84   }
85
86   /// End 2D point of the arc
87   inline static const std::string& END_POINT_ID()
88   {
89     static const std::string ID = "end_point";
90     return ID;
91   }
92
93   inline static const std::string& END_POINT_REF_ID()
94   {
95     static const std::string ID = "end_point_ref";
96     return ID;
97   }
98
99   /// Passed point of the arc.
100   static const std::string& PASSED_POINT_ID()
101   {
102     static const std::string ID("passed_point");
103     return ID;
104   }
105
106   static const std::string& PASSED_POINT_REF_ID()
107   {
108     static const std::string ID("passed_point_ref");
109     return ID;
110   }
111
112   static const std::string& TANGENT_POINT_ID()
113   {
114     static const std::string ID("tangent_point");
115     return ID;
116   }
117
118   /// Reversed flag
119   inline static const std::string& REVERSED_ID()
120   {
121     static const std::string ID("reversed");
122     return ID;
123   }
124
125   /// Arc radius.
126   static const std::string& RADIUS_ID()
127   {
128     static const std::string ID("radius");
129     return ID;
130   }
131
132   /// Arc angle.
133   static const std::string& ANGLE_ID()
134   {
135     static const std::string ID("angle");
136     return ID;
137   }
138
139   /// Returns the kind of a feature
140   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
141   {
142     static std::string MY_KIND = SketchPlugin_MacroArc::ID();
143     return MY_KIND;
144   }
145
146   /// \brief Request for initialization of data model of the feature: adding all attributes.
147   SKETCHPLUGIN_EXPORT virtual void initAttributes();
148
149   /// Called on change of any argument-attribute of this object
150   /// \param theID identifier of changed attribute
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 an arc-shape
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
166   /// Reimplemented from ModelAPI_Feature::isMacro().
167   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
168
169   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
170
171   /// Use plugin manager for features creation.
172   SketchPlugin_MacroArc();
173
174 private:
175   /// Set fields for center, start and end points
176   void fillByCenterAndTwoPassed();
177   /// Set fields for center, start and end points by selected passed points
178   void fillByThreePassedPoints();
179   /// Set fields for center, start and end points by selected tangent edge
180   void fillByTangentEdge();
181
182   FeaturePtr createArcFeature();
183
184   void recalculateReversedFlagByEnd(const GeomAPI_Circ2d& theCurrentCircular);
185   void recalculateReversedFlagByPassed(const GeomAPI_Circ2d& theCurrentCircular);
186
187 private:
188   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
189   std::shared_ptr<GeomAPI_Pnt2d> myStart;
190   std::shared_ptr<GeomAPI_Pnt2d> myEnd;
191
192   /// To define in which direction draw arc.
193   double myParamBefore;
194 };
195
196 #endif