1 // Name : SketchAPI_Sketch.cpp
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Sketch.h"
9 //--------------------------------------------------------------------------------------
10 #include <SketchPlugin_Constraint.h>
11 #include <SketchPlugin_ConstraintAngle.h>
12 #include <SketchPlugin_ConstraintCoincidence.h>
13 #include <SketchPlugin_ConstraintCollinear.h>
14 #include <SketchPlugin_ConstraintDistance.h>
15 #include <SketchPlugin_ConstraintEqual.h>
16 #include <SketchPlugin_ConstraintFillet.h>
17 #include <SketchPlugin_ConstraintHorizontal.h>
18 #include <SketchPlugin_ConstraintLength.h>
19 #include <SketchPlugin_ConstraintMiddle.h>
20 #include <SketchPlugin_ConstraintMirror.h>
21 #include <SketchPlugin_ConstraintParallel.h>
22 #include <SketchPlugin_ConstraintPerpendicular.h>
23 #include <SketchPlugin_ConstraintRadius.h>
24 #include <SketchPlugin_ConstraintRigid.h>
25 #include <SketchPlugin_ConstraintTangent.h>
26 #include <SketchPlugin_ConstraintVertical.h>
27 //--------------------------------------------------------------------------------------
28 #include <ModelAPI_CompositeFeature.h>
29 #include <ModelAPI_ResultConstruction.h>
30 #include <ModelHighAPI_Dumper.h>
31 #include <ModelHighAPI_RefAttr.h>
32 #include <ModelHighAPI_Selection.h>
33 #include <ModelHighAPI_Services.h>
34 #include <ModelHighAPI_Tools.h>
35 //--------------------------------------------------------------------------------------
36 #include "SketchAPI_Arc.h"
37 #include "SketchAPI_Circle.h"
38 #include "SketchAPI_IntersectionPoint.h"
39 #include "SketchAPI_Line.h"
40 #include "SketchAPI_Mirror.h"
41 #include "SketchAPI_Point.h"
42 #include "SketchAPI_Projection.h"
43 #include "SketchAPI_Rectangle.h"
44 #include "SketchAPI_Rotation.h"
45 #include "SketchAPI_Translation.h"
46 //--------------------------------------------------------------------------------------
47 SketchAPI_Sketch::SketchAPI_Sketch(
48 const std::shared_ptr<ModelAPI_Feature> & theFeature)
49 : ModelHighAPI_Interface(theFeature)
54 SketchAPI_Sketch::SketchAPI_Sketch(
55 const std::shared_ptr<ModelAPI_Feature> & theFeature,
56 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
57 : ModelHighAPI_Interface(theFeature)
64 SketchAPI_Sketch::SketchAPI_Sketch(
65 const std::shared_ptr<ModelAPI_Feature> & theFeature,
66 const ModelHighAPI_Selection & theExternal)
67 : ModelHighAPI_Interface(theFeature)
70 setExternal(theExternal);
74 SketchAPI_Sketch::~SketchAPI_Sketch()
79 //--------------------------------------------------------------------------------------
80 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
82 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
85 //--------------------------------------------------------------------------------------
86 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
88 fillAttribute(thePlane->origin(), myorigin);
89 fillAttribute(thePlane->dirX(), mydirX);
90 fillAttribute(thePlane->normal(), mynormal);
95 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
97 fillAttribute(theExternal, myexternal);
102 //--------------------------------------------------------------------------------------
103 void SketchAPI_Sketch::setValue(
104 const std::shared_ptr<ModelAPI_Feature> & theConstraint,
105 const ModelHighAPI_Double & theValue)
107 // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
108 fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
110 // theConstraint->execute();
113 //--------------------------------------------------------------------------------------
114 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
116 const_cast<SketchAPI_Sketch*>(this)->execute();
118 std::list<ModelHighAPI_Selection> aSelectionList;
120 ResultConstructionPtr aResultConstruction =
121 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
122 if (aResultConstruction.get() == NULL)
123 return aSelectionList;
125 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
126 aSelectionList.push_back(
127 ModelHighAPI_Selection(aResultConstruction,
128 aResultConstruction->face(anIndex)));
131 return aSelectionList;
134 //--------------------------------------------------------------------------------------
135 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
136 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
138 // TODO(spo): check that thePart is not empty
139 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
140 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
143 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
144 const ModelHighAPI_Selection & theExternal)
146 // TODO(spo): check that thePart is not empty
147 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
148 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
151 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
152 const std::string & theExternalName)
154 // TODO(spo): check that thePart is not empty
155 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
156 return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
159 //--------------------------------------------------------------------------------------
160 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
161 double theX, double theY)
163 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
164 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
166 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
167 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
169 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
170 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
172 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
174 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
175 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
177 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
179 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
180 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
183 //--------------------------------------------------------------------------------------
184 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
185 const ModelHighAPI_Selection & theExternal)
187 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
188 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
190 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
191 const std::string & theExternalName)
193 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
194 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
197 //--------------------------------------------------------------------------------------
198 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
200 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
201 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
203 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
204 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
205 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
207 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
208 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
210 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
212 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
213 LinePtr aLine(new SketchAPI_Line(aFeature, theExternal));
214 setFixed(InterfacePtr(aLine));
217 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
219 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
220 LinePtr aLine(new SketchAPI_Line(aFeature, theExternalName));
221 setFixed(InterfacePtr(aLine));
225 //--------------------------------------------------------------------------------------
226 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
228 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
229 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
231 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
232 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
233 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
235 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
236 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
239 //--------------------------------------------------------------------------------------
240 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
244 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
245 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
248 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
251 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
252 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
255 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
256 double theX2, double theY2,
257 double theX3, double theY3)
259 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
260 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
263 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
264 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
265 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
267 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
268 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
271 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
273 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
274 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
277 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
279 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
280 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
281 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
284 //--------------------------------------------------------------------------------------
285 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
286 double theStartX, double theStartY,
287 double theEndX, double theEndY,
290 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
291 return ArcPtr(new SketchAPI_Arc(aFeature,
292 theCenterX, theCenterY,
293 theStartX, theStartY,
298 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
299 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
300 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
303 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
304 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
307 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
308 double theEndX, double theEndY,
309 double thePassedX, double thePassedY)
311 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
312 return ArcPtr(new SketchAPI_Arc(aFeature,
313 theStartX, theStartY,
315 thePassedX, thePassedY));
318 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
319 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
320 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
322 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
323 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
326 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
327 double theEndX, double theEndY,
330 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
331 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
334 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
335 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
338 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
339 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
342 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
344 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
345 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
348 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
350 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
351 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
352 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
355 //--------------------------------------------------------------------------------------
356 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
357 const ModelHighAPI_Selection & theExternalFeature)
359 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
360 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
363 //--------------------------------------------------------------------------------------
364 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
365 const ModelHighAPI_RefAttr & theMirrorLine,
366 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
368 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
369 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
372 //--------------------------------------------------------------------------------------
373 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
374 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
375 const ModelHighAPI_RefAttr & thePoint1,
376 const ModelHighAPI_RefAttr & thePoint2,
377 const ModelHighAPI_Integer & theNumberOfObjects,
380 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
381 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1, thePoint2, theNumberOfObjects, theFullValue));
384 //--------------------------------------------------------------------------------------
385 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
386 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
387 const ModelHighAPI_RefAttr & theCenter,
388 const ModelHighAPI_Double & theAngle,
389 const ModelHighAPI_Integer & theNumberOfObjects,
392 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
393 return RotationPtr(new SketchAPI_Rotation(aFeature, theObjects, theCenter, theAngle, theNumberOfObjects, theFullValue));
396 //--------------------------------------------------------------------------------------
397 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
398 const ModelHighAPI_RefAttr & theLine1,
399 const ModelHighAPI_RefAttr & theLine2,
400 const ModelHighAPI_Double & theValue)
402 // TODO(spo): is support of angle type necessary?
403 std::shared_ptr<ModelAPI_Feature> aFeature =
404 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
405 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
406 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
407 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
412 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
413 const ModelHighAPI_RefAttr & thePoint1,
414 const ModelHighAPI_RefAttr & thePoint2)
416 std::shared_ptr<ModelAPI_Feature> aFeature =
417 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
418 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
419 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
424 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCollinear(
425 const ModelHighAPI_RefAttr & theLine1,
426 const ModelHighAPI_RefAttr & theLine2)
428 std::shared_ptr<ModelAPI_Feature> aFeature =
429 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
430 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
431 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
436 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
437 const ModelHighAPI_RefAttr & thePoint,
438 const ModelHighAPI_RefAttr & thePointOrLine,
439 const ModelHighAPI_Double & theValue)
441 std::shared_ptr<ModelAPI_Feature> aFeature =
442 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
443 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
444 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
445 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
450 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setEqual(
451 const ModelHighAPI_RefAttr & theObject1,
452 const ModelHighAPI_RefAttr & theObject2)
454 std::shared_ptr<ModelAPI_Feature> aFeature =
455 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
456 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
457 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
462 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFillet(
463 const std::list<ModelHighAPI_RefAttr> & thePoints,
464 const ModelHighAPI_Double & theRadius)
466 std::shared_ptr<ModelAPI_Feature> aFeature =
467 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
468 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
469 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
474 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFixed(
475 const ModelHighAPI_RefAttr & theObject)
477 std::shared_ptr<ModelAPI_Feature> aFeature =
478 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
479 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
484 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setHorizontal(
485 const ModelHighAPI_RefAttr & theLine)
487 std::shared_ptr<ModelAPI_Feature> aFeature =
488 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
489 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
494 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
495 const ModelHighAPI_RefAttr & theLine,
496 const ModelHighAPI_Double & theValue)
498 std::shared_ptr<ModelAPI_Feature> aFeature =
499 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
500 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
501 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
506 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setMiddlePoint(
507 const ModelHighAPI_RefAttr & thePoint,
508 const ModelHighAPI_RefAttr & theLine)
510 std::shared_ptr<ModelAPI_Feature> aFeature =
511 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
512 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
513 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
518 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
519 const ModelHighAPI_RefAttr & theLine1,
520 const ModelHighAPI_RefAttr & theLine2)
522 std::shared_ptr<ModelAPI_Feature> aFeature =
523 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
524 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
525 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
530 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
531 const ModelHighAPI_RefAttr & theLine1,
532 const ModelHighAPI_RefAttr & theLine2)
534 std::shared_ptr<ModelAPI_Feature> aFeature =
535 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
536 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
537 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
542 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRadius(
543 const ModelHighAPI_RefAttr & theCircleOrArc,
544 const ModelHighAPI_Double & theValue)
546 std::shared_ptr<ModelAPI_Feature> aFeature =
547 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
548 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
549 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
554 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setTangent(
555 const ModelHighAPI_RefAttr & theLine,
556 const ModelHighAPI_RefAttr & theCircle)
558 std::shared_ptr<ModelAPI_Feature> aFeature =
559 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
560 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
561 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
566 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setVertical(
567 const ModelHighAPI_RefAttr & theLine)
569 std::shared_ptr<ModelAPI_Feature> aFeature =
570 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
571 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
576 //--------------------------------------------------------------------------------------
578 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
580 FeaturePtr aBase = feature();
581 const std::string& aDocName = theDumper.name(aBase->document());
583 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
584 if (anExternal->value()) {
585 FeaturePtr aPlnFeature = ModelAPI_Feature::feature(anExternal->context()->data()->owner());
586 const std::string& aPlaneName = theDumper.name(aPlnFeature);
587 theDumper << aBase << " = model.addSketch(" << aDocName << ", \"" << aPlaneName << "\")" << std::endl;
589 // Sketch is base on a plane.
590 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
591 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
592 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
593 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
594 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
595 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
597 // Check the plane is coordinate plane
598 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
599 if (aPlaneName.empty()) {
600 // needs import additional module
601 theDumper.importModule("GeomAPI");
602 // dump plane parameters
603 const std::string& aSketchName = theDumper.name(aBase);
604 std::string anOriginName = aSketchName + "_origin";
605 std::string aNormalName = aSketchName + "_norm";
606 std::string aDirXName = aSketchName + "_dirx";
607 theDumper << anOriginName << " = " << anOrigin << std::endl
608 << aNormalName << " = " << aNormal << std::endl
609 << aDirXName << " = " << aDirX << std::endl;
610 // dump sketch based on arbitrary plane
611 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
612 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
614 // dump sketch based on coordinate plane
615 theDumper << aBase << " = model.addSketch(" << aDocName
616 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;