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::setPlane(const ModelHighAPI_Selection & thePlane,
131 bool theRemoveExternalDependency)
133 std::shared_ptr<SketchPlugin_Sketch> aSketch =
134 std::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
136 DocumentPtr aDoc = aSketch->document();
137 bool useVisible = false;
138 FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
139 aDoc->setCurrentFeature(aSketch, useVisible);
141 if (theRemoveExternalDependency)
142 aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
144 setExternal(thePlane);
146 aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
149 //--------------------------------------------------------------------------------------
150 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
152 fillAttribute(theExternal, myexternal);
157 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
159 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
160 ModelHighAPI_Selection aSel(aRes);
164 //--------------------------------------------------------------------------------------
165 void SketchAPI_Sketch::setValue(
166 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
167 const ModelHighAPI_Double & theValue)
169 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
171 // theConstraint->execute();
174 //--------------------------------------------------------------------------------------
175 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
177 const_cast<SketchAPI_Sketch*>(this)->execute();
179 std::list<ModelHighAPI_Selection> aSelectionList;
181 ResultConstructionPtr aResultConstruction =
182 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
183 if (aResultConstruction.get() == NULL)
184 return aSelectionList;
186 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
187 aSelectionList.push_back(
188 ModelHighAPI_Selection(aResultConstruction,
189 aResultConstruction->face(anIndex)));
192 return aSelectionList;
195 //--------------------------------------------------------------------------------------
196 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
197 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
199 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
200 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
203 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
204 const ModelHighAPI_Selection & theExternal)
206 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
207 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
210 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
211 const std::string & theExternalName)
213 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
215 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
218 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
219 std::shared_ptr<ModelAPI_Object> thePlaneObject)
221 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
222 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
226 //--------------------------------------------------------------------------------------
227 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
228 double theX, double theY)
230 std::shared_ptr<ModelAPI_Feature> aFeature =
231 compositeFeature()->addFeature(SketchPlugin_Point::ID());
232 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
234 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
235 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
237 std::shared_ptr<ModelAPI_Feature> aFeature =
238 compositeFeature()->addFeature(SketchPlugin_Point::ID());
239 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
241 std::shared_ptr<SketchAPI_Point>
242 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
244 std::shared_ptr<ModelAPI_Feature> aFeature =
245 compositeFeature()->addFeature(SketchPlugin_Point::ID());
246 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
248 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
250 std::shared_ptr<ModelAPI_Feature> aFeature =
251 compositeFeature()->addFeature(SketchPlugin_Point::ID());
252 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
255 //--------------------------------------------------------------------------------------
256 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
257 const ModelHighAPI_Selection & theExternal,
260 std::shared_ptr<ModelAPI_Feature> aFeature =
261 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
262 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
263 anIntersection->setIncludeToResult(theKeepResult);
264 return anIntersection;
266 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
267 const std::string & theExternalName,
270 std::shared_ptr<ModelAPI_Feature> aFeature =
271 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
272 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
273 anIntersection->setIncludeToResult(theKeepResult);
274 return anIntersection;
277 //--------------------------------------------------------------------------------------
278 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
279 double theX2, double theY2)
281 std::shared_ptr<ModelAPI_Feature> aFeature =
282 compositeFeature()->addFeature(SketchPlugin_Line::ID());
283 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
285 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
286 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
287 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
289 std::shared_ptr<ModelAPI_Feature> aFeature =
290 compositeFeature()->addFeature(SketchPlugin_Line::ID());
291 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
293 std::shared_ptr<SketchAPI_Line>
294 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
296 std::shared_ptr<ModelAPI_Feature> aFeature =
297 compositeFeature()->addFeature(SketchPlugin_Line::ID());
298 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
300 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
302 std::shared_ptr<ModelAPI_Feature> aFeature =
303 compositeFeature()->addFeature(SketchPlugin_Line::ID());
304 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
307 //--------------------------------------------------------------------------------------
308 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
309 double theX2, double theY2)
311 std::shared_ptr<ModelAPI_Feature> aFeature =
312 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
313 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
315 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
316 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
317 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
319 std::shared_ptr<ModelAPI_Feature> aFeature =
320 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
321 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
324 //--------------------------------------------------------------------------------------
325 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
329 std::shared_ptr<ModelAPI_Feature> aFeature =
330 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
331 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
334 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
335 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
338 std::shared_ptr<ModelAPI_Feature> aFeature =
339 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
340 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
343 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
348 std::shared_ptr<ModelAPI_Feature> aFeature =
349 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
350 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
351 thePassedX, thePassedY));
354 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
355 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
356 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
358 std::shared_ptr<ModelAPI_Feature> aFeature =
359 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
360 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
363 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
364 double theX2, double theY2,
365 double theX3, double theY3)
367 std::shared_ptr<ModelAPI_Feature> aFeature =
368 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
369 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
374 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
375 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
376 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
377 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
379 std::shared_ptr<ModelAPI_Feature> aFeature =
380 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
381 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
384 std::shared_ptr<SketchAPI_Circle>
385 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
387 std::shared_ptr<ModelAPI_Feature> aFeature =
388 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
389 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
392 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
394 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
395 std::shared_ptr<ModelAPI_Feature> aFeature =
396 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
397 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
400 //--------------------------------------------------------------------------------------
401 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
402 double theStartX, double theStartY,
403 double theEndX, double theEndY,
406 std::shared_ptr<ModelAPI_Feature> aFeature =
407 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
408 return ArcPtr(new SketchAPI_Arc(aFeature,
409 theCenterX, theCenterY,
410 theStartX, theStartY,
415 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
416 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
417 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
418 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
421 std::shared_ptr<ModelAPI_Feature> aFeature =
422 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
423 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
426 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
427 double theEndX, double theEndY,
428 double thePassedX, double thePassedY)
430 std::shared_ptr<ModelAPI_Feature> aFeature =
431 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
432 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
433 theStartX, theStartY,
435 thePassedX, thePassedY));
438 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
439 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
440 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
441 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
443 std::shared_ptr<ModelAPI_Feature> aFeature =
444 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
445 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
448 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
449 const ModelHighAPI_RefAttr& theTangentPoint,
450 double theEndX, double theEndY,
453 std::shared_ptr<ModelAPI_Feature> aFeature =
454 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
455 return MacroArcPtr(new SketchAPI_MacroArc(
456 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
459 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
460 const ModelHighAPI_RefAttr& theTangentPoint,
461 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
464 std::shared_ptr<ModelAPI_Feature> aFeature =
465 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
466 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
469 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
471 std::shared_ptr<ModelAPI_Feature> aFeature =
472 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
473 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
476 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
478 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
479 std::shared_ptr<ModelAPI_Feature> aFeature =
480 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
481 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
484 //--------------------------------------------------------------------------------------
485 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
486 const ModelHighAPI_Selection & theExternalFeature,
489 std::shared_ptr<ModelAPI_Feature> aFeature =
490 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
491 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
492 aProjection->setIncludeToResult(theKeepResult);
496 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
497 const std::string & theExternalName,
500 std::shared_ptr<ModelAPI_Feature> aFeature =
501 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
502 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
503 aProjection->setIncludeToResult(theKeepResult);
507 //--------------------------------------------------------------------------------------
508 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
509 const ModelHighAPI_RefAttr & theMirrorLine,
510 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
512 std::shared_ptr<ModelAPI_Feature> aFeature =
513 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
514 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
517 //--------------------------------------------------------------------------------------
518 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
519 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
520 const ModelHighAPI_RefAttr & thePoint1,
521 const ModelHighAPI_RefAttr & thePoint2,
522 const ModelHighAPI_Integer & theNumberOfObjects,
525 std::shared_ptr<ModelAPI_Feature> aFeature =
526 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
527 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
528 thePoint2, theNumberOfObjects, theFullValue));
531 //--------------------------------------------------------------------------------------
532 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
533 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
534 const ModelHighAPI_RefAttr & theCenter,
535 const ModelHighAPI_Double & theAngle,
536 const ModelHighAPI_Integer & theNumberOfObjects,
540 std::shared_ptr<ModelAPI_Feature> aFeature =
541 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
543 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
544 theAngle, theNumberOfObjects, theFullValue, theReversed));
547 //--------------------------------------------------------------------------------------
548 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
549 const ModelHighAPI_Reference& theFeature,
550 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
552 std::shared_ptr<ModelAPI_Feature> aFeature =
553 compositeFeature()->addFeature(SketchPlugin_Split::ID());
554 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
556 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
557 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
558 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
559 fillAttribute(thePositionPoint, aPointAttr);
562 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
565 //--------------------------------------------------------------------------------------
566 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
567 const ModelHighAPI_Reference& theFeature,
568 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
570 std::shared_ptr<ModelAPI_Feature> aFeature =
571 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
572 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
574 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
575 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
576 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
577 fillAttribute(thePositionPoint, aPointAttr);
580 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
583 //--------------------------------------------------------------------------------------
584 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
585 const ModelHighAPI_RefAttr & theLine1,
586 const ModelHighAPI_RefAttr & theLine2,
587 const ModelHighAPI_Double & theValue)
589 std::shared_ptr<ModelAPI_Feature> aFeature =
590 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
591 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
592 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
593 // fill the value before llines to avoid calculation of angle value by the Angle feature
594 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
595 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
596 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
598 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
601 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
602 const ModelHighAPI_RefAttr & theLine1,
603 const ModelHighAPI_RefAttr & theLine2,
604 const ModelHighAPI_Double & theValue)
606 std::shared_ptr<ModelAPI_Feature> aFeature =
607 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
608 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
609 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
610 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
611 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
612 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
614 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
617 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
618 const ModelHighAPI_RefAttr & theLine1,
619 const ModelHighAPI_RefAttr & theLine2,
620 const ModelHighAPI_Double & theValue)
622 std::shared_ptr<ModelAPI_Feature> aFeature =
623 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
624 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
625 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
626 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
627 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
628 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
630 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
633 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
634 const ModelHighAPI_RefAttr & thePoint1,
635 const ModelHighAPI_RefAttr & thePoint2)
637 std::shared_ptr<ModelAPI_Feature> aFeature =
638 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
639 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
640 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
642 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
645 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
646 const ModelHighAPI_RefAttr & theLine1,
647 const ModelHighAPI_RefAttr & theLine2)
649 std::shared_ptr<ModelAPI_Feature> aFeature =
650 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
651 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
652 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
654 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
657 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
658 const ModelHighAPI_RefAttr & thePoint,
659 const ModelHighAPI_RefAttr & thePointOrLine,
660 const ModelHighAPI_Double & theValue,
663 std::shared_ptr<ModelAPI_Feature> aFeature =
664 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
665 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
666 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
667 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
668 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
670 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
673 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
674 const ModelHighAPI_RefAttr & thePoint,
675 const ModelHighAPI_RefAttr & thePointOrLine,
676 const ModelHighAPI_Double & theValue)
678 return setDistance(thePoint, thePointOrLine, theValue, true);
681 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
682 const ModelHighAPI_RefAttr & thePoint,
683 const ModelHighAPI_RefAttr & thePointOrLine,
684 const ModelHighAPI_Double & theValue)
686 return setDistance(thePoint, thePointOrLine, theValue, false);
689 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
690 const ModelHighAPI_RefAttr & thePoint1,
691 const ModelHighAPI_RefAttr & thePoint2,
692 const ModelHighAPI_Double & theValue)
694 std::shared_ptr<ModelAPI_Feature> aFeature =
695 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
696 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
697 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
698 fillAttribute(theValue,
699 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
701 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
704 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
705 const ModelHighAPI_RefAttr & thePoint1,
706 const ModelHighAPI_RefAttr & thePoint2,
707 const ModelHighAPI_Double & theValue)
709 std::shared_ptr<ModelAPI_Feature> aFeature =
710 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
711 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
712 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
713 fillAttribute(theValue,
714 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
716 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
719 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
720 const ModelHighAPI_RefAttr & theObject1,
721 const ModelHighAPI_RefAttr & theObject2)
723 std::shared_ptr<ModelAPI_Feature> aFeature =
724 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
725 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
726 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
728 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
731 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
732 const ModelHighAPI_RefAttr & thePoint)
734 std::shared_ptr<ModelAPI_Feature> aFeature =
735 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
736 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
737 apply(); // finish operation to remove Fillet feature correcly
738 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
741 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
742 const ModelHighAPI_RefAttr & thePoint,
743 const ModelHighAPI_Double & theRadius)
745 CompositeFeaturePtr aSketch = compositeFeature();
746 int aNbSubs = aSketch->numberOfSubs();
749 InterfacePtr aFilletFeature = setFillet(thePoint);
751 // set radius for just created arc
752 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
753 if (anArc->getKind() == SketchPlugin_Arc::ID())
754 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
756 return aFilletFeature;
759 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
760 const ModelHighAPI_RefAttr & theObject)
762 std::shared_ptr<ModelAPI_Feature> aFeature =
763 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
764 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
766 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
769 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
770 const ModelHighAPI_RefAttr & theLine)
772 std::shared_ptr<ModelAPI_Feature> aFeature =
773 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
774 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
776 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
779 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
780 const ModelHighAPI_RefAttr & theLine,
781 const ModelHighAPI_Double & theValue)
783 std::shared_ptr<ModelAPI_Feature> aFeature =
784 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
785 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
786 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
788 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
791 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
792 const ModelHighAPI_RefAttr & thePoint,
793 const ModelHighAPI_RefAttr & theLine)
795 std::shared_ptr<ModelAPI_Feature> aFeature =
796 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
797 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
798 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
800 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
803 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
804 const ModelHighAPI_RefAttr & theLine1,
805 const ModelHighAPI_RefAttr & theLine2)
807 std::shared_ptr<ModelAPI_Feature> aFeature =
808 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
809 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
810 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
812 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
815 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
816 const ModelHighAPI_RefAttr & theLine1,
817 const ModelHighAPI_RefAttr & theLine2)
819 std::shared_ptr<ModelAPI_Feature> aFeature =
820 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
821 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
822 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
824 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
827 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
828 const ModelHighAPI_RefAttr & theCircleOrArc,
829 const ModelHighAPI_Double & theValue)
831 std::shared_ptr<ModelAPI_Feature> aFeature =
832 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
833 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
834 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
836 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
839 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
840 const ModelHighAPI_RefAttr & theLine,
841 const ModelHighAPI_RefAttr & theCircle)
843 std::shared_ptr<ModelAPI_Feature> aFeature =
844 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
845 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
846 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
848 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
851 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
852 const ModelHighAPI_RefAttr & theLine)
854 std::shared_ptr<ModelAPI_Feature> aFeature =
855 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
856 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
858 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
861 //--------------------------------------------------------------------------------------
863 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
865 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
866 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
869 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
871 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
872 theFeature->attribute(SketchPlugin_Line::START_ID()));
873 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
874 theFeature->attribute(SketchPlugin_Line::END_ID()));
876 if (!aStartAttr || !aEndAttr)
877 return std::shared_ptr<GeomAPI_Pnt2d>();
879 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
880 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
881 return std::shared_ptr<GeomAPI_Pnt2d>(
882 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
885 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
887 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
888 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
889 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
891 if (!aCenter || !aRadius)
892 return std::shared_ptr<GeomAPI_Pnt2d>();
894 return std::shared_ptr<GeomAPI_Pnt2d>(
895 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
898 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
900 static const double PI = 3.141592653589793238463;
902 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
903 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
904 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
905 theFeature->attribute(SketchPlugin_Arc::START_ID()));
906 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
907 theFeature->attribute(SketchPlugin_Arc::END_ID()));
909 if (!aCenterAttr || !aStartAttr || !aEndAttr)
910 return std::shared_ptr<GeomAPI_Pnt2d>();
912 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
913 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
914 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
915 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
917 double anAngle = aStartDir->angle(aEndDir);
918 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
919 if (isReversed && anAngle > 0.)
921 else if (!isReversed && anAngle <= 0.)
924 double cosA = cos(anAngle);
925 double sinA = sin(anAngle);
927 // rotate start dir to find middle point on arc
928 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
929 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
930 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
932 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
935 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
937 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
938 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
940 // move only features of the following types
941 const std::string& aFeatureKind = aFeature->getKind();
942 if (aFeatureKind == SketchPlugin_Point::ID())
943 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
944 else if (aFeatureKind == SketchPlugin_Line::ID())
945 aMiddlePoint = middlePointOnLine(aFeature);
946 else if (aFeatureKind == SketchPlugin_Circle::ID())
947 aMiddlePoint = pointOnCircle(aFeature);
948 else if (aFeatureKind == SketchPlugin_Arc::ID())
949 aMiddlePoint = middlePointOnArc(aFeature);
954 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
955 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
957 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
958 theMovedEntity.fillMessage(aMessage);
960 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
961 if (aMessage->movedAttribute())
962 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
964 anOriginalPosition = middlePoint(aMessage->movedObject());
966 if (!anOriginalPosition)
967 return; // something has gone wrong, do not process movement
969 aMessage->setOriginalPosition(anOriginalPosition);
970 aMessage->setCurrentPosition(theTargetPoint);
971 Events_Loop::loop()->send(aMessage);
974 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
975 double theTargetX, double theTargetY)
977 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
978 move(theMovedEntity, aTargetPoint);
981 //--------------------------------------------------------------------------------------
983 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
985 FeaturePtr aBase = feature();
986 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
987 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
988 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
989 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
990 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
991 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
992 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
994 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
997 //--------------------------------------------------------------------------------------
999 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1001 FeaturePtr aBase = feature();
1002 const std::string& aDocName = theDumper.name(aBase->document());
1004 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1005 if (anExternal->value()) {
1006 theDumper << aBase << " = model.addSketch(" << aDocName <<
1007 ", " << anExternal << ")" << std::endl;
1009 // Sketch is base on a plane.
1010 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1011 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1012 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1013 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1014 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1015 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1017 // Check the plane is coordinate plane
1018 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1019 if(anExternal->context()) { // checking for selected planes
1020 if (!aPlaneName.empty()
1021 && anExternal->context()->data()
1022 && anExternal->context()->data()->name() == aPlaneName) {
1023 // dump sketch based on coordinate plane
1024 theDumper << aBase << " = model.addSketch(" << aDocName
1025 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1026 } else { // some other plane
1027 theDumper << aBase << " = model.addSketch(" << aDocName <<
1028 ", " << anExternal<< ")" << std::endl;
1031 if (aPlaneName.empty()) {
1032 // needs import additional module
1033 theDumper.importModule("GeomAPI");
1034 // dump plane parameters
1035 const std::string& aSketchName = theDumper.name(aBase);
1036 std::string anOriginName = aSketchName + "_origin";
1037 std::string aNormalName = aSketchName + "_norm";
1038 std::string aDirXName = aSketchName + "_dirx";
1039 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1040 // and then dumplicate dumping it in the next line
1041 theDumper << anOriginName << " = " << anOrigin << "\n"
1042 << aNormalName << " = " << aNormal << "\n"
1043 << aDirXName << " = " << aDirX << "\n";
1044 // dump sketch based on arbitrary plane
1045 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1046 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1048 // dump sketch based on coordinate plane
1049 theDumper << aBase << " = model.addSketch(" << aDocName
1050 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1055 // dump sketch's subfeatures
1056 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1057 theDumper.processSubs(aCompFeat, true);