1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef SketchPlugin_MacroArc_H_
21 #define SketchPlugin_MacroArc_H_
23 #include <ModelAPI_IReentrant.h>
25 #include "SketchPlugin.h"
26 #include "SketchPlugin_SketchEntity.h"
28 #include <GeomAPI_IPresentable.h>
33 /**\class SketchPlugin_MacroArc
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.
40 class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity,
41 public GeomAPI_IPresentable,
42 public ModelAPI_IReentrant
46 inline static const std::string& ID()
48 static const std::string ID("SketchMacroArc");
52 inline static const std::string& ARC_TYPE()
54 static const std::string ID("arc_type");
58 static const std::string& ARC_TYPE_BY_CENTER_AND_POINTS()
60 static const std::string ID("by_center_and_points");
63 static const std::string& ARC_TYPE_BY_THREE_POINTS()
65 static const std::string ID("by_three_points");
69 inline static const std::string& ARC_TYPE_BY_TANGENT_EDGE()
71 static const std::string ID("by_tangent_edge");
75 inline static const std::string& ARC_TYPE_BY_TRANSVERSAL_LINE()
77 static const std::string ID("by_transversal_line");
81 /// Central 2D point of the circle which contains the arc
82 inline static const std::string& CENTER_POINT_ID()
84 static const std::string ID = "center_point";
88 inline static const std::string& CENTER_POINT_REF_ID()
90 static const std::string ID = "center_point_ref";
94 /// Start 2D point of the arc
95 inline static const std::string& START_POINT_1_ID()
97 static const std::string ID = "start_point_1";
101 /// Start 2D point of the arc
102 inline static const std::string& START_POINT_2_ID()
104 static const std::string ID = "start_point_2";
108 inline static const std::string& START_POINT_REF_ID()
110 static const std::string ID = "start_point_ref";
114 /// End 2D point of the arc
115 inline static const std::string& END_POINT_1_ID()
117 static const std::string ID = "end_point_1";
121 /// End 2D point of the arc
122 inline static const std::string& END_POINT_2_ID()
124 static const std::string ID = "end_point_2";
128 /// End 2D point of the arc
129 inline static const std::string& END_POINT_3_ID()
131 static const std::string ID = "end_point_3";
135 inline static const std::string& END_POINT_REF_ID()
137 static const std::string ID = "end_point_ref";
141 /// Passed point of the arc.
142 static const std::string& PASSED_POINT_ID()
144 static const std::string ID("passed_point");
148 static const std::string& PASSED_POINT_REF_ID()
150 static const std::string ID("passed_point_ref");
154 static const std::string& TANGENT_POINT_ID()
156 static const std::string ID("tangent_point");
161 inline static const std::string& REVERSED_ID()
163 static const std::string ID("reversed");
168 static const std::string& RADIUS_ID()
170 static const std::string ID("radius");
175 static const std::string& ANGLE_ID()
177 static const std::string ID("angle");
182 static const std::string& EDIT_ARC_TYPE_ID()
184 static const std::string ID("edit_arc_type");
188 /// Returns the kind of a feature
189 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
191 static std::string MY_KIND = SketchPlugin_MacroArc::ID();
195 /// \brief Request for initialization of data model of the feature: adding all attributes.
196 SKETCHPLUGIN_EXPORT virtual void initAttributes();
198 /// Called on change of any argument-attribute of this object
199 /// \param theID identifier of changed attribute
200 SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
202 /// Returns the AIS preview
203 virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
205 /// Creates an arc-shape
206 SKETCHPLUGIN_EXPORT virtual void execute();
208 /// Reimplemented from ModelAPI_Feature::isMacro().
209 SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
211 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
213 /// Apply information of the message to current object. It fills reference object,
214 /// tangent type and tangent point refence in case of tangent arc
215 virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
217 /// Use plugin manager for features creation.
218 SketchPlugin_MacroArc();
220 /// Returns shape of arc.
221 /// \param isBound if true prepare arc, otherwice create circle containing this arc
222 GeomShapePtr getArcShape(bool isBound = true);
225 /// Set fields for center, start and end points
226 void fillByCenterAndTwoPassed();
227 /// Set fields for center, start and end points by selected passed points
228 void fillByThreePassedPoints();
229 /// Set fields for center, start and end points by selected tangent or transversal edge
230 /// \param theTransversal if \c true, builds transversal arc, otherwise builds tangential arc.
231 void fillByEdge(bool theTransversal);
233 FeaturePtr createArcFeature();
235 void recalculateReversedFlagByEnd(const GeomAPI_Circ2d& theCurrentCircular);
236 void recalculateReversedFlagByPassed(const GeomAPI_Circ2d& theCurrentCircular);
239 std::shared_ptr<GeomAPI_Pnt2d> myCenter;
240 std::shared_ptr<GeomAPI_Pnt2d> myStart;
241 std::shared_ptr<GeomAPI_Pnt2d> myEnd;
243 /// To define in which direction draw arc.
244 double myParamBefore;