1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef SketchPlugin_MacroArc_H_
22 #define SketchPlugin_MacroArc_H_
24 #include <ModelAPI_IReentrant.h>
26 #include "SketchPlugin.h"
27 #include "SketchPlugin_SketchEntity.h"
29 #include <GeomAPI_IPresentable.h>
34 /**\class SketchPlugin_MacroArc
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.
41 class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity,
42 public GeomAPI_IPresentable,
43 public ModelAPI_IReentrant
47 inline static const std::string& ID()
49 static const std::string ID("SketchMacroArc");
53 inline static const std::string& ARC_TYPE()
55 static const std::string ID("arc_type");
59 static const std::string& ARC_TYPE_BY_CENTER_AND_POINTS()
61 static const std::string ID("by_center_and_points");
64 static const std::string& ARC_TYPE_BY_THREE_POINTS()
66 static const std::string ID("by_three_points");
70 inline static const std::string& ARC_TYPE_BY_TANGENT_EDGE()
72 static const std::string ID("by_tangent_edge");
76 /// Central 2D point of the circle which contains the arc
77 inline static const std::string& CENTER_POINT_ID()
79 static const std::string ID = "center_point";
83 inline static const std::string& CENTER_POINT_REF_ID()
85 static const std::string ID = "center_point_ref";
89 /// Start 2D point of the arc
90 inline static const std::string& START_POINT_1_ID()
92 static const std::string ID = "start_point_1";
96 /// Start 2D point of the arc
97 inline static const std::string& START_POINT_2_ID()
99 static const std::string ID = "start_point_2";
103 inline static const std::string& START_POINT_REF_ID()
105 static const std::string ID = "start_point_ref";
109 /// End 2D point of the arc
110 inline static const std::string& END_POINT_1_ID()
112 static const std::string ID = "end_point_1";
116 /// End 2D point of the arc
117 inline static const std::string& END_POINT_2_ID()
119 static const std::string ID = "end_point_2";
123 /// End 2D point of the arc
124 inline static const std::string& END_POINT_3_ID()
126 static const std::string ID = "end_point_3";
130 inline static const std::string& END_POINT_REF_ID()
132 static const std::string ID = "end_point_ref";
136 /// Passed point of the arc.
137 static const std::string& PASSED_POINT_ID()
139 static const std::string ID("passed_point");
143 static const std::string& PASSED_POINT_REF_ID()
145 static const std::string ID("passed_point_ref");
149 static const std::string& TANGENT_POINT_ID()
151 static const std::string ID("tangent_point");
156 inline static const std::string& REVERSED_ID()
158 static const std::string ID("reversed");
163 static const std::string& RADIUS_ID()
165 static const std::string ID("radius");
170 static const std::string& ANGLE_ID()
172 static const std::string ID("angle");
177 static const std::string& EDIT_ARC_TYPE_ID()
179 static const std::string ID("edit_arc_type");
183 /// Returns the kind of a feature
184 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
186 static std::string MY_KIND = SketchPlugin_MacroArc::ID();
190 /// \brief Request for initialization of data model of the feature: adding all attributes.
191 SKETCHPLUGIN_EXPORT virtual void initAttributes();
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);
197 /// Returns the AIS preview
198 virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
200 /// Creates an arc-shape
201 SKETCHPLUGIN_EXPORT virtual void execute();
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)
210 /// Reimplemented from ModelAPI_Feature::isMacro().
211 SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
213 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
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);
219 /// Use plugin manager for features creation.
220 SketchPlugin_MacroArc();
222 /// Returns shape of arc.
223 /// \param isBound if true prepare arc, otherwice create circle containing this arc
224 GeomShapePtr getArcShape(bool isBound = true);
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();
234 FeaturePtr createArcFeature();
236 void recalculateReversedFlagByEnd(const GeomAPI_Circ2d& theCurrentCircular);
237 void recalculateReversedFlagByPassed(const GeomAPI_Circ2d& theCurrentCircular);
240 std::shared_ptr<GeomAPI_Pnt2d> myCenter;
241 std::shared_ptr<GeomAPI_Pnt2d> myStart;
242 std::shared_ptr<GeomAPI_Pnt2d> myEnd;
244 /// To define in which direction draw arc.
245 double myParamBefore;