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(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
576 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
577 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
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(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
592 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
593 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
594 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
596 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
599 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
600 const ModelHighAPI_RefAttr & theLine1,
601 const ModelHighAPI_RefAttr & theLine2,
602 const ModelHighAPI_Double & theValue)
604 std::shared_ptr<ModelAPI_Feature> aFeature =
605 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
606 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
607 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
608 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
609 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
610 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
611 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
613 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
616 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
617 const ModelHighAPI_RefAttr & thePoint1,
618 const ModelHighAPI_RefAttr & thePoint2)
620 std::shared_ptr<ModelAPI_Feature> aFeature =
621 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
622 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
623 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
625 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
628 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
629 const ModelHighAPI_RefAttr & theLine1,
630 const ModelHighAPI_RefAttr & theLine2)
632 std::shared_ptr<ModelAPI_Feature> aFeature =
633 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
634 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
635 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
637 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
640 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
641 const ModelHighAPI_RefAttr & thePoint,
642 const ModelHighAPI_RefAttr & thePointOrLine,
643 const ModelHighAPI_Double & theValue,
646 std::shared_ptr<ModelAPI_Feature> aFeature =
647 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
648 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
649 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
650 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
651 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
653 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
656 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
657 const ModelHighAPI_RefAttr & thePoint,
658 const ModelHighAPI_RefAttr & thePointOrLine,
659 const ModelHighAPI_Double & theValue)
661 return setDistance(thePoint, thePointOrLine, theValue, true);
664 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
665 const ModelHighAPI_RefAttr & thePoint,
666 const ModelHighAPI_RefAttr & thePointOrLine,
667 const ModelHighAPI_Double & theValue)
669 return setDistance(thePoint, thePointOrLine, theValue, false);
672 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
673 const ModelHighAPI_RefAttr & thePoint1,
674 const ModelHighAPI_RefAttr & thePoint2,
675 const ModelHighAPI_Double & theValue)
677 std::shared_ptr<ModelAPI_Feature> aFeature =
678 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
679 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
680 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
681 fillAttribute(theValue,
682 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
684 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
687 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
688 const ModelHighAPI_RefAttr & thePoint1,
689 const ModelHighAPI_RefAttr & thePoint2,
690 const ModelHighAPI_Double & theValue)
692 std::shared_ptr<ModelAPI_Feature> aFeature =
693 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
694 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
695 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
696 fillAttribute(theValue,
697 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
699 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
702 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
703 const ModelHighAPI_RefAttr & theObject1,
704 const ModelHighAPI_RefAttr & theObject2)
706 std::shared_ptr<ModelAPI_Feature> aFeature =
707 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
708 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
709 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
711 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
714 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
715 const ModelHighAPI_RefAttr & thePoint)
717 std::shared_ptr<ModelAPI_Feature> aFeature =
718 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
719 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
720 apply(); // finish operation to remove Fillet feature correcly
721 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
724 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
725 const ModelHighAPI_RefAttr & thePoint,
726 const ModelHighAPI_Double & theRadius)
728 CompositeFeaturePtr aSketch = compositeFeature();
729 int aNbSubs = aSketch->numberOfSubs();
732 InterfacePtr aFilletFeature = setFillet(thePoint);
734 // set radius for just created arc
735 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
736 if (anArc->getKind() == SketchPlugin_Arc::ID())
737 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
739 return aFilletFeature;
742 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
743 const ModelHighAPI_RefAttr & theObject)
745 std::shared_ptr<ModelAPI_Feature> aFeature =
746 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
747 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
749 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
752 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
753 const ModelHighAPI_RefAttr & theLine)
755 std::shared_ptr<ModelAPI_Feature> aFeature =
756 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
757 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
759 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
762 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
763 const ModelHighAPI_RefAttr & theLine,
764 const ModelHighAPI_Double & theValue)
766 std::shared_ptr<ModelAPI_Feature> aFeature =
767 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
768 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
769 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
771 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
774 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
775 const ModelHighAPI_RefAttr & thePoint,
776 const ModelHighAPI_RefAttr & theLine)
778 std::shared_ptr<ModelAPI_Feature> aFeature =
779 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
780 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
781 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
783 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
786 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
787 const ModelHighAPI_RefAttr & theLine1,
788 const ModelHighAPI_RefAttr & theLine2)
790 std::shared_ptr<ModelAPI_Feature> aFeature =
791 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
792 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
793 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
795 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
798 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
799 const ModelHighAPI_RefAttr & theLine1,
800 const ModelHighAPI_RefAttr & theLine2)
802 std::shared_ptr<ModelAPI_Feature> aFeature =
803 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
804 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
805 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
807 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
810 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
811 const ModelHighAPI_RefAttr & theCircleOrArc,
812 const ModelHighAPI_Double & theValue)
814 std::shared_ptr<ModelAPI_Feature> aFeature =
815 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
816 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
817 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
819 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
822 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
823 const ModelHighAPI_RefAttr & theLine,
824 const ModelHighAPI_RefAttr & theCircle)
826 std::shared_ptr<ModelAPI_Feature> aFeature =
827 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
828 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
829 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
831 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
834 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
835 const ModelHighAPI_RefAttr & theLine)
837 std::shared_ptr<ModelAPI_Feature> aFeature =
838 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
839 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
841 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
844 //--------------------------------------------------------------------------------------
846 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
848 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
851 return std::shared_ptr<GeomAPI_Pnt2d>();
854 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
856 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
857 theFeature->attribute(SketchPlugin_Line::START_ID()));
858 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
859 theFeature->attribute(SketchPlugin_Line::END_ID()));
861 if (!aStartAttr || !aEndAttr)
862 return std::shared_ptr<GeomAPI_Pnt2d>();
864 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
865 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
866 return std::shared_ptr<GeomAPI_Pnt2d>(
867 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
870 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
872 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
873 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
874 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
876 if (!aCenter || !aRadius)
877 return std::shared_ptr<GeomAPI_Pnt2d>();
879 return std::shared_ptr<GeomAPI_Pnt2d>(
880 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
883 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
885 static const double PI = 3.141592653589793238463;
887 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
888 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
889 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
890 theFeature->attribute(SketchPlugin_Arc::START_ID()));
891 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
892 theFeature->attribute(SketchPlugin_Arc::END_ID()));
894 if (!aCenterAttr || !aStartAttr || !aEndAttr)
895 return std::shared_ptr<GeomAPI_Pnt2d>();
897 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
898 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
899 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
900 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
902 double anAngle = aStartDir->angle(aEndDir);
903 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
904 if (isReversed && anAngle > 0.)
906 else if (!isReversed && anAngle <= 0.)
909 double cosA = cos(anAngle);
910 double sinA = sin(anAngle);
912 // rotate start dir to find middle point on arc
913 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
914 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
915 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
917 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
920 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
922 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
924 const std::string& aFeatureKind = aFeature->getKind();
925 if (aFeatureKind == SketchPlugin_Point::ID())
926 return pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
927 else if (aFeatureKind == SketchPlugin_Line::ID())
928 return middlePointOnLine(aFeature);
929 else if (aFeatureKind == SketchPlugin_Circle::ID())
930 return pointOnCircle(aFeature);
931 else if (aFeatureKind == SketchPlugin_Arc::ID())
932 return middlePointOnArc(aFeature);
934 // do not move other types of features
935 return std::shared_ptr<GeomAPI_Pnt2d>();
938 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
939 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
941 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
942 theMovedEntity.fillMessage(aMessage);
944 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
945 if (aMessage->movedAttribute())
946 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
948 anOriginalPosition = middlePoint(aMessage->movedObject());
950 if (!anOriginalPosition)
951 return; // something has gone wrong, do not process movement
953 aMessage->setOriginalPosition(anOriginalPosition);
954 aMessage->setCurrentPosition(theTargetPoint);
955 Events_Loop::loop()->send(aMessage);
958 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
959 double theTargetX, double theTargetY)
961 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
962 move(theMovedEntity, aTargetPoint);
965 //--------------------------------------------------------------------------------------
967 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
969 FeaturePtr aBase = feature();
970 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
971 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
972 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
973 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
974 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
975 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
976 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
978 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
981 //--------------------------------------------------------------------------------------
983 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
985 FeaturePtr aBase = feature();
986 const std::string& aDocName = theDumper.name(aBase->document());
988 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
989 if (anExternal->value()) {
990 theDumper << aBase << " = model.addSketch(" << aDocName <<
991 ", " << anExternal << ")" << std::endl;
993 // Sketch is base on a plane.
994 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
995 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
996 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
997 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
998 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
999 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1001 // Check the plane is coordinate plane
1002 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1003 if(anExternal->context()) { // checking for selected planes
1004 if (!aPlaneName.empty()
1005 && anExternal->context()->data()
1006 && anExternal->context()->data()->name() == aPlaneName) {
1007 // dump sketch based on coordinate plane
1008 theDumper << aBase << " = model.addSketch(" << aDocName
1009 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1010 } else { // some other plane
1011 theDumper << aBase << " = model.addSketch(" << aDocName <<
1012 ", " << anExternal<< ")" << std::endl;
1015 if (aPlaneName.empty()) {
1016 // needs import additional module
1017 theDumper.importModule("GeomAPI");
1018 // dump plane parameters
1019 const std::string& aSketchName = theDumper.name(aBase);
1020 std::string anOriginName = aSketchName + "_origin";
1021 std::string aNormalName = aSketchName + "_norm";
1022 std::string aDirXName = aSketchName + "_dirx";
1023 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1024 // and then dumplicate dumping it in the next line
1025 theDumper << anOriginName << " = " << anOrigin << "\n"
1026 << aNormalName << " = " << aNormal << "\n"
1027 << aDirXName << " = " << aDirX << "\n";
1028 // dump sketch based on arbitrary plane
1029 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1030 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1032 // dump sketch based on coordinate plane
1033 theDumper << aBase << " = model.addSketch(" << aDocName
1034 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1039 // dump sketch's subfeatures
1040 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1041 theDumper.processSubs(aCompFeat, true);