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_Mirror.h"
46 #include "SketchAPI_Point.h"
47 #include "SketchAPI_Projection.h"
48 #include "SketchAPI_Rectangle.h"
49 #include "SketchAPI_Rotation.h"
50 #include "SketchAPI_Translation.h"
51 //--------------------------------------------------------------------------------------
52 SketchAPI_Sketch::SketchAPI_Sketch(
53 const std::shared_ptr<ModelAPI_Feature> & theFeature)
54 : ModelHighAPI_Interface(theFeature)
59 SketchAPI_Sketch::SketchAPI_Sketch(
60 const std::shared_ptr<ModelAPI_Feature> & theFeature,
61 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
62 : ModelHighAPI_Interface(theFeature)
69 SketchAPI_Sketch::SketchAPI_Sketch(
70 const std::shared_ptr<ModelAPI_Feature> & theFeature,
71 const ModelHighAPI_Selection & theExternal)
72 : ModelHighAPI_Interface(theFeature)
75 setExternal(theExternal);
79 SketchAPI_Sketch::SketchAPI_Sketch(
80 const std::shared_ptr<ModelAPI_Feature> & theFeature,
81 std::shared_ptr<ModelAPI_Object> thePlaneObject)
82 : ModelHighAPI_Interface(theFeature)
85 setExternal(thePlaneObject);
89 SketchAPI_Sketch::~SketchAPI_Sketch()
94 //--------------------------------------------------------------------------------------
95 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
97 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
100 //--------------------------------------------------------------------------------------
101 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
103 fillAttribute(thePlane->origin(), myorigin);
104 fillAttribute(thePlane->dirX(), mydirX);
105 fillAttribute(thePlane->normal(), mynormal);
110 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
112 fillAttribute(theExternal, myexternal);
117 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
119 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
120 ModelHighAPI_Selection aSel(aRes);
124 //--------------------------------------------------------------------------------------
125 void SketchAPI_Sketch::setValue(
126 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
127 const ModelHighAPI_Double & theValue)
129 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
131 // theConstraint->execute();
134 //--------------------------------------------------------------------------------------
135 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
137 const_cast<SketchAPI_Sketch*>(this)->execute();
139 std::list<ModelHighAPI_Selection> aSelectionList;
141 ResultConstructionPtr aResultConstruction =
142 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
143 if (aResultConstruction.get() == NULL)
144 return aSelectionList;
146 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
147 aSelectionList.push_back(
148 ModelHighAPI_Selection(aResultConstruction,
149 aResultConstruction->face(anIndex)));
152 return aSelectionList;
155 //--------------------------------------------------------------------------------------
156 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
157 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
159 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
160 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
163 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
164 const ModelHighAPI_Selection & theExternal)
166 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
167 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
170 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
171 const std::string & theExternalName)
173 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
175 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
178 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
179 std::shared_ptr<ModelAPI_Object> thePlaneObject)
181 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
182 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
186 //--------------------------------------------------------------------------------------
187 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
188 double theX, double theY)
190 std::shared_ptr<ModelAPI_Feature> aFeature =
191 compositeFeature()->addFeature(SketchPlugin_Point::ID());
192 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
194 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
195 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
197 std::shared_ptr<ModelAPI_Feature> aFeature =
198 compositeFeature()->addFeature(SketchPlugin_Point::ID());
199 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
201 std::shared_ptr<SketchAPI_Point>
202 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
204 std::shared_ptr<ModelAPI_Feature> aFeature =
205 compositeFeature()->addFeature(SketchPlugin_Point::ID());
206 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
208 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
210 std::shared_ptr<ModelAPI_Feature> aFeature =
211 compositeFeature()->addFeature(SketchPlugin_Point::ID());
212 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
215 //--------------------------------------------------------------------------------------
216 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
217 const ModelHighAPI_Selection & theExternal)
219 std::shared_ptr<ModelAPI_Feature> aFeature =
220 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
221 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
223 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
224 const std::string & theExternalName)
226 std::shared_ptr<ModelAPI_Feature> aFeature =
227 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
228 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
231 //--------------------------------------------------------------------------------------
232 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
233 double theX2, double theY2)
235 std::shared_ptr<ModelAPI_Feature> aFeature =
236 compositeFeature()->addFeature(SketchPlugin_Line::ID());
237 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
239 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
240 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
241 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
243 std::shared_ptr<ModelAPI_Feature> aFeature =
244 compositeFeature()->addFeature(SketchPlugin_Line::ID());
245 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
247 std::shared_ptr<SketchAPI_Line>
248 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
250 std::shared_ptr<ModelAPI_Feature> aFeature =
251 compositeFeature()->addFeature(SketchPlugin_Line::ID());
252 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
254 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
256 std::shared_ptr<ModelAPI_Feature> aFeature =
257 compositeFeature()->addFeature(SketchPlugin_Line::ID());
258 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
261 //--------------------------------------------------------------------------------------
262 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
263 double theX2, double theY2)
265 std::shared_ptr<ModelAPI_Feature> aFeature =
266 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
267 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
269 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
270 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
271 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
273 std::shared_ptr<ModelAPI_Feature> aFeature =
274 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
275 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
278 //--------------------------------------------------------------------------------------
279 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
283 std::shared_ptr<ModelAPI_Feature> aFeature =
284 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
285 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
288 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
289 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
292 std::shared_ptr<ModelAPI_Feature> aFeature =
293 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
294 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
297 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
298 double theX2, double theY2,
299 double theX3, double theY3)
301 std::shared_ptr<ModelAPI_Feature> aFeature =
302 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
303 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
306 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
307 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
308 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
309 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
311 std::shared_ptr<ModelAPI_Feature> aFeature =
312 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
313 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
316 std::shared_ptr<SketchAPI_Circle>
317 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
319 std::shared_ptr<ModelAPI_Feature> aFeature =
320 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
321 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
324 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
326 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
327 std::shared_ptr<ModelAPI_Feature> aFeature =
328 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
329 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
332 //--------------------------------------------------------------------------------------
333 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
334 double theStartX, double theStartY,
335 double theEndX, double theEndY,
338 std::shared_ptr<ModelAPI_Feature> aFeature =
339 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
340 return ArcPtr(new SketchAPI_Arc(aFeature,
341 theCenterX, theCenterY,
342 theStartX, theStartY,
347 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
348 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
349 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
350 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
353 std::shared_ptr<ModelAPI_Feature> aFeature =
354 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
355 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
358 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
359 double theEndX, double theEndY,
360 double thePassedX, double thePassedY)
362 std::shared_ptr<ModelAPI_Feature> aFeature =
363 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
364 return ArcPtr(new SketchAPI_Arc(aFeature,
365 theStartX, theStartY,
367 thePassedX, thePassedY));
370 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
371 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
372 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
373 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
375 std::shared_ptr<ModelAPI_Feature> aFeature =
376 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
377 return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed));
380 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
381 const ModelHighAPI_RefAttr& theTangentPoint,
382 double theEndX, double theEndY,
385 std::shared_ptr<ModelAPI_Feature> aFeature =
386 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
387 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed));
390 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
391 const ModelHighAPI_RefAttr& theTangentPoint,
392 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
395 std::shared_ptr<ModelAPI_Feature> aFeature =
396 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
397 return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed));
400 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
402 std::shared_ptr<ModelAPI_Feature> aFeature =
403 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
404 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
407 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
409 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
410 std::shared_ptr<ModelAPI_Feature> aFeature =
411 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
412 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
415 //--------------------------------------------------------------------------------------
416 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
417 const ModelHighAPI_Selection & theExternalFeature)
419 std::shared_ptr<ModelAPI_Feature> aFeature =
420 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
421 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
424 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
425 const std::string & theExternalName)
427 std::shared_ptr<ModelAPI_Feature> aFeature =
428 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
429 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
432 //--------------------------------------------------------------------------------------
433 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
434 const ModelHighAPI_RefAttr & theMirrorLine,
435 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
437 std::shared_ptr<ModelAPI_Feature> aFeature =
438 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
439 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
442 //--------------------------------------------------------------------------------------
443 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
444 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
445 const ModelHighAPI_RefAttr & thePoint1,
446 const ModelHighAPI_RefAttr & thePoint2,
447 const ModelHighAPI_Integer & theNumberOfObjects,
450 std::shared_ptr<ModelAPI_Feature> aFeature =
451 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
452 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
453 thePoint2, theNumberOfObjects, theFullValue));
456 //--------------------------------------------------------------------------------------
457 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
458 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
459 const ModelHighAPI_RefAttr & theCenter,
460 const ModelHighAPI_Double & theAngle,
461 const ModelHighAPI_Integer & theNumberOfObjects,
464 std::shared_ptr<ModelAPI_Feature> aFeature =
465 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
467 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
468 theAngle, theNumberOfObjects, theFullValue));
471 //--------------------------------------------------------------------------------------
472 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
473 const ModelHighAPI_Reference& theFeature,
474 const ModelHighAPI_RefAttr& thePoint1,
475 const ModelHighAPI_RefAttr& thePoint2)
477 std::shared_ptr<ModelAPI_Feature> aFeature =
478 compositeFeature()->addFeature(SketchPlugin_ConstraintSplit::ID());
479 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Constraint::VALUE()));
480 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
481 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
482 //aFeature->execute();
483 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
486 //--------------------------------------------------------------------------------------
487 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
488 const ModelHighAPI_Reference& theFeature,
489 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
491 std::shared_ptr<ModelAPI_Feature> aFeature =
492 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
493 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::BASE_OBJECT()));
495 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::ENTITY_POINT());
496 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
497 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
498 fillAttribute(thePositionPoint, aPointAttr);
501 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
504 //--------------------------------------------------------------------------------------
505 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
506 const ModelHighAPI_RefAttr & theLine1,
507 const ModelHighAPI_RefAttr & theLine2,
508 const ModelHighAPI_Double & theValue)
510 std::shared_ptr<ModelAPI_Feature> aFeature =
511 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
512 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
513 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
514 // fill the value before llines to avoid calculation of angle value by the Angle feature
515 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
516 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
517 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
519 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
522 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
523 const ModelHighAPI_RefAttr & theLine1,
524 const ModelHighAPI_RefAttr & theLine2,
525 const ModelHighAPI_Double & theValue)
527 std::shared_ptr<ModelAPI_Feature> aFeature =
528 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
529 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
530 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
531 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
532 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
533 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
534 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
536 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
539 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
540 const ModelHighAPI_RefAttr & theLine1,
541 const ModelHighAPI_RefAttr & theLine2,
542 const ModelHighAPI_Double & theValue)
544 std::shared_ptr<ModelAPI_Feature> aFeature =
545 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
546 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
547 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
548 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
549 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
550 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
551 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
553 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
556 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
557 const ModelHighAPI_RefAttr & thePoint1,
558 const ModelHighAPI_RefAttr & thePoint2)
560 std::shared_ptr<ModelAPI_Feature> aFeature =
561 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
562 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
563 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
565 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
568 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
569 const ModelHighAPI_RefAttr & theLine1,
570 const ModelHighAPI_RefAttr & theLine2)
572 std::shared_ptr<ModelAPI_Feature> aFeature =
573 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
574 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
575 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
577 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
580 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
581 const ModelHighAPI_RefAttr & thePoint,
582 const ModelHighAPI_RefAttr & thePointOrLine,
583 const ModelHighAPI_Double & theValue)
585 std::shared_ptr<ModelAPI_Feature> aFeature =
586 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
587 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
588 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
589 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
591 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
594 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
595 const ModelHighAPI_RefAttr & theObject1,
596 const ModelHighAPI_RefAttr & theObject2)
598 std::shared_ptr<ModelAPI_Feature> aFeature =
599 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
600 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
601 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
603 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
606 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
607 const ModelHighAPI_RefAttr & thePoint)
609 std::shared_ptr<ModelAPI_Feature> aFeature =
610 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
611 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
612 apply(); // finish operation to remove Fillet feature correcly
613 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
616 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
617 const ModelHighAPI_RefAttr & thePoint,
618 const ModelHighAPI_Double & theRadius)
620 CompositeFeaturePtr aSketch = compositeFeature();
621 int aNbSubs = aSketch->numberOfSubs();
624 InterfacePtr aFilletFeature = setFillet(thePoint);
626 // set radius for just created arc
627 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
628 if (anArc->getKind() == SketchPlugin_Arc::ID())
629 setRadius(ModelHighAPI_RefAttr(anArc->lastResult()), ModelHighAPI_Double(theRadius));
631 return aFilletFeature;
634 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
635 const ModelHighAPI_RefAttr & theObject)
637 std::shared_ptr<ModelAPI_Feature> aFeature =
638 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
639 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
641 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
644 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
645 const ModelHighAPI_RefAttr & theLine)
647 std::shared_ptr<ModelAPI_Feature> aFeature =
648 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
649 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
651 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
654 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
655 const ModelHighAPI_RefAttr & theLine,
656 const ModelHighAPI_Double & theValue)
658 std::shared_ptr<ModelAPI_Feature> aFeature =
659 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
660 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
661 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
663 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
666 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
667 const ModelHighAPI_RefAttr & thePoint,
668 const ModelHighAPI_RefAttr & theLine)
670 std::shared_ptr<ModelAPI_Feature> aFeature =
671 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
672 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
673 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
675 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
678 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
679 const ModelHighAPI_RefAttr & theLine1,
680 const ModelHighAPI_RefAttr & theLine2)
682 std::shared_ptr<ModelAPI_Feature> aFeature =
683 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
684 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
685 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
687 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
690 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
691 const ModelHighAPI_RefAttr & theLine1,
692 const ModelHighAPI_RefAttr & theLine2)
694 std::shared_ptr<ModelAPI_Feature> aFeature =
695 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
696 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
697 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
699 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
702 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
703 const ModelHighAPI_RefAttr & theCircleOrArc,
704 const ModelHighAPI_Double & theValue)
706 std::shared_ptr<ModelAPI_Feature> aFeature =
707 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
708 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
709 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
711 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
714 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
715 const ModelHighAPI_RefAttr & theLine,
716 const ModelHighAPI_RefAttr & theCircle)
718 std::shared_ptr<ModelAPI_Feature> aFeature =
719 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
720 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
721 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
723 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
726 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
727 const ModelHighAPI_RefAttr & theLine)
729 std::shared_ptr<ModelAPI_Feature> aFeature =
730 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
731 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
733 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
736 //--------------------------------------------------------------------------------------
738 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
740 FeaturePtr aBase = feature();
741 const std::string& aDocName = theDumper.name(aBase->document());
743 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
744 if (anExternal->value()) {
745 theDumper << aBase << " = model.addSketch(" << aDocName <<
746 ", " << anExternal << ")" << std::endl;
748 // Sketch is base on a plane.
749 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
750 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
751 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
752 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
753 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
754 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
756 // Check the plane is coordinate plane
757 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
758 if(anExternal->context()) { // checking for selected planes
759 if (!aPlaneName.empty()
760 && anExternal->context()->data()
761 && anExternal->context()->data()->name() == aPlaneName) {
762 // dump sketch based on coordinate plane
763 theDumper << aBase << " = model.addSketch(" << aDocName
764 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
765 } else { // some other plane
766 theDumper << aBase << " = model.addSketch(" << aDocName <<
767 ", " << anExternal<< ")" << std::endl;
770 if (aPlaneName.empty()) {
771 // needs import additional module
772 theDumper.importModule("GeomAPI");
773 // dump plane parameters
774 const std::string& aSketchName = theDumper.name(aBase);
775 std::string anOriginName = aSketchName + "_origin";
776 std::string aNormalName = aSketchName + "_norm";
777 std::string aDirXName = aSketchName + "_dirx";
778 // use "\n" instead of std::endl to avoid automatic dumping sketch here
779 // and then dumplicate dumping it in the next line
780 theDumper << anOriginName << " = " << anOrigin << "\n"
781 << aNormalName << " = " << aNormal << "\n"
782 << aDirXName << " = " << aDirX << "\n";
783 // dump sketch based on arbitrary plane
784 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
785 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
787 // dump sketch based on coordinate plane
788 theDumper << aBase << " = model.addSketch(" << aDocName
789 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
794 // dump sketch's subfeatures
795 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
796 theDumper.processSubs(aCompFeat, true);