1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "SketchAPI_Sketch.h"
21 //--------------------------------------------------------------------------------------
22 #include <SketchPlugin_Constraint.h>
23 #include <SketchPlugin_ConstraintAngle.h>
24 #include <SketchPlugin_ConstraintCoincidence.h>
25 #include <SketchPlugin_ConstraintCollinear.h>
26 #include <SketchPlugin_ConstraintDistance.h>
27 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
28 #include <SketchPlugin_ConstraintDistanceVertical.h>
29 #include <SketchPlugin_ConstraintEqual.h>
30 #include <SketchPlugin_Fillet.h>
31 #include <SketchPlugin_ConstraintHorizontal.h>
32 #include <SketchPlugin_ConstraintLength.h>
33 #include <SketchPlugin_ConstraintMiddle.h>
34 #include <SketchPlugin_ConstraintMirror.h>
35 #include <SketchPlugin_ConstraintParallel.h>
36 #include <SketchPlugin_ConstraintPerpendicular.h>
37 #include <SketchPlugin_ConstraintRadius.h>
38 #include <SketchPlugin_ConstraintRigid.h>
39 #include <SketchPlugin_Trim.h>
40 #include <SketchPlugin_Split.h>
41 #include <SketchPlugin_ConstraintTangent.h>
42 #include <SketchPlugin_ConstraintVertical.h>
43 #include <SketcherPrs_Tools.h>
44 //--------------------------------------------------------------------------------------
45 #include <ModelAPI_Events.h>
46 #include <ModelAPI_CompositeFeature.h>
47 #include <ModelAPI_ResultConstruction.h>
48 #include <ModelHighAPI_Double.h>
49 #include <ModelHighAPI_Dumper.h>
50 #include <ModelHighAPI_RefAttr.h>
51 #include <ModelHighAPI_Selection.h>
52 #include <ModelHighAPI_Services.h>
53 #include <ModelHighAPI_Tools.h>
54 //--------------------------------------------------------------------------------------
55 #include "SketchAPI_Arc.h"
56 #include "SketchAPI_MacroArc.h"
57 #include "SketchAPI_Circle.h"
58 #include "SketchAPI_IntersectionPoint.h"
59 #include "SketchAPI_Line.h"
60 #include "SketchAPI_MacroCircle.h"
61 #include "SketchAPI_Mirror.h"
62 #include "SketchAPI_Point.h"
63 #include "SketchAPI_Projection.h"
64 #include "SketchAPI_Rectangle.h"
65 #include "SketchAPI_Rotation.h"
66 #include "SketchAPI_Translation.h"
67 //--------------------------------------------------------------------------------------
68 #include <GeomAPI_Dir2d.h>
69 #include <GeomAPI_XY.h>
71 //--------------------------------------------------------------------------------------
72 SketchAPI_Sketch::SketchAPI_Sketch(
73 const std::shared_ptr<ModelAPI_Feature> & theFeature)
74 : ModelHighAPI_Interface(theFeature)
79 SketchAPI_Sketch::SketchAPI_Sketch(
80 const std::shared_ptr<ModelAPI_Feature> & theFeature,
81 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
82 : ModelHighAPI_Interface(theFeature)
89 SketchAPI_Sketch::SketchAPI_Sketch(
90 const std::shared_ptr<ModelAPI_Feature> & theFeature,
91 const ModelHighAPI_Selection & theExternal)
92 : ModelHighAPI_Interface(theFeature)
95 setExternal(theExternal);
99 SketchAPI_Sketch::SketchAPI_Sketch(
100 const std::shared_ptr<ModelAPI_Feature> & theFeature,
101 std::shared_ptr<ModelAPI_Object> thePlaneObject)
102 : ModelHighAPI_Interface(theFeature)
105 setExternal(thePlaneObject);
109 SketchAPI_Sketch::~SketchAPI_Sketch()
114 //--------------------------------------------------------------------------------------
115 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
117 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
120 //--------------------------------------------------------------------------------------
121 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
123 fillAttribute(thePlane->origin(), myorigin);
124 fillAttribute(thePlane->dirX(), mydirX);
125 fillAttribute(thePlane->normal(), mynormal);
130 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
132 fillAttribute(theExternal, myexternal);
137 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
139 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
140 ModelHighAPI_Selection aSel(aRes);
144 //--------------------------------------------------------------------------------------
145 void SketchAPI_Sketch::setValue(
146 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
147 const ModelHighAPI_Double & theValue)
149 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
151 // theConstraint->execute();
154 //--------------------------------------------------------------------------------------
155 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
157 const_cast<SketchAPI_Sketch*>(this)->execute();
159 std::list<ModelHighAPI_Selection> aSelectionList;
161 ResultConstructionPtr aResultConstruction =
162 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
163 if (aResultConstruction.get() == NULL)
164 return aSelectionList;
166 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
167 aSelectionList.push_back(
168 ModelHighAPI_Selection(aResultConstruction,
169 aResultConstruction->face(anIndex)));
172 return aSelectionList;
175 //--------------------------------------------------------------------------------------
176 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
177 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
179 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
180 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
183 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
184 const ModelHighAPI_Selection & theExternal)
186 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
187 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
190 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
191 const std::string & theExternalName)
193 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
195 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
198 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
199 std::shared_ptr<ModelAPI_Object> thePlaneObject)
201 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
202 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
206 //--------------------------------------------------------------------------------------
207 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
208 double theX, double theY)
210 std::shared_ptr<ModelAPI_Feature> aFeature =
211 compositeFeature()->addFeature(SketchPlugin_Point::ID());
212 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
214 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
215 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
217 std::shared_ptr<ModelAPI_Feature> aFeature =
218 compositeFeature()->addFeature(SketchPlugin_Point::ID());
219 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
221 std::shared_ptr<SketchAPI_Point>
222 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
224 std::shared_ptr<ModelAPI_Feature> aFeature =
225 compositeFeature()->addFeature(SketchPlugin_Point::ID());
226 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
228 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
230 std::shared_ptr<ModelAPI_Feature> aFeature =
231 compositeFeature()->addFeature(SketchPlugin_Point::ID());
232 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
235 //--------------------------------------------------------------------------------------
236 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
237 const ModelHighAPI_Selection & theExternal,
240 std::shared_ptr<ModelAPI_Feature> aFeature =
241 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
242 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
243 anIntersection->setIncludeToResult(theKeepResult);
244 return anIntersection;
246 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
247 const std::string & theExternalName,
250 std::shared_ptr<ModelAPI_Feature> aFeature =
251 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
252 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
253 anIntersection->setIncludeToResult(theKeepResult);
254 return anIntersection;
257 //--------------------------------------------------------------------------------------
258 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
259 double theX2, double theY2)
261 std::shared_ptr<ModelAPI_Feature> aFeature =
262 compositeFeature()->addFeature(SketchPlugin_Line::ID());
263 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
265 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
266 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
267 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
269 std::shared_ptr<ModelAPI_Feature> aFeature =
270 compositeFeature()->addFeature(SketchPlugin_Line::ID());
271 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
273 std::shared_ptr<SketchAPI_Line>
274 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
276 std::shared_ptr<ModelAPI_Feature> aFeature =
277 compositeFeature()->addFeature(SketchPlugin_Line::ID());
278 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
280 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
282 std::shared_ptr<ModelAPI_Feature> aFeature =
283 compositeFeature()->addFeature(SketchPlugin_Line::ID());
284 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
287 //--------------------------------------------------------------------------------------
288 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
289 double theX2, double theY2)
291 std::shared_ptr<ModelAPI_Feature> aFeature =
292 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
293 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
295 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
296 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
297 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
299 std::shared_ptr<ModelAPI_Feature> aFeature =
300 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
301 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
304 //--------------------------------------------------------------------------------------
305 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
309 std::shared_ptr<ModelAPI_Feature> aFeature =
310 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
311 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
314 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
315 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
318 std::shared_ptr<ModelAPI_Feature> aFeature =
319 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
320 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
323 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
328 std::shared_ptr<ModelAPI_Feature> aFeature =
329 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
330 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
331 thePassedX, thePassedY));
334 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
335 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
336 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
338 std::shared_ptr<ModelAPI_Feature> aFeature =
339 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
340 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
343 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
344 double theX2, double theY2,
345 double theX3, double theY3)
347 std::shared_ptr<ModelAPI_Feature> aFeature =
348 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
349 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
354 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
355 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
356 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
357 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
359 std::shared_ptr<ModelAPI_Feature> aFeature =
360 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
361 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
364 std::shared_ptr<SketchAPI_Circle>
365 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
367 std::shared_ptr<ModelAPI_Feature> aFeature =
368 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
369 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
372 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
374 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
375 std::shared_ptr<ModelAPI_Feature> aFeature =
376 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
377 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
380 //--------------------------------------------------------------------------------------
381 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
382 double theStartX, double theStartY,
383 double theEndX, double theEndY,
386 std::shared_ptr<ModelAPI_Feature> aFeature =
387 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
388 return ArcPtr(new SketchAPI_Arc(aFeature,
389 theCenterX, theCenterY,
390 theStartX, theStartY,
395 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
396 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
397 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
398 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
401 std::shared_ptr<ModelAPI_Feature> aFeature =
402 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
403 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
406 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
407 double theEndX, double theEndY,
408 double thePassedX, double thePassedY)
410 std::shared_ptr<ModelAPI_Feature> aFeature =
411 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
412 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
413 theStartX, theStartY,
415 thePassedX, thePassedY));
418 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
419 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
420 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
421 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
423 std::shared_ptr<ModelAPI_Feature> aFeature =
424 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
425 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
428 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
429 const ModelHighAPI_RefAttr& theTangentPoint,
430 double theEndX, double theEndY,
433 std::shared_ptr<ModelAPI_Feature> aFeature =
434 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
435 return MacroArcPtr(new SketchAPI_MacroArc(
436 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
439 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
440 const ModelHighAPI_RefAttr& theTangentPoint,
441 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
444 std::shared_ptr<ModelAPI_Feature> aFeature =
445 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
446 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
449 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
451 std::shared_ptr<ModelAPI_Feature> aFeature =
452 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
453 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
456 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
458 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
459 std::shared_ptr<ModelAPI_Feature> aFeature =
460 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
461 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
464 //--------------------------------------------------------------------------------------
465 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
466 const ModelHighAPI_Selection & theExternalFeature,
469 std::shared_ptr<ModelAPI_Feature> aFeature =
470 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
471 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
472 aProjection->setIncludeToResult(theKeepResult);
476 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
477 const std::string & theExternalName,
480 std::shared_ptr<ModelAPI_Feature> aFeature =
481 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
482 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
483 aProjection->setIncludeToResult(theKeepResult);
487 //--------------------------------------------------------------------------------------
488 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
489 const ModelHighAPI_RefAttr & theMirrorLine,
490 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
492 std::shared_ptr<ModelAPI_Feature> aFeature =
493 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
494 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
497 //--------------------------------------------------------------------------------------
498 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
499 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
500 const ModelHighAPI_RefAttr & thePoint1,
501 const ModelHighAPI_RefAttr & thePoint2,
502 const ModelHighAPI_Integer & theNumberOfObjects,
505 std::shared_ptr<ModelAPI_Feature> aFeature =
506 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
507 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
508 thePoint2, theNumberOfObjects, theFullValue));
511 //--------------------------------------------------------------------------------------
512 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
513 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
514 const ModelHighAPI_RefAttr & theCenter,
515 const ModelHighAPI_Double & theAngle,
516 const ModelHighAPI_Integer & theNumberOfObjects,
520 std::shared_ptr<ModelAPI_Feature> aFeature =
521 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
523 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
524 theAngle, theNumberOfObjects, theFullValue, theReversed));
527 //--------------------------------------------------------------------------------------
528 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
529 const ModelHighAPI_Reference& theFeature,
530 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
532 std::shared_ptr<ModelAPI_Feature> aFeature =
533 compositeFeature()->addFeature(SketchPlugin_Split::ID());
534 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
536 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
537 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
538 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
539 fillAttribute(thePositionPoint, aPointAttr);
542 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
545 //--------------------------------------------------------------------------------------
546 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
547 const ModelHighAPI_Reference& theFeature,
548 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
550 std::shared_ptr<ModelAPI_Feature> aFeature =
551 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
552 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
554 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
555 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
556 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
557 fillAttribute(thePositionPoint, aPointAttr);
560 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
563 //--------------------------------------------------------------------------------------
564 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
565 const ModelHighAPI_RefAttr & theLine1,
566 const ModelHighAPI_RefAttr & theLine2,
567 const ModelHighAPI_Double & theValue)
569 std::shared_ptr<ModelAPI_Feature> aFeature =
570 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
571 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
572 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
573 // fill the value before llines to avoid calculation of angle value by the Angle feature
574 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
575 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
576 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
578 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
581 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
582 const ModelHighAPI_RefAttr & theLine1,
583 const ModelHighAPI_RefAttr & theLine2,
584 const ModelHighAPI_Double & theValue)
586 std::shared_ptr<ModelAPI_Feature> aFeature =
587 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
588 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
589 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
590 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
591 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
592 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
594 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
597 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
598 const ModelHighAPI_RefAttr & theLine1,
599 const ModelHighAPI_RefAttr & theLine2,
600 const ModelHighAPI_Double & theValue)
602 std::shared_ptr<ModelAPI_Feature> aFeature =
603 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
604 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
605 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
606 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
607 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
608 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
610 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
613 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
614 const ModelHighAPI_RefAttr & thePoint1,
615 const ModelHighAPI_RefAttr & thePoint2)
617 std::shared_ptr<ModelAPI_Feature> aFeature =
618 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
619 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
620 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
622 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
625 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
626 const ModelHighAPI_RefAttr & theLine1,
627 const ModelHighAPI_RefAttr & theLine2)
629 std::shared_ptr<ModelAPI_Feature> aFeature =
630 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
631 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
632 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
634 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
637 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
638 const ModelHighAPI_RefAttr & thePoint,
639 const ModelHighAPI_RefAttr & thePointOrLine,
640 const ModelHighAPI_Double & theValue,
643 std::shared_ptr<ModelAPI_Feature> aFeature =
644 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
645 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
646 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
647 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
648 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
650 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
653 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
654 const ModelHighAPI_RefAttr & thePoint,
655 const ModelHighAPI_RefAttr & thePointOrLine,
656 const ModelHighAPI_Double & theValue)
658 return setDistance(thePoint, thePointOrLine, theValue, true);
661 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
662 const ModelHighAPI_RefAttr & thePoint,
663 const ModelHighAPI_RefAttr & thePointOrLine,
664 const ModelHighAPI_Double & theValue)
666 return setDistance(thePoint, thePointOrLine, theValue, false);
669 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
670 const ModelHighAPI_RefAttr & thePoint1,
671 const ModelHighAPI_RefAttr & thePoint2,
672 const ModelHighAPI_Double & theValue)
674 std::shared_ptr<ModelAPI_Feature> aFeature =
675 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
676 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
677 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
678 fillAttribute(theValue,
679 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
681 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
684 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
685 const ModelHighAPI_RefAttr & thePoint1,
686 const ModelHighAPI_RefAttr & thePoint2,
687 const ModelHighAPI_Double & theValue)
689 std::shared_ptr<ModelAPI_Feature> aFeature =
690 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
691 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
692 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
693 fillAttribute(theValue,
694 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
696 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
699 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
700 const ModelHighAPI_RefAttr & theObject1,
701 const ModelHighAPI_RefAttr & theObject2)
703 std::shared_ptr<ModelAPI_Feature> aFeature =
704 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
705 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
706 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
708 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
711 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
712 const ModelHighAPI_RefAttr & thePoint)
714 std::shared_ptr<ModelAPI_Feature> aFeature =
715 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
716 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
717 apply(); // finish operation to remove Fillet feature correcly
718 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
721 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
722 const ModelHighAPI_RefAttr & thePoint,
723 const ModelHighAPI_Double & theRadius)
725 CompositeFeaturePtr aSketch = compositeFeature();
726 int aNbSubs = aSketch->numberOfSubs();
729 InterfacePtr aFilletFeature = setFillet(thePoint);
731 // set radius for just created arc
732 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
733 if (anArc->getKind() == SketchPlugin_Arc::ID())
734 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
736 return aFilletFeature;
739 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
740 const ModelHighAPI_RefAttr & theObject)
742 std::shared_ptr<ModelAPI_Feature> aFeature =
743 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
744 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
746 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
749 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
750 const ModelHighAPI_RefAttr & theLine)
752 std::shared_ptr<ModelAPI_Feature> aFeature =
753 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
754 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
756 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
759 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
760 const ModelHighAPI_RefAttr & theLine,
761 const ModelHighAPI_Double & theValue)
763 std::shared_ptr<ModelAPI_Feature> aFeature =
764 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
765 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
766 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
768 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
771 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
772 const ModelHighAPI_RefAttr & thePoint,
773 const ModelHighAPI_RefAttr & theLine)
775 std::shared_ptr<ModelAPI_Feature> aFeature =
776 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
777 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
778 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
780 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
783 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
784 const ModelHighAPI_RefAttr & theLine1,
785 const ModelHighAPI_RefAttr & theLine2)
787 std::shared_ptr<ModelAPI_Feature> aFeature =
788 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
789 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
790 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
792 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
795 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
796 const ModelHighAPI_RefAttr & theLine1,
797 const ModelHighAPI_RefAttr & theLine2)
799 std::shared_ptr<ModelAPI_Feature> aFeature =
800 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
801 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
802 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
804 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
807 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
808 const ModelHighAPI_RefAttr & theCircleOrArc,
809 const ModelHighAPI_Double & theValue)
811 std::shared_ptr<ModelAPI_Feature> aFeature =
812 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
813 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
814 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
816 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
819 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
820 const ModelHighAPI_RefAttr & theLine,
821 const ModelHighAPI_RefAttr & theCircle)
823 std::shared_ptr<ModelAPI_Feature> aFeature =
824 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
825 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
826 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
828 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
831 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
832 const ModelHighAPI_RefAttr & theLine)
834 std::shared_ptr<ModelAPI_Feature> aFeature =
835 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
836 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
838 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
841 //--------------------------------------------------------------------------------------
843 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
845 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
846 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
849 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
851 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
852 theFeature->attribute(SketchPlugin_Line::START_ID()));
853 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
854 theFeature->attribute(SketchPlugin_Line::END_ID()));
856 if (!aStartAttr || !aEndAttr)
857 return std::shared_ptr<GeomAPI_Pnt2d>();
859 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
860 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
861 return std::shared_ptr<GeomAPI_Pnt2d>(
862 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
865 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
867 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
868 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
869 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
871 if (!aCenter || !aRadius)
872 return std::shared_ptr<GeomAPI_Pnt2d>();
874 return std::shared_ptr<GeomAPI_Pnt2d>(
875 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
878 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
880 static const double PI = 3.141592653589793238463;
882 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
883 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
884 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
885 theFeature->attribute(SketchPlugin_Arc::START_ID()));
886 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
887 theFeature->attribute(SketchPlugin_Arc::END_ID()));
889 if (!aCenterAttr || !aStartAttr || !aEndAttr)
890 return std::shared_ptr<GeomAPI_Pnt2d>();
892 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
893 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
894 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
895 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
897 double anAngle = aStartDir->angle(aEndDir);
898 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
899 if (isReversed && anAngle > 0.)
901 else if (!isReversed && anAngle <= 0.)
904 double cosA = cos(anAngle);
905 double sinA = sin(anAngle);
907 // rotate start dir to find middle point on arc
908 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
909 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
910 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
912 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
915 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
917 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
918 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
920 // move only features of the following types
921 const std::string& aFeatureKind = aFeature->getKind();
922 if (aFeatureKind == SketchPlugin_Point::ID())
923 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
924 else if (aFeatureKind == SketchPlugin_Line::ID())
925 aMiddlePoint = middlePointOnLine(aFeature);
926 else if (aFeatureKind == SketchPlugin_Circle::ID())
927 aMiddlePoint = pointOnCircle(aFeature);
928 else if (aFeatureKind == SketchPlugin_Arc::ID())
929 aMiddlePoint = middlePointOnArc(aFeature);
934 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
935 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
937 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
938 theMovedEntity.fillMessage(aMessage);
940 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
941 if (aMessage->movedAttribute())
942 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
944 anOriginalPosition = middlePoint(aMessage->movedObject());
946 if (!anOriginalPosition)
947 return; // something has gone wrong, do not process movement
949 aMessage->setOriginalPosition(anOriginalPosition);
950 aMessage->setCurrentPosition(theTargetPoint);
951 Events_Loop::loop()->send(aMessage);
954 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
955 double theTargetX, double theTargetY)
957 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
958 move(theMovedEntity, aTargetPoint);
961 //--------------------------------------------------------------------------------------
963 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
965 FeaturePtr aBase = feature();
966 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
967 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
968 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
969 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
970 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
971 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
972 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
974 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
977 //--------------------------------------------------------------------------------------
979 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
981 FeaturePtr aBase = feature();
982 const std::string& aDocName = theDumper.name(aBase->document());
984 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
985 if (anExternal->value()) {
986 theDumper << aBase << " = model.addSketch(" << aDocName <<
987 ", " << anExternal << ")" << std::endl;
989 // Sketch is base on a plane.
990 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
991 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
992 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
993 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
994 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
995 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
997 // Check the plane is coordinate plane
998 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
999 if(anExternal->context()) { // checking for selected planes
1000 if (!aPlaneName.empty()
1001 && anExternal->context()->data()
1002 && anExternal->context()->data()->name() == aPlaneName) {
1003 // dump sketch based on coordinate plane
1004 theDumper << aBase << " = model.addSketch(" << aDocName
1005 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1006 } else { // some other plane
1007 theDumper << aBase << " = model.addSketch(" << aDocName <<
1008 ", " << anExternal<< ")" << std::endl;
1011 if (aPlaneName.empty()) {
1012 // needs import additional module
1013 theDumper.importModule("GeomAPI");
1014 // dump plane parameters
1015 const std::string& aSketchName = theDumper.name(aBase);
1016 std::string anOriginName = aSketchName + "_origin";
1017 std::string aNormalName = aSketchName + "_norm";
1018 std::string aDirXName = aSketchName + "_dirx";
1019 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1020 // and then dumplicate dumping it in the next line
1021 theDumper << anOriginName << " = " << anOrigin << "\n"
1022 << aNormalName << " = " << aNormal << "\n"
1023 << aDirXName << " = " << aDirX << "\n";
1024 // dump sketch based on arbitrary plane
1025 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1026 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1028 // dump sketch based on coordinate plane
1029 theDumper << aBase << " = model.addSketch(" << aDocName
1030 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1035 // dump sketch's subfeatures
1036 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1037 theDumper.processSubs(aCompFeat, true);