1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : SketchAPI_Sketch.cpp
6 // 07/06/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Sketch.h"
10 //--------------------------------------------------------------------------------------
11 #include <SketchPlugin_Constraint.h>
12 #include <SketchPlugin_ConstraintAngle.h>
13 #include <SketchPlugin_ConstraintCoincidence.h>
14 #include <SketchPlugin_ConstraintCollinear.h>
15 #include <SketchPlugin_ConstraintDistance.h>
16 #include <SketchPlugin_ConstraintEqual.h>
17 #include <SketchPlugin_ConstraintFillet.h>
18 #include <SketchPlugin_ConstraintHorizontal.h>
19 #include <SketchPlugin_ConstraintLength.h>
20 #include <SketchPlugin_ConstraintMiddle.h>
21 #include <SketchPlugin_ConstraintMirror.h>
22 #include <SketchPlugin_ConstraintParallel.h>
23 #include <SketchPlugin_ConstraintPerpendicular.h>
24 #include <SketchPlugin_ConstraintRadius.h>
25 #include <SketchPlugin_ConstraintRigid.h>
26 #include <SketchPlugin_ConstraintSplit.h>
27 #include <SketchPlugin_ConstraintTangent.h>
28 #include <SketchPlugin_ConstraintVertical.h>
29 #include <SketcherPrs_Tools.h>
30 //--------------------------------------------------------------------------------------
31 #include <ModelAPI_CompositeFeature.h>
32 #include <ModelAPI_ResultConstruction.h>
33 #include <ModelHighAPI_Dumper.h>
34 #include <ModelHighAPI_RefAttr.h>
35 #include <ModelHighAPI_Selection.h>
36 #include <ModelHighAPI_Services.h>
37 #include <ModelHighAPI_Tools.h>
38 //--------------------------------------------------------------------------------------
39 #include "SketchAPI_Arc.h"
40 #include "SketchAPI_Circle.h"
41 #include "SketchAPI_IntersectionPoint.h"
42 #include "SketchAPI_Line.h"
43 #include "SketchAPI_Mirror.h"
44 #include "SketchAPI_Point.h"
45 #include "SketchAPI_Projection.h"
46 #include "SketchAPI_Rectangle.h"
47 #include "SketchAPI_Rotation.h"
48 #include "SketchAPI_Translation.h"
49 //--------------------------------------------------------------------------------------
50 SketchAPI_Sketch::SketchAPI_Sketch(
51 const std::shared_ptr<ModelAPI_Feature> & theFeature)
52 : ModelHighAPI_Interface(theFeature)
57 SketchAPI_Sketch::SketchAPI_Sketch(
58 const std::shared_ptr<ModelAPI_Feature> & theFeature,
59 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
60 : ModelHighAPI_Interface(theFeature)
67 SketchAPI_Sketch::SketchAPI_Sketch(
68 const std::shared_ptr<ModelAPI_Feature> & theFeature,
69 const ModelHighAPI_Selection & theExternal)
70 : ModelHighAPI_Interface(theFeature)
73 setExternal(theExternal);
77 SketchAPI_Sketch::SketchAPI_Sketch(
78 const std::shared_ptr<ModelAPI_Feature> & theFeature,
79 std::shared_ptr<ModelAPI_Object> thePlaneObject)
80 : ModelHighAPI_Interface(theFeature)
83 setExternal(thePlaneObject);
87 SketchAPI_Sketch::~SketchAPI_Sketch()
92 //--------------------------------------------------------------------------------------
93 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
95 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
98 //--------------------------------------------------------------------------------------
99 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
101 fillAttribute(thePlane->origin(), myorigin);
102 fillAttribute(thePlane->dirX(), mydirX);
103 fillAttribute(thePlane->normal(), mynormal);
108 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
110 fillAttribute(theExternal, myexternal);
115 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
117 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
118 ModelHighAPI_Selection aSel(aRes);
122 //--------------------------------------------------------------------------------------
123 void SketchAPI_Sketch::setValue(
124 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
125 const ModelHighAPI_Double & theValue)
127 // TODO(spo): check somehow that the feature is a constraint or eliminate
128 // crash if the feature have no real attribute VALUE
129 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
131 // theConstraint->execute();
134 //--------------------------------------------------------------------------------------
135 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
137 const_cast<SketchAPI_Sketch*>(this)->execute();
139 std::list<ModelHighAPI_Selection> aSelectionList;
141 ResultConstructionPtr aResultConstruction =
142 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
143 if (aResultConstruction.get() == NULL)
144 return aSelectionList;
146 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
147 aSelectionList.push_back(
148 ModelHighAPI_Selection(aResultConstruction,
149 aResultConstruction->face(anIndex)));
152 return aSelectionList;
155 //--------------------------------------------------------------------------------------
156 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
157 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
159 // TODO(spo): check that thePart is not empty
160 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
161 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
164 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
165 const ModelHighAPI_Selection & theExternal)
167 // TODO(spo): check that thePart is not empty
168 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
169 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
172 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
173 const std::string & theExternalName)
175 // TODO(spo): check that thePart is not empty
176 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
178 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
181 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
182 std::shared_ptr<ModelAPI_Object> thePlaneObject)
184 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
185 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
189 //--------------------------------------------------------------------------------------
190 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
191 double theX, double theY)
193 std::shared_ptr<ModelAPI_Feature> aFeature =
194 compositeFeature()->addFeature(SketchPlugin_Point::ID());
195 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
197 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
198 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
200 std::shared_ptr<ModelAPI_Feature> aFeature =
201 compositeFeature()->addFeature(SketchPlugin_Point::ID());
202 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
204 std::shared_ptr<SketchAPI_Point>
205 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
207 std::shared_ptr<ModelAPI_Feature> aFeature =
208 compositeFeature()->addFeature(SketchPlugin_Point::ID());
209 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
211 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
213 std::shared_ptr<ModelAPI_Feature> aFeature =
214 compositeFeature()->addFeature(SketchPlugin_Point::ID());
215 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
218 //--------------------------------------------------------------------------------------
219 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
220 const ModelHighAPI_Selection & theExternal)
222 std::shared_ptr<ModelAPI_Feature> aFeature =
223 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
224 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
226 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
227 const std::string & theExternalName)
229 std::shared_ptr<ModelAPI_Feature> aFeature =
230 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
231 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
234 //--------------------------------------------------------------------------------------
235 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
236 double theX2, double theY2)
238 std::shared_ptr<ModelAPI_Feature> aFeature =
239 compositeFeature()->addFeature(SketchPlugin_Line::ID());
240 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
242 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
243 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
244 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
246 std::shared_ptr<ModelAPI_Feature> aFeature =
247 compositeFeature()->addFeature(SketchPlugin_Line::ID());
248 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
250 std::shared_ptr<SketchAPI_Line>
251 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
253 std::shared_ptr<ModelAPI_Feature> aFeature =
254 compositeFeature()->addFeature(SketchPlugin_Line::ID());
255 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
257 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
259 std::shared_ptr<ModelAPI_Feature> aFeature =
260 compositeFeature()->addFeature(SketchPlugin_Line::ID());
261 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
264 //--------------------------------------------------------------------------------------
265 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
266 double theX2, double theY2)
268 std::shared_ptr<ModelAPI_Feature> aFeature =
269 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
270 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
272 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
273 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
274 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
276 std::shared_ptr<ModelAPI_Feature> aFeature =
277 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
278 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
281 //--------------------------------------------------------------------------------------
282 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
286 std::shared_ptr<ModelAPI_Feature> aFeature =
287 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
288 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
291 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
292 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
295 std::shared_ptr<ModelAPI_Feature> aFeature =
296 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
297 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
300 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
301 double theX2, double theY2,
302 double theX3, double theY3)
304 std::shared_ptr<ModelAPI_Feature> aFeature =
305 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
306 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
309 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
310 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
311 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
312 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
314 std::shared_ptr<ModelAPI_Feature> aFeature =
315 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
316 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
319 std::shared_ptr<SketchAPI_Circle>
320 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
322 std::shared_ptr<ModelAPI_Feature> aFeature =
323 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
324 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
327 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
329 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
330 std::shared_ptr<ModelAPI_Feature> aFeature =
331 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
332 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
335 //--------------------------------------------------------------------------------------
336 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
337 double theStartX, double theStartY,
338 double theEndX, double theEndY,
341 std::shared_ptr<ModelAPI_Feature> aFeature =
342 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
343 return ArcPtr(new SketchAPI_Arc(aFeature,
344 theCenterX, theCenterY,
345 theStartX, theStartY,
350 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
351 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
352 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
353 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
356 std::shared_ptr<ModelAPI_Feature> aFeature =
357 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
358 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
361 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
362 double theEndX, double theEndY,
363 double thePassedX, double thePassedY)
365 std::shared_ptr<ModelAPI_Feature> aFeature =
366 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
367 return ArcPtr(new SketchAPI_Arc(aFeature,
368 theStartX, theStartY,
370 thePassedX, thePassedY));
373 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
374 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
375 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
376 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
378 std::shared_ptr<ModelAPI_Feature> aFeature =
379 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
380 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
383 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
384 const ModelHighAPI_RefAttr& theTangentPoint,
385 double theEndX, double theEndY,
388 std::shared_ptr<ModelAPI_Feature> aFeature =
389 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
390 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
393 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
394 const ModelHighAPI_RefAttr& theTangentPoint,
395 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
398 std::shared_ptr<ModelAPI_Feature> aFeature =
399 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
400 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
403 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
405 std::shared_ptr<ModelAPI_Feature> aFeature =
406 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
407 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
410 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
412 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
413 std::shared_ptr<ModelAPI_Feature> aFeature =
414 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
415 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
418 //--------------------------------------------------------------------------------------
419 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
420 const ModelHighAPI_Selection & theExternalFeature)
422 std::shared_ptr<ModelAPI_Feature> aFeature =
423 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
424 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
427 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
428 const std::string & theExternalName)
430 std::shared_ptr<ModelAPI_Feature> aFeature =
431 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
432 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
435 //--------------------------------------------------------------------------------------
436 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
437 const ModelHighAPI_RefAttr & theMirrorLine,
438 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
440 std::shared_ptr<ModelAPI_Feature> aFeature =
441 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
442 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
445 //--------------------------------------------------------------------------------------
446 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
447 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
448 const ModelHighAPI_RefAttr & thePoint1,
449 const ModelHighAPI_RefAttr & thePoint2,
450 const ModelHighAPI_Integer & theNumberOfObjects,
453 std::shared_ptr<ModelAPI_Feature> aFeature =
454 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
455 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
456 thePoint2, theNumberOfObjects, theFullValue));
459 //--------------------------------------------------------------------------------------
460 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
461 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
462 const ModelHighAPI_RefAttr & theCenter,
463 const ModelHighAPI_Double & theAngle,
464 const ModelHighAPI_Integer & theNumberOfObjects,
467 std::shared_ptr<ModelAPI_Feature> aFeature =
468 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
470 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
471 theAngle, theNumberOfObjects, theFullValue));
474 //--------------------------------------------------------------------------------------
475 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
476 const ModelHighAPI_Reference& theFeature,
477 const ModelHighAPI_RefAttr& thePoint1,
478 const ModelHighAPI_RefAttr& thePoint2)
480 std::shared_ptr<ModelAPI_Feature> aFeature =
481 compositeFeature()->addFeature(SketchPlugin_ConstraintSplit::ID());
482 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Constraint::VALUE()));
483 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
484 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
485 //aFeature->execute();
486 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
489 //--------------------------------------------------------------------------------------
490 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
491 const ModelHighAPI_RefAttr & theLine1,
492 const ModelHighAPI_RefAttr & theLine2,
493 const ModelHighAPI_Double & theValue)
495 std::shared_ptr<ModelAPI_Feature> aFeature =
496 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
497 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
498 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
499 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
500 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
501 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
503 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
506 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
507 const ModelHighAPI_RefAttr & theLine1,
508 const ModelHighAPI_RefAttr & theLine2,
509 const ModelHighAPI_Double & theValue)
511 std::shared_ptr<ModelAPI_Feature> aFeature =
512 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
513 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
514 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
515 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
516 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
517 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
518 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
520 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
523 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
524 const ModelHighAPI_RefAttr & theLine1,
525 const ModelHighAPI_RefAttr & theLine2,
526 const ModelHighAPI_Double & theValue)
528 std::shared_ptr<ModelAPI_Feature> aFeature =
529 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
530 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
531 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
532 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
533 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
534 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
535 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
537 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
540 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
541 const ModelHighAPI_RefAttr & thePoint1,
542 const ModelHighAPI_RefAttr & thePoint2)
544 std::shared_ptr<ModelAPI_Feature> aFeature =
545 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
546 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
547 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
549 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
552 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
553 const ModelHighAPI_RefAttr & theLine1,
554 const ModelHighAPI_RefAttr & theLine2)
556 std::shared_ptr<ModelAPI_Feature> aFeature =
557 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
558 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
559 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
561 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
564 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
565 const ModelHighAPI_RefAttr & thePoint,
566 const ModelHighAPI_RefAttr & thePointOrLine,
567 const ModelHighAPI_Double & theValue)
569 std::shared_ptr<ModelAPI_Feature> aFeature =
570 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
571 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
572 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
573 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
575 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
578 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
579 const ModelHighAPI_RefAttr & theObject1,
580 const ModelHighAPI_RefAttr & theObject2)
582 std::shared_ptr<ModelAPI_Feature> aFeature =
583 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
584 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
585 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
587 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
590 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
591 const std::list<ModelHighAPI_RefAttr> & thePoints,
592 const ModelHighAPI_Double & theRadius)
594 std::shared_ptr<ModelAPI_Feature> aFeature =
595 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
596 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
597 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
599 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
602 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
603 const ModelHighAPI_RefAttr & theObject)
605 std::shared_ptr<ModelAPI_Feature> aFeature =
606 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
607 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
609 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
612 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
613 const ModelHighAPI_RefAttr & theLine)
615 std::shared_ptr<ModelAPI_Feature> aFeature =
616 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
617 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
619 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
622 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
623 const ModelHighAPI_RefAttr & theLine,
624 const ModelHighAPI_Double & theValue)
626 std::shared_ptr<ModelAPI_Feature> aFeature =
627 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
628 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
629 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
631 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
634 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
635 const ModelHighAPI_RefAttr & thePoint,
636 const ModelHighAPI_RefAttr & theLine)
638 std::shared_ptr<ModelAPI_Feature> aFeature =
639 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
640 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
641 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
643 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
646 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
647 const ModelHighAPI_RefAttr & theLine1,
648 const ModelHighAPI_RefAttr & theLine2)
650 std::shared_ptr<ModelAPI_Feature> aFeature =
651 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
652 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
653 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
655 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
658 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
659 const ModelHighAPI_RefAttr & theLine1,
660 const ModelHighAPI_RefAttr & theLine2)
662 std::shared_ptr<ModelAPI_Feature> aFeature =
663 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
664 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
665 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
667 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
670 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
671 const ModelHighAPI_RefAttr & theCircleOrArc,
672 const ModelHighAPI_Double & theValue)
674 std::shared_ptr<ModelAPI_Feature> aFeature =
675 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
676 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
677 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
679 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
682 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
683 const ModelHighAPI_RefAttr & theLine,
684 const ModelHighAPI_RefAttr & theCircle)
686 std::shared_ptr<ModelAPI_Feature> aFeature =
687 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
688 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
689 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
691 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
694 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
695 const ModelHighAPI_RefAttr & theLine)
697 std::shared_ptr<ModelAPI_Feature> aFeature =
698 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
699 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
701 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
704 //--------------------------------------------------------------------------------------
706 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
708 FeaturePtr aBase = feature();
709 const std::string& aDocName = theDumper.name(aBase->document());
711 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
712 if (anExternal->value()) {
713 theDumper << aBase << " = model.addSketch(" << aDocName <<
714 ", " << anExternal << ")" << std::endl;
716 // Sketch is base on a plane.
717 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
718 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
719 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
720 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
721 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
722 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
724 // Check the plane is coordinate plane
725 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
726 if (anExternal->context()) { // checking for selected planes
727 if (!aPlaneName.empty()) {
728 // dump sketch based on coordinate plane
729 theDumper << aBase << " = model.addSketch(" << aDocName
730 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
731 } else { // some other plane
732 theDumper << aBase << " = model.addSketch(" << aDocName <<
733 ", " << anExternal<< ")" << std::endl;
736 if (aPlaneName.empty()) {
737 // needs import additional module
738 theDumper.importModule("GeomAPI");
739 // dump plane parameters
740 const std::string& aSketchName = theDumper.name(aBase);
741 std::string anOriginName = aSketchName + "_origin";
742 std::string aNormalName = aSketchName + "_norm";
743 std::string aDirXName = aSketchName + "_dirx";
744 // use "\n" instead of std::endl to avoid automatic dumping sketch here
745 // and then dumplicate dumping it in the next line
746 theDumper << anOriginName << " = " << anOrigin << "\n"
747 << aNormalName << " = " << aNormal << "\n"
748 << aDirXName << " = " << aDirX << "\n";
749 // dump sketch based on arbitrary plane
750 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
751 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
753 // dump sketch based on coordinate plane
754 theDumper << aBase << " = model.addSketch(" << aDocName
755 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
760 // dump sketch's subfeatures
761 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
762 theDumper.processSubs(aCompFeat, true);