1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SketchAPI_Sketch.h"
22 //--------------------------------------------------------------------------------------
23 #include <SketchPlugin_Constraint.h>
24 #include <SketchPlugin_ConstraintAngle.h>
25 #include <SketchPlugin_ConstraintCoincidence.h>
26 #include <SketchPlugin_ConstraintCollinear.h>
27 #include <SketchPlugin_ConstraintDistance.h>
28 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
29 #include <SketchPlugin_ConstraintDistanceVertical.h>
30 #include <SketchPlugin_ConstraintEqual.h>
31 #include <SketchPlugin_Fillet.h>
32 #include <SketchPlugin_ConstraintHorizontal.h>
33 #include <SketchPlugin_ConstraintLength.h>
34 #include <SketchPlugin_ConstraintMiddle.h>
35 #include <SketchPlugin_ConstraintMirror.h>
36 #include <SketchPlugin_ConstraintParallel.h>
37 #include <SketchPlugin_ConstraintPerpendicular.h>
38 #include <SketchPlugin_ConstraintRadius.h>
39 #include <SketchPlugin_ConstraintRigid.h>
40 #include <SketchPlugin_Trim.h>
41 #include <SketchPlugin_Split.h>
42 #include <SketchPlugin_ConstraintTangent.h>
43 #include <SketchPlugin_ConstraintVertical.h>
44 #include <SketcherPrs_Tools.h>
45 //--------------------------------------------------------------------------------------
46 #include <ModelAPI_Events.h>
47 #include <ModelAPI_CompositeFeature.h>
48 #include <ModelAPI_ResultConstruction.h>
49 #include <ModelHighAPI_Double.h>
50 #include <ModelHighAPI_Dumper.h>
51 #include <ModelHighAPI_RefAttr.h>
52 #include <ModelHighAPI_Selection.h>
53 #include <ModelHighAPI_Services.h>
54 #include <ModelHighAPI_Tools.h>
55 //--------------------------------------------------------------------------------------
56 #include "SketchAPI_Arc.h"
57 #include "SketchAPI_MacroArc.h"
58 #include "SketchAPI_Circle.h"
59 #include "SketchAPI_IntersectionPoint.h"
60 #include "SketchAPI_Line.h"
61 #include "SketchAPI_MacroCircle.h"
62 #include "SketchAPI_Mirror.h"
63 #include "SketchAPI_Point.h"
64 #include "SketchAPI_Projection.h"
65 #include "SketchAPI_Rectangle.h"
66 #include "SketchAPI_Rotation.h"
67 #include "SketchAPI_Translation.h"
68 //--------------------------------------------------------------------------------------
69 #include <GeomAPI_Dir2d.h>
70 #include <GeomAPI_XY.h>
72 //--------------------------------------------------------------------------------------
73 SketchAPI_Sketch::SketchAPI_Sketch(
74 const std::shared_ptr<ModelAPI_Feature> & theFeature)
75 : ModelHighAPI_Interface(theFeature)
80 SketchAPI_Sketch::SketchAPI_Sketch(
81 const std::shared_ptr<ModelAPI_Feature> & theFeature,
82 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
83 : ModelHighAPI_Interface(theFeature)
90 SketchAPI_Sketch::SketchAPI_Sketch(
91 const std::shared_ptr<ModelAPI_Feature> & theFeature,
92 const ModelHighAPI_Selection & theExternal)
93 : ModelHighAPI_Interface(theFeature)
96 setExternal(theExternal);
100 SketchAPI_Sketch::SketchAPI_Sketch(
101 const std::shared_ptr<ModelAPI_Feature> & theFeature,
102 std::shared_ptr<ModelAPI_Object> thePlaneObject)
103 : ModelHighAPI_Interface(theFeature)
106 setExternal(thePlaneObject);
110 SketchAPI_Sketch::~SketchAPI_Sketch()
115 //--------------------------------------------------------------------------------------
116 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
118 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
121 //--------------------------------------------------------------------------------------
122 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
124 fillAttribute(thePlane->origin(), myorigin);
125 fillAttribute(thePlane->dirX(), mydirX);
126 fillAttribute(thePlane->normal(), mynormal);
131 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
133 fillAttribute(theExternal, myexternal);
138 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
140 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
141 ModelHighAPI_Selection aSel(aRes);
145 //--------------------------------------------------------------------------------------
146 void SketchAPI_Sketch::setValue(
147 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
148 const ModelHighAPI_Double & theValue)
150 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
152 // theConstraint->execute();
155 //--------------------------------------------------------------------------------------
156 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
158 const_cast<SketchAPI_Sketch*>(this)->execute();
160 std::list<ModelHighAPI_Selection> aSelectionList;
162 ResultConstructionPtr aResultConstruction =
163 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
164 if (aResultConstruction.get() == NULL)
165 return aSelectionList;
167 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
168 aSelectionList.push_back(
169 ModelHighAPI_Selection(aResultConstruction,
170 aResultConstruction->face(anIndex)));
173 return aSelectionList;
176 //--------------------------------------------------------------------------------------
177 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
178 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
180 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
181 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
184 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
185 const ModelHighAPI_Selection & theExternal)
187 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
188 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
191 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
192 const std::string & theExternalName)
194 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
196 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
199 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
200 std::shared_ptr<ModelAPI_Object> thePlaneObject)
202 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
203 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
207 //--------------------------------------------------------------------------------------
208 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
209 double theX, double theY)
211 std::shared_ptr<ModelAPI_Feature> aFeature =
212 compositeFeature()->addFeature(SketchPlugin_Point::ID());
213 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
215 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
216 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
218 std::shared_ptr<ModelAPI_Feature> aFeature =
219 compositeFeature()->addFeature(SketchPlugin_Point::ID());
220 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
222 std::shared_ptr<SketchAPI_Point>
223 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
225 std::shared_ptr<ModelAPI_Feature> aFeature =
226 compositeFeature()->addFeature(SketchPlugin_Point::ID());
227 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
229 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
231 std::shared_ptr<ModelAPI_Feature> aFeature =
232 compositeFeature()->addFeature(SketchPlugin_Point::ID());
233 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
236 //--------------------------------------------------------------------------------------
237 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
238 const ModelHighAPI_Selection & theExternal,
241 std::shared_ptr<ModelAPI_Feature> aFeature =
242 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
243 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
244 anIntersection->setIncludeToResult(theKeepResult);
245 return anIntersection;
247 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
248 const std::string & theExternalName,
251 std::shared_ptr<ModelAPI_Feature> aFeature =
252 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
253 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
254 anIntersection->setIncludeToResult(theKeepResult);
255 return anIntersection;
258 //--------------------------------------------------------------------------------------
259 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
260 double theX2, double theY2)
262 std::shared_ptr<ModelAPI_Feature> aFeature =
263 compositeFeature()->addFeature(SketchPlugin_Line::ID());
264 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
266 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
267 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
268 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
270 std::shared_ptr<ModelAPI_Feature> aFeature =
271 compositeFeature()->addFeature(SketchPlugin_Line::ID());
272 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
274 std::shared_ptr<SketchAPI_Line>
275 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
277 std::shared_ptr<ModelAPI_Feature> aFeature =
278 compositeFeature()->addFeature(SketchPlugin_Line::ID());
279 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
281 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
283 std::shared_ptr<ModelAPI_Feature> aFeature =
284 compositeFeature()->addFeature(SketchPlugin_Line::ID());
285 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
288 //--------------------------------------------------------------------------------------
289 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
290 double theX2, double theY2)
292 std::shared_ptr<ModelAPI_Feature> aFeature =
293 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
294 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
296 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
297 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
298 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
300 std::shared_ptr<ModelAPI_Feature> aFeature =
301 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
302 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
305 //--------------------------------------------------------------------------------------
306 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
310 std::shared_ptr<ModelAPI_Feature> aFeature =
311 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
312 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
315 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
316 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
319 std::shared_ptr<ModelAPI_Feature> aFeature =
320 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
321 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
324 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
329 std::shared_ptr<ModelAPI_Feature> aFeature =
330 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
331 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
332 thePassedX, thePassedY));
335 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
336 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
337 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
339 std::shared_ptr<ModelAPI_Feature> aFeature =
340 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
341 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
344 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
345 double theX2, double theY2,
346 double theX3, double theY3)
348 std::shared_ptr<ModelAPI_Feature> aFeature =
349 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
350 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
355 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
356 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
357 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
358 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
360 std::shared_ptr<ModelAPI_Feature> aFeature =
361 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
362 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
365 std::shared_ptr<SketchAPI_Circle>
366 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
368 std::shared_ptr<ModelAPI_Feature> aFeature =
369 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
370 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
373 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
375 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
376 std::shared_ptr<ModelAPI_Feature> aFeature =
377 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
378 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
381 //--------------------------------------------------------------------------------------
382 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
383 double theStartX, double theStartY,
384 double theEndX, double theEndY,
387 std::shared_ptr<ModelAPI_Feature> aFeature =
388 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
389 return ArcPtr(new SketchAPI_Arc(aFeature,
390 theCenterX, theCenterY,
391 theStartX, theStartY,
396 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
397 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
398 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
399 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
402 std::shared_ptr<ModelAPI_Feature> aFeature =
403 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
404 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
407 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
408 double theEndX, double theEndY,
409 double thePassedX, double thePassedY)
411 std::shared_ptr<ModelAPI_Feature> aFeature =
412 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
413 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
414 theStartX, theStartY,
416 thePassedX, thePassedY));
419 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
420 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
421 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
422 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
424 std::shared_ptr<ModelAPI_Feature> aFeature =
425 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
426 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
429 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
430 const ModelHighAPI_RefAttr& theTangentPoint,
431 double theEndX, double theEndY,
434 std::shared_ptr<ModelAPI_Feature> aFeature =
435 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
436 return MacroArcPtr(new SketchAPI_MacroArc(
437 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
440 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
441 const ModelHighAPI_RefAttr& theTangentPoint,
442 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
445 std::shared_ptr<ModelAPI_Feature> aFeature =
446 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
447 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
450 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
452 std::shared_ptr<ModelAPI_Feature> aFeature =
453 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
454 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
457 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
459 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
460 std::shared_ptr<ModelAPI_Feature> aFeature =
461 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
462 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
465 //--------------------------------------------------------------------------------------
466 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
467 const ModelHighAPI_Selection & theExternalFeature,
470 std::shared_ptr<ModelAPI_Feature> aFeature =
471 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
472 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
473 aProjection->setIncludeToResult(theKeepResult);
477 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
478 const std::string & theExternalName,
481 std::shared_ptr<ModelAPI_Feature> aFeature =
482 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
483 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
484 aProjection->setIncludeToResult(theKeepResult);
488 //--------------------------------------------------------------------------------------
489 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
490 const ModelHighAPI_RefAttr & theMirrorLine,
491 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
493 std::shared_ptr<ModelAPI_Feature> aFeature =
494 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
495 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
498 //--------------------------------------------------------------------------------------
499 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
500 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
501 const ModelHighAPI_RefAttr & thePoint1,
502 const ModelHighAPI_RefAttr & thePoint2,
503 const ModelHighAPI_Integer & theNumberOfObjects,
506 std::shared_ptr<ModelAPI_Feature> aFeature =
507 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
508 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
509 thePoint2, theNumberOfObjects, theFullValue));
512 //--------------------------------------------------------------------------------------
513 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
514 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
515 const ModelHighAPI_RefAttr & theCenter,
516 const ModelHighAPI_Double & theAngle,
517 const ModelHighAPI_Integer & theNumberOfObjects,
521 std::shared_ptr<ModelAPI_Feature> aFeature =
522 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
524 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
525 theAngle, theNumberOfObjects, theFullValue, theReversed));
528 //--------------------------------------------------------------------------------------
529 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
530 const ModelHighAPI_Reference& theFeature,
531 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
533 std::shared_ptr<ModelAPI_Feature> aFeature =
534 compositeFeature()->addFeature(SketchPlugin_Split::ID());
535 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
537 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
538 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
539 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
540 fillAttribute(thePositionPoint, aPointAttr);
543 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
546 //--------------------------------------------------------------------------------------
547 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
548 const ModelHighAPI_Reference& theFeature,
549 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
551 std::shared_ptr<ModelAPI_Feature> aFeature =
552 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
553 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
555 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
556 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
557 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
558 fillAttribute(thePositionPoint, aPointAttr);
561 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
564 //--------------------------------------------------------------------------------------
565 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
566 const ModelHighAPI_RefAttr & theLine1,
567 const ModelHighAPI_RefAttr & theLine2,
568 const ModelHighAPI_Double & theValue)
570 std::shared_ptr<ModelAPI_Feature> aFeature =
571 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
572 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
573 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
574 // fill the value before llines to avoid calculation of angle value by the Angle feature
575 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
576 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
577 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
579 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
582 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
583 const ModelHighAPI_RefAttr & theLine1,
584 const ModelHighAPI_RefAttr & theLine2,
585 const ModelHighAPI_Double & theValue)
587 std::shared_ptr<ModelAPI_Feature> aFeature =
588 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
589 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
590 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
591 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
592 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
593 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
595 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
598 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
599 const ModelHighAPI_RefAttr & theLine1,
600 const ModelHighAPI_RefAttr & theLine2,
601 const ModelHighAPI_Double & theValue)
603 std::shared_ptr<ModelAPI_Feature> aFeature =
604 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
605 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
606 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
607 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
608 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
609 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
611 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
614 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
615 const ModelHighAPI_RefAttr & thePoint1,
616 const ModelHighAPI_RefAttr & thePoint2)
618 std::shared_ptr<ModelAPI_Feature> aFeature =
619 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
620 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
621 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
623 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
626 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
627 const ModelHighAPI_RefAttr & theLine1,
628 const ModelHighAPI_RefAttr & theLine2)
630 std::shared_ptr<ModelAPI_Feature> aFeature =
631 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
632 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
633 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
635 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
638 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
639 const ModelHighAPI_RefAttr & thePoint,
640 const ModelHighAPI_RefAttr & thePointOrLine,
641 const ModelHighAPI_Double & theValue,
644 std::shared_ptr<ModelAPI_Feature> aFeature =
645 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
646 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
647 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
648 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
649 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
651 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
654 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
655 const ModelHighAPI_RefAttr & thePoint,
656 const ModelHighAPI_RefAttr & thePointOrLine,
657 const ModelHighAPI_Double & theValue)
659 return setDistance(thePoint, thePointOrLine, theValue, true);
662 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
663 const ModelHighAPI_RefAttr & thePoint,
664 const ModelHighAPI_RefAttr & thePointOrLine,
665 const ModelHighAPI_Double & theValue)
667 return setDistance(thePoint, thePointOrLine, theValue, false);
670 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
671 const ModelHighAPI_RefAttr & thePoint1,
672 const ModelHighAPI_RefAttr & thePoint2,
673 const ModelHighAPI_Double & theValue)
675 std::shared_ptr<ModelAPI_Feature> aFeature =
676 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
677 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
678 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
679 fillAttribute(theValue,
680 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
682 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
685 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
686 const ModelHighAPI_RefAttr & thePoint1,
687 const ModelHighAPI_RefAttr & thePoint2,
688 const ModelHighAPI_Double & theValue)
690 std::shared_ptr<ModelAPI_Feature> aFeature =
691 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
692 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
693 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
694 fillAttribute(theValue,
695 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
697 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
700 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
701 const ModelHighAPI_RefAttr & theObject1,
702 const ModelHighAPI_RefAttr & theObject2)
704 std::shared_ptr<ModelAPI_Feature> aFeature =
705 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
706 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
707 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
709 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
712 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
713 const ModelHighAPI_RefAttr & thePoint)
715 std::shared_ptr<ModelAPI_Feature> aFeature =
716 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
717 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
718 apply(); // finish operation to remove Fillet feature correcly
719 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
722 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
723 const ModelHighAPI_RefAttr & thePoint,
724 const ModelHighAPI_Double & theRadius)
726 CompositeFeaturePtr aSketch = compositeFeature();
727 int aNbSubs = aSketch->numberOfSubs();
730 InterfacePtr aFilletFeature = setFillet(thePoint);
732 // set radius for just created arc
733 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
734 if (anArc->getKind() == SketchPlugin_Arc::ID())
735 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
737 return aFilletFeature;
740 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
741 const ModelHighAPI_RefAttr & theObject)
743 std::shared_ptr<ModelAPI_Feature> aFeature =
744 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
745 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
747 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
750 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
751 const ModelHighAPI_RefAttr & theLine)
753 std::shared_ptr<ModelAPI_Feature> aFeature =
754 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
755 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
757 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
760 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
761 const ModelHighAPI_RefAttr & theLine,
762 const ModelHighAPI_Double & theValue)
764 std::shared_ptr<ModelAPI_Feature> aFeature =
765 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
766 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
767 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
769 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
772 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
773 const ModelHighAPI_RefAttr & thePoint,
774 const ModelHighAPI_RefAttr & theLine)
776 std::shared_ptr<ModelAPI_Feature> aFeature =
777 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
778 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
779 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
781 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
784 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
785 const ModelHighAPI_RefAttr & theLine1,
786 const ModelHighAPI_RefAttr & theLine2)
788 std::shared_ptr<ModelAPI_Feature> aFeature =
789 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
790 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
791 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
793 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
796 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
797 const ModelHighAPI_RefAttr & theLine1,
798 const ModelHighAPI_RefAttr & theLine2)
800 std::shared_ptr<ModelAPI_Feature> aFeature =
801 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
802 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
803 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
805 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
808 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
809 const ModelHighAPI_RefAttr & theCircleOrArc,
810 const ModelHighAPI_Double & theValue)
812 std::shared_ptr<ModelAPI_Feature> aFeature =
813 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
814 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
815 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
817 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
820 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
821 const ModelHighAPI_RefAttr & theLine,
822 const ModelHighAPI_RefAttr & theCircle)
824 std::shared_ptr<ModelAPI_Feature> aFeature =
825 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
826 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
827 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
829 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
832 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
833 const ModelHighAPI_RefAttr & theLine)
835 std::shared_ptr<ModelAPI_Feature> aFeature =
836 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
837 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
839 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
842 //--------------------------------------------------------------------------------------
844 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
846 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
847 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
850 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
852 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
853 theFeature->attribute(SketchPlugin_Line::START_ID()));
854 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
855 theFeature->attribute(SketchPlugin_Line::END_ID()));
857 if (!aStartAttr || !aEndAttr)
858 return std::shared_ptr<GeomAPI_Pnt2d>();
860 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
861 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
862 return std::shared_ptr<GeomAPI_Pnt2d>(
863 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
866 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
868 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
869 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
870 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
872 if (!aCenter || !aRadius)
873 return std::shared_ptr<GeomAPI_Pnt2d>();
875 return std::shared_ptr<GeomAPI_Pnt2d>(
876 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
879 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
881 static const double PI = 3.141592653589793238463;
883 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
884 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
885 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
886 theFeature->attribute(SketchPlugin_Arc::START_ID()));
887 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
888 theFeature->attribute(SketchPlugin_Arc::END_ID()));
890 if (!aCenterAttr || !aStartAttr || !aEndAttr)
891 return std::shared_ptr<GeomAPI_Pnt2d>();
893 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
894 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
895 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
896 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
898 double anAngle = aStartDir->angle(aEndDir);
899 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
900 if (isReversed && anAngle > 0.)
902 else if (!isReversed && anAngle <= 0.)
905 double cosA = cos(anAngle);
906 double sinA = sin(anAngle);
908 // rotate start dir to find middle point on arc
909 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
910 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
911 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
913 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
916 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
918 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
919 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
921 // move only features of the following types
922 const std::string& aFeatureKind = aFeature->getKind();
923 if (aFeatureKind == SketchPlugin_Point::ID())
924 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
925 else if (aFeatureKind == SketchPlugin_Line::ID())
926 aMiddlePoint = middlePointOnLine(aFeature);
927 else if (aFeatureKind == SketchPlugin_Circle::ID())
928 aMiddlePoint = pointOnCircle(aFeature);
929 else if (aFeatureKind == SketchPlugin_Arc::ID())
930 aMiddlePoint = middlePointOnArc(aFeature);
935 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
936 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
938 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
939 theMovedEntity.fillMessage(aMessage);
941 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
942 if (aMessage->movedAttribute())
943 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
945 anOriginalPosition = middlePoint(aMessage->movedObject());
947 if (!anOriginalPosition)
948 return; // something has gone wrong, do not process movement
950 aMessage->setOriginalPosition(anOriginalPosition);
951 aMessage->setCurrentPosition(theTargetPoint);
952 Events_Loop::loop()->send(aMessage);
955 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
956 double theTargetX, double theTargetY)
958 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
959 move(theMovedEntity, aTargetPoint);
962 //--------------------------------------------------------------------------------------
964 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
966 FeaturePtr aBase = feature();
967 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
968 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
969 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
970 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
971 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
972 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
973 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
975 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
978 //--------------------------------------------------------------------------------------
980 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
982 FeaturePtr aBase = feature();
983 const std::string& aDocName = theDumper.name(aBase->document());
985 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
986 if (anExternal->value()) {
987 theDumper << aBase << " = model.addSketch(" << aDocName <<
988 ", " << anExternal << ")" << std::endl;
990 // Sketch is base on a plane.
991 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
992 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
993 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
994 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
995 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
996 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
998 // Check the plane is coordinate plane
999 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1000 if(anExternal->context()) { // checking for selected planes
1001 if (!aPlaneName.empty()
1002 && anExternal->context()->data()
1003 && anExternal->context()->data()->name() == aPlaneName) {
1004 // dump sketch based on coordinate plane
1005 theDumper << aBase << " = model.addSketch(" << aDocName
1006 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1007 } else { // some other plane
1008 theDumper << aBase << " = model.addSketch(" << aDocName <<
1009 ", " << anExternal<< ")" << std::endl;
1012 if (aPlaneName.empty()) {
1013 // needs import additional module
1014 theDumper.importModule("GeomAPI");
1015 // dump plane parameters
1016 const std::string& aSketchName = theDumper.name(aBase);
1017 std::string anOriginName = aSketchName + "_origin";
1018 std::string aNormalName = aSketchName + "_norm";
1019 std::string aDirXName = aSketchName + "_dirx";
1020 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1021 // and then dumplicate dumping it in the next line
1022 theDumper << anOriginName << " = " << anOrigin << "\n"
1023 << aNormalName << " = " << aNormal << "\n"
1024 << aDirXName << " = " << aDirX << "\n";
1025 // dump sketch based on arbitrary plane
1026 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1027 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1029 // dump sketch based on coordinate plane
1030 theDumper << aBase << " = model.addSketch(" << aDocName
1031 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1036 // dump sketch's subfeatures
1037 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1038 theDumper.processSubs(aCompFeat, true);