1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 <SketchPlugin_MacroBSpline.h>
44 #include <SketcherPrs_Tools.h>
45 //--------------------------------------------------------------------------------------
46 #include <ModelAPI_Events.h>
47 #include <ModelAPI_CompositeFeature.h>
48 #include <ModelAPI_ResultConstruction.h>
49 #include <ModelHighAPI_Double.h>
50 #include <ModelHighAPI_Dumper.h>
51 #include <ModelHighAPI_RefAttr.h>
52 #include <ModelHighAPI_Selection.h>
53 #include <ModelHighAPI_Services.h>
54 #include <ModelHighAPI_Tools.h>
55 //--------------------------------------------------------------------------------------
56 #include "SketchAPI_Arc.h"
57 #include "SketchAPI_BSpline.h"
58 #include "SketchAPI_Circle.h"
59 #include "SketchAPI_Ellipse.h"
60 #include "SketchAPI_EllipticArc.h"
61 #include "SketchAPI_IntersectionPoint.h"
62 #include "SketchAPI_Line.h"
63 #include "SketchAPI_MacroArc.h"
64 #include "SketchAPI_MacroCircle.h"
65 #include "SketchAPI_MacroEllipse.h"
66 #include "SketchAPI_MacroEllipticArc.h"
67 #include "SketchAPI_Mirror.h"
68 #include "SketchAPI_Point.h"
69 #include "SketchAPI_Projection.h"
70 #include "SketchAPI_Rectangle.h"
71 #include "SketchAPI_Rotation.h"
72 #include "SketchAPI_Translation.h"
73 //--------------------------------------------------------------------------------------
74 #include <GeomAPI_Curve.h>
75 #include <GeomAPI_Dir2d.h>
76 #include <GeomAPI_PlanarEdges.h>
77 #include <GeomAPI_ShapeExplorer.h>
78 #include <GeomAPI_XY.h>
79 #include <GeomAlgoAPI_SketchBuilder.h>
83 //--------------------------------------------------------------------------------------
84 SketchAPI_Sketch::SketchAPI_Sketch(
85 const std::shared_ptr<ModelAPI_Feature> & theFeature)
86 : ModelHighAPI_Interface(theFeature)
91 SketchAPI_Sketch::SketchAPI_Sketch(
92 const std::shared_ptr<ModelAPI_Feature> & theFeature,
93 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
94 : ModelHighAPI_Interface(theFeature)
101 SketchAPI_Sketch::SketchAPI_Sketch(
102 const std::shared_ptr<ModelAPI_Feature> & theFeature,
103 const ModelHighAPI_Selection & theExternal)
104 : ModelHighAPI_Interface(theFeature)
107 setExternal(theExternal);
111 SketchAPI_Sketch::SketchAPI_Sketch(
112 const std::shared_ptr<ModelAPI_Feature> & theFeature,
113 std::shared_ptr<ModelAPI_Object> thePlaneObject)
114 : ModelHighAPI_Interface(theFeature)
117 setExternal(thePlaneObject);
121 SketchAPI_Sketch::~SketchAPI_Sketch()
126 //--------------------------------------------------------------------------------------
127 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
129 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
132 //--------------------------------------------------------------------------------------
133 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
135 fillAttribute(thePlane->origin(), myorigin);
136 fillAttribute(thePlane->dirX(), mydirX);
137 fillAttribute(thePlane->normal(), mynormal);
142 void SketchAPI_Sketch::setPlane(const ModelHighAPI_Selection & thePlane,
143 bool theRemoveExternalDependency)
145 FeaturePtr aSketch = feature();
147 DocumentPtr aDoc = aSketch->document();
148 bool useVisible = false;
149 FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
150 aDoc->setCurrentFeature(aSketch, useVisible);
152 if (theRemoveExternalDependency)
153 aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
155 setExternal(thePlane);
157 aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
160 //--------------------------------------------------------------------------------------
161 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
163 fillAttribute(theExternal, myexternal);
168 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
170 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
171 ModelHighAPI_Selection aSel(aRes);
175 //--------------------------------------------------------------------------------------
176 void SketchAPI_Sketch::setValue(
177 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
178 const ModelHighAPI_Double & theValue)
180 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
182 // theConstraint->execute();
185 //--------------------------------------------------------------------------------------
186 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
188 const_cast<SketchAPI_Sketch*>(this)->execute();
190 std::list<ModelHighAPI_Selection> aSelectionList;
192 ResultConstructionPtr aResultConstruction =
193 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
194 if (aResultConstruction.get() == NULL)
195 return aSelectionList;
197 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
198 aSelectionList.push_back(
199 ModelHighAPI_Selection(aResultConstruction,
200 aResultConstruction->face(anIndex)));
203 return aSelectionList;
206 //--------------------------------------------------------------------------------------
207 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
208 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
210 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
211 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
214 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
215 const ModelHighAPI_Selection & theExternal)
217 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
218 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
221 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
222 const std::string & theExternalName)
224 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
226 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
229 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
230 std::shared_ptr<ModelAPI_Object> thePlaneObject)
232 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
233 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
237 //--------------------------------------------------------------------------------------
238 std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
240 std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
241 std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
242 for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
243 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
244 PointPtr aPoint(new SketchAPI_Point(aFeature));
245 aFreePoints.push_back(aPoint);
250 //--------------------------------------------------------------------------------------
251 static GeomCurvePtr untrimmedCurve(GeomShapePtr theShape)
253 GeomCurvePtr aCurve(new GeomAPI_Curve(theShape));
254 if (aCurve->isTrimmed())
255 aCurve = aCurve->basisCurve();
259 void SketchAPI_Sketch::changeFacesOrder(
260 const std::list<std::list<ModelHighAPI_Selection> >& theFaces)
262 // collect faces of the sketch
263 ResultConstructionPtr aSketchResult =
264 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
265 if (!aSketchResult) {
266 // sketch is nested to a boolean operation, thus, it has no result yet.
267 feature()->execute();
269 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
271 std::list<GeomFacePtr> aFaces;
272 int aFacesNum = aSketchResult->facesNum();
273 for (int i = 0; i < aFacesNum; ++i)
274 aFaces.push_back(aSketchResult->face(i));
275 // find new faces order according to the given lists of edges
276 std::list<GeomFacePtr> aNewFacesOrder;
277 std::list<std::list<ModelHighAPI_Selection> >::const_iterator anIt = theFaces.begin();
278 for (; anIt != theFaces.end(); ++anIt) {
279 // find the appropriate face
280 std::list<GeomFacePtr>::iterator aFIt = aFaces.begin();
281 for (; aFIt != aFaces.end(); ++aFIt) {
282 std::list<ModelHighAPI_Selection>::const_iterator aEdgeIt = anIt->begin();
283 GeomAPI_ShapeExplorer aFExp(*aFIt, GeomAPI_Shape::EDGE);
284 for (; aEdgeIt != anIt->end() && aFExp.more(); ++aEdgeIt, aFExp.next()) {
285 ResultPtr aCurRes = aEdgeIt->resultSubShapePair().first;
288 GeomCurvePtr aCurve1 = untrimmedCurve(aCurRes->shape());
289 GeomCurvePtr aCurve2 = untrimmedCurve(aFExp.current());
290 if (!aCurve1->isEqual(aCurve2))
294 if (aEdgeIt == anIt->end() && !aFExp.more()) {
296 aNewFacesOrder.push_back(*aFIt);
302 // place the rest faces at the end of new faces list
304 aNewFacesOrder.insert(aNewFacesOrder.end(), aFaces.begin(), aFaces.end());
305 // update the result of the sketch with the new order of faces
306 aSketchResult->setFacesOrder(aNewFacesOrder);
309 //--------------------------------------------------------------------------------------
310 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
311 double theX, double theY)
313 std::shared_ptr<ModelAPI_Feature> aFeature =
314 compositeFeature()->addFeature(SketchPlugin_Point::ID());
315 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
317 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
318 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
320 std::shared_ptr<ModelAPI_Feature> aFeature =
321 compositeFeature()->addFeature(SketchPlugin_Point::ID());
322 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
324 std::shared_ptr<SketchAPI_Point>
325 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
327 std::shared_ptr<ModelAPI_Feature> aFeature =
328 compositeFeature()->addFeature(SketchPlugin_Point::ID());
329 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
331 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
333 std::shared_ptr<ModelAPI_Feature> aFeature =
334 compositeFeature()->addFeature(SketchPlugin_Point::ID());
335 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
338 //--------------------------------------------------------------------------------------
339 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
340 const ModelHighAPI_Selection & theExternal,
343 std::shared_ptr<ModelAPI_Feature> aFeature =
344 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
345 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
346 anIntersection->setIncludeToResult(theKeepResult);
347 return anIntersection;
349 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
350 const std::string & theExternalName,
353 std::shared_ptr<ModelAPI_Feature> aFeature =
354 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
355 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
356 anIntersection->setIncludeToResult(theKeepResult);
357 return anIntersection;
360 //--------------------------------------------------------------------------------------
361 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
362 double theX2, double theY2)
364 std::shared_ptr<ModelAPI_Feature> aFeature =
365 compositeFeature()->addFeature(SketchPlugin_Line::ID());
366 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
368 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
369 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
370 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
372 std::shared_ptr<ModelAPI_Feature> aFeature =
373 compositeFeature()->addFeature(SketchPlugin_Line::ID());
374 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
376 std::shared_ptr<SketchAPI_Line>
377 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
379 std::shared_ptr<ModelAPI_Feature> aFeature =
380 compositeFeature()->addFeature(SketchPlugin_Line::ID());
381 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
383 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
385 std::shared_ptr<ModelAPI_Feature> aFeature =
386 compositeFeature()->addFeature(SketchPlugin_Line::ID());
387 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
390 //--------------------------------------------------------------------------------------
391 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
392 double theX2, double theY2)
394 std::shared_ptr<ModelAPI_Feature> aFeature =
395 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
396 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
398 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
399 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
400 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
402 std::shared_ptr<ModelAPI_Feature> aFeature =
403 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
404 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
407 //--------------------------------------------------------------------------------------
408 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
412 std::shared_ptr<ModelAPI_Feature> aFeature =
413 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
414 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
417 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
418 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
421 std::shared_ptr<ModelAPI_Feature> aFeature =
422 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
423 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
426 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
431 std::shared_ptr<ModelAPI_Feature> aFeature =
432 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
433 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
434 thePassedX, thePassedY));
437 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
438 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
439 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
441 std::shared_ptr<ModelAPI_Feature> aFeature =
442 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
443 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
446 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
447 double theX2, double theY2,
448 double theX3, double theY3)
450 std::shared_ptr<ModelAPI_Feature> aFeature =
451 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
452 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
457 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
458 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
459 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
460 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
462 std::shared_ptr<ModelAPI_Feature> aFeature =
463 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
464 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
467 std::shared_ptr<SketchAPI_Circle>
468 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
470 std::shared_ptr<ModelAPI_Feature> aFeature =
471 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
472 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
475 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
477 std::shared_ptr<ModelAPI_Feature> aFeature =
478 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
479 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
482 //--------------------------------------------------------------------------------------
483 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
484 double theStartX, double theStartY,
485 double theEndX, double theEndY,
488 std::shared_ptr<ModelAPI_Feature> aFeature =
489 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
490 return ArcPtr(new SketchAPI_Arc(aFeature,
491 theCenterX, theCenterY,
492 theStartX, theStartY,
497 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
498 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
499 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
500 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
503 std::shared_ptr<ModelAPI_Feature> aFeature =
504 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
505 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
508 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
509 double theEndX, double theEndY,
510 double thePassedX, double thePassedY)
512 std::shared_ptr<ModelAPI_Feature> aFeature =
513 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
514 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
515 theStartX, theStartY,
517 thePassedX, thePassedY));
520 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
521 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
522 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
523 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
525 std::shared_ptr<ModelAPI_Feature> aFeature =
526 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
527 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
530 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
531 const ModelHighAPI_RefAttr& theTangentPoint,
532 double theEndX, double theEndY,
536 std::shared_ptr<ModelAPI_Feature> aFeature =
537 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
538 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
540 aMacroArc->setByTransversal(theTangentPoint, theEndX, theEndY, theInversed);
542 aMacroArc->setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
546 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
547 const ModelHighAPI_RefAttr& theTangentPoint,
548 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
552 std::shared_ptr<ModelAPI_Feature> aFeature =
553 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
554 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
556 aMacroArc->setByTransversal(theTangentPoint, theEnd, theInversed);
558 aMacroArc->setByTangent(theTangentPoint, theEnd, theInversed);
562 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
564 std::shared_ptr<ModelAPI_Feature> aFeature =
565 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
566 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
569 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
571 std::shared_ptr<ModelAPI_Feature> aFeature =
572 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
573 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
576 //--------------------------------------------------------------------------------------
577 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
578 double theCenterX, double theCenterY,
579 double theFocusX, double theFocusY,
580 double theMinorRadius)
582 std::shared_ptr<ModelAPI_Feature> aFeature =
583 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
584 return EllipsePtr(new SketchAPI_Ellipse(aFeature,
585 theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius));
588 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
589 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
590 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
591 double theMinorRadius)
593 std::shared_ptr<ModelAPI_Feature> aFeature =
594 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
595 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius));
598 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
599 double thePoint1X, double thePoint1Y,
600 double thePoint2X, double thePoint2Y,
601 double thePassedX, double thePassedY,
604 std::shared_ptr<ModelAPI_Feature> aFeature =
605 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
606 return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature,
607 thePoint1X, thePoint1Y, thePoint2X, thePoint2Y, thePassedX, thePassedY, isPoint1Center));
610 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
611 const PointOrReference& thePoint1,
612 const PointOrReference& thePoint2,
613 const PointOrReference& thePassedPoint,
616 std::shared_ptr<ModelAPI_Feature> aFeature =
617 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
618 MacroEllipsePtr anEllipse;
619 if (thePoint1.second.isEmpty() &&
620 thePoint2.second.isEmpty() &&
621 thePassedPoint.second.isEmpty()) {
622 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
623 thePoint1.first, thePoint2.first, thePassedPoint.first, isPoint1Center));
626 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
627 thePoint1.first, thePoint1.second,
628 thePoint2.first, thePoint2.second,
629 thePassedPoint.first, thePassedPoint.second,
635 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
636 const ModelHighAPI_Selection & theExternal)
638 std::shared_ptr<ModelAPI_Feature> aFeature =
639 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
640 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal));
643 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
644 const std::string & theExternalName)
646 std::shared_ptr<ModelAPI_Feature> aFeature =
647 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
648 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName));
651 //--------------------------------------------------------------------------------------
652 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
653 double theCenterX, double theCenterY,
654 double theFocusX, double theFocusY,
655 double theStartX, double theStartY,
656 double theEndX, double theEndY,
659 std::shared_ptr<ModelAPI_Feature> aFeature =
660 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
661 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature,
662 theCenterX, theCenterY,
663 theFocusX, theFocusY,
664 theStartX, theStartY,
669 std::shared_ptr<SketchAPI_MacroEllipticArc> SketchAPI_Sketch::addEllipticArc(
670 const PointOrReference& theCenter,
671 const PointOrReference& theMajorAxisPoint,
672 const PointOrReference& theStartPoint,
673 const PointOrReference& theEndPoint,
676 std::shared_ptr<ModelAPI_Feature> aFeature =
677 compositeFeature()->addFeature(SketchPlugin_MacroEllipticArc::ID());
678 return MacroEllipticArcPtr(new SketchAPI_MacroEllipticArc(aFeature,
679 theCenter.first, theCenter.second,
680 theMajorAxisPoint.first, theMajorAxisPoint.second,
681 theStartPoint.first, theStartPoint.second,
682 theEndPoint.first, theEndPoint.second,
686 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
687 const ModelHighAPI_Selection & theExternal)
689 std::shared_ptr<ModelAPI_Feature> aFeature =
690 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
691 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternal));
694 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
695 const std::string & theExternalName)
697 std::shared_ptr<ModelAPI_Feature> aFeature =
698 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
699 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternalName));
702 //--------------------------------------------------------------------------------------
704 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(
705 const ModelHighAPI_Selection & external,
707 const std::list<PointOrReference>& poles,
708 const std::list<ModelHighAPI_Double>& weights,
709 const std::list<ModelHighAPI_Double>& knots,
710 const std::list<ModelHighAPI_Integer>& multiplicities,
713 // split poles and references to other shapes
714 bool hasReference = false;
715 std::list<GeomPnt2dPtr> aPoints;
716 std::list<ModelHighAPI_RefAttr> aReferences;
717 for (std::list<PointOrReference>::const_iterator it = poles.begin(); it != poles.end(); ++it) {
718 aPoints.push_back(it->first);
719 aReferences.push_back(it->second);
720 if (!it->second.isEmpty())
725 CompositeFeaturePtr aSketch = compositeFeature();
727 // use macro-feature to create coincidences to referred features
728 FeaturePtr aMacroFeature = aSketch->addFeature(
729 periodic ? SketchPlugin_MacroBSplinePeriodic::ID() : SketchPlugin_MacroBSpline::ID());
730 AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
731 aMacroFeature->attribute(SketchPlugin_MacroBSpline::POLES_ID()));
732 AttributeDoubleArrayPtr aWeightsAttr =
733 aMacroFeature->data()->realArray(SketchPlugin_MacroBSpline::WEIGHTS_ID());
734 AttributeRefAttrListPtr aPolesRefAttr =
735 aMacroFeature->data()->refattrlist(SketchPlugin_MacroBSpline::REF_POLES_ID());
736 // always generate a control polygon to apply coincidences correctly
737 aMacroFeature->boolean(SketchPlugin_MacroBSpline::CONTROL_POLYGON_ID())->setValue(true);
738 // initialize B-spline attributes
739 fillAttribute(aPoints, aPolesAttr);
741 fillAttribute(std::list<ModelHighAPI_Double>(poles.size(), 1.0), aWeightsAttr);
743 fillAttribute(weights, aWeightsAttr);
744 fillAttribute(aReferences, aPolesRefAttr);
745 apply(); // to kill macro-feature
747 // find created B-spline feature
748 const std::string& aKindToFind =
749 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID();
750 int aNbSubs = aSketch->numberOfSubs();
751 for (int anIndex = aNbSubs - 1; anIndex >= 0; --anIndex) {
752 FeaturePtr aFeature = aSketch->subFeature(anIndex);
753 if (aFeature->getKind() == aKindToFind) {
754 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
755 : new SketchAPI_BSpline(aFeature));
762 // compute B-spline by parameters
763 FeaturePtr aFeature = aSketch->addFeature(
764 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
766 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
767 : new SketchAPI_BSpline(aFeature));
768 if (external.variantType() != ModelHighAPI_Selection::VT_Empty)
769 aBSpline->setByExternal(external);
770 else if (knots.empty() || multiplicities.empty())
771 aBSpline->setByDegreePolesAndWeights(degree, aPoints, weights);
773 aBSpline->setByParameters(degree, aPoints, weights, knots, multiplicities);
778 //--------------------------------------------------------------------------------------
779 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
780 const ModelHighAPI_Selection & theExternalFeature,
783 std::shared_ptr<ModelAPI_Feature> aFeature =
784 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
785 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
786 aProjection->setIncludeToResult(theKeepResult);
790 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
791 const std::string & theExternalName,
794 std::shared_ptr<ModelAPI_Feature> aFeature =
795 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
796 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
797 aProjection->setIncludeToResult(theKeepResult);
801 //--------------------------------------------------------------------------------------
802 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
803 const ModelHighAPI_RefAttr & theMirrorLine,
804 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
806 std::shared_ptr<ModelAPI_Feature> aFeature =
807 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
808 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
811 //--------------------------------------------------------------------------------------
812 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
813 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
814 const ModelHighAPI_RefAttr & thePoint1,
815 const ModelHighAPI_RefAttr & thePoint2,
816 const ModelHighAPI_Integer & theNumberOfObjects,
819 std::shared_ptr<ModelAPI_Feature> aFeature =
820 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
821 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
822 thePoint2, theNumberOfObjects, theFullValue));
825 //--------------------------------------------------------------------------------------
826 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
827 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
828 const ModelHighAPI_RefAttr & theCenter,
829 const ModelHighAPI_Double & theAngle,
830 const ModelHighAPI_Integer & theNumberOfObjects,
834 std::shared_ptr<ModelAPI_Feature> aFeature =
835 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
837 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
838 theAngle, theNumberOfObjects, theFullValue, theReversed));
841 //--------------------------------------------------------------------------------------
842 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
843 const ModelHighAPI_Reference& theFeature,
844 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
846 std::shared_ptr<ModelAPI_Feature> aFeature =
847 compositeFeature()->addFeature(SketchPlugin_Split::ID());
848 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
850 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
851 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
852 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
853 fillAttribute(thePositionPoint, aPointAttr);
856 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
859 //--------------------------------------------------------------------------------------
860 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
861 const ModelHighAPI_Reference& theFeature,
862 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
864 std::shared_ptr<ModelAPI_Feature> aFeature =
865 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
866 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
868 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
869 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
870 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
871 fillAttribute(thePositionPoint, aPointAttr);
874 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
877 //--------------------------------------------------------------------------------------
878 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
879 const ModelHighAPI_RefAttr & theLine1,
880 const ModelHighAPI_RefAttr & theLine2,
881 const ModelHighAPI_Double & theValue,
882 const std::string& theType)
884 std::shared_ptr<ModelAPI_Feature> aFeature =
885 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
887 const int aVersion = theType.empty() ? SketchPlugin_ConstraintAngle::THE_VERSION_0
888 : SketchPlugin_ConstraintAngle::THE_VERSION_1;
889 fillAttribute(aVersion, aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
891 int aType = (int)SketcherPrs_Tools::ANGLE_DIRECT;
892 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::PREV_TYPE_ID()));
893 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
895 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_0)
896 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
898 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
899 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
901 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_1) {
902 std::string aTypeLC = theType;
903 std::transform(aTypeLC.begin(), aTypeLC.end(), aTypeLC.begin(), ::tolower);
904 if (aTypeLC == "supplementary")
905 aType = (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
906 else if (aTypeLC == "backward")
907 aType = (int)SketcherPrs_Tools::ANGLE_BACKWARD;
909 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
910 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
914 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
917 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
918 const ModelHighAPI_RefAttr & theLine1,
919 const ModelHighAPI_RefAttr & theLine2,
920 const ModelHighAPI_Double & theValue)
922 std::shared_ptr<ModelAPI_Feature> aFeature =
923 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
924 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
925 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
926 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
927 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
928 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
929 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
930 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
932 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
935 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
936 const ModelHighAPI_RefAttr & theLine1,
937 const ModelHighAPI_RefAttr & theLine2,
938 const ModelHighAPI_Double & theValue)
940 std::shared_ptr<ModelAPI_Feature> aFeature =
941 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
942 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
943 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
944 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
945 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
946 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
947 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
948 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
950 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
953 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
954 const ModelHighAPI_RefAttr & thePoint1,
955 const ModelHighAPI_RefAttr & thePoint2)
957 std::shared_ptr<ModelAPI_Feature> aFeature =
958 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
959 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
960 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
962 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
965 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
966 const ModelHighAPI_RefAttr & theLine1,
967 const ModelHighAPI_RefAttr & theLine2)
969 std::shared_ptr<ModelAPI_Feature> aFeature =
970 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
971 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
972 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
974 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
977 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
978 const ModelHighAPI_RefAttr & thePoint,
979 const ModelHighAPI_RefAttr & thePointOrLine,
980 const ModelHighAPI_Double & theValue,
983 std::shared_ptr<ModelAPI_Feature> aFeature =
984 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
985 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
986 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
987 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
988 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
990 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
993 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
994 const ModelHighAPI_RefAttr & thePoint,
995 const ModelHighAPI_RefAttr & thePointOrLine,
996 const ModelHighAPI_Double & theValue)
998 return setDistance(thePoint, thePointOrLine, theValue, true);
1001 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
1002 const ModelHighAPI_RefAttr & thePoint,
1003 const ModelHighAPI_RefAttr & thePointOrLine,
1004 const ModelHighAPI_Double & theValue)
1006 return setDistance(thePoint, thePointOrLine, theValue, false);
1009 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
1010 const ModelHighAPI_RefAttr & thePoint1,
1011 const ModelHighAPI_RefAttr & thePoint2,
1012 const ModelHighAPI_Double & theValue)
1014 std::shared_ptr<ModelAPI_Feature> aFeature =
1015 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
1016 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1017 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1018 fillAttribute(theValue,
1019 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1020 aFeature->execute();
1021 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1024 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
1025 const ModelHighAPI_RefAttr & thePoint1,
1026 const ModelHighAPI_RefAttr & thePoint2,
1027 const ModelHighAPI_Double & theValue)
1029 std::shared_ptr<ModelAPI_Feature> aFeature =
1030 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
1031 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1032 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1033 fillAttribute(theValue,
1034 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1035 aFeature->execute();
1036 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1039 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
1040 const ModelHighAPI_RefAttr & theObject1,
1041 const ModelHighAPI_RefAttr & theObject2)
1043 std::shared_ptr<ModelAPI_Feature> aFeature =
1044 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
1045 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1046 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1047 aFeature->execute();
1048 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1051 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
1052 const ModelHighAPI_RefAttr & thePoint)
1054 std::shared_ptr<ModelAPI_Feature> aFeature =
1055 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
1056 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
1057 apply(); // finish operation to remove Fillet feature correcly
1058 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1061 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
1062 const ModelHighAPI_RefAttr & thePoint,
1063 const ModelHighAPI_Double & theRadius)
1065 CompositeFeaturePtr aSketch = compositeFeature();
1066 int aNbSubs = aSketch->numberOfSubs();
1069 InterfacePtr aFilletFeature = setFillet(thePoint);
1071 // set radius for just created arc
1072 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
1073 if (anArc->getKind() == SketchPlugin_Arc::ID())
1074 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
1076 return aFilletFeature;
1079 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
1080 const ModelHighAPI_RefAttr & theObject)
1082 std::shared_ptr<ModelAPI_Feature> aFeature =
1083 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
1084 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1085 aFeature->execute();
1086 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1089 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
1090 const ModelHighAPI_RefAttr & theLine)
1092 std::shared_ptr<ModelAPI_Feature> aFeature =
1093 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1094 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1095 aFeature->execute();
1096 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1099 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1100 const ModelHighAPI_RefAttr & theLine,
1101 const ModelHighAPI_Double & theValue)
1103 std::shared_ptr<ModelAPI_Feature> aFeature =
1104 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1105 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1106 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1107 aFeature->execute();
1108 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1111 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1112 const ModelHighAPI_RefAttr & thePoint,
1113 const ModelHighAPI_RefAttr & theLine)
1115 std::shared_ptr<ModelAPI_Feature> aFeature =
1116 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1117 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1118 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1119 aFeature->execute();
1120 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1123 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1124 const ModelHighAPI_RefAttr & theLine1,
1125 const ModelHighAPI_RefAttr & theLine2)
1127 std::shared_ptr<ModelAPI_Feature> aFeature =
1128 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1129 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1130 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1131 aFeature->execute();
1132 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1135 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1136 const ModelHighAPI_RefAttr & theLine1,
1137 const ModelHighAPI_RefAttr & theLine2)
1139 std::shared_ptr<ModelAPI_Feature> aFeature =
1140 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1141 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1142 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1143 aFeature->execute();
1144 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1147 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1148 const ModelHighAPI_RefAttr & theCircleOrArc,
1149 const ModelHighAPI_Double & theValue)
1151 std::shared_ptr<ModelAPI_Feature> aFeature =
1152 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1153 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1154 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1155 aFeature->execute();
1156 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1159 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1160 const ModelHighAPI_RefAttr & theLine,
1161 const ModelHighAPI_RefAttr & theCircle)
1163 std::shared_ptr<ModelAPI_Feature> aFeature =
1164 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1165 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1166 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1167 aFeature->execute();
1168 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1171 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1172 const ModelHighAPI_RefAttr & theLine)
1174 std::shared_ptr<ModelAPI_Feature> aFeature =
1175 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1176 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1177 aFeature->execute();
1178 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1181 //--------------------------------------------------------------------------------------
1183 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1185 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1186 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1189 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1191 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1192 theFeature->attribute(SketchPlugin_Line::START_ID()));
1193 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1194 theFeature->attribute(SketchPlugin_Line::END_ID()));
1196 if (!aStartAttr || !aEndAttr)
1197 return std::shared_ptr<GeomAPI_Pnt2d>();
1199 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1200 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1201 return std::shared_ptr<GeomAPI_Pnt2d>(
1202 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1205 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1207 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1208 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1209 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1211 if (!aCenter || !aRadius)
1212 return std::shared_ptr<GeomAPI_Pnt2d>();
1214 return std::shared_ptr<GeomAPI_Pnt2d>(
1215 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1218 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1220 static const double PI = 3.141592653589793238463;
1222 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1223 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1224 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1225 theFeature->attribute(SketchPlugin_Arc::START_ID()));
1226 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1227 theFeature->attribute(SketchPlugin_Arc::END_ID()));
1229 if (!aCenterAttr || !aStartAttr || !aEndAttr)
1230 return std::shared_ptr<GeomAPI_Pnt2d>();
1232 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1233 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1234 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1235 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1237 double anAngle = aStartDir->angle(aEndDir);
1238 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1239 if (isReversed && anAngle > 0.)
1240 anAngle -= 2.0 * PI;
1241 else if (!isReversed && anAngle <= 0.)
1242 anAngle += 2.0 * PI;
1244 double cosA = cos(anAngle);
1245 double sinA = sin(anAngle);
1247 // rotate start dir to find middle point on arc
1248 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1249 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1250 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1252 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1255 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1256 bool isEllipse = true)
1258 const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1259 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1260 AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1261 theFeature->attribute(anAttrName));
1262 return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1265 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnBSpline(const FeaturePtr& theFeature,
1266 SketchAPI_Sketch* theSketch)
1268 GeomAPI_Edge anEdge(theFeature->lastResult()->shape());
1269 GeomPointPtr aMiddle = anEdge.middlePoint();
1270 return theSketch->to2D(aMiddle);
1273 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject,
1274 SketchAPI_Sketch* theSketch)
1276 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1277 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1279 // move only features of the following types
1280 const std::string& aFeatureKind = aFeature->getKind();
1281 if (aFeatureKind == SketchPlugin_Point::ID())
1282 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1283 else if (aFeatureKind == SketchPlugin_Line::ID())
1284 aMiddlePoint = middlePointOnLine(aFeature);
1285 else if (aFeatureKind == SketchPlugin_Circle::ID())
1286 aMiddlePoint = pointOnCircle(aFeature);
1287 else if (aFeatureKind == SketchPlugin_Arc::ID())
1288 aMiddlePoint = middlePointOnArc(aFeature);
1289 else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1290 aMiddlePoint = pointOnEllipse(aFeature);
1291 else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1292 aMiddlePoint = pointOnEllipse(aFeature, false);
1293 else if (aFeatureKind == SketchPlugin_BSpline::ID() ||
1294 aFeatureKind == SketchPlugin_BSplinePeriodic::ID())
1295 aMiddlePoint = middlePointOnBSpline(aFeature, theSketch);
1297 return aMiddlePoint;
1300 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1301 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1303 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1304 theMovedEntity.fillMessage(aMessage);
1306 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1307 if (aMessage->movedAttribute())
1308 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1310 anOriginalPosition = middlePoint(aMessage->movedObject(), this);
1312 if (!anOriginalPosition)
1313 return; // something has gone wrong, do not process movement
1315 aMessage->setOriginalPosition(anOriginalPosition);
1316 aMessage->setCurrentPosition(theTargetPoint);
1317 Events_Loop::loop()->send(aMessage);
1320 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1321 double theTargetX, double theTargetY)
1323 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1324 move(theMovedEntity, aTargetPoint);
1327 //--------------------------------------------------------------------------------------
1329 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1331 FeaturePtr aBase = feature();
1332 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1333 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1334 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1335 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1336 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1337 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1338 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1340 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1343 //--------------------------------------------------------------------------------------
1345 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1347 // collect edges of the first face
1348 std::list<GeomShapePtr> anEdges1;
1349 for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1350 anEdges1.push_back(anExp.current());
1351 // compare edges of faces
1352 for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1353 GeomShapePtr aCurrent = anExp.current();
1354 bool isFound = false;
1355 std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1356 for (; anIt1 != anEdges1.end(); ++anIt1)
1357 if (aCurrent->isSameGeometry(*anIt1)) {
1359 anEdges1.erase(anIt1);
1365 return !anEdges1.empty();
1368 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1370 ResultConstructionPtr aSketchResult =
1371 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1375 std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1376 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1380 // collect faces constructed by SketchBuilder algorithm
1381 GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1382 aWires->norm(), aWires);
1383 const ListOfShape& aFaces = aSketchBuilder.faces();
1385 // compare faces stored in sketch with faces generated by SketchBuilder
1386 int aNbSketchFaces = aSketchResult->facesNum();
1388 for (ListOfShape::const_iterator aFIt = aFaces.begin();
1389 aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1390 ++aFIt, ++aFaceIndex) {
1391 GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1392 GeomFacePtr aCurFace = (*aFIt)->face();
1393 if (isDifferent(aSketchFace, aCurFace))
1399 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1400 std::list<std::list<ResultPtr> >& theEdges)
1402 ResultConstructionPtr aSketchResult =
1403 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1407 // collect curves of the sketch
1408 std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1409 int aSubNum = theSketch->numberOfSubs();
1410 for (int a = 0; a < aSubNum; ++a) {
1411 FeaturePtr aSub = theSketch->subFeature(a);
1412 const std::list<ResultPtr>& aResults = aSub->results();
1413 std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1414 for (; aRes != aResults.cend(); aRes++) {
1415 GeomShapePtr aCurShape = (*aRes)->shape();
1416 if (aCurShape && aCurShape->isEdge())
1417 aCurves[untrimmedCurve(aCurShape)] = *aRes;
1421 // convert each face to the list of results of its edges
1422 int aFacesNum = aSketchResult->facesNum();
1423 for (int a = 0; a < aFacesNum; ++a) {
1424 theEdges.push_back(std::list<ResultPtr>());
1425 std::list<ResultPtr>& aCurEdges = theEdges.back();
1427 GeomFacePtr aFace = aSketchResult->face(a);
1428 for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1429 anExp.more(); anExp.next()) {
1430 GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1431 aCurEdges.push_back(aCurves[aCurrent]);
1436 //--------------------------------------------------------------------------------------
1438 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1440 FeaturePtr aBase = feature();
1441 const std::string& aDocName = theDumper.name(aBase->document());
1443 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1444 if (anExternal->value()) {
1445 theDumper << aBase << " = model.addSketch(" << aDocName <<
1446 ", " << anExternal << ")" << std::endl;
1448 // Sketch is base on a plane.
1449 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1450 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1451 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1452 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1453 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1454 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1456 // Check the plane is coordinate plane
1457 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1458 if(anExternal->context()) { // checking for selected planes
1459 if (!aPlaneName.empty()
1460 && anExternal->context()->data()
1461 && anExternal->context()->data()->name() == aPlaneName) {
1462 // dump sketch based on coordinate plane
1463 theDumper << aBase << " = model.addSketch(" << aDocName
1464 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1465 } else { // some other plane
1466 theDumper << aBase << " = model.addSketch(" << aDocName <<
1467 ", " << anExternal<< ")" << std::endl;
1470 if (aPlaneName.empty()) {
1471 // needs import additional module
1472 theDumper.importModule("GeomAPI");
1473 // dump plane parameters
1474 const std::string& aSketchName = theDumper.name(aBase);
1475 std::string anOriginName = aSketchName + "_origin";
1476 std::string aNormalName = aSketchName + "_norm";
1477 std::string aDirXName = aSketchName + "_dirx";
1478 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1479 // and then dumplicate dumping it in the next line
1480 theDumper << anOriginName << " = " << anOrigin << "\n"
1481 << aNormalName << " = " << aNormal << "\n"
1482 << aDirXName << " = " << aDirX << "\n";
1483 // dump sketch based on arbitrary plane
1484 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1485 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1487 // dump sketch based on coordinate plane
1488 theDumper << aBase << " = model.addSketch(" << aDocName
1489 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1494 // dump sketch's subfeatures
1495 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1496 theDumper.processSubs(aCompFeat, true);
1498 // if face order differs to the order generated by SketchBuilder,
1499 // dump the list of faces for correct execution of the script
1500 if (isCustomFacesOrder(aCompFeat)) {
1501 std::list<std::list<ResultPtr> > aFaces;
1502 edgesOfSketchFaces(aCompFeat, aFaces);
1504 const std::string& aSketchName = theDumper.name(aBase);
1505 std::string aMethodName(".changeFacesOrder");
1506 std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1508 theDumper << aSketchName << aMethodName << "([";
1509 for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1510 aFIt != aFaces.end(); ++aFIt) {
1511 if (aFIt != aFaces.begin())
1512 theDumper << ",\n" << aSpaceShift << " ";
1515 theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1516 // call model.do() for correct update of the document's labels related to the changed faces
1517 theDumper << "model.do()" << std::endl;