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_Fillet.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_Double.h>
35 #include <ModelHighAPI_Dumper.h>
36 #include <ModelHighAPI_RefAttr.h>
37 #include <ModelHighAPI_Selection.h>
38 #include <ModelHighAPI_Services.h>
39 #include <ModelHighAPI_Tools.h>
40 //--------------------------------------------------------------------------------------
41 #include "SketchAPI_Arc.h"
42 #include "SketchAPI_Circle.h"
43 #include "SketchAPI_IntersectionPoint.h"
44 #include "SketchAPI_Line.h"
45 #include "SketchAPI_MacroCircle.h"
46 #include "SketchAPI_Mirror.h"
47 #include "SketchAPI_Point.h"
48 #include "SketchAPI_Projection.h"
49 #include "SketchAPI_Rectangle.h"
50 #include "SketchAPI_Rotation.h"
51 #include "SketchAPI_Translation.h"
52 //--------------------------------------------------------------------------------------
53 SketchAPI_Sketch::SketchAPI_Sketch(
54 const std::shared_ptr<ModelAPI_Feature> & theFeature)
55 : ModelHighAPI_Interface(theFeature)
60 SketchAPI_Sketch::SketchAPI_Sketch(
61 const std::shared_ptr<ModelAPI_Feature> & theFeature,
62 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
63 : ModelHighAPI_Interface(theFeature)
70 SketchAPI_Sketch::SketchAPI_Sketch(
71 const std::shared_ptr<ModelAPI_Feature> & theFeature,
72 const ModelHighAPI_Selection & theExternal)
73 : ModelHighAPI_Interface(theFeature)
76 setExternal(theExternal);
80 SketchAPI_Sketch::SketchAPI_Sketch(
81 const std::shared_ptr<ModelAPI_Feature> & theFeature,
82 std::shared_ptr<ModelAPI_Object> thePlaneObject)
83 : ModelHighAPI_Interface(theFeature)
86 setExternal(thePlaneObject);
90 SketchAPI_Sketch::~SketchAPI_Sketch()
95 //--------------------------------------------------------------------------------------
96 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
98 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
101 //--------------------------------------------------------------------------------------
102 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
104 fillAttribute(thePlane->origin(), myorigin);
105 fillAttribute(thePlane->dirX(), mydirX);
106 fillAttribute(thePlane->normal(), mynormal);
111 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
113 fillAttribute(theExternal, myexternal);
118 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
120 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
121 ModelHighAPI_Selection aSel(aRes);
125 //--------------------------------------------------------------------------------------
126 void SketchAPI_Sketch::setValue(
127 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
128 const ModelHighAPI_Double & theValue)
130 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
132 // theConstraint->execute();
135 //--------------------------------------------------------------------------------------
136 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
138 const_cast<SketchAPI_Sketch*>(this)->execute();
140 std::list<ModelHighAPI_Selection> aSelectionList;
142 ResultConstructionPtr aResultConstruction =
143 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
144 if (aResultConstruction.get() == NULL)
145 return aSelectionList;
147 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
148 aSelectionList.push_back(
149 ModelHighAPI_Selection(aResultConstruction,
150 aResultConstruction->face(anIndex)));
153 return aSelectionList;
156 //--------------------------------------------------------------------------------------
157 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
158 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
160 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
161 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
164 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
165 const ModelHighAPI_Selection & theExternal)
167 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
168 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
171 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
172 const std::string & theExternalName)
174 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
176 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
179 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
180 std::shared_ptr<ModelAPI_Object> thePlaneObject)
182 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
183 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
187 //--------------------------------------------------------------------------------------
188 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
189 double theX, double theY)
191 std::shared_ptr<ModelAPI_Feature> aFeature =
192 compositeFeature()->addFeature(SketchPlugin_Point::ID());
193 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
195 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
196 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
198 std::shared_ptr<ModelAPI_Feature> aFeature =
199 compositeFeature()->addFeature(SketchPlugin_Point::ID());
200 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
202 std::shared_ptr<SketchAPI_Point>
203 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
205 std::shared_ptr<ModelAPI_Feature> aFeature =
206 compositeFeature()->addFeature(SketchPlugin_Point::ID());
207 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
209 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
211 std::shared_ptr<ModelAPI_Feature> aFeature =
212 compositeFeature()->addFeature(SketchPlugin_Point::ID());
213 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
216 //--------------------------------------------------------------------------------------
217 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
218 const ModelHighAPI_Selection & theExternal)
220 std::shared_ptr<ModelAPI_Feature> aFeature =
221 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
222 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
224 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
225 const std::string & theExternalName)
227 std::shared_ptr<ModelAPI_Feature> aFeature =
228 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
229 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
232 //--------------------------------------------------------------------------------------
233 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
234 double theX2, double theY2)
236 std::shared_ptr<ModelAPI_Feature> aFeature =
237 compositeFeature()->addFeature(SketchPlugin_Line::ID());
238 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
240 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
241 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
242 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
244 std::shared_ptr<ModelAPI_Feature> aFeature =
245 compositeFeature()->addFeature(SketchPlugin_Line::ID());
246 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
248 std::shared_ptr<SketchAPI_Line>
249 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
251 std::shared_ptr<ModelAPI_Feature> aFeature =
252 compositeFeature()->addFeature(SketchPlugin_Line::ID());
253 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
255 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
257 std::shared_ptr<ModelAPI_Feature> aFeature =
258 compositeFeature()->addFeature(SketchPlugin_Line::ID());
259 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
262 //--------------------------------------------------------------------------------------
263 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
264 double theX2, double theY2)
266 std::shared_ptr<ModelAPI_Feature> aFeature =
267 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
268 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
270 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
271 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
272 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
274 std::shared_ptr<ModelAPI_Feature> aFeature =
275 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
276 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
279 //--------------------------------------------------------------------------------------
280 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
284 std::shared_ptr<ModelAPI_Feature> aFeature =
285 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
286 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
289 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
290 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
293 std::shared_ptr<ModelAPI_Feature> aFeature =
294 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
295 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
298 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
303 std::shared_ptr<ModelAPI_Feature> aFeature =
304 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
305 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
306 thePassedX, thePassedY));
309 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
310 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
311 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
313 std::shared_ptr<ModelAPI_Feature> aFeature =
314 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
315 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
318 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
319 double theX2, double theY2,
320 double theX3, double theY3)
322 std::shared_ptr<ModelAPI_Feature> aFeature =
323 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
324 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
329 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
330 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
331 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
332 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
334 std::shared_ptr<ModelAPI_Feature> aFeature =
335 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
336 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
339 std::shared_ptr<SketchAPI_Circle>
340 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
342 std::shared_ptr<ModelAPI_Feature> aFeature =
343 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
344 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
347 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
349 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
350 std::shared_ptr<ModelAPI_Feature> aFeature =
351 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
352 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
355 //--------------------------------------------------------------------------------------
356 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
357 double theStartX, double theStartY,
358 double theEndX, double theEndY,
361 std::shared_ptr<ModelAPI_Feature> aFeature =
362 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
363 return ArcPtr(new SketchAPI_Arc(aFeature,
364 theCenterX, theCenterY,
365 theStartX, theStartY,
370 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
371 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
372 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
373 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
376 std::shared_ptr<ModelAPI_Feature> aFeature =
377 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
378 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
381 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
382 double theEndX, double theEndY,
383 double thePassedX, double thePassedY)
385 std::shared_ptr<ModelAPI_Feature> aFeature =
386 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
387 return ArcPtr(new SketchAPI_Arc(aFeature,
388 theStartX, theStartY,
390 thePassedX, thePassedY));
393 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
394 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
395 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
396 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
398 std::shared_ptr<ModelAPI_Feature> aFeature =
399 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
400 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
403 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
404 const ModelHighAPI_RefAttr& theTangentPoint,
405 double theEndX, double theEndY,
408 std::shared_ptr<ModelAPI_Feature> aFeature =
409 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
410 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
413 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
414 const ModelHighAPI_RefAttr& theTangentPoint,
415 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
418 std::shared_ptr<ModelAPI_Feature> aFeature =
419 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
420 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
423 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
425 std::shared_ptr<ModelAPI_Feature> aFeature =
426 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
427 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
430 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
432 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
433 std::shared_ptr<ModelAPI_Feature> aFeature =
434 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
435 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
438 //--------------------------------------------------------------------------------------
439 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
440 const ModelHighAPI_Selection & theExternalFeature)
442 std::shared_ptr<ModelAPI_Feature> aFeature =
443 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
444 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
447 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
448 const std::string & theExternalName)
450 std::shared_ptr<ModelAPI_Feature> aFeature =
451 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
452 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
455 //--------------------------------------------------------------------------------------
456 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
457 const ModelHighAPI_RefAttr & theMirrorLine,
458 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
460 std::shared_ptr<ModelAPI_Feature> aFeature =
461 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
462 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
465 //--------------------------------------------------------------------------------------
466 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
467 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
468 const ModelHighAPI_RefAttr & thePoint1,
469 const ModelHighAPI_RefAttr & thePoint2,
470 const ModelHighAPI_Integer & theNumberOfObjects,
473 std::shared_ptr<ModelAPI_Feature> aFeature =
474 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
475 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
476 thePoint2, theNumberOfObjects, theFullValue));
479 //--------------------------------------------------------------------------------------
480 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
481 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
482 const ModelHighAPI_RefAttr & theCenter,
483 const ModelHighAPI_Double & theAngle,
484 const ModelHighAPI_Integer & theNumberOfObjects,
487 std::shared_ptr<ModelAPI_Feature> aFeature =
488 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
490 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
491 theAngle, theNumberOfObjects, theFullValue));
494 //--------------------------------------------------------------------------------------
495 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
496 const ModelHighAPI_Reference& theFeature,
497 const ModelHighAPI_RefAttr& thePoint1,
498 const ModelHighAPI_RefAttr& thePoint2)
500 std::shared_ptr<ModelAPI_Feature> aFeature =
501 compositeFeature()->addFeature(SketchPlugin_ConstraintSplit::ID());
502 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Constraint::VALUE()));
503 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
504 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
505 //aFeature->execute();
506 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
509 //--------------------------------------------------------------------------------------
510 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
511 const ModelHighAPI_Reference& theFeature,
512 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
514 std::shared_ptr<ModelAPI_Feature> aFeature =
515 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
516 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
518 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
519 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
520 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
521 fillAttribute(thePositionPoint, aPointAttr);
524 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
527 //--------------------------------------------------------------------------------------
528 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
529 const ModelHighAPI_RefAttr & theLine1,
530 const ModelHighAPI_RefAttr & theLine2,
531 const ModelHighAPI_Double & theValue)
533 std::shared_ptr<ModelAPI_Feature> aFeature =
534 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
535 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
536 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
537 // fill the value before llines to avoid calculation of angle value by the Angle feature
538 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
539 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
540 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
542 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
545 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
546 const ModelHighAPI_RefAttr & theLine1,
547 const ModelHighAPI_RefAttr & theLine2,
548 const ModelHighAPI_Double & theValue)
550 std::shared_ptr<ModelAPI_Feature> aFeature =
551 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
552 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
553 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
554 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
555 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
556 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
557 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
559 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
562 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
563 const ModelHighAPI_RefAttr & theLine1,
564 const ModelHighAPI_RefAttr & theLine2,
565 const ModelHighAPI_Double & theValue)
567 std::shared_ptr<ModelAPI_Feature> aFeature =
568 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
569 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
570 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
571 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
572 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
573 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
574 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
576 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
579 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
580 const ModelHighAPI_RefAttr & thePoint1,
581 const ModelHighAPI_RefAttr & thePoint2)
583 std::shared_ptr<ModelAPI_Feature> aFeature =
584 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
585 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
586 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
588 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
591 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
592 const ModelHighAPI_RefAttr & theLine1,
593 const ModelHighAPI_RefAttr & theLine2)
595 std::shared_ptr<ModelAPI_Feature> aFeature =
596 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
597 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
598 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
600 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
603 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
604 const ModelHighAPI_RefAttr & thePoint,
605 const ModelHighAPI_RefAttr & thePointOrLine,
606 const ModelHighAPI_Double & theValue)
608 std::shared_ptr<ModelAPI_Feature> aFeature =
609 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
610 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
611 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
612 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
614 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
617 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
618 const ModelHighAPI_RefAttr & theObject1,
619 const ModelHighAPI_RefAttr & theObject2)
621 std::shared_ptr<ModelAPI_Feature> aFeature =
622 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
623 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
624 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
626 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
629 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
630 const ModelHighAPI_RefAttr & thePoint)
632 std::shared_ptr<ModelAPI_Feature> aFeature =
633 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
634 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
635 apply(); // finish operation to remove Fillet feature correcly
636 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
639 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
640 const ModelHighAPI_RefAttr & thePoint,
641 const ModelHighAPI_Double & theRadius)
643 CompositeFeaturePtr aSketch = compositeFeature();
644 int aNbSubs = aSketch->numberOfSubs();
647 InterfacePtr aFilletFeature = setFillet(thePoint);
649 // set radius for just created arc
650 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
651 if (anArc->getKind() == SketchPlugin_Arc::ID())
652 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
654 return aFilletFeature;
657 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
658 const ModelHighAPI_RefAttr & theObject)
660 std::shared_ptr<ModelAPI_Feature> aFeature =
661 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
662 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
664 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
667 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
668 const ModelHighAPI_RefAttr & theLine)
670 std::shared_ptr<ModelAPI_Feature> aFeature =
671 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
672 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
674 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
677 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
678 const ModelHighAPI_RefAttr & theLine,
679 const ModelHighAPI_Double & theValue)
681 std::shared_ptr<ModelAPI_Feature> aFeature =
682 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
683 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
684 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
686 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
689 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
690 const ModelHighAPI_RefAttr & thePoint,
691 const ModelHighAPI_RefAttr & theLine)
693 std::shared_ptr<ModelAPI_Feature> aFeature =
694 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
695 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
696 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
698 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
701 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
702 const ModelHighAPI_RefAttr & theLine1,
703 const ModelHighAPI_RefAttr & theLine2)
705 std::shared_ptr<ModelAPI_Feature> aFeature =
706 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
707 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
708 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
710 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
713 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
714 const ModelHighAPI_RefAttr & theLine1,
715 const ModelHighAPI_RefAttr & theLine2)
717 std::shared_ptr<ModelAPI_Feature> aFeature =
718 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
719 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
720 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
722 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
725 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
726 const ModelHighAPI_RefAttr & theCircleOrArc,
727 const ModelHighAPI_Double & theValue)
729 std::shared_ptr<ModelAPI_Feature> aFeature =
730 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
731 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
732 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
734 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
737 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
738 const ModelHighAPI_RefAttr & theLine,
739 const ModelHighAPI_RefAttr & theCircle)
741 std::shared_ptr<ModelAPI_Feature> aFeature =
742 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
743 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
744 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
746 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
749 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
750 const ModelHighAPI_RefAttr & theLine)
752 std::shared_ptr<ModelAPI_Feature> aFeature =
753 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
754 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
756 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
759 //--------------------------------------------------------------------------------------
761 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
763 FeaturePtr aBase = feature();
764 const std::string& aDocName = theDumper.name(aBase->document());
766 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
767 if (anExternal->value()) {
768 theDumper << aBase << " = model.addSketch(" << aDocName <<
769 ", " << anExternal << ")" << std::endl;
771 // Sketch is base on a plane.
772 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
773 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
774 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
775 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
776 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
777 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
779 // Check the plane is coordinate plane
780 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
781 if(anExternal->context()) { // checking for selected planes
782 if (!aPlaneName.empty()
783 && anExternal->context()->data()
784 && anExternal->context()->data()->name() == aPlaneName) {
785 // dump sketch based on coordinate plane
786 theDumper << aBase << " = model.addSketch(" << aDocName
787 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
788 } else { // some other plane
789 theDumper << aBase << " = model.addSketch(" << aDocName <<
790 ", " << anExternal<< ")" << std::endl;
793 if (aPlaneName.empty()) {
794 // needs import additional module
795 theDumper.importModule("GeomAPI");
796 // dump plane parameters
797 const std::string& aSketchName = theDumper.name(aBase);
798 std::string anOriginName = aSketchName + "_origin";
799 std::string aNormalName = aSketchName + "_norm";
800 std::string aDirXName = aSketchName + "_dirx";
801 // use "\n" instead of std::endl to avoid automatic dumping sketch here
802 // and then dumplicate dumping it in the next line
803 theDumper << anOriginName << " = " << anOrigin << "\n"
804 << aNormalName << " = " << aNormal << "\n"
805 << aDirXName << " = " << aDirX << "\n";
806 // dump sketch based on arbitrary plane
807 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
808 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
810 // dump sketch based on coordinate plane
811 theDumper << aBase << " = model.addSketch(" << aDocName
812 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
817 // dump sketch's subfeatures
818 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
819 theDumper.processSubs(aCompFeat, true);