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_CurveFitting.h>
40 #include <SketchPlugin_Trim.h>
41 #include <SketchPlugin_Split.h>
42 #include <SketchPlugin_ConstraintTangent.h>
43 #include <SketchPlugin_ConstraintVertical.h>
44 #include <SketchPlugin_MacroBSpline.h>
45 #include <SketchPlugin_SketchCopy.h>
46 #include <SketchPlugin_Offset.h>
47 #include <SketcherPrs_Tools.h>
48 //--------------------------------------------------------------------------------------
49 #include <ModelAPI_Events.h>
50 #include <ModelAPI_CompositeFeature.h>
51 #include <ModelAPI_ResultConstruction.h>
52 #include <ModelHighAPI_Double.h>
53 #include <ModelHighAPI_Dumper.h>
54 #include <ModelHighAPI_RefAttr.h>
55 #include <ModelHighAPI_Selection.h>
56 #include <ModelHighAPI_Services.h>
57 #include <ModelHighAPI_Tools.h>
58 //--------------------------------------------------------------------------------------
59 #include "SketchAPI_Arc.h"
60 #include "SketchAPI_BSpline.h"
61 #include "SketchAPI_Circle.h"
62 #include "SketchAPI_Ellipse.h"
63 #include "SketchAPI_EllipticArc.h"
64 #include "SketchAPI_IntersectionPoint.h"
65 #include "SketchAPI_Line.h"
66 #include "SketchAPI_MacroArc.h"
67 #include "SketchAPI_MacroCircle.h"
68 #include "SketchAPI_MacroEllipse.h"
69 #include "SketchAPI_MacroEllipticArc.h"
70 #include "SketchAPI_Mirror.h"
71 #include "SketchAPI_Offset.h"
72 #include "SketchAPI_Point.h"
73 #include "SketchAPI_Projection.h"
74 #include "SketchAPI_Rectangle.h"
75 #include "SketchAPI_Rotation.h"
76 #include "SketchAPI_Translation.h"
77 //--------------------------------------------------------------------------------------
78 #include <GeomAPI_Curve.h>
79 #include <GeomAPI_Dir2d.h>
80 #include <GeomAPI_PlanarEdges.h>
81 #include <GeomAPI_ShapeExplorer.h>
82 #include <GeomAPI_XY.h>
83 #include <GeomAlgoAPI_SketchBuilder.h>
87 //--------------------------------------------------------------------------------------
88 SketchAPI_Sketch::SketchAPI_Sketch(
89 const std::shared_ptr<ModelAPI_Feature> & theFeature)
90 : ModelHighAPI_Interface(theFeature)
95 SketchAPI_Sketch::SketchAPI_Sketch(
96 const std::shared_ptr<ModelAPI_Feature> & theFeature,
97 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
98 : ModelHighAPI_Interface(theFeature)
105 SketchAPI_Sketch::SketchAPI_Sketch(
106 const std::shared_ptr<ModelAPI_Feature> & theFeature,
107 const ModelHighAPI_Selection & theExternal)
108 : ModelHighAPI_Interface(theFeature)
111 setExternal(theExternal);
115 SketchAPI_Sketch::SketchAPI_Sketch(
116 const std::shared_ptr<ModelAPI_Feature> & theFeature,
117 std::shared_ptr<ModelAPI_Object> thePlaneObject)
118 : ModelHighAPI_Interface(theFeature)
121 setExternal(thePlaneObject);
125 SketchAPI_Sketch::~SketchAPI_Sketch()
130 //--------------------------------------------------------------------------------------
131 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
133 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
136 //--------------------------------------------------------------------------------------
137 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
139 fillAttribute(thePlane->origin(), myorigin);
140 fillAttribute(thePlane->dirX(), mydirX);
141 fillAttribute(thePlane->normal(), mynormal);
146 void SketchAPI_Sketch::setPlane(const ModelHighAPI_Selection & thePlane,
147 bool theRemoveExternalDependency)
149 FeaturePtr aSketch = feature();
151 DocumentPtr aDoc = aSketch->document();
152 bool useVisible = false;
153 FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
154 aDoc->setCurrentFeature(aSketch, useVisible);
156 if (theRemoveExternalDependency)
157 aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
159 setExternal(thePlane);
161 aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
164 //--------------------------------------------------------------------------------------
165 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
167 fillAttribute(theExternal, myexternal);
172 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
174 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
175 ModelHighAPI_Selection aSel(aRes);
179 //--------------------------------------------------------------------------------------
180 void SketchAPI_Sketch::setValue(
181 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
182 const ModelHighAPI_Double & theValue)
184 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
186 // theConstraint->execute();
189 //--------------------------------------------------------------------------------------
190 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
192 const_cast<SketchAPI_Sketch*>(this)->execute();
194 std::list<ModelHighAPI_Selection> aSelectionList;
196 ResultConstructionPtr aResultConstruction =
197 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
198 if (aResultConstruction.get() == NULL)
199 return aSelectionList;
201 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
202 aSelectionList.push_back(
203 ModelHighAPI_Selection(aResultConstruction,
204 aResultConstruction->face(anIndex)));
207 return aSelectionList;
210 //--------------------------------------------------------------------------------------
211 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
212 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
214 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
215 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
218 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
219 const ModelHighAPI_Selection & theExternal)
221 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
222 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
225 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
226 const std::string & theExternalName)
228 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
230 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
233 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
234 std::shared_ptr<ModelAPI_Object> thePlaneObject)
236 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
237 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
240 //--------------------------------------------------------------------------------------
241 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
242 const SketchPtr & theSketch)
244 FeaturePtr aCopyer = thePart->addFeature(SketchPlugin_SketchCopy::ID());
245 aCopyer->reference(SketchPlugin_SketchCopy::BASE_ID())->setValue(theSketch->feature());
248 FeaturePtr aNewSketch = thePart->nextFeature(aCopyer);
250 // perform removing the macro-feature
251 thePart->removeFeature(aCopyer);
254 return SketchPtr(new SketchAPI_Sketch(aNewSketch));
258 //--------------------------------------------------------------------------------------
259 std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
261 std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
262 std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
263 for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
264 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
265 PointPtr aPoint(new SketchAPI_Point(aFeature));
266 aFreePoints.push_back(aPoint);
271 //--------------------------------------------------------------------------------------
272 static GeomCurvePtr untrimmedCurve(GeomShapePtr theShape)
274 GeomCurvePtr aCurve(new GeomAPI_Curve(theShape));
275 if (aCurve->isTrimmed())
276 aCurve = aCurve->basisCurve();
280 void SketchAPI_Sketch::changeFacesOrder(
281 const std::list<std::list<ModelHighAPI_Selection> >& theFaces)
283 // collect faces of the sketch
284 ResultConstructionPtr aSketchResult =
285 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
286 if (!aSketchResult) {
287 // sketch is nested to a boolean operation, thus, it has no result yet.
288 feature()->execute();
290 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
292 std::list<GeomFacePtr> aFaces;
293 int aFacesNum = aSketchResult->facesNum();
294 for (int i = 0; i < aFacesNum; ++i)
295 aFaces.push_back(aSketchResult->face(i));
296 // find new faces order according to the given lists of edges
297 std::list<GeomFacePtr> aNewFacesOrder;
298 std::list<std::list<ModelHighAPI_Selection> >::const_iterator anIt = theFaces.begin();
299 for (; anIt != theFaces.end(); ++anIt) {
300 // find the appropriate face
301 std::list<GeomFacePtr>::iterator aFIt = aFaces.begin();
302 for (; aFIt != aFaces.end(); ++aFIt) {
303 std::list<ModelHighAPI_Selection>::const_iterator aEdgeIt = anIt->begin();
304 GeomAPI_ShapeExplorer aFExp(*aFIt, GeomAPI_Shape::EDGE);
305 for (; aEdgeIt != anIt->end() && aFExp.more(); ++aEdgeIt, aFExp.next()) {
306 ResultPtr aCurRes = aEdgeIt->resultSubShapePair().first;
309 GeomCurvePtr aCurve1 = untrimmedCurve(aCurRes->shape());
310 GeomCurvePtr aCurve2 = untrimmedCurve(aFExp.current());
311 if (!aCurve1->isEqual(aCurve2))
315 if (aEdgeIt == anIt->end() && !aFExp.more()) {
317 aNewFacesOrder.push_back(*aFIt);
323 // place the rest faces at the end of new faces list
325 aNewFacesOrder.insert(aNewFacesOrder.end(), aFaces.begin(), aFaces.end());
326 // update the result of the sketch with the new order of faces
327 aSketchResult->setFacesOrder(aNewFacesOrder);
330 //--------------------------------------------------------------------------------------
331 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
332 double theX, double theY)
334 std::shared_ptr<ModelAPI_Feature> aFeature =
335 compositeFeature()->addFeature(SketchPlugin_Point::ID());
336 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
338 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
339 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
341 std::shared_ptr<ModelAPI_Feature> aFeature =
342 compositeFeature()->addFeature(SketchPlugin_Point::ID());
343 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
345 std::shared_ptr<SketchAPI_Point>
346 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
348 std::shared_ptr<ModelAPI_Feature> aFeature =
349 compositeFeature()->addFeature(SketchPlugin_Point::ID());
350 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
352 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
354 std::shared_ptr<ModelAPI_Feature> aFeature =
355 compositeFeature()->addFeature(SketchPlugin_Point::ID());
356 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
359 //--------------------------------------------------------------------------------------
360 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
361 const ModelHighAPI_Selection & theExternal,
364 std::shared_ptr<ModelAPI_Feature> aFeature =
365 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
366 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
367 anIntersection->setIncludeToResult(theKeepResult);
368 return anIntersection;
370 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
371 const std::string & theExternalName,
374 std::shared_ptr<ModelAPI_Feature> aFeature =
375 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
376 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
377 anIntersection->setIncludeToResult(theKeepResult);
378 return anIntersection;
381 //--------------------------------------------------------------------------------------
382 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
383 double theX2, double theY2)
385 std::shared_ptr<ModelAPI_Feature> aFeature =
386 compositeFeature()->addFeature(SketchPlugin_Line::ID());
387 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
389 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
390 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
391 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
393 std::shared_ptr<ModelAPI_Feature> aFeature =
394 compositeFeature()->addFeature(SketchPlugin_Line::ID());
395 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
397 std::shared_ptr<SketchAPI_Line>
398 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
400 std::shared_ptr<ModelAPI_Feature> aFeature =
401 compositeFeature()->addFeature(SketchPlugin_Line::ID());
402 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
404 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
406 std::shared_ptr<ModelAPI_Feature> aFeature =
407 compositeFeature()->addFeature(SketchPlugin_Line::ID());
408 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
411 //--------------------------------------------------------------------------------------
412 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
413 double theX2, double theY2)
415 std::shared_ptr<ModelAPI_Feature> aFeature =
416 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
417 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
419 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
420 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
421 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
423 std::shared_ptr<ModelAPI_Feature> aFeature =
424 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
425 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
428 //--------------------------------------------------------------------------------------
429 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
433 std::shared_ptr<ModelAPI_Feature> aFeature =
434 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
435 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
438 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
439 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
442 std::shared_ptr<ModelAPI_Feature> aFeature =
443 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
444 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
447 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
452 std::shared_ptr<ModelAPI_Feature> aFeature =
453 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
454 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
455 thePassedX, thePassedY));
458 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
459 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
460 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
462 std::shared_ptr<ModelAPI_Feature> aFeature =
463 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
464 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
467 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
468 double theX2, double theY2,
469 double theX3, double theY3)
471 std::shared_ptr<ModelAPI_Feature> aFeature =
472 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
473 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
478 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
479 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
480 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
481 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
483 std::shared_ptr<ModelAPI_Feature> aFeature =
484 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
485 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
488 std::shared_ptr<SketchAPI_Circle>
489 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
491 std::shared_ptr<ModelAPI_Feature> aFeature =
492 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
493 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
496 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
498 std::shared_ptr<ModelAPI_Feature> aFeature =
499 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
500 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
503 //--------------------------------------------------------------------------------------
504 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
505 double theStartX, double theStartY,
506 double theEndX, double theEndY,
509 std::shared_ptr<ModelAPI_Feature> aFeature =
510 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
511 return ArcPtr(new SketchAPI_Arc(aFeature,
512 theCenterX, theCenterY,
513 theStartX, theStartY,
518 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
519 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
520 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
521 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
524 std::shared_ptr<ModelAPI_Feature> aFeature =
525 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
526 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
529 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
530 double theEndX, double theEndY,
531 double thePassedX, double thePassedY)
533 std::shared_ptr<ModelAPI_Feature> aFeature =
534 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
535 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
536 theStartX, theStartY,
538 thePassedX, thePassedY));
541 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
542 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
543 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
544 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
546 std::shared_ptr<ModelAPI_Feature> aFeature =
547 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
548 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
551 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
552 const ModelHighAPI_RefAttr& theTangentPoint,
553 double theEndX, double theEndY,
557 std::shared_ptr<ModelAPI_Feature> aFeature =
558 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
559 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
561 aMacroArc->setByTransversal(theTangentPoint, theEndX, theEndY, theInversed);
563 aMacroArc->setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
567 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
568 const ModelHighAPI_RefAttr& theTangentPoint,
569 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
573 std::shared_ptr<ModelAPI_Feature> aFeature =
574 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
575 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
577 aMacroArc->setByTransversal(theTangentPoint, theEnd, theInversed);
579 aMacroArc->setByTangent(theTangentPoint, theEnd, theInversed);
583 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
585 std::shared_ptr<ModelAPI_Feature> aFeature =
586 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
587 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
590 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
592 std::shared_ptr<ModelAPI_Feature> aFeature =
593 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
594 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
597 //--------------------------------------------------------------------------------------
598 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
599 double theCenterX, double theCenterY,
600 double theFocusX, double theFocusY,
601 double theMinorRadius)
603 std::shared_ptr<ModelAPI_Feature> aFeature =
604 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
605 return EllipsePtr(new SketchAPI_Ellipse(aFeature,
606 theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius));
609 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
610 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
611 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
612 double theMinorRadius)
614 std::shared_ptr<ModelAPI_Feature> aFeature =
615 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
616 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius));
619 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
620 double thePoint1X, double thePoint1Y,
621 double thePoint2X, double thePoint2Y,
622 double thePassedX, double thePassedY,
625 std::shared_ptr<ModelAPI_Feature> aFeature =
626 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
627 return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature,
628 thePoint1X, thePoint1Y, thePoint2X, thePoint2Y, thePassedX, thePassedY, isPoint1Center));
631 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
632 const PointOrReference& thePoint1,
633 const PointOrReference& thePoint2,
634 const PointOrReference& thePassedPoint,
637 std::shared_ptr<ModelAPI_Feature> aFeature =
638 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
639 MacroEllipsePtr anEllipse;
640 if (thePoint1.second.isEmpty() &&
641 thePoint2.second.isEmpty() &&
642 thePassedPoint.second.isEmpty()) {
643 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
644 thePoint1.first, thePoint2.first, thePassedPoint.first, isPoint1Center));
647 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
648 thePoint1.first, thePoint1.second,
649 thePoint2.first, thePoint2.second,
650 thePassedPoint.first, thePassedPoint.second,
656 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
657 const ModelHighAPI_Selection & theExternal)
659 std::shared_ptr<ModelAPI_Feature> aFeature =
660 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
661 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal));
664 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
665 const std::string & theExternalName)
667 std::shared_ptr<ModelAPI_Feature> aFeature =
668 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
669 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName));
672 //--------------------------------------------------------------------------------------
673 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
674 double theCenterX, double theCenterY,
675 double theFocusX, double theFocusY,
676 double theStartX, double theStartY,
677 double theEndX, double theEndY,
680 std::shared_ptr<ModelAPI_Feature> aFeature =
681 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
682 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature,
683 theCenterX, theCenterY,
684 theFocusX, theFocusY,
685 theStartX, theStartY,
690 std::shared_ptr<SketchAPI_MacroEllipticArc> SketchAPI_Sketch::addEllipticArc(
691 const PointOrReference& theCenter,
692 const PointOrReference& theMajorAxisPoint,
693 const PointOrReference& theStartPoint,
694 const PointOrReference& theEndPoint,
697 std::shared_ptr<ModelAPI_Feature> aFeature =
698 compositeFeature()->addFeature(SketchPlugin_MacroEllipticArc::ID());
699 return MacroEllipticArcPtr(new SketchAPI_MacroEllipticArc(aFeature,
700 theCenter.first, theCenter.second,
701 theMajorAxisPoint.first, theMajorAxisPoint.second,
702 theStartPoint.first, theStartPoint.second,
703 theEndPoint.first, theEndPoint.second,
707 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
708 const ModelHighAPI_Selection & theExternal)
710 std::shared_ptr<ModelAPI_Feature> aFeature =
711 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
712 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternal));
715 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
716 const std::string & theExternalName)
718 std::shared_ptr<ModelAPI_Feature> aFeature =
719 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
720 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternalName));
723 //--------------------------------------------------------------------------------------
725 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(
726 const ModelHighAPI_Selection & external,
728 const std::list<PointOrReference>& poles,
729 const std::list<ModelHighAPI_Double>& weights,
730 const std::list<ModelHighAPI_Double>& knots,
731 const std::list<ModelHighAPI_Integer>& multiplicities,
734 // split poles and references to other shapes
735 bool hasReference = false;
736 std::list<GeomPnt2dPtr> aPoints;
737 std::list<ModelHighAPI_RefAttr> aReferences;
738 for (std::list<PointOrReference>::const_iterator it = poles.begin(); it != poles.end(); ++it) {
739 aPoints.push_back(it->first);
740 aReferences.push_back(it->second);
741 if (!it->second.isEmpty())
746 CompositeFeaturePtr aSketch = compositeFeature();
748 // use macro-feature to create coincidences to referred features
749 FeaturePtr aMacroFeature = aSketch->addFeature(
750 periodic ? SketchPlugin_MacroBSplinePeriodic::ID() : SketchPlugin_MacroBSpline::ID());
751 AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
752 aMacroFeature->attribute(SketchPlugin_MacroBSpline::POLES_ID()));
753 AttributeDoubleArrayPtr aWeightsAttr =
754 aMacroFeature->data()->realArray(SketchPlugin_MacroBSpline::WEIGHTS_ID());
755 AttributeRefAttrListPtr aPolesRefAttr =
756 aMacroFeature->data()->refattrlist(SketchPlugin_MacroBSpline::REF_POLES_ID());
757 // always generate a control polygon to apply coincidences correctly
758 aMacroFeature->boolean(SketchPlugin_MacroBSpline::CONTROL_POLYGON_ID())->setValue(true);
759 // initialize B-spline attributes
760 fillAttribute(aPoints, aPolesAttr);
762 fillAttribute(std::list<ModelHighAPI_Double>(poles.size(), 1.0), aWeightsAttr);
764 fillAttribute(weights, aWeightsAttr);
765 fillAttribute(aReferences, aPolesRefAttr);
766 apply(); // to kill macro-feature
768 // find created B-spline feature
769 const std::string& aKindToFind =
770 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID();
771 int aNbSubs = aSketch->numberOfSubs();
772 for (int anIndex = aNbSubs - 1; anIndex >= 0; --anIndex) {
773 FeaturePtr aFeature = aSketch->subFeature(anIndex);
774 if (aFeature->getKind() == aKindToFind) {
775 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
776 : new SketchAPI_BSpline(aFeature));
783 // compute B-spline by parameters
784 FeaturePtr aFeature = aSketch->addFeature(
785 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
787 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
788 : new SketchAPI_BSpline(aFeature));
789 if (external.variantType() != ModelHighAPI_Selection::VT_Empty)
790 aBSpline->setByExternal(external);
791 else if (knots.empty() || multiplicities.empty())
792 aBSpline->setByDegreePolesAndWeights(degree, aPoints, weights);
794 aBSpline->setByParameters(degree, aPoints, weights, knots, multiplicities);
799 //--------------------------------------------------------------------------------------
800 static std::shared_ptr<SketchAPI_BSpline> buildInterpolation(
801 const CompositeFeaturePtr& theSketch,
802 const FeaturePtr& theCurveFittingFeature,
803 const std::list<ModelHighAPI_RefAttr>& points,
807 AttributeBooleanPtr aPeriodicAttr =
808 theCurveFittingFeature->boolean(SketchPlugin_CurveFitting::PERIODIC_ID());
809 fillAttribute(periodic, aPeriodicAttr);
810 AttributeBooleanPtr aClosedAttr =
811 theCurveFittingFeature->boolean(SketchPlugin_CurveFitting::CLOSED_ID());
812 fillAttribute(closed, aClosedAttr);
813 AttributeRefAttrListPtr aPointsAttr =
814 theCurveFittingFeature->refattrlist(SketchPlugin_CurveFitting::POINTS_ID());
815 fillAttribute(points, aPointsAttr);
816 apply(); // to execute and kill the macro-feature
818 // find created B-spline feature
820 const std::string& aKindToFind =
821 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID();
822 int aNbSubs = theSketch->numberOfSubs();
823 for (int anIndex = aNbSubs - 1; anIndex >= 0; --anIndex) {
824 FeaturePtr aFeature = theSketch->subFeature(anIndex);
825 if (aFeature->getKind() == aKindToFind) {
826 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
827 : new SketchAPI_BSpline(aFeature));
835 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addInterpolation(
836 const std::list<ModelHighAPI_RefAttr>& points,
840 CompositeFeaturePtr aSketch = compositeFeature();
841 FeaturePtr anInterpFeature = aSketch->addFeature(SketchPlugin_CurveFitting::ID());
842 anInterpFeature->string(SketchPlugin_CurveFitting::TYPE_ID())
843 ->setValue(SketchPlugin_CurveFitting::TYPE_INTERPOLATION_ID());
844 return buildInterpolation(aSketch, anInterpFeature, points, periodic, closed);
847 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addApproximation(
848 const std::list<ModelHighAPI_RefAttr>& points,
849 const ModelHighAPI_Double& precision,
853 CompositeFeaturePtr aSketch = compositeFeature();
854 FeaturePtr anInterpFeature = aSketch->addFeature(SketchPlugin_CurveFitting::ID());
855 anInterpFeature->string(SketchPlugin_CurveFitting::TYPE_ID())
856 ->setValue(SketchPlugin_CurveFitting::TYPE_APPROXIMATION_ID());
857 fillAttribute(precision, anInterpFeature->real(SketchPlugin_CurveFitting::PRECISION_ID()));
858 return buildInterpolation(aSketch, anInterpFeature, points, periodic, closed);
861 //--------------------------------------------------------------------------------------
862 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
863 const ModelHighAPI_Selection & theExternalFeature,
865 bool keepRefToOriginal)
867 std::shared_ptr<ModelAPI_Feature> aFeature =
868 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
869 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature));
870 aProjection->setIncludeToResult(keepResult);
871 aProjection->setKeepReferenceToOriginal(keepRefToOriginal);
872 aProjection->setExternalFeature(theExternalFeature);
876 //--------------------------------------------------------------------------------------
877 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
878 const ModelHighAPI_RefAttr & theMirrorLine,
879 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
881 std::shared_ptr<ModelAPI_Feature> aFeature =
882 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
883 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
886 //--------------------------------------------------------------------------------------
887 std::shared_ptr<SketchAPI_Offset> SketchAPI_Sketch::addOffset(
888 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
889 const ModelHighAPI_Double & theValue,
890 const bool theReversed)
892 std::shared_ptr<ModelAPI_Feature> aFeature =
893 compositeFeature()->addFeature(SketchPlugin_Offset::ID());
894 return OffsetPtr(new SketchAPI_Offset(aFeature, theObjects, theValue, theReversed));
897 //--------------------------------------------------------------------------------------
898 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
899 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
900 const ModelHighAPI_RefAttr & thePoint1,
901 const ModelHighAPI_RefAttr & thePoint2,
902 const ModelHighAPI_Integer & theNumberOfObjects,
905 std::shared_ptr<ModelAPI_Feature> aFeature =
906 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
907 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
908 thePoint2, theNumberOfObjects, theFullValue));
911 //--------------------------------------------------------------------------------------
912 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
913 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
914 const ModelHighAPI_RefAttr & theCenter,
915 const ModelHighAPI_Double & theAngle,
916 const ModelHighAPI_Integer & theNumberOfObjects,
920 std::shared_ptr<ModelAPI_Feature> aFeature =
921 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
923 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
924 theAngle, theNumberOfObjects, theFullValue, theReversed));
927 //--------------------------------------------------------------------------------------
928 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
929 const ModelHighAPI_Reference& theFeature,
930 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
932 std::shared_ptr<ModelAPI_Feature> aFeature =
933 compositeFeature()->addFeature(SketchPlugin_Split::ID());
934 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
936 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
937 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
938 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
939 fillAttribute(thePositionPoint, aPointAttr);
942 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
945 //--------------------------------------------------------------------------------------
946 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
947 const ModelHighAPI_Reference& theFeature,
948 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
950 std::shared_ptr<ModelAPI_Feature> aFeature =
951 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
952 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
954 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
955 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
956 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
957 fillAttribute(thePositionPoint, aPointAttr);
960 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
963 //--------------------------------------------------------------------------------------
964 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
965 const ModelHighAPI_RefAttr & theLine1,
966 const ModelHighAPI_RefAttr & theLine2,
967 const ModelHighAPI_Double & theValue,
968 const std::string& theType)
970 std::shared_ptr<ModelAPI_Feature> aFeature =
971 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
973 const int aVersion = theType.empty() ? SketchPlugin_ConstraintAngle::THE_VERSION_0
974 : SketchPlugin_ConstraintAngle::THE_VERSION_1;
975 fillAttribute(aVersion, aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
977 int aType = (int)SketcherPrs_Tools::ANGLE_DIRECT;
978 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::PREV_TYPE_ID()));
979 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
981 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_0)
982 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
984 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
985 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
987 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_1) {
988 std::string aTypeLC = theType;
989 std::transform(aTypeLC.begin(), aTypeLC.end(), aTypeLC.begin(),
990 [](char c) { return static_cast<char>(::tolower(c)); });
991 if (aTypeLC == "supplementary")
992 aType = (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
993 else if (aTypeLC == "backward")
994 aType = (int)SketcherPrs_Tools::ANGLE_BACKWARD;
996 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
997 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1000 aFeature->execute();
1001 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1004 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
1005 const ModelHighAPI_RefAttr & theLine1,
1006 const ModelHighAPI_RefAttr & theLine2,
1007 const ModelHighAPI_Double & theValue)
1009 std::shared_ptr<ModelAPI_Feature> aFeature =
1010 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
1011 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
1012 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
1013 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
1014 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1015 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1016 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1017 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1018 aFeature->execute();
1019 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1022 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
1023 const ModelHighAPI_RefAttr & theLine1,
1024 const ModelHighAPI_RefAttr & theLine2,
1025 const ModelHighAPI_Double & theValue)
1027 std::shared_ptr<ModelAPI_Feature> aFeature =
1028 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
1029 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
1030 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
1031 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
1032 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1033 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1034 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1035 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1036 aFeature->execute();
1037 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1040 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
1041 const ModelHighAPI_RefAttr & thePoint1,
1042 const ModelHighAPI_RefAttr & thePoint2)
1044 std::shared_ptr<ModelAPI_Feature> aFeature =
1045 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
1046 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1047 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1048 aFeature->execute();
1049 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1052 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
1053 const ModelHighAPI_RefAttr & theLine1,
1054 const ModelHighAPI_RefAttr & theLine2)
1056 std::shared_ptr<ModelAPI_Feature> aFeature =
1057 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
1058 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1059 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1060 aFeature->execute();
1061 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1064 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
1065 const ModelHighAPI_RefAttr & thePoint,
1066 const ModelHighAPI_RefAttr & thePointOrLine,
1067 const ModelHighAPI_Double & theValue,
1070 std::shared_ptr<ModelAPI_Feature> aFeature =
1071 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
1072 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1073 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1074 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1075 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
1076 aFeature->execute();
1077 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1080 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
1081 const ModelHighAPI_RefAttr & thePoint,
1082 const ModelHighAPI_RefAttr & thePointOrLine,
1083 const ModelHighAPI_Double & theValue)
1085 return setDistance(thePoint, thePointOrLine, theValue, true);
1088 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
1089 const ModelHighAPI_RefAttr & thePoint,
1090 const ModelHighAPI_RefAttr & thePointOrLine,
1091 const ModelHighAPI_Double & theValue)
1093 return setDistance(thePoint, thePointOrLine, theValue, false);
1096 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
1097 const ModelHighAPI_RefAttr & thePoint1,
1098 const ModelHighAPI_RefAttr & thePoint2,
1099 const ModelHighAPI_Double & theValue)
1101 std::shared_ptr<ModelAPI_Feature> aFeature =
1102 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
1103 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1104 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1105 fillAttribute(theValue,
1106 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1107 aFeature->execute();
1108 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1111 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
1112 const ModelHighAPI_RefAttr & thePoint1,
1113 const ModelHighAPI_RefAttr & thePoint2,
1114 const ModelHighAPI_Double & theValue)
1116 std::shared_ptr<ModelAPI_Feature> aFeature =
1117 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
1118 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1119 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1120 fillAttribute(theValue,
1121 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1122 aFeature->execute();
1123 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1126 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
1127 const ModelHighAPI_RefAttr & theObject1,
1128 const ModelHighAPI_RefAttr & theObject2)
1130 std::shared_ptr<ModelAPI_Feature> aFeature =
1131 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
1132 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1133 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1134 aFeature->execute();
1135 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1138 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
1139 const ModelHighAPI_RefAttr & thePoint)
1141 std::shared_ptr<ModelAPI_Feature> aFeature =
1142 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
1143 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
1144 apply(); // finish operation to remove Fillet feature correcly
1145 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1148 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
1149 const ModelHighAPI_RefAttr & thePoint,
1150 const ModelHighAPI_Double & theRadius)
1152 CompositeFeaturePtr aSketch = compositeFeature();
1153 int aNbSubs = aSketch->numberOfSubs();
1156 InterfacePtr aFilletFeature = setFillet(thePoint);
1158 // set radius for just created arc
1159 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
1160 if (anArc->getKind() == SketchPlugin_Arc::ID())
1161 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
1163 return aFilletFeature;
1166 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
1167 const ModelHighAPI_RefAttr & theObject)
1169 std::shared_ptr<ModelAPI_Feature> aFeature =
1170 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
1171 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1172 aFeature->execute();
1173 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1176 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
1177 const ModelHighAPI_RefAttr & theLine)
1179 std::shared_ptr<ModelAPI_Feature> aFeature =
1180 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1181 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1182 aFeature->execute();
1183 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1186 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1187 const ModelHighAPI_RefAttr & theLine,
1188 const ModelHighAPI_Double & theValue)
1190 std::shared_ptr<ModelAPI_Feature> aFeature =
1191 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1192 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1193 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1194 aFeature->execute();
1195 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1198 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1199 const ModelHighAPI_RefAttr & thePoint,
1200 const ModelHighAPI_RefAttr & theLine)
1202 std::shared_ptr<ModelAPI_Feature> aFeature =
1203 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1204 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1205 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1206 aFeature->execute();
1207 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1210 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1211 const ModelHighAPI_RefAttr & theLine1,
1212 const ModelHighAPI_RefAttr & theLine2)
1214 std::shared_ptr<ModelAPI_Feature> aFeature =
1215 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1216 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1217 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1218 aFeature->execute();
1219 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1222 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1223 const ModelHighAPI_RefAttr & theLine1,
1224 const ModelHighAPI_RefAttr & theLine2)
1226 std::shared_ptr<ModelAPI_Feature> aFeature =
1227 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1228 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1229 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1230 aFeature->execute();
1231 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1234 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1235 const ModelHighAPI_RefAttr & theCircleOrArc,
1236 const ModelHighAPI_Double & theValue)
1238 std::shared_ptr<ModelAPI_Feature> aFeature =
1239 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1240 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1241 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1242 aFeature->execute();
1243 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1246 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1247 const ModelHighAPI_RefAttr & theLine,
1248 const ModelHighAPI_RefAttr & theCircle)
1250 std::shared_ptr<ModelAPI_Feature> aFeature =
1251 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1252 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1253 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1254 aFeature->execute();
1255 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1258 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1259 const ModelHighAPI_RefAttr & theLine)
1261 std::shared_ptr<ModelAPI_Feature> aFeature =
1262 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1263 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1264 aFeature->execute();
1265 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1268 //--------------------------------------------------------------------------------------
1270 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1272 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1273 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1276 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1278 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1279 theFeature->attribute(SketchPlugin_Line::START_ID()));
1280 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1281 theFeature->attribute(SketchPlugin_Line::END_ID()));
1283 if (!aStartAttr || !aEndAttr)
1284 return std::shared_ptr<GeomAPI_Pnt2d>();
1286 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1287 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1288 return std::shared_ptr<GeomAPI_Pnt2d>(
1289 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1292 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1294 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1295 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1296 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1298 if (!aCenter || !aRadius)
1299 return std::shared_ptr<GeomAPI_Pnt2d>();
1301 return std::shared_ptr<GeomAPI_Pnt2d>(
1302 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1305 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1307 static const double PI = 3.141592653589793238463;
1309 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1310 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1311 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1312 theFeature->attribute(SketchPlugin_Arc::START_ID()));
1313 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1314 theFeature->attribute(SketchPlugin_Arc::END_ID()));
1316 if (!aCenterAttr || !aStartAttr || !aEndAttr)
1317 return std::shared_ptr<GeomAPI_Pnt2d>();
1319 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1320 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1321 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1322 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1324 double anAngle = aStartDir->angle(aEndDir);
1325 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1326 if (isReversed && anAngle > 0.)
1327 anAngle -= 2.0 * PI;
1328 else if (!isReversed && anAngle <= 0.)
1329 anAngle += 2.0 * PI;
1331 double cosA = cos(anAngle);
1332 double sinA = sin(anAngle);
1334 // rotate start dir to find middle point on arc
1335 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1336 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1337 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1339 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1342 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1343 bool isEllipse = true)
1345 const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1346 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1347 AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1348 theFeature->attribute(anAttrName));
1349 return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1352 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnBSpline(const FeaturePtr& theFeature,
1353 SketchAPI_Sketch* theSketch)
1355 GeomAPI_Edge anEdge(theFeature->lastResult()->shape());
1356 GeomPointPtr aMiddle = anEdge.middlePoint();
1357 return theSketch->to2D(aMiddle);
1360 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject,
1361 SketchAPI_Sketch* theSketch)
1363 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1364 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1366 // move only features of the following types
1367 const std::string& aFeatureKind = aFeature->getKind();
1368 if (aFeatureKind == SketchPlugin_Point::ID())
1369 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1370 else if (aFeatureKind == SketchPlugin_Line::ID())
1371 aMiddlePoint = middlePointOnLine(aFeature);
1372 else if (aFeatureKind == SketchPlugin_Circle::ID())
1373 aMiddlePoint = pointOnCircle(aFeature);
1374 else if (aFeatureKind == SketchPlugin_Arc::ID())
1375 aMiddlePoint = middlePointOnArc(aFeature);
1376 else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1377 aMiddlePoint = pointOnEllipse(aFeature);
1378 else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1379 aMiddlePoint = pointOnEllipse(aFeature, false);
1380 else if (aFeatureKind == SketchPlugin_BSpline::ID() ||
1381 aFeatureKind == SketchPlugin_BSplinePeriodic::ID())
1382 aMiddlePoint = middlePointOnBSpline(aFeature, theSketch);
1384 return aMiddlePoint;
1387 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1388 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1390 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1391 theMovedEntity.fillMessage(aMessage);
1393 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1394 if (aMessage->movedAttribute())
1395 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1397 anOriginalPosition = middlePoint(aMessage->movedObject(), this);
1399 if (!anOriginalPosition)
1400 return; // something has gone wrong, do not process movement
1402 aMessage->setOriginalPosition(anOriginalPosition);
1403 aMessage->setCurrentPosition(theTargetPoint);
1404 Events_Loop::loop()->send(aMessage);
1407 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1408 double theTargetX, double theTargetY)
1410 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1411 move(theMovedEntity, aTargetPoint);
1414 //--------------------------------------------------------------------------------------
1416 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1418 FeaturePtr aBase = feature();
1419 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1420 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1421 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1422 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1423 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1424 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1425 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1427 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1430 //--------------------------------------------------------------------------------------
1432 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1434 // collect edges of the first face
1435 std::list<GeomShapePtr> anEdges1;
1436 for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1437 anEdges1.push_back(anExp.current());
1438 // compare edges of faces
1439 for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1440 GeomShapePtr aCurrent = anExp.current();
1441 bool isFound = false;
1442 std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1443 for (; anIt1 != anEdges1.end(); ++anIt1)
1444 if (aCurrent->isSameGeometry(*anIt1)) {
1446 anEdges1.erase(anIt1);
1452 return !anEdges1.empty();
1455 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1457 ResultConstructionPtr aSketchResult =
1458 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1462 std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1463 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1467 // collect faces constructed by SketchBuilder algorithm
1468 GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1469 aWires->norm(), aWires);
1470 const ListOfShape& aFaces = aSketchBuilder.faces();
1472 // compare faces stored in sketch with faces generated by SketchBuilder
1473 int aNbSketchFaces = aSketchResult->facesNum();
1475 for (ListOfShape::const_iterator aFIt = aFaces.begin();
1476 aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1477 ++aFIt, ++aFaceIndex) {
1478 GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1479 GeomFacePtr aCurFace = (*aFIt)->face();
1480 if (isDifferent(aSketchFace, aCurFace))
1486 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1487 std::list<std::list<ResultPtr> >& theEdges)
1489 ResultConstructionPtr aSketchResult =
1490 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1494 // collect curves of the sketch
1495 std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1496 int aSubNum = theSketch->numberOfSubs();
1497 for (int a = 0; a < aSubNum; ++a) {
1498 FeaturePtr aSub = theSketch->subFeature(a);
1499 const std::list<ResultPtr>& aResults = aSub->results();
1500 std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1501 for (; aRes != aResults.cend(); aRes++) {
1502 GeomShapePtr aCurShape = (*aRes)->shape();
1503 if (aCurShape && aCurShape->isEdge())
1504 aCurves[untrimmedCurve(aCurShape)] = *aRes;
1508 // convert each face to the list of results of its edges
1509 int aFacesNum = aSketchResult->facesNum();
1510 for (int a = 0; a < aFacesNum; ++a) {
1511 theEdges.push_back(std::list<ResultPtr>());
1512 std::list<ResultPtr>& aCurEdges = theEdges.back();
1514 GeomFacePtr aFace = aSketchResult->face(a);
1515 for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1516 anExp.more(); anExp.next()) {
1517 GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1518 aCurEdges.push_back(aCurves[aCurrent]);
1523 //--------------------------------------------------------------------------------------
1525 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1527 FeaturePtr aBase = feature();
1528 const std::string& aDocName = theDumper.name(aBase->document());
1530 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1531 if (anExternal->value()) {
1532 theDumper << aBase << " = model.addSketch(" << aDocName <<
1533 ", " << anExternal << ")" << std::endl;
1535 // Sketch is base on a plane.
1536 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1537 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1538 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1539 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1540 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1541 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1543 // Check the plane is coordinate plane
1544 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1545 if(anExternal->context()) { // checking for selected planes
1546 if (!aPlaneName.empty()
1547 && anExternal->context()->data()
1548 && anExternal->context()->data()->name() == aPlaneName) {
1549 // dump sketch based on coordinate plane
1550 theDumper << aBase << " = model.addSketch(" << aDocName
1551 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1552 } else { // some other plane
1553 theDumper << aBase << " = model.addSketch(" << aDocName <<
1554 ", " << anExternal<< ")" << std::endl;
1557 if (aPlaneName.empty()) {
1558 // needs import additional module
1559 theDumper.importModule("GeomAPI");
1560 // dump plane parameters
1561 const std::string& aSketchName = theDumper.name(aBase);
1562 std::string anOriginName = aSketchName + "_origin";
1563 std::string aNormalName = aSketchName + "_norm";
1564 std::string aDirXName = aSketchName + "_dirx";
1565 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1566 // and then dumplicate dumping it in the next line
1567 theDumper << anOriginName << " = " << anOrigin << "\n"
1568 << aNormalName << " = " << aNormal << "\n"
1569 << aDirXName << " = " << aDirX << "\n";
1570 // dump sketch based on arbitrary plane
1571 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1572 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1574 // dump sketch based on coordinate plane
1575 theDumper << aBase << " = model.addSketch(" << aDocName
1576 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1581 // dump sketch's subfeatures
1582 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1583 theDumper.processSubs(aCompFeat, true);
1585 // if face order differs to the order generated by SketchBuilder,
1586 // dump the list of faces for correct execution of the script
1587 if (isCustomFacesOrder(aCompFeat)) {
1588 std::list<std::list<ResultPtr> > aFaces;
1589 edgesOfSketchFaces(aCompFeat, aFaces);
1591 const std::string& aSketchName = theDumper.name(aBase);
1592 std::string aMethodName(".changeFacesOrder");
1593 std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1595 theDumper << aSketchName << aMethodName << "([";
1596 for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1597 aFIt != aFaces.end(); ++aFIt) {
1598 if (aFIt != aFaces.begin())
1599 theDumper << ",\n" << aSpaceShift << " ";
1602 theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1603 // call model.do() for correct update of the document's labels related to the changed faces
1604 theDumper << "model.do()" << std::endl;