Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
[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_EllipticArc> SketchAPI_Sketch::addEllipticArc(
666     const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
667     const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
668     const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
669     const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
670     bool theInversed)
671 {
672   std::shared_ptr<ModelAPI_Feature> aFeature =
673       compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
674   return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature,
675       theCenter, theFocus, theStart, theEnd, theInversed));
676 }
677
678 std::shared_ptr<SketchAPI_MacroEllipticArc> SketchAPI_Sketch::addEllipticArc(
679     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theCenter,
680     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theMajorAxisPoint,
681     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theStartPoint,
682     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theEndPoint,
683     bool theInversed)
684 {
685   std::shared_ptr<ModelAPI_Feature> aFeature =
686       compositeFeature()->addFeature(SketchPlugin_MacroEllipticArc::ID());
687   return MacroEllipticArcPtr(new SketchAPI_MacroEllipticArc(aFeature,
688       theCenter.first, theCenter.second,
689       theMajorAxisPoint.first, theMajorAxisPoint.second,
690       theStartPoint.first, theStartPoint.second,
691       theEndPoint.first, theEndPoint.second,
692       theInversed));
693 }
694
695 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
696     const ModelHighAPI_Selection & theExternal)
697 {
698   std::shared_ptr<ModelAPI_Feature> aFeature =
699       compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
700   return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternal));
701 }
702
703 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
704     const std::string & theExternalName)
705 {
706   std::shared_ptr<ModelAPI_Feature> aFeature =
707       compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
708   return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternalName));
709 }
710
711 //--------------------------------------------------------------------------------------
712 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
713     const ModelHighAPI_Selection & theExternalFeature,
714     bool theKeepResult)
715 {
716   std::shared_ptr<ModelAPI_Feature> aFeature =
717     compositeFeature()->addFeature(SketchPlugin_Projection::ID());
718   ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
719   aProjection->setIncludeToResult(theKeepResult);
720   return aProjection;
721 }
722
723 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
724     const std::string & theExternalName,
725     bool theKeepResult)
726 {
727   std::shared_ptr<ModelAPI_Feature> aFeature =
728     compositeFeature()->addFeature(SketchPlugin_Projection::ID());
729   ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
730   aProjection->setIncludeToResult(theKeepResult);
731   return aProjection;
732 }
733
734 //--------------------------------------------------------------------------------------
735 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
736     const ModelHighAPI_RefAttr & theMirrorLine,
737     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
738 {
739   std::shared_ptr<ModelAPI_Feature> aFeature =
740     compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
741   return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
742 }
743
744 //--------------------------------------------------------------------------------------
745 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
746     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
747     const ModelHighAPI_RefAttr & thePoint1,
748     const ModelHighAPI_RefAttr & thePoint2,
749     const ModelHighAPI_Integer & theNumberOfObjects,
750     bool theFullValue)
751 {
752   std::shared_ptr<ModelAPI_Feature> aFeature =
753     compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
754   return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
755                                                   thePoint2, theNumberOfObjects, theFullValue));
756 }
757
758 //--------------------------------------------------------------------------------------
759 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
760     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
761     const ModelHighAPI_RefAttr & theCenter,
762     const ModelHighAPI_Double & theAngle,
763     const ModelHighAPI_Integer & theNumberOfObjects,
764     bool theFullValue,
765     bool theReversed)
766 {
767   std::shared_ptr<ModelAPI_Feature> aFeature =
768     compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
769   return RotationPtr(
770     new SketchAPI_Rotation(aFeature, theObjects, theCenter,
771                            theAngle, theNumberOfObjects, theFullValue, theReversed));
772 }
773
774 //--------------------------------------------------------------------------------------
775 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
776                                           const ModelHighAPI_Reference& theFeature,
777                                           const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
778 {
779   std::shared_ptr<ModelAPI_Feature> aFeature =
780     compositeFeature()->addFeature(SketchPlugin_Split::ID());
781   fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
782
783   AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
784   if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
785     AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
786     fillAttribute(thePositionPoint, aPointAttr);
787   }
788
789   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
790 }
791
792 //--------------------------------------------------------------------------------------
793 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
794                                         const ModelHighAPI_Reference& theFeature,
795                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
796 {
797   std::shared_ptr<ModelAPI_Feature> aFeature =
798     compositeFeature()->addFeature(SketchPlugin_Trim::ID());
799   fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
800
801   AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
802   if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
803     AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
804     fillAttribute(thePositionPoint, aPointAttr);
805   }
806
807   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
808 }
809
810 //--------------------------------------------------------------------------------------
811 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
812     const ModelHighAPI_RefAttr & theLine1,
813     const ModelHighAPI_RefAttr & theLine2,
814     const ModelHighAPI_Double & theValue)
815 {
816   std::shared_ptr<ModelAPI_Feature> aFeature =
817       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
818   fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
819       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
820   // fill the value before llines to avoid calculation of angle value by the Angle feature
821   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
822   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
823   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
824   aFeature->execute();
825   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
826 }
827
828 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
829     const ModelHighAPI_RefAttr & theLine1,
830     const ModelHighAPI_RefAttr & theLine2,
831     const ModelHighAPI_Double & theValue)
832 {
833   std::shared_ptr<ModelAPI_Feature> aFeature =
834       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
835   fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
836       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
837   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
838   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
839   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
840   aFeature->execute();
841   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
842 }
843
844 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
845     const ModelHighAPI_RefAttr & theLine1,
846     const ModelHighAPI_RefAttr & theLine2,
847     const ModelHighAPI_Double & theValue)
848 {
849   std::shared_ptr<ModelAPI_Feature> aFeature =
850       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
851   fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
852       aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
853   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
854   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
855   fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
856   aFeature->execute();
857   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
858 }
859
860 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
861     const ModelHighAPI_RefAttr & thePoint1,
862     const ModelHighAPI_RefAttr & thePoint2)
863 {
864   std::shared_ptr<ModelAPI_Feature> aFeature =
865       compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
866   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
867   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
868   aFeature->execute();
869   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
870 }
871
872 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
873     const ModelHighAPI_RefAttr & theLine1,
874     const ModelHighAPI_RefAttr & theLine2)
875 {
876   std::shared_ptr<ModelAPI_Feature> aFeature =
877       compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
878   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
879   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
880   aFeature->execute();
881   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
882 }
883
884 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
885     const ModelHighAPI_RefAttr & thePoint,
886     const ModelHighAPI_RefAttr & thePointOrLine,
887     const ModelHighAPI_Double & theValue,
888     bool isSigned)
889 {
890   std::shared_ptr<ModelAPI_Feature> aFeature =
891       compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
892   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
893   fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
894   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
895   fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
896   aFeature->execute();
897   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
898 }
899
900 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
901     const ModelHighAPI_RefAttr & thePoint,
902     const ModelHighAPI_RefAttr & thePointOrLine,
903     const ModelHighAPI_Double & theValue)
904 {
905   return setDistance(thePoint, thePointOrLine, theValue, true);
906 }
907
908 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
909     const ModelHighAPI_RefAttr & thePoint,
910     const ModelHighAPI_RefAttr & thePointOrLine,
911     const ModelHighAPI_Double & theValue)
912 {
913   return setDistance(thePoint, thePointOrLine, theValue, false);
914 }
915
916 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
917     const ModelHighAPI_RefAttr & thePoint1,
918     const ModelHighAPI_RefAttr & thePoint2,
919     const ModelHighAPI_Double & theValue)
920 {
921   std::shared_ptr<ModelAPI_Feature> aFeature =
922       compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
923   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
924   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
925   fillAttribute(theValue,
926       aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
927   aFeature->execute();
928   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
929 }
930
931 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
932     const ModelHighAPI_RefAttr & thePoint1,
933     const ModelHighAPI_RefAttr & thePoint2,
934     const ModelHighAPI_Double & theValue)
935 {
936   std::shared_ptr<ModelAPI_Feature> aFeature =
937       compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
938   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
939   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
940   fillAttribute(theValue,
941       aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
942   aFeature->execute();
943   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
944 }
945
946 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
947     const ModelHighAPI_RefAttr & theObject1,
948     const ModelHighAPI_RefAttr & theObject2)
949 {
950   std::shared_ptr<ModelAPI_Feature> aFeature =
951       compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
952   fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
953   fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
954   aFeature->execute();
955   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
956 }
957
958 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
959     const ModelHighAPI_RefAttr & thePoint)
960 {
961   std::shared_ptr<ModelAPI_Feature> aFeature =
962       compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
963   fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
964   apply(); // finish operation to remove Fillet feature correcly
965   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
966 }
967
968 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
969     const ModelHighAPI_RefAttr & thePoint,
970     const ModelHighAPI_Double & theRadius)
971 {
972   CompositeFeaturePtr aSketch = compositeFeature();
973   int aNbSubs = aSketch->numberOfSubs();
974
975   // create fillet
976   InterfacePtr aFilletFeature = setFillet(thePoint);
977
978   // set radius for just created arc
979   FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
980   if (anArc->getKind() == SketchPlugin_Arc::ID())
981     setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
982
983   return aFilletFeature;
984 }
985
986 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
987     const ModelHighAPI_RefAttr & theObject)
988 {
989   std::shared_ptr<ModelAPI_Feature> aFeature =
990       compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
991   fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
992   aFeature->execute();
993   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
994 }
995
996 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
997     const ModelHighAPI_RefAttr & theLine)
998 {
999   std::shared_ptr<ModelAPI_Feature> aFeature =
1000       compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1001   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1002   aFeature->execute();
1003   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1004 }
1005
1006 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1007     const ModelHighAPI_RefAttr & theLine,
1008     const ModelHighAPI_Double & theValue)
1009 {
1010   std::shared_ptr<ModelAPI_Feature> aFeature =
1011       compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1012   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1013   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1014   aFeature->execute();
1015   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1016 }
1017
1018 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1019     const ModelHighAPI_RefAttr & thePoint,
1020     const ModelHighAPI_RefAttr & theLine)
1021 {
1022   std::shared_ptr<ModelAPI_Feature> aFeature =
1023       compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1024   fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1025   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1026   aFeature->execute();
1027   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1028 }
1029
1030 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1031     const ModelHighAPI_RefAttr & theLine1,
1032     const ModelHighAPI_RefAttr & theLine2)
1033 {
1034   std::shared_ptr<ModelAPI_Feature> aFeature =
1035       compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1036   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1037   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1038   aFeature->execute();
1039   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1040 }
1041
1042 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1043     const ModelHighAPI_RefAttr & theLine1,
1044     const ModelHighAPI_RefAttr & theLine2)
1045 {
1046   std::shared_ptr<ModelAPI_Feature> aFeature =
1047       compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1048   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1049   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1050   aFeature->execute();
1051   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1052 }
1053
1054 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1055     const ModelHighAPI_RefAttr & theCircleOrArc,
1056     const ModelHighAPI_Double & theValue)
1057 {
1058   std::shared_ptr<ModelAPI_Feature> aFeature =
1059       compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1060   fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1061   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1062   aFeature->execute();
1063   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1064 }
1065
1066 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1067     const ModelHighAPI_RefAttr & theLine,
1068     const ModelHighAPI_RefAttr & theCircle)
1069 {
1070   std::shared_ptr<ModelAPI_Feature> aFeature =
1071       compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1072   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1073   fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1074   aFeature->execute();
1075   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1076 }
1077
1078 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1079     const ModelHighAPI_RefAttr & theLine)
1080 {
1081   std::shared_ptr<ModelAPI_Feature> aFeature =
1082       compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1083   fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1084   aFeature->execute();
1085   return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1086 }
1087
1088 //--------------------------------------------------------------------------------------
1089
1090 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1091 {
1092   AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1093   return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1094 }
1095
1096 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1097 {
1098   AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1099       theFeature->attribute(SketchPlugin_Line::START_ID()));
1100   AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1101       theFeature->attribute(SketchPlugin_Line::END_ID()));
1102
1103   if (!aStartAttr || !aEndAttr)
1104     return std::shared_ptr<GeomAPI_Pnt2d>();
1105
1106   std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1107   std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1108   return std::shared_ptr<GeomAPI_Pnt2d>(
1109       new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1110 }
1111
1112 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1113 {
1114   AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1115       theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1116   AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1117
1118   if (!aCenter || !aRadius)
1119     return std::shared_ptr<GeomAPI_Pnt2d>();
1120
1121   return std::shared_ptr<GeomAPI_Pnt2d>(
1122       new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1123 }
1124
1125 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1126 {
1127   static const double PI = 3.141592653589793238463;
1128
1129   AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1130       theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1131   AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1132       theFeature->attribute(SketchPlugin_Arc::START_ID()));
1133   AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1134       theFeature->attribute(SketchPlugin_Arc::END_ID()));
1135
1136   if (!aCenterAttr || !aStartAttr || !aEndAttr)
1137     return std::shared_ptr<GeomAPI_Pnt2d>();
1138
1139   std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1140       aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1141   std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1142       aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1143
1144   double anAngle = aStartDir->angle(aEndDir);
1145   bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1146   if (isReversed && anAngle > 0.)
1147     anAngle -= 2.0 * PI;
1148   else if (!isReversed && anAngle <= 0.)
1149     anAngle += 2.0 * PI;
1150
1151   double cosA = cos(anAngle);
1152   double sinA = sin(anAngle);
1153
1154   // rotate start dir to find middle point on arc
1155   double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1156   double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1157   double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1158
1159   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1160 }
1161
1162 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature)
1163 {
1164   AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1165       theFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()));
1166   return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1167 }
1168
1169 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
1170 {
1171   std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1172   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1173   if (aFeature) {
1174     // move only features of the following types
1175     const std::string& aFeatureKind = aFeature->getKind();
1176     if (aFeatureKind == SketchPlugin_Point::ID())
1177       aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1178     else if (aFeatureKind == SketchPlugin_Line::ID())
1179       aMiddlePoint = middlePointOnLine(aFeature);
1180     else if (aFeatureKind == SketchPlugin_Circle::ID())
1181       aMiddlePoint = pointOnCircle(aFeature);
1182     else if (aFeatureKind == SketchPlugin_Arc::ID())
1183       aMiddlePoint = middlePointOnArc(aFeature);
1184     else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1185       aMiddlePoint = pointOnEllipse(aFeature);
1186   }
1187   return aMiddlePoint;
1188 }
1189
1190 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1191                             const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1192 {
1193   std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1194   theMovedEntity.fillMessage(aMessage);
1195
1196   std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1197   if (aMessage->movedAttribute())
1198     anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1199   else
1200     anOriginalPosition = middlePoint(aMessage->movedObject());
1201
1202   if (!anOriginalPosition)
1203     return; // something has gone wrong, do not process movement
1204
1205   aMessage->setOriginalPosition(anOriginalPosition);
1206   aMessage->setCurrentPosition(theTargetPoint);
1207   Events_Loop::loop()->send(aMessage);
1208 }
1209
1210 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1211                             double theTargetX, double theTargetY)
1212 {
1213   std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1214   move(theMovedEntity, aTargetPoint);
1215 }
1216
1217 //--------------------------------------------------------------------------------------
1218
1219 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1220 {
1221   FeaturePtr aBase = feature();
1222   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1223       aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1224   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1225       aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1226   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1227       aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1228   std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1229
1230   return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1231 }
1232
1233 //--------------------------------------------------------------------------------------
1234
1235 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1236 {
1237   // collect edges of the first face
1238   std::list<GeomShapePtr> anEdges1;
1239   for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1240     anEdges1.push_back(anExp.current());
1241   // compare edges of faces
1242   for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1243     GeomShapePtr aCurrent = anExp.current();
1244     bool isFound = false;
1245     std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1246     for (; anIt1 != anEdges1.end(); ++anIt1)
1247       if (aCurrent->isSameGeometry(*anIt1)) {
1248         isFound = true;
1249         anEdges1.erase(anIt1);
1250         break;
1251       }
1252     if (!isFound)
1253       return true;
1254   }
1255   return !anEdges1.empty();
1256 }
1257
1258 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1259 {
1260   ResultConstructionPtr aSketchResult =
1261       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1262   if (!aSketchResult)
1263     return false;
1264
1265   std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1266       std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1267   if (!aWires)
1268     return false;
1269
1270   // collect faces constructed by SketchBuilder algorithm
1271   GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1272                                            aWires->norm(), aWires);
1273   const ListOfShape& aFaces = aSketchBuilder.faces();
1274
1275   // compare faces stored in sketch with faces generated by SketchBuilder
1276   int aNbSketchFaces = aSketchResult->facesNum();
1277   int aFaceIndex = 0;
1278   for (ListOfShape::const_iterator aFIt = aFaces.begin();
1279        aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1280        ++aFIt, ++aFaceIndex) {
1281     GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1282     GeomFacePtr aCurFace = (*aFIt)->face();
1283     if (isDifferent(aSketchFace, aCurFace))
1284       return true;
1285   }
1286   return false;
1287 }
1288
1289 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1290                                std::list<std::list<ResultPtr> >& theEdges)
1291 {
1292   ResultConstructionPtr aSketchResult =
1293       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1294   if (!aSketchResult)
1295     return;
1296
1297   // collect curves of the sketch
1298   std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1299   int aSubNum = theSketch->numberOfSubs();
1300   for (int a = 0; a < aSubNum; ++a) {
1301     FeaturePtr aSub = theSketch->subFeature(a);
1302     const std::list<ResultPtr>& aResults = aSub->results();
1303     std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1304     for (; aRes != aResults.cend(); aRes++) {
1305       GeomShapePtr aCurShape = (*aRes)->shape();
1306       if (aCurShape && aCurShape->isEdge())
1307         aCurves[untrimmedCurve(aCurShape)] = *aRes;
1308     }
1309   }
1310
1311   // convert each face to the list of results of its edges
1312   int aFacesNum = aSketchResult->facesNum();
1313   for (int a = 0; a < aFacesNum; ++a) {
1314     theEdges.push_back(std::list<ResultPtr>());
1315     std::list<ResultPtr>& aCurEdges = theEdges.back();
1316
1317     GeomFacePtr aFace = aSketchResult->face(a);
1318     for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1319          anExp.more(); anExp.next()) {
1320       GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1321       aCurEdges.push_back(aCurves[aCurrent]);
1322     }
1323   }
1324 }
1325
1326 //--------------------------------------------------------------------------------------
1327
1328 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1329 {
1330   FeaturePtr aBase = feature();
1331   const std::string& aDocName = theDumper.name(aBase->document());
1332
1333   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1334   if (anExternal->value()) {
1335     theDumper << aBase << " = model.addSketch(" << aDocName <<
1336       ", " << anExternal << ")" << std::endl;
1337   } else {
1338     // Sketch is base on a plane.
1339     std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1340         aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1341     std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1342         aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1343     std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1344         aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1345
1346     // Check the plane is coordinate plane
1347     std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1348     if(anExternal->context()) { // checking for selected planes
1349       if (!aPlaneName.empty()
1350           && anExternal->context()->data()
1351           && anExternal->context()->data()->name() == aPlaneName) {
1352         // dump sketch based on coordinate plane
1353         theDumper << aBase << " = model.addSketch(" << aDocName
1354                   << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1355       } else { // some other plane
1356         theDumper << aBase << " = model.addSketch(" << aDocName <<
1357           ", " << anExternal<< ")" << std::endl;
1358       }
1359     } else {
1360       if (aPlaneName.empty()) {
1361         // needs import additional module
1362         theDumper.importModule("GeomAPI");
1363         // dump plane parameters
1364         const std::string& aSketchName = theDumper.name(aBase);
1365         std::string anOriginName = aSketchName + "_origin";
1366         std::string aNormalName  = aSketchName + "_norm";
1367         std::string aDirXName    = aSketchName + "_dirx";
1368         // use "\n" instead of std::endl to avoid automatic dumping sketch here
1369         // and then dumplicate dumping it in the next line
1370         theDumper << anOriginName << " = " << anOrigin << "\n"
1371                   << aNormalName  << " = " << aNormal  << "\n"
1372                   << aDirXName    << " = " << aDirX    << "\n";
1373         // dump sketch based on arbitrary plane
1374         theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1375                   << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1376       } else {
1377         // dump sketch based on coordinate plane
1378         theDumper << aBase << " = model.addSketch(" << aDocName
1379                   << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1380       }
1381     }
1382   }
1383
1384   // dump sketch's subfeatures
1385   CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1386   theDumper.processSubs(aCompFeat, true);
1387
1388   // if face order differs to the order generated by SketchBuilder,
1389   // dump the list of faces for correct execution of the script
1390   if (isCustomFacesOrder(aCompFeat)) {
1391     std::list<std::list<ResultPtr> > aFaces;
1392     edgesOfSketchFaces(aCompFeat, aFaces);
1393
1394     const std::string& aSketchName = theDumper.name(aBase);
1395     std::string aMethodName(".changeFacesOrder");
1396     std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1397
1398     theDumper << aSketchName << aMethodName << "([";
1399     for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1400          aFIt != aFaces.end(); ++aFIt) {
1401       if (aFIt != aFaces.begin())
1402         theDumper << ",\n" << aSpaceShift << "  ";
1403       theDumper << *aFIt;
1404     }
1405     theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1406   }
1407 }