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 #include <SketcherPrs_Tools.h>
28 //--------------------------------------------------------------------------------------
29 #include <ModelAPI_CompositeFeature.h>
30 #include <ModelAPI_ResultConstruction.h>
31 #include <ModelHighAPI_Dumper.h>
32 #include <ModelHighAPI_RefAttr.h>
33 #include <ModelHighAPI_Selection.h>
34 #include <ModelHighAPI_Services.h>
35 #include <ModelHighAPI_Tools.h>
36 //--------------------------------------------------------------------------------------
37 #include "SketchAPI_Arc.h"
38 #include "SketchAPI_Circle.h"
39 #include "SketchAPI_IntersectionPoint.h"
40 #include "SketchAPI_Line.h"
41 #include "SketchAPI_Mirror.h"
42 #include "SketchAPI_Point.h"
43 #include "SketchAPI_Projection.h"
44 #include "SketchAPI_Rectangle.h"
45 #include "SketchAPI_Rotation.h"
46 #include "SketchAPI_Translation.h"
47 //--------------------------------------------------------------------------------------
48 SketchAPI_Sketch::SketchAPI_Sketch(
49 const std::shared_ptr<ModelAPI_Feature> & theFeature)
50 : ModelHighAPI_Interface(theFeature)
55 SketchAPI_Sketch::SketchAPI_Sketch(
56 const std::shared_ptr<ModelAPI_Feature> & theFeature,
57 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
58 : ModelHighAPI_Interface(theFeature)
65 SketchAPI_Sketch::SketchAPI_Sketch(
66 const std::shared_ptr<ModelAPI_Feature> & theFeature,
67 const ModelHighAPI_Selection & theExternal)
68 : ModelHighAPI_Interface(theFeature)
71 setExternal(theExternal);
75 SketchAPI_Sketch::SketchAPI_Sketch(
76 const std::shared_ptr<ModelAPI_Feature> & theFeature,
77 std::shared_ptr<ModelAPI_Object> thePlaneObject)
78 : ModelHighAPI_Interface(theFeature)
81 setExternal(thePlaneObject);
85 SketchAPI_Sketch::~SketchAPI_Sketch()
90 //--------------------------------------------------------------------------------------
91 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
93 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
96 //--------------------------------------------------------------------------------------
97 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
99 fillAttribute(thePlane->origin(), myorigin);
100 fillAttribute(thePlane->dirX(), mydirX);
101 fillAttribute(thePlane->normal(), mynormal);
106 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
108 fillAttribute(theExternal, myexternal);
113 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
115 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
116 ModelHighAPI_Selection aSel(aRes);
120 //--------------------------------------------------------------------------------------
121 void SketchAPI_Sketch::setValue(
122 const std::shared_ptr<ModelAPI_Feature> & theConstraint,
123 const ModelHighAPI_Double & theValue)
125 // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
126 fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
128 // theConstraint->execute();
131 //--------------------------------------------------------------------------------------
132 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
134 const_cast<SketchAPI_Sketch*>(this)->execute();
136 std::list<ModelHighAPI_Selection> aSelectionList;
138 ResultConstructionPtr aResultConstruction =
139 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
140 if (aResultConstruction.get() == NULL)
141 return aSelectionList;
143 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
144 aSelectionList.push_back(
145 ModelHighAPI_Selection(aResultConstruction,
146 aResultConstruction->face(anIndex)));
149 return aSelectionList;
152 //--------------------------------------------------------------------------------------
153 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
154 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
156 // TODO(spo): check that thePart is not empty
157 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
158 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
161 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
162 const ModelHighAPI_Selection & theExternal)
164 // TODO(spo): check that thePart is not empty
165 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
166 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
169 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
170 const std::string & theExternalName)
172 // TODO(spo): check that thePart is not empty
173 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
174 return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
177 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
178 std::shared_ptr<ModelAPI_Object> thePlaneObject)
180 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
181 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
185 //--------------------------------------------------------------------------------------
186 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
187 double theX, double theY)
189 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
190 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
192 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
193 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
195 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
196 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
198 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
200 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
201 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
203 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
205 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
206 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
209 //--------------------------------------------------------------------------------------
210 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
211 const ModelHighAPI_Selection & theExternal)
213 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
214 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
216 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
217 const std::string & theExternalName)
219 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
220 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
223 //--------------------------------------------------------------------------------------
224 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
226 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
227 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
229 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
230 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
231 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
233 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
234 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
236 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
238 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
239 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
241 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
243 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
244 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
247 //--------------------------------------------------------------------------------------
248 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
250 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
251 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
253 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
254 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
255 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
257 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
258 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
261 //--------------------------------------------------------------------------------------
262 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
266 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
267 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
270 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
273 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
274 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
277 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
278 double theX2, double theY2,
279 double theX3, double theY3)
281 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
282 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
285 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
286 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
287 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
289 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
290 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
293 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
295 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
296 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
299 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
301 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
302 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
303 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
306 //--------------------------------------------------------------------------------------
307 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
308 double theStartX, double theStartY,
309 double theEndX, double theEndY,
312 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
313 return ArcPtr(new SketchAPI_Arc(aFeature,
314 theCenterX, theCenterY,
315 theStartX, theStartY,
320 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
321 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
322 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
325 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
326 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
329 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
330 double theEndX, double theEndY,
331 double thePassedX, double thePassedY)
333 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
334 return ArcPtr(new SketchAPI_Arc(aFeature,
335 theStartX, theStartY,
337 thePassedX, thePassedY));
340 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
341 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
342 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
344 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
345 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
348 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
349 double theEndX, double theEndY,
352 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
353 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
356 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
357 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
360 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
361 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
364 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
366 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
367 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
370 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
372 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
373 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
374 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
377 //--------------------------------------------------------------------------------------
378 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
379 const ModelHighAPI_Selection & theExternalFeature)
381 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
382 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
385 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
386 const std::string & theExternalName)
388 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
389 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
392 //--------------------------------------------------------------------------------------
393 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
394 const ModelHighAPI_RefAttr & theMirrorLine,
395 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
397 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
398 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
401 //--------------------------------------------------------------------------------------
402 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
403 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
404 const ModelHighAPI_RefAttr & thePoint1,
405 const ModelHighAPI_RefAttr & thePoint2,
406 const ModelHighAPI_Integer & theNumberOfObjects,
409 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
410 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1, thePoint2, theNumberOfObjects, theFullValue));
413 //--------------------------------------------------------------------------------------
414 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
415 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
416 const ModelHighAPI_RefAttr & theCenter,
417 const ModelHighAPI_Double & theAngle,
418 const ModelHighAPI_Integer & theNumberOfObjects,
421 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
422 return RotationPtr(new SketchAPI_Rotation(aFeature, theObjects, theCenter, theAngle, theNumberOfObjects, theFullValue));
425 //--------------------------------------------------------------------------------------
426 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
427 const ModelHighAPI_RefAttr & theLine1,
428 const ModelHighAPI_RefAttr & theLine2,
429 const ModelHighAPI_Double & theValue)
431 std::shared_ptr<ModelAPI_Feature> aFeature =
432 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
433 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
434 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
435 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
436 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
437 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
442 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleComplementary(
443 const ModelHighAPI_RefAttr & theLine1,
444 const ModelHighAPI_RefAttr & theLine2,
445 const ModelHighAPI_Double & theValue)
447 std::shared_ptr<ModelAPI_Feature> aFeature =
448 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
449 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
450 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
451 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
452 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
453 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
454 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
459 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleBackward(
460 const ModelHighAPI_RefAttr & theLine1,
461 const ModelHighAPI_RefAttr & theLine2,
462 const ModelHighAPI_Double & theValue)
464 std::shared_ptr<ModelAPI_Feature> aFeature =
465 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
466 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
467 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
468 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
469 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
470 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
471 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
476 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
477 const ModelHighAPI_RefAttr & thePoint1,
478 const ModelHighAPI_RefAttr & thePoint2)
480 std::shared_ptr<ModelAPI_Feature> aFeature =
481 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
482 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
483 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
488 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCollinear(
489 const ModelHighAPI_RefAttr & theLine1,
490 const ModelHighAPI_RefAttr & theLine2)
492 std::shared_ptr<ModelAPI_Feature> aFeature =
493 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
494 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
495 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
500 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
501 const ModelHighAPI_RefAttr & thePoint,
502 const ModelHighAPI_RefAttr & thePointOrLine,
503 const ModelHighAPI_Double & theValue)
505 std::shared_ptr<ModelAPI_Feature> aFeature =
506 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
507 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
508 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
509 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
514 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setEqual(
515 const ModelHighAPI_RefAttr & theObject1,
516 const ModelHighAPI_RefAttr & theObject2)
518 std::shared_ptr<ModelAPI_Feature> aFeature =
519 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
520 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
521 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
526 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFillet(
527 const std::list<ModelHighAPI_RefAttr> & thePoints,
528 const ModelHighAPI_Double & theRadius)
530 std::shared_ptr<ModelAPI_Feature> aFeature =
531 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
532 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
533 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
538 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFixed(
539 const ModelHighAPI_RefAttr & theObject)
541 std::shared_ptr<ModelAPI_Feature> aFeature =
542 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
543 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
548 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setHorizontal(
549 const ModelHighAPI_RefAttr & theLine)
551 std::shared_ptr<ModelAPI_Feature> aFeature =
552 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
553 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
558 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
559 const ModelHighAPI_RefAttr & theLine,
560 const ModelHighAPI_Double & theValue)
562 std::shared_ptr<ModelAPI_Feature> aFeature =
563 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
564 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
565 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
570 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setMiddlePoint(
571 const ModelHighAPI_RefAttr & thePoint,
572 const ModelHighAPI_RefAttr & theLine)
574 std::shared_ptr<ModelAPI_Feature> aFeature =
575 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
576 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
577 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
582 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
583 const ModelHighAPI_RefAttr & theLine1,
584 const ModelHighAPI_RefAttr & theLine2)
586 std::shared_ptr<ModelAPI_Feature> aFeature =
587 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
588 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
589 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
594 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
595 const ModelHighAPI_RefAttr & theLine1,
596 const ModelHighAPI_RefAttr & theLine2)
598 std::shared_ptr<ModelAPI_Feature> aFeature =
599 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
600 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
601 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
606 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRadius(
607 const ModelHighAPI_RefAttr & theCircleOrArc,
608 const ModelHighAPI_Double & theValue)
610 std::shared_ptr<ModelAPI_Feature> aFeature =
611 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
612 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
613 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
618 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setTangent(
619 const ModelHighAPI_RefAttr & theLine,
620 const ModelHighAPI_RefAttr & theCircle)
622 std::shared_ptr<ModelAPI_Feature> aFeature =
623 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
624 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
625 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
630 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setVertical(
631 const ModelHighAPI_RefAttr & theLine)
633 std::shared_ptr<ModelAPI_Feature> aFeature =
634 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
635 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
640 //--------------------------------------------------------------------------------------
642 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
644 FeaturePtr aBase = feature();
645 const std::string& aDocName = theDumper.name(aBase->document());
647 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
648 if (anExternal->value()) {
649 theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal << ")" << std::endl;
651 // Sketch is base on a plane.
652 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
653 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
654 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
655 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
656 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
657 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
659 // Check the plane is coordinate plane
660 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
661 if (anExternal->context()) { // checking for selected planes
662 if (!aPlaneName.empty()) {
663 // dump sketch based on coordinate plane
664 theDumper << aBase << " = model.addSketch(" << aDocName
665 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
666 } else { // some other plane
667 theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal<< ")" << std::endl;
670 if (aPlaneName.empty()) {
671 // needs import additional module
672 theDumper.importModule("GeomAPI");
673 // dump plane parameters
674 const std::string& aSketchName = theDumper.name(aBase);
675 std::string anOriginName = aSketchName + "_origin";
676 std::string aNormalName = aSketchName + "_norm";
677 std::string aDirXName = aSketchName + "_dirx";
678 // use "\n" instead of std::endl to avoid automatic dumping sketch here
679 // and then dumplicate dumping it in the next line
680 theDumper << anOriginName << " = " << anOrigin << "\n"
681 << aNormalName << " = " << aNormal << "\n"
682 << aDirXName << " = " << aDirX << "\n";
683 // dump sketch based on arbitrary plane
684 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
685 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
687 // dump sketch based on coordinate plane
688 theDumper << aBase << " = model.addSketch(" << aDocName
689 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
694 // dump sketch's subfeatures
695 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
696 theDumper.processSubs(aCompFeat, true);