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 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 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 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
165 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
168 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
169 const std::string & theExternalName)
171 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
173 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
176 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
177 std::shared_ptr<ModelAPI_Object> thePlaneObject)
179 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
180 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
184 //--------------------------------------------------------------------------------------
185 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
186 double theX, double theY)
188 std::shared_ptr<ModelAPI_Feature> aFeature =
189 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 =
196 compositeFeature()->addFeature(SketchPlugin_Point::ID());
197 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
199 std::shared_ptr<SketchAPI_Point>
200 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
202 std::shared_ptr<ModelAPI_Feature> aFeature =
203 compositeFeature()->addFeature(SketchPlugin_Point::ID());
204 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
206 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
208 std::shared_ptr<ModelAPI_Feature> aFeature =
209 compositeFeature()->addFeature(SketchPlugin_Point::ID());
210 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
213 //--------------------------------------------------------------------------------------
214 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
215 const ModelHighAPI_Selection & theExternal)
217 std::shared_ptr<ModelAPI_Feature> aFeature =
218 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
219 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
221 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
222 const std::string & theExternalName)
224 std::shared_ptr<ModelAPI_Feature> aFeature =
225 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
226 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
229 //--------------------------------------------------------------------------------------
230 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
231 double theX2, double theY2)
233 std::shared_ptr<ModelAPI_Feature> aFeature =
234 compositeFeature()->addFeature(SketchPlugin_Line::ID());
235 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
237 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
238 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
239 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
241 std::shared_ptr<ModelAPI_Feature> aFeature =
242 compositeFeature()->addFeature(SketchPlugin_Line::ID());
243 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
245 std::shared_ptr<SketchAPI_Line>
246 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
248 std::shared_ptr<ModelAPI_Feature> aFeature =
249 compositeFeature()->addFeature(SketchPlugin_Line::ID());
250 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
252 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
254 std::shared_ptr<ModelAPI_Feature> aFeature =
255 compositeFeature()->addFeature(SketchPlugin_Line::ID());
256 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
259 //--------------------------------------------------------------------------------------
260 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
261 double theX2, double theY2)
263 std::shared_ptr<ModelAPI_Feature> aFeature =
264 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
265 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
267 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
268 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
269 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
271 std::shared_ptr<ModelAPI_Feature> aFeature =
272 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
273 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
276 //--------------------------------------------------------------------------------------
277 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
281 std::shared_ptr<ModelAPI_Feature> aFeature =
282 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
283 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
286 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
287 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
290 std::shared_ptr<ModelAPI_Feature> aFeature =
291 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
292 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
295 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
296 double theX2, double theY2,
297 double theX3, double theY3)
299 std::shared_ptr<ModelAPI_Feature> aFeature =
300 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
301 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
304 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
305 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
306 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
307 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
309 std::shared_ptr<ModelAPI_Feature> aFeature =
310 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
311 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
314 std::shared_ptr<SketchAPI_Circle>
315 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
317 std::shared_ptr<ModelAPI_Feature> aFeature =
318 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
319 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
322 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
324 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
325 std::shared_ptr<ModelAPI_Feature> aFeature =
326 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
327 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
330 //--------------------------------------------------------------------------------------
331 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
332 double theStartX, double theStartY,
333 double theEndX, double theEndY,
336 std::shared_ptr<ModelAPI_Feature> aFeature =
337 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
338 return ArcPtr(new SketchAPI_Arc(aFeature,
339 theCenterX, theCenterY,
340 theStartX, theStartY,
345 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
346 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
347 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
348 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
351 std::shared_ptr<ModelAPI_Feature> aFeature =
352 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
353 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
356 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
357 double theEndX, double theEndY,
358 double thePassedX, double thePassedY)
360 std::shared_ptr<ModelAPI_Feature> aFeature =
361 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
362 return ArcPtr(new SketchAPI_Arc(aFeature,
363 theStartX, theStartY,
365 thePassedX, thePassedY));
368 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
369 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
370 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
371 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
373 std::shared_ptr<ModelAPI_Feature> aFeature =
374 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
375 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
378 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
379 const ModelHighAPI_RefAttr& theTangentPoint,
380 double theEndX, double theEndY,
383 std::shared_ptr<ModelAPI_Feature> aFeature =
384 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
385 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
388 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
389 const ModelHighAPI_RefAttr& theTangentPoint,
390 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
393 std::shared_ptr<ModelAPI_Feature> aFeature =
394 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
395 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
398 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
400 std::shared_ptr<ModelAPI_Feature> aFeature =
401 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
402 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
405 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
407 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
408 std::shared_ptr<ModelAPI_Feature> aFeature =
409 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
410 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
413 //--------------------------------------------------------------------------------------
414 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
415 const ModelHighAPI_Selection & theExternalFeature)
417 std::shared_ptr<ModelAPI_Feature> aFeature =
418 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
419 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
422 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
423 const std::string & theExternalName)
425 std::shared_ptr<ModelAPI_Feature> aFeature =
426 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
427 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
430 //--------------------------------------------------------------------------------------
431 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
432 const ModelHighAPI_RefAttr & theMirrorLine,
433 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
435 std::shared_ptr<ModelAPI_Feature> aFeature =
436 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
437 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
440 //--------------------------------------------------------------------------------------
441 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
442 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
443 const ModelHighAPI_RefAttr & thePoint1,
444 const ModelHighAPI_RefAttr & thePoint2,
445 const ModelHighAPI_Integer & theNumberOfObjects,
448 std::shared_ptr<ModelAPI_Feature> aFeature =
449 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
450 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
451 thePoint2, theNumberOfObjects, theFullValue));
454 //--------------------------------------------------------------------------------------
455 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
456 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
457 const ModelHighAPI_RefAttr & theCenter,
458 const ModelHighAPI_Double & theAngle,
459 const ModelHighAPI_Integer & theNumberOfObjects,
462 std::shared_ptr<ModelAPI_Feature> aFeature =
463 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
465 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
466 theAngle, theNumberOfObjects, theFullValue));
469 //--------------------------------------------------------------------------------------
470 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
471 const ModelHighAPI_Reference& theFeature,
472 const ModelHighAPI_RefAttr& thePoint1,
473 const ModelHighAPI_RefAttr& thePoint2)
475 std::shared_ptr<ModelAPI_Feature> aFeature =
476 compositeFeature()->addFeature(SketchPlugin_ConstraintSplit::ID());
477 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Constraint::VALUE()));
478 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
479 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
480 //aFeature->execute();
481 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
484 //--------------------------------------------------------------------------------------
485 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
486 const ModelHighAPI_RefAttr & theLine1,
487 const ModelHighAPI_RefAttr & theLine2,
488 const ModelHighAPI_Double & theValue)
490 std::shared_ptr<ModelAPI_Feature> aFeature =
491 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
492 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
493 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
494 // fill the value before llines to avoid calculation of angle value by the Angle feature
495 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
496 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
497 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
499 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
502 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
503 const ModelHighAPI_RefAttr & theLine1,
504 const ModelHighAPI_RefAttr & theLine2,
505 const ModelHighAPI_Double & theValue)
507 std::shared_ptr<ModelAPI_Feature> aFeature =
508 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
509 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
510 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
511 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
512 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
513 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
514 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
516 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
519 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
520 const ModelHighAPI_RefAttr & theLine1,
521 const ModelHighAPI_RefAttr & theLine2,
522 const ModelHighAPI_Double & theValue)
524 std::shared_ptr<ModelAPI_Feature> aFeature =
525 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
526 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
527 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
528 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
529 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
530 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
531 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
533 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
536 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
537 const ModelHighAPI_RefAttr & thePoint1,
538 const ModelHighAPI_RefAttr & thePoint2)
540 std::shared_ptr<ModelAPI_Feature> aFeature =
541 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
542 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
543 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
545 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
548 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
549 const ModelHighAPI_RefAttr & theLine1,
550 const ModelHighAPI_RefAttr & theLine2)
552 std::shared_ptr<ModelAPI_Feature> aFeature =
553 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
554 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
555 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
557 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
560 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
561 const ModelHighAPI_RefAttr & thePoint,
562 const ModelHighAPI_RefAttr & thePointOrLine,
563 const ModelHighAPI_Double & theValue)
565 std::shared_ptr<ModelAPI_Feature> aFeature =
566 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
567 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
568 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
569 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
571 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
574 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
575 const ModelHighAPI_RefAttr & theObject1,
576 const ModelHighAPI_RefAttr & theObject2)
578 std::shared_ptr<ModelAPI_Feature> aFeature =
579 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
580 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
581 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
583 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
586 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
587 const std::list<ModelHighAPI_RefAttr> & thePoints,
588 const ModelHighAPI_Double & theRadius)
590 std::shared_ptr<ModelAPI_Feature> aFeature =
591 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
592 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
593 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
595 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
598 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
599 const ModelHighAPI_RefAttr & theObject)
601 std::shared_ptr<ModelAPI_Feature> aFeature =
602 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
603 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
605 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
608 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
609 const ModelHighAPI_RefAttr & theLine)
611 std::shared_ptr<ModelAPI_Feature> aFeature =
612 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
613 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
615 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
618 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
619 const ModelHighAPI_RefAttr & theLine,
620 const ModelHighAPI_Double & theValue)
622 std::shared_ptr<ModelAPI_Feature> aFeature =
623 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
624 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
625 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
627 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
630 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
631 const ModelHighAPI_RefAttr & thePoint,
632 const ModelHighAPI_RefAttr & theLine)
634 std::shared_ptr<ModelAPI_Feature> aFeature =
635 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
636 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
637 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
639 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
642 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
643 const ModelHighAPI_RefAttr & theLine1,
644 const ModelHighAPI_RefAttr & theLine2)
646 std::shared_ptr<ModelAPI_Feature> aFeature =
647 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
648 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
649 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
651 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
654 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
655 const ModelHighAPI_RefAttr & theLine1,
656 const ModelHighAPI_RefAttr & theLine2)
658 std::shared_ptr<ModelAPI_Feature> aFeature =
659 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
660 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
661 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
663 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
666 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
667 const ModelHighAPI_RefAttr & theCircleOrArc,
668 const ModelHighAPI_Double & theValue)
670 std::shared_ptr<ModelAPI_Feature> aFeature =
671 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
672 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
673 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
675 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
678 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
679 const ModelHighAPI_RefAttr & theLine,
680 const ModelHighAPI_RefAttr & theCircle)
682 std::shared_ptr<ModelAPI_Feature> aFeature =
683 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
684 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
685 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
687 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
690 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
691 const ModelHighAPI_RefAttr & theLine)
693 std::shared_ptr<ModelAPI_Feature> aFeature =
694 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
695 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
697 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
700 //--------------------------------------------------------------------------------------
702 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
704 FeaturePtr aBase = feature();
705 const std::string& aDocName = theDumper.name(aBase->document());
707 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
708 if (anExternal->value()) {
709 theDumper << aBase << " = model.addSketch(" << aDocName <<
710 ", " << anExternal << ")" << std::endl;
712 // Sketch is base on a plane.
713 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
714 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
715 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
716 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
717 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
718 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
720 // Check the plane is coordinate plane
721 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
722 if (anExternal->context()) { // checking for selected planes
723 if (!aPlaneName.empty()) {
724 // dump sketch based on coordinate plane
725 theDumper << aBase << " = model.addSketch(" << aDocName
726 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
727 } else { // some other plane
728 theDumper << aBase << " = model.addSketch(" << aDocName <<
729 ", " << anExternal<< ")" << std::endl;
732 if (aPlaneName.empty()) {
733 // needs import additional module
734 theDumper.importModule("GeomAPI");
735 // dump plane parameters
736 const std::string& aSketchName = theDumper.name(aBase);
737 std::string anOriginName = aSketchName + "_origin";
738 std::string aNormalName = aSketchName + "_norm";
739 std::string aDirXName = aSketchName + "_dirx";
740 // use "\n" instead of std::endl to avoid automatic dumping sketch here
741 // and then dumplicate dumping it in the next line
742 theDumper << anOriginName << " = " << anOrigin << "\n"
743 << aNormalName << " = " << aNormal << "\n"
744 << aDirXName << " = " << aDirX << "\n";
745 // dump sketch based on arbitrary plane
746 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
747 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
749 // dump sketch based on coordinate plane
750 theDumper << aBase << " = model.addSketch(" << aDocName
751 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
756 // dump sketch's subfeatures
757 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
758 theDumper.processSubs(aCompFeat, true);