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 FeaturePtr aSketch = feature();
135 DocumentPtr aDoc = aSketch->document();
136 bool useVisible = false;
137 FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
138 aDoc->setCurrentFeature(aSketch, useVisible);
140 if (theRemoveExternalDependency)
141 aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
143 setExternal(thePlane);
145 aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
148 //--------------------------------------------------------------------------------------
149 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
151 fillAttribute(theExternal, myexternal);
156 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
158 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
159 ModelHighAPI_Selection aSel(aRes);
163 //--------------------------------------------------------------------------------------
164 void SketchAPI_Sketch::setValue(
165 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
166 const ModelHighAPI_Double & theValue)
168 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
170 // theConstraint->execute();
173 //--------------------------------------------------------------------------------------
174 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
176 const_cast<SketchAPI_Sketch*>(this)->execute();
178 std::list<ModelHighAPI_Selection> aSelectionList;
180 ResultConstructionPtr aResultConstruction =
181 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
182 if (aResultConstruction.get() == NULL)
183 return aSelectionList;
185 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
186 aSelectionList.push_back(
187 ModelHighAPI_Selection(aResultConstruction,
188 aResultConstruction->face(anIndex)));
191 return aSelectionList;
194 //--------------------------------------------------------------------------------------
195 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
196 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
198 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
199 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
202 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
203 const ModelHighAPI_Selection & theExternal)
205 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
206 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
209 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
210 const std::string & theExternalName)
212 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
214 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
217 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
218 std::shared_ptr<ModelAPI_Object> thePlaneObject)
220 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
221 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
225 //--------------------------------------------------------------------------------------
226 std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
228 std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
229 std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
230 for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
231 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
232 PointPtr aPoint(new SketchAPI_Point(aFeature));
233 aFreePoints.push_back(aPoint);
238 //--------------------------------------------------------------------------------------
239 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
240 double theX, double theY)
242 std::shared_ptr<ModelAPI_Feature> aFeature =
243 compositeFeature()->addFeature(SketchPlugin_Point::ID());
244 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
246 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
247 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
249 std::shared_ptr<ModelAPI_Feature> aFeature =
250 compositeFeature()->addFeature(SketchPlugin_Point::ID());
251 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
253 std::shared_ptr<SketchAPI_Point>
254 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
256 std::shared_ptr<ModelAPI_Feature> aFeature =
257 compositeFeature()->addFeature(SketchPlugin_Point::ID());
258 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
260 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
262 std::shared_ptr<ModelAPI_Feature> aFeature =
263 compositeFeature()->addFeature(SketchPlugin_Point::ID());
264 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
267 //--------------------------------------------------------------------------------------
268 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
269 const ModelHighAPI_Selection & theExternal,
272 std::shared_ptr<ModelAPI_Feature> aFeature =
273 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
274 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternal));
275 anIntersection->setIncludeToResult(theKeepResult);
276 return anIntersection;
278 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
279 const std::string & theExternalName,
282 std::shared_ptr<ModelAPI_Feature> aFeature =
283 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
284 IntersectionPointPtr anIntersection(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
285 anIntersection->setIncludeToResult(theKeepResult);
286 return anIntersection;
289 //--------------------------------------------------------------------------------------
290 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
291 double theX2, double theY2)
293 std::shared_ptr<ModelAPI_Feature> aFeature =
294 compositeFeature()->addFeature(SketchPlugin_Line::ID());
295 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
297 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
298 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
299 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
301 std::shared_ptr<ModelAPI_Feature> aFeature =
302 compositeFeature()->addFeature(SketchPlugin_Line::ID());
303 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
305 std::shared_ptr<SketchAPI_Line>
306 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
308 std::shared_ptr<ModelAPI_Feature> aFeature =
309 compositeFeature()->addFeature(SketchPlugin_Line::ID());
310 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
312 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
314 std::shared_ptr<ModelAPI_Feature> aFeature =
315 compositeFeature()->addFeature(SketchPlugin_Line::ID());
316 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
319 //--------------------------------------------------------------------------------------
320 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
321 double theX2, double theY2)
323 std::shared_ptr<ModelAPI_Feature> aFeature =
324 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
325 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
327 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
328 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
329 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
331 std::shared_ptr<ModelAPI_Feature> aFeature =
332 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
333 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
336 //--------------------------------------------------------------------------------------
337 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
341 std::shared_ptr<ModelAPI_Feature> aFeature =
342 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
343 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
346 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
347 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
350 std::shared_ptr<ModelAPI_Feature> aFeature =
351 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
352 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
355 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
360 std::shared_ptr<ModelAPI_Feature> aFeature =
361 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
362 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
363 thePassedX, thePassedY));
366 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
367 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
368 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
370 std::shared_ptr<ModelAPI_Feature> aFeature =
371 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
372 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
375 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
376 double theX2, double theY2,
377 double theX3, double theY3)
379 std::shared_ptr<ModelAPI_Feature> aFeature =
380 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
381 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
386 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
387 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
388 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
389 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
391 std::shared_ptr<ModelAPI_Feature> aFeature =
392 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
393 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
396 std::shared_ptr<SketchAPI_Circle>
397 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
399 std::shared_ptr<ModelAPI_Feature> aFeature =
400 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
401 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
404 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
406 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
407 std::shared_ptr<ModelAPI_Feature> aFeature =
408 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
409 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
412 //--------------------------------------------------------------------------------------
413 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
414 double theStartX, double theStartY,
415 double theEndX, double theEndY,
418 std::shared_ptr<ModelAPI_Feature> aFeature =
419 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
420 return ArcPtr(new SketchAPI_Arc(aFeature,
421 theCenterX, theCenterY,
422 theStartX, theStartY,
427 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
428 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
429 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
430 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
433 std::shared_ptr<ModelAPI_Feature> aFeature =
434 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
435 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
438 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
439 double theEndX, double theEndY,
440 double thePassedX, double thePassedY)
442 std::shared_ptr<ModelAPI_Feature> aFeature =
443 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
444 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
445 theStartX, theStartY,
447 thePassedX, thePassedY));
450 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
451 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
452 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
453 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
455 std::shared_ptr<ModelAPI_Feature> aFeature =
456 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
457 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
460 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
461 const ModelHighAPI_RefAttr& theTangentPoint,
462 double theEndX, double theEndY,
465 std::shared_ptr<ModelAPI_Feature> aFeature =
466 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
467 return MacroArcPtr(new SketchAPI_MacroArc(
468 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
471 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
472 const ModelHighAPI_RefAttr& theTangentPoint,
473 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
476 std::shared_ptr<ModelAPI_Feature> aFeature =
477 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
478 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
481 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
483 std::shared_ptr<ModelAPI_Feature> aFeature =
484 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
485 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
488 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
490 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
491 std::shared_ptr<ModelAPI_Feature> aFeature =
492 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
493 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
496 //--------------------------------------------------------------------------------------
497 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
498 const ModelHighAPI_Selection & theExternalFeature,
501 std::shared_ptr<ModelAPI_Feature> aFeature =
502 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
503 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
504 aProjection->setIncludeToResult(theKeepResult);
508 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
509 const std::string & theExternalName,
512 std::shared_ptr<ModelAPI_Feature> aFeature =
513 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
514 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
515 aProjection->setIncludeToResult(theKeepResult);
519 //--------------------------------------------------------------------------------------
520 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
521 const ModelHighAPI_RefAttr & theMirrorLine,
522 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
524 std::shared_ptr<ModelAPI_Feature> aFeature =
525 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
526 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
529 //--------------------------------------------------------------------------------------
530 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
531 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
532 const ModelHighAPI_RefAttr & thePoint1,
533 const ModelHighAPI_RefAttr & thePoint2,
534 const ModelHighAPI_Integer & theNumberOfObjects,
537 std::shared_ptr<ModelAPI_Feature> aFeature =
538 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
539 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
540 thePoint2, theNumberOfObjects, theFullValue));
543 //--------------------------------------------------------------------------------------
544 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
545 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
546 const ModelHighAPI_RefAttr & theCenter,
547 const ModelHighAPI_Double & theAngle,
548 const ModelHighAPI_Integer & theNumberOfObjects,
552 std::shared_ptr<ModelAPI_Feature> aFeature =
553 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
555 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
556 theAngle, theNumberOfObjects, theFullValue, theReversed));
559 //--------------------------------------------------------------------------------------
560 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
561 const ModelHighAPI_Reference& theFeature,
562 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
564 std::shared_ptr<ModelAPI_Feature> aFeature =
565 compositeFeature()->addFeature(SketchPlugin_Split::ID());
566 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
568 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
569 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
570 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
571 fillAttribute(thePositionPoint, aPointAttr);
574 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
577 //--------------------------------------------------------------------------------------
578 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
579 const ModelHighAPI_Reference& theFeature,
580 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
582 std::shared_ptr<ModelAPI_Feature> aFeature =
583 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
584 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
586 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
587 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
588 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
589 fillAttribute(thePositionPoint, aPointAttr);
592 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
595 //--------------------------------------------------------------------------------------
596 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
597 const ModelHighAPI_RefAttr & theLine1,
598 const ModelHighAPI_RefAttr & theLine2,
599 const ModelHighAPI_Double & theValue)
601 std::shared_ptr<ModelAPI_Feature> aFeature =
602 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
603 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
604 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
605 // fill the value before llines to avoid calculation of angle value by the Angle feature
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::setAngleComplementary(
614 const ModelHighAPI_RefAttr & theLine1,
615 const ModelHighAPI_RefAttr & theLine2,
616 const ModelHighAPI_Double & theValue)
618 std::shared_ptr<ModelAPI_Feature> aFeature =
619 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
620 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
621 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
622 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
623 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
624 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
626 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
629 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
630 const ModelHighAPI_RefAttr & theLine1,
631 const ModelHighAPI_RefAttr & theLine2,
632 const ModelHighAPI_Double & theValue)
634 std::shared_ptr<ModelAPI_Feature> aFeature =
635 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
636 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
637 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
638 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
639 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
640 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
642 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
645 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
646 const ModelHighAPI_RefAttr & thePoint1,
647 const ModelHighAPI_RefAttr & thePoint2)
649 std::shared_ptr<ModelAPI_Feature> aFeature =
650 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
651 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
652 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
654 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
657 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
658 const ModelHighAPI_RefAttr & theLine1,
659 const ModelHighAPI_RefAttr & theLine2)
661 std::shared_ptr<ModelAPI_Feature> aFeature =
662 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
663 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
664 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
666 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
669 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
670 const ModelHighAPI_RefAttr & thePoint,
671 const ModelHighAPI_RefAttr & thePointOrLine,
672 const ModelHighAPI_Double & theValue,
675 std::shared_ptr<ModelAPI_Feature> aFeature =
676 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
677 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
678 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
679 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
680 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
682 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
685 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
686 const ModelHighAPI_RefAttr & thePoint,
687 const ModelHighAPI_RefAttr & thePointOrLine,
688 const ModelHighAPI_Double & theValue)
690 return setDistance(thePoint, thePointOrLine, theValue, true);
693 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
694 const ModelHighAPI_RefAttr & thePoint,
695 const ModelHighAPI_RefAttr & thePointOrLine,
696 const ModelHighAPI_Double & theValue)
698 return setDistance(thePoint, thePointOrLine, theValue, false);
701 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
702 const ModelHighAPI_RefAttr & thePoint1,
703 const ModelHighAPI_RefAttr & thePoint2,
704 const ModelHighAPI_Double & theValue)
706 std::shared_ptr<ModelAPI_Feature> aFeature =
707 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
708 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
709 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
710 fillAttribute(theValue,
711 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
713 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
716 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
717 const ModelHighAPI_RefAttr & thePoint1,
718 const ModelHighAPI_RefAttr & thePoint2,
719 const ModelHighAPI_Double & theValue)
721 std::shared_ptr<ModelAPI_Feature> aFeature =
722 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
723 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
724 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
725 fillAttribute(theValue,
726 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
728 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
731 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
732 const ModelHighAPI_RefAttr & theObject1,
733 const ModelHighAPI_RefAttr & theObject2)
735 std::shared_ptr<ModelAPI_Feature> aFeature =
736 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
737 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
738 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
740 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
743 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
744 const ModelHighAPI_RefAttr & thePoint)
746 std::shared_ptr<ModelAPI_Feature> aFeature =
747 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
748 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
749 apply(); // finish operation to remove Fillet feature correcly
750 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
753 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
754 const ModelHighAPI_RefAttr & thePoint,
755 const ModelHighAPI_Double & theRadius)
757 CompositeFeaturePtr aSketch = compositeFeature();
758 int aNbSubs = aSketch->numberOfSubs();
761 InterfacePtr aFilletFeature = setFillet(thePoint);
763 // set radius for just created arc
764 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
765 if (anArc->getKind() == SketchPlugin_Arc::ID())
766 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
768 return aFilletFeature;
771 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
772 const ModelHighAPI_RefAttr & theObject)
774 std::shared_ptr<ModelAPI_Feature> aFeature =
775 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
776 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
778 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
781 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
782 const ModelHighAPI_RefAttr & theLine)
784 std::shared_ptr<ModelAPI_Feature> aFeature =
785 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
786 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
788 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
791 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
792 const ModelHighAPI_RefAttr & theLine,
793 const ModelHighAPI_Double & theValue)
795 std::shared_ptr<ModelAPI_Feature> aFeature =
796 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
797 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
798 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
800 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
803 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
804 const ModelHighAPI_RefAttr & thePoint,
805 const ModelHighAPI_RefAttr & theLine)
807 std::shared_ptr<ModelAPI_Feature> aFeature =
808 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
809 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
810 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
812 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
815 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
816 const ModelHighAPI_RefAttr & theLine1,
817 const ModelHighAPI_RefAttr & theLine2)
819 std::shared_ptr<ModelAPI_Feature> aFeature =
820 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::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::setPerpendicular(
828 const ModelHighAPI_RefAttr & theLine1,
829 const ModelHighAPI_RefAttr & theLine2)
831 std::shared_ptr<ModelAPI_Feature> aFeature =
832 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
833 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
834 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
836 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
839 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
840 const ModelHighAPI_RefAttr & theCircleOrArc,
841 const ModelHighAPI_Double & theValue)
843 std::shared_ptr<ModelAPI_Feature> aFeature =
844 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
845 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
846 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
848 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
851 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
852 const ModelHighAPI_RefAttr & theLine,
853 const ModelHighAPI_RefAttr & theCircle)
855 std::shared_ptr<ModelAPI_Feature> aFeature =
856 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
857 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
858 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
860 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
863 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
864 const ModelHighAPI_RefAttr & theLine)
866 std::shared_ptr<ModelAPI_Feature> aFeature =
867 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
868 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
870 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
873 //--------------------------------------------------------------------------------------
875 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
877 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
878 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
881 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
883 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
884 theFeature->attribute(SketchPlugin_Line::START_ID()));
885 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
886 theFeature->attribute(SketchPlugin_Line::END_ID()));
888 if (!aStartAttr || !aEndAttr)
889 return std::shared_ptr<GeomAPI_Pnt2d>();
891 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
892 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
893 return std::shared_ptr<GeomAPI_Pnt2d>(
894 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
897 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
899 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
900 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
901 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
903 if (!aCenter || !aRadius)
904 return std::shared_ptr<GeomAPI_Pnt2d>();
906 return std::shared_ptr<GeomAPI_Pnt2d>(
907 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
910 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
912 static const double PI = 3.141592653589793238463;
914 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
915 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
916 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
917 theFeature->attribute(SketchPlugin_Arc::START_ID()));
918 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
919 theFeature->attribute(SketchPlugin_Arc::END_ID()));
921 if (!aCenterAttr || !aStartAttr || !aEndAttr)
922 return std::shared_ptr<GeomAPI_Pnt2d>();
924 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
925 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
926 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
927 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
929 double anAngle = aStartDir->angle(aEndDir);
930 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
931 if (isReversed && anAngle > 0.)
933 else if (!isReversed && anAngle <= 0.)
936 double cosA = cos(anAngle);
937 double sinA = sin(anAngle);
939 // rotate start dir to find middle point on arc
940 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
941 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
942 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
944 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
947 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
949 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
950 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
952 // move only features of the following types
953 const std::string& aFeatureKind = aFeature->getKind();
954 if (aFeatureKind == SketchPlugin_Point::ID())
955 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
956 else if (aFeatureKind == SketchPlugin_Line::ID())
957 aMiddlePoint = middlePointOnLine(aFeature);
958 else if (aFeatureKind == SketchPlugin_Circle::ID())
959 aMiddlePoint = pointOnCircle(aFeature);
960 else if (aFeatureKind == SketchPlugin_Arc::ID())
961 aMiddlePoint = middlePointOnArc(aFeature);
966 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
967 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
969 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
970 theMovedEntity.fillMessage(aMessage);
972 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
973 if (aMessage->movedAttribute())
974 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
976 anOriginalPosition = middlePoint(aMessage->movedObject());
978 if (!anOriginalPosition)
979 return; // something has gone wrong, do not process movement
981 aMessage->setOriginalPosition(anOriginalPosition);
982 aMessage->setCurrentPosition(theTargetPoint);
983 Events_Loop::loop()->send(aMessage);
986 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
987 double theTargetX, double theTargetY)
989 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
990 move(theMovedEntity, aTargetPoint);
993 //--------------------------------------------------------------------------------------
995 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
997 FeaturePtr aBase = feature();
998 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
999 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1000 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1001 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1002 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1003 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1004 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1006 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1009 //--------------------------------------------------------------------------------------
1011 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1013 FeaturePtr aBase = feature();
1014 const std::string& aDocName = theDumper.name(aBase->document());
1016 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1017 if (anExternal->value()) {
1018 theDumper << aBase << " = model.addSketch(" << aDocName <<
1019 ", " << anExternal << ")" << std::endl;
1021 // Sketch is base on a plane.
1022 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1023 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1024 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1025 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1026 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1027 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1029 // Check the plane is coordinate plane
1030 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1031 if(anExternal->context()) { // checking for selected planes
1032 if (!aPlaneName.empty()
1033 && anExternal->context()->data()
1034 && anExternal->context()->data()->name() == aPlaneName) {
1035 // dump sketch based on coordinate plane
1036 theDumper << aBase << " = model.addSketch(" << aDocName
1037 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1038 } else { // some other plane
1039 theDumper << aBase << " = model.addSketch(" << aDocName <<
1040 ", " << anExternal<< ")" << std::endl;
1043 if (aPlaneName.empty()) {
1044 // needs import additional module
1045 theDumper.importModule("GeomAPI");
1046 // dump plane parameters
1047 const std::string& aSketchName = theDumper.name(aBase);
1048 std::string anOriginName = aSketchName + "_origin";
1049 std::string aNormalName = aSketchName + "_norm";
1050 std::string aDirXName = aSketchName + "_dirx";
1051 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1052 // and then dumplicate dumping it in the next line
1053 theDumper << anOriginName << " = " << anOrigin << "\n"
1054 << aNormalName << " = " << aNormal << "\n"
1055 << aDirXName << " = " << aDirX << "\n";
1056 // dump sketch based on arbitrary plane
1057 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1058 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1060 // dump sketch based on coordinate plane
1061 theDumper << aBase << " = model.addSketch(" << aDocName
1062 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1067 // dump sketch's subfeatures
1068 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1069 theDumper.processSubs(aCompFeat, true);