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