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_MacroArc.h"
43 #include "SketchAPI_Circle.h"
44 #include "SketchAPI_IntersectionPoint.h"
45 #include "SketchAPI_Line.h"
46 #include "SketchAPI_MacroCircle.h"
47 #include "SketchAPI_Mirror.h"
48 #include "SketchAPI_Point.h"
49 #include "SketchAPI_Projection.h"
50 #include "SketchAPI_Rectangle.h"
51 #include "SketchAPI_Rotation.h"
52 #include "SketchAPI_Translation.h"
53 //--------------------------------------------------------------------------------------
54 SketchAPI_Sketch::SketchAPI_Sketch(
55 const std::shared_ptr<ModelAPI_Feature> & theFeature)
56 : ModelHighAPI_Interface(theFeature)
61 SketchAPI_Sketch::SketchAPI_Sketch(
62 const std::shared_ptr<ModelAPI_Feature> & theFeature,
63 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
64 : ModelHighAPI_Interface(theFeature)
71 SketchAPI_Sketch::SketchAPI_Sketch(
72 const std::shared_ptr<ModelAPI_Feature> & theFeature,
73 const ModelHighAPI_Selection & theExternal)
74 : ModelHighAPI_Interface(theFeature)
77 setExternal(theExternal);
81 SketchAPI_Sketch::SketchAPI_Sketch(
82 const std::shared_ptr<ModelAPI_Feature> & theFeature,
83 std::shared_ptr<ModelAPI_Object> thePlaneObject)
84 : ModelHighAPI_Interface(theFeature)
87 setExternal(thePlaneObject);
91 SketchAPI_Sketch::~SketchAPI_Sketch()
96 //--------------------------------------------------------------------------------------
97 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
99 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
102 //--------------------------------------------------------------------------------------
103 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
105 fillAttribute(thePlane->origin(), myorigin);
106 fillAttribute(thePlane->dirX(), mydirX);
107 fillAttribute(thePlane->normal(), mynormal);
112 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
114 fillAttribute(theExternal, myexternal);
119 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
121 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
122 ModelHighAPI_Selection aSel(aRes);
126 //--------------------------------------------------------------------------------------
127 void SketchAPI_Sketch::setValue(
128 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
129 const ModelHighAPI_Double & theValue)
131 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
133 // theConstraint->execute();
136 //--------------------------------------------------------------------------------------
137 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
139 const_cast<SketchAPI_Sketch*>(this)->execute();
141 std::list<ModelHighAPI_Selection> aSelectionList;
143 ResultConstructionPtr aResultConstruction =
144 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
145 if (aResultConstruction.get() == NULL)
146 return aSelectionList;
148 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
149 aSelectionList.push_back(
150 ModelHighAPI_Selection(aResultConstruction,
151 aResultConstruction->face(anIndex)));
154 return aSelectionList;
157 //--------------------------------------------------------------------------------------
158 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
159 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
161 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
162 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
165 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
166 const ModelHighAPI_Selection & theExternal)
168 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
169 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
172 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
173 const std::string & theExternalName)
175 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
177 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
180 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
181 std::shared_ptr<ModelAPI_Object> thePlaneObject)
183 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
184 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
188 //--------------------------------------------------------------------------------------
189 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
190 double theX, double theY)
192 std::shared_ptr<ModelAPI_Feature> aFeature =
193 compositeFeature()->addFeature(SketchPlugin_Point::ID());
194 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
196 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
197 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
199 std::shared_ptr<ModelAPI_Feature> aFeature =
200 compositeFeature()->addFeature(SketchPlugin_Point::ID());
201 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
203 std::shared_ptr<SketchAPI_Point>
204 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
206 std::shared_ptr<ModelAPI_Feature> aFeature =
207 compositeFeature()->addFeature(SketchPlugin_Point::ID());
208 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
210 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
212 std::shared_ptr<ModelAPI_Feature> aFeature =
213 compositeFeature()->addFeature(SketchPlugin_Point::ID());
214 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
217 //--------------------------------------------------------------------------------------
218 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
219 const ModelHighAPI_Selection & theExternal)
221 std::shared_ptr<ModelAPI_Feature> aFeature =
222 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
223 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
225 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
226 const std::string & theExternalName)
228 std::shared_ptr<ModelAPI_Feature> aFeature =
229 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
230 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
233 //--------------------------------------------------------------------------------------
234 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
235 double theX2, double theY2)
237 std::shared_ptr<ModelAPI_Feature> aFeature =
238 compositeFeature()->addFeature(SketchPlugin_Line::ID());
239 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
241 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
242 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
243 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
245 std::shared_ptr<ModelAPI_Feature> aFeature =
246 compositeFeature()->addFeature(SketchPlugin_Line::ID());
247 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
249 std::shared_ptr<SketchAPI_Line>
250 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
252 std::shared_ptr<ModelAPI_Feature> aFeature =
253 compositeFeature()->addFeature(SketchPlugin_Line::ID());
254 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
256 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
258 std::shared_ptr<ModelAPI_Feature> aFeature =
259 compositeFeature()->addFeature(SketchPlugin_Line::ID());
260 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
263 //--------------------------------------------------------------------------------------
264 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
265 double theX2, double theY2)
267 std::shared_ptr<ModelAPI_Feature> aFeature =
268 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
269 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
271 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
272 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
273 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
275 std::shared_ptr<ModelAPI_Feature> aFeature =
276 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
277 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
280 //--------------------------------------------------------------------------------------
281 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
285 std::shared_ptr<ModelAPI_Feature> aFeature =
286 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
287 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
290 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
291 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
294 std::shared_ptr<ModelAPI_Feature> aFeature =
295 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
296 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
299 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
304 std::shared_ptr<ModelAPI_Feature> aFeature =
305 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
306 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
307 thePassedX, thePassedY));
310 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
311 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
312 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
314 std::shared_ptr<ModelAPI_Feature> aFeature =
315 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
316 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
319 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
320 double theX2, double theY2,
321 double theX3, double theY3)
323 std::shared_ptr<ModelAPI_Feature> aFeature =
324 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
325 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
330 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
331 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
332 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
333 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
335 std::shared_ptr<ModelAPI_Feature> aFeature =
336 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
337 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
340 std::shared_ptr<SketchAPI_Circle>
341 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
343 std::shared_ptr<ModelAPI_Feature> aFeature =
344 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
345 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
348 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
350 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
351 std::shared_ptr<ModelAPI_Feature> aFeature =
352 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
353 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
356 //--------------------------------------------------------------------------------------
357 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
358 double theStartX, double theStartY,
359 double theEndX, double theEndY,
362 std::shared_ptr<ModelAPI_Feature> aFeature =
363 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
364 return ArcPtr(new SketchAPI_Arc(aFeature,
365 theCenterX, theCenterY,
366 theStartX, theStartY,
371 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
372 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
373 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
374 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
377 std::shared_ptr<ModelAPI_Feature> aFeature =
378 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
379 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
382 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
383 double theEndX, double theEndY,
384 double thePassedX, double thePassedY)
386 std::shared_ptr<ModelAPI_Feature> aFeature =
387 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
388 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
389 theStartX, theStartY,
391 thePassedX, thePassedY));
394 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
395 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
396 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
397 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
399 std::shared_ptr<ModelAPI_Feature> aFeature =
400 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
401 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
404 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
405 const ModelHighAPI_RefAttr& theTangentPoint,
406 double theEndX, double theEndY,
409 std::shared_ptr<ModelAPI_Feature> aFeature =
410 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
411 return MacroArcPtr(new SketchAPI_MacroArc(
412 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
415 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
416 const ModelHighAPI_RefAttr& theTangentPoint,
417 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
420 std::shared_ptr<ModelAPI_Feature> aFeature =
421 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
422 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
425 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
427 std::shared_ptr<ModelAPI_Feature> aFeature =
428 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
429 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
432 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
434 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
435 std::shared_ptr<ModelAPI_Feature> aFeature =
436 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
437 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
440 //--------------------------------------------------------------------------------------
441 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
442 const ModelHighAPI_Selection & theExternalFeature)
444 std::shared_ptr<ModelAPI_Feature> aFeature =
445 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
446 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
449 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
450 const std::string & theExternalName)
452 std::shared_ptr<ModelAPI_Feature> aFeature =
453 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
454 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
457 //--------------------------------------------------------------------------------------
458 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
459 const ModelHighAPI_RefAttr & theMirrorLine,
460 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
462 std::shared_ptr<ModelAPI_Feature> aFeature =
463 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
464 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
467 //--------------------------------------------------------------------------------------
468 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
469 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
470 const ModelHighAPI_RefAttr & thePoint1,
471 const ModelHighAPI_RefAttr & thePoint2,
472 const ModelHighAPI_Integer & theNumberOfObjects,
475 std::shared_ptr<ModelAPI_Feature> aFeature =
476 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
477 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
478 thePoint2, theNumberOfObjects, theFullValue));
481 //--------------------------------------------------------------------------------------
482 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
483 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
484 const ModelHighAPI_RefAttr & theCenter,
485 const ModelHighAPI_Double & theAngle,
486 const ModelHighAPI_Integer & theNumberOfObjects,
489 std::shared_ptr<ModelAPI_Feature> aFeature =
490 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
492 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
493 theAngle, theNumberOfObjects, theFullValue));
496 //--------------------------------------------------------------------------------------
497 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
498 const ModelHighAPI_Reference& theFeature,
499 const ModelHighAPI_RefAttr& thePoint1,
500 const ModelHighAPI_RefAttr& thePoint2)
502 std::shared_ptr<ModelAPI_Feature> aFeature =
503 compositeFeature()->addFeature(SketchPlugin_ConstraintSplit::ID());
504 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Constraint::VALUE()));
505 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
506 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
507 //aFeature->execute();
508 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
511 //--------------------------------------------------------------------------------------
512 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
513 const ModelHighAPI_Reference& theFeature,
514 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
516 std::shared_ptr<ModelAPI_Feature> aFeature =
517 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
518 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
520 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
521 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
522 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
523 fillAttribute(thePositionPoint, aPointAttr);
526 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
529 //--------------------------------------------------------------------------------------
530 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
531 const ModelHighAPI_RefAttr & theLine1,
532 const ModelHighAPI_RefAttr & theLine2,
533 const ModelHighAPI_Double & theValue)
535 std::shared_ptr<ModelAPI_Feature> aFeature =
536 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
537 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
538 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
539 // fill the value before llines to avoid calculation of angle value by the Angle feature
540 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
541 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
542 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
544 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
547 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
548 const ModelHighAPI_RefAttr & theLine1,
549 const ModelHighAPI_RefAttr & theLine2,
550 const ModelHighAPI_Double & theValue)
552 std::shared_ptr<ModelAPI_Feature> aFeature =
553 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
554 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
555 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
556 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
557 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
558 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
559 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
561 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
564 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
565 const ModelHighAPI_RefAttr & theLine1,
566 const ModelHighAPI_RefAttr & theLine2,
567 const ModelHighAPI_Double & theValue)
569 std::shared_ptr<ModelAPI_Feature> aFeature =
570 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
571 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
572 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
573 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
574 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
575 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
576 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
578 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
581 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
582 const ModelHighAPI_RefAttr & thePoint1,
583 const ModelHighAPI_RefAttr & thePoint2)
585 std::shared_ptr<ModelAPI_Feature> aFeature =
586 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
587 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
588 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
590 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
593 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
594 const ModelHighAPI_RefAttr & theLine1,
595 const ModelHighAPI_RefAttr & theLine2)
597 std::shared_ptr<ModelAPI_Feature> aFeature =
598 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
599 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
600 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
602 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
605 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
606 const ModelHighAPI_RefAttr & thePoint,
607 const ModelHighAPI_RefAttr & thePointOrLine,
608 const ModelHighAPI_Double & theValue)
610 std::shared_ptr<ModelAPI_Feature> aFeature =
611 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
612 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
613 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
614 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
616 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
619 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
620 const ModelHighAPI_RefAttr & theObject1,
621 const ModelHighAPI_RefAttr & theObject2)
623 std::shared_ptr<ModelAPI_Feature> aFeature =
624 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
625 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
626 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
628 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
631 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
632 const ModelHighAPI_RefAttr & thePoint)
634 std::shared_ptr<ModelAPI_Feature> aFeature =
635 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
636 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
637 apply(); // finish operation to remove Fillet feature correcly
638 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
641 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
642 const ModelHighAPI_RefAttr & thePoint,
643 const ModelHighAPI_Double & theRadius)
645 CompositeFeaturePtr aSketch = compositeFeature();
646 int aNbSubs = aSketch->numberOfSubs();
649 InterfacePtr aFilletFeature = setFillet(thePoint);
651 // set radius for just created arc
652 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
653 if (anArc->getKind() == SketchPlugin_Arc::ID())
654 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
656 return aFilletFeature;
659 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
660 const ModelHighAPI_RefAttr & theObject)
662 std::shared_ptr<ModelAPI_Feature> aFeature =
663 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
664 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
666 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
669 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
670 const ModelHighAPI_RefAttr & theLine)
672 std::shared_ptr<ModelAPI_Feature> aFeature =
673 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
674 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
676 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
679 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
680 const ModelHighAPI_RefAttr & theLine,
681 const ModelHighAPI_Double & theValue)
683 std::shared_ptr<ModelAPI_Feature> aFeature =
684 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
685 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
686 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
688 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
691 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
692 const ModelHighAPI_RefAttr & thePoint,
693 const ModelHighAPI_RefAttr & theLine)
695 std::shared_ptr<ModelAPI_Feature> aFeature =
696 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
697 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
698 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
700 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
703 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
704 const ModelHighAPI_RefAttr & theLine1,
705 const ModelHighAPI_RefAttr & theLine2)
707 std::shared_ptr<ModelAPI_Feature> aFeature =
708 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
709 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
710 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
712 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
715 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
716 const ModelHighAPI_RefAttr & theLine1,
717 const ModelHighAPI_RefAttr & theLine2)
719 std::shared_ptr<ModelAPI_Feature> aFeature =
720 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
721 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
722 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
724 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
727 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
728 const ModelHighAPI_RefAttr & theCircleOrArc,
729 const ModelHighAPI_Double & theValue)
731 std::shared_ptr<ModelAPI_Feature> aFeature =
732 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
733 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
734 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
736 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
739 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
740 const ModelHighAPI_RefAttr & theLine,
741 const ModelHighAPI_RefAttr & theCircle)
743 std::shared_ptr<ModelAPI_Feature> aFeature =
744 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
745 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
746 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
748 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
751 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
752 const ModelHighAPI_RefAttr & theLine)
754 std::shared_ptr<ModelAPI_Feature> aFeature =
755 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
756 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
758 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
761 //--------------------------------------------------------------------------------------
763 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
765 FeaturePtr aBase = feature();
766 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
767 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
768 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
769 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
770 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
771 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
772 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
774 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
777 //--------------------------------------------------------------------------------------
779 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
781 FeaturePtr aBase = feature();
782 const std::string& aDocName = theDumper.name(aBase->document());
784 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
785 if (anExternal->value()) {
786 theDumper << aBase << " = model.addSketch(" << aDocName <<
787 ", " << anExternal << ")" << std::endl;
789 // Sketch is base on a plane.
790 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
791 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
792 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
793 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
794 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
795 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
797 // Check the plane is coordinate plane
798 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
799 if(anExternal->context()) { // checking for selected planes
800 if (!aPlaneName.empty()
801 && anExternal->context()->data()
802 && anExternal->context()->data()->name() == aPlaneName) {
803 // dump sketch based on coordinate plane
804 theDumper << aBase << " = model.addSketch(" << aDocName
805 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
806 } else { // some other plane
807 theDumper << aBase << " = model.addSketch(" << aDocName <<
808 ", " << anExternal<< ")" << std::endl;
811 if (aPlaneName.empty()) {
812 // needs import additional module
813 theDumper.importModule("GeomAPI");
814 // dump plane parameters
815 const std::string& aSketchName = theDumper.name(aBase);
816 std::string anOriginName = aSketchName + "_origin";
817 std::string aNormalName = aSketchName + "_norm";
818 std::string aDirXName = aSketchName + "_dirx";
819 // use "\n" instead of std::endl to avoid automatic dumping sketch here
820 // and then dumplicate dumping it in the next line
821 theDumper << anOriginName << " = " << anOrigin << "\n"
822 << aNormalName << " = " << aNormal << "\n"
823 << aDirXName << " = " << aDirX << "\n";
824 // dump sketch based on arbitrary plane
825 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
826 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
828 // dump sketch based on coordinate plane
829 theDumper << aBase << " = model.addSketch(" << aDocName
830 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
835 // dump sketch's subfeatures
836 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
837 theDumper.processSubs(aCompFeat, true);