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_Trim.h>
28 #include <SketchPlugin_ConstraintTangent.h>
29 #include <SketchPlugin_ConstraintVertical.h>
30 #include <SketcherPrs_Tools.h>
31 //--------------------------------------------------------------------------------------
32 #include <ModelAPI_CompositeFeature.h>
33 #include <ModelAPI_ResultConstruction.h>
34 #include <ModelHighAPI_Dumper.h>
35 #include <ModelHighAPI_RefAttr.h>
36 #include <ModelHighAPI_Selection.h>
37 #include <ModelHighAPI_Services.h>
38 #include <ModelHighAPI_Tools.h>
39 //--------------------------------------------------------------------------------------
40 #include "SketchAPI_Arc.h"
41 #include "SketchAPI_Circle.h"
42 #include "SketchAPI_IntersectionPoint.h"
43 #include "SketchAPI_Line.h"
44 #include "SketchAPI_Mirror.h"
45 #include "SketchAPI_Point.h"
46 #include "SketchAPI_Projection.h"
47 #include "SketchAPI_Rectangle.h"
48 #include "SketchAPI_Rotation.h"
49 #include "SketchAPI_Translation.h"
50 //--------------------------------------------------------------------------------------
51 SketchAPI_Sketch::SketchAPI_Sketch(
52 const std::shared_ptr<ModelAPI_Feature> & theFeature)
53 : ModelHighAPI_Interface(theFeature)
58 SketchAPI_Sketch::SketchAPI_Sketch(
59 const std::shared_ptr<ModelAPI_Feature> & theFeature,
60 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
61 : ModelHighAPI_Interface(theFeature)
68 SketchAPI_Sketch::SketchAPI_Sketch(
69 const std::shared_ptr<ModelAPI_Feature> & theFeature,
70 const ModelHighAPI_Selection & theExternal)
71 : ModelHighAPI_Interface(theFeature)
74 setExternal(theExternal);
78 SketchAPI_Sketch::SketchAPI_Sketch(
79 const std::shared_ptr<ModelAPI_Feature> & theFeature,
80 std::shared_ptr<ModelAPI_Object> thePlaneObject)
81 : ModelHighAPI_Interface(theFeature)
84 setExternal(thePlaneObject);
88 SketchAPI_Sketch::~SketchAPI_Sketch()
93 //--------------------------------------------------------------------------------------
94 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
96 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
99 //--------------------------------------------------------------------------------------
100 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
102 fillAttribute(thePlane->origin(), myorigin);
103 fillAttribute(thePlane->dirX(), mydirX);
104 fillAttribute(thePlane->normal(), mynormal);
109 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
111 fillAttribute(theExternal, myexternal);
116 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
118 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
119 ModelHighAPI_Selection aSel(aRes);
123 //--------------------------------------------------------------------------------------
124 void SketchAPI_Sketch::setValue(
125 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
126 const ModelHighAPI_Double & theValue)
128 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
130 // theConstraint->execute();
133 //--------------------------------------------------------------------------------------
134 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
136 const_cast<SketchAPI_Sketch*>(this)->execute();
138 std::list<ModelHighAPI_Selection> aSelectionList;
140 ResultConstructionPtr aResultConstruction =
141 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
142 if (aResultConstruction.get() == NULL)
143 return aSelectionList;
145 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
146 aSelectionList.push_back(
147 ModelHighAPI_Selection(aResultConstruction,
148 aResultConstruction->face(anIndex)));
151 return aSelectionList;
154 //--------------------------------------------------------------------------------------
155 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
156 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
158 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
159 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
162 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
163 const ModelHighAPI_Selection & theExternal)
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 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
174 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 =
190 compositeFeature()->addFeature(SketchPlugin_Point::ID());
191 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
193 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
194 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
196 std::shared_ptr<ModelAPI_Feature> aFeature =
197 compositeFeature()->addFeature(SketchPlugin_Point::ID());
198 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
200 std::shared_ptr<SketchAPI_Point>
201 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
203 std::shared_ptr<ModelAPI_Feature> aFeature =
204 compositeFeature()->addFeature(SketchPlugin_Point::ID());
205 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
207 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
209 std::shared_ptr<ModelAPI_Feature> aFeature =
210 compositeFeature()->addFeature(SketchPlugin_Point::ID());
211 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
214 //--------------------------------------------------------------------------------------
215 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
216 const ModelHighAPI_Selection & theExternal)
218 std::shared_ptr<ModelAPI_Feature> aFeature =
219 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
220 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
222 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
223 const std::string & theExternalName)
225 std::shared_ptr<ModelAPI_Feature> aFeature =
226 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
227 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
230 //--------------------------------------------------------------------------------------
231 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
232 double theX2, double theY2)
234 std::shared_ptr<ModelAPI_Feature> aFeature =
235 compositeFeature()->addFeature(SketchPlugin_Line::ID());
236 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
238 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
239 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
240 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
242 std::shared_ptr<ModelAPI_Feature> aFeature =
243 compositeFeature()->addFeature(SketchPlugin_Line::ID());
244 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
246 std::shared_ptr<SketchAPI_Line>
247 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
249 std::shared_ptr<ModelAPI_Feature> aFeature =
250 compositeFeature()->addFeature(SketchPlugin_Line::ID());
251 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
253 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
255 std::shared_ptr<ModelAPI_Feature> aFeature =
256 compositeFeature()->addFeature(SketchPlugin_Line::ID());
257 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
260 //--------------------------------------------------------------------------------------
261 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
262 double theX2, double theY2)
264 std::shared_ptr<ModelAPI_Feature> aFeature =
265 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
266 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
268 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
269 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
270 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
272 std::shared_ptr<ModelAPI_Feature> aFeature =
273 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
274 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
277 //--------------------------------------------------------------------------------------
278 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
282 std::shared_ptr<ModelAPI_Feature> aFeature =
283 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
284 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
287 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
288 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
291 std::shared_ptr<ModelAPI_Feature> aFeature =
292 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
293 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
296 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
297 double theX2, double theY2,
298 double theX3, double theY3)
300 std::shared_ptr<ModelAPI_Feature> aFeature =
301 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
302 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
305 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
306 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
307 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
308 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
310 std::shared_ptr<ModelAPI_Feature> aFeature =
311 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
312 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
315 std::shared_ptr<SketchAPI_Circle>
316 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
318 std::shared_ptr<ModelAPI_Feature> aFeature =
319 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
320 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
323 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
325 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
326 std::shared_ptr<ModelAPI_Feature> aFeature =
327 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
328 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
331 //--------------------------------------------------------------------------------------
332 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
333 double theStartX, double theStartY,
334 double theEndX, double theEndY,
337 std::shared_ptr<ModelAPI_Feature> aFeature =
338 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
339 return ArcPtr(new SketchAPI_Arc(aFeature,
340 theCenterX, theCenterY,
341 theStartX, theStartY,
346 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
347 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
348 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
349 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
352 std::shared_ptr<ModelAPI_Feature> aFeature =
353 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
354 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
357 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
358 double theEndX, double theEndY,
359 double thePassedX, double thePassedY)
361 std::shared_ptr<ModelAPI_Feature> aFeature =
362 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
363 return ArcPtr(new SketchAPI_Arc(aFeature,
364 theStartX, theStartY,
366 thePassedX, thePassedY));
369 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
370 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
371 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
372 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
374 std::shared_ptr<ModelAPI_Feature> aFeature =
375 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
376 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
379 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
380 const ModelHighAPI_RefAttr& theTangentPoint,
381 double theEndX, double theEndY,
384 std::shared_ptr<ModelAPI_Feature> aFeature =
385 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
386 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
389 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
390 const ModelHighAPI_RefAttr& theTangentPoint,
391 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
394 std::shared_ptr<ModelAPI_Feature> aFeature =
395 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
396 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
399 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
401 std::shared_ptr<ModelAPI_Feature> aFeature =
402 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
403 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
406 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
408 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
409 std::shared_ptr<ModelAPI_Feature> aFeature =
410 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
411 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
414 //--------------------------------------------------------------------------------------
415 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
416 const ModelHighAPI_Selection & theExternalFeature)
418 std::shared_ptr<ModelAPI_Feature> aFeature =
419 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
420 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
423 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
424 const std::string & theExternalName)
426 std::shared_ptr<ModelAPI_Feature> aFeature =
427 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
428 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
431 //--------------------------------------------------------------------------------------
432 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
433 const ModelHighAPI_RefAttr & theMirrorLine,
434 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
436 std::shared_ptr<ModelAPI_Feature> aFeature =
437 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
438 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
441 //--------------------------------------------------------------------------------------
442 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
443 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
444 const ModelHighAPI_RefAttr & thePoint1,
445 const ModelHighAPI_RefAttr & thePoint2,
446 const ModelHighAPI_Integer & theNumberOfObjects,
449 std::shared_ptr<ModelAPI_Feature> aFeature =
450 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
451 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
452 thePoint2, theNumberOfObjects, theFullValue));
455 //--------------------------------------------------------------------------------------
456 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
457 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
458 const ModelHighAPI_RefAttr & theCenter,
459 const ModelHighAPI_Double & theAngle,
460 const ModelHighAPI_Integer & theNumberOfObjects,
463 std::shared_ptr<ModelAPI_Feature> aFeature =
464 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
466 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
467 theAngle, theNumberOfObjects, theFullValue));
470 //--------------------------------------------------------------------------------------
471 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
472 const ModelHighAPI_Reference& theFeature,
473 const ModelHighAPI_RefAttr& thePoint1,
474 const ModelHighAPI_RefAttr& thePoint2)
476 std::shared_ptr<ModelAPI_Feature> aFeature =
477 compositeFeature()->addFeature(SketchPlugin_ConstraintSplit::ID());
478 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Constraint::VALUE()));
479 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
480 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
481 //aFeature->execute();
482 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
485 //--------------------------------------------------------------------------------------
486 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
487 const ModelHighAPI_Reference& theFeature,
488 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
490 std::shared_ptr<ModelAPI_Feature> aFeature =
491 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
492 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::BASE_OBJECT()));
494 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::ENTITY_POINT());
495 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
496 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
497 fillAttribute(thePositionPoint, aPointAttr);
500 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
503 //--------------------------------------------------------------------------------------
504 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
505 const ModelHighAPI_RefAttr & theLine1,
506 const ModelHighAPI_RefAttr & theLine2,
507 const ModelHighAPI_Double & theValue)
509 std::shared_ptr<ModelAPI_Feature> aFeature =
510 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
511 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
512 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
513 // fill the value before llines to avoid calculation of angle value by the Angle feature
514 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
515 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
516 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
518 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
521 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
522 const ModelHighAPI_RefAttr & theLine1,
523 const ModelHighAPI_RefAttr & theLine2,
524 const ModelHighAPI_Double & theValue)
526 std::shared_ptr<ModelAPI_Feature> aFeature =
527 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
528 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
529 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
530 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
531 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
532 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
533 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
535 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
538 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
539 const ModelHighAPI_RefAttr & theLine1,
540 const ModelHighAPI_RefAttr & theLine2,
541 const ModelHighAPI_Double & theValue)
543 std::shared_ptr<ModelAPI_Feature> aFeature =
544 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
545 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
546 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
547 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
548 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
549 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
550 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
552 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
555 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
556 const ModelHighAPI_RefAttr & thePoint1,
557 const ModelHighAPI_RefAttr & thePoint2)
559 std::shared_ptr<ModelAPI_Feature> aFeature =
560 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
561 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
562 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
564 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
567 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
568 const ModelHighAPI_RefAttr & theLine1,
569 const ModelHighAPI_RefAttr & theLine2)
571 std::shared_ptr<ModelAPI_Feature> aFeature =
572 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
573 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
574 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
576 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
579 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
580 const ModelHighAPI_RefAttr & thePoint,
581 const ModelHighAPI_RefAttr & thePointOrLine,
582 const ModelHighAPI_Double & theValue)
584 std::shared_ptr<ModelAPI_Feature> aFeature =
585 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
586 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
587 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
588 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
590 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
593 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
594 const ModelHighAPI_RefAttr & theObject1,
595 const ModelHighAPI_RefAttr & theObject2)
597 std::shared_ptr<ModelAPI_Feature> aFeature =
598 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
599 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
600 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
602 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
605 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
606 const std::list<ModelHighAPI_RefAttr> & thePoints,
607 const ModelHighAPI_Double & theRadius)
609 std::shared_ptr<ModelAPI_Feature> aFeature =
610 compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID());
611 fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A()));
612 fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE()));
614 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
617 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
618 const ModelHighAPI_RefAttr & theObject)
620 std::shared_ptr<ModelAPI_Feature> aFeature =
621 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
622 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
624 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
627 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
628 const ModelHighAPI_RefAttr & theLine)
630 std::shared_ptr<ModelAPI_Feature> aFeature =
631 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
632 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
634 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
637 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
638 const ModelHighAPI_RefAttr & theLine,
639 const ModelHighAPI_Double & theValue)
641 std::shared_ptr<ModelAPI_Feature> aFeature =
642 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
643 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
644 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
646 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
649 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
650 const ModelHighAPI_RefAttr & thePoint,
651 const ModelHighAPI_RefAttr & theLine)
653 std::shared_ptr<ModelAPI_Feature> aFeature =
654 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
655 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
656 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
658 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
661 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
662 const ModelHighAPI_RefAttr & theLine1,
663 const ModelHighAPI_RefAttr & theLine2)
665 std::shared_ptr<ModelAPI_Feature> aFeature =
666 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
667 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
668 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
670 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
673 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
674 const ModelHighAPI_RefAttr & theLine1,
675 const ModelHighAPI_RefAttr & theLine2)
677 std::shared_ptr<ModelAPI_Feature> aFeature =
678 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
679 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
680 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
682 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
685 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
686 const ModelHighAPI_RefAttr & theCircleOrArc,
687 const ModelHighAPI_Double & theValue)
689 std::shared_ptr<ModelAPI_Feature> aFeature =
690 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
691 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
692 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
694 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
697 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
698 const ModelHighAPI_RefAttr & theLine,
699 const ModelHighAPI_RefAttr & theCircle)
701 std::shared_ptr<ModelAPI_Feature> aFeature =
702 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
703 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
704 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
706 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
709 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
710 const ModelHighAPI_RefAttr & theLine)
712 std::shared_ptr<ModelAPI_Feature> aFeature =
713 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
714 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
716 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
719 //--------------------------------------------------------------------------------------
721 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
723 FeaturePtr aBase = feature();
724 const std::string& aDocName = theDumper.name(aBase->document());
726 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
727 if (anExternal->value()) {
728 theDumper << aBase << " = model.addSketch(" << aDocName <<
729 ", " << anExternal << ")" << std::endl;
731 // Sketch is base on a plane.
732 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
733 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
734 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
735 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
736 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
737 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
739 // Check the plane is coordinate plane
740 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
741 if(anExternal->context()) { // checking for selected planes
742 if (!aPlaneName.empty()
743 && anExternal->context()->data()
744 && anExternal->context()->data()->name() == aPlaneName) {
745 // dump sketch based on coordinate plane
746 theDumper << aBase << " = model.addSketch(" << aDocName
747 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
748 } else { // some other plane
749 theDumper << aBase << " = model.addSketch(" << aDocName <<
750 ", " << anExternal<< ")" << std::endl;
753 if (aPlaneName.empty()) {
754 // needs import additional module
755 theDumper.importModule("GeomAPI");
756 // dump plane parameters
757 const std::string& aSketchName = theDumper.name(aBase);
758 std::string anOriginName = aSketchName + "_origin";
759 std::string aNormalName = aSketchName + "_norm";
760 std::string aDirXName = aSketchName + "_dirx";
761 // use "\n" instead of std::endl to avoid automatic dumping sketch here
762 // and then dumplicate dumping it in the next line
763 theDumper << anOriginName << " = " << anOrigin << "\n"
764 << aNormalName << " = " << aNormal << "\n"
765 << aDirXName << " = " << aDirX << "\n";
766 // dump sketch based on arbitrary plane
767 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
768 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
770 // dump sketch based on coordinate plane
771 theDumper << aBase << " = model.addSketch(" << aDocName
772 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
777 // dump sketch's subfeatures
778 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
779 theDumper.processSubs(aCompFeat, true);