Salome HOME
Add Mirror and fix tests
[modules/shaper.git] / src / SketchAPI / SketchAPI_Sketch.cpp
1 // Name   : SketchAPI_Sketch.cpp
2 // Purpose: 
3 //
4 // History:
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Sketch.h"
9 //--------------------------------------------------------------------------------------
10 #include <SketchPlugin_Constraint.h>
11 #include <SketchPlugin_ConstraintAngle.h>
12 #include <SketchPlugin_ConstraintCoincidence.h>
13 #include <SketchPlugin_ConstraintCollinear.h>
14 #include <SketchPlugin_ConstraintDistance.h>
15 #include <SketchPlugin_ConstraintEqual.h>
16 #include <SketchPlugin_ConstraintFillet.h>
17 #include <SketchPlugin_ConstraintHorizontal.h>
18 #include <SketchPlugin_ConstraintLength.h>
19 #include <SketchPlugin_ConstraintMiddle.h>
20 #include <SketchPlugin_ConstraintMirror.h>
21 #include <SketchPlugin_ConstraintParallel.h>
22 #include <SketchPlugin_ConstraintPerpendicular.h>
23 #include <SketchPlugin_ConstraintRadius.h>
24 #include <SketchPlugin_ConstraintRigid.h>
25 #include <SketchPlugin_ConstraintTangent.h>
26 #include <SketchPlugin_ConstraintVertical.h>
27 //--------------------------------------------------------------------------------------
28 #include <ModelAPI_CompositeFeature.h>
29 #include <ModelAPI_ResultConstruction.h>
30 #include <ModelHighAPI_RefAttr.h>
31 #include <ModelHighAPI_Selection.h>
32 #include <ModelHighAPI_Tools.h>
33 //--------------------------------------------------------------------------------------
34 #include "SketchAPI_Arc.h"
35 #include "SketchAPI_Circle.h"
36 #include "SketchAPI_Line.h"
37 #include "SketchAPI_Mirror.h"
38 #include "SketchAPI_Point.h"
39 //--------------------------------------------------------------------------------------
40 SketchAPI_Sketch::SketchAPI_Sketch(
41     const std::shared_ptr<ModelAPI_Feature> & theFeature)
42 : ModelHighAPI_Interface(theFeature)
43 {
44   initialize();
45 }
46
47 SketchAPI_Sketch::SketchAPI_Sketch(
48     const std::shared_ptr<ModelAPI_Feature> & theFeature,
49     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
50 : ModelHighAPI_Interface(theFeature)
51 {
52   if (initialize()) {
53     setPlane(thePlane);
54   }
55 }
56
57 SketchAPI_Sketch::SketchAPI_Sketch(
58     const std::shared_ptr<ModelAPI_Feature> & theFeature,
59     const ModelHighAPI_Selection & theExternal)
60 : ModelHighAPI_Interface(theFeature)
61 {
62   if (initialize()) {
63     setExternal(theExternal);
64   }
65 }
66
67 SketchAPI_Sketch::~SketchAPI_Sketch()
68 {
69
70 }
71
72 //--------------------------------------------------------------------------------------
73 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
74 {
75   return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
76 }
77
78 //--------------------------------------------------------------------------------------
79 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
80 {
81   fillAttribute(thePlane->origin(), myorigin);
82   fillAttribute(thePlane->dirX(), mydirX);
83   fillAttribute(thePlane->normal(), mynormal);
84
85   execute();
86 }
87
88 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
89 {
90   fillAttribute(theExternal, myexternal);
91
92   execute();
93 }
94
95 //--------------------------------------------------------------------------------------
96 void SketchAPI_Sketch::setValue(
97     const std::shared_ptr<ModelAPI_Feature> & theConstraint,
98     const ModelHighAPI_Double & theValue)
99 {
100   // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
101   fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
102
103 //  theConstraint->execute();
104 }
105
106 //--------------------------------------------------------------------------------------
107 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
108 {
109   const_cast<SketchAPI_Sketch*>(this)->execute();
110
111   std::list<ModelHighAPI_Selection> aSelectionList;
112
113   ResultConstructionPtr aResultConstruction =
114       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
115   if (aResultConstruction.get() == NULL)
116     return aSelectionList;
117
118   for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
119     aSelectionList.push_back(
120         ModelHighAPI_Selection(aResultConstruction,
121                                aResultConstruction->face(anIndex)));
122   }
123
124   return aSelectionList;
125 }
126
127 //--------------------------------------------------------------------------------------
128 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
129                     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
130 {
131   // TODO(spo): check that thePart is not empty
132   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
133   return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
134 }
135
136 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
137                     const ModelHighAPI_Selection & theExternal)
138 {
139   // TODO(spo): check that thePart is not empty
140   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
141   return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
142 }
143
144 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
145                     const std::string & theExternalName)
146 {
147   // TODO(spo): check that thePart is not empty
148   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
149   return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
150 }
151
152 //--------------------------------------------------------------------------------------
153 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
154     double theX, double theY)
155 {
156   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
157   return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
158 }
159 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
160     const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
161 {
162   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
163   return PointPtr(new SketchAPI_Point(aFeature, thePoint));
164 }
165 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
166 {
167   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
168   return PointPtr(new SketchAPI_Point(aFeature, theExternal));
169 }
170 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
171 {
172   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
173   return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
174 }
175
176 //--------------------------------------------------------------------------------------
177 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
178 {
179   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
180   return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
181 }
182 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
183     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
184     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
185 {
186   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
187   return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
188 }
189 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
190 {
191   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
192   return LinePtr(new SketchAPI_Line(aFeature, theExternal));
193 }
194 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
195 {
196   // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
197   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
198   return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
199 }
200
201 //--------------------------------------------------------------------------------------
202 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
203                                                               double theCenterY,
204                                                               double theRadius)
205 {
206   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
207   return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
208 }
209
210 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
211                                                               double theRadius)
212 {
213   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
214   return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
215 }
216
217 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
218                                                               double theX2, double theY2,
219                                                               double theX3, double theY3)
220 {
221   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
222   return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
223 }
224
225 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
226                                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
227                                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
228 {
229   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
230   return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
231 }
232
233 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
234 {
235   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
236   return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
237 }
238
239 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
240 {
241   // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
242   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
243   return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
244 }
245
246 //--------------------------------------------------------------------------------------
247 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
248                                                         double theStartX, double theStartY,
249                                                         double theEndX, double theEndY,
250                                                         bool theInversed)
251 {
252   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
253   return ArcPtr(new SketchAPI_Arc(aFeature,
254                                   theCenterX, theCenterY,
255                                   theStartX, theStartY,
256                                   theEndX, theEndY,
257                                   theInversed));
258 }
259
260 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
261                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
262                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
263                                                         bool theInversed)
264 {
265   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
266   return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
267 }
268
269 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
270                                                         double theEndX, double theEndY,
271                                                         double thePassedX, double thePassedY)
272 {
273   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
274   return ArcPtr(new SketchAPI_Arc(aFeature,
275                                   theStartX, theStartY,
276                                   theEndX, theEndY,
277                                   thePassedX, thePassedY));
278 }
279
280 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
281                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
282                                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
283 {
284   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
285   return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
286 }
287
288 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
289                                                         double theEndX, double theEndY,
290                                                         bool theInversed)
291 {
292   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
293   return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
294 }
295
296 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
297                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
298                                                         bool theInversed)
299 {
300   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
301   return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
302 }
303
304 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
305 {
306   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
307   return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
308 }
309
310 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
311 {
312   // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
313   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
314   return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
315 }
316
317 //--------------------------------------------------------------------------------------
318 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
319     const ModelHighAPI_RefAttr & theMirrorLine,
320     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
321 {
322   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
323   return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
324 }
325
326 //--------------------------------------------------------------------------------------
327 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
328     const ModelHighAPI_RefAttr & theLine1,
329     const ModelHighAPI_RefAttr & theLine2,
330     const ModelHighAPI_Double & theValue)
331 {
332   // TODO(spo): is support of angle type necessary?
333   std::shared_ptr<ModelAPI_Feature> aFeature =
334       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
335   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
336   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
337   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
338   aFeature->execute();
339   return aFeature;
340 }
341
342 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
343     const ModelHighAPI_RefAttr & thePoint1,
344     const ModelHighAPI_RefAttr & thePoint2)
345 {
346   std::shared_ptr<ModelAPI_Feature> aFeature =
347       compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
348   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
349   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
350   aFeature->execute();
351   return aFeature;
352 }
353
354 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCollinear(
355     const ModelHighAPI_RefAttr & theLine1,
356     const ModelHighAPI_RefAttr & theLine2)
357 {
358   std::shared_ptr<ModelAPI_Feature> aFeature =
359       compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
360   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
361   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
362   aFeature->execute();
363   return aFeature;
364 }
365
366 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
367     const ModelHighAPI_RefAttr & thePoint,
368     const ModelHighAPI_RefAttr & thePointOrLine,
369     const ModelHighAPI_Double & theValue)
370 {
371   std::shared_ptr<ModelAPI_Feature> aFeature =
372       compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
373   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
374   fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
375   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
376   aFeature->execute();
377   return aFeature;
378 }
379
380 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setEqual(
381     const ModelHighAPI_RefAttr & theObject1,
382     const ModelHighAPI_RefAttr & theObject2)
383 {
384   std::shared_ptr<ModelAPI_Feature> aFeature =
385       compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
386   fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
387   fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
388   aFeature->execute();
389   return aFeature;
390 }
391
392 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFillet(
393     const std::list<ModelHighAPI_RefAttr> & thePoints,
394     const ModelHighAPI_Double & theRadius)
395 {
396   std::shared_ptr<ModelAPI_Feature> aFeature =
397       compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
398   fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
399   fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
400   aFeature->execute();
401   return aFeature;
402 }
403
404 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setHorizontal(
405     const ModelHighAPI_RefAttr & theLine)
406 {
407   std::shared_ptr<ModelAPI_Feature> aFeature =
408       compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
409   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
410   aFeature->execute();
411   return aFeature;
412 }
413
414 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
415     const ModelHighAPI_RefAttr & theLine,
416     const ModelHighAPI_Double & theValue)
417 {
418   std::shared_ptr<ModelAPI_Feature> aFeature =
419       compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
420   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
421   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
422   aFeature->execute();
423   return aFeature;
424 }
425
426 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setMiddlePoint(
427     const ModelHighAPI_RefAttr & thePoint,
428     const ModelHighAPI_RefAttr & theLine)
429 {
430   std::shared_ptr<ModelAPI_Feature> aFeature =
431       compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
432   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
433   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
434   aFeature->execute();
435   return aFeature;
436 }
437
438 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
439     const ModelHighAPI_RefAttr & theLine1,
440     const ModelHighAPI_RefAttr & theLine2)
441 {
442   std::shared_ptr<ModelAPI_Feature> aFeature =
443       compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
444   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
445   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
446   aFeature->execute();
447   return aFeature;
448 }
449
450 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
451     const ModelHighAPI_RefAttr & theLine1,
452     const ModelHighAPI_RefAttr & theLine2)
453 {
454   std::shared_ptr<ModelAPI_Feature> aFeature =
455       compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
456   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
457   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
458   aFeature->execute();
459   return aFeature;
460 }
461
462 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRadius(
463     const ModelHighAPI_RefAttr & theCircleOrArc,
464     const ModelHighAPI_Double & theValue)
465 {
466   std::shared_ptr<ModelAPI_Feature> aFeature =
467       compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
468   fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
469   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
470   aFeature->execute();
471   return aFeature;
472 }
473
474 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRigid(
475     const ModelHighAPI_RefAttr & theObject)
476 {
477   // TODO(spo): should it be renamed to Fixed?
478   std::shared_ptr<ModelAPI_Feature> aFeature =
479       compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
480   fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
481   aFeature->execute();
482   return aFeature;
483 }
484
485 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setTangent(
486     const ModelHighAPI_RefAttr & theLine,
487     const ModelHighAPI_RefAttr & theCircle)
488 {
489   std::shared_ptr<ModelAPI_Feature> aFeature =
490       compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
491   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
492   fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
493   aFeature->execute();
494   return aFeature;
495 }
496
497 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setVertical(
498     const ModelHighAPI_RefAttr & theLine)
499 {
500   std::shared_ptr<ModelAPI_Feature> aFeature =
501       compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
502   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
503   aFeature->execute();
504   return aFeature;
505 }
506
507 //--------------------------------------------------------------------------------------