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,
466 std::shared_ptr<ModelAPI_Feature> aFeature =
467 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
468 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
470 aMacroArc->setByTransversal(theTangentPoint, theEndX, theEndY, theInversed);
472 aMacroArc->setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
476 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
477 const ModelHighAPI_RefAttr& theTangentPoint,
478 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
482 std::shared_ptr<ModelAPI_Feature> aFeature =
483 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
484 MacroArcPtr aMacroArc(new SketchAPI_MacroArc(aFeature));
486 aMacroArc->setByTransversal(theTangentPoint, theEnd, theInversed);
488 aMacroArc->setByTangent(theTangentPoint, theEnd, theInversed);
492 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
494 std::shared_ptr<ModelAPI_Feature> aFeature =
495 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
496 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
499 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
501 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
502 std::shared_ptr<ModelAPI_Feature> aFeature =
503 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
504 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
507 //--------------------------------------------------------------------------------------
508 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
509 const ModelHighAPI_Selection & theExternalFeature,
512 std::shared_ptr<ModelAPI_Feature> aFeature =
513 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
514 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
515 aProjection->setIncludeToResult(theKeepResult);
519 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
520 const std::string & theExternalName,
523 std::shared_ptr<ModelAPI_Feature> aFeature =
524 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
525 ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
526 aProjection->setIncludeToResult(theKeepResult);
530 //--------------------------------------------------------------------------------------
531 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
532 const ModelHighAPI_RefAttr & theMirrorLine,
533 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
535 std::shared_ptr<ModelAPI_Feature> aFeature =
536 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
537 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
540 //--------------------------------------------------------------------------------------
541 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
542 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
543 const ModelHighAPI_RefAttr & thePoint1,
544 const ModelHighAPI_RefAttr & thePoint2,
545 const ModelHighAPI_Integer & theNumberOfObjects,
548 std::shared_ptr<ModelAPI_Feature> aFeature =
549 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
550 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
551 thePoint2, theNumberOfObjects, theFullValue));
554 //--------------------------------------------------------------------------------------
555 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
556 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
557 const ModelHighAPI_RefAttr & theCenter,
558 const ModelHighAPI_Double & theAngle,
559 const ModelHighAPI_Integer & theNumberOfObjects,
563 std::shared_ptr<ModelAPI_Feature> aFeature =
564 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
566 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
567 theAngle, theNumberOfObjects, theFullValue, theReversed));
570 //--------------------------------------------------------------------------------------
571 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
572 const ModelHighAPI_Reference& theFeature,
573 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
575 std::shared_ptr<ModelAPI_Feature> aFeature =
576 compositeFeature()->addFeature(SketchPlugin_Split::ID());
577 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
579 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
580 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
581 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
582 fillAttribute(thePositionPoint, aPointAttr);
585 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
588 //--------------------------------------------------------------------------------------
589 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
590 const ModelHighAPI_Reference& theFeature,
591 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
593 std::shared_ptr<ModelAPI_Feature> aFeature =
594 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
595 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
597 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
598 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
599 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
600 fillAttribute(thePositionPoint, aPointAttr);
603 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
606 //--------------------------------------------------------------------------------------
607 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
608 const ModelHighAPI_RefAttr & theLine1,
609 const ModelHighAPI_RefAttr & theLine2,
610 const ModelHighAPI_Double & theValue)
612 std::shared_ptr<ModelAPI_Feature> aFeature =
613 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
614 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
615 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
616 // fill the value before llines to avoid calculation of angle value by the Angle feature
617 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
618 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
619 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
621 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
624 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
625 const ModelHighAPI_RefAttr & theLine1,
626 const ModelHighAPI_RefAttr & theLine2,
627 const ModelHighAPI_Double & theValue)
629 std::shared_ptr<ModelAPI_Feature> aFeature =
630 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
631 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
632 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
633 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
634 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
635 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
637 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
640 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
641 const ModelHighAPI_RefAttr & theLine1,
642 const ModelHighAPI_RefAttr & theLine2,
643 const ModelHighAPI_Double & theValue)
645 std::shared_ptr<ModelAPI_Feature> aFeature =
646 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
647 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
648 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
649 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
650 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
651 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
653 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
656 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
657 const ModelHighAPI_RefAttr & thePoint1,
658 const ModelHighAPI_RefAttr & thePoint2)
660 std::shared_ptr<ModelAPI_Feature> aFeature =
661 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
662 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
663 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
665 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
668 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
669 const ModelHighAPI_RefAttr & theLine1,
670 const ModelHighAPI_RefAttr & theLine2)
672 std::shared_ptr<ModelAPI_Feature> aFeature =
673 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
674 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
675 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
677 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
680 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
681 const ModelHighAPI_RefAttr & thePoint,
682 const ModelHighAPI_RefAttr & thePointOrLine,
683 const ModelHighAPI_Double & theValue,
686 std::shared_ptr<ModelAPI_Feature> aFeature =
687 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
688 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
689 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
690 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
691 fillAttribute(isSigned, aFeature->boolean(SketchPlugin_ConstraintDistance::SIGNED()));
693 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
696 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setSignedDistance(
697 const ModelHighAPI_RefAttr & thePoint,
698 const ModelHighAPI_RefAttr & thePointOrLine,
699 const ModelHighAPI_Double & theValue)
701 return setDistance(thePoint, thePointOrLine, theValue, true);
704 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setUnsignedDistance(
705 const ModelHighAPI_RefAttr & thePoint,
706 const ModelHighAPI_RefAttr & thePointOrLine,
707 const ModelHighAPI_Double & theValue)
709 return setDistance(thePoint, thePointOrLine, theValue, false);
712 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontalDistance(
713 const ModelHighAPI_RefAttr & thePoint1,
714 const ModelHighAPI_RefAttr & thePoint2,
715 const ModelHighAPI_Double & theValue)
717 std::shared_ptr<ModelAPI_Feature> aFeature =
718 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID());
719 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
720 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
721 fillAttribute(theValue,
722 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
724 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
727 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVerticalDistance(
728 const ModelHighAPI_RefAttr & thePoint1,
729 const ModelHighAPI_RefAttr & thePoint2,
730 const ModelHighAPI_Double & theValue)
732 std::shared_ptr<ModelAPI_Feature> aFeature =
733 compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID());
734 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
735 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
736 fillAttribute(theValue,
737 aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()));
739 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
742 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
743 const ModelHighAPI_RefAttr & theObject1,
744 const ModelHighAPI_RefAttr & theObject2)
746 std::shared_ptr<ModelAPI_Feature> aFeature =
747 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
748 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
749 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
751 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
754 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
755 const ModelHighAPI_RefAttr & thePoint)
757 std::shared_ptr<ModelAPI_Feature> aFeature =
758 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
759 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
760 apply(); // finish operation to remove Fillet feature correcly
761 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
764 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
765 const ModelHighAPI_RefAttr & thePoint,
766 const ModelHighAPI_Double & theRadius)
768 CompositeFeaturePtr aSketch = compositeFeature();
769 int aNbSubs = aSketch->numberOfSubs();
772 InterfacePtr aFilletFeature = setFillet(thePoint);
774 // set radius for just created arc
775 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
776 if (anArc->getKind() == SketchPlugin_Arc::ID())
777 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
779 return aFilletFeature;
782 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
783 const ModelHighAPI_RefAttr & theObject)
785 std::shared_ptr<ModelAPI_Feature> aFeature =
786 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
787 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
789 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
792 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
793 const ModelHighAPI_RefAttr & theLine)
795 std::shared_ptr<ModelAPI_Feature> aFeature =
796 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
797 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
799 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
802 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
803 const ModelHighAPI_RefAttr & theLine,
804 const ModelHighAPI_Double & theValue)
806 std::shared_ptr<ModelAPI_Feature> aFeature =
807 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
808 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
809 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
811 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
814 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
815 const ModelHighAPI_RefAttr & thePoint,
816 const ModelHighAPI_RefAttr & theLine)
818 std::shared_ptr<ModelAPI_Feature> aFeature =
819 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
820 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
821 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
823 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
826 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
827 const ModelHighAPI_RefAttr & theLine1,
828 const ModelHighAPI_RefAttr & theLine2)
830 std::shared_ptr<ModelAPI_Feature> aFeature =
831 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
832 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
833 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
835 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
838 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
839 const ModelHighAPI_RefAttr & theLine1,
840 const ModelHighAPI_RefAttr & theLine2)
842 std::shared_ptr<ModelAPI_Feature> aFeature =
843 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
844 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
845 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
847 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
850 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
851 const ModelHighAPI_RefAttr & theCircleOrArc,
852 const ModelHighAPI_Double & theValue)
854 std::shared_ptr<ModelAPI_Feature> aFeature =
855 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
856 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
857 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
859 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
862 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
863 const ModelHighAPI_RefAttr & theLine,
864 const ModelHighAPI_RefAttr & theCircle)
866 std::shared_ptr<ModelAPI_Feature> aFeature =
867 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
868 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
869 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
871 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
874 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
875 const ModelHighAPI_RefAttr & theLine)
877 std::shared_ptr<ModelAPI_Feature> aFeature =
878 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
879 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
881 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
884 //--------------------------------------------------------------------------------------
886 static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(const AttributePtr& thePoint)
888 AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePoint);
889 return aPnt ? aPnt->pnt() : std::shared_ptr<GeomAPI_Pnt2d>();
892 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnLine(const FeaturePtr& theFeature)
894 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
895 theFeature->attribute(SketchPlugin_Line::START_ID()));
896 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
897 theFeature->attribute(SketchPlugin_Line::END_ID()));
899 if (!aStartAttr || !aEndAttr)
900 return std::shared_ptr<GeomAPI_Pnt2d>();
902 std::shared_ptr<GeomAPI_XY> aStartPoint = aStartAttr->pnt()->xy();
903 std::shared_ptr<GeomAPI_XY> aEndPoint = aEndAttr->pnt()->xy();
904 return std::shared_ptr<GeomAPI_Pnt2d>(
905 new GeomAPI_Pnt2d(aStartPoint->added(aEndPoint)->multiplied(0.5)));
908 static std::shared_ptr<GeomAPI_Pnt2d> pointOnCircle(const FeaturePtr& theFeature)
910 AttributePoint2DPtr aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
911 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
912 AttributeDoublePtr aRadius = theFeature->real(SketchPlugin_Circle::RADIUS_ID());
914 if (!aCenter || !aRadius)
915 return std::shared_ptr<GeomAPI_Pnt2d>();
917 return std::shared_ptr<GeomAPI_Pnt2d>(
918 new GeomAPI_Pnt2d(aCenter->x() + aRadius->value(), aCenter->y()));
921 static std::shared_ptr<GeomAPI_Pnt2d> middlePointOnArc(const FeaturePtr& theFeature)
923 static const double PI = 3.141592653589793238463;
925 AttributePoint2DPtr aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
926 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
927 AttributePoint2DPtr aStartAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
928 theFeature->attribute(SketchPlugin_Arc::START_ID()));
929 AttributePoint2DPtr aEndAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
930 theFeature->attribute(SketchPlugin_Arc::END_ID()));
932 if (!aCenterAttr || !aStartAttr || !aEndAttr)
933 return std::shared_ptr<GeomAPI_Pnt2d>();
935 std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
936 aStartAttr->x() - aCenterAttr->x(), aStartAttr->y() - aCenterAttr->y()));
937 std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
938 aEndAttr->x() - aCenterAttr->x(), aEndAttr->y() - aCenterAttr->y()));
940 double anAngle = aStartDir->angle(aEndDir);
941 bool isReversed = theFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
942 if (isReversed && anAngle > 0.)
944 else if (!isReversed && anAngle <= 0.)
947 double cosA = cos(anAngle);
948 double sinA = sin(anAngle);
950 // rotate start dir to find middle point on arc
951 double aRadius = aStartAttr->pnt()->distance(aCenterAttr->pnt());
952 double x = aCenterAttr->x() + aRadius * (aStartDir->x() * cosA - aStartDir->y() * sinA);
953 double y = aCenterAttr->y() + aRadius * (aStartDir->x() * sinA + aStartDir->y() * cosA);
955 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y));
958 static std::shared_ptr<GeomAPI_Pnt2d> middlePoint(const ObjectPtr& theObject)
960 std::shared_ptr<GeomAPI_Pnt2d> aMiddlePoint;
961 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
963 // move only features of the following types
964 const std::string& aFeatureKind = aFeature->getKind();
965 if (aFeatureKind == SketchPlugin_Point::ID())
966 aMiddlePoint = pointCoordinates(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
967 else if (aFeatureKind == SketchPlugin_Line::ID())
968 aMiddlePoint = middlePointOnLine(aFeature);
969 else if (aFeatureKind == SketchPlugin_Circle::ID())
970 aMiddlePoint = pointOnCircle(aFeature);
971 else if (aFeatureKind == SketchPlugin_Arc::ID())
972 aMiddlePoint = middlePointOnArc(aFeature);
977 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
978 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint)
980 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(new ModelAPI_ObjectMovedMessage);
981 theMovedEntity.fillMessage(aMessage);
983 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition;
984 if (aMessage->movedAttribute())
985 anOriginalPosition = pointCoordinates(aMessage->movedAttribute());
987 anOriginalPosition = middlePoint(aMessage->movedObject());
989 if (!anOriginalPosition)
990 return; // something has gone wrong, do not process movement
992 aMessage->setOriginalPosition(anOriginalPosition);
993 aMessage->setCurrentPosition(theTargetPoint);
994 Events_Loop::loop()->send(aMessage);
997 void SketchAPI_Sketch::move(const ModelHighAPI_RefAttr& theMovedEntity,
998 double theTargetX, double theTargetY)
1000 std::shared_ptr<GeomAPI_Pnt2d> aTargetPoint(new GeomAPI_Pnt2d(theTargetX, theTargetY));
1001 move(theMovedEntity, aTargetPoint);
1004 //--------------------------------------------------------------------------------------
1006 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1008 FeaturePtr aBase = feature();
1009 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1010 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1011 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1012 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
1013 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1014 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
1015 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1017 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
1020 //--------------------------------------------------------------------------------------
1022 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
1024 FeaturePtr aBase = feature();
1025 const std::string& aDocName = theDumper.name(aBase->document());
1027 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
1028 if (anExternal->value()) {
1029 theDumper << aBase << " = model.addSketch(" << aDocName <<
1030 ", " << anExternal << ")" << std::endl;
1032 // Sketch is base on a plane.
1033 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1034 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
1035 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1036 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
1037 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1038 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
1040 // Check the plane is coordinate plane
1041 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
1042 if(anExternal->context()) { // checking for selected planes
1043 if (!aPlaneName.empty()
1044 && anExternal->context()->data()
1045 && anExternal->context()->data()->name() == aPlaneName) {
1046 // dump sketch based on coordinate plane
1047 theDumper << aBase << " = model.addSketch(" << aDocName
1048 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
1049 } else { // some other plane
1050 theDumper << aBase << " = model.addSketch(" << aDocName <<
1051 ", " << anExternal<< ")" << std::endl;
1054 if (aPlaneName.empty()) {
1055 // needs import additional module
1056 theDumper.importModule("GeomAPI");
1057 // dump plane parameters
1058 const std::string& aSketchName = theDumper.name(aBase);
1059 std::string anOriginName = aSketchName + "_origin";
1060 std::string aNormalName = aSketchName + "_norm";
1061 std::string aDirXName = aSketchName + "_dirx";
1062 // use "\n" instead of std::endl to avoid automatic dumping sketch here
1063 // and then dumplicate dumping it in the next line
1064 theDumper << anOriginName << " = " << anOrigin << "\n"
1065 << aNormalName << " = " << aNormal << "\n"
1066 << aDirXName << " = " << aDirX << "\n";
1067 // dump sketch based on arbitrary plane
1068 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
1069 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
1071 // dump sketch based on coordinate plane
1072 theDumper << aBase << " = model.addSketch(" << aDocName
1073 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
1078 // dump sketch's subfeatures
1079 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
1080 theDumper.processSubs(aCompFeat, true);