1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketchAPI_Sketch.h"
21 //--------------------------------------------------------------------------------------
22 #include <SketchPlugin_Constraint.h>
23 #include <SketchPlugin_ConstraintAngle.h>
24 #include <SketchPlugin_ConstraintCoincidence.h>
25 #include <SketchPlugin_ConstraintCollinear.h>
26 #include <SketchPlugin_ConstraintDistance.h>
27 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
28 #include <SketchPlugin_ConstraintDistanceVertical.h>
29 #include <SketchPlugin_ConstraintEqual.h>
30 #include <SketchPlugin_Fillet.h>
31 #include <SketchPlugin_ConstraintHorizontal.h>
32 #include <SketchPlugin_ConstraintLength.h>
33 #include <SketchPlugin_ConstraintMiddle.h>
34 #include <SketchPlugin_ConstraintMirror.h>
35 #include <SketchPlugin_ConstraintParallel.h>
36 #include <SketchPlugin_ConstraintPerpendicular.h>
37 #include <SketchPlugin_ConstraintRadius.h>
38 #include <SketchPlugin_ConstraintRigid.h>
39 #include <SketchPlugin_Trim.h>
40 #include <SketchPlugin_Split.h>
41 #include <SketchPlugin_ConstraintTangent.h>
42 #include <SketchPlugin_ConstraintVertical.h>
43 #include <SketcherPrs_Tools.h>
44 //--------------------------------------------------------------------------------------
45 #include <ModelAPI_Events.h>
46 #include <ModelAPI_CompositeFeature.h>
47 #include <ModelAPI_ResultConstruction.h>
48 #include <ModelHighAPI_Double.h>
49 #include <ModelHighAPI_Dumper.h>
50 #include <ModelHighAPI_RefAttr.h>
51 #include <ModelHighAPI_Selection.h>
52 #include <ModelHighAPI_Services.h>
53 #include <ModelHighAPI_Tools.h>
54 //--------------------------------------------------------------------------------------
55 #include "SketchAPI_Arc.h"
56 #include "SketchAPI_BSpline.h"
57 #include "SketchAPI_Circle.h"
58 #include "SketchAPI_Ellipse.h"
59 #include "SketchAPI_EllipticArc.h"
60 #include "SketchAPI_IntersectionPoint.h"
61 #include "SketchAPI_Line.h"
62 #include "SketchAPI_MacroArc.h"
63 #include "SketchAPI_MacroCircle.h"
64 #include "SketchAPI_MacroEllipse.h"
65 #include "SketchAPI_MacroEllipticArc.h"
66 #include "SketchAPI_Mirror.h"
67 #include "SketchAPI_Point.h"
68 #include "SketchAPI_Projection.h"
69 #include "SketchAPI_Rectangle.h"
70 #include "SketchAPI_Rotation.h"
71 #include "SketchAPI_Translation.h"
72 //--------------------------------------------------------------------------------------
73 #include <GeomAPI_Curve.h>
74 #include <GeomAPI_Dir2d.h>
75 #include <GeomAPI_PlanarEdges.h>
76 #include <GeomAPI_ShapeExplorer.h>
77 #include <GeomAPI_XY.h>
78 #include <GeomAlgoAPI_SketchBuilder.h>
82 //--------------------------------------------------------------------------------------
83 SketchAPI_Sketch::SketchAPI_Sketch(
84 const std::shared_ptr<ModelAPI_Feature> & theFeature)
85 : ModelHighAPI_Interface(theFeature)
90 SketchAPI_Sketch::SketchAPI_Sketch(
91 const std::shared_ptr<ModelAPI_Feature> & theFeature,
92 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
93 : ModelHighAPI_Interface(theFeature)
100 SketchAPI_Sketch::SketchAPI_Sketch(
101 const std::shared_ptr<ModelAPI_Feature> & theFeature,
102 const ModelHighAPI_Selection & theExternal)
103 : ModelHighAPI_Interface(theFeature)
106 setExternal(theExternal);
110 SketchAPI_Sketch::SketchAPI_Sketch(
111 const std::shared_ptr<ModelAPI_Feature> & theFeature,
112 std::shared_ptr<ModelAPI_Object> thePlaneObject)
113 : ModelHighAPI_Interface(theFeature)
116 setExternal(thePlaneObject);
120 SketchAPI_Sketch::~SketchAPI_Sketch()
125 //--------------------------------------------------------------------------------------
126 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
128 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
131 //--------------------------------------------------------------------------------------
132 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
134 fillAttribute(thePlane->origin(), myorigin);
135 fillAttribute(thePlane->dirX(), mydirX);
136 fillAttribute(thePlane->normal(), mynormal);
141 void SketchAPI_Sketch::setPlane(const ModelHighAPI_Selection & thePlane,
142 bool theRemoveExternalDependency)
144 FeaturePtr aSketch = feature();
146 DocumentPtr aDoc = aSketch->document();
147 bool useVisible = false;
148 FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
149 aDoc->setCurrentFeature(aSketch, useVisible);
151 if (theRemoveExternalDependency)
152 aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
154 setExternal(thePlane);
156 aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
159 //--------------------------------------------------------------------------------------
160 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
162 fillAttribute(theExternal, myexternal);
167 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
169 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
170 ModelHighAPI_Selection aSel(aRes);
174 //--------------------------------------------------------------------------------------
175 void SketchAPI_Sketch::setValue(
176 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
177 const ModelHighAPI_Double & theValue)
179 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
181 // theConstraint->execute();
184 //--------------------------------------------------------------------------------------
185 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
187 const_cast<SketchAPI_Sketch*>(this)->execute();
189 std::list<ModelHighAPI_Selection> aSelectionList;
191 ResultConstructionPtr aResultConstruction =
192 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
193 if (aResultConstruction.get() == NULL)
194 return aSelectionList;
196 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
197 aSelectionList.push_back(
198 ModelHighAPI_Selection(aResultConstruction,
199 aResultConstruction->face(anIndex)));
202 return aSelectionList;
205 //--------------------------------------------------------------------------------------
206 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
207 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
209 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
210 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
213 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
214 const ModelHighAPI_Selection & theExternal)
216 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
217 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
220 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
221 const std::string & theExternalName)
223 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
225 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
228 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
229 std::shared_ptr<ModelAPI_Object> thePlaneObject)
231 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
232 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
236 //--------------------------------------------------------------------------------------
237 std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
239 std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
240 std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
241 for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
242 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
243 PointPtr aPoint(new SketchAPI_Point(aFeature));
244 aFreePoints.push_back(aPoint);
249 //--------------------------------------------------------------------------------------
250 static GeomCurvePtr untrimmedCurve(GeomShapePtr theShape)
252 GeomCurvePtr aCurve(new GeomAPI_Curve(theShape));
253 if (aCurve->isTrimmed())
254 aCurve = aCurve->basisCurve();
258 void SketchAPI_Sketch::changeFacesOrder(
259 const std::list<std::list<ModelHighAPI_Selection> >& theFaces)
261 // collect faces of the sketch
262 ResultConstructionPtr aSketchResult =
263 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
264 if (!aSketchResult) {
265 // sketch is nested to a boolean operation, thus, it has no result yet.
266 feature()->execute();
268 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->lastResult());
270 std::list<GeomFacePtr> aFaces;
271 int aFacesNum = aSketchResult->facesNum();
272 for (int i = 0; i < aFacesNum; ++i)
273 aFaces.push_back(aSketchResult->face(i));
274 // find new faces order according to the given lists of edges
275 std::list<GeomFacePtr> aNewFacesOrder;
276 std::list<std::list<ModelHighAPI_Selection> >::const_iterator anIt = theFaces.begin();
277 for (; anIt != theFaces.end(); ++anIt) {
278 // find the appropriate face
279 std::list<GeomFacePtr>::iterator aFIt = aFaces.begin();
280 for (; aFIt != aFaces.end(); ++aFIt) {
281 std::list<ModelHighAPI_Selection>::const_iterator aEdgeIt = anIt->begin();
282 GeomAPI_ShapeExplorer aFExp(*aFIt, GeomAPI_Shape::EDGE);
283 for (; aEdgeIt != anIt->end() && aFExp.more(); ++aEdgeIt, aFExp.next()) {
284 ResultPtr aCurRes = aEdgeIt->resultSubShapePair().first;
287 GeomCurvePtr aCurve1 = untrimmedCurve(aCurRes->shape());
288 GeomCurvePtr aCurve2 = untrimmedCurve(aFExp.current());
289 if (!aCurve1->isEqual(aCurve2))
293 if (aEdgeIt == anIt->end() && !aFExp.more()) {
295 aNewFacesOrder.push_back(*aFIt);
301 // place the rest faces at the end of new faces list
303 aNewFacesOrder.insert(aNewFacesOrder.end(), aFaces.begin(), aFaces.end());
304 // update the result of the sketch with the new order of faces
305 aSketchResult->setFacesOrder(aNewFacesOrder);
308 //--------------------------------------------------------------------------------------
309 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
310 double theX, double theY)
312 std::shared_ptr<ModelAPI_Feature> aFeature =
313 compositeFeature()->addFeature(SketchPlugin_Point::ID());
314 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
316 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
317 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
319 std::shared_ptr<ModelAPI_Feature> aFeature =
320 compositeFeature()->addFeature(SketchPlugin_Point::ID());
321 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
323 std::shared_ptr<SketchAPI_Point>
324 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
326 std::shared_ptr<ModelAPI_Feature> aFeature =
327 compositeFeature()->addFeature(SketchPlugin_Point::ID());
328 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
330 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
332 std::shared_ptr<ModelAPI_Feature> aFeature =
333 compositeFeature()->addFeature(SketchPlugin_Point::ID());
334 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
337 //--------------------------------------------------------------------------------------
338 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
339 const ModelHighAPI_Selection & theExternal,
342 std::shared_ptr<ModelAPI_Feature> aFeature =
343 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
344 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
345 anIntersection->setIncludeToResult(theKeepResult);
346 return anIntersection;
348 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
349 const std::string & theExternalName,
352 std::shared_ptr<ModelAPI_Feature> aFeature =
353 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
354 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
355 anIntersection->setIncludeToResult(theKeepResult);
356 return anIntersection;
359 //--------------------------------------------------------------------------------------
360 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
361 double theX2, double theY2)
363 std::shared_ptr<ModelAPI_Feature> aFeature =
364 compositeFeature()->addFeature(SketchPlugin_Line::ID());
365 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
367 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
368 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
369 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
371 std::shared_ptr<ModelAPI_Feature> aFeature =
372 compositeFeature()->addFeature(SketchPlugin_Line::ID());
373 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
375 std::shared_ptr<SketchAPI_Line>
376 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
378 std::shared_ptr<ModelAPI_Feature> aFeature =
379 compositeFeature()->addFeature(SketchPlugin_Line::ID());
380 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
382 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
384 std::shared_ptr<ModelAPI_Feature> aFeature =
385 compositeFeature()->addFeature(SketchPlugin_Line::ID());
386 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
389 //--------------------------------------------------------------------------------------
390 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
391 double theX2, double theY2)
393 std::shared_ptr<ModelAPI_Feature> aFeature =
394 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
395 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
397 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
398 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
399 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
401 std::shared_ptr<ModelAPI_Feature> aFeature =
402 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
403 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
406 //--------------------------------------------------------------------------------------
407 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
411 std::shared_ptr<ModelAPI_Feature> aFeature =
412 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
413 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
416 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
417 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
420 std::shared_ptr<ModelAPI_Feature> aFeature =
421 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
422 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
425 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
430 std::shared_ptr<ModelAPI_Feature> aFeature =
431 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
432 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
433 thePassedX, thePassedY));
436 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
437 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
438 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
440 std::shared_ptr<ModelAPI_Feature> aFeature =
441 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
442 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
445 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
446 double theX2, double theY2,
447 double theX3, double theY3)
449 std::shared_ptr<ModelAPI_Feature> aFeature =
450 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
451 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
456 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
457 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
458 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
459 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
461 std::shared_ptr<ModelAPI_Feature> aFeature =
462 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
463 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
466 std::shared_ptr<SketchAPI_Circle>
467 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
469 std::shared_ptr<ModelAPI_Feature> aFeature =
470 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
471 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
474 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
476 std::shared_ptr<ModelAPI_Feature> aFeature =
477 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
478 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
481 //--------------------------------------------------------------------------------------
482 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
483 double theStartX, double theStartY,
484 double theEndX, double theEndY,
487 std::shared_ptr<ModelAPI_Feature> aFeature =
488 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
489 return ArcPtr(new SketchAPI_Arc(aFeature,
490 theCenterX, theCenterY,
491 theStartX, theStartY,
496 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
497 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
498 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
499 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
502 std::shared_ptr<ModelAPI_Feature> aFeature =
503 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
504 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
507 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
508 double theEndX, double theEndY,
509 double thePassedX, double thePassedY)
511 std::shared_ptr<ModelAPI_Feature> aFeature =
512 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
513 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
514 theStartX, theStartY,
516 thePassedX, thePassedY));
519 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
520 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
521 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
522 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
524 std::shared_ptr<ModelAPI_Feature> aFeature =
525 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
526 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
529 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
530 const ModelHighAPI_RefAttr& theTangentPoint,
531 double theEndX, double theEndY,
535 std::shared_ptr<ModelAPI_Feature> aFeature =
536 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
537 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
539 aMacroArc->setByTransversal(theTangentPoint, theEndX, theEndY, theInversed);
541 aMacroArc->setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
545 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
546 const ModelHighAPI_RefAttr& theTangentPoint,
547 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
551 std::shared_ptr<ModelAPI_Feature> aFeature =
552 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
553 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
555 aMacroArc->setByTransversal(theTangentPoint, theEnd, theInversed);
557 aMacroArc->setByTangent(theTangentPoint, theEnd, theInversed);
561 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
563 std::shared_ptr<ModelAPI_Feature> aFeature =
564 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
565 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
568 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
570 std::shared_ptr<ModelAPI_Feature> aFeature =
571 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
572 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
575 //--------------------------------------------------------------------------------------
576 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
577 double theCenterX, double theCenterY,
578 double theFocusX, double theFocusY,
579 double theMinorRadius)
581 std::shared_ptr<ModelAPI_Feature> aFeature =
582 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
583 return EllipsePtr(new SketchAPI_Ellipse(aFeature,
584 theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius));
587 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
588 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
589 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
590 double theMinorRadius)
592 std::shared_ptr<ModelAPI_Feature> aFeature =
593 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
594 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius));
597 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
598 double thePoint1X, double thePoint1Y,
599 double thePoint2X, double thePoint2Y,
600 double thePassedX, double thePassedY,
603 std::shared_ptr<ModelAPI_Feature> aFeature =
604 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
605 return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature,
606 thePoint1X, thePoint1Y, thePoint2X, thePoint2Y, thePassedX, thePassedY, isPoint1Center));
609 std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
610 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint1,
611 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint2,
612 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePassedPoint,
615 std::shared_ptr<ModelAPI_Feature> aFeature =
616 compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
617 MacroEllipsePtr anEllipse;
618 if (thePoint1.second.isEmpty() &&
619 thePoint2.second.isEmpty() &&
620 thePassedPoint.second.isEmpty()) {
621 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
622 thePoint1.first, thePoint2.first, thePassedPoint.first, isPoint1Center));
625 anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
626 thePoint1.first, thePoint1.second,
627 thePoint2.first, thePoint2.second,
628 thePassedPoint.first, thePassedPoint.second,
634 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
635 const ModelHighAPI_Selection & theExternal)
637 std::shared_ptr<ModelAPI_Feature> aFeature =
638 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
639 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal));
642 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
643 const std::string & theExternalName)
645 std::shared_ptr<ModelAPI_Feature> aFeature =
646 compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
647 return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName));
650 //--------------------------------------------------------------------------------------
651 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
652 double theCenterX, double theCenterY,
653 double theFocusX, double theFocusY,
654 double theStartX, double theStartY,
655 double theEndX, double theEndY,
658 std::shared_ptr<ModelAPI_Feature> aFeature =
659 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
660 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature,
661 theCenterX, theCenterY,
662 theFocusX, theFocusY,
663 theStartX, theStartY,
668 std::shared_ptr<SketchAPI_MacroEllipticArc> SketchAPI_Sketch::addEllipticArc(
669 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theCenter,
670 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theMajorAxisPoint,
671 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theStartPoint,
672 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theEndPoint,
675 std::shared_ptr<ModelAPI_Feature> aFeature =
676 compositeFeature()->addFeature(SketchPlugin_MacroEllipticArc::ID());
677 return MacroEllipticArcPtr(new SketchAPI_MacroEllipticArc(aFeature,
678 theCenter.first, theCenter.second,
679 theMajorAxisPoint.first, theMajorAxisPoint.second,
680 theStartPoint.first, theStartPoint.second,
681 theEndPoint.first, theEndPoint.second,
685 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
686 const ModelHighAPI_Selection & theExternal)
688 std::shared_ptr<ModelAPI_Feature> aFeature =
689 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
690 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternal));
693 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
694 const std::string & theExternalName)
696 std::shared_ptr<ModelAPI_Feature> aFeature =
697 compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
698 return EllipticArcPtr(new SketchAPI_EllipticArc(aFeature, theExternalName));
701 //--------------------------------------------------------------------------------------
702 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(
703 const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
704 const std::list<ModelHighAPI_Double>& theWeights)
706 FeaturePtr aFeature = compositeFeature()->addFeature(SketchPlugin_BSpline::ID());
707 return BSplinePtr(new SketchAPI_BSpline(aFeature, thePoles, theWeights));
710 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(
712 const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
713 const std::list<ModelHighAPI_Double>& theWeights,
714 const std::list<ModelHighAPI_Double>& theKnots,
715 const std::list<ModelHighAPI_Integer>& theMults)
717 FeaturePtr aFeature = compositeFeature()->addFeature(SketchPlugin_BSpline::ID());
718 return BSplinePtr(new SketchAPI_BSpline(aFeature,
719 theDegree, thePoles, theWeights, theKnots, theMults));
722 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(
723 const ModelHighAPI_Selection & theExternal)
725 FeaturePtr aFeature = compositeFeature()->addFeature(SketchPlugin_BSpline::ID());
726 return BSplinePtr(new SketchAPI_BSpline(aFeature, theExternal));
729 std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addSpline(const std::string & theExternalName)
731 FeaturePtr aFeature = compositeFeature()->addFeature(SketchPlugin_BSpline::ID());
732 return BSplinePtr(new SketchAPI_BSpline(aFeature, theExternalName));
735 //--------------------------------------------------------------------------------------
736 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
737 const ModelHighAPI_Selection & theExternalFeature,
740 std::shared_ptr<ModelAPI_Feature> aFeature =
741 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
742 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
743 aProjection->setIncludeToResult(theKeepResult);
747 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
748 const std::string & theExternalName,
751 std::shared_ptr<ModelAPI_Feature> aFeature =
752 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
753 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
754 aProjection->setIncludeToResult(theKeepResult);
758 //--------------------------------------------------------------------------------------
759 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
760 const ModelHighAPI_RefAttr & theMirrorLine,
761 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
763 std::shared_ptr<ModelAPI_Feature> aFeature =
764 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
765 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
768 //--------------------------------------------------------------------------------------
769 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
770 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
771 const ModelHighAPI_RefAttr & thePoint1,
772 const ModelHighAPI_RefAttr & thePoint2,
773 const ModelHighAPI_Integer & theNumberOfObjects,
776 std::shared_ptr<ModelAPI_Feature> aFeature =
777 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
778 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
779 thePoint2, theNumberOfObjects, theFullValue));
782 //--------------------------------------------------------------------------------------
783 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
784 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
785 const ModelHighAPI_RefAttr & theCenter,
786 const ModelHighAPI_Double & theAngle,
787 const ModelHighAPI_Integer & theNumberOfObjects,
791 std::shared_ptr<ModelAPI_Feature> aFeature =
792 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
794 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
795 theAngle, theNumberOfObjects, theFullValue, theReversed));
798 //--------------------------------------------------------------------------------------
799 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
800 const ModelHighAPI_Reference& theFeature,
801 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
803 std::shared_ptr<ModelAPI_Feature> aFeature =
804 compositeFeature()->addFeature(SketchPlugin_Split::ID());
805 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
807 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
808 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
809 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
810 fillAttribute(thePositionPoint, aPointAttr);
813 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
816 //--------------------------------------------------------------------------------------
817 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
818 const ModelHighAPI_Reference& theFeature,
819 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
821 std::shared_ptr<ModelAPI_Feature> aFeature =
822 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
823 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
825 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
826 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
827 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
828 fillAttribute(thePositionPoint, aPointAttr);
831 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
834 //--------------------------------------------------------------------------------------
835 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
836 const ModelHighAPI_RefAttr & theLine1,
837 const ModelHighAPI_RefAttr & theLine2,
838 const ModelHighAPI_Double & theValue,
839 const std::string& theType)
841 std::shared_ptr<ModelAPI_Feature> aFeature =
842 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
844 const int aVersion = theType.empty() ? SketchPlugin_ConstraintAngle::THE_VERSION_0
845 : SketchPlugin_ConstraintAngle::THE_VERSION_1;
846 fillAttribute(aVersion, aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
848 int aType = (int)SketcherPrs_Tools::ANGLE_DIRECT;
849 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::PREV_TYPE_ID()));
850 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
852 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_0)
853 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
855 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
856 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
858 if (aVersion == SketchPlugin_ConstraintAngle::THE_VERSION_1) {
859 std::string aTypeLC = theType;
860 std::transform(aTypeLC.begin(), aTypeLC.end(), aTypeLC.begin(), ::tolower);
861 if (aTypeLC == "supplementary")
862 aType = (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
863 else if (aTypeLC == "backward")
864 aType = (int)SketcherPrs_Tools::ANGLE_BACKWARD;
866 fillAttribute(aType, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
867 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
871 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
874 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
875 const ModelHighAPI_RefAttr & theLine1,
876 const ModelHighAPI_RefAttr & theLine2,
877 const ModelHighAPI_Double & theValue)
879 std::shared_ptr<ModelAPI_Feature> aFeature =
880 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
881 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
882 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
883 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
884 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
885 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
886 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
887 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
889 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
892 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
893 const ModelHighAPI_RefAttr & theLine1,
894 const ModelHighAPI_RefAttr & theLine2,
895 const ModelHighAPI_Double & theValue)
897 std::shared_ptr<ModelAPI_Feature> aFeature =
898 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
899 fillAttribute(SketchPlugin_ConstraintAngle::THE_VERSION_0,
900 aFeature->integer(SketchPlugin_ConstraintAngle::VERSION_ID()));
901 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
902 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
903 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
904 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
905 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
907 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
910 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
911 const ModelHighAPI_RefAttr & thePoint1,
912 const ModelHighAPI_RefAttr & thePoint2)
914 std::shared_ptr<ModelAPI_Feature> aFeature =
915 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
916 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
917 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
919 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
922 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
923 const ModelHighAPI_RefAttr & theLine1,
924 const ModelHighAPI_RefAttr & theLine2)
926 std::shared_ptr<ModelAPI_Feature> aFeature =
927 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
928 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
929 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
931 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
934 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
935 const ModelHighAPI_RefAttr & thePoint,
936 const ModelHighAPI_RefAttr & thePointOrLine,
937 const ModelHighAPI_Double & theValue,
940 std::shared_ptr<ModelAPI_Feature> aFeature =
941 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
942 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
943 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
944 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
945 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
947 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
950 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
951 const ModelHighAPI_RefAttr & thePoint,
952 const ModelHighAPI_RefAttr & thePointOrLine,
953 const ModelHighAPI_Double & theValue)
955 return setDistance(thePoint, thePointOrLine, theValue, true);
958 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
959 const ModelHighAPI_RefAttr & thePoint,
960 const ModelHighAPI_RefAttr & thePointOrLine,
961 const ModelHighAPI_Double & theValue)
963 return setDistance(thePoint, thePointOrLine, theValue, false);
966 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
967 const ModelHighAPI_RefAttr & thePoint1,
968 const ModelHighAPI_RefAttr & thePoint2,
969 const ModelHighAPI_Double & theValue)
971 std::shared_ptr<ModelAPI_Feature> aFeature =
972 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
973 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
974 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
975 fillAttribute(theValue,
976 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
978 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
981 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
982 const ModelHighAPI_RefAttr & thePoint1,
983 const ModelHighAPI_RefAttr & thePoint2,
984 const ModelHighAPI_Double & theValue)
986 std::shared_ptr<ModelAPI_Feature> aFeature =
987 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
988 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
989 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
990 fillAttribute(theValue,
991 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
993 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
996 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
997 const ModelHighAPI_RefAttr & theObject1,
998 const ModelHighAPI_RefAttr & theObject2)
1000 std::shared_ptr<ModelAPI_Feature> aFeature =
1001 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
1002 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1003 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1004 aFeature->execute();
1005 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1008 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
1009 const ModelHighAPI_RefAttr & thePoint)
1011 std::shared_ptr<ModelAPI_Feature> aFeature =
1012 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
1013 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
1014 apply(); // finish operation to remove Fillet feature correcly
1015 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1018 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
1019 const ModelHighAPI_RefAttr & thePoint,
1020 const ModelHighAPI_Double & theRadius)
1022 CompositeFeaturePtr aSketch = compositeFeature();
1023 int aNbSubs = aSketch->numberOfSubs();
1026 InterfacePtr aFilletFeature = setFillet(thePoint);
1028 // set radius for just created arc
1029 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
1030 if (anArc->getKind() == SketchPlugin_Arc::ID())
1031 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
1033 return aFilletFeature;
1036 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
1037 const ModelHighAPI_RefAttr & theObject)
1039 std::shared_ptr<ModelAPI_Feature> aFeature =
1040 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
1041 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1042 aFeature->execute();
1043 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1046 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
1047 const ModelHighAPI_RefAttr & theLine)
1049 std::shared_ptr<ModelAPI_Feature> aFeature =
1050 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
1051 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1052 aFeature->execute();
1053 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1056 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
1057 const ModelHighAPI_RefAttr & theLine,
1058 const ModelHighAPI_Double & theValue)
1060 std::shared_ptr<ModelAPI_Feature> aFeature =
1061 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
1062 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1063 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1064 aFeature->execute();
1065 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1068 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
1069 const ModelHighAPI_RefAttr & thePoint,
1070 const ModelHighAPI_RefAttr & theLine)
1072 std::shared_ptr<ModelAPI_Feature> aFeature =
1073 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
1074 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1075 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1076 aFeature->execute();
1077 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1080 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
1081 const ModelHighAPI_RefAttr & theLine1,
1082 const ModelHighAPI_RefAttr & theLine2)
1084 std::shared_ptr<ModelAPI_Feature> aFeature =
1085 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
1086 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1087 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1088 aFeature->execute();
1089 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1092 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
1093 const ModelHighAPI_RefAttr & theLine1,
1094 const ModelHighAPI_RefAttr & theLine2)
1096 std::shared_ptr<ModelAPI_Feature> aFeature =
1097 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
1098 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1099 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1100 aFeature->execute();
1101 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1104 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
1105 const ModelHighAPI_RefAttr & theCircleOrArc,
1106 const ModelHighAPI_Double & theValue)
1108 std::shared_ptr<ModelAPI_Feature> aFeature =
1109 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
1110 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1111 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
1112 aFeature->execute();
1113 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1116 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
1117 const ModelHighAPI_RefAttr & theLine,
1118 const ModelHighAPI_RefAttr & theCircle)
1120 std::shared_ptr<ModelAPI_Feature> aFeature =
1121 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
1122 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1123 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
1124 aFeature->execute();
1125 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1128 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
1129 const ModelHighAPI_RefAttr & theLine)
1131 std::shared_ptr<ModelAPI_Feature> aFeature =
1132 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
1133 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
1134 aFeature->execute();
1135 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
1138 //--------------------------------------------------------------------------------------
1140 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
1142 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
1143 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1146 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
1148 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1149 theFeature->attribute(SketchPlugin_Line::START_ID()));
1150 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1151 theFeature->attribute(SketchPlugin_Line::END_ID()));
1153 if (!aStartAttr || !aEndAttr)
1154 return std::shared_ptr<GeomAPI_Pnt2d>();
1156 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
1157 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
1158 return std::shared_ptr<GeomAPI_Pnt2d>(
1159 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
1162 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
1164 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1165 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
1166 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
1168 if (!aCenter || !aRadius)
1169 return std::shared_ptr<GeomAPI_Pnt2d>();
1171 return std::shared_ptr<GeomAPI_Pnt2d>(
1172 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
1175 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
1177 static const double PI = 3.141592653589793238463;
1179 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1180 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1181 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1182 theFeature->attribute(SketchPlugin_Arc::START_ID()));
1183 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1184 theFeature->attribute(SketchPlugin_Arc::END_ID()));
1186 if (!aCenterAttr || !aStartAttr || !aEndAttr)
1187 return std::shared_ptr<GeomAPI_Pnt2d>();
1189 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
1190 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
1191 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
1192 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
1194 double anAngle = aStartDir->angle(aEndDir);
1195 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1196 if (isReversed && anAngle > 0.)
1197 anAngle -= 2.0 * PI;
1198 else if (!isReversed && anAngle <= 0.)
1199 anAngle += 2.0 * PI;
1201 double cosA = cos(anAngle);
1202 double sinA = sin(anAngle);
1204 // rotate start dir to find middle point on arc
1205 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
1206 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
1207 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
1209 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
1212 static std::shared_ptr<GeomAPI_Pnt2d> pointOnEllipse(const FeaturePtr& theFeature,
1213 bool isEllipse = true)
1215 const std::string& anAttrName = isEllipse ? SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() :
1216 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID();
1217 AttributePoint2DPtr aMajorAxisEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1218 theFeature->attribute(anAttrName));
1219 return aMajorAxisEnd ? aMajorAxisEnd->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
1222 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
1224 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
1225 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1227 // move only features of the following types
1228 const std::string& aFeatureKind = aFeature->getKind();
1229 if (aFeatureKind == SketchPlugin_Point::ID())
1230 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
1231 else if (aFeatureKind == SketchPlugin_Line::ID())
1232 aMiddlePoint = middlePointOnLine(aFeature);
1233 else if (aFeatureKind == SketchPlugin_Circle::ID())
1234 aMiddlePoint = pointOnCircle(aFeature);
1235 else if (aFeatureKind == SketchPlugin_Arc::ID())
1236 aMiddlePoint = middlePointOnArc(aFeature);
1237 else if (aFeatureKind == SketchPlugin_Ellipse::ID())
1238 aMiddlePoint = pointOnEllipse(aFeature);
1239 else if (aFeatureKind == SketchPlugin_EllipticArc::ID())
1240 aMiddlePoint = pointOnEllipse(aFeature, false);
1242 return aMiddlePoint;
1245 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1246 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
1248 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
1249 theMovedEntity.fillMessage(aMessage);
1251 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
1252 if (aMessage->movedAttribute())
1253 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
1255 anOriginalPosition = middlePoint(aMessage->movedObject());
1257 if (!anOriginalPosition)
1258 return; // something has gone wrong, do not process movement
1260 aMessage->setOriginalPosition(anOriginalPosition);
1261 aMessage->setCurrentPosition(theTargetPoint);
1262 Events_Loop::loop()->send(aMessage);
1265 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
1266 double theTargetX, double theTargetY)
1268 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1269 move(theMovedEntity, aTargetPoint);
1272 //--------------------------------------------------------------------------------------
1274 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1276 FeaturePtr aBase = feature();
1277 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1278 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1279 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1280 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1281 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1282 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1283 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1285 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1288 //--------------------------------------------------------------------------------------
1290 static bool isDifferent(GeomFacePtr theFace1, GeomFacePtr theFace2)
1292 // collect edges of the first face
1293 std::list<GeomShapePtr> anEdges1;
1294 for (GeomAPI_ShapeExplorer anExp(theFace1, GeomAPI_Shape::EDGE); anExp.more(); anExp.next())
1295 anEdges1.push_back(anExp.current());
1296 // compare edges of faces
1297 for (GeomAPI_ShapeExplorer anExp(theFace2, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
1298 GeomShapePtr aCurrent = anExp.current();
1299 bool isFound = false;
1300 std::list<GeomShapePtr>::iterator anIt1 = anEdges1.begin();
1301 for (; anIt1 != anEdges1.end(); ++anIt1)
1302 if (aCurrent->isSameGeometry(*anIt1)) {
1304 anEdges1.erase(anIt1);
1310 return !anEdges1.empty();
1313 static bool isCustomFacesOrder(CompositeFeaturePtr theSketch)
1315 ResultConstructionPtr aSketchResult =
1316 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1320 std::shared_ptr<GeomAPI_PlanarEdges> aWires =
1321 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aSketchResult->shape());
1325 // collect faces constructed by SketchBuilder algorithm
1326 GeomAlgoAPI_SketchBuilder aSketchBuilder(aWires->origin(), aWires->dirX(),
1327 aWires->norm(), aWires);
1328 const ListOfShape& aFaces = aSketchBuilder.faces();
1330 // compare faces stored in sketch with faces generated by SketchBuilder
1331 int aNbSketchFaces = aSketchResult->facesNum();
1333 for (ListOfShape::const_iterator aFIt = aFaces.begin();
1334 aFIt != aFaces.end() && aFaceIndex < aNbSketchFaces;
1335 ++aFIt, ++aFaceIndex) {
1336 GeomFacePtr aSketchFace = aSketchResult->face(aFaceIndex);
1337 GeomFacePtr aCurFace = (*aFIt)->face();
1338 if (isDifferent(aSketchFace, aCurFace))
1344 static void edgesOfSketchFaces(CompositeFeaturePtr theSketch,
1345 std::list<std::list<ResultPtr> >& theEdges)
1347 ResultConstructionPtr aSketchResult =
1348 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theSketch->lastResult());
1352 // collect curves of the sketch
1353 std::map<GeomCurvePtr, ResultPtr, GeomAPI_Curve::Comparator> aCurves;
1354 int aSubNum = theSketch->numberOfSubs();
1355 for (int a = 0; a < aSubNum; ++a) {
1356 FeaturePtr aSub = theSketch->subFeature(a);
1357 const std::list<ResultPtr>& aResults = aSub->results();
1358 std::list<ResultPtr>::const_iterator aRes = aResults.cbegin();
1359 for (; aRes != aResults.cend(); aRes++) {
1360 GeomShapePtr aCurShape = (*aRes)->shape();
1361 if (aCurShape && aCurShape->isEdge())
1362 aCurves[untrimmedCurve(aCurShape)] = *aRes;
1366 // convert each face to the list of results of its edges
1367 int aFacesNum = aSketchResult->facesNum();
1368 for (int a = 0; a < aFacesNum; ++a) {
1369 theEdges.push_back(std::list<ResultPtr>());
1370 std::list<ResultPtr>& aCurEdges = theEdges.back();
1372 GeomFacePtr aFace = aSketchResult->face(a);
1373 for (GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE);
1374 anExp.more(); anExp.next()) {
1375 GeomCurvePtr aCurrent = untrimmedCurve(anExp.current());
1376 aCurEdges.push_back(aCurves[aCurrent]);
1381 //--------------------------------------------------------------------------------------
1383 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1385 FeaturePtr aBase = feature();
1386 const std::string& aDocName = theDumper.name(aBase->document());
1388 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1389 if (anExternal->value()) {
1390 theDumper << aBase << " = model.addSketch(" << aDocName <<
1391 ", " << anExternal << ")" << std::endl;
1393 // Sketch is base on a plane.
1394 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1395 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1396 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1397 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1398 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1399 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1401 // Check the plane is coordinate plane
1402 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1403 if(anExternal->context()) { // checking for selected planes
1404 if (!aPlaneName.empty()
1405 && anExternal->context()->data()
1406 && anExternal->context()->data()->name() == aPlaneName) {
1407 // dump sketch based on coordinate plane
1408 theDumper << aBase << " = model.addSketch(" << aDocName
1409 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1410 } else { // some other plane
1411 theDumper << aBase << " = model.addSketch(" << aDocName <<
1412 ", " << anExternal<< ")" << std::endl;
1415 if (aPlaneName.empty()) {
1416 // needs import additional module
1417 theDumper.importModule("GeomAPI");
1418 // dump plane parameters
1419 const std::string& aSketchName = theDumper.name(aBase);
1420 std::string anOriginName = aSketchName + "_origin";
1421 std::string aNormalName = aSketchName + "_norm";
1422 std::string aDirXName = aSketchName + "_dirx";
1423 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1424 // and then dumplicate dumping it in the next line
1425 theDumper << anOriginName << " = " << anOrigin << "\n"
1426 << aNormalName << " = " << aNormal << "\n"
1427 << aDirXName << " = " << aDirX << "\n";
1428 // dump sketch based on arbitrary plane
1429 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1430 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1432 // dump sketch based on coordinate plane
1433 theDumper << aBase << " = model.addSketch(" << aDocName
1434 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1439 // dump sketch's subfeatures
1440 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1441 theDumper.processSubs(aCompFeat, true);
1443 // if face order differs to the order generated by SketchBuilder,
1444 // dump the list of faces for correct execution of the script
1445 if (isCustomFacesOrder(aCompFeat)) {
1446 std::list<std::list<ResultPtr> > aFaces;
1447 edgesOfSketchFaces(aCompFeat, aFaces);
1449 const std::string& aSketchName = theDumper.name(aBase);
1450 std::string aMethodName(".changeFacesOrder");
1451 std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');
1453 theDumper << aSketchName << aMethodName << "([";
1454 for (std::list<std::list<ResultPtr> >::iterator aFIt = aFaces.begin();
1455 aFIt != aFaces.end(); ++aFIt) {
1456 if (aFIt != aFaces.begin())
1457 theDumper << ",\n" << aSpaceShift << " ";
1460 theDumper << "\n" << aSpaceShift << " ])" << std::endl;
1461 // call model.do() for correct update of the document's labels related to the changed faces
1462 theDumper << "model.do()" << std::endl;