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