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