1 // Copyright (C) 2014-2020 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 <SketchPlugin_SketchCopy.h>
45 #include <SketcherPrs_Tools.h>
46 //--------------------------------------------------------------------------------------
47 #include <ModelAPI_Events.h>
48 #include <ModelAPI_CompositeFeature.h>
49 #include <ModelAPI_ResultConstruction.h>
50 #include <ModelHighAPI_Double.h>
51 #include <ModelHighAPI_Dumper.h>
52 #include <ModelHighAPI_RefAttr.h>
53 #include <ModelHighAPI_Selection.h>
54 #include <ModelHighAPI_Services.h>
55 #include <ModelHighAPI_Tools.h>
56 //--------------------------------------------------------------------------------------
57 #include "SketchAPI_Arc.h"
58 #include "SketchAPI_BSpline.h"
59 #include "SketchAPI_Circle.h"
60 #include "SketchAPI_Ellipse.h"
61 #include "SketchAPI_EllipticArc.h"
62 #include "SketchAPI_IntersectionPoint.h"
63 #include "SketchAPI_Line.h"
64 #include "SketchAPI_MacroArc.h"
65 #include "SketchAPI_MacroCircle.h"
66 #include "SketchAPI_MacroEllipse.h"
67 #include "SketchAPI_MacroEllipticArc.h"
68 #include "SketchAPI_Mirror.h"
69 #include "SketchAPI_Point.h"
70 #include "SketchAPI_Projection.h"
71 #include "SketchAPI_Rectangle.h"
72 #include "SketchAPI_Rotation.h"
73 #include "SketchAPI_Translation.h"
74 //--------------------------------------------------------------------------------------
75 #include <GeomAPI_Curve.h>
76 #include <GeomAPI_Dir2d.h>
77 #include <GeomAPI_PlanarEdges.h>
78 #include <GeomAPI_ShapeExplorer.h>
79 #include <GeomAPI_XY.h>
80 #include <GeomAlgoAPI_SketchBuilder.h>
84 //--------------------------------------------------------------------------------------
85 SketchAPI_Sketch::SketchAPI_Sketch(
86 const std::shared_ptr<ModelAPI_Feature> & theFeature)
87 : ModelHighAPI_Interface(theFeature)
92 SketchAPI_Sketch::SketchAPI_Sketch(
93 const std::shared_ptr<ModelAPI_Feature> & theFeature,
94 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
95 : ModelHighAPI_Interface(theFeature)
102 SketchAPI_Sketch::SketchAPI_Sketch(
103 const std::shared_ptr<ModelAPI_Feature> & theFeature,
104 const ModelHighAPI_Selection & theExternal)
105 : ModelHighAPI_Interface(theFeature)
108 setExternal(theExternal);
112 SketchAPI_Sketch::SketchAPI_Sketch(
113 const std::shared_ptr<ModelAPI_Feature> & theFeature,
114 std::shared_ptr<ModelAPI_Object> thePlaneObject)
115 : ModelHighAPI_Interface(theFeature)
118 setExternal(thePlaneObject);
122 SketchAPI_Sketch::~SketchAPI_Sketch()
127 //--------------------------------------------------------------------------------------
128 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
130 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
133 //--------------------------------------------------------------------------------------
134 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
136 fillAttribute(thePlane->origin(), myorigin);
137 fillAttribute(thePlane->dirX(), mydirX);
138 fillAttribute(thePlane->normal(), mynormal);
143 void SketchAPI_Sketch::setPlane(const ModelHighAPI_Selection & thePlane,
144 bool theRemoveExternalDependency)
146 FeaturePtr aSketch = feature();
148 DocumentPtr aDoc = aSketch->document();
149 bool useVisible = false;
150 FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
151 aDoc->setCurrentFeature(aSketch, useVisible);
153 if (theRemoveExternalDependency)
154 aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
156 setExternal(thePlane);
158 aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
161 //--------------------------------------------------------------------------------------
162 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
164 fillAttribute(theExternal, myexternal);
169 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
171 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
172 ModelHighAPI_Selection aSel(aRes);
176 //--------------------------------------------------------------------------------------
177 void SketchAPI_Sketch::setValue(
178 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
179 const ModelHighAPI_Double & theValue)
181 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
183 // theConstraint->execute();
186 //--------------------------------------------------------------------------------------
187 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
189 const_cast<SketchAPI_Sketch*>(this)->execute();
191 std::list<ModelHighAPI_Selection> aSelectionList;
193 ResultConstructionPtr aResultConstruction =
194 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
195 if (aResultConstruction.get() == NULL)
196 return aSelectionList;
198 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
199 aSelectionList.push_back(
200 ModelHighAPI_Selection(aResultConstruction,
201 aResultConstruction->face(anIndex)));
204 return aSelectionList;
207 //--------------------------------------------------------------------------------------
208 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
209 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
211 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
212 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
215 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
216 const ModelHighAPI_Selection & theExternal)
218 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
219 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
222 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
223 const std::string & theExternalName)
225 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
227 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
230 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
231 std::shared_ptr<ModelAPI_Object> thePlaneObject)
233 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
234 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
237 //--------------------------------------------------------------------------------------
238 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
239 const SketchPtr & theSketch)
241 FeaturePtr aCopyer = thePart->addFeature(SketchPlugin_SketchCopy::ID());
242 aCopyer->reference(SketchPlugin_SketchCopy::BASE_ID())->setValue(theSketch->feature());
245 FeaturePtr aNewSketch = thePart->nextFeature(aCopyer);
247 // perform removing the macro-feature
248 thePart->removeFeature(aCopyer);
251 return SketchPtr(new SketchAPI_Sketch(aNewSketch));
255 //--------------------------------------------------------------------------------------
256 std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
258 std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
259 std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
260 for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
261 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
262 PointPtr aPoint(new SketchAPI_Point(aFeature));
263 aFreePoints.push_back(aPoint);
268 //--------------------------------------------------------------------------------------
269 static GeomCurvePtr untrimmedCurve(GeomShapePtr theShape)
271 GeomCurvePtr aCurve(new GeomAPI_Curve(theShape));
272 if (aCurve->isTrimmed())
273 aCurve = aCurve->basisCurve();
277 void SketchAPI_Sketch::changeFacesOrder(
278 const std::list<std::list<ModelHighAPI_Selection> >& theFaces)
280 // collect faces of the sketch
281 ResultConstructionPtr aSketchResult =
282 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
283 if (!aSketchResult) {
284 // sketch is nested to a boolean operation, thus, it has no result yet.
285 feature()->execute();
287 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
289 std::list<GeomFacePtr> aFaces;
290 int aFacesNum = aSketchResult->facesNum();
291 for (int i = 0; i < aFacesNum; ++i)
292 aFaces.push_back(aSketchResult->face(i));
293 // find new faces order according to the given lists of edges
294 std::list<GeomFacePtr> aNewFacesOrder;
295 std::list<std::list<ModelHighAPI_Selection> >::const_iterator anIt = theFaces.begin();
296 for (; anIt != theFaces.end(); ++anIt) {
297 // find the appropriate face
298 std::list<GeomFacePtr>::iterator aFIt = aFaces.begin();
299 for (; aFIt != aFaces.end(); ++aFIt) {
300 std::list<ModelHighAPI_Selection>::const_iterator aEdgeIt = anIt->begin();
301 GeomAPI_ShapeExplorer aFExp(*aFIt, GeomAPI_Shape::EDGE);
302 for (; aEdgeIt != anIt->end() && aFExp.more(); ++aEdgeIt, aFExp.next()) {
303 ResultPtr aCurRes = aEdgeIt->resultSubShapePair().first;
306 GeomCurvePtr aCurve1 = untrimmedCurve(aCurRes->shape());
307 GeomCurvePtr aCurve2 = untrimmedCurve(aFExp.current());
308 if (!aCurve1->isEqual(aCurve2))
312 if (aEdgeIt == anIt->end() && !aFExp.more()) {
314 aNewFacesOrder.push_back(*aFIt);
320 // place the rest faces at the end of new faces list
322 aNewFacesOrder.insert(aNewFacesOrder.end(), aFaces.begin(), aFaces.end());
323 // update the result of the sketch with the new order of faces
324 aSketchResult->setFacesOrder(aNewFacesOrder);
327 //--------------------------------------------------------------------------------------
328 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
329 double theX, double theY)
331 std::shared_ptr<ModelAPI_Feature> aFeature =
332 compositeFeature()->addFeature(SketchPlugin_Point::ID());
333 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
335 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
336 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
338 std::shared_ptr<ModelAPI_Feature> aFeature =
339 compositeFeature()->addFeature(SketchPlugin_Point::ID());
340 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
342 std::shared_ptr<SketchAPI_Point>
343 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
345 std::shared_ptr<ModelAPI_Feature> aFeature =
346 compositeFeature()->addFeature(SketchPlugin_Point::ID());
347 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
349 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
351 std::shared_ptr<ModelAPI_Feature> aFeature =
352 compositeFeature()->addFeature(SketchPlugin_Point::ID());
353 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
356 //--------------------------------------------------------------------------------------
357 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
358 const ModelHighAPI_Selection & theExternal,
361 std::shared_ptr<ModelAPI_Feature> aFeature =
362 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
363 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
364 anIntersection->setIncludeToResult(theKeepResult);
365 return anIntersection;
367 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
368 const std::string & theExternalName,
371 std::shared_ptr<ModelAPI_Feature> aFeature =
372 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
373 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
374 anIntersection->setIncludeToResult(theKeepResult);
375 return anIntersection;
378 //--------------------------------------------------------------------------------------
379 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
380 double theX2, double theY2)
382 std::shared_ptr<ModelAPI_Feature> aFeature =
383 compositeFeature()->addFeature(SketchPlugin_Line::ID());
384 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
386 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
387 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
388 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
390 std::shared_ptr<ModelAPI_Feature> aFeature =
391 compositeFeature()->addFeature(SketchPlugin_Line::ID());
392 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
394 std::shared_ptr<SketchAPI_Line>
395 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
397 std::shared_ptr<ModelAPI_Feature> aFeature =
398 compositeFeature()->addFeature(SketchPlugin_Line::ID());
399 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
401 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
403 std::shared_ptr<ModelAPI_Feature> aFeature =
404 compositeFeature()->addFeature(SketchPlugin_Line::ID());
405 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
408 //--------------------------------------------------------------------------------------
409 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
410 double theX2, double theY2)
412 std::shared_ptr<ModelAPI_Feature> aFeature =
413 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
414 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
416 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
417 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
418 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
420 std::shared_ptr<ModelAPI_Feature> aFeature =
421 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
422 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
425 //--------------------------------------------------------------------------------------
426 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
430 std::shared_ptr<ModelAPI_Feature> aFeature =
431 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
432 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
435 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
436 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
439 std::shared_ptr<ModelAPI_Feature> aFeature =
440 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
441 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
444 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
449 std::shared_ptr<ModelAPI_Feature> aFeature =
450 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
451 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
452 thePassedX, thePassedY));
455 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
456 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
457 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
459 std::shared_ptr<ModelAPI_Feature> aFeature =
460 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
461 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
464 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
465 double theX2, double theY2,
466 double theX3, double theY3)
468 std::shared_ptr<ModelAPI_Feature> aFeature =
469 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
470 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
475 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
476 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
477 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
478 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
480 std::shared_ptr<ModelAPI_Feature> aFeature =
481 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
482 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
485 std::shared_ptr<SketchAPI_Circle>
486 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
488 std::shared_ptr<ModelAPI_Feature> aFeature =
489 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
490 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
493 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
495 std::shared_ptr<ModelAPI_Feature> aFeature =
496 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
497 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
500 //--------------------------------------------------------------------------------------
501 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
502 double theStartX, double theStartY,
503 double theEndX, double theEndY,
506 std::shared_ptr<ModelAPI_Feature> aFeature =
507 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
508 return ArcPtr(new SketchAPI_Arc(aFeature,
509 theCenterX, theCenterY,
510 theStartX, theStartY,
515 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
516 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
517 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
518 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
521 std::shared_ptr<ModelAPI_Feature> aFeature =
522 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
523 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
526 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
527 double theEndX, double theEndY,
528 double thePassedX, double thePassedY)
530 std::shared_ptr<ModelAPI_Feature> aFeature =
531 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
532 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
533 theStartX, theStartY,
535 thePassedX, thePassedY));
538 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
539 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
540 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
541 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
543 std::shared_ptr<ModelAPI_Feature> aFeature =
544 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
545 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
548 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
549 const ModelHighAPI_RefAttr& theTangentPoint,
550 double theEndX, double theEndY,
554 std::shared_ptr<ModelAPI_Feature> aFeature =
555 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
556 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
558 aMacroArc->setByTransversal(theTangentPoint, theEndX, theEndY, theInversed);
560 aMacroArc->setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
564 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
565 const ModelHighAPI_RefAttr& theTangentPoint,
566 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
570 std::shared_ptr<ModelAPI_Feature> aFeature =
571 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
572 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
574 aMacroArc->setByTransversal(theTangentPoint, theEnd, theInversed);
576 aMacroArc->setByTangent(theTangentPoint, theEnd, theInversed);
580 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
582 std::shared_ptr<ModelAPI_Feature> aFeature =
583 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
584 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
587 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
589 std::shared_ptr<ModelAPI_Feature> aFeature =
590 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
591 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
594 //--------------------------------------------------------------------------------------
595 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
596 double theCenterX, double theCenterY,
597 double theFocusX, double theFocusY,
598 double theMinorRadius)
600 std::shared_ptr<ModelAPI_Feature> aFeature =
601 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
602 return EllipsePtr(new SketchAPI_Ellipse(aFeature,
603 theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius));
606 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
607 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
608 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
609 double theMinorRadius)
611 std::shared_ptr<ModelAPI_Feature> aFeature =
612 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
613 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius));
616 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
617 double thePoint1X, double thePoint1Y,
618 double thePoint2X, double thePoint2Y,
619 double thePassedX, double thePassedY,
622 std::shared_ptr<ModelAPI_Feature> aFeature =
623 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
624 return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature,
625 thePoint1X, thePoint1Y, thePoint2X, thePoint2Y, thePassedX, thePassedY, isPoint1Center));
628 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
629 const PointOrReference& thePoint1,
630 const PointOrReference& thePoint2,
631 const PointOrReference& thePassedPoint,
634 std::shared_ptr<ModelAPI_Feature> aFeature =
635 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
636 MacroEllipsePtr anEllipse;
637 if (thePoint1.second.isEmpty() &&
638 thePoint2.second.isEmpty() &&
639 thePassedPoint.second.isEmpty()) {
640 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
641 thePoint1.first, thePoint2.first, thePassedPoint.first, isPoint1Center));
644 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
645 thePoint1.first, thePoint1.second,
646 thePoint2.first, thePoint2.second,
647 thePassedPoint.first, thePassedPoint.second,
653 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
654 const ModelHighAPI_Selection & theExternal)
656 std::shared_ptr<ModelAPI_Feature> aFeature =
657 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
658 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal));
661 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
662 const std::string & theExternalName)
664 std::shared_ptr<ModelAPI_Feature> aFeature =
665 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
666 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName));
669 //--------------------------------------------------------------------------------------
670 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
671 double theCenterX, double theCenterY,
672 double theFocusX, double theFocusY,
673 double theStartX, double theStartY,
674 double theEndX, double theEndY,
677 std::shared_ptr<ModelAPI_Feature> aFeature =
678 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
679 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature,
680 theCenterX, theCenterY,
681 theFocusX, theFocusY,
682 theStartX, theStartY,
687 std::shared_ptr<SketchAPI_MacroEllipticArc> SketchAPI_Sketch::addEllipticArc(
688 const PointOrReference& theCenter,
689 const PointOrReference& theMajorAxisPoint,
690 const PointOrReference& theStartPoint,
691 const PointOrReference& theEndPoint,
694 std::shared_ptr<ModelAPI_Feature> aFeature =
695 compositeFeature()->addFeature(SketchPlugin_MacroEllipticArc::ID());
696 return MacroEllipticArcPtr(new SketchAPI_MacroEllipticArc(aFeature,
697 theCenter.first, theCenter.second,
698 theMajorAxisPoint.first, theMajorAxisPoint.second,
699 theStartPoint.first, theStartPoint.second,
700 theEndPoint.first, theEndPoint.second,
704 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
705 const ModelHighAPI_Selection & theExternal)
707 std::shared_ptr<ModelAPI_Feature> aFeature =
708 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
709 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternal));
712 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
713 const std::string & theExternalName)
715 std::shared_ptr<ModelAPI_Feature> aFeature =
716 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
717 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternalName));
720 //--------------------------------------------------------------------------------------
722 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(
723 const ModelHighAPI_Selection & external,
725 const std::list<PointOrReference>& poles,
726 const std::list<ModelHighAPI_Double>& weights,
727 const std::list<ModelHighAPI_Double>& knots,
728 const std::list<ModelHighAPI_Integer>& multiplicities,
731 // split poles and references to other shapes
732 bool hasReference = false;
733 std::list<GeomPnt2dPtr> aPoints;
734 std::list<ModelHighAPI_RefAttr> aReferences;
735 for (std::list<PointOrReference>::const_iterator it = poles.begin(); it != poles.end(); ++it) {
736 aPoints.push_back(it->first);
737 aReferences.push_back(it->second);
738 if (!it->second.isEmpty())
743 CompositeFeaturePtr aSketch = compositeFeature();
745 // use macro-feature to create coincidences to referred features
746 FeaturePtr aMacroFeature = aSketch->addFeature(
747 periodic ? SketchPlugin_MacroBSplinePeriodic::ID() : SketchPlugin_MacroBSpline::ID());
748 AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
749 aMacroFeature->attribute(SketchPlugin_MacroBSpline::POLES_ID()));
750 AttributeDoubleArrayPtr aWeightsAttr =
751 aMacroFeature->data()->realArray(SketchPlugin_MacroBSpline::WEIGHTS_ID());
752 AttributeRefAttrListPtr aPolesRefAttr =
753 aMacroFeature->data()->refattrlist(SketchPlugin_MacroBSpline::REF_POLES_ID());
754 // always generate a control polygon to apply coincidences correctly
755 aMacroFeature->boolean(SketchPlugin_MacroBSpline::CONTROL_POLYGON_ID())->setValue(true);
756 // initialize B-spline attributes
757 fillAttribute(aPoints, aPolesAttr);
759 fillAttribute(std::list<ModelHighAPI_Double>(poles.size(), 1.0), aWeightsAttr);
761 fillAttribute(weights, aWeightsAttr);
762 fillAttribute(aReferences, aPolesRefAttr);
763 apply(); // to kill macro-feature
765 // find created B-spline feature
766 const std::string& aKindToFind =
767 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID();
768 int aNbSubs = aSketch->numberOfSubs();
769 for (int anIndex = aNbSubs - 1; anIndex >= 0; --anIndex) {
770 FeaturePtr aFeature = aSketch->subFeature(anIndex);
771 if (aFeature->getKind() == aKindToFind) {
772 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
773 : new SketchAPI_BSpline(aFeature));
780 // compute B-spline by parameters
781 FeaturePtr aFeature = aSketch->addFeature(
782 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
784 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
785 : new SketchAPI_BSpline(aFeature));
786 if (external.variantType() != ModelHighAPI_Selection::VT_Empty)
787 aBSpline->setByExternal(external);
788 else if (knots.empty() || multiplicities.empty())
789 aBSpline->setByDegreePolesAndWeights(degree, aPoints, weights);
791 aBSpline->setByParameters(degree, aPoints, weights, knots, multiplicities);
796 //--------------------------------------------------------------------------------------
797 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
798 const ModelHighAPI_Selection & theExternalFeature,
801 std::shared_ptr<ModelAPI_Feature> aFeature =
802 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
803 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
804 aProjection->setIncludeToResult(theKeepResult);
808 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
809 const std::string & theExternalName,
812 std::shared_ptr<ModelAPI_Feature> aFeature =
813 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
814 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
815 aProjection->setIncludeToResult(theKeepResult);
819 //--------------------------------------------------------------------------------------
820 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
821 const ModelHighAPI_RefAttr & theMirrorLine,
822 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
824 std::shared_ptr<ModelAPI_Feature> aFeature =
825 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
826 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
829 //--------------------------------------------------------------------------------------
830 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
831 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
832 const ModelHighAPI_RefAttr & thePoint1,
833 const ModelHighAPI_RefAttr & thePoint2,
834 const ModelHighAPI_Integer & theNumberOfObjects,
837 std::shared_ptr<ModelAPI_Feature> aFeature =
838 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
839 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
840 thePoint2, theNumberOfObjects, theFullValue));
843 //--------------------------------------------------------------------------------------
844 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
845 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
846 const ModelHighAPI_RefAttr & theCenter,
847 const ModelHighAPI_Double & theAngle,
848 const ModelHighAPI_Integer & theNumberOfObjects,
852 std::shared_ptr<ModelAPI_Feature> aFeature =
853 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
855 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
856 theAngle, theNumberOfObjects, theFullValue, theReversed));
859 //--------------------------------------------------------------------------------------
860 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
861 const ModelHighAPI_Reference& theFeature,
862 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
864 std::shared_ptr<ModelAPI_Feature> aFeature =
865 compositeFeature()->addFeature(SketchPlugin_Split::ID());
866 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
868 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::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::addTrim(
879 const ModelHighAPI_Reference& theFeature,
880 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
882 std::shared_ptr<ModelAPI_Feature> aFeature =
883 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
884 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
886 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
887 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
888 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
889 fillAttribute(thePositionPoint, aPointAttr);
892 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
895 //--------------------------------------------------------------------------------------
896 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
897 const ModelHighAPI_RefAttr & theLine1,
898 const ModelHighAPI_RefAttr & theLine2,
899 const ModelHighAPI_Double & theValue,
900 const std::string& theType)
902 std::shared_ptr<ModelAPI_Feature> aFeature =
903 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
905 const int aVersion = theType.empty() ? SketchPlugin_ConstraintAngle::THE_VERSION_0
906 : SketchPlugin_ConstraintAngle::THE_VERSION_1;
907 fillAttribute(aVersion, aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
909 int aType = (int)SketcherPrs_Tools::ANGLE_DIRECT;
910 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::PREV_TYPE_ID()));
911 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
913 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_0)
914 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
916 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
917 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
919 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_1) {
920 std::string aTypeLC = theType;
921 std::transform(aTypeLC.begin(), aTypeLC.end(), aTypeLC.begin(),
922 [](char c) { return static_cast<char>(::tolower(c)); });
923 if (aTypeLC == "supplementary")
924 aType = (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
925 else if (aTypeLC == "backward")
926 aType = (int)SketcherPrs_Tools::ANGLE_BACKWARD;
928 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
929 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
933 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
936 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
937 const ModelHighAPI_RefAttr & theLine1,
938 const ModelHighAPI_RefAttr & theLine2,
939 const ModelHighAPI_Double & theValue)
941 std::shared_ptr<ModelAPI_Feature> aFeature =
942 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
943 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
944 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
945 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
946 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
947 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
948 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
949 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
951 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
954 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
955 const ModelHighAPI_RefAttr & theLine1,
956 const ModelHighAPI_RefAttr & theLine2,
957 const ModelHighAPI_Double & theValue)
959 std::shared_ptr<ModelAPI_Feature> aFeature =
960 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
961 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
962 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
963 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
964 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
965 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
966 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
967 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
969 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
972 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
973 const ModelHighAPI_RefAttr & thePoint1,
974 const ModelHighAPI_RefAttr & thePoint2)
976 std::shared_ptr<ModelAPI_Feature> aFeature =
977 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
978 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
979 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
981 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
984 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
985 const ModelHighAPI_RefAttr & theLine1,
986 const ModelHighAPI_RefAttr & theLine2)
988 std::shared_ptr<ModelAPI_Feature> aFeature =
989 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
990 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
991 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
993 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
996 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
997 const ModelHighAPI_RefAttr & thePoint,
998 const ModelHighAPI_RefAttr & thePointOrLine,
999 const ModelHighAPI_Double & theValue,
1002 std::shared_ptr<ModelAPI_Feature> aFeature =
1003 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
1004 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1005 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1006 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1007 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
1008 aFeature->execute();
1009 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1012 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
1013 const ModelHighAPI_RefAttr & thePoint,
1014 const ModelHighAPI_RefAttr & thePointOrLine,
1015 const ModelHighAPI_Double & theValue)
1017 return setDistance(thePoint, thePointOrLine, theValue, true);
1020 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
1021 const ModelHighAPI_RefAttr & thePoint,
1022 const ModelHighAPI_RefAttr & thePointOrLine,
1023 const ModelHighAPI_Double & theValue)
1025 return setDistance(thePoint, thePointOrLine, theValue, false);
1028 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
1029 const ModelHighAPI_RefAttr & thePoint1,
1030 const ModelHighAPI_RefAttr & thePoint2,
1031 const ModelHighAPI_Double & theValue)
1033 std::shared_ptr<ModelAPI_Feature> aFeature =
1034 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
1035 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1036 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1037 fillAttribute(theValue,
1038 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1039 aFeature->execute();
1040 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1043 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
1044 const ModelHighAPI_RefAttr & thePoint1,
1045 const ModelHighAPI_RefAttr & thePoint2,
1046 const ModelHighAPI_Double & theValue)
1048 std::shared_ptr<ModelAPI_Feature> aFeature =
1049 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
1050 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1051 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1052 fillAttribute(theValue,
1053 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1054 aFeature->execute();
1055 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1058 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
1059 const ModelHighAPI_RefAttr & theObject1,
1060 const ModelHighAPI_RefAttr & theObject2)
1062 std::shared_ptr<ModelAPI_Feature> aFeature =
1063 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
1064 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1065 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1066 aFeature->execute();
1067 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1070 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
1071 const ModelHighAPI_RefAttr & thePoint)
1073 std::shared_ptr<ModelAPI_Feature> aFeature =
1074 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
1075 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
1076 apply(); // finish operation to remove Fillet feature correcly
1077 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1080 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
1081 const ModelHighAPI_RefAttr & thePoint,
1082 const ModelHighAPI_Double & theRadius)
1084 CompositeFeaturePtr aSketch = compositeFeature();
1085 int aNbSubs = aSketch->numberOfSubs();
1088 InterfacePtr aFilletFeature = setFillet(thePoint);
1090 // set radius for just created arc
1091 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
1092 if (anArc->getKind() == SketchPlugin_Arc::ID())
1093 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
1095 return aFilletFeature;
1098 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
1099 const ModelHighAPI_RefAttr & theObject)
1101 std::shared_ptr<ModelAPI_Feature> aFeature =
1102 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
1103 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1104 aFeature->execute();
1105 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1108 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
1109 const ModelHighAPI_RefAttr & theLine)
1111 std::shared_ptr<ModelAPI_Feature> aFeature =
1112 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1113 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1114 aFeature->execute();
1115 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1118 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1119 const ModelHighAPI_RefAttr & theLine,
1120 const ModelHighAPI_Double & theValue)
1122 std::shared_ptr<ModelAPI_Feature> aFeature =
1123 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1124 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1125 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1126 aFeature->execute();
1127 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1130 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1131 const ModelHighAPI_RefAttr & thePoint,
1132 const ModelHighAPI_RefAttr & theLine)
1134 std::shared_ptr<ModelAPI_Feature> aFeature =
1135 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1136 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1137 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1138 aFeature->execute();
1139 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1142 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1143 const ModelHighAPI_RefAttr & theLine1,
1144 const ModelHighAPI_RefAttr & theLine2)
1146 std::shared_ptr<ModelAPI_Feature> aFeature =
1147 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1148 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1149 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1150 aFeature->execute();
1151 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1154 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1155 const ModelHighAPI_RefAttr & theLine1,
1156 const ModelHighAPI_RefAttr & theLine2)
1158 std::shared_ptr<ModelAPI_Feature> aFeature =
1159 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1160 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1161 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1162 aFeature->execute();
1163 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1166 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1167 const ModelHighAPI_RefAttr & theCircleOrArc,
1168 const ModelHighAPI_Double & theValue)
1170 std::shared_ptr<ModelAPI_Feature> aFeature =
1171 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1172 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1173 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1174 aFeature->execute();
1175 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1178 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1179 const ModelHighAPI_RefAttr & theLine,
1180 const ModelHighAPI_RefAttr & theCircle)
1182 std::shared_ptr<ModelAPI_Feature> aFeature =
1183 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1184 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1185 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1186 aFeature->execute();
1187 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1190 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1191 const ModelHighAPI_RefAttr & theLine)
1193 std::shared_ptr<ModelAPI_Feature> aFeature =
1194 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1195 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1196 aFeature->execute();
1197 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1200 //--------------------------------------------------------------------------------------
1202 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1204 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1205 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1208 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1210 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1211 theFeature->attribute(SketchPlugin_Line::START_ID()));
1212 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1213 theFeature->attribute(SketchPlugin_Line::END_ID()));
1215 if (!aStartAttr || !aEndAttr)
1216 return std::shared_ptr<GeomAPI_Pnt2d>();
1218 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1219 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1220 return std::shared_ptr<GeomAPI_Pnt2d>(
1221 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1224 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1226 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1227 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1228 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1230 if (!aCenter || !aRadius)
1231 return std::shared_ptr<GeomAPI_Pnt2d>();
1233 return std::shared_ptr<GeomAPI_Pnt2d>(
1234 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1237 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1239 static const double PI = 3.141592653589793238463;
1241 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1242 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1243 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1244 theFeature->attribute(SketchPlugin_Arc::START_ID()));
1245 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1246 theFeature->attribute(SketchPlugin_Arc::END_ID()));
1248 if (!aCenterAttr || !aStartAttr || !aEndAttr)
1249 return std::shared_ptr<GeomAPI_Pnt2d>();
1251 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1252 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1253 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1254 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1256 double anAngle = aStartDir->angle(aEndDir);
1257 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1258 if (isReversed && anAngle > 0.)
1259 anAngle -= 2.0 * PI;
1260 else if (!isReversed && anAngle <= 0.)
1261 anAngle += 2.0 * PI;
1263 double cosA = cos(anAngle);
1264 double sinA = sin(anAngle);
1266 // rotate start dir to find middle point on arc
1267 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1268 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1269 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1271 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1274 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1275 bool isEllipse = true)
1277 const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1278 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1279 AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1280 theFeature->attribute(anAttrName));
1281 return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1284 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnBSpline(const FeaturePtr& theFeature,
1285 SketchAPI_Sketch* theSketch)
1287 GeomAPI_Edge anEdge(theFeature->lastResult()->shape());
1288 GeomPointPtr aMiddle = anEdge.middlePoint();
1289 return theSketch->to2D(aMiddle);
1292 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject,
1293 SketchAPI_Sketch* theSketch)
1295 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1296 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1298 // move only features of the following types
1299 const std::string& aFeatureKind = aFeature->getKind();
1300 if (aFeatureKind == SketchPlugin_Point::ID())
1301 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1302 else if (aFeatureKind == SketchPlugin_Line::ID())
1303 aMiddlePoint = middlePointOnLine(aFeature);
1304 else if (aFeatureKind == SketchPlugin_Circle::ID())
1305 aMiddlePoint = pointOnCircle(aFeature);
1306 else if (aFeatureKind == SketchPlugin_Arc::ID())
1307 aMiddlePoint = middlePointOnArc(aFeature);
1308 else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1309 aMiddlePoint = pointOnEllipse(aFeature);
1310 else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1311 aMiddlePoint = pointOnEllipse(aFeature, false);
1312 else if (aFeatureKind == SketchPlugin_BSpline::ID() ||
1313 aFeatureKind == SketchPlugin_BSplinePeriodic::ID())
1314 aMiddlePoint = middlePointOnBSpline(aFeature, theSketch);
1316 return aMiddlePoint;
1319 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1320 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1322 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1323 theMovedEntity.fillMessage(aMessage);
1325 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1326 if (aMessage->movedAttribute())
1327 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1329 anOriginalPosition = middlePoint(aMessage->movedObject(), this);
1331 if (!anOriginalPosition)
1332 return; // something has gone wrong, do not process movement
1334 aMessage->setOriginalPosition(anOriginalPosition);
1335 aMessage->setCurrentPosition(theTargetPoint);
1336 Events_Loop::loop()->send(aMessage);
1339 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1340 double theTargetX, double theTargetY)
1342 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1343 move(theMovedEntity, aTargetPoint);
1346 //--------------------------------------------------------------------------------------
1348 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1350 FeaturePtr aBase = feature();
1351 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1352 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1353 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1354 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1355 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1356 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1357 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1359 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1362 //--------------------------------------------------------------------------------------
1364 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1366 // collect edges of the first face
1367 std::list<GeomShapePtr> anEdges1;
1368 for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1369 anEdges1.push_back(anExp.current());
1370 // compare edges of faces
1371 for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1372 GeomShapePtr aCurrent = anExp.current();
1373 bool isFound = false;
1374 std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1375 for (; anIt1 != anEdges1.end(); ++anIt1)
1376 if (aCurrent->isSameGeometry(*anIt1)) {
1378 anEdges1.erase(anIt1);
1384 return !anEdges1.empty();
1387 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1389 ResultConstructionPtr aSketchResult =
1390 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1394 std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1395 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1399 // collect faces constructed by SketchBuilder algorithm
1400 GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1401 aWires->norm(), aWires);
1402 const ListOfShape& aFaces = aSketchBuilder.faces();
1404 // compare faces stored in sketch with faces generated by SketchBuilder
1405 int aNbSketchFaces = aSketchResult->facesNum();
1407 for (ListOfShape::const_iterator aFIt = aFaces.begin();
1408 aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1409 ++aFIt, ++aFaceIndex) {
1410 GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1411 GeomFacePtr aCurFace = (*aFIt)->face();
1412 if (isDifferent(aSketchFace, aCurFace))
1418 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1419 std::list<std::list<ResultPtr> >& theEdges)
1421 ResultConstructionPtr aSketchResult =
1422 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1426 // collect curves of the sketch
1427 std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1428 int aSubNum = theSketch->numberOfSubs();
1429 for (int a = 0; a < aSubNum; ++a) {
1430 FeaturePtr aSub = theSketch->subFeature(a);
1431 const std::list<ResultPtr>& aResults = aSub->results();
1432 std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1433 for (; aRes != aResults.cend(); aRes++) {
1434 GeomShapePtr aCurShape = (*aRes)->shape();
1435 if (aCurShape && aCurShape->isEdge())
1436 aCurves[untrimmedCurve(aCurShape)] = *aRes;
1440 // convert each face to the list of results of its edges
1441 int aFacesNum = aSketchResult->facesNum();
1442 for (int a = 0; a < aFacesNum; ++a) {
1443 theEdges.push_back(std::list<ResultPtr>());
1444 std::list<ResultPtr>& aCurEdges = theEdges.back();
1446 GeomFacePtr aFace = aSketchResult->face(a);
1447 for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1448 anExp.more(); anExp.next()) {
1449 GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1450 aCurEdges.push_back(aCurves[aCurrent]);
1455 //--------------------------------------------------------------------------------------
1457 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1459 FeaturePtr aBase = feature();
1460 const std::string& aDocName = theDumper.name(aBase->document());
1462 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1463 if (anExternal->value()) {
1464 theDumper << aBase << " = model.addSketch(" << aDocName <<
1465 ", " << anExternal << ")" << std::endl;
1467 // Sketch is base on a plane.
1468 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1469 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1470 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1471 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1472 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1473 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1475 // Check the plane is coordinate plane
1476 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1477 if(anExternal->context()) { // checking for selected planes
1478 if (!aPlaneName.empty()
1479 && anExternal->context()->data()
1480 && anExternal->context()->data()->name() == aPlaneName) {
1481 // dump sketch based on coordinate plane
1482 theDumper << aBase << " = model.addSketch(" << aDocName
1483 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1484 } else { // some other plane
1485 theDumper << aBase << " = model.addSketch(" << aDocName <<
1486 ", " << anExternal<< ")" << std::endl;
1489 if (aPlaneName.empty()) {
1490 // needs import additional module
1491 theDumper.importModule("GeomAPI");
1492 // dump plane parameters
1493 const std::string& aSketchName = theDumper.name(aBase);
1494 std::string anOriginName = aSketchName + "_origin";
1495 std::string aNormalName = aSketchName + "_norm";
1496 std::string aDirXName = aSketchName + "_dirx";
1497 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1498 // and then dumplicate dumping it in the next line
1499 theDumper << anOriginName << " = " << anOrigin << "\n"
1500 << aNormalName << " = " << aNormal << "\n"
1501 << aDirXName << " = " << aDirX << "\n";
1502 // dump sketch based on arbitrary plane
1503 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1504 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1506 // dump sketch based on coordinate plane
1507 theDumper << aBase << " = model.addSketch(" << aDocName
1508 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1513 // dump sketch's subfeatures
1514 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1515 theDumper.processSubs(aCompFeat, true);
1517 // if face order differs to the order generated by SketchBuilder,
1518 // dump the list of faces for correct execution of the script
1519 if (isCustomFacesOrder(aCompFeat)) {
1520 std::list<std::list<ResultPtr> > aFaces;
1521 edgesOfSketchFaces(aCompFeat, aFaces);
1523 const std::string& aSketchName = theDumper.name(aBase);
1524 std::string aMethodName(".changeFacesOrder");
1525 std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1527 theDumper << aSketchName << aMethodName << "([";
1528 for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1529 aFIt != aFaces.end(); ++aFIt) {
1530 if (aFIt != aFaces.begin())
1531 theDumper << ",\n" << aSpaceShift << " ";
1534 theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1535 // call model.do() for correct update of the document's labels related to the changed faces
1536 theDumper << "model.do()" << std::endl;