1 // Name : SketchAPI_Sketch.cpp
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Sketch.h"
9 //--------------------------------------------------------------------------------------
10 #include <SketchPlugin_Constraint.h>
11 #include <SketchPlugin_ConstraintAngle.h>
12 #include <SketchPlugin_ConstraintCoincidence.h>
13 #include <SketchPlugin_ConstraintCollinear.h>
14 #include <SketchPlugin_ConstraintDistance.h>
15 #include <SketchPlugin_ConstraintEqual.h>
16 #include <SketchPlugin_ConstraintFillet.h>
17 #include <SketchPlugin_ConstraintHorizontal.h>
18 #include <SketchPlugin_ConstraintLength.h>
19 #include <SketchPlugin_ConstraintMiddle.h>
20 #include <SketchPlugin_ConstraintMirror.h>
21 #include <SketchPlugin_ConstraintParallel.h>
22 #include <SketchPlugin_ConstraintPerpendicular.h>
23 #include <SketchPlugin_ConstraintRadius.h>
24 #include <SketchPlugin_ConstraintRigid.h>
25 #include <SketchPlugin_ConstraintSplit.h>
26 #include <SketchPlugin_ConstraintTangent.h>
27 #include <SketchPlugin_ConstraintVertical.h>
28 #include <SketcherPrs_Tools.h>
29 //--------------------------------------------------------------------------------------
30 #include <ModelAPI_CompositeFeature.h>
31 #include <ModelAPI_ResultConstruction.h>
32 #include <ModelHighAPI_Dumper.h>
33 #include <ModelHighAPI_RefAttr.h>
34 #include <ModelHighAPI_Selection.h>
35 #include <ModelHighAPI_Services.h>
36 #include <ModelHighAPI_Tools.h>
37 //--------------------------------------------------------------------------------------
38 #include "SketchAPI_Arc.h"
39 #include "SketchAPI_Circle.h"
40 #include "SketchAPI_IntersectionPoint.h"
41 #include "SketchAPI_Line.h"
42 #include "SketchAPI_Mirror.h"
43 #include "SketchAPI_Point.h"
44 #include "SketchAPI_Projection.h"
45 #include "SketchAPI_Rectangle.h"
46 #include "SketchAPI_Rotation.h"
47 #include "SketchAPI_Translation.h"
48 //--------------------------------------------------------------------------------------
49 SketchAPI_Sketch::SketchAPI_Sketch(
50 const std::shared_ptr<ModelAPI_Feature> & theFeature)
51 : ModelHighAPI_Interface(theFeature)
56 SketchAPI_Sketch::SketchAPI_Sketch(
57 const std::shared_ptr<ModelAPI_Feature> & theFeature,
58 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
59 : ModelHighAPI_Interface(theFeature)
66 SketchAPI_Sketch::SketchAPI_Sketch(
67 const std::shared_ptr<ModelAPI_Feature> & theFeature,
68 const ModelHighAPI_Selection & theExternal)
69 : ModelHighAPI_Interface(theFeature)
72 setExternal(theExternal);
76 SketchAPI_Sketch::SketchAPI_Sketch(
77 const std::shared_ptr<ModelAPI_Feature> & theFeature,
78 std::shared_ptr<ModelAPI_Object> thePlaneObject)
79 : ModelHighAPI_Interface(theFeature)
82 setExternal(thePlaneObject);
86 SketchAPI_Sketch::~SketchAPI_Sketch()
91 //--------------------------------------------------------------------------------------
92 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
94 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
97 //--------------------------------------------------------------------------------------
98 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
100 fillAttribute(thePlane->origin(), myorigin);
101 fillAttribute(thePlane->dirX(), mydirX);
102 fillAttribute(thePlane->normal(), mynormal);
107 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
109 fillAttribute(theExternal, myexternal);
114 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
116 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
117 ModelHighAPI_Selection aSel(aRes);
121 //--------------------------------------------------------------------------------------
122 void SketchAPI_Sketch::setValue(
123 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
124 const ModelHighAPI_Double & theValue)
126 // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
127 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
129 // theConstraint->execute();
132 //--------------------------------------------------------------------------------------
133 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
135 const_cast<SketchAPI_Sketch*>(this)->execute();
137 std::list<ModelHighAPI_Selection> aSelectionList;
139 ResultConstructionPtr aResultConstruction =
140 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
141 if (aResultConstruction.get() == NULL)
142 return aSelectionList;
144 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
145 aSelectionList.push_back(
146 ModelHighAPI_Selection(aResultConstruction,
147 aResultConstruction->face(anIndex)));
150 return aSelectionList;
153 //--------------------------------------------------------------------------------------
154 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
155 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
157 // TODO(spo): check that thePart is not empty
158 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
159 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
162 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
163 const ModelHighAPI_Selection & theExternal)
165 // TODO(spo): check that thePart is not empty
166 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
167 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
170 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
171 const std::string & theExternalName)
173 // TODO(spo): check that thePart is not empty
174 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
175 return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
178 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
179 std::shared_ptr<ModelAPI_Object> thePlaneObject)
181 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
182 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
186 //--------------------------------------------------------------------------------------
187 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
188 double theX, double theY)
190 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
191 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
193 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
194 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
196 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
197 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
199 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
201 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
202 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
204 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
206 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
207 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
210 //--------------------------------------------------------------------------------------
211 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
212 const ModelHighAPI_Selection & theExternal)
214 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
215 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
217 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
218 const std::string & theExternalName)
220 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
221 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
224 //--------------------------------------------------------------------------------------
225 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
227 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
228 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
230 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
231 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
232 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
234 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
235 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
237 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
239 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
240 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
242 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
244 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
245 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
248 //--------------------------------------------------------------------------------------
249 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
251 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
252 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
254 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
255 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
256 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
258 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
259 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
262 //--------------------------------------------------------------------------------------
263 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
267 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
268 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
271 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
274 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
275 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
278 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
279 double theX2, double theY2,
280 double theX3, double theY3)
282 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
283 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
286 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
287 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
288 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
290 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
291 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
294 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
296 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
297 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
300 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
302 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
303 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
304 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
307 //--------------------------------------------------------------------------------------
308 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
309 double theStartX, double theStartY,
310 double theEndX, double theEndY,
313 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
314 return ArcPtr(new SketchAPI_Arc(aFeature,
315 theCenterX, theCenterY,
316 theStartX, theStartY,
321 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
322 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
323 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
326 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
327 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
330 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
331 double theEndX, double theEndY,
332 double thePassedX, double thePassedY)
334 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
335 return ArcPtr(new SketchAPI_Arc(aFeature,
336 theStartX, theStartY,
338 thePassedX, thePassedY));
341 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
342 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
343 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
345 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
346 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
349 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
350 double theEndX, double theEndY,
353 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
354 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
357 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
358 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
361 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
362 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
365 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
367 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
368 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
371 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
373 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
374 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
375 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
378 //--------------------------------------------------------------------------------------
379 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
380 const ModelHighAPI_Selection & theExternalFeature)
382 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
383 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
386 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
387 const std::string & theExternalName)
389 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
390 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
393 //--------------------------------------------------------------------------------------
394 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
395 const ModelHighAPI_RefAttr & theMirrorLine,
396 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
398 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
399 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
402 //--------------------------------------------------------------------------------------
403 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
404 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
405 const ModelHighAPI_RefAttr & thePoint1,
406 const ModelHighAPI_RefAttr & thePoint2,
407 const ModelHighAPI_Integer & theNumberOfObjects,
410 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
411 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1, thePoint2, theNumberOfObjects, theFullValue));
414 //--------------------------------------------------------------------------------------
415 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
416 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
417 const ModelHighAPI_RefAttr & theCenter,
418 const ModelHighAPI_Double & theAngle,
419 const ModelHighAPI_Integer & theNumberOfObjects,
422 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
423 return RotationPtr(new SketchAPI_Rotation(aFeature, theObjects, theCenter, theAngle, theNumberOfObjects, theFullValue));
426 //--------------------------------------------------------------------------------------
427 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(const ModelHighAPI_Reference& theFeature,
428 const ModelHighAPI_RefAttr& thePoint1,
429 const ModelHighAPI_RefAttr& thePoint2)
431 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintSplit::ID());
432 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Constraint::VALUE()));
433 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
434 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
435 //aFeature->execute();
436 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
439 //--------------------------------------------------------------------------------------
440 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
441 const ModelHighAPI_RefAttr & theLine1,
442 const ModelHighAPI_RefAttr & theLine2,
443 const ModelHighAPI_Double & theValue)
445 std::shared_ptr<ModelAPI_Feature> aFeature =
446 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
447 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
448 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
449 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
450 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
451 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
453 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
456 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
457 const ModelHighAPI_RefAttr & theLine1,
458 const ModelHighAPI_RefAttr & theLine2,
459 const ModelHighAPI_Double & theValue)
461 std::shared_ptr<ModelAPI_Feature> aFeature =
462 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
463 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
464 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
465 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
466 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
467 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
468 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
470 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
473 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
474 const ModelHighAPI_RefAttr & theLine1,
475 const ModelHighAPI_RefAttr & theLine2,
476 const ModelHighAPI_Double & theValue)
478 std::shared_ptr<ModelAPI_Feature> aFeature =
479 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
480 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
481 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
482 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
483 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
484 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
485 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
487 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
490 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
491 const ModelHighAPI_RefAttr & thePoint1,
492 const ModelHighAPI_RefAttr & thePoint2)
494 std::shared_ptr<ModelAPI_Feature> aFeature =
495 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
496 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
497 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
499 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
502 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
503 const ModelHighAPI_RefAttr & theLine1,
504 const ModelHighAPI_RefAttr & theLine2)
506 std::shared_ptr<ModelAPI_Feature> aFeature =
507 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
508 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
509 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
511 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
514 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
515 const ModelHighAPI_RefAttr & thePoint,
516 const ModelHighAPI_RefAttr & thePointOrLine,
517 const ModelHighAPI_Double & theValue)
519 std::shared_ptr<ModelAPI_Feature> aFeature =
520 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
521 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
522 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
523 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
525 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
528 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
529 const ModelHighAPI_RefAttr & theObject1,
530 const ModelHighAPI_RefAttr & theObject2)
532 std::shared_ptr<ModelAPI_Feature> aFeature =
533 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
534 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
535 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
537 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
540 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
541 const std::list<ModelHighAPI_RefAttr> & thePoints,
542 const ModelHighAPI_Double & theRadius)
544 std::shared_ptr<ModelAPI_Feature> aFeature =
545 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
546 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
547 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
549 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
552 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
553 const ModelHighAPI_RefAttr & theObject)
555 std::shared_ptr<ModelAPI_Feature> aFeature =
556 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
557 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
559 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
562 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
563 const ModelHighAPI_RefAttr & theLine)
565 std::shared_ptr<ModelAPI_Feature> aFeature =
566 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
567 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
569 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
572 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
573 const ModelHighAPI_RefAttr & theLine,
574 const ModelHighAPI_Double & theValue)
576 std::shared_ptr<ModelAPI_Feature> aFeature =
577 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
578 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
579 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
581 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
584 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
585 const ModelHighAPI_RefAttr & thePoint,
586 const ModelHighAPI_RefAttr & theLine)
588 std::shared_ptr<ModelAPI_Feature> aFeature =
589 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
590 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
591 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
593 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
596 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
597 const ModelHighAPI_RefAttr & theLine1,
598 const ModelHighAPI_RefAttr & theLine2)
600 std::shared_ptr<ModelAPI_Feature> aFeature =
601 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
602 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
603 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
605 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
608 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
609 const ModelHighAPI_RefAttr & theLine1,
610 const ModelHighAPI_RefAttr & theLine2)
612 std::shared_ptr<ModelAPI_Feature> aFeature =
613 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
614 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
615 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
617 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
620 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
621 const ModelHighAPI_RefAttr & theCircleOrArc,
622 const ModelHighAPI_Double & theValue)
624 std::shared_ptr<ModelAPI_Feature> aFeature =
625 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
626 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
627 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
629 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
632 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
633 const ModelHighAPI_RefAttr & theLine,
634 const ModelHighAPI_RefAttr & theCircle)
636 std::shared_ptr<ModelAPI_Feature> aFeature =
637 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
638 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
639 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
641 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
644 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
645 const ModelHighAPI_RefAttr & theLine)
647 std::shared_ptr<ModelAPI_Feature> aFeature =
648 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
649 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
651 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
654 //--------------------------------------------------------------------------------------
656 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
658 FeaturePtr aBase = feature();
659 const std::string& aDocName = theDumper.name(aBase->document());
661 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
662 if (anExternal->value()) {
663 theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal << ")" << std::endl;
665 // Sketch is base on a plane.
666 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
667 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
668 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
669 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
670 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
671 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
673 // Check the plane is coordinate plane
674 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
675 if (anExternal->context()) { // checking for selected planes
676 if (!aPlaneName.empty()) {
677 // dump sketch based on coordinate plane
678 theDumper << aBase << " = model.addSketch(" << aDocName
679 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
680 } else { // some other plane
681 theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal<< ")" << std::endl;
684 if (aPlaneName.empty()) {
685 // needs import additional module
686 theDumper.importModule("GeomAPI");
687 // dump plane parameters
688 const std::string& aSketchName = theDumper.name(aBase);
689 std::string anOriginName = aSketchName + "_origin";
690 std::string aNormalName = aSketchName + "_norm";
691 std::string aDirXName = aSketchName + "_dirx";
692 // use "\n" instead of std::endl to avoid automatic dumping sketch here
693 // and then dumplicate dumping it in the next line
694 theDumper << anOriginName << " = " << anOrigin << "\n"
695 << aNormalName << " = " << aNormal << "\n"
696 << aDirXName << " = " << aDirX << "\n";
697 // dump sketch based on arbitrary plane
698 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
699 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
701 // dump sketch based on coordinate plane
702 theDumper << aBase << " = model.addSketch(" << aDocName
703 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
708 // dump sketch's subfeatures
709 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
710 theDumper.processSubs(aCompFeat, true);