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