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,
866 std::shared_ptr<ModelAPI_Feature> aFeature =
867 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
868 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
869 aProjection->setIncludeToResult(theKeepResult);
873 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
874 const std::string & theExternalName,
877 std::shared_ptr<ModelAPI_Feature> aFeature =
878 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
879 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
880 aProjection->setIncludeToResult(theKeepResult);
884 //--------------------------------------------------------------------------------------
885 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
886 const ModelHighAPI_RefAttr & theMirrorLine,
887 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
889 std::shared_ptr<ModelAPI_Feature> aFeature =
890 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
891 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
894 //--------------------------------------------------------------------------------------
895 std::shared_ptr<SketchAPI_Offset> SketchAPI_Sketch::addOffset(
896 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
897 const ModelHighAPI_Double & theValue,
898 const bool theReversed)
900 std::shared_ptr<ModelAPI_Feature> aFeature =
901 compositeFeature()->addFeature(SketchPlugin_Offset::ID());
902 return OffsetPtr(new SketchAPI_Offset(aFeature, theObjects, theValue, theReversed));
905 //--------------------------------------------------------------------------------------
906 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
907 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
908 const ModelHighAPI_RefAttr & thePoint1,
909 const ModelHighAPI_RefAttr & thePoint2,
910 const ModelHighAPI_Integer & theNumberOfObjects,
913 std::shared_ptr<ModelAPI_Feature> aFeature =
914 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
915 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
916 thePoint2, theNumberOfObjects, theFullValue));
919 //--------------------------------------------------------------------------------------
920 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
921 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
922 const ModelHighAPI_RefAttr & theCenter,
923 const ModelHighAPI_Double & theAngle,
924 const ModelHighAPI_Integer & theNumberOfObjects,
928 std::shared_ptr<ModelAPI_Feature> aFeature =
929 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
931 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
932 theAngle, theNumberOfObjects, theFullValue, theReversed));
935 //--------------------------------------------------------------------------------------
936 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
937 const ModelHighAPI_Reference& theFeature,
938 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
940 std::shared_ptr<ModelAPI_Feature> aFeature =
941 compositeFeature()->addFeature(SketchPlugin_Split::ID());
942 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
944 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
945 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
946 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
947 fillAttribute(thePositionPoint, aPointAttr);
950 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
953 //--------------------------------------------------------------------------------------
954 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
955 const ModelHighAPI_Reference& theFeature,
956 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
958 std::shared_ptr<ModelAPI_Feature> aFeature =
959 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
960 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
962 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
963 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
964 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
965 fillAttribute(thePositionPoint, aPointAttr);
968 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
971 //--------------------------------------------------------------------------------------
972 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
973 const ModelHighAPI_RefAttr & theLine1,
974 const ModelHighAPI_RefAttr & theLine2,
975 const ModelHighAPI_Double & theValue,
976 const std::string& theType)
978 std::shared_ptr<ModelAPI_Feature> aFeature =
979 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
981 const int aVersion = theType.empty() ? SketchPlugin_ConstraintAngle::THE_VERSION_0
982 : SketchPlugin_ConstraintAngle::THE_VERSION_1;
983 fillAttribute(aVersion, aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
985 int aType = (int)SketcherPrs_Tools::ANGLE_DIRECT;
986 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::PREV_TYPE_ID()));
987 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
989 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_0)
990 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
992 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
993 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
995 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_1) {
996 std::string aTypeLC = theType;
997 std::transform(aTypeLC.begin(), aTypeLC.end(), aTypeLC.begin(),
998 [](char c) { return static_cast<char>(::tolower(c)); });
999 if (aTypeLC == "supplementary")
1000 aType = (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
1001 else if (aTypeLC == "backward")
1002 aType = (int)SketcherPrs_Tools::ANGLE_BACKWARD;
1004 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1005 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1008 aFeature->execute();
1009 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1012 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
1013 const ModelHighAPI_RefAttr & theLine1,
1014 const ModelHighAPI_RefAttr & theLine2,
1015 const ModelHighAPI_Double & theValue)
1017 std::shared_ptr<ModelAPI_Feature> aFeature =
1018 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
1019 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
1020 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
1021 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
1022 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1023 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1024 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1025 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1026 aFeature->execute();
1027 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1030 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
1031 const ModelHighAPI_RefAttr & theLine1,
1032 const ModelHighAPI_RefAttr & theLine2,
1033 const ModelHighAPI_Double & theValue)
1035 std::shared_ptr<ModelAPI_Feature> aFeature =
1036 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
1037 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
1038 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
1039 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
1040 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1041 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1042 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1043 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1044 aFeature->execute();
1045 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1048 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
1049 const ModelHighAPI_RefAttr & thePoint1,
1050 const ModelHighAPI_RefAttr & thePoint2)
1052 std::shared_ptr<ModelAPI_Feature> aFeature =
1053 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
1054 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1055 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1056 aFeature->execute();
1057 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1060 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
1061 const ModelHighAPI_RefAttr & theLine1,
1062 const ModelHighAPI_RefAttr & theLine2)
1064 std::shared_ptr<ModelAPI_Feature> aFeature =
1065 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
1066 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1067 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1068 aFeature->execute();
1069 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1072 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
1073 const ModelHighAPI_RefAttr & thePoint,
1074 const ModelHighAPI_RefAttr & thePointOrLine,
1075 const ModelHighAPI_Double & theValue,
1078 std::shared_ptr<ModelAPI_Feature> aFeature =
1079 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
1080 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1081 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1082 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1083 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
1084 aFeature->execute();
1085 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1088 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
1089 const ModelHighAPI_RefAttr & thePoint,
1090 const ModelHighAPI_RefAttr & thePointOrLine,
1091 const ModelHighAPI_Double & theValue)
1093 return setDistance(thePoint, thePointOrLine, theValue, true);
1096 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
1097 const ModelHighAPI_RefAttr & thePoint,
1098 const ModelHighAPI_RefAttr & thePointOrLine,
1099 const ModelHighAPI_Double & theValue)
1101 return setDistance(thePoint, thePointOrLine, theValue, false);
1104 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
1105 const ModelHighAPI_RefAttr & thePoint1,
1106 const ModelHighAPI_RefAttr & thePoint2,
1107 const ModelHighAPI_Double & theValue)
1109 std::shared_ptr<ModelAPI_Feature> aFeature =
1110 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
1111 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1112 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1113 fillAttribute(theValue,
1114 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1115 aFeature->execute();
1116 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1119 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
1120 const ModelHighAPI_RefAttr & thePoint1,
1121 const ModelHighAPI_RefAttr & thePoint2,
1122 const ModelHighAPI_Double & theValue)
1124 std::shared_ptr<ModelAPI_Feature> aFeature =
1125 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
1126 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1127 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1128 fillAttribute(theValue,
1129 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1130 aFeature->execute();
1131 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1134 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
1135 const ModelHighAPI_RefAttr & theObject1,
1136 const ModelHighAPI_RefAttr & theObject2)
1138 std::shared_ptr<ModelAPI_Feature> aFeature =
1139 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
1140 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1141 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1142 aFeature->execute();
1143 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1146 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
1147 const ModelHighAPI_RefAttr & thePoint)
1149 std::shared_ptr<ModelAPI_Feature> aFeature =
1150 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
1151 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
1152 apply(); // finish operation to remove Fillet feature correcly
1153 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1156 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
1157 const ModelHighAPI_RefAttr & thePoint,
1158 const ModelHighAPI_Double & theRadius)
1160 CompositeFeaturePtr aSketch = compositeFeature();
1161 int aNbSubs = aSketch->numberOfSubs();
1164 InterfacePtr aFilletFeature = setFillet(thePoint);
1166 // set radius for just created arc
1167 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
1168 if (anArc->getKind() == SketchPlugin_Arc::ID())
1169 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
1171 return aFilletFeature;
1174 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
1175 const ModelHighAPI_RefAttr & theObject)
1177 std::shared_ptr<ModelAPI_Feature> aFeature =
1178 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
1179 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1180 aFeature->execute();
1181 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1184 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
1185 const ModelHighAPI_RefAttr & theLine)
1187 std::shared_ptr<ModelAPI_Feature> aFeature =
1188 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1189 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1190 aFeature->execute();
1191 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1194 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1195 const ModelHighAPI_RefAttr & theLine,
1196 const ModelHighAPI_Double & theValue)
1198 std::shared_ptr<ModelAPI_Feature> aFeature =
1199 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1200 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1201 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1202 aFeature->execute();
1203 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1206 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1207 const ModelHighAPI_RefAttr & thePoint,
1208 const ModelHighAPI_RefAttr & theLine)
1210 std::shared_ptr<ModelAPI_Feature> aFeature =
1211 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1212 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1213 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1214 aFeature->execute();
1215 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1218 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1219 const ModelHighAPI_RefAttr & theLine1,
1220 const ModelHighAPI_RefAttr & theLine2)
1222 std::shared_ptr<ModelAPI_Feature> aFeature =
1223 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1224 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1225 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1226 aFeature->execute();
1227 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1230 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1231 const ModelHighAPI_RefAttr & theLine1,
1232 const ModelHighAPI_RefAttr & theLine2)
1234 std::shared_ptr<ModelAPI_Feature> aFeature =
1235 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1236 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1237 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1238 aFeature->execute();
1239 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1242 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1243 const ModelHighAPI_RefAttr & theCircleOrArc,
1244 const ModelHighAPI_Double & theValue)
1246 std::shared_ptr<ModelAPI_Feature> aFeature =
1247 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1248 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1249 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1250 aFeature->execute();
1251 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1254 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1255 const ModelHighAPI_RefAttr & theLine,
1256 const ModelHighAPI_RefAttr & theCircle)
1258 std::shared_ptr<ModelAPI_Feature> aFeature =
1259 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1260 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1261 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1262 aFeature->execute();
1263 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1266 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1267 const ModelHighAPI_RefAttr & theLine)
1269 std::shared_ptr<ModelAPI_Feature> aFeature =
1270 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1271 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1272 aFeature->execute();
1273 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1276 //--------------------------------------------------------------------------------------
1278 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1280 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1281 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1284 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1286 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1287 theFeature->attribute(SketchPlugin_Line::START_ID()));
1288 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1289 theFeature->attribute(SketchPlugin_Line::END_ID()));
1291 if (!aStartAttr || !aEndAttr)
1292 return std::shared_ptr<GeomAPI_Pnt2d>();
1294 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1295 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1296 return std::shared_ptr<GeomAPI_Pnt2d>(
1297 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1300 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1302 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1303 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1304 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1306 if (!aCenter || !aRadius)
1307 return std::shared_ptr<GeomAPI_Pnt2d>();
1309 return std::shared_ptr<GeomAPI_Pnt2d>(
1310 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1313 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1315 static const double PI = 3.141592653589793238463;
1317 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1318 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1319 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1320 theFeature->attribute(SketchPlugin_Arc::START_ID()));
1321 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1322 theFeature->attribute(SketchPlugin_Arc::END_ID()));
1324 if (!aCenterAttr || !aStartAttr || !aEndAttr)
1325 return std::shared_ptr<GeomAPI_Pnt2d>();
1327 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1328 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1329 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1330 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1332 double anAngle = aStartDir->angle(aEndDir);
1333 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1334 if (isReversed && anAngle > 0.)
1335 anAngle -= 2.0 * PI;
1336 else if (!isReversed && anAngle <= 0.)
1337 anAngle += 2.0 * PI;
1339 double cosA = cos(anAngle);
1340 double sinA = sin(anAngle);
1342 // rotate start dir to find middle point on arc
1343 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1344 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1345 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1347 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1350 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1351 bool isEllipse = true)
1353 const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1354 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1355 AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1356 theFeature->attribute(anAttrName));
1357 return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1360 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnBSpline(const FeaturePtr& theFeature,
1361 SketchAPI_Sketch* theSketch)
1363 GeomAPI_Edge anEdge(theFeature->lastResult()->shape());
1364 GeomPointPtr aMiddle = anEdge.middlePoint();
1365 return theSketch->to2D(aMiddle);
1368 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject,
1369 SketchAPI_Sketch* theSketch)
1371 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1372 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1374 // move only features of the following types
1375 const std::string& aFeatureKind = aFeature->getKind();
1376 if (aFeatureKind == SketchPlugin_Point::ID())
1377 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1378 else if (aFeatureKind == SketchPlugin_Line::ID())
1379 aMiddlePoint = middlePointOnLine(aFeature);
1380 else if (aFeatureKind == SketchPlugin_Circle::ID())
1381 aMiddlePoint = pointOnCircle(aFeature);
1382 else if (aFeatureKind == SketchPlugin_Arc::ID())
1383 aMiddlePoint = middlePointOnArc(aFeature);
1384 else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1385 aMiddlePoint = pointOnEllipse(aFeature);
1386 else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1387 aMiddlePoint = pointOnEllipse(aFeature, false);
1388 else if (aFeatureKind == SketchPlugin_BSpline::ID() ||
1389 aFeatureKind == SketchPlugin_BSplinePeriodic::ID())
1390 aMiddlePoint = middlePointOnBSpline(aFeature, theSketch);
1392 return aMiddlePoint;
1395 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1396 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1398 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1399 theMovedEntity.fillMessage(aMessage);
1401 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1402 if (aMessage->movedAttribute())
1403 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1405 anOriginalPosition = middlePoint(aMessage->movedObject(), this);
1407 if (!anOriginalPosition)
1408 return; // something has gone wrong, do not process movement
1410 aMessage->setOriginalPosition(anOriginalPosition);
1411 aMessage->setCurrentPosition(theTargetPoint);
1412 Events_Loop::loop()->send(aMessage);
1415 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1416 double theTargetX, double theTargetY)
1418 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1419 move(theMovedEntity, aTargetPoint);
1422 //--------------------------------------------------------------------------------------
1424 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1426 FeaturePtr aBase = feature();
1427 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1428 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1429 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1430 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1431 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1432 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1433 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1435 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1438 //--------------------------------------------------------------------------------------
1440 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1442 // collect edges of the first face
1443 std::list<GeomShapePtr> anEdges1;
1444 for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1445 anEdges1.push_back(anExp.current());
1446 // compare edges of faces
1447 for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1448 GeomShapePtr aCurrent = anExp.current();
1449 bool isFound = false;
1450 std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1451 for (; anIt1 != anEdges1.end(); ++anIt1)
1452 if (aCurrent->isSameGeometry(*anIt1)) {
1454 anEdges1.erase(anIt1);
1460 return !anEdges1.empty();
1463 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1465 ResultConstructionPtr aSketchResult =
1466 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1470 std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1471 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1475 // collect faces constructed by SketchBuilder algorithm
1476 GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1477 aWires->norm(), aWires);
1478 const ListOfShape& aFaces = aSketchBuilder.faces();
1480 // compare faces stored in sketch with faces generated by SketchBuilder
1481 int aNbSketchFaces = aSketchResult->facesNum();
1483 for (ListOfShape::const_iterator aFIt = aFaces.begin();
1484 aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1485 ++aFIt, ++aFaceIndex) {
1486 GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1487 GeomFacePtr aCurFace = (*aFIt)->face();
1488 if (isDifferent(aSketchFace, aCurFace))
1494 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1495 std::list<std::list<ResultPtr> >& theEdges)
1497 ResultConstructionPtr aSketchResult =
1498 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1502 // collect curves of the sketch
1503 std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1504 int aSubNum = theSketch->numberOfSubs();
1505 for (int a = 0; a < aSubNum; ++a) {
1506 FeaturePtr aSub = theSketch->subFeature(a);
1507 const std::list<ResultPtr>& aResults = aSub->results();
1508 std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1509 for (; aRes != aResults.cend(); aRes++) {
1510 GeomShapePtr aCurShape = (*aRes)->shape();
1511 if (aCurShape && aCurShape->isEdge())
1512 aCurves[untrimmedCurve(aCurShape)] = *aRes;
1516 // convert each face to the list of results of its edges
1517 int aFacesNum = aSketchResult->facesNum();
1518 for (int a = 0; a < aFacesNum; ++a) {
1519 theEdges.push_back(std::list<ResultPtr>());
1520 std::list<ResultPtr>& aCurEdges = theEdges.back();
1522 GeomFacePtr aFace = aSketchResult->face(a);
1523 for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1524 anExp.more(); anExp.next()) {
1525 GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1526 aCurEdges.push_back(aCurves[aCurrent]);
1531 //--------------------------------------------------------------------------------------
1533 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1535 FeaturePtr aBase = feature();
1536 const std::string& aDocName = theDumper.name(aBase->document());
1538 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1539 if (anExternal->value()) {
1540 theDumper << aBase << " = model.addSketch(" << aDocName <<
1541 ", " << anExternal << ")" << std::endl;
1543 // Sketch is base on a plane.
1544 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1545 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1546 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1547 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1548 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1549 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1551 // Check the plane is coordinate plane
1552 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1553 if(anExternal->context()) { // checking for selected planes
1554 if (!aPlaneName.empty()
1555 && anExternal->context()->data()
1556 && anExternal->context()->data()->name() == aPlaneName) {
1557 // dump sketch based on coordinate plane
1558 theDumper << aBase << " = model.addSketch(" << aDocName
1559 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1560 } else { // some other plane
1561 theDumper << aBase << " = model.addSketch(" << aDocName <<
1562 ", " << anExternal<< ")" << std::endl;
1565 if (aPlaneName.empty()) {
1566 // needs import additional module
1567 theDumper.importModule("GeomAPI");
1568 // dump plane parameters
1569 const std::string& aSketchName = theDumper.name(aBase);
1570 std::string anOriginName = aSketchName + "_origin";
1571 std::string aNormalName = aSketchName + "_norm";
1572 std::string aDirXName = aSketchName + "_dirx";
1573 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1574 // and then dumplicate dumping it in the next line
1575 theDumper << anOriginName << " = " << anOrigin << "\n"
1576 << aNormalName << " = " << aNormal << "\n"
1577 << aDirXName << " = " << aDirX << "\n";
1578 // dump sketch based on arbitrary plane
1579 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1580 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1582 // dump sketch based on coordinate plane
1583 theDumper << aBase << " = model.addSketch(" << aDocName
1584 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1589 // dump sketch's subfeatures
1590 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1591 theDumper.processSubs(aCompFeat, true);
1593 // if face order differs to the order generated by SketchBuilder,
1594 // dump the list of faces for correct execution of the script
1595 if (isCustomFacesOrder(aCompFeat)) {
1596 std::list<std::list<ResultPtr> > aFaces;
1597 edgesOfSketchFaces(aCompFeat, aFaces);
1599 const std::string& aSketchName = theDumper.name(aBase);
1600 std::string aMethodName(".changeFacesOrder");
1601 std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1603 theDumper << aSketchName << aMethodName << "([";
1604 for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1605 aFIt != aFaces.end(); ++aFIt) {
1606 if (aFIt != aFaces.begin())
1607 theDumper << ",\n" << aSpaceShift << " ";
1610 theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1611 // call model.do() for correct update of the document's labels related to the changed faces
1612 theDumper << "model.do()" << std::endl;