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_ConstraintTangent.h>
26 #include <SketchPlugin_ConstraintVertical.h>
27 //--------------------------------------------------------------------------------------
28 #include <ModelAPI_CompositeFeature.h>
29 #include <ModelAPI_ResultConstruction.h>
30 #include <ModelHighAPI_Dumper.h>
31 #include <ModelHighAPI_RefAttr.h>
32 #include <ModelHighAPI_Selection.h>
33 #include <ModelHighAPI_Services.h>
34 #include <ModelHighAPI_Tools.h>
35 //--------------------------------------------------------------------------------------
36 #include "SketchAPI_Arc.h"
37 #include "SketchAPI_Circle.h"
38 #include "SketchAPI_IntersectionPoint.h"
39 #include "SketchAPI_Line.h"
40 #include "SketchAPI_Mirror.h"
41 #include "SketchAPI_Point.h"
42 #include "SketchAPI_Projection.h"
43 #include "SketchAPI_Rectangle.h"
44 #include "SketchAPI_Rotation.h"
45 #include "SketchAPI_Translation.h"
46 //--------------------------------------------------------------------------------------
47 SketchAPI_Sketch::SketchAPI_Sketch(
48 const std::shared_ptr<ModelAPI_Feature> & theFeature)
49 : ModelHighAPI_Interface(theFeature)
54 SketchAPI_Sketch::SketchAPI_Sketch(
55 const std::shared_ptr<ModelAPI_Feature> & theFeature,
56 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
57 : ModelHighAPI_Interface(theFeature)
64 SketchAPI_Sketch::SketchAPI_Sketch(
65 const std::shared_ptr<ModelAPI_Feature> & theFeature,
66 const ModelHighAPI_Selection & theExternal)
67 : ModelHighAPI_Interface(theFeature)
70 setExternal(theExternal);
74 SketchAPI_Sketch::~SketchAPI_Sketch()
79 //--------------------------------------------------------------------------------------
80 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
82 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
85 //--------------------------------------------------------------------------------------
86 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
88 fillAttribute(thePlane->origin(), myorigin);
89 fillAttribute(thePlane->dirX(), mydirX);
90 fillAttribute(thePlane->normal(), mynormal);
95 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
97 fillAttribute(theExternal, myexternal);
102 //--------------------------------------------------------------------------------------
103 void SketchAPI_Sketch::setValue(
104 const std::shared_ptr<ModelAPI_Feature> & theConstraint,
105 const ModelHighAPI_Double & theValue)
107 // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
108 fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
110 // theConstraint->execute();
113 //--------------------------------------------------------------------------------------
114 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
116 const_cast<SketchAPI_Sketch*>(this)->execute();
118 std::list<ModelHighAPI_Selection> aSelectionList;
120 ResultConstructionPtr aResultConstruction =
121 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
122 if (aResultConstruction.get() == NULL)
123 return aSelectionList;
125 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
126 aSelectionList.push_back(
127 ModelHighAPI_Selection(aResultConstruction,
128 aResultConstruction->face(anIndex)));
131 return aSelectionList;
134 //--------------------------------------------------------------------------------------
135 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
136 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
138 // TODO(spo): check that thePart is not empty
139 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
140 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
143 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
144 const ModelHighAPI_Selection & theExternal)
146 // TODO(spo): check that thePart is not empty
147 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
148 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
151 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
152 const std::string & theExternalName)
154 // TODO(spo): check that thePart is not empty
155 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
156 return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
159 //--------------------------------------------------------------------------------------
160 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
161 double theX, double theY)
163 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
164 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
166 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
167 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
169 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
170 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
172 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
174 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
175 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
177 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
179 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
180 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
183 //--------------------------------------------------------------------------------------
184 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
185 const ModelHighAPI_Selection & theExternal)
187 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
188 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
190 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
191 const std::string & theExternalName)
193 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
194 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
197 //--------------------------------------------------------------------------------------
198 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
200 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
201 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
203 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
204 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
205 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
207 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
208 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
210 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
212 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
213 LinePtr aLine(new SketchAPI_Line(aFeature, theExternal));
214 setFixed(InterfacePtr(aLine));
217 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
219 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
220 LinePtr aLine(new SketchAPI_Line(aFeature, theExternalName));
221 setFixed(InterfacePtr(aLine));
225 //--------------------------------------------------------------------------------------
226 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
228 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
229 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
231 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
232 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
233 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
235 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
236 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
239 //--------------------------------------------------------------------------------------
240 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
244 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
245 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
248 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
251 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
252 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
255 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
256 double theX2, double theY2,
257 double theX3, double theY3)
259 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
260 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
263 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
264 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
265 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
267 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
268 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
271 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
273 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
274 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
277 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
279 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
280 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
281 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
284 //--------------------------------------------------------------------------------------
285 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
286 double theStartX, double theStartY,
287 double theEndX, double theEndY,
290 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
291 return ArcPtr(new SketchAPI_Arc(aFeature,
292 theCenterX, theCenterY,
293 theStartX, theStartY,
298 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
299 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
300 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
303 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
304 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
307 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
308 double theEndX, double theEndY,
309 double thePassedX, double thePassedY)
311 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
312 return ArcPtr(new SketchAPI_Arc(aFeature,
313 theStartX, theStartY,
315 thePassedX, thePassedY));
318 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
319 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
320 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
322 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
323 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
326 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
327 double theEndX, double theEndY,
330 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
331 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
334 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
335 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
338 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
339 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
342 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
344 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
345 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
348 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
350 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
351 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
352 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
355 //--------------------------------------------------------------------------------------
356 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
357 const ModelHighAPI_Selection & theExternalFeature)
359 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
360 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
363 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
364 const std::string & theExternalName)
366 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
367 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
370 //--------------------------------------------------------------------------------------
371 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
372 const ModelHighAPI_RefAttr & theMirrorLine,
373 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
375 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
376 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
379 //--------------------------------------------------------------------------------------
380 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
381 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
382 const ModelHighAPI_RefAttr & thePoint1,
383 const ModelHighAPI_RefAttr & thePoint2,
384 const ModelHighAPI_Integer & theNumberOfObjects,
387 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
388 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1, thePoint2, theNumberOfObjects, theFullValue));
391 //--------------------------------------------------------------------------------------
392 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
393 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
394 const ModelHighAPI_RefAttr & theCenter,
395 const ModelHighAPI_Double & theAngle,
396 const ModelHighAPI_Integer & theNumberOfObjects,
399 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
400 return RotationPtr(new SketchAPI_Rotation(aFeature, theObjects, theCenter, theAngle, theNumberOfObjects, theFullValue));
403 //--------------------------------------------------------------------------------------
404 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
405 const ModelHighAPI_RefAttr & theLine1,
406 const ModelHighAPI_RefAttr & theLine2,
407 const ModelHighAPI_Double & theValue)
409 // TODO(spo): is support of angle type necessary?
410 std::shared_ptr<ModelAPI_Feature> aFeature =
411 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
412 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
413 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
414 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
419 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
420 const ModelHighAPI_RefAttr & thePoint1,
421 const ModelHighAPI_RefAttr & thePoint2)
423 std::shared_ptr<ModelAPI_Feature> aFeature =
424 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
425 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
426 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
431 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCollinear(
432 const ModelHighAPI_RefAttr & theLine1,
433 const ModelHighAPI_RefAttr & theLine2)
435 std::shared_ptr<ModelAPI_Feature> aFeature =
436 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
437 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
438 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
443 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
444 const ModelHighAPI_RefAttr & thePoint,
445 const ModelHighAPI_RefAttr & thePointOrLine,
446 const ModelHighAPI_Double & theValue)
448 std::shared_ptr<ModelAPI_Feature> aFeature =
449 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
450 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
451 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
452 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
457 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setEqual(
458 const ModelHighAPI_RefAttr & theObject1,
459 const ModelHighAPI_RefAttr & theObject2)
461 std::shared_ptr<ModelAPI_Feature> aFeature =
462 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
463 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
464 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
469 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFillet(
470 const std::list<ModelHighAPI_RefAttr> & thePoints,
471 const ModelHighAPI_Double & theRadius)
473 std::shared_ptr<ModelAPI_Feature> aFeature =
474 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
475 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
476 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
481 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFixed(
482 const ModelHighAPI_RefAttr & theObject)
484 std::shared_ptr<ModelAPI_Feature> aFeature =
485 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
486 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
491 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setHorizontal(
492 const ModelHighAPI_RefAttr & theLine)
494 std::shared_ptr<ModelAPI_Feature> aFeature =
495 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
496 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
501 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
502 const ModelHighAPI_RefAttr & theLine,
503 const ModelHighAPI_Double & theValue)
505 std::shared_ptr<ModelAPI_Feature> aFeature =
506 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
507 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
508 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
513 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setMiddlePoint(
514 const ModelHighAPI_RefAttr & thePoint,
515 const ModelHighAPI_RefAttr & theLine)
517 std::shared_ptr<ModelAPI_Feature> aFeature =
518 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
519 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
520 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
525 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
526 const ModelHighAPI_RefAttr & theLine1,
527 const ModelHighAPI_RefAttr & theLine2)
529 std::shared_ptr<ModelAPI_Feature> aFeature =
530 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
531 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
532 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
537 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
538 const ModelHighAPI_RefAttr & theLine1,
539 const ModelHighAPI_RefAttr & theLine2)
541 std::shared_ptr<ModelAPI_Feature> aFeature =
542 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
543 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
544 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
549 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRadius(
550 const ModelHighAPI_RefAttr & theCircleOrArc,
551 const ModelHighAPI_Double & theValue)
553 std::shared_ptr<ModelAPI_Feature> aFeature =
554 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
555 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
556 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
561 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setTangent(
562 const ModelHighAPI_RefAttr & theLine,
563 const ModelHighAPI_RefAttr & theCircle)
565 std::shared_ptr<ModelAPI_Feature> aFeature =
566 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
567 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
568 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
573 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setVertical(
574 const ModelHighAPI_RefAttr & theLine)
576 std::shared_ptr<ModelAPI_Feature> aFeature =
577 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
578 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
583 //--------------------------------------------------------------------------------------
585 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
587 FeaturePtr aBase = feature();
588 const std::string& aDocName = theDumper.name(aBase->document());
590 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
591 if (anExternal->value()) {
592 FeaturePtr aPlnFeature = ModelAPI_Feature::feature(anExternal->context()->data()->owner());
593 const std::string& aPlaneName = theDumper.name(aPlnFeature);
594 theDumper << aBase << " = model.addSketch(" << aDocName << ", \"" << aPlaneName << "\")" << std::endl;
596 // Sketch is base on a plane.
597 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
598 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
599 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
600 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
601 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
602 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
604 // Check the plane is coordinate plane
605 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
606 if (aPlaneName.empty()) {
607 // needs import additional module
608 theDumper.importModule("GeomAPI");
609 // dump plane parameters
610 const std::string& aSketchName = theDumper.name(aBase);
611 std::string anOriginName = aSketchName + "_origin";
612 std::string aNormalName = aSketchName + "_norm";
613 std::string aDirXName = aSketchName + "_dirx";
614 theDumper << anOriginName << " = " << anOrigin << std::endl
615 << aNormalName << " = " << aNormal << std::endl
616 << aDirXName << " = " << aDirX << std::endl;
617 // dump sketch based on arbitrary plane
618 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
619 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
621 // dump sketch based on coordinate plane
622 theDumper << aBase << " = model.addSketch(" << aDocName
623 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;