Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroCircle.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_MacroCircle_H_
22 #define SketchPlugin_MacroCircle_H_
23
24 #include <ModelAPI_IReentrant.h>
25
26 #include "SketchPlugin.h"
27
28 #include "SketchPlugin_SketchEntity.h"
29
30 #include <GeomAPI_IPresentable.h>
31
32 class GeomAPI_Circ2d;
33 class GeomAPI_Pnt2d;
34
35 /**\class SketchPlugin_MacroCircle
36  * \ingroup Plugins
37  * \brief Feature for creation of the new circle in Sketch.
38  */
39 class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity,
40                                 public GeomAPI_IPresentable,
41                                 public ModelAPI_IReentrant
42 {
43  public:
44   /// Circle feature kind
45   inline static const std::string& ID()
46   {
47     static const std::string ID("SketchMacroCircle");
48     return ID;
49   }
50
51   inline static const std::string& CIRCLE_TYPE()
52   {
53     static const std::string ID("circle_type");
54     return ID;
55   }
56
57   inline static const std::string& EDIT_CIRCLE_TYPE()
58   {
59     static const std::string ID("edit_circle_type");
60     return ID;
61   }
62
63   /// Creation method by center and passed point.
64   inline static const std::string& CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()
65   {
66     static const std::string ID("circle_type_by_center_and_passed_points");
67     return ID;
68   }
69
70   /// Creation method by three points.
71   inline static const std::string& CIRCLE_TYPE_BY_THREE_POINTS()
72   {
73     static const std::string ID("circle_type_by_three_points");
74     return ID;
75   }
76
77   /// 2D point - center of the circle.
78   inline static const std::string& CENTER_POINT_ID()
79   {
80     static const std::string ID("center_point");
81     return ID;
82   }
83
84   /// Reference for center point selection.
85   inline static const std::string& CENTER_POINT_REF_ID()
86   {
87     static const std::string ID("center_point_ref");
88     return ID;
89   }
90
91   /// 2D point - passed point of the circle
92   inline static const std::string& PASSED_POINT_ID()
93   {
94     static const std::string ID("passed_point");
95     return ID;
96   }
97
98   /// Reference for passed point selection.
99   inline static const std::string& PASSED_POINT_REF_ID()
100   {
101     static const std::string ID("passed_point_ref");
102     return ID;
103   }
104
105   /// First point id.
106   inline static const std::string& FIRST_POINT_ID()
107   {
108     static const std::string ID("first_point");
109     return ID;
110   }
111
112   /// Reference for first point selection.
113   inline static const std::string& FIRST_POINT_REF_ID()
114   {
115     static const std::string ID("first_point_ref");
116     return ID;
117   }
118
119   /// Second point id.
120   inline static const std::string& SECOND_POINT_ID()
121   {
122     static const std::string ID("second_point");
123     return ID;
124   }
125
126   /// Reference for second point selection.
127   inline static const std::string& SECOND_POINT_REF_ID()
128   {
129     static const std::string ID("second_point_ref");
130     return ID;
131   }
132
133   /// Third point id.
134   inline static const std::string& THIRD_POINT_ID()
135   {
136     static const std::string ID("third_point");
137     return ID;
138   }
139
140   /// Reference for third point selection.
141   inline static const std::string& THIRD_POINT_REF_ID()
142   {
143     static const std::string ID("third_point_ref");
144     return ID;
145   }
146
147   /// Radius of the circle
148   inline static const std::string& CIRCLE_RADIUS_ID()
149   {
150     static const std::string ID("circle_radius");
151     return ID;
152   }
153
154   /// Returns the kind of a feature
155   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
156   {
157     static std::string MY_KIND = SketchPlugin_MacroCircle::ID();
158     return MY_KIND;
159   }
160
161   /// \brief Request for initialization of data model of the feature: adding all attributes.
162   SKETCHPLUGIN_EXPORT virtual void initAttributes();
163
164   /// Called on change of any argument-attribute of this object
165   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
166
167   /// Returns the AIS preview
168   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
169
170   /// Creates a new part document if needed
171   SKETCHPLUGIN_EXPORT virtual void execute();
172
173   /// Moves the feature
174   /// \param theDeltaX the delta for X coordinate is moved
175   /// \param theDeltaY the delta for Y coordinate is moved
176   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
177   {};
178
179   /// Reimplemented from ModelAPI_Feature::isMacro().
180   /// \returns true
181   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
182
183   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
184
185   /// Apply information of the message to current object. It fills reference object,
186   /// tangent type and tangent point refence in case of tangent arc
187   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
188
189   /// Use plugin manager for features creation
190   SketchPlugin_MacroCircle();
191
192 private:
193   void fillByCenterAndPassed();
194   void fillByThreePoints();
195   /// set fields if only two of three points is initialized
196   void fillByTwoPassedPoints();
197
198   void constraintsForCircleByCenterAndPassed(FeaturePtr theCircleFeature);
199   void constraintsForCircleByThreePoints(FeaturePtr theCircleFeature);
200
201   FeaturePtr createCircleFeature();
202
203 private:
204   std::shared_ptr<GeomAPI_Pnt2d> myCenter;
205   double                         myRadius;
206 };
207
208 #endif