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)
240 std::shared_ptr<ModelAPI_Feature> aFeature =
241 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
242 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
244 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
245 const std::string & theExternalName)
247 std::shared_ptr<ModelAPI_Feature> aFeature =
248 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
249 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
252 //--------------------------------------------------------------------------------------
253 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
254 double theX2, double theY2)
256 std::shared_ptr<ModelAPI_Feature> aFeature =
257 compositeFeature()->addFeature(SketchPlugin_Line::ID());
258 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
260 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
261 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
262 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
264 std::shared_ptr<ModelAPI_Feature> aFeature =
265 compositeFeature()->addFeature(SketchPlugin_Line::ID());
266 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
268 std::shared_ptr<SketchAPI_Line>
269 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
271 std::shared_ptr<ModelAPI_Feature> aFeature =
272 compositeFeature()->addFeature(SketchPlugin_Line::ID());
273 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
275 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
277 std::shared_ptr<ModelAPI_Feature> aFeature =
278 compositeFeature()->addFeature(SketchPlugin_Line::ID());
279 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
282 //--------------------------------------------------------------------------------------
283 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
284 double theX2, double theY2)
286 std::shared_ptr<ModelAPI_Feature> aFeature =
287 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
288 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
290 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
291 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
292 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
294 std::shared_ptr<ModelAPI_Feature> aFeature =
295 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
296 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
299 //--------------------------------------------------------------------------------------
300 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
304 std::shared_ptr<ModelAPI_Feature> aFeature =
305 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
306 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
309 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
310 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
313 std::shared_ptr<ModelAPI_Feature> aFeature =
314 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
315 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
318 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
323 std::shared_ptr<ModelAPI_Feature> aFeature =
324 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
325 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
326 thePassedX, thePassedY));
329 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
330 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
331 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
333 std::shared_ptr<ModelAPI_Feature> aFeature =
334 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
335 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
338 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
339 double theX2, double theY2,
340 double theX3, double theY3)
342 std::shared_ptr<ModelAPI_Feature> aFeature =
343 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
344 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
349 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
350 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
351 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
352 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
354 std::shared_ptr<ModelAPI_Feature> aFeature =
355 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
356 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
359 std::shared_ptr<SketchAPI_Circle>
360 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
362 std::shared_ptr<ModelAPI_Feature> aFeature =
363 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
364 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
367 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
369 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
370 std::shared_ptr<ModelAPI_Feature> aFeature =
371 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
372 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
375 //--------------------------------------------------------------------------------------
376 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
377 double theStartX, double theStartY,
378 double theEndX, double theEndY,
381 std::shared_ptr<ModelAPI_Feature> aFeature =
382 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
383 return ArcPtr(new SketchAPI_Arc(aFeature,
384 theCenterX, theCenterY,
385 theStartX, theStartY,
390 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
391 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
392 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
393 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
396 std::shared_ptr<ModelAPI_Feature> aFeature =
397 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
398 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
401 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
402 double theEndX, double theEndY,
403 double thePassedX, double thePassedY)
405 std::shared_ptr<ModelAPI_Feature> aFeature =
406 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
407 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
408 theStartX, theStartY,
410 thePassedX, thePassedY));
413 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
414 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
415 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
416 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
418 std::shared_ptr<ModelAPI_Feature> aFeature =
419 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
420 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
423 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
424 const ModelHighAPI_RefAttr& theTangentPoint,
425 double theEndX, double theEndY,
428 std::shared_ptr<ModelAPI_Feature> aFeature =
429 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
430 return MacroArcPtr(new SketchAPI_MacroArc(
431 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
434 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
435 const ModelHighAPI_RefAttr& theTangentPoint,
436 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
439 std::shared_ptr<ModelAPI_Feature> aFeature =
440 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
441 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
444 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
446 std::shared_ptr<ModelAPI_Feature> aFeature =
447 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
448 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
451 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
453 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
454 std::shared_ptr<ModelAPI_Feature> aFeature =
455 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
456 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
459 //--------------------------------------------------------------------------------------
460 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
461 const ModelHighAPI_Selection & theExternalFeature,
464 std::shared_ptr<ModelAPI_Feature> aFeature =
465 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
466 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
467 aProjection->setIncludeToResult(theKeepResult);
471 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
472 const std::string & theExternalName,
475 std::shared_ptr<ModelAPI_Feature> aFeature =
476 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
477 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
478 aProjection->setIncludeToResult(theKeepResult);
482 //--------------------------------------------------------------------------------------
483 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
484 const ModelHighAPI_RefAttr & theMirrorLine,
485 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
487 std::shared_ptr<ModelAPI_Feature> aFeature =
488 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
489 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
492 //--------------------------------------------------------------------------------------
493 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
494 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
495 const ModelHighAPI_RefAttr & thePoint1,
496 const ModelHighAPI_RefAttr & thePoint2,
497 const ModelHighAPI_Integer & theNumberOfObjects,
500 std::shared_ptr<ModelAPI_Feature> aFeature =
501 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
502 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
503 thePoint2, theNumberOfObjects, theFullValue));
506 //--------------------------------------------------------------------------------------
507 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
508 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
509 const ModelHighAPI_RefAttr & theCenter,
510 const ModelHighAPI_Double & theAngle,
511 const ModelHighAPI_Integer & theNumberOfObjects,
515 std::shared_ptr<ModelAPI_Feature> aFeature =
516 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
518 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
519 theAngle, theNumberOfObjects, theFullValue, theReversed));
522 //--------------------------------------------------------------------------------------
523 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
524 const ModelHighAPI_Reference& theFeature,
525 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
527 std::shared_ptr<ModelAPI_Feature> aFeature =
528 compositeFeature()->addFeature(SketchPlugin_Split::ID());
529 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
531 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
532 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
533 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
534 fillAttribute(thePositionPoint, aPointAttr);
537 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
540 //--------------------------------------------------------------------------------------
541 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
542 const ModelHighAPI_Reference& theFeature,
543 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
545 std::shared_ptr<ModelAPI_Feature> aFeature =
546 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
547 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
549 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
550 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
551 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
552 fillAttribute(thePositionPoint, aPointAttr);
555 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
558 //--------------------------------------------------------------------------------------
559 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
560 const ModelHighAPI_RefAttr & theLine1,
561 const ModelHighAPI_RefAttr & theLine2,
562 const ModelHighAPI_Double & theValue)
564 std::shared_ptr<ModelAPI_Feature> aFeature =
565 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
566 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
567 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
568 // fill the value before llines to avoid calculation of angle value by the Angle feature
569 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
570 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
571 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
573 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
576 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
577 const ModelHighAPI_RefAttr & theLine1,
578 const ModelHighAPI_RefAttr & theLine2,
579 const ModelHighAPI_Double & theValue)
581 std::shared_ptr<ModelAPI_Feature> aFeature =
582 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
583 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
584 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
585 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
586 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
587 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
588 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
590 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
593 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
594 const ModelHighAPI_RefAttr & theLine1,
595 const ModelHighAPI_RefAttr & theLine2,
596 const ModelHighAPI_Double & theValue)
598 std::shared_ptr<ModelAPI_Feature> aFeature =
599 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
600 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
601 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
602 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
603 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
604 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
605 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
607 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
610 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
611 const ModelHighAPI_RefAttr & thePoint1,
612 const ModelHighAPI_RefAttr & thePoint2)
614 std::shared_ptr<ModelAPI_Feature> aFeature =
615 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
616 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
617 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
619 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
622 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
623 const ModelHighAPI_RefAttr & theLine1,
624 const ModelHighAPI_RefAttr & theLine2)
626 std::shared_ptr<ModelAPI_Feature> aFeature =
627 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
628 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
629 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
631 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
634 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
635 const ModelHighAPI_RefAttr & thePoint,
636 const ModelHighAPI_RefAttr & thePointOrLine,
637 const ModelHighAPI_Double & theValue,
640 std::shared_ptr<ModelAPI_Feature> aFeature =
641 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
642 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
643 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
644 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
645 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
647 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
650 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
651 const ModelHighAPI_RefAttr & thePoint,
652 const ModelHighAPI_RefAttr & thePointOrLine,
653 const ModelHighAPI_Double & theValue)
655 return setDistance(thePoint, thePointOrLine, theValue, true);
658 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
659 const ModelHighAPI_RefAttr & thePoint,
660 const ModelHighAPI_RefAttr & thePointOrLine,
661 const ModelHighAPI_Double & theValue)
663 return setDistance(thePoint, thePointOrLine, theValue, false);
666 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
667 const ModelHighAPI_RefAttr & thePoint1,
668 const ModelHighAPI_RefAttr & thePoint2,
669 const ModelHighAPI_Double & theValue)
671 std::shared_ptr<ModelAPI_Feature> aFeature =
672 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
673 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
674 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
675 fillAttribute(theValue,
676 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
678 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
681 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
682 const ModelHighAPI_RefAttr & thePoint1,
683 const ModelHighAPI_RefAttr & thePoint2,
684 const ModelHighAPI_Double & theValue)
686 std::shared_ptr<ModelAPI_Feature> aFeature =
687 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
688 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
689 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
690 fillAttribute(theValue,
691 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
693 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
696 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
697 const ModelHighAPI_RefAttr & theObject1,
698 const ModelHighAPI_RefAttr & theObject2)
700 std::shared_ptr<ModelAPI_Feature> aFeature =
701 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
702 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
703 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
705 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
708 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
709 const ModelHighAPI_RefAttr & thePoint)
711 std::shared_ptr<ModelAPI_Feature> aFeature =
712 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
713 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
714 apply(); // finish operation to remove Fillet feature correcly
715 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
718 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
719 const ModelHighAPI_RefAttr & thePoint,
720 const ModelHighAPI_Double & theRadius)
722 CompositeFeaturePtr aSketch = compositeFeature();
723 int aNbSubs = aSketch->numberOfSubs();
726 InterfacePtr aFilletFeature = setFillet(thePoint);
728 // set radius for just created arc
729 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
730 if (anArc->getKind() == SketchPlugin_Arc::ID())
731 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
733 return aFilletFeature;
736 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
737 const ModelHighAPI_RefAttr & theObject)
739 std::shared_ptr<ModelAPI_Feature> aFeature =
740 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
741 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
743 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
746 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
747 const ModelHighAPI_RefAttr & theLine)
749 std::shared_ptr<ModelAPI_Feature> aFeature =
750 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
751 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
753 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
756 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
757 const ModelHighAPI_RefAttr & theLine,
758 const ModelHighAPI_Double & theValue)
760 std::shared_ptr<ModelAPI_Feature> aFeature =
761 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
762 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
763 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
765 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
768 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
769 const ModelHighAPI_RefAttr & thePoint,
770 const ModelHighAPI_RefAttr & theLine)
772 std::shared_ptr<ModelAPI_Feature> aFeature =
773 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
774 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
775 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
777 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
780 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
781 const ModelHighAPI_RefAttr & theLine1,
782 const ModelHighAPI_RefAttr & theLine2)
784 std::shared_ptr<ModelAPI_Feature> aFeature =
785 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
786 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
787 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
789 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
792 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
793 const ModelHighAPI_RefAttr & theLine1,
794 const ModelHighAPI_RefAttr & theLine2)
796 std::shared_ptr<ModelAPI_Feature> aFeature =
797 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
798 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
799 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
801 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
804 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
805 const ModelHighAPI_RefAttr & theCircleOrArc,
806 const ModelHighAPI_Double & theValue)
808 std::shared_ptr<ModelAPI_Feature> aFeature =
809 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
810 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
811 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
813 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
816 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
817 const ModelHighAPI_RefAttr & theLine,
818 const ModelHighAPI_RefAttr & theCircle)
820 std::shared_ptr<ModelAPI_Feature> aFeature =
821 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
822 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
823 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
825 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
828 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
829 const ModelHighAPI_RefAttr & theLine)
831 std::shared_ptr<ModelAPI_Feature> aFeature =
832 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
833 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
835 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
838 //--------------------------------------------------------------------------------------
840 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
842 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
845 return std::shared_ptr<GeomAPI_Pnt2d>();
848 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
850 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
851 theFeature->attribute(SketchPlugin_Line::START_ID()));
852 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
853 theFeature->attribute(SketchPlugin_Line::END_ID()));
855 if (!aStartAttr || !aEndAttr)
856 return std::shared_ptr<GeomAPI_Pnt2d>();
858 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
859 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
860 return std::shared_ptr<GeomAPI_Pnt2d>(
861 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
864 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
866 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
867 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
868 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
870 if (!aCenter || !aRadius)
871 return std::shared_ptr<GeomAPI_Pnt2d>();
873 return std::shared_ptr<GeomAPI_Pnt2d>(
874 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
877 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
879 static const double PI = 3.141592653589793238463;
881 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
882 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
883 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
884 theFeature->attribute(SketchPlugin_Arc::START_ID()));
885 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
886 theFeature->attribute(SketchPlugin_Arc::END_ID()));
888 if (!aCenterAttr || !aStartAttr || !aEndAttr)
889 return std::shared_ptr<GeomAPI_Pnt2d>();
891 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
892 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
893 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
894 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
896 double anAngle = aStartDir->angle(aEndDir);
897 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
898 if (isReversed && anAngle > 0.)
900 else if (!isReversed && anAngle <= 0.)
903 double cosA = cos(anAngle);
904 double sinA = sin(anAngle);
906 // rotate start dir to find middle point on arc
907 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
908 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
909 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
911 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
914 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
916 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
918 const std::string& aFeatureKind = aFeature->getKind();
919 if (aFeatureKind == SketchPlugin_Point::ID())
920 return pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
921 else if (aFeatureKind == SketchPlugin_Line::ID())
922 return middlePointOnLine(aFeature);
923 else if (aFeatureKind == SketchPlugin_Circle::ID())
924 return pointOnCircle(aFeature);
925 else if (aFeatureKind == SketchPlugin_Arc::ID())
926 return middlePointOnArc(aFeature);
928 // do not move other types of features
929 return std::shared_ptr<GeomAPI_Pnt2d>();
932 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
933 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
935 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
936 theMovedEntity.fillMessage(aMessage);
938 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
939 if (aMessage->movedAttribute())
940 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
942 anOriginalPosition = middlePoint(aMessage->movedObject());
944 if (!anOriginalPosition)
945 return; // something has gone wrong, do not process movement
947 aMessage->setOriginalPosition(anOriginalPosition);
948 aMessage->setCurrentPosition(theTargetPoint);
949 Events_Loop::loop()->send(aMessage);
952 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
953 double theTargetX, double theTargetY)
955 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
956 move(theMovedEntity, aTargetPoint);
959 //--------------------------------------------------------------------------------------
961 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
963 FeaturePtr aBase = feature();
964 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
965 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
966 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
967 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
968 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
969 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
970 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
972 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
975 //--------------------------------------------------------------------------------------
977 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
979 FeaturePtr aBase = feature();
980 const std::string& aDocName = theDumper.name(aBase->document());
982 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
983 if (anExternal->value()) {
984 theDumper << aBase << " = model.addSketch(" << aDocName <<
985 ", " << anExternal << ")" << std::endl;
987 // Sketch is base on a plane.
988 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
989 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
990 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
991 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
992 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
993 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
995 // Check the plane is coordinate plane
996 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
997 if(anExternal->context()) { // checking for selected planes
998 if (!aPlaneName.empty()
999 && anExternal->context()->data()
1000 && anExternal->context()->data()->name() == aPlaneName) {
1001 // dump sketch based on coordinate plane
1002 theDumper << aBase << " = model.addSketch(" << aDocName
1003 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1004 } else { // some other plane
1005 theDumper << aBase << " = model.addSketch(" << aDocName <<
1006 ", " << anExternal<< ")" << std::endl;
1009 if (aPlaneName.empty()) {
1010 // needs import additional module
1011 theDumper.importModule("GeomAPI");
1012 // dump plane parameters
1013 const std::string& aSketchName = theDumper.name(aBase);
1014 std::string anOriginName = aSketchName + "_origin";
1015 std::string aNormalName = aSketchName + "_norm";
1016 std::string aDirXName = aSketchName + "_dirx";
1017 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1018 // and then dumplicate dumping it in the next line
1019 theDumper << anOriginName << " = " << anOrigin << "\n"
1020 << aNormalName << " = " << aNormal << "\n"
1021 << aDirXName << " = " << aDirX << "\n";
1022 // dump sketch based on arbitrary plane
1023 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1024 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1026 // dump sketch based on coordinate plane
1027 theDumper << aBase << " = model.addSketch(" << aDocName
1028 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1033 // dump sketch's subfeatures
1034 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1035 theDumper.processSubs(aCompFeat, true);