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_MacroRectangle.h"
71 #include "SketchAPI_Mirror.h"
72 #include "SketchAPI_Offset.h"
73 #include "SketchAPI_Point.h"
74 #include "SketchAPI_Projection.h"
75 #include "SketchAPI_Rectangle.h"
76 #include "SketchAPI_Rotation.h"
77 #include "SketchAPI_Translation.h"
78 //--------------------------------------------------------------------------------------
79 #include <GeomAPI_Curve.h>
80 #include <GeomAPI_Dir2d.h>
81 #include <GeomAPI_PlanarEdges.h>
82 #include <GeomAPI_ShapeExplorer.h>
83 #include <GeomAPI_XY.h>
84 #include <GeomAlgoAPI_SketchBuilder.h>
88 //--------------------------------------------------------------------------------------
89 SketchAPI_Sketch::SketchAPI_Sketch(
90 const std::shared_ptr<ModelAPI_Feature> & theFeature)
91 : ModelHighAPI_Interface(theFeature)
96 SketchAPI_Sketch::SketchAPI_Sketch(
97 const std::shared_ptr<ModelAPI_Feature> & theFeature,
98 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
99 : ModelHighAPI_Interface(theFeature)
106 SketchAPI_Sketch::SketchAPI_Sketch(
107 const std::shared_ptr<ModelAPI_Feature> & theFeature,
108 const ModelHighAPI_Selection & theExternal)
109 : ModelHighAPI_Interface(theFeature)
112 setExternal(theExternal);
116 SketchAPI_Sketch::SketchAPI_Sketch(
117 const std::shared_ptr<ModelAPI_Feature> & theFeature,
118 std::shared_ptr<ModelAPI_Object> thePlaneObject)
119 : ModelHighAPI_Interface(theFeature)
122 setExternal(thePlaneObject);
126 SketchAPI_Sketch::~SketchAPI_Sketch()
131 //--------------------------------------------------------------------------------------
132 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
134 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
137 //--------------------------------------------------------------------------------------
138 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
140 fillAttribute(thePlane->origin(), myorigin);
141 fillAttribute(thePlane->dirX(), mydirX);
142 fillAttribute(thePlane->normal(), mynormal);
147 void SketchAPI_Sketch::setPlane(const ModelHighAPI_Selection & thePlane,
148 bool theRemoveExternalDependency)
150 FeaturePtr aSketch = feature();
152 DocumentPtr aDoc = aSketch->document();
153 bool useVisible = false;
154 FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
155 aDoc->setCurrentFeature(aSketch, useVisible);
157 if (theRemoveExternalDependency)
158 aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
160 setExternal(thePlane);
162 aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
165 //--------------------------------------------------------------------------------------
166 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
168 fillAttribute(theExternal, myexternal);
173 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
175 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
176 ModelHighAPI_Selection aSel(aRes);
180 //--------------------------------------------------------------------------------------
181 void SketchAPI_Sketch::setValue(
182 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
183 const ModelHighAPI_Double & theValue)
185 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
187 // theConstraint->execute();
190 //--------------------------------------------------------------------------------------
191 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
193 const_cast<SketchAPI_Sketch*>(this)->execute();
195 std::list<ModelHighAPI_Selection> aSelectionList;
197 ResultConstructionPtr aResultConstruction =
198 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
199 if (aResultConstruction.get() == NULL)
200 return aSelectionList;
202 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
203 aSelectionList.push_back(
204 ModelHighAPI_Selection(aResultConstruction,
205 aResultConstruction->face(anIndex)));
208 return aSelectionList;
211 //--------------------------------------------------------------------------------------
212 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
213 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
215 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
216 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
219 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
220 const ModelHighAPI_Selection & theExternal)
222 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
223 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
226 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
227 const std::wstring & theExternalName)
229 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
231 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
234 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
235 std::shared_ptr<ModelAPI_Object> thePlaneObject)
237 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
238 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
241 //--------------------------------------------------------------------------------------
242 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
243 const SketchPtr & theSketch)
245 FeaturePtr aCopyer = thePart->addFeature(SketchPlugin_SketchCopy::ID());
246 aCopyer->reference(SketchPlugin_SketchCopy::BASE_ID())->setValue(theSketch->feature());
249 FeaturePtr aNewSketch = thePart->nextFeature(aCopyer);
251 // perform removing the macro-feature
252 thePart->removeFeature(aCopyer);
255 return SketchPtr(new SketchAPI_Sketch(aNewSketch));
259 //--------------------------------------------------------------------------------------
260 std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
262 std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
263 std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
264 for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
265 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
266 PointPtr aPoint(new SketchAPI_Point(aFeature));
267 aFreePoints.push_back(aPoint);
272 //--------------------------------------------------------------------------------------
273 static GeomCurvePtr untrimmedCurve(GeomShapePtr theShape)
275 GeomCurvePtr aCurve(new GeomAPI_Curve(theShape));
276 if (aCurve->isTrimmed())
277 aCurve = aCurve->basisCurve();
281 void SketchAPI_Sketch::changeFacesOrder(
282 const std::list<std::list<ModelHighAPI_Selection> >& theFaces)
284 // collect faces of the sketch
285 ResultConstructionPtr aSketchResult =
286 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
287 if (!aSketchResult) {
288 // sketch is nested to a boolean operation, thus, it has no result yet.
289 feature()->execute();
291 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
293 std::list<GeomFacePtr> aFaces;
294 int aFacesNum = aSketchResult->facesNum();
295 for (int i = 0; i < aFacesNum; ++i)
296 aFaces.push_back(aSketchResult->face(i));
297 // find new faces order according to the given lists of edges
298 std::list<GeomFacePtr> aNewFacesOrder;
299 std::list<std::list<ModelHighAPI_Selection> >::const_iterator anIt = theFaces.begin();
300 for (; anIt != theFaces.end(); ++anIt) {
301 // find the appropriate face
302 std::list<GeomFacePtr>::iterator aFIt = aFaces.begin();
303 for (; aFIt != aFaces.end(); ++aFIt) {
304 std::list<ModelHighAPI_Selection>::const_iterator aEdgeIt = anIt->begin();
305 GeomAPI_ShapeExplorer aFExp(*aFIt, GeomAPI_Shape::EDGE);
306 for (; aEdgeIt != anIt->end() && aFExp.more(); ++aEdgeIt, aFExp.next()) {
307 ResultPtr aCurRes = aEdgeIt->resultSubShapePair().first;
310 GeomCurvePtr aCurve1 = untrimmedCurve(aCurRes->shape());
311 GeomCurvePtr aCurve2 = untrimmedCurve(aFExp.current());
312 if (!aCurve1->isEqual(aCurve2))
316 if (aEdgeIt == anIt->end() && !aFExp.more()) {
318 aNewFacesOrder.push_back(*aFIt);
324 // place the rest faces at the end of new faces list
326 aNewFacesOrder.insert(aNewFacesOrder.end(), aFaces.begin(), aFaces.end());
327 // update the result of the sketch with the new order of faces
328 aSketchResult->setFacesOrder(aNewFacesOrder);
331 //--------------------------------------------------------------------------------------
332 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
333 double theX, double theY)
335 std::shared_ptr<ModelAPI_Feature> aFeature =
336 compositeFeature()->addFeature(SketchPlugin_Point::ID());
337 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
339 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
340 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
342 std::shared_ptr<ModelAPI_Feature> aFeature =
343 compositeFeature()->addFeature(SketchPlugin_Point::ID());
344 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
346 std::shared_ptr<SketchAPI_Point>
347 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
349 std::shared_ptr<ModelAPI_Feature> aFeature =
350 compositeFeature()->addFeature(SketchPlugin_Point::ID());
351 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
353 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::wstring & theExternalName)
355 std::shared_ptr<ModelAPI_Feature> aFeature =
356 compositeFeature()->addFeature(SketchPlugin_Point::ID());
357 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
360 //--------------------------------------------------------------------------------------
361 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
362 const ModelHighAPI_Selection & theExternal,
365 std::shared_ptr<ModelAPI_Feature> aFeature =
366 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
367 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
368 anIntersection->setIncludeToResult(theKeepResult);
369 return anIntersection;
371 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
372 const std::wstring & theExternalName,
375 std::shared_ptr<ModelAPI_Feature> aFeature =
376 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
377 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
378 anIntersection->setIncludeToResult(theKeepResult);
379 return anIntersection;
382 //--------------------------------------------------------------------------------------
383 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
384 double theX2, double theY2)
386 std::shared_ptr<ModelAPI_Feature> aFeature =
387 compositeFeature()->addFeature(SketchPlugin_Line::ID());
388 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
390 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
391 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
392 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
394 std::shared_ptr<ModelAPI_Feature> aFeature =
395 compositeFeature()->addFeature(SketchPlugin_Line::ID());
396 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
398 std::shared_ptr<SketchAPI_Line>
399 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
401 std::shared_ptr<ModelAPI_Feature> aFeature =
402 compositeFeature()->addFeature(SketchPlugin_Line::ID());
403 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
405 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::wstring & theExternalName)
407 std::shared_ptr<ModelAPI_Feature> aFeature =
408 compositeFeature()->addFeature(SketchPlugin_Line::ID());
409 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
412 //--------------------------------------------------------------------------------------
413 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
414 double theX2, double theY2)
416 std::shared_ptr<ModelAPI_Feature> aFeature =
417 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
418 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
420 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
421 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
422 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
424 std::shared_ptr<ModelAPI_Feature> aFeature =
425 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
426 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
429 std::shared_ptr<SketchAPI_MacroRectangle> SketchAPI_Sketch::addRectangle(
430 double theX1, double theY1, double theX2, double theY2, bool thePoint2IsCenter)
432 std::shared_ptr<ModelAPI_Feature> aFeature =
433 compositeFeature()->addFeature(SketchAPI_MacroRectangle::ID());
434 return MacroRectanglePtr(new SketchAPI_MacroRectangle(aFeature, theX1, theY1, theX2, theY2, thePoint2IsCenter));
436 std::shared_ptr<SketchAPI_MacroRectangle> SketchAPI_Sketch::addRectangle(
437 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
438 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint, bool theEndPointIsCenter)
440 std::shared_ptr<ModelAPI_Feature> aFeature =
441 compositeFeature()->addFeature(SketchAPI_MacroRectangle::ID());
442 return MacroRectanglePtr(new SketchAPI_MacroRectangle(aFeature, theStartPoint, theEndPoint, theEndPointIsCenter));
445 //--------------------------------------------------------------------------------------
446 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
450 std::shared_ptr<ModelAPI_Feature> aFeature =
451 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
452 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
455 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
456 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
459 std::shared_ptr<ModelAPI_Feature> aFeature =
460 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
461 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
464 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
469 std::shared_ptr<ModelAPI_Feature> aFeature =
470 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
471 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
472 thePassedX, thePassedY));
475 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
476 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
477 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
479 std::shared_ptr<ModelAPI_Feature> aFeature =
480 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
481 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
484 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
485 double theX2, double theY2,
486 double theX3, double theY3)
488 std::shared_ptr<ModelAPI_Feature> aFeature =
489 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
490 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
495 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
496 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
497 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
498 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
500 std::shared_ptr<ModelAPI_Feature> aFeature =
501 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
502 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
505 std::shared_ptr<SketchAPI_Circle>
506 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
508 std::shared_ptr<ModelAPI_Feature> aFeature =
509 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
510 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
513 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::wstring & theExternalName)
515 std::shared_ptr<ModelAPI_Feature> aFeature =
516 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
517 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
520 //--------------------------------------------------------------------------------------
521 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
522 double theStartX, double theStartY,
523 double theEndX, double theEndY,
526 std::shared_ptr<ModelAPI_Feature> aFeature =
527 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
528 return ArcPtr(new SketchAPI_Arc(aFeature,
529 theCenterX, theCenterY,
530 theStartX, theStartY,
535 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
536 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
537 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
538 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
541 std::shared_ptr<ModelAPI_Feature> aFeature =
542 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
543 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
546 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
547 double theEndX, double theEndY,
548 double thePassedX, double thePassedY)
550 std::shared_ptr<ModelAPI_Feature> aFeature =
551 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
552 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
553 theStartX, theStartY,
555 thePassedX, thePassedY));
558 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
559 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
560 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
561 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
563 std::shared_ptr<ModelAPI_Feature> aFeature =
564 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
565 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
568 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
569 const ModelHighAPI_RefAttr& theTangentPoint,
570 double theEndX, double theEndY,
574 std::shared_ptr<ModelAPI_Feature> aFeature =
575 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
576 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
578 aMacroArc->setByTransversal(theTangentPoint, theEndX, theEndY, theInversed);
580 aMacroArc->setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
584 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
585 const ModelHighAPI_RefAttr& theTangentPoint,
586 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
590 std::shared_ptr<ModelAPI_Feature> aFeature =
591 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
592 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
594 aMacroArc->setByTransversal(theTangentPoint, theEnd, theInversed);
596 aMacroArc->setByTangent(theTangentPoint, theEnd, theInversed);
600 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
602 std::shared_ptr<ModelAPI_Feature> aFeature =
603 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
604 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
607 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::wstring & theExternalName)
609 std::shared_ptr<ModelAPI_Feature> aFeature =
610 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
611 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
614 //--------------------------------------------------------------------------------------
615 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
616 double theCenterX, double theCenterY,
617 double theFocusX, double theFocusY,
618 double theMinorRadius)
620 std::shared_ptr<ModelAPI_Feature> aFeature =
621 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
622 return EllipsePtr(new SketchAPI_Ellipse(aFeature,
623 theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius));
626 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
627 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
628 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
629 double theMinorRadius)
631 std::shared_ptr<ModelAPI_Feature> aFeature =
632 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
633 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius));
636 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
637 double thePoint1X, double thePoint1Y,
638 double thePoint2X, double thePoint2Y,
639 double thePassedX, double thePassedY,
642 std::shared_ptr<ModelAPI_Feature> aFeature =
643 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
644 return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature,
645 thePoint1X, thePoint1Y, thePoint2X, thePoint2Y, thePassedX, thePassedY, isPoint1Center));
648 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
649 const PointOrReference& thePoint1,
650 const PointOrReference& thePoint2,
651 const PointOrReference& thePassedPoint,
654 std::shared_ptr<ModelAPI_Feature> aFeature =
655 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
656 MacroEllipsePtr anEllipse;
657 if (thePoint1.second.isEmpty() &&
658 thePoint2.second.isEmpty() &&
659 thePassedPoint.second.isEmpty()) {
660 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
661 thePoint1.first, thePoint2.first, thePassedPoint.first, isPoint1Center));
664 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
665 thePoint1.first, thePoint1.second,
666 thePoint2.first, thePoint2.second,
667 thePassedPoint.first, thePassedPoint.second,
673 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
674 const ModelHighAPI_Selection & theExternal)
676 std::shared_ptr<ModelAPI_Feature> aFeature =
677 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
678 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal));
681 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
682 const std::wstring & theExternalName)
684 std::shared_ptr<ModelAPI_Feature> aFeature =
685 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
686 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName));
689 //--------------------------------------------------------------------------------------
690 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
691 double theCenterX, double theCenterY,
692 double theFocusX, double theFocusY,
693 double theStartX, double theStartY,
694 double theEndX, double theEndY,
697 std::shared_ptr<ModelAPI_Feature> aFeature =
698 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
699 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature,
700 theCenterX, theCenterY,
701 theFocusX, theFocusY,
702 theStartX, theStartY,
707 std::shared_ptr<SketchAPI_MacroEllipticArc> SketchAPI_Sketch::addEllipticArc(
708 const PointOrReference& theCenter,
709 const PointOrReference& theMajorAxisPoint,
710 const PointOrReference& theStartPoint,
711 const PointOrReference& theEndPoint,
714 std::shared_ptr<ModelAPI_Feature> aFeature =
715 compositeFeature()->addFeature(SketchPlugin_MacroEllipticArc::ID());
716 return MacroEllipticArcPtr(new SketchAPI_MacroEllipticArc(aFeature,
717 theCenter.first, theCenter.second,
718 theMajorAxisPoint.first, theMajorAxisPoint.second,
719 theStartPoint.first, theStartPoint.second,
720 theEndPoint.first, theEndPoint.second,
724 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
725 const ModelHighAPI_Selection & theExternal)
727 std::shared_ptr<ModelAPI_Feature> aFeature =
728 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
729 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternal));
732 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
733 const std::wstring & theExternalName)
735 std::shared_ptr<ModelAPI_Feature> aFeature =
736 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
737 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternalName));
740 //--------------------------------------------------------------------------------------
742 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(
743 const ModelHighAPI_Selection & external,
745 const std::list<PointOrReference>& poles,
746 const std::list<ModelHighAPI_Double>& weights,
747 const std::list<ModelHighAPI_Double>& knots,
748 const std::list<ModelHighAPI_Integer>& multiplicities,
751 // split poles and references to other shapes
752 bool hasReference = false;
753 std::list<GeomPnt2dPtr> aPoints;
754 std::list<ModelHighAPI_RefAttr> aReferences;
755 for (std::list<PointOrReference>::const_iterator it = poles.begin(); it != poles.end(); ++it) {
756 aPoints.push_back(it->first);
757 aReferences.push_back(it->second);
758 if (!it->second.isEmpty())
763 CompositeFeaturePtr aSketch = compositeFeature();
765 // use macro-feature to create coincidences to referred features
766 FeaturePtr aMacroFeature = aSketch->addFeature(
767 periodic ? SketchPlugin_MacroBSplinePeriodic::ID() : SketchPlugin_MacroBSpline::ID());
768 AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
769 aMacroFeature->attribute(SketchPlugin_MacroBSpline::POLES_ID()));
770 AttributeDoubleArrayPtr aWeightsAttr =
771 aMacroFeature->data()->realArray(SketchPlugin_MacroBSpline::WEIGHTS_ID());
772 AttributeRefAttrListPtr aPolesRefAttr =
773 aMacroFeature->data()->refattrlist(SketchPlugin_MacroBSpline::REF_POLES_ID());
774 // always generate a control polygon to apply coincidences correctly
775 aMacroFeature->boolean(SketchPlugin_MacroBSpline::CONTROL_POLYGON_ID())->setValue(true);
776 // initialize B-spline attributes
777 fillAttribute(aPoints, aPolesAttr);
779 fillAttribute(std::list<ModelHighAPI_Double>(poles.size(), 1.0), aWeightsAttr);
781 fillAttribute(weights, aWeightsAttr);
782 fillAttribute(aReferences, aPolesRefAttr);
783 apply(); // to kill macro-feature
785 // find created B-spline feature
786 const std::string& aKindToFind =
787 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID();
788 int aNbSubs = aSketch->numberOfSubs();
789 for (int anIndex = aNbSubs - 1; anIndex >= 0; --anIndex) {
790 FeaturePtr aFeature = aSketch->subFeature(anIndex);
791 if (aFeature->getKind() == aKindToFind) {
792 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
793 : new SketchAPI_BSpline(aFeature));
800 // compute B-spline by parameters
801 FeaturePtr aFeature = aSketch->addFeature(
802 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
804 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
805 : new SketchAPI_BSpline(aFeature));
806 if (external.variantType() != ModelHighAPI_Selection::VT_Empty)
807 aBSpline->setByExternal(external);
808 else if (knots.empty() || multiplicities.empty())
809 aBSpline->setByDegreePolesAndWeights(degree, aPoints, weights);
811 aBSpline->setByParameters(degree, aPoints, weights, knots, multiplicities);
816 //--------------------------------------------------------------------------------------
817 static std::shared_ptr<SketchAPI_BSpline> buildInterpolation(
818 const CompositeFeaturePtr& theSketch,
819 const FeaturePtr& theCurveFittingFeature,
820 const std::list<ModelHighAPI_RefAttr>& points,
824 AttributeBooleanPtr aPeriodicAttr =
825 theCurveFittingFeature->boolean(SketchPlugin_CurveFitting::PERIODIC_ID());
826 fillAttribute(periodic, aPeriodicAttr);
827 AttributeBooleanPtr aClosedAttr =
828 theCurveFittingFeature->boolean(SketchPlugin_CurveFitting::CLOSED_ID());
829 fillAttribute(closed, aClosedAttr);
830 AttributeRefAttrListPtr aPointsAttr =
831 theCurveFittingFeature->refattrlist(SketchPlugin_CurveFitting::POINTS_ID());
832 fillAttribute(points, aPointsAttr);
833 apply(); // to execute and kill the macro-feature
835 // find created B-spline feature
837 const std::string& aKindToFind =
838 periodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID();
839 int aNbSubs = theSketch->numberOfSubs();
840 for (int anIndex = aNbSubs - 1; anIndex >= 0; --anIndex) {
841 FeaturePtr aFeature = theSketch->subFeature(anIndex);
842 if (aFeature->getKind() == aKindToFind) {
843 aBSpline.reset(periodic ? new SketchAPI_BSplinePeriodic(aFeature)
844 : new SketchAPI_BSpline(aFeature));
852 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addInterpolation(
853 const std::list<ModelHighAPI_RefAttr>& points,
857 CompositeFeaturePtr aSketch = compositeFeature();
858 FeaturePtr anInterpFeature = aSketch->addFeature(SketchPlugin_CurveFitting::ID());
859 anInterpFeature->string(SketchPlugin_CurveFitting::TYPE_ID())
860 ->setValue(SketchPlugin_CurveFitting::TYPE_INTERPOLATION_ID());
861 return buildInterpolation(aSketch, anInterpFeature, points, periodic, closed);
864 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addApproximation(
865 const std::list<ModelHighAPI_RefAttr>& points,
866 const ModelHighAPI_Double& precision,
870 CompositeFeaturePtr aSketch = compositeFeature();
871 FeaturePtr anInterpFeature = aSketch->addFeature(SketchPlugin_CurveFitting::ID());
872 anInterpFeature->string(SketchPlugin_CurveFitting::TYPE_ID())
873 ->setValue(SketchPlugin_CurveFitting::TYPE_APPROXIMATION_ID());
874 fillAttribute(precision, anInterpFeature->real(SketchPlugin_CurveFitting::PRECISION_ID()));
875 return buildInterpolation(aSketch, anInterpFeature, points, periodic, closed);
878 //--------------------------------------------------------------------------------------
879 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
880 const ModelHighAPI_Selection & theExternalFeature,
882 bool keepRefToOriginal)
884 std::shared_ptr<ModelAPI_Feature> aFeature =
885 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
886 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature));
887 aProjection->setIncludeToResult(keepResult);
888 aProjection->setKeepReferenceToOriginal(keepRefToOriginal);
889 aProjection->setExternalFeature(theExternalFeature);
893 //--------------------------------------------------------------------------------------
894 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
895 const ModelHighAPI_RefAttr & theMirrorLine,
896 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
898 std::shared_ptr<ModelAPI_Feature> aFeature =
899 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
900 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
903 //--------------------------------------------------------------------------------------
904 std::shared_ptr<SketchAPI_Offset> SketchAPI_Sketch::addOffset(
905 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
906 const ModelHighAPI_Double & theValue,
907 const bool theReversed)
909 std::shared_ptr<ModelAPI_Feature> aFeature =
910 compositeFeature()->addFeature(SketchPlugin_Offset::ID());
911 return OffsetPtr(new SketchAPI_Offset(aFeature, theObjects, theValue, theReversed));
914 //--------------------------------------------------------------------------------------
915 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
916 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
917 const ModelHighAPI_RefAttr & thePoint1,
918 const ModelHighAPI_RefAttr & thePoint2,
919 const ModelHighAPI_Integer & theNumberOfObjects,
922 std::shared_ptr<ModelAPI_Feature> aFeature =
923 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
924 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
925 thePoint2, theNumberOfObjects, theFullValue));
928 //--------------------------------------------------------------------------------------
929 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
930 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
931 const ModelHighAPI_RefAttr & theCenter,
932 const ModelHighAPI_Double & theAngle,
933 const ModelHighAPI_Integer & theNumberOfObjects,
937 std::shared_ptr<ModelAPI_Feature> aFeature =
938 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
940 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
941 theAngle, theNumberOfObjects, theFullValue, theReversed));
944 //--------------------------------------------------------------------------------------
945 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
946 const ModelHighAPI_Reference& theFeature,
947 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
949 std::shared_ptr<ModelAPI_Feature> aFeature =
950 compositeFeature()->addFeature(SketchPlugin_Split::ID());
951 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
953 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
954 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
955 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
956 fillAttribute(thePositionPoint, aPointAttr);
959 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
962 //--------------------------------------------------------------------------------------
963 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
964 const ModelHighAPI_Reference& theFeature,
965 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
967 std::shared_ptr<ModelAPI_Feature> aFeature =
968 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
969 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
971 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
972 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
973 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
974 fillAttribute(thePositionPoint, aPointAttr);
977 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
980 //--------------------------------------------------------------------------------------
981 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
982 const ModelHighAPI_RefAttr & theLine1,
983 const ModelHighAPI_RefAttr & theLine2,
984 const ModelHighAPI_Double & theValue,
985 const std::string& theType)
987 std::shared_ptr<ModelAPI_Feature> aFeature =
988 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
990 const int aVersion = theType.empty() ? SketchPlugin_ConstraintAngle::THE_VERSION_0
991 : SketchPlugin_ConstraintAngle::THE_VERSION_1;
992 fillAttribute(aVersion, aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
994 int aType = (int)SketcherPrs_Tools::ANGLE_DIRECT;
995 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::PREV_TYPE_ID()));
996 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
998 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_0)
999 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1001 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1002 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1004 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_1) {
1005 std::string aTypeLC = theType;
1006 std::transform(aTypeLC.begin(), aTypeLC.end(), aTypeLC.begin(),
1007 [](char c) { return static_cast<char>(::tolower(c)); });
1008 if (aTypeLC == "supplementary")
1009 aType = (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
1010 else if (aTypeLC == "backward")
1011 aType = (int)SketcherPrs_Tools::ANGLE_BACKWARD;
1013 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1014 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1017 aFeature->execute();
1018 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1021 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
1022 const ModelHighAPI_RefAttr & theLine1,
1023 const ModelHighAPI_RefAttr & theLine2,
1024 const ModelHighAPI_Double & theValue)
1026 std::shared_ptr<ModelAPI_Feature> aFeature =
1027 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
1028 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
1029 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
1030 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
1031 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1032 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1033 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1034 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1035 aFeature->execute();
1036 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1039 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
1040 const ModelHighAPI_RefAttr & theLine1,
1041 const ModelHighAPI_RefAttr & theLine2,
1042 const ModelHighAPI_Double & theValue)
1044 std::shared_ptr<ModelAPI_Feature> aFeature =
1045 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
1046 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
1047 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
1048 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
1049 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
1050 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
1051 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1052 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1053 aFeature->execute();
1054 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1057 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
1058 const ModelHighAPI_RefAttr & thePoint1,
1059 const ModelHighAPI_RefAttr & thePoint2)
1061 std::shared_ptr<ModelAPI_Feature> aFeature =
1062 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
1063 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1064 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1065 aFeature->execute();
1066 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1069 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
1070 const ModelHighAPI_RefAttr & theLine1,
1071 const ModelHighAPI_RefAttr & theLine2)
1073 std::shared_ptr<ModelAPI_Feature> aFeature =
1074 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
1075 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1076 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1077 aFeature->execute();
1078 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1081 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
1082 const ModelHighAPI_RefAttr & thePoint,
1083 const ModelHighAPI_RefAttr & thePointOrLine,
1084 const ModelHighAPI_Double & theValue,
1087 std::shared_ptr<ModelAPI_Feature> aFeature =
1088 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
1089 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1090 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1091 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1092 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
1093 aFeature->execute();
1094 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1097 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
1098 const ModelHighAPI_RefAttr & thePoint,
1099 const ModelHighAPI_RefAttr & thePointOrLine,
1100 const ModelHighAPI_Double & theValue)
1102 return setDistance(thePoint, thePointOrLine, theValue, true);
1105 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
1106 const ModelHighAPI_RefAttr & thePoint,
1107 const ModelHighAPI_RefAttr & thePointOrLine,
1108 const ModelHighAPI_Double & theValue)
1110 return setDistance(thePoint, thePointOrLine, theValue, false);
1113 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
1114 const ModelHighAPI_RefAttr & thePoint1,
1115 const ModelHighAPI_RefAttr & thePoint2,
1116 const ModelHighAPI_Double & theValue)
1118 std::shared_ptr<ModelAPI_Feature> aFeature =
1119 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
1120 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1121 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1122 fillAttribute(theValue,
1123 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1124 aFeature->execute();
1125 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1128 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
1129 const ModelHighAPI_RefAttr & thePoint1,
1130 const ModelHighAPI_RefAttr & thePoint2,
1131 const ModelHighAPI_Double & theValue)
1133 std::shared_ptr<ModelAPI_Feature> aFeature =
1134 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
1135 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1136 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1137 fillAttribute(theValue,
1138 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
1139 aFeature->execute();
1140 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1143 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
1144 const ModelHighAPI_RefAttr & theObject1,
1145 const ModelHighAPI_RefAttr & theObject2)
1147 std::shared_ptr<ModelAPI_Feature> aFeature =
1148 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
1149 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1150 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1151 aFeature->execute();
1152 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1155 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
1156 const ModelHighAPI_RefAttr & thePoint)
1158 std::shared_ptr<ModelAPI_Feature> aFeature =
1159 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
1160 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
1161 apply(); // finish operation to remove Fillet feature correcly
1162 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1165 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
1166 const ModelHighAPI_RefAttr & thePoint,
1167 const ModelHighAPI_Double & theRadius)
1169 CompositeFeaturePtr aSketch = compositeFeature();
1170 int aNbSubs = aSketch->numberOfSubs();
1173 InterfacePtr aFilletFeature = setFillet(thePoint);
1175 // set radius for just created arc
1176 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
1177 if (anArc->getKind() == SketchPlugin_Arc::ID())
1178 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
1180 return aFilletFeature;
1183 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
1184 const ModelHighAPI_RefAttr & theObject)
1186 std::shared_ptr<ModelAPI_Feature> aFeature =
1187 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
1188 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1189 aFeature->execute();
1190 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1193 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
1194 const ModelHighAPI_RefAttr & theLine)
1196 std::shared_ptr<ModelAPI_Feature> aFeature =
1197 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1198 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1199 aFeature->execute();
1200 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1203 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1204 const ModelHighAPI_RefAttr & theLine,
1205 const ModelHighAPI_Double & theValue)
1207 std::shared_ptr<ModelAPI_Feature> aFeature =
1208 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1209 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1210 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1211 aFeature->execute();
1212 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1215 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1216 const ModelHighAPI_RefAttr & thePoint,
1217 const ModelHighAPI_RefAttr & theLine)
1219 std::shared_ptr<ModelAPI_Feature> aFeature =
1220 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1221 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1222 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1223 aFeature->execute();
1224 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1227 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1228 const ModelHighAPI_RefAttr & theLine1,
1229 const ModelHighAPI_RefAttr & theLine2)
1231 std::shared_ptr<ModelAPI_Feature> aFeature =
1232 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1233 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1234 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1235 aFeature->execute();
1236 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1239 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1240 const ModelHighAPI_RefAttr & theLine1,
1241 const ModelHighAPI_RefAttr & theLine2)
1243 std::shared_ptr<ModelAPI_Feature> aFeature =
1244 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1245 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1246 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1247 aFeature->execute();
1248 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1251 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1252 const ModelHighAPI_RefAttr & theCircleOrArc,
1253 const ModelHighAPI_Double & theValue)
1255 std::shared_ptr<ModelAPI_Feature> aFeature =
1256 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1257 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1258 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1259 aFeature->execute();
1260 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1263 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1264 const ModelHighAPI_RefAttr & theLine,
1265 const ModelHighAPI_RefAttr & theCircle)
1267 std::shared_ptr<ModelAPI_Feature> aFeature =
1268 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1269 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1270 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1271 aFeature->execute();
1272 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1275 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1276 const ModelHighAPI_RefAttr & theLine)
1278 std::shared_ptr<ModelAPI_Feature> aFeature =
1279 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1280 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1281 aFeature->execute();
1282 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1285 //--------------------------------------------------------------------------------------
1287 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1289 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1290 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1293 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1295 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1296 theFeature->attribute(SketchPlugin_Line::START_ID()));
1297 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1298 theFeature->attribute(SketchPlugin_Line::END_ID()));
1300 if (!aStartAttr || !aEndAttr)
1301 return std::shared_ptr<GeomAPI_Pnt2d>();
1303 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1304 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1305 return std::shared_ptr<GeomAPI_Pnt2d>(
1306 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1309 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1311 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1312 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1313 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1315 if (!aCenter || !aRadius)
1316 return std::shared_ptr<GeomAPI_Pnt2d>();
1318 return std::shared_ptr<GeomAPI_Pnt2d>(
1319 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1322 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1324 static const double PI = 3.141592653589793238463;
1326 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1327 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1328 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1329 theFeature->attribute(SketchPlugin_Arc::START_ID()));
1330 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1331 theFeature->attribute(SketchPlugin_Arc::END_ID()));
1333 if (!aCenterAttr || !aStartAttr || !aEndAttr)
1334 return std::shared_ptr<GeomAPI_Pnt2d>();
1336 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1337 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1338 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1339 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1341 double anAngle = aStartDir->angle(aEndDir);
1342 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1343 if (isReversed && anAngle > 0.)
1344 anAngle -= 2.0 * PI;
1345 else if (!isReversed && anAngle <= 0.)
1346 anAngle += 2.0 * PI;
1348 double cosA = cos(anAngle);
1349 double sinA = sin(anAngle);
1351 // rotate start dir to find middle point on arc
1352 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1353 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1354 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1356 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1359 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1360 bool isEllipse = true)
1362 const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1363 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1364 AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1365 theFeature->attribute(anAttrName));
1366 return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1369 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnBSpline(const FeaturePtr& theFeature,
1370 SketchAPI_Sketch* theSketch)
1372 GeomAPI_Edge anEdge(theFeature->lastResult()->shape());
1373 GeomPointPtr aMiddle = anEdge.middlePoint();
1374 return theSketch->to2D(aMiddle);
1377 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject,
1378 SketchAPI_Sketch* theSketch)
1380 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1381 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1383 // move only features of the following types
1384 const std::string& aFeatureKind = aFeature->getKind();
1385 if (aFeatureKind == SketchPlugin_Point::ID())
1386 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1387 else if (aFeatureKind == SketchPlugin_Line::ID())
1388 aMiddlePoint = middlePointOnLine(aFeature);
1389 else if (aFeatureKind == SketchPlugin_Circle::ID())
1390 aMiddlePoint = pointOnCircle(aFeature);
1391 else if (aFeatureKind == SketchPlugin_Arc::ID())
1392 aMiddlePoint = middlePointOnArc(aFeature);
1393 else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1394 aMiddlePoint = pointOnEllipse(aFeature);
1395 else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1396 aMiddlePoint = pointOnEllipse(aFeature, false);
1397 else if (aFeatureKind == SketchPlugin_BSpline::ID() ||
1398 aFeatureKind == SketchPlugin_BSplinePeriodic::ID())
1399 aMiddlePoint = middlePointOnBSpline(aFeature, theSketch);
1401 return aMiddlePoint;
1404 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1405 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1407 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1408 theMovedEntity.fillMessage(aMessage);
1410 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1411 if (aMessage->movedAttribute())
1412 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1414 anOriginalPosition = middlePoint(aMessage->movedObject(), this);
1416 if (!anOriginalPosition)
1417 return; // something has gone wrong, do not process movement
1419 aMessage->setOriginalPosition(anOriginalPosition);
1420 aMessage->setCurrentPosition(theTargetPoint);
1421 Events_Loop::loop()->send(aMessage);
1424 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1425 double theTargetX, double theTargetY)
1427 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1428 move(theMovedEntity, aTargetPoint);
1431 //--------------------------------------------------------------------------------------
1433 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1435 FeaturePtr aBase = feature();
1436 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1437 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1438 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1439 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1440 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1441 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1442 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1444 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1447 //--------------------------------------------------------------------------------------
1449 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1451 // collect edges of the first face
1452 std::list<GeomShapePtr> anEdges1;
1453 for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1454 anEdges1.push_back(anExp.current());
1455 // compare edges of faces
1456 for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1457 GeomShapePtr aCurrent = anExp.current();
1458 bool isFound = false;
1459 std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1460 for (; anIt1 != anEdges1.end(); ++anIt1)
1461 if (aCurrent->isSameGeometry(*anIt1)) {
1463 anEdges1.erase(anIt1);
1469 return !anEdges1.empty();
1472 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1474 ResultConstructionPtr aSketchResult =
1475 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1479 std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1480 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1484 // collect faces constructed by SketchBuilder algorithm
1485 GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1486 aWires->norm(), aWires);
1487 const ListOfShape& aFaces = aSketchBuilder.faces();
1489 // compare faces stored in sketch with faces generated by SketchBuilder
1490 int aNbSketchFaces = aSketchResult->facesNum();
1492 for (ListOfShape::const_iterator aFIt = aFaces.begin();
1493 aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1494 ++aFIt, ++aFaceIndex) {
1495 GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1496 GeomFacePtr aCurFace = (*aFIt)->face();
1497 if (isDifferent(aSketchFace, aCurFace))
1503 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1504 std::list<std::list<ResultPtr> >& theEdges)
1506 ResultConstructionPtr aSketchResult =
1507 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1511 // collect curves of the sketch
1512 std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1513 int aSubNum = theSketch->numberOfSubs();
1514 for (int a = 0; a < aSubNum; ++a) {
1515 FeaturePtr aSub = theSketch->subFeature(a);
1516 const std::list<ResultPtr>& aResults = aSub->results();
1517 std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1518 for (; aRes != aResults.cend(); aRes++) {
1519 GeomShapePtr aCurShape = (*aRes)->shape();
1520 if (aCurShape && aCurShape->isEdge())
1521 aCurves[untrimmedCurve(aCurShape)] = *aRes;
1525 // convert each face to the list of results of its edges
1526 int aFacesNum = aSketchResult->facesNum();
1527 for (int a = 0; a < aFacesNum; ++a) {
1528 theEdges.push_back(std::list<ResultPtr>());
1529 std::list<ResultPtr>& aCurEdges = theEdges.back();
1531 GeomFacePtr aFace = aSketchResult->face(a);
1532 for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1533 anExp.more(); anExp.next()) {
1534 GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1535 aCurEdges.push_back(aCurves[aCurrent]);
1540 //--------------------------------------------------------------------------------------
1542 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1544 FeaturePtr aBase = feature();
1545 const std::string& aDocName = theDumper.name(aBase->document());
1547 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1548 if (anExternal->value()) {
1549 theDumper << aBase << " = model.addSketch(" << aDocName <<
1550 ", " << anExternal << ")" << std::endl;
1552 // Sketch is base on a plane.
1553 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1554 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1555 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1556 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1557 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1558 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1560 // Check the plane is coordinate plane
1561 std::wstring aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1562 if(anExternal->context()) { // checking for selected planes
1563 if (!aPlaneName.empty()
1564 && anExternal->context()->data()
1565 && anExternal->context()->data()->name() == aPlaneName) {
1566 // dump sketch based on coordinate plane
1567 theDumper << aBase << " = model.addSketch(" << aDocName
1568 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1569 } else { // some other plane
1570 theDumper << aBase << " = model.addSketch(" << aDocName <<
1571 ", " << anExternal<< ")" << std::endl;
1574 if (aPlaneName.empty()) {
1575 // needs import additional module
1576 theDumper.importModule("GeomAPI");
1577 // dump plane parameters
1578 const std::string& aSketchName = theDumper.name(aBase);
1579 std::string anOriginName = aSketchName + "_origin";
1580 std::string aNormalName = aSketchName + "_norm";
1581 std::string aDirXName = aSketchName + "_dirx";
1582 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1583 // and then dumplicate dumping it in the next line
1584 theDumper << anOriginName << " = " << anOrigin << "\n"
1585 << aNormalName << " = " << aNormal << "\n"
1586 << aDirXName << " = " << aDirX << "\n";
1587 // dump sketch based on arbitrary plane
1588 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1589 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1591 // dump sketch based on coordinate plane
1592 theDumper << aBase << " = model.addSketch(" << aDocName
1593 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1598 // dump sketch's subfeatures
1599 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1600 theDumper.processSubs(aCompFeat, true);
1602 // if face order differs to the order generated by SketchBuilder,
1603 // dump the list of faces for correct execution of the script
1604 if (isCustomFacesOrder(aCompFeat)) {
1605 std::list<std::list<ResultPtr> > aFaces;
1606 edgesOfSketchFaces(aCompFeat, aFaces);
1608 /// remove faces that must not be dumped
1609 std::vector< std::list<std::list<ResultPtr>>::iterator> aFacesToRemove;
1610 for(auto itFaces = aFaces.begin(); itFaces != aFaces.end(); ++itFaces)
1612 auto & facesGroup = *itFaces;
1613 std::vector<std::list<ResultPtr>::iterator> subFacestoRemove;
1614 for(auto itGroup = facesGroup.begin(); itGroup != facesGroup.end(); ++itGroup)
1616 FeaturePtr aFeature = ModelAPI_Feature::feature(*itGroup);
1617 if(theDumper.isDumped(aFeature)){
1618 subFacestoRemove.push_back(itGroup);
1621 for(auto itGroup :subFacestoRemove){
1622 facesGroup.erase(itGroup);
1625 if(!facesGroup.size()){
1626 aFacesToRemove.push_back(itFaces);
1629 for(auto itFaces :aFacesToRemove){
1630 aFaces.erase(itFaces);
1636 const std::string& aSketchName = theDumper.name(aBase);
1637 std::string aMethodName(".changeFacesOrder");
1638 std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1640 theDumper << aSketchName << aMethodName << "([";
1641 for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1642 aFIt != aFaces.end(); ++aFIt) {
1643 if (aFIt != aFaces.begin())
1644 theDumper << ",\n" << aSpaceShift << " ";
1647 theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1648 // call model.do() for correct update of the document's labels related to the changed faces
1649 theDumper << "model.do()" << std::endl;