Salome HOME
Merge remote-tracking branch 'origin/CEA_2019'
[modules/shaper.git] / src / SketchAPI / SketchAPI_Sketch.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SketchAPI_Sketch.h"
21 //--------------------------------------------------------------------------------------
22 #include <SketchPlugin_Constraint.h>
23 #include <SketchPlugin_ConstraintAngle.h>
24 #include <SketchPlugin_ConstraintCoincidence.h>
25 #include <SketchPlugin_ConstraintCollinear.h>
26 #include <SketchPlugin_ConstraintDistance.h>
27 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
28 #include <SketchPlugin_ConstraintDistanceVertical.h>
29 #include <SketchPlugin_ConstraintEqual.h>
30 #include <SketchPlugin_Fillet.h>
31 #include <SketchPlugin_ConstraintHorizontal.h>
32 #include <SketchPlugin_ConstraintLength.h>
33 #include <SketchPlugin_ConstraintMiddle.h>
34 #include <SketchPlugin_ConstraintMirror.h>
35 #include <SketchPlugin_ConstraintParallel.h>
36 #include <SketchPlugin_ConstraintPerpendicular.h>
37 #include <SketchPlugin_ConstraintRadius.h>
38 #include <SketchPlugin_ConstraintRigid.h>
39 #include <SketchPlugin_Trim.h>
40 #include <SketchPlugin_Split.h>
41 #include <SketchPlugin_ConstraintTangent.h>
42 #include <SketchPlugin_ConstraintVertical.h>
43 #include <SketcherPrs_Tools.h>
44 //--------------------------------------------------------------------------------------
45 #include <ModelAPI_Events.h>
46 #include <ModelAPI_CompositeFeature.h>
47 #include <ModelAPI_ResultConstruction.h>
48 #include <ModelHighAPI_Double.h>
49 #include <ModelHighAPI_Dumper.h>
50 #include <ModelHighAPI_RefAttr.h>
51 #include <ModelHighAPI_Selection.h>
52 #include <ModelHighAPI_Services.h>
53 #include <ModelHighAPI_Tools.h>
54 //--------------------------------------------------------------------------------------
55 #include "SketchAPI_Arc.h"
56 #include "SketchAPI_Circle.h"
57 #include "SketchAPI_Ellipse.h"
58 #include "SketchAPI_EllipticArc.h"
59 #include "SketchAPI_IntersectionPoint.h"
60 #include "SketchAPI_Line.h"
61 #include "SketchAPI_MacroArc.h"
62 #include "SketchAPI_MacroCircle.h"
63 #include "SketchAPI_MacroEllipse.h"
64 #include "SketchAPI_MacroEllipticArc.h"
65 #include "SketchAPI_Mirror.h"
66 #include "SketchAPI_Point.h"
67 #include "SketchAPI_Projection.h"
68 #include "SketchAPI_Rectangle.h"
69 #include "SketchAPI_Rotation.h"
70 #include "SketchAPI_Translation.h"
71 //--------------------------------------------------------------------------------------
72 #include <GeomAPI_Curve.h>
73 #include <GeomAPI_Dir2d.h>
74 #include <GeomAPI_PlanarEdges.h>
75 #include <GeomAPI_ShapeExplorer.h>
76 #include <GeomAPI_XY.h>
77 #include <GeomAlgoAPI_SketchBuilder.h>
78 #include <cmath>
79 //--------------------------------------------------------------------------------------
80 SketchAPI_Sketch::SketchAPI_Sketch(
81     const std::shared_ptr<ModelAPI_Feature> & theFeature)
82 : ModelHighAPI_Interface(theFeature)
83 {
84   initialize();
85 }
86
87 SketchAPI_Sketch::SketchAPI_Sketch(
88     const std::shared_ptr<ModelAPI_Feature> & theFeature,
89     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
90 : ModelHighAPI_Interface(theFeature)
91 {
92   if (initialize()) {
93     setPlane(thePlane);
94   }
95 }
96
97 SketchAPI_Sketch::SketchAPI_Sketch(
98     const std::shared_ptr<ModelAPI_Feature> & theFeature,
99     const ModelHighAPI_Selection & theExternal)
100 : ModelHighAPI_Interface(theFeature)
101 {
102   if (initialize()) {
103     setExternal(theExternal);
104   }
105 }
106
107 SketchAPI_Sketch::SketchAPI_Sketch(
108     const std::shared_ptr<ModelAPI_Feature> & theFeature,
109     std::shared_ptr<ModelAPI_Object> thePlaneObject)
110 : ModelHighAPI_Interface(theFeature)
111 {
112   if (initialize()) {
113     setExternal(thePlaneObject);
114   }
115 }
116
117 SketchAPI_Sketch::~SketchAPI_Sketch()
118 {
119
120 }
121
122 //--------------------------------------------------------------------------------------
123 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
124 {
125   return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
126 }
127
128 //--------------------------------------------------------------------------------------
129 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
130 {
131   fillAttribute(thePlane->origin(), myorigin);
132   fillAttribute(thePlane->dirX(), mydirX);
133   fillAttribute(thePlane->normal(), mynormal);
134
135   execute();
136 }
137
138 void SketchAPI_Sketch::setPlane(const ModelHighAPI_Selection & thePlane,
139                                 bool theRemoveExternalDependency)
140 {
141   FeaturePtr aSketch = feature();
142
143   DocumentPtr aDoc = aSketch->document();
144   bool useVisible = false;
145   FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
146   aDoc->setCurrentFeature(aSketch, useVisible);
147
148   if (theRemoveExternalDependency)
149     aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
150
151   setExternal(thePlane);
152
153   aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
154 }
155
156 //--------------------------------------------------------------------------------------
157 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
158 {
159   fillAttribute(theExternal, myexternal);
160
161   execute();
162 }
163
164 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
165 {
166   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
167   ModelHighAPI_Selection aSel(aRes);
168   setExternal(aSel);
169 }
170
171 //--------------------------------------------------------------------------------------
172 void SketchAPI_Sketch::setValue(
173     const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
174     const ModelHighAPI_Double & theValue)
175 {
176   fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
177
178 //  theConstraint->execute();
179 }
180
181 //--------------------------------------------------------------------------------------
182 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
183 {
184   const_cast<SketchAPI_Sketch*>(this)->execute();
185
186   std::list<ModelHighAPI_Selection> aSelectionList;
187
188   ResultConstructionPtr aResultConstruction =
189       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
190   if (aResultConstruction.get() == NULL)
191     return aSelectionList;
192
193   for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
194     aSelectionList.push_back(
195         ModelHighAPI_Selection(aResultConstruction,
196                                aResultConstruction->face(anIndex)));
197   }
198
199   return aSelectionList;
200 }
201
202 //--------------------------------------------------------------------------------------
203 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
204                     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
205 {
206   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
207   return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
208 }
209
210 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
211                     const ModelHighAPI_Selection & theExternal)
212 {
213   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
214   return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
215 }
216
217 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
218                     const std::string & theExternalName)
219 {
220   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
221   return SketchPtr(
222     new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
223 }
224
225 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
226                     std::shared_ptr<ModelAPI_Object> thePlaneObject)
227 {
228   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
229   return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
230 }
231
232
233 //--------------------------------------------------------------------------------------
234 std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
235 {
236   std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
237   std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
238   for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
239     FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
240     PointPtr aPoint(new SketchAPI_Point(aFeature));
241     aFreePoints.push_back(aPoint);
242   }
243   return aFreePoints;
244 }
245
246 //--------------------------------------------------------------------------------------
247 static GeomCurvePtr untrimmedCurve(GeomShapePtr theShape)
248 {
249   GeomCurvePtr aCurve(new GeomAPI_Curve(theShape));
250   if (aCurve->isTrimmed())
251     aCurve = aCurve->basisCurve();
252   return aCurve;
253 }
254
255 void SketchAPI_Sketch::changeFacesOrder(
256     const std::list<std::list<ModelHighAPI_Selection> >& theFaces)
257 {
258   // collect faces of the sketch
259   ResultConstructionPtr aSketchResult =
260       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
261   if (!aSketchResult) {
262     // sketch is nested to a boolean operation, thus, it has no result yet.
263     feature()->execute();
264     aSketchResult =
265         std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
266   }
267   std::list<GeomFacePtr> aFaces;
268   int aFacesNum = aSketchResult->facesNum();
269   for (int i = 0; i < aFacesNum; ++i)
270     aFaces.push_back(aSketchResult->face(i));
271   // find new faces order according to the given lists of edges
272   std::list<GeomFacePtr> aNewFacesOrder;
273   std::list<std::list<ModelHighAPI_Selection> >::const_iterator anIt = theFaces.begin();
274   for (; anIt != theFaces.end(); ++anIt) {
275     // find the appropriate face
276     std::list<GeomFacePtr>::iterator aFIt = aFaces.begin();
277     for (; aFIt != aFaces.end(); ++aFIt) {
278       std::list<ModelHighAPI_Selection>::const_iterator aEdgeIt = anIt->begin();
279       GeomAPI_ShapeExplorer aFExp(*aFIt, GeomAPI_Shape::EDGE);
280       for (; aEdgeIt != anIt->end() && aFExp.more(); ++aEdgeIt, aFExp.next()) {
281         ResultPtr aCurRes = aEdgeIt->resultSubShapePair().first;
282         if (!aCurRes)
283           break;
284         GeomCurvePtr aCurve1 = untrimmedCurve(aCurRes->shape());
285         GeomCurvePtr aCurve2 = untrimmedCurve(aFExp.current());
286         if (!aCurve1->isEqual(aCurve2))
287           break;
288       }
289
290       if (aEdgeIt == anIt->end() && !aFExp.more()) {
291         // face is found
292         aNewFacesOrder.push_back(*aFIt);
293         aFaces.erase(aFIt);
294         break;
295       }
296     }
297   }
298   // place the rest faces at the end of new faces list
299   if (!aFaces.empty())
300     aNewFacesOrder.insert(aNewFacesOrder.end(), aFaces.begin(), aFaces.end());
301   // update the result of the sketch with the new order of faces
302   aSketchResult->setFacesOrder(aNewFacesOrder);
303 }
304
305 //--------------------------------------------------------------------------------------
306 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
307     double theX, double theY)
308 {
309   std::shared_ptr<ModelAPI_Feature> aFeature =
310     compositeFeature()->addFeature(SketchPlugin_Point::ID());
311   return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
312 }
313 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
314     const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
315 {
316   std::shared_ptr<ModelAPI_Feature> aFeature =
317     compositeFeature()->addFeature(SketchPlugin_Point::ID());
318   return PointPtr(new SketchAPI_Point(aFeature, thePoint));
319 }
320 std::shared_ptr<SketchAPI_Point>
321   SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
322 {
323   std::shared_ptr<ModelAPI_Feature> aFeature =
324     compositeFeature()->addFeature(SketchPlugin_Point::ID());
325   return PointPtr(new SketchAPI_Point(aFeature, theExternal));
326 }
327 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
328 {
329   std::shared_ptr<ModelAPI_Feature> aFeature =
330     compositeFeature()->addFeature(SketchPlugin_Point::ID());
331   return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
332 }
333
334 //--------------------------------------------------------------------------------------
335 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
336     const ModelHighAPI_Selection & theExternal,
337     bool theKeepResult)
338 {
339   std::shared_ptr<ModelAPI_Feature> aFeature =
340     compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
341   IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
342   anIntersection->setIncludeToResult(theKeepResult);
343   return anIntersection;
344 }
345 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
346     const std::string & theExternalName,
347     bool theKeepResult)
348 {
349   std::shared_ptr<ModelAPI_Feature> aFeature =
350     compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
351   IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
352   anIntersection->setIncludeToResult(theKeepResult);
353   return anIntersection;
354 }
355
356 //--------------------------------------------------------------------------------------
357 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
358                                                           double theX2, double theY2)
359 {
360   std::shared_ptr<ModelAPI_Feature> aFeature =
361     compositeFeature()->addFeature(SketchPlugin_Line::ID());
362   return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
363 }
364 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
365     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
366     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
367 {
368   std::shared_ptr<ModelAPI_Feature> aFeature =
369     compositeFeature()->addFeature(SketchPlugin_Line::ID());
370   return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
371 }
372 std::shared_ptr<SketchAPI_Line>
373   SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
374 {
375   std::shared_ptr<ModelAPI_Feature> aFeature =
376     compositeFeature()->addFeature(SketchPlugin_Line::ID());
377   return LinePtr(new SketchAPI_Line(aFeature, theExternal));
378 }
379 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
380 {
381   std::shared_ptr<ModelAPI_Feature> aFeature =
382     compositeFeature()->addFeature(SketchPlugin_Line::ID());
383   return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
384 }
385
386 //--------------------------------------------------------------------------------------
387 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
388                                                                     double theX2, double theY2)
389 {
390   std::shared_ptr<ModelAPI_Feature> aFeature =
391     compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
392   return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
393 }
394 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
395     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
396     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
397 {
398   std::shared_ptr<ModelAPI_Feature> aFeature =
399     compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
400   return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
401 }
402
403 //--------------------------------------------------------------------------------------
404 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
405                                                               double theCenterY,
406                                                               double theRadius)
407 {
408   std::shared_ptr<ModelAPI_Feature> aFeature =
409     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
410   return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
411 }
412
413 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
414                                     const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
415                                     double theRadius)
416 {
417   std::shared_ptr<ModelAPI_Feature> aFeature =
418     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
419   return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
420 }
421
422 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
423                                                                    double theCenterY,
424                                                                    double thePassedX,
425                                                                    double thePassedY)
426 {
427   std::shared_ptr<ModelAPI_Feature> aFeature =
428     compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
429   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
430                                                             thePassedX, thePassedY));
431 }
432
433 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
434     const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
435     const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
436 {
437   std::shared_ptr<ModelAPI_Feature> aFeature =
438     compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
439   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
440 }
441
442 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
443                                                                    double theX2, double theY2,
444                                                                    double theX3, double theY3)
445 {
446   std::shared_ptr<ModelAPI_Feature> aFeature =
447     compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
448   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
449                                                             theX2, theY2,
450                                                             theX3, theY3));
451 }
452
453 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
454     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
455     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
456     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
457 {
458   std::shared_ptr<ModelAPI_Feature> aFeature =
459     compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
460   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
461 }
462
463 std::shared_ptr<SketchAPI_Circle>
464   SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
465 {
466   std::shared_ptr<ModelAPI_Feature> aFeature =
467     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
468   return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
469 }
470
471 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
472 {
473   std::shared_ptr<ModelAPI_Feature> aFeature =
474     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
475   return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
476 }
477
478 //--------------------------------------------------------------------------------------
479 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
480                                                         double theStartX, double theStartY,
481                                                         double theEndX, double theEndY,
482                                                         bool theInversed)
483 {
484   std::shared_ptr<ModelAPI_Feature> aFeature =
485     compositeFeature()->addFeature(SketchPlugin_Arc::ID());
486   return ArcPtr(new SketchAPI_Arc(aFeature,
487                                   theCenterX, theCenterY,
488                                   theStartX, theStartY,
489                                   theEndX, theEndY,
490                                   theInversed));
491 }
492
493 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
494                                               const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
495                                               const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
496                                               const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
497                                               bool theInversed)
498 {
499   std::shared_ptr<ModelAPI_Feature> aFeature =
500     compositeFeature()->addFeature(SketchPlugin_Arc::ID());
501   return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
502 }
503
504 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
505                                                         double theEndX, double theEndY,
506                                                         double thePassedX, double thePassedY)
507 {
508   std::shared_ptr<ModelAPI_Feature> aFeature =
509     compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
510   return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
511                                        theStartX, theStartY,
512                                        theEndX, theEndY,
513                                        thePassedX, thePassedY));
514 }
515
516 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
517                                                 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
518                                                 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
519                                                 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
520 {
521   std::shared_ptr<ModelAPI_Feature> aFeature =
522     compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
523   return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
524 }
525
526 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
527                                                 const ModelHighAPI_RefAttr& theTangentPoint,
528                                                 double theEndX, double theEndY,
529                                                 bool theInversed,
530                                                 bool theTransversal)
531 {
532   std::shared_ptr<ModelAPI_Feature> aFeature =
533     compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
534   MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
535   if (theTransversal)
536     aMacroArc->setByTransversal(theTangentPoint, theEndX, theEndY, theInversed);
537   else
538     aMacroArc->setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
539   return aMacroArc;
540 }
541
542 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
543                                               const ModelHighAPI_RefAttr& theTangentPoint,
544                                               const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
545                                               bool theInversed,
546                                               bool theTransversal)
547 {
548   std::shared_ptr<ModelAPI_Feature> aFeature =
549     compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
550   MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
551   if (theTransversal)
552     aMacroArc->setByTransversal(theTangentPoint, theEnd, theInversed);
553   else
554     aMacroArc->setByTangent(theTangentPoint, theEnd, theInversed);
555   return aMacroArc;
556 }
557
558 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
559 {
560   std::shared_ptr<ModelAPI_Feature> aFeature =
561     compositeFeature()->addFeature(SketchPlugin_Arc::ID());
562   return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
563 }
564
565 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
566 {
567   std::shared_ptr<ModelAPI_Feature> aFeature =
568     compositeFeature()->addFeature(SketchPlugin_Arc::ID());
569   return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
570 }
571
572 //--------------------------------------------------------------------------------------
573 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
574     double theCenterX, double theCenterY,
575     double theFocusX, double theFocusY,
576     double theMinorRadius)
577 {
578   std::shared_ptr<ModelAPI_Feature> aFeature =
579       compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
580   return EllipsePtr(new SketchAPI_Ellipse(aFeature,
581       theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius));
582 }
583
584 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
585     const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
586     const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
587     double theMinorRadius)
588 {
589   std::shared_ptr<ModelAPI_Feature> aFeature =
590       compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
591   return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius));
592 }
593
594 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
595     double thePoint1X, double thePoint1Y,
596     double thePoint2X, double thePoint2Y,
597     double thePassedX, double thePassedY,
598     bool isPoint1Center)
599 {
600   std::shared_ptr<ModelAPI_Feature> aFeature =
601       compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
602   return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature,
603       thePoint1X, thePoint1Y, thePoint2X, thePoint2Y, thePassedX, thePassedY, isPoint1Center));
604 }
605
606 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
607     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint1,
608     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint2,
609     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePassedPoint,
610     bool isPoint1Center)
611 {
612   std::shared_ptr<ModelAPI_Feature> aFeature =
613       compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
614   MacroEllipsePtr anEllipse;
615   if (thePoint1.second.isEmpty() &&
616       thePoint2.second.isEmpty() &&
617       thePassedPoint.second.isEmpty()) {
618     anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
619         thePoint1.first, thePoint2.first, thePassedPoint.first, isPoint1Center));
620   }
621   else {
622     anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
623         thePoint1.first, thePoint1.second,
624         thePoint2.first, thePoint2.second,
625         thePassedPoint.first, thePassedPoint.second,
626         isPoint1Center));
627   }
628   return anEllipse;
629 }
630
631 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
632     const ModelHighAPI_Selection & theExternal)
633 {
634   std::shared_ptr<ModelAPI_Feature> aFeature =
635       compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
636   return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal));
637 }
638
639 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
640     const std::string & theExternalName)
641 {
642   std::shared_ptr<ModelAPI_Feature> aFeature =
643       compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
644   return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName));
645 }
646
647 //--------------------------------------------------------------------------------------
648 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
649     double theCenterX, double theCenterY,
650     double theFocusX, double theFocusY,
651     double theStartX, double theStartY,
652     double theEndX, double theEndY,
653     bool theInversed)
654 {
655   std::shared_ptr<ModelAPI_Feature> aFeature =
656       compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
657   return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature,
658       theCenterX, theCenterY,
659       theFocusX, theFocusY,
660       theStartX, theStartY,
661       theEndX, theEndY,
662       theInversed));
663 }
664
665 std::shared_ptr<SketchAPI_MacroEllipticArc> SketchAPI_Sketch::addEllipticArc(
666     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theCenter,
667     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theMajorAxisPoint,
668     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theStartPoint,
669     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theEndPoint,
670     bool theInversed)
671 {
672   std::shared_ptr<ModelAPI_Feature> aFeature =
673       compositeFeature()->addFeature(SketchPlugin_MacroEllipticArc::ID());
674   return MacroEllipticArcPtr(new SketchAPI_MacroEllipticArc(aFeature,
675       theCenter.first, theCenter.second,
676       theMajorAxisPoint.first, theMajorAxisPoint.second,
677       theStartPoint.first, theStartPoint.second,
678       theEndPoint.first, theEndPoint.second,
679       theInversed));
680 }
681
682 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
683     const ModelHighAPI_Selection & theExternal)
684 {
685   std::shared_ptr<ModelAPI_Feature> aFeature =
686       compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
687   return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternal));
688 }
689
690 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
691     const std::string & theExternalName)
692 {
693   std::shared_ptr<ModelAPI_Feature> aFeature =
694       compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
695   return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternalName));
696 }
697
698 //--------------------------------------------------------------------------------------
699 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
700     const ModelHighAPI_Selection & theExternalFeature,
701     bool theKeepResult)
702 {
703   std::shared_ptr<ModelAPI_Feature> aFeature =
704     compositeFeature()->addFeature(SketchPlugin_Projection::ID());
705   ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
706   aProjection->setIncludeToResult(theKeepResult);
707   return aProjection;
708 }
709
710 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
711     const std::string & theExternalName,
712     bool theKeepResult)
713 {
714   std::shared_ptr<ModelAPI_Feature> aFeature =
715     compositeFeature()->addFeature(SketchPlugin_Projection::ID());
716   ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
717   aProjection->setIncludeToResult(theKeepResult);
718   return aProjection;
719 }
720
721 //--------------------------------------------------------------------------------------
722 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
723     const ModelHighAPI_RefAttr & theMirrorLine,
724     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
725 {
726   std::shared_ptr<ModelAPI_Feature> aFeature =
727     compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
728   return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
729 }
730
731 //--------------------------------------------------------------------------------------
732 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
733     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
734     const ModelHighAPI_RefAttr & thePoint1,
735     const ModelHighAPI_RefAttr & thePoint2,
736     const ModelHighAPI_Integer & theNumberOfObjects,
737     bool theFullValue)
738 {
739   std::shared_ptr<ModelAPI_Feature> aFeature =
740     compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
741   return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
742                                                   thePoint2, theNumberOfObjects, theFullValue));
743 }
744
745 //--------------------------------------------------------------------------------------
746 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
747     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
748     const ModelHighAPI_RefAttr & theCenter,
749     const ModelHighAPI_Double & theAngle,
750     const ModelHighAPI_Integer & theNumberOfObjects,
751     bool theFullValue,
752     bool theReversed)
753 {
754   std::shared_ptr<ModelAPI_Feature> aFeature =
755     compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
756   return RotationPtr(
757     new SketchAPI_Rotation(aFeature, theObjects, theCenter,
758                            theAngle, theNumberOfObjects, theFullValue, theReversed));
759 }
760
761 //--------------------------------------------------------------------------------------
762 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
763                                           const ModelHighAPI_Reference& theFeature,
764                                           const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
765 {
766   std::shared_ptr<ModelAPI_Feature> aFeature =
767     compositeFeature()->addFeature(SketchPlugin_Split::ID());
768   fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
769
770   AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
771   if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
772     AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
773     fillAttribute(thePositionPoint, aPointAttr);
774   }
775
776   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
777 }
778
779 //--------------------------------------------------------------------------------------
780 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
781                                         const ModelHighAPI_Reference& theFeature,
782                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
783 {
784   std::shared_ptr<ModelAPI_Feature> aFeature =
785     compositeFeature()->addFeature(SketchPlugin_Trim::ID());
786   fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
787
788   AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
789   if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
790     AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
791     fillAttribute(thePositionPoint, aPointAttr);
792   }
793
794   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
795 }
796
797 //--------------------------------------------------------------------------------------
798 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
799     const ModelHighAPI_RefAttr & theLine1,
800     const ModelHighAPI_RefAttr & theLine2,
801     const ModelHighAPI_Double & theValue)
802 {
803   std::shared_ptr<ModelAPI_Feature> aFeature =
804       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
805   fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
806       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
807   // fill the value before llines to avoid calculation of angle value by the Angle feature
808   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
809   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
810   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
811   aFeature->execute();
812   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
813 }
814
815 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
816     const ModelHighAPI_RefAttr & theLine1,
817     const ModelHighAPI_RefAttr & theLine2,
818     const ModelHighAPI_Double & theValue)
819 {
820   std::shared_ptr<ModelAPI_Feature> aFeature =
821       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
822   fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
823       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
824   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
825   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
826   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
827   aFeature->execute();
828   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
829 }
830
831 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
832     const ModelHighAPI_RefAttr & theLine1,
833     const ModelHighAPI_RefAttr & theLine2,
834     const ModelHighAPI_Double & theValue)
835 {
836   std::shared_ptr<ModelAPI_Feature> aFeature =
837       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
838   fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
839       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
840   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
841   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
842   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
843   aFeature->execute();
844   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
845 }
846
847 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
848     const ModelHighAPI_RefAttr & thePoint1,
849     const ModelHighAPI_RefAttr & thePoint2)
850 {
851   std::shared_ptr<ModelAPI_Feature> aFeature =
852       compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
853   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
854   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
855   aFeature->execute();
856   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
857 }
858
859 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
860     const ModelHighAPI_RefAttr & theLine1,
861     const ModelHighAPI_RefAttr & theLine2)
862 {
863   std::shared_ptr<ModelAPI_Feature> aFeature =
864       compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
865   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
866   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
867   aFeature->execute();
868   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
869 }
870
871 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
872     const ModelHighAPI_RefAttr & thePoint,
873     const ModelHighAPI_RefAttr & thePointOrLine,
874     const ModelHighAPI_Double & theValue,
875     bool isSigned)
876 {
877   std::shared_ptr<ModelAPI_Feature> aFeature =
878       compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
879   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
880   fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
881   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
882   fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
883   aFeature->execute();
884   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
885 }
886
887 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
888     const ModelHighAPI_RefAttr & thePoint,
889     const ModelHighAPI_RefAttr & thePointOrLine,
890     const ModelHighAPI_Double & theValue)
891 {
892   return setDistance(thePoint, thePointOrLine, theValue, true);
893 }
894
895 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
896     const ModelHighAPI_RefAttr & thePoint,
897     const ModelHighAPI_RefAttr & thePointOrLine,
898     const ModelHighAPI_Double & theValue)
899 {
900   return setDistance(thePoint, thePointOrLine, theValue, false);
901 }
902
903 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
904     const ModelHighAPI_RefAttr & thePoint1,
905     const ModelHighAPI_RefAttr & thePoint2,
906     const ModelHighAPI_Double & theValue)
907 {
908   std::shared_ptr<ModelAPI_Feature> aFeature =
909       compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
910   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
911   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
912   fillAttribute(theValue,
913       aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
914   aFeature->execute();
915   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
916 }
917
918 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
919     const ModelHighAPI_RefAttr & thePoint1,
920     const ModelHighAPI_RefAttr & thePoint2,
921     const ModelHighAPI_Double & theValue)
922 {
923   std::shared_ptr<ModelAPI_Feature> aFeature =
924       compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
925   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
926   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
927   fillAttribute(theValue,
928       aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
929   aFeature->execute();
930   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
931 }
932
933 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
934     const ModelHighAPI_RefAttr & theObject1,
935     const ModelHighAPI_RefAttr & theObject2)
936 {
937   std::shared_ptr<ModelAPI_Feature> aFeature =
938       compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
939   fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
940   fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
941   aFeature->execute();
942   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
943 }
944
945 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
946     const ModelHighAPI_RefAttr & thePoint)
947 {
948   std::shared_ptr<ModelAPI_Feature> aFeature =
949       compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
950   fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
951   apply(); // finish operation to remove Fillet feature correcly
952   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
953 }
954
955 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
956     const ModelHighAPI_RefAttr & thePoint,
957     const ModelHighAPI_Double & theRadius)
958 {
959   CompositeFeaturePtr aSketch = compositeFeature();
960   int aNbSubs = aSketch->numberOfSubs();
961
962   // create fillet
963   InterfacePtr aFilletFeature = setFillet(thePoint);
964
965   // set radius for just created arc
966   FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
967   if (anArc->getKind() == SketchPlugin_Arc::ID())
968     setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
969
970   return aFilletFeature;
971 }
972
973 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
974     const ModelHighAPI_RefAttr & theObject)
975 {
976   std::shared_ptr<ModelAPI_Feature> aFeature =
977       compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
978   fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
979   aFeature->execute();
980   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
981 }
982
983 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
984     const ModelHighAPI_RefAttr & theLine)
985 {
986   std::shared_ptr<ModelAPI_Feature> aFeature =
987       compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
988   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
989   aFeature->execute();
990   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
991 }
992
993 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
994     const ModelHighAPI_RefAttr & theLine,
995     const ModelHighAPI_Double & theValue)
996 {
997   std::shared_ptr<ModelAPI_Feature> aFeature =
998       compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
999   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1000   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1001   aFeature->execute();
1002   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1003 }
1004
1005 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1006     const ModelHighAPI_RefAttr & thePoint,
1007     const ModelHighAPI_RefAttr & theLine)
1008 {
1009   std::shared_ptr<ModelAPI_Feature> aFeature =
1010       compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1011   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1012   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1013   aFeature->execute();
1014   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1015 }
1016
1017 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1018     const ModelHighAPI_RefAttr & theLine1,
1019     const ModelHighAPI_RefAttr & theLine2)
1020 {
1021   std::shared_ptr<ModelAPI_Feature> aFeature =
1022       compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1023   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1024   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1025   aFeature->execute();
1026   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1027 }
1028
1029 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1030     const ModelHighAPI_RefAttr & theLine1,
1031     const ModelHighAPI_RefAttr & theLine2)
1032 {
1033   std::shared_ptr<ModelAPI_Feature> aFeature =
1034       compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1035   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1036   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1037   aFeature->execute();
1038   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1039 }
1040
1041 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1042     const ModelHighAPI_RefAttr & theCircleOrArc,
1043     const ModelHighAPI_Double & theValue)
1044 {
1045   std::shared_ptr<ModelAPI_Feature> aFeature =
1046       compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1047   fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1048   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1049   aFeature->execute();
1050   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1051 }
1052
1053 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1054     const ModelHighAPI_RefAttr & theLine,
1055     const ModelHighAPI_RefAttr & theCircle)
1056 {
1057   std::shared_ptr<ModelAPI_Feature> aFeature =
1058       compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1059   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1060   fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1061   aFeature->execute();
1062   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1063 }
1064
1065 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1066     const ModelHighAPI_RefAttr & theLine)
1067 {
1068   std::shared_ptr<ModelAPI_Feature> aFeature =
1069       compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1070   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1071   aFeature->execute();
1072   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1073 }
1074
1075 //--------------------------------------------------------------------------------------
1076
1077 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1078 {
1079   AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1080   return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1081 }
1082
1083 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1084 {
1085   AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1086       theFeature->attribute(SketchPlugin_Line::START_ID()));
1087   AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1088       theFeature->attribute(SketchPlugin_Line::END_ID()));
1089
1090   if (!aStartAttr || !aEndAttr)
1091     return std::shared_ptr<GeomAPI_Pnt2d>();
1092
1093   std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1094   std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1095   return std::shared_ptr<GeomAPI_Pnt2d>(
1096       new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1097 }
1098
1099 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1100 {
1101   AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1102       theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1103   AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1104
1105   if (!aCenter || !aRadius)
1106     return std::shared_ptr<GeomAPI_Pnt2d>();
1107
1108   return std::shared_ptr<GeomAPI_Pnt2d>(
1109       new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1110 }
1111
1112 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1113 {
1114   static const double PI = 3.141592653589793238463;
1115
1116   AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1117       theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1118   AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1119       theFeature->attribute(SketchPlugin_Arc::START_ID()));
1120   AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1121       theFeature->attribute(SketchPlugin_Arc::END_ID()));
1122
1123   if (!aCenterAttr || !aStartAttr || !aEndAttr)
1124     return std::shared_ptr<GeomAPI_Pnt2d>();
1125
1126   std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1127       aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1128   std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1129       aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1130
1131   double anAngle = aStartDir->angle(aEndDir);
1132   bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1133   if (isReversed && anAngle > 0.)
1134     anAngle -= 2.0 * PI;
1135   else if (!isReversed && anAngle <= 0.)
1136     anAngle += 2.0 * PI;
1137
1138   double cosA = cos(anAngle);
1139   double sinA = sin(anAngle);
1140
1141   // rotate start dir to find middle point on arc
1142   double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1143   double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1144   double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1145
1146   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1147 }
1148
1149 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1150                                                      bool isEllipse = true)
1151 {
1152   const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1153                                   SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1154   AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1155       theFeature->attribute(anAttrName));
1156   return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1157 }
1158
1159 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
1160 {
1161   std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1162   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1163   if (aFeature) {
1164     // move only features of the following types
1165     const std::string& aFeatureKind = aFeature->getKind();
1166     if (aFeatureKind == SketchPlugin_Point::ID())
1167       aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1168     else if (aFeatureKind == SketchPlugin_Line::ID())
1169       aMiddlePoint = middlePointOnLine(aFeature);
1170     else if (aFeatureKind == SketchPlugin_Circle::ID())
1171       aMiddlePoint = pointOnCircle(aFeature);
1172     else if (aFeatureKind == SketchPlugin_Arc::ID())
1173       aMiddlePoint = middlePointOnArc(aFeature);
1174     else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1175       aMiddlePoint = pointOnEllipse(aFeature);
1176     else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1177       aMiddlePoint = pointOnEllipse(aFeature, false);
1178   }
1179   return aMiddlePoint;
1180 }
1181
1182 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1183                             const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1184 {
1185   std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1186   theMovedEntity.fillMessage(aMessage);
1187
1188   std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1189   if (aMessage->movedAttribute())
1190     anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1191   else
1192     anOriginalPosition = middlePoint(aMessage->movedObject());
1193
1194   if (!anOriginalPosition)
1195     return; // something has gone wrong, do not process movement
1196
1197   aMessage->setOriginalPosition(anOriginalPosition);
1198   aMessage->setCurrentPosition(theTargetPoint);
1199   Events_Loop::loop()->send(aMessage);
1200 }
1201
1202 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1203                             double theTargetX, double theTargetY)
1204 {
1205   std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1206   move(theMovedEntity, aTargetPoint);
1207 }
1208
1209 //--------------------------------------------------------------------------------------
1210
1211 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1212 {
1213   FeaturePtr aBase = feature();
1214   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1215       aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1216   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1217       aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1218   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1219       aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1220   std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1221
1222   return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1223 }
1224
1225 //--------------------------------------------------------------------------------------
1226
1227 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1228 {
1229   // collect edges of the first face
1230   std::list<GeomShapePtr> anEdges1;
1231   for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1232     anEdges1.push_back(anExp.current());
1233   // compare edges of faces
1234   for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1235     GeomShapePtr aCurrent = anExp.current();
1236     bool isFound = false;
1237     std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1238     for (; anIt1 != anEdges1.end(); ++anIt1)
1239       if (aCurrent->isSameGeometry(*anIt1)) {
1240         isFound = true;
1241         anEdges1.erase(anIt1);
1242         break;
1243       }
1244     if (!isFound)
1245       return true;
1246   }
1247   return !anEdges1.empty();
1248 }
1249
1250 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1251 {
1252   ResultConstructionPtr aSketchResult =
1253       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1254   if (!aSketchResult)
1255     return false;
1256
1257   std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1258       std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1259   if (!aWires)
1260     return false;
1261
1262   // collect faces constructed by SketchBuilder algorithm
1263   GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1264                                            aWires->norm(), aWires);
1265   const ListOfShape& aFaces = aSketchBuilder.faces();
1266
1267   // compare faces stored in sketch with faces generated by SketchBuilder
1268   int aNbSketchFaces = aSketchResult->facesNum();
1269   int aFaceIndex = 0;
1270   for (ListOfShape::const_iterator aFIt = aFaces.begin();
1271        aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1272        ++aFIt, ++aFaceIndex) {
1273     GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1274     GeomFacePtr aCurFace = (*aFIt)->face();
1275     if (isDifferent(aSketchFace, aCurFace))
1276       return true;
1277   }
1278   return false;
1279 }
1280
1281 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1282                                std::list<std::list<ResultPtr> >& theEdges)
1283 {
1284   ResultConstructionPtr aSketchResult =
1285       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1286   if (!aSketchResult)
1287     return;
1288
1289   // collect curves of the sketch
1290   std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1291   int aSubNum = theSketch->numberOfSubs();
1292   for (int a = 0; a < aSubNum; ++a) {
1293     FeaturePtr aSub = theSketch->subFeature(a);
1294     const std::list<ResultPtr>& aResults = aSub->results();
1295     std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1296     for (; aRes != aResults.cend(); aRes++) {
1297       GeomShapePtr aCurShape = (*aRes)->shape();
1298       if (aCurShape && aCurShape->isEdge())
1299         aCurves[untrimmedCurve(aCurShape)] = *aRes;
1300     }
1301   }
1302
1303   // convert each face to the list of results of its edges
1304   int aFacesNum = aSketchResult->facesNum();
1305   for (int a = 0; a < aFacesNum; ++a) {
1306     theEdges.push_back(std::list<ResultPtr>());
1307     std::list<ResultPtr>& aCurEdges = theEdges.back();
1308
1309     GeomFacePtr aFace = aSketchResult->face(a);
1310     for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1311          anExp.more(); anExp.next()) {
1312       GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1313       aCurEdges.push_back(aCurves[aCurrent]);
1314     }
1315   }
1316 }
1317
1318 //--------------------------------------------------------------------------------------
1319
1320 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1321 {
1322   FeaturePtr aBase = feature();
1323   const std::string& aDocName = theDumper.name(aBase->document());
1324
1325   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1326   if (anExternal->value()) {
1327     theDumper << aBase << " = model.addSketch(" << aDocName <<
1328       ", " << anExternal << ")" << std::endl;
1329   } else {
1330     // Sketch is base on a plane.
1331     std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1332         aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1333     std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1334         aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1335     std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1336         aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1337
1338     // Check the plane is coordinate plane
1339     std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1340     if(anExternal->context()) { // checking for selected planes
1341       if (!aPlaneName.empty()
1342           && anExternal->context()->data()
1343           && anExternal->context()->data()->name() == aPlaneName) {
1344         // dump sketch based on coordinate plane
1345         theDumper << aBase << " = model.addSketch(" << aDocName
1346                   << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1347       } else { // some other plane
1348         theDumper << aBase << " = model.addSketch(" << aDocName <<
1349           ", " << anExternal<< ")" << std::endl;
1350       }
1351     } else {
1352       if (aPlaneName.empty()) {
1353         // needs import additional module
1354         theDumper.importModule("GeomAPI");
1355         // dump plane parameters
1356         const std::string& aSketchName = theDumper.name(aBase);
1357         std::string anOriginName = aSketchName + "_origin";
1358         std::string aNormalName  = aSketchName + "_norm";
1359         std::string aDirXName    = aSketchName + "_dirx";
1360         // use "\n" instead of std::endl to avoid automatic dumping sketch here
1361         // and then dumplicate dumping it in the next line
1362         theDumper << anOriginName << " = " << anOrigin << "\n"
1363                   << aNormalName  << " = " << aNormal  << "\n"
1364                   << aDirXName    << " = " << aDirX    << "\n";
1365         // dump sketch based on arbitrary plane
1366         theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1367                   << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1368       } else {
1369         // dump sketch based on coordinate plane
1370         theDumper << aBase << " = model.addSketch(" << aDocName
1371                   << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1372       }
1373     }
1374   }
1375
1376   // dump sketch's subfeatures
1377   CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1378   theDumper.processSubs(aCompFeat, true);
1379
1380   // if face order differs to the order generated by SketchBuilder,
1381   // dump the list of faces for correct execution of the script
1382   if (isCustomFacesOrder(aCompFeat)) {
1383     std::list<std::list<ResultPtr> > aFaces;
1384     edgesOfSketchFaces(aCompFeat, aFaces);
1385
1386     const std::string& aSketchName = theDumper.name(aBase);
1387     std::string aMethodName(".changeFacesOrder");
1388     std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1389
1390     theDumper << aSketchName << aMethodName << "([";
1391     for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1392          aFIt != aFaces.end(); ++aFIt) {
1393       if (aFIt != aFaces.begin())
1394         theDumper << ",\n" << aSpaceShift << "  ";
1395       theDumper << *aFIt;
1396     }
1397     theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1398   }
1399 }