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 LinePtr aLine(new SketchAPI_Line(aFeature, theExternal));
240 setFixed(InterfacePtr(aLine));
243 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
245 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
246 LinePtr aLine(new SketchAPI_Line(aFeature, theExternalName));
247 setFixed(InterfacePtr(aLine));
251 //--------------------------------------------------------------------------------------
252 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
254 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
255 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
257 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
258 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
259 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
261 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
262 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
265 //--------------------------------------------------------------------------------------
266 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
270 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
271 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
274 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
277 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
278 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
281 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
282 double theX2, double theY2,
283 double theX3, double theY3)
285 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
286 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
289 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
290 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
291 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
293 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
294 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
297 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
299 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
300 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
303 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
305 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
306 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
307 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
310 //--------------------------------------------------------------------------------------
311 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
312 double theStartX, double theStartY,
313 double theEndX, double theEndY,
316 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
317 return ArcPtr(new SketchAPI_Arc(aFeature,
318 theCenterX, theCenterY,
319 theStartX, theStartY,
324 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
325 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
326 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
329 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
330 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
333 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
334 double theEndX, double theEndY,
335 double thePassedX, double thePassedY)
337 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
338 return ArcPtr(new SketchAPI_Arc(aFeature,
339 theStartX, theStartY,
341 thePassedX, thePassedY));
344 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
345 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
346 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
348 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
349 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
352 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
353 double theEndX, double theEndY,
356 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
357 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
360 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
361 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
364 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
365 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
368 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
370 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
371 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
374 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
376 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
377 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
378 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
381 //--------------------------------------------------------------------------------------
382 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
383 const ModelHighAPI_Selection & theExternalFeature)
385 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
386 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
389 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
390 const std::string & theExternalName)
392 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
393 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
396 //--------------------------------------------------------------------------------------
397 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
398 const ModelHighAPI_RefAttr & theMirrorLine,
399 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
401 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
402 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
405 //--------------------------------------------------------------------------------------
406 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
407 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
408 const ModelHighAPI_RefAttr & thePoint1,
409 const ModelHighAPI_RefAttr & thePoint2,
410 const ModelHighAPI_Integer & theNumberOfObjects,
413 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
414 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1, thePoint2, theNumberOfObjects, theFullValue));
417 //--------------------------------------------------------------------------------------
418 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
419 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
420 const ModelHighAPI_RefAttr & theCenter,
421 const ModelHighAPI_Double & theAngle,
422 const ModelHighAPI_Integer & theNumberOfObjects,
425 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
426 return RotationPtr(new SketchAPI_Rotation(aFeature, theObjects, theCenter, theAngle, theNumberOfObjects, theFullValue));
429 //--------------------------------------------------------------------------------------
430 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
431 const ModelHighAPI_RefAttr & theLine1,
432 const ModelHighAPI_RefAttr & theLine2,
433 const ModelHighAPI_Double & theValue)
435 std::shared_ptr<ModelAPI_Feature> aFeature =
436 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
437 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
438 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
439 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
440 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
441 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
446 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleComplementary(
447 const ModelHighAPI_RefAttr & theLine1,
448 const ModelHighAPI_RefAttr & theLine2,
449 const ModelHighAPI_Double & theValue)
451 std::shared_ptr<ModelAPI_Feature> aFeature =
452 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
453 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
454 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
455 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
456 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
457 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
458 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
463 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleBackward(
464 const ModelHighAPI_RefAttr & theLine1,
465 const ModelHighAPI_RefAttr & theLine2,
466 const ModelHighAPI_Double & theValue)
468 std::shared_ptr<ModelAPI_Feature> aFeature =
469 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
470 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
471 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
472 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
473 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
474 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
475 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
480 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
481 const ModelHighAPI_RefAttr & thePoint1,
482 const ModelHighAPI_RefAttr & thePoint2)
484 std::shared_ptr<ModelAPI_Feature> aFeature =
485 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
486 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
487 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
492 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCollinear(
493 const ModelHighAPI_RefAttr & theLine1,
494 const ModelHighAPI_RefAttr & theLine2)
496 std::shared_ptr<ModelAPI_Feature> aFeature =
497 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
498 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
499 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
504 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
505 const ModelHighAPI_RefAttr & thePoint,
506 const ModelHighAPI_RefAttr & thePointOrLine,
507 const ModelHighAPI_Double & theValue)
509 std::shared_ptr<ModelAPI_Feature> aFeature =
510 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
511 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
512 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
513 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
518 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setEqual(
519 const ModelHighAPI_RefAttr & theObject1,
520 const ModelHighAPI_RefAttr & theObject2)
522 std::shared_ptr<ModelAPI_Feature> aFeature =
523 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
524 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
525 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
530 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFillet(
531 const std::list<ModelHighAPI_RefAttr> & thePoints,
532 const ModelHighAPI_Double & theRadius)
534 std::shared_ptr<ModelAPI_Feature> aFeature =
535 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
536 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
537 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
542 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFixed(
543 const ModelHighAPI_RefAttr & theObject)
545 std::shared_ptr<ModelAPI_Feature> aFeature =
546 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
547 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
552 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setHorizontal(
553 const ModelHighAPI_RefAttr & theLine)
555 std::shared_ptr<ModelAPI_Feature> aFeature =
556 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
557 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
562 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
563 const ModelHighAPI_RefAttr & theLine,
564 const ModelHighAPI_Double & theValue)
566 std::shared_ptr<ModelAPI_Feature> aFeature =
567 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
568 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
569 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
574 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setMiddlePoint(
575 const ModelHighAPI_RefAttr & thePoint,
576 const ModelHighAPI_RefAttr & theLine)
578 std::shared_ptr<ModelAPI_Feature> aFeature =
579 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
580 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
581 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
586 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
587 const ModelHighAPI_RefAttr & theLine1,
588 const ModelHighAPI_RefAttr & theLine2)
590 std::shared_ptr<ModelAPI_Feature> aFeature =
591 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
592 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
593 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
598 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
599 const ModelHighAPI_RefAttr & theLine1,
600 const ModelHighAPI_RefAttr & theLine2)
602 std::shared_ptr<ModelAPI_Feature> aFeature =
603 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
604 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
605 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
610 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRadius(
611 const ModelHighAPI_RefAttr & theCircleOrArc,
612 const ModelHighAPI_Double & theValue)
614 std::shared_ptr<ModelAPI_Feature> aFeature =
615 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
616 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
617 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
622 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setTangent(
623 const ModelHighAPI_RefAttr & theLine,
624 const ModelHighAPI_RefAttr & theCircle)
626 std::shared_ptr<ModelAPI_Feature> aFeature =
627 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
628 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
629 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
634 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setVertical(
635 const ModelHighAPI_RefAttr & theLine)
637 std::shared_ptr<ModelAPI_Feature> aFeature =
638 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
639 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
644 //--------------------------------------------------------------------------------------
646 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
648 FeaturePtr aBase = feature();
649 const std::string& aDocName = theDumper.name(aBase->document());
651 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
652 if (anExternal->value()) {
653 theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal << ")" << std::endl;
655 // Sketch is base on a plane.
656 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
657 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
658 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
659 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
660 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
661 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
663 // Check the plane is coordinate plane
664 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
665 if (anExternal->context()) { // checking for selected planes
666 if (!aPlaneName.empty()) {
667 // dump sketch based on coordinate plane
668 theDumper << aBase << " = model.addSketch(" << aDocName
669 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
670 } else { // some other plane
671 theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal<< ")" << std::endl;
674 if (aPlaneName.empty()) {
675 // needs import additional module
676 theDumper.importModule("GeomAPI");
677 // dump plane parameters
678 const std::string& aSketchName = theDumper.name(aBase);
679 std::string anOriginName = aSketchName + "_origin";
680 std::string aNormalName = aSketchName + "_norm";
681 std::string aDirXName = aSketchName + "_dirx";
682 // use "\n" instead of std::endl to avoid automatic dumping sketch here
683 // and then dumplicate dumping it in the next line
684 theDumper << anOriginName << " = " << anOrigin << "\n"
685 << aNormalName << " = " << aNormal << "\n"
686 << aDirXName << " = " << aDirX << "\n";
687 // dump sketch based on arbitrary plane
688 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
689 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
691 // dump sketch based on coordinate plane
692 theDumper << aBase << " = model.addSketch(" << aDocName
693 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
698 // dump sketch's subfeatures
699 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
700 theDumper.processSubs(aCompFeat, true);