Salome HOME
Add Projection to SketchAPI_Sketch
[modules/shaper.git] / src / SketchAPI / SketchAPI_Arc.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchAPI_Arc.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "SketchAPI_Arc.h"
8
9 #include <GeomAPI_Pnt2d.h>
10
11 #include <ModelHighAPI_Double.h>
12 #include <ModelHighAPI_Selection.h>
13 #include <ModelHighAPI_Tools.h>
14
15 //==================================================================================================
16 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
17 : SketchAPI_SketchEntity(theFeature)
18 {
19   initialize();
20 }
21
22 //==================================================================================================
23 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
24                              double theCenterX, double theCenterY,
25                              double theStartX, double theStartY,
26                              double theEndX, double theEndY,
27                              bool theInversed)
28 : SketchAPI_SketchEntity(theFeature)
29 {
30   if(initialize()) {
31     setByCenterStartEnd(theCenterX, theCenterY, theStartX, theStartY, theEndX, theEndY, theInversed);
32   }
33 }
34
35 //==================================================================================================
36 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
38                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
39                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
40                              bool theInversed)
41 : SketchAPI_SketchEntity(theFeature)
42 {
43   if(initialize()) {
44     setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
45   }
46 }
47
48 //==================================================================================================
49 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
50                              double theStartX, double theStartY,
51                              double theEndX, double theEndY,
52                              double thePassedX, double thePassedY)
53 : SketchAPI_SketchEntity(theFeature)
54 {
55   if (initialize()) {
56     setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
57   }
58 }
59
60 //==================================================================================================
61 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
63                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
64                              const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
65 : SketchAPI_SketchEntity(theFeature)
66 {
67   if (initialize()) {
68     setByStartEndPassed(theStart, theEnd, thePassed);
69   }
70 }
71
72 //==================================================================================================
73 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
74                              const ModelHighAPI_RefAttr& theTangentPoint,
75                              double theEndX, double theEndY,
76                              bool theInversed)
77 : SketchAPI_SketchEntity(theFeature)
78 {
79   if (initialize()) {
80     setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
81   }
82 }
83
84 //==================================================================================================
85 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
86                              const ModelHighAPI_RefAttr& theTangentPoint,
87                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
88                              bool theInversed)
89 : SketchAPI_SketchEntity(theFeature)
90 {
91   if (initialize()) {
92     setByTangent(theTangentPoint, theEnd, theInversed);
93   }
94 }
95
96 //==================================================================================================
97 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
98                              const ModelHighAPI_Selection& theExternal)
99 : SketchAPI_SketchEntity(theFeature)
100 {
101   if (initialize()) {
102     setByExternal(theExternal);
103   }
104 }
105
106 //==================================================================================================
107 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
108                              const std::string& theExternalName)
109 : SketchAPI_SketchEntity(theFeature)
110 {
111   if (initialize()) {
112     setByExternalName(theExternalName);
113   }
114 }
115
116 //==================================================================================================
117 SketchAPI_Arc::~SketchAPI_Arc()
118 {
119
120 }
121
122 //==================================================================================================
123 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
124                                         double theStartX, double theStartY,
125                                         double theEndX, double theEndY,
126                                         bool theInversed)
127 {
128   fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType);
129   fillAttribute(center(), theCenterX, theCenterY);
130   fillAttribute(startPoint(), theStartX, theStartY);
131   fillAttribute(endPoint(), theEndX, theEndY);
132   fillAttribute(theInversed, myinversed);
133
134   execute();
135 }
136
137 //==================================================================================================
138 void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
139                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
140                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
141                                         bool theInversed)
142 {
143   fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType);
144   fillAttribute(theCenter, mycenter);
145   fillAttribute(theStart, mystartPoint);
146   fillAttribute(theEnd, myendPoint);
147   fillAttribute(theInversed, myinversed);
148
149   execute();
150 }
151
152 //==================================================================================================
153 void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY,
154                                         double theEndX, double theEndY,
155                                         double thePassedX, double thePassedY)
156 {
157   fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
158   fillAttribute(startPoint(), theStartX, theStartY);
159   fillAttribute(endPoint(), theEndX, theEndY);
160   fillAttribute(passedPoint(), thePassedX, thePassedY);
161
162   execute();
163 }
164
165 //==================================================================================================
166 void SketchAPI_Arc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
167                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
168                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
169 {
170   fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
171   fillAttribute(theStart, mystartPoint);
172   fillAttribute(theEnd, myendPoint);
173   fillAttribute(thePassed, mypassedPoint);
174
175   execute();
176 }
177
178 //==================================================================================================
179 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
180                                  double theEndX, double theEndY,
181                                  bool theInversed)
182 {
183   fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
184   fillAttribute(theTangentPoint, mytangentPoint);
185   fillAttribute(endPoint(), theEndX, theEndY);
186   fillAttribute(theInversed, myinversed);
187
188   execute();
189 }
190
191 //==================================================================================================
192 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
193                                  const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
194                                  bool theInversed)
195 {
196   fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
197   fillAttribute(theTangentPoint, mytangentPoint);
198   fillAttribute(theEnd, myendPoint);
199   fillAttribute(theInversed, myinversed);
200
201   execute();
202 }
203
204 //==================================================================================================
205 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
206 {
207   fillAttribute(theExternal, external());
208
209   execute();
210 }
211
212 //==================================================================================================
213 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
214 {
215   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
216
217   execute();
218 }
219
220 //==================================================================================================
221 void SketchAPI_Arc::setRadius(double theRadius)
222 {
223   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
224
225   execute();
226 }
227
228 //==================================================================================================
229 void SketchAPI_Arc::setAngle(double theAngle)
230 {
231   fillAttribute(ModelHighAPI_Double(theAngle), myangle);
232
233   execute();
234 }