]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Sketch.cpp
Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API. Debug of unit...
[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 #include <SketcherPrs_Tools.h>
28 //--------------------------------------------------------------------------------------
29 #include <ModelAPI_CompositeFeature.h>
30 #include <ModelAPI_ResultConstruction.h>
31 #include <ModelHighAPI_Dumper.h>
32 #include <ModelHighAPI_RefAttr.h>
33 #include <ModelHighAPI_Selection.h>
34 #include <ModelHighAPI_Services.h>
35 #include <ModelHighAPI_Tools.h>
36 //--------------------------------------------------------------------------------------
37 #include "SketchAPI_Arc.h"
38 #include "SketchAPI_Circle.h"
39 #include "SketchAPI_IntersectionPoint.h"
40 #include "SketchAPI_Line.h"
41 #include "SketchAPI_Mirror.h"
42 #include "SketchAPI_Point.h"
43 #include "SketchAPI_Projection.h"
44 #include "SketchAPI_Rectangle.h"
45 #include "SketchAPI_Rotation.h"
46 #include "SketchAPI_Translation.h"
47 //--------------------------------------------------------------------------------------
48 SketchAPI_Sketch::SketchAPI_Sketch(
49     const std::shared_ptr<ModelAPI_Feature> & theFeature)
50 : ModelHighAPI_Interface(theFeature)
51 {
52   initialize();
53 }
54
55 SketchAPI_Sketch::SketchAPI_Sketch(
56     const std::shared_ptr<ModelAPI_Feature> & theFeature,
57     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
58 : ModelHighAPI_Interface(theFeature)
59 {
60   if (initialize()) {
61     setPlane(thePlane);
62   }
63 }
64
65 SketchAPI_Sketch::SketchAPI_Sketch(
66     const std::shared_ptr<ModelAPI_Feature> & theFeature,
67     const ModelHighAPI_Selection & theExternal)
68 : ModelHighAPI_Interface(theFeature)
69 {
70   if (initialize()) {
71     setExternal(theExternal);
72   }
73 }
74
75 SketchAPI_Sketch::SketchAPI_Sketch(
76     const std::shared_ptr<ModelAPI_Feature> & theFeature,
77     std::shared_ptr<ModelAPI_Object> thePlaneObject)
78 : ModelHighAPI_Interface(theFeature)
79 {
80   if (initialize()) {
81     setExternal(thePlaneObject);
82   }
83 }
84
85 SketchAPI_Sketch::~SketchAPI_Sketch()
86 {
87
88 }
89
90 //--------------------------------------------------------------------------------------
91 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
92 {
93   return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
94 }
95
96 //--------------------------------------------------------------------------------------
97 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
98 {
99   fillAttribute(thePlane->origin(), myorigin);
100   fillAttribute(thePlane->dirX(), mydirX);
101   fillAttribute(thePlane->normal(), mynormal);
102
103   execute();
104 }
105
106 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
107 {
108   fillAttribute(theExternal, myexternal);
109
110   execute();
111 }
112
113 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
114 {
115   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
116   ModelHighAPI_Selection aSel(aRes);
117   setExternal(aSel);
118 }
119
120 //--------------------------------------------------------------------------------------
121 void SketchAPI_Sketch::setValue(
122     const std::shared_ptr<ModelAPI_Feature> & theConstraint,
123     const ModelHighAPI_Double & theValue)
124 {
125   // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
126   fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
127
128 //  theConstraint->execute();
129 }
130
131 //--------------------------------------------------------------------------------------
132 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
133 {
134   const_cast<SketchAPI_Sketch*>(this)->execute();
135
136   std::list<ModelHighAPI_Selection> aSelectionList;
137
138   ResultConstructionPtr aResultConstruction =
139       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
140   if (aResultConstruction.get() == NULL)
141     return aSelectionList;
142
143   for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
144     aSelectionList.push_back(
145         ModelHighAPI_Selection(aResultConstruction,
146                                aResultConstruction->face(anIndex)));
147   }
148
149   return aSelectionList;
150 }
151
152 //--------------------------------------------------------------------------------------
153 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
154                     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
155 {
156   // TODO(spo): check that thePart is not empty
157   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
158   return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
159 }
160
161 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
162                     const ModelHighAPI_Selection & theExternal)
163 {
164   // TODO(spo): check that thePart is not empty
165   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
166   return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
167 }
168
169 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
170                     const std::string & theExternalName)
171 {
172   // TODO(spo): check that thePart is not empty
173   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
174   return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
175 }
176
177 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
178                     std::shared_ptr<ModelAPI_Object> thePlaneObject)
179 {
180   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
181   return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
182 }
183
184
185 //--------------------------------------------------------------------------------------
186 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
187     double theX, double theY)
188 {
189   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
190   return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
191 }
192 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
193     const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
194 {
195   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
196   return PointPtr(new SketchAPI_Point(aFeature, thePoint));
197 }
198 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
199 {
200   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
201   return PointPtr(new SketchAPI_Point(aFeature, theExternal));
202 }
203 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
204 {
205   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
206   return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
207 }
208
209 //--------------------------------------------------------------------------------------
210 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
211     const ModelHighAPI_Selection & theExternal)
212 {
213   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
214   return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
215 }
216 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
217     const std::string & theExternalName)
218 {
219   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
220   return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
221 }
222
223 //--------------------------------------------------------------------------------------
224 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
225 {
226   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
227   return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
228 }
229 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
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(SketchPlugin_Line::ID());
234   return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
235 }
236 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
237 {
238   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
239   LinePtr aLine(new SketchAPI_Line(aFeature, theExternal));
240   setFixed(InterfacePtr(aLine));
241   return aLine;
242 }
243 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
244 {
245   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
246   LinePtr aLine(new SketchAPI_Line(aFeature, theExternalName));
247   setFixed(InterfacePtr(aLine));
248   return aLine;
249 }
250
251 //--------------------------------------------------------------------------------------
252 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
253 {
254   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
255   return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
256 }
257 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
258     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
259     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
260 {
261   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
262   return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
263 }
264
265 //--------------------------------------------------------------------------------------
266 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
267                                                               double theCenterY,
268                                                               double theRadius)
269 {
270   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
271   return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
272 }
273
274 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
275                                                               double theRadius)
276 {
277   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
278   return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
279 }
280
281 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
282                                                               double theX2, double theY2,
283                                                               double theX3, double theY3)
284 {
285   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
286   return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
287 }
288
289 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
290                                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
291                                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
292 {
293   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
294   return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
295 }
296
297 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
298 {
299   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
300   return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
301 }
302
303 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
304 {
305   // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
306   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
307   return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
308 }
309
310 //--------------------------------------------------------------------------------------
311 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
312                                                         double theStartX, double theStartY,
313                                                         double theEndX, double theEndY,
314                                                         bool theInversed)
315 {
316   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
317   return ArcPtr(new SketchAPI_Arc(aFeature,
318                                   theCenterX, theCenterY,
319                                   theStartX, theStartY,
320                                   theEndX, theEndY,
321                                   theInversed));
322 }
323
324 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
325                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
326                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
327                                                         bool theInversed)
328 {
329   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
330   return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
331 }
332
333 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
334                                                         double theEndX, double theEndY,
335                                                         double thePassedX, double thePassedY)
336 {
337   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
338   return ArcPtr(new SketchAPI_Arc(aFeature,
339                                   theStartX, theStartY,
340                                   theEndX, theEndY,
341                                   thePassedX, thePassedY));
342 }
343
344 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
345                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
346                                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
347 {
348   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
349   return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
350 }
351
352 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
353                                                         double theEndX, double theEndY,
354                                                         bool theInversed)
355 {
356   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
357   return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
358 }
359
360 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
361                                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
362                                                         bool theInversed)
363 {
364   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
365   return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
366 }
367
368 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
369 {
370   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
371   return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
372 }
373
374 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
375 {
376   // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
377   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
378   return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
379 }
380
381 //--------------------------------------------------------------------------------------
382 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
383     const ModelHighAPI_Selection & theExternalFeature)
384 {
385   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
386   return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
387 }
388
389 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
390     const std::string & theExternalName)
391 {
392   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
393   return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
394 }
395
396 //--------------------------------------------------------------------------------------
397 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
398     const ModelHighAPI_RefAttr & theMirrorLine,
399     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
400 {
401   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
402   return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
403 }
404
405 //--------------------------------------------------------------------------------------
406 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
407     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
408     const ModelHighAPI_RefAttr & thePoint1,
409     const ModelHighAPI_RefAttr & thePoint2,
410     const ModelHighAPI_Integer & theNumberOfObjects,
411     bool theFullValue)
412 {
413   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
414   return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1, thePoint2, theNumberOfObjects, theFullValue));
415 }
416
417 //--------------------------------------------------------------------------------------
418 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
419     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
420     const ModelHighAPI_RefAttr & theCenter,
421     const ModelHighAPI_Double & theAngle,
422     const ModelHighAPI_Integer & theNumberOfObjects,
423     bool theFullValue)
424 {
425   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
426   return RotationPtr(new SketchAPI_Rotation(aFeature, theObjects, theCenter, theAngle, theNumberOfObjects, theFullValue));
427 }
428
429 //--------------------------------------------------------------------------------------
430 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
431     const ModelHighAPI_RefAttr & theLine1,
432     const ModelHighAPI_RefAttr & theLine2,
433     const ModelHighAPI_Double & theValue)
434 {
435   std::shared_ptr<ModelAPI_Feature> aFeature =
436       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
437   fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
438       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
439   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
440   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
441   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
442   aFeature->execute();
443   return aFeature;
444 }
445
446 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleComplementary(
447     const ModelHighAPI_RefAttr & theLine1,
448     const ModelHighAPI_RefAttr & theLine2,
449     const ModelHighAPI_Double & theValue)
450 {
451   std::shared_ptr<ModelAPI_Feature> aFeature =
452       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
453   fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
454       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
455   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
456   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
457   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
458 //  fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
459   aFeature->execute();
460   return aFeature;
461 }
462
463 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleBackward(
464     const ModelHighAPI_RefAttr & theLine1,
465     const ModelHighAPI_RefAttr & theLine2,
466     const ModelHighAPI_Double & theValue)
467 {
468   std::shared_ptr<ModelAPI_Feature> aFeature =
469       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
470   fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
471       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
472   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
473   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
474   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
475 //  fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
476   aFeature->execute();
477   return aFeature;
478 }
479
480 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
481     const ModelHighAPI_RefAttr & thePoint1,
482     const ModelHighAPI_RefAttr & thePoint2)
483 {
484   std::shared_ptr<ModelAPI_Feature> aFeature =
485       compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
486   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
487   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
488   aFeature->execute();
489   return aFeature;
490 }
491
492 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCollinear(
493     const ModelHighAPI_RefAttr & theLine1,
494     const ModelHighAPI_RefAttr & theLine2)
495 {
496   std::shared_ptr<ModelAPI_Feature> aFeature =
497       compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
498   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
499   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
500   aFeature->execute();
501   return aFeature;
502 }
503
504 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
505     const ModelHighAPI_RefAttr & thePoint,
506     const ModelHighAPI_RefAttr & thePointOrLine,
507     const ModelHighAPI_Double & theValue)
508 {
509   std::shared_ptr<ModelAPI_Feature> aFeature =
510       compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
511   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
512   fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
513   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
514   aFeature->execute();
515   return aFeature;
516 }
517
518 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setEqual(
519     const ModelHighAPI_RefAttr & theObject1,
520     const ModelHighAPI_RefAttr & theObject2)
521 {
522   std::shared_ptr<ModelAPI_Feature> aFeature =
523       compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
524   fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
525   fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
526   aFeature->execute();
527   return aFeature;
528 }
529
530 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFillet(
531     const std::list<ModelHighAPI_RefAttr> & thePoints,
532     const ModelHighAPI_Double & theRadius)
533 {
534   std::shared_ptr<ModelAPI_Feature> aFeature =
535       compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
536   fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
537   fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
538   aFeature->execute();
539   return aFeature;
540 }
541
542 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFixed(
543     const ModelHighAPI_RefAttr & theObject)
544 {
545   std::shared_ptr<ModelAPI_Feature> aFeature =
546       compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
547   fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
548   aFeature->execute();
549   return aFeature;
550 }
551
552 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setHorizontal(
553     const ModelHighAPI_RefAttr & theLine)
554 {
555   std::shared_ptr<ModelAPI_Feature> aFeature =
556       compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
557   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
558   aFeature->execute();
559   return aFeature;
560 }
561
562 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
563     const ModelHighAPI_RefAttr & theLine,
564     const ModelHighAPI_Double & theValue)
565 {
566   std::shared_ptr<ModelAPI_Feature> aFeature =
567       compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
568   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
569   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
570   aFeature->execute();
571   return aFeature;
572 }
573
574 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setMiddlePoint(
575     const ModelHighAPI_RefAttr & thePoint,
576     const ModelHighAPI_RefAttr & theLine)
577 {
578   std::shared_ptr<ModelAPI_Feature> aFeature =
579       compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
580   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
581   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
582   aFeature->execute();
583   return aFeature;
584 }
585
586 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
587     const ModelHighAPI_RefAttr & theLine1,
588     const ModelHighAPI_RefAttr & theLine2)
589 {
590   std::shared_ptr<ModelAPI_Feature> aFeature =
591       compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
592   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
593   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
594   aFeature->execute();
595   return aFeature;
596 }
597
598 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
599     const ModelHighAPI_RefAttr & theLine1,
600     const ModelHighAPI_RefAttr & theLine2)
601 {
602   std::shared_ptr<ModelAPI_Feature> aFeature =
603       compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
604   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
605   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
606   aFeature->execute();
607   return aFeature;
608 }
609
610 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRadius(
611     const ModelHighAPI_RefAttr & theCircleOrArc,
612     const ModelHighAPI_Double & theValue)
613 {
614   std::shared_ptr<ModelAPI_Feature> aFeature =
615       compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
616   fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
617   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
618   aFeature->execute();
619   return aFeature;
620 }
621
622 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setTangent(
623     const ModelHighAPI_RefAttr & theLine,
624     const ModelHighAPI_RefAttr & theCircle)
625 {
626   std::shared_ptr<ModelAPI_Feature> aFeature =
627       compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
628   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
629   fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
630   aFeature->execute();
631   return aFeature;
632 }
633
634 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setVertical(
635     const ModelHighAPI_RefAttr & theLine)
636 {
637   std::shared_ptr<ModelAPI_Feature> aFeature =
638       compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
639   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
640   aFeature->execute();
641   return aFeature;
642 }
643
644 //--------------------------------------------------------------------------------------
645
646 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
647 {
648   FeaturePtr aBase = feature();
649   const std::string& aDocName = theDumper.name(aBase->document());
650
651   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
652   if (anExternal->value()) {
653     theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal << ")" << std::endl;
654   } else {
655     // Sketch is base on a plane.
656     std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
657         aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
658     std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
659         aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
660     std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
661         aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
662
663     // Check the plane is coordinate plane
664     std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
665     if (anExternal->context()) { // checking for selected planes
666       if (!aPlaneName.empty()) {
667         // dump sketch based on coordinate plane
668         theDumper << aBase << " = model.addSketch(" << aDocName
669                   << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
670       } else { // some other plane
671         theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal<< ")" << std::endl;
672       }
673     } else {
674       if (aPlaneName.empty()) {
675         // needs import additional module
676         theDumper.importModule("GeomAPI");
677         // dump plane parameters
678         const std::string& aSketchName = theDumper.name(aBase);
679         std::string anOriginName = aSketchName + "_origin";
680         std::string aNormalName  = aSketchName + "_norm";
681         std::string aDirXName    = aSketchName + "_dirx";
682         theDumper << anOriginName << " = " << anOrigin << std::endl
683                   << aNormalName  << " = " << aNormal  << std::endl
684                   << aDirXName    << " = " << aDirX    << std::endl;
685         // dump sketch based on arbitrary plane
686         theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
687                   << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
688       } else {
689         // dump sketch based on coordinate plane
690         theDumper << aBase << " = model.addSketch(" << aDocName
691                   << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
692       }
693     }
694   }
695
696   // dump sketch's subfeatures
697   CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
698   theDumper.processSubs(aCompFeat, true);
699 }