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 <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(), ::tolower);
922 if (aTypeLC == "supplementary")
923 aType = (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
924 else if (aTypeLC == "backward")
925 aType = (int)SketcherPrs_Tools::ANGLE_BACKWARD;
927 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
928 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
932 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
935 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
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_COMPLEMENTARY,
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::setAngleBackward(
954 const ModelHighAPI_RefAttr & theLine1,
955 const ModelHighAPI_RefAttr & theLine2,
956 const ModelHighAPI_Double & theValue)
958 std::shared_ptr<ModelAPI_Feature> aFeature =
959 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
960 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
961 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
962 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
963 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
964 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
965 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
966 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
968 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
971 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
972 const ModelHighAPI_RefAttr & thePoint1,
973 const ModelHighAPI_RefAttr & thePoint2)
975 std::shared_ptr<ModelAPI_Feature> aFeature =
976 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
977 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
978 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
980 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
983 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
984 const ModelHighAPI_RefAttr & theLine1,
985 const ModelHighAPI_RefAttr & theLine2)
987 std::shared_ptr<ModelAPI_Feature> aFeature =
988 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
989 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
990 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
992 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
995 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
996 const ModelHighAPI_RefAttr & thePoint,
997 const ModelHighAPI_RefAttr & thePointOrLine,
998 const ModelHighAPI_Double & theValue,
1001 std::shared_ptr<ModelAPI_Feature> aFeature =
1002 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
1003 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1004 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1005 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1006 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
1007 aFeature->execute();
1008 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1011 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
1012 const ModelHighAPI_RefAttr & thePoint,
1013 const ModelHighAPI_RefAttr & thePointOrLine,
1014 const ModelHighAPI_Double & theValue)
1016 return setDistance(thePoint, thePointOrLine, theValue, true);
1019 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
1020 const ModelHighAPI_RefAttr & thePoint,
1021 const ModelHighAPI_RefAttr & thePointOrLine,
1022 const ModelHighAPI_Double & theValue)
1024 return setDistance(thePoint, thePointOrLine, theValue, false);
1027 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
1028 const ModelHighAPI_RefAttr & thePoint1,
1029 const ModelHighAPI_RefAttr & thePoint2,
1030 const ModelHighAPI_Double & theValue)
1032 std::shared_ptr<ModelAPI_Feature> aFeature =
1033 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
1034 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1035 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1036 fillAttribute(theValue,
1037 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1038 aFeature->execute();
1039 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1042 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
1043 const ModelHighAPI_RefAttr & thePoint1,
1044 const ModelHighAPI_RefAttr & thePoint2,
1045 const ModelHighAPI_Double & theValue)
1047 std::shared_ptr<ModelAPI_Feature> aFeature =
1048 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
1049 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1050 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1051 fillAttribute(theValue,
1052 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1053 aFeature->execute();
1054 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1057 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
1058 const ModelHighAPI_RefAttr & theObject1,
1059 const ModelHighAPI_RefAttr & theObject2)
1061 std::shared_ptr<ModelAPI_Feature> aFeature =
1062 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
1063 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1064 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1065 aFeature->execute();
1066 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1069 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
1070 const ModelHighAPI_RefAttr & thePoint)
1072 std::shared_ptr<ModelAPI_Feature> aFeature =
1073 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
1074 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
1075 apply(); // finish operation to remove Fillet feature correcly
1076 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1079 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
1080 const ModelHighAPI_RefAttr & thePoint,
1081 const ModelHighAPI_Double & theRadius)
1083 CompositeFeaturePtr aSketch = compositeFeature();
1084 int aNbSubs = aSketch->numberOfSubs();
1087 InterfacePtr aFilletFeature = setFillet(thePoint);
1089 // set radius for just created arc
1090 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
1091 if (anArc->getKind() == SketchPlugin_Arc::ID())
1092 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
1094 return aFilletFeature;
1097 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
1098 const ModelHighAPI_RefAttr & theObject)
1100 std::shared_ptr<ModelAPI_Feature> aFeature =
1101 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
1102 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1103 aFeature->execute();
1104 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1107 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
1108 const ModelHighAPI_RefAttr & theLine)
1110 std::shared_ptr<ModelAPI_Feature> aFeature =
1111 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1112 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1113 aFeature->execute();
1114 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1117 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1118 const ModelHighAPI_RefAttr & theLine,
1119 const ModelHighAPI_Double & theValue)
1121 std::shared_ptr<ModelAPI_Feature> aFeature =
1122 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1123 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1124 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1125 aFeature->execute();
1126 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1129 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1130 const ModelHighAPI_RefAttr & thePoint,
1131 const ModelHighAPI_RefAttr & theLine)
1133 std::shared_ptr<ModelAPI_Feature> aFeature =
1134 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1135 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1136 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1137 aFeature->execute();
1138 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1141 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1142 const ModelHighAPI_RefAttr & theLine1,
1143 const ModelHighAPI_RefAttr & theLine2)
1145 std::shared_ptr<ModelAPI_Feature> aFeature =
1146 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1147 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1148 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1149 aFeature->execute();
1150 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1153 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1154 const ModelHighAPI_RefAttr & theLine1,
1155 const ModelHighAPI_RefAttr & theLine2)
1157 std::shared_ptr<ModelAPI_Feature> aFeature =
1158 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1159 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1160 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1161 aFeature->execute();
1162 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1165 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1166 const ModelHighAPI_RefAttr & theCircleOrArc,
1167 const ModelHighAPI_Double & theValue)
1169 std::shared_ptr<ModelAPI_Feature> aFeature =
1170 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1171 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1172 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1173 aFeature->execute();
1174 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1177 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1178 const ModelHighAPI_RefAttr & theLine,
1179 const ModelHighAPI_RefAttr & theCircle)
1181 std::shared_ptr<ModelAPI_Feature> aFeature =
1182 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1183 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1184 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1185 aFeature->execute();
1186 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1189 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1190 const ModelHighAPI_RefAttr & theLine)
1192 std::shared_ptr<ModelAPI_Feature> aFeature =
1193 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1194 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1195 aFeature->execute();
1196 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1199 //--------------------------------------------------------------------------------------
1201 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1203 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1204 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1207 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1209 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1210 theFeature->attribute(SketchPlugin_Line::START_ID()));
1211 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1212 theFeature->attribute(SketchPlugin_Line::END_ID()));
1214 if (!aStartAttr || !aEndAttr)
1215 return std::shared_ptr<GeomAPI_Pnt2d>();
1217 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1218 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1219 return std::shared_ptr<GeomAPI_Pnt2d>(
1220 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1223 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1225 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1226 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1227 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1229 if (!aCenter || !aRadius)
1230 return std::shared_ptr<GeomAPI_Pnt2d>();
1232 return std::shared_ptr<GeomAPI_Pnt2d>(
1233 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1236 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1238 static const double PI = 3.141592653589793238463;
1240 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1241 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1242 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1243 theFeature->attribute(SketchPlugin_Arc::START_ID()));
1244 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1245 theFeature->attribute(SketchPlugin_Arc::END_ID()));
1247 if (!aCenterAttr || !aStartAttr || !aEndAttr)
1248 return std::shared_ptr<GeomAPI_Pnt2d>();
1250 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1251 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1252 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1253 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1255 double anAngle = aStartDir->angle(aEndDir);
1256 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1257 if (isReversed && anAngle > 0.)
1258 anAngle -= 2.0 * PI;
1259 else if (!isReversed && anAngle <= 0.)
1260 anAngle += 2.0 * PI;
1262 double cosA = cos(anAngle);
1263 double sinA = sin(anAngle);
1265 // rotate start dir to find middle point on arc
1266 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1267 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1268 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1270 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1273 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1274 bool isEllipse = true)
1276 const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1277 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1278 AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1279 theFeature->attribute(anAttrName));
1280 return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1283 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnBSpline(const FeaturePtr& theFeature,
1284 SketchAPI_Sketch* theSketch)
1286 GeomAPI_Edge anEdge(theFeature->lastResult()->shape());
1287 GeomPointPtr aMiddle = anEdge.middlePoint();
1288 return theSketch->to2D(aMiddle);
1291 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject,
1292 SketchAPI_Sketch* theSketch)
1294 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1295 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1297 // move only features of the following types
1298 const std::string& aFeatureKind = aFeature->getKind();
1299 if (aFeatureKind == SketchPlugin_Point::ID())
1300 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1301 else if (aFeatureKind == SketchPlugin_Line::ID())
1302 aMiddlePoint = middlePointOnLine(aFeature);
1303 else if (aFeatureKind == SketchPlugin_Circle::ID())
1304 aMiddlePoint = pointOnCircle(aFeature);
1305 else if (aFeatureKind == SketchPlugin_Arc::ID())
1306 aMiddlePoint = middlePointOnArc(aFeature);
1307 else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1308 aMiddlePoint = pointOnEllipse(aFeature);
1309 else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1310 aMiddlePoint = pointOnEllipse(aFeature, false);
1311 else if (aFeatureKind == SketchPlugin_BSpline::ID() ||
1312 aFeatureKind == SketchPlugin_BSplinePeriodic::ID())
1313 aMiddlePoint = middlePointOnBSpline(aFeature, theSketch);
1315 return aMiddlePoint;
1318 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1319 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1321 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1322 theMovedEntity.fillMessage(aMessage);
1324 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1325 if (aMessage->movedAttribute())
1326 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1328 anOriginalPosition = middlePoint(aMessage->movedObject(), this);
1330 if (!anOriginalPosition)
1331 return; // something has gone wrong, do not process movement
1333 aMessage->setOriginalPosition(anOriginalPosition);
1334 aMessage->setCurrentPosition(theTargetPoint);
1335 Events_Loop::loop()->send(aMessage);
1338 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1339 double theTargetX, double theTargetY)
1341 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1342 move(theMovedEntity, aTargetPoint);
1345 //--------------------------------------------------------------------------------------
1347 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1349 FeaturePtr aBase = feature();
1350 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1351 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1352 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1353 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1354 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1355 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1356 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1358 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1361 //--------------------------------------------------------------------------------------
1363 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1365 // collect edges of the first face
1366 std::list<GeomShapePtr> anEdges1;
1367 for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1368 anEdges1.push_back(anExp.current());
1369 // compare edges of faces
1370 for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1371 GeomShapePtr aCurrent = anExp.current();
1372 bool isFound = false;
1373 std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1374 for (; anIt1 != anEdges1.end(); ++anIt1)
1375 if (aCurrent->isSameGeometry(*anIt1)) {
1377 anEdges1.erase(anIt1);
1383 return !anEdges1.empty();
1386 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1388 ResultConstructionPtr aSketchResult =
1389 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1393 std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1394 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1398 // collect faces constructed by SketchBuilder algorithm
1399 GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1400 aWires->norm(), aWires);
1401 const ListOfShape& aFaces = aSketchBuilder.faces();
1403 // compare faces stored in sketch with faces generated by SketchBuilder
1404 int aNbSketchFaces = aSketchResult->facesNum();
1406 for (ListOfShape::const_iterator aFIt = aFaces.begin();
1407 aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1408 ++aFIt, ++aFaceIndex) {
1409 GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1410 GeomFacePtr aCurFace = (*aFIt)->face();
1411 if (isDifferent(aSketchFace, aCurFace))
1417 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1418 std::list<std::list<ResultPtr> >& theEdges)
1420 ResultConstructionPtr aSketchResult =
1421 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1425 // collect curves of the sketch
1426 std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1427 int aSubNum = theSketch->numberOfSubs();
1428 for (int a = 0; a < aSubNum; ++a) {
1429 FeaturePtr aSub = theSketch->subFeature(a);
1430 const std::list<ResultPtr>& aResults = aSub->results();
1431 std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1432 for (; aRes != aResults.cend(); aRes++) {
1433 GeomShapePtr aCurShape = (*aRes)->shape();
1434 if (aCurShape && aCurShape->isEdge())
1435 aCurves[untrimmedCurve(aCurShape)] = *aRes;
1439 // convert each face to the list of results of its edges
1440 int aFacesNum = aSketchResult->facesNum();
1441 for (int a = 0; a < aFacesNum; ++a) {
1442 theEdges.push_back(std::list<ResultPtr>());
1443 std::list<ResultPtr>& aCurEdges = theEdges.back();
1445 GeomFacePtr aFace = aSketchResult->face(a);
1446 for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1447 anExp.more(); anExp.next()) {
1448 GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1449 aCurEdges.push_back(aCurves[aCurrent]);
1454 //--------------------------------------------------------------------------------------
1456 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1458 FeaturePtr aBase = feature();
1459 const std::string& aDocName = theDumper.name(aBase->document());
1461 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1462 if (anExternal->value()) {
1463 theDumper << aBase << " = model.addSketch(" << aDocName <<
1464 ", " << anExternal << ")" << std::endl;
1466 // Sketch is base on a plane.
1467 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1468 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1469 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1470 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1471 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1472 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1474 // Check the plane is coordinate plane
1475 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1476 if(anExternal->context()) { // checking for selected planes
1477 if (!aPlaneName.empty()
1478 && anExternal->context()->data()
1479 && anExternal->context()->data()->name() == aPlaneName) {
1480 // dump sketch based on coordinate plane
1481 theDumper << aBase << " = model.addSketch(" << aDocName
1482 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1483 } else { // some other plane
1484 theDumper << aBase << " = model.addSketch(" << aDocName <<
1485 ", " << anExternal<< ")" << std::endl;
1488 if (aPlaneName.empty()) {
1489 // needs import additional module
1490 theDumper.importModule("GeomAPI");
1491 // dump plane parameters
1492 const std::string& aSketchName = theDumper.name(aBase);
1493 std::string anOriginName = aSketchName + "_origin";
1494 std::string aNormalName = aSketchName + "_norm";
1495 std::string aDirXName = aSketchName + "_dirx";
1496 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1497 // and then dumplicate dumping it in the next line
1498 theDumper << anOriginName << " = " << anOrigin << "\n"
1499 << aNormalName << " = " << aNormal << "\n"
1500 << aDirXName << " = " << aDirX << "\n";
1501 // dump sketch based on arbitrary plane
1502 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1503 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1505 // dump sketch based on coordinate plane
1506 theDumper << aBase << " = model.addSketch(" << aDocName
1507 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1512 // dump sketch's subfeatures
1513 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1514 theDumper.processSubs(aCompFeat, true);
1516 // if face order differs to the order generated by SketchBuilder,
1517 // dump the list of faces for correct execution of the script
1518 if (isCustomFacesOrder(aCompFeat)) {
1519 std::list<std::list<ResultPtr> > aFaces;
1520 edgesOfSketchFaces(aCompFeat, aFaces);
1522 const std::string& aSketchName = theDumper.name(aBase);
1523 std::string aMethodName(".changeFacesOrder");
1524 std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1526 theDumper << aSketchName << aMethodName << "([";
1527 for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1528 aFIt != aFaces.end(); ++aFIt) {
1529 if (aFIt != aFaces.begin())
1530 theDumper << ",\n" << aSpaceShift << " ";
1533 theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1534 // call model.do() for correct update of the document's labels related to the changed faces
1535 theDumper << "model.do()" << std::endl;