Salome HOME
Issue #2024: Redesign of circle and arc of circle
[modules/shaper.git] / src / SketchAPI / SketchAPI_MacroArc.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchAPI_MacroArc.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "SketchAPI_MacroArc.h"
8
9 #include <GeomAPI_Pnt2d.h>
10
11 #include <ModelHighAPI_Double.h>
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Selection.h>
14 #include <ModelHighAPI_Tools.h>
15
16 #include <SketchPlugin_ConstraintCoincidence.h>
17 #include <SketchPlugin_ConstraintTangent.h>
18
19 /// Obtain constraints prepared by tangent arc
20 static std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc);
21
22 //================================================================================================
23 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
24 : SketchAPI_SketchEntity(theFeature)
25 {
26   initialize();
27 }
28
29 //================================================================================================
30 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
31                              double theCenterX, double theCenterY,
32                              double theStartX, double theStartY,
33                              double theEndX, double theEndY,
34                              bool theInversed)
35 : SketchAPI_SketchEntity(theFeature)
36 {
37   if(initialize()) {
38     setByCenterStartEnd(theCenterX, theCenterY, theStartX,
39                         theStartY, theEndX, theEndY, theInversed);
40   }
41 }
42
43 //================================================================================================
44 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
46                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
47                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
48                              bool theInversed)
49 : SketchAPI_SketchEntity(theFeature)
50 {
51   if(initialize()) {
52     setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
53   }
54 }
55
56 //================================================================================================
57 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
58                              double theStartX, double theStartY,
59                              double theEndX, double theEndY,
60                              double thePassedX, double thePassedY)
61 : SketchAPI_SketchEntity(theFeature)
62 {
63   if (initialize()) {
64     setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
65   }
66 }
67
68 //===============================================================================================
69 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
70                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
71                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
72                              const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
73 : SketchAPI_SketchEntity(theFeature)
74 {
75   if (initialize()) {
76     setByStartEndPassed(theStart, theEnd, thePassed);
77   }
78 }
79
80 //================================================================================================
81 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
82                              const ModelHighAPI_RefAttr& theTangentPoint,
83                              double theEndX, double theEndY,
84                              bool theInversed)
85 : SketchAPI_SketchEntity(theFeature)
86 {
87   if (initialize()) {
88     setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
89   }
90 }
91
92 //================================================================================================
93 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
94                              const ModelHighAPI_RefAttr& theTangentPoint,
95                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
96                              bool theInversed)
97 : SketchAPI_SketchEntity(theFeature)
98 {
99   if (initialize()) {
100     setByTangent(theTangentPoint, theEnd, theInversed);
101   }
102 }
103
104 //================================================================================================
105 SketchAPI_MacroArc::~SketchAPI_MacroArc()
106 {
107
108 }
109
110 //================================================================================================
111 void SketchAPI_MacroArc::setByCenterStartEnd(double theCenterX, double theCenterY,
112                                         double theStartX, double theStartY,
113                                         double theEndX, double theEndY,
114                                         bool theInversed)
115 {
116   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType);
117   fillAttribute(center(), theCenterX, theCenterY);
118   fillAttribute(startPoint1(), theStartX, theStartY);
119   fillAttribute(endPoint1(), theEndX, theEndY);
120   fillAttribute(theInversed, myreversed);
121
122   execute();
123 }
124
125 //================================================================================================
126 void SketchAPI_MacroArc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
127                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
128                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
129                                         bool theInversed)
130 {
131   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType);
132   fillAttribute(theCenter, mycenter);
133   fillAttribute(theStart, mystartPoint1);
134   fillAttribute(theEnd, myendPoint1);
135   fillAttribute(theInversed, myreversed);
136
137   execute();
138 }
139
140 //================================================================================================
141 void SketchAPI_MacroArc::setByStartEndPassed(double theStartX, double theStartY,
142                                         double theEndX, double theEndY,
143                                         double thePassedX, double thePassedY)
144 {
145   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType);
146   fillAttribute(startPoint2(), theStartX, theStartY);
147   fillAttribute(endPoint2(), theEndX, theEndY);
148   fillAttribute(passedPoint(), thePassedX, thePassedY);
149
150   execute();
151 }
152
153 //================================================================================================
154 void SketchAPI_MacroArc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
155                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
156                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
157 {
158   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType);
159   fillAttribute(theStart, mystartPoint2);
160   fillAttribute(theEnd, myendPoint2);
161   fillAttribute(thePassed, mypassedPoint);
162
163   execute();
164 }
165
166 //================================================================================================
167 void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
168                                  double theEndX, double theEndY,
169                                  bool theInversed)
170 {
171   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType);
172   fillAttribute(theTangentPoint, mytangentPoint);
173   fillAttribute(endPoint3(), theEndX, theEndY);
174   fillAttribute(theInversed, myreversed);
175
176   execute();
177 }
178
179 //================================================================================================
180 void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
181                                  const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
182                                  bool theInversed)
183 {
184   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType);
185   fillAttribute(theTangentPoint, mytangentPoint);
186   fillAttribute(theEnd, myendPoint3);
187   fillAttribute(theInversed, myreversed);
188
189   execute();
190 }