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()
80 //--------------------------------------------------------------------------------------
81 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
83 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
86 //--------------------------------------------------------------------------------------
87 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
89 fillAttribute(thePlane->origin(), myorigin);
90 fillAttribute(thePlane->dirX(), mydirX);
91 fillAttribute(thePlane->normal(), mynormal);
96 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
98 fillAttribute(theExternal, myexternal);
103 //--------------------------------------------------------------------------------------
104 void SketchAPI_Sketch::setValue(
105 const std::shared_ptr<ModelAPI_Feature> & theConstraint,
106 const ModelHighAPI_Double & theValue)
108 // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
109 fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
111 // theConstraint->execute();
114 //--------------------------------------------------------------------------------------
115 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
117 const_cast<SketchAPI_Sketch*>(this)->execute();
119 std::list<ModelHighAPI_Selection> aSelectionList;
121 ResultConstructionPtr aResultConstruction =
122 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
123 if (aResultConstruction.get() == NULL)
124 return aSelectionList;
126 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
127 aSelectionList.push_back(
128 ModelHighAPI_Selection(aResultConstruction,
129 aResultConstruction->face(anIndex)));
132 return aSelectionList;
135 //--------------------------------------------------------------------------------------
136 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
137 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
139 // TODO(spo): check that thePart is not empty
140 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
141 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
144 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
145 const ModelHighAPI_Selection & theExternal)
147 // TODO(spo): check that thePart is not empty
148 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
149 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
152 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
153 const std::string & theExternalName)
155 // TODO(spo): check that thePart is not empty
156 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
157 return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
160 //--------------------------------------------------------------------------------------
161 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
162 double theX, double theY)
164 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
165 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
167 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
168 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
170 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
171 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
173 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
175 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
176 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
178 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
180 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
181 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
184 //--------------------------------------------------------------------------------------
185 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
186 const ModelHighAPI_Selection & theExternal)
188 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
189 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
191 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
192 const std::string & theExternalName)
194 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
195 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
198 //--------------------------------------------------------------------------------------
199 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
201 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
202 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
204 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
205 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
206 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
208 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
209 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
211 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
213 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
214 LinePtr aLine(new SketchAPI_Line(aFeature, theExternal));
215 setFixed(InterfacePtr(aLine));
218 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
220 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
221 LinePtr aLine(new SketchAPI_Line(aFeature, theExternalName));
222 setFixed(InterfacePtr(aLine));
226 //--------------------------------------------------------------------------------------
227 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
229 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
230 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
232 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
233 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
234 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
236 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
237 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
240 //--------------------------------------------------------------------------------------
241 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
245 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
246 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
249 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
252 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
253 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
256 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
257 double theX2, double theY2,
258 double theX3, double theY3)
260 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
261 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
264 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
265 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
266 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
268 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
269 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
272 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
274 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
275 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
278 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
280 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
281 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
282 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
285 //--------------------------------------------------------------------------------------
286 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
287 double theStartX, double theStartY,
288 double theEndX, double theEndY,
291 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
292 return ArcPtr(new SketchAPI_Arc(aFeature,
293 theCenterX, theCenterY,
294 theStartX, theStartY,
299 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
300 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
301 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
304 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
305 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
308 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
309 double theEndX, double theEndY,
310 double thePassedX, double thePassedY)
312 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
313 return ArcPtr(new SketchAPI_Arc(aFeature,
314 theStartX, theStartY,
316 thePassedX, thePassedY));
319 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
320 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
321 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
323 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
324 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
327 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
328 double theEndX, double theEndY,
331 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
332 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
335 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_RefAttr& theTangentPoint,
336 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
339 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
340 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
343 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
345 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
346 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
349 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
351 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
352 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID());
353 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
356 //--------------------------------------------------------------------------------------
357 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
358 const ModelHighAPI_Selection & theExternalFeature)
360 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
361 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
364 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
365 const std::string & theExternalName)
367 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Projection::ID());
368 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
371 //--------------------------------------------------------------------------------------
372 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
373 const ModelHighAPI_RefAttr & theMirrorLine,
374 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
376 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
377 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
380 //--------------------------------------------------------------------------------------
381 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
382 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
383 const ModelHighAPI_RefAttr & thePoint1,
384 const ModelHighAPI_RefAttr & thePoint2,
385 const ModelHighAPI_Integer & theNumberOfObjects,
388 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
389 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1, thePoint2, theNumberOfObjects, theFullValue));
392 //--------------------------------------------------------------------------------------
393 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
394 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
395 const ModelHighAPI_RefAttr & theCenter,
396 const ModelHighAPI_Double & theAngle,
397 const ModelHighAPI_Integer & theNumberOfObjects,
400 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
401 return RotationPtr(new SketchAPI_Rotation(aFeature, theObjects, theCenter, theAngle, theNumberOfObjects, theFullValue));
404 //--------------------------------------------------------------------------------------
405 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
406 const ModelHighAPI_RefAttr & theLine1,
407 const ModelHighAPI_RefAttr & theLine2,
408 const ModelHighAPI_Double & theValue)
410 std::shared_ptr<ModelAPI_Feature> aFeature =
411 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
412 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
413 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
414 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
415 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
416 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
421 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleComplementary(
422 const ModelHighAPI_RefAttr & theLine1,
423 const ModelHighAPI_RefAttr & theLine2,
424 const ModelHighAPI_Double & theValue)
426 std::shared_ptr<ModelAPI_Feature> aFeature =
427 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
428 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
429 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
430 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
431 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
432 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
433 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
438 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleBackward(
439 const ModelHighAPI_RefAttr & theLine1,
440 const ModelHighAPI_RefAttr & theLine2,
441 const ModelHighAPI_Double & theValue)
443 std::shared_ptr<ModelAPI_Feature> aFeature =
444 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
445 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
446 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
447 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
448 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
449 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
450 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
455 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
456 const ModelHighAPI_RefAttr & thePoint1,
457 const ModelHighAPI_RefAttr & thePoint2)
459 std::shared_ptr<ModelAPI_Feature> aFeature =
460 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
461 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
462 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
467 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCollinear(
468 const ModelHighAPI_RefAttr & theLine1,
469 const ModelHighAPI_RefAttr & theLine2)
471 std::shared_ptr<ModelAPI_Feature> aFeature =
472 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
473 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
474 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
479 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
480 const ModelHighAPI_RefAttr & thePoint,
481 const ModelHighAPI_RefAttr & thePointOrLine,
482 const ModelHighAPI_Double & theValue)
484 std::shared_ptr<ModelAPI_Feature> aFeature =
485 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
486 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
487 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
488 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
493 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setEqual(
494 const ModelHighAPI_RefAttr & theObject1,
495 const ModelHighAPI_RefAttr & theObject2)
497 std::shared_ptr<ModelAPI_Feature> aFeature =
498 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
499 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
500 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
505 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFillet(
506 const std::list<ModelHighAPI_RefAttr> & thePoints,
507 const ModelHighAPI_Double & theRadius)
509 std::shared_ptr<ModelAPI_Feature> aFeature =
510 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
511 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
512 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
517 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setFixed(
518 const ModelHighAPI_RefAttr & theObject)
520 std::shared_ptr<ModelAPI_Feature> aFeature =
521 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
522 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
527 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setHorizontal(
528 const ModelHighAPI_RefAttr & theLine)
530 std::shared_ptr<ModelAPI_Feature> aFeature =
531 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
532 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
537 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
538 const ModelHighAPI_RefAttr & theLine,
539 const ModelHighAPI_Double & theValue)
541 std::shared_ptr<ModelAPI_Feature> aFeature =
542 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
543 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
544 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
549 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setMiddlePoint(
550 const ModelHighAPI_RefAttr & thePoint,
551 const ModelHighAPI_RefAttr & theLine)
553 std::shared_ptr<ModelAPI_Feature> aFeature =
554 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
555 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
556 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
561 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
562 const ModelHighAPI_RefAttr & theLine1,
563 const ModelHighAPI_RefAttr & theLine2)
565 std::shared_ptr<ModelAPI_Feature> aFeature =
566 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
567 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
568 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
573 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
574 const ModelHighAPI_RefAttr & theLine1,
575 const ModelHighAPI_RefAttr & theLine2)
577 std::shared_ptr<ModelAPI_Feature> aFeature =
578 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
579 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
580 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
585 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setRadius(
586 const ModelHighAPI_RefAttr & theCircleOrArc,
587 const ModelHighAPI_Double & theValue)
589 std::shared_ptr<ModelAPI_Feature> aFeature =
590 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
591 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
592 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
597 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setTangent(
598 const ModelHighAPI_RefAttr & theLine,
599 const ModelHighAPI_RefAttr & theCircle)
601 std::shared_ptr<ModelAPI_Feature> aFeature =
602 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
603 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
604 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
609 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setVertical(
610 const ModelHighAPI_RefAttr & theLine)
612 std::shared_ptr<ModelAPI_Feature> aFeature =
613 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
614 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
619 //--------------------------------------------------------------------------------------
621 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
623 FeaturePtr aBase = feature();
624 const std::string& aDocName = theDumper.name(aBase->document());
626 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
627 if (anExternal->value()) {
628 theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal << ")" << std::endl;
630 // Sketch is base on a plane.
631 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
632 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
633 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
634 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
635 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
636 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
638 // Check the plane is coordinate plane
639 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
640 if (aPlaneName.empty()) {
641 // needs import additional module
642 theDumper.importModule("GeomAPI");
643 // dump plane parameters
644 const std::string& aSketchName = theDumper.name(aBase);
645 std::string anOriginName = aSketchName + "_origin";
646 std::string aNormalName = aSketchName + "_norm";
647 std::string aDirXName = aSketchName + "_dirx";
648 theDumper << anOriginName << " = " << anOrigin << std::endl
649 << aNormalName << " = " << aNormal << std::endl
650 << aDirXName << " = " << aDirX << std::endl;
651 // dump sketch based on arbitrary plane
652 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
653 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
655 // dump sketch based on coordinate plane
656 theDumper << aBase << " = model.addSketch(" << aDocName
657 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;