1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SketchAPI_Sketch.h"
22 //--------------------------------------------------------------------------------------
23 #include <SketchPlugin_Constraint.h>
24 #include <SketchPlugin_ConstraintAngle.h>
25 #include <SketchPlugin_ConstraintCoincidence.h>
26 #include <SketchPlugin_ConstraintCollinear.h>
27 #include <SketchPlugin_ConstraintDistance.h>
28 #include <SketchPlugin_ConstraintEqual.h>
29 #include <SketchPlugin_Fillet.h>
30 #include <SketchPlugin_ConstraintHorizontal.h>
31 #include <SketchPlugin_ConstraintLength.h>
32 #include <SketchPlugin_ConstraintMiddle.h>
33 #include <SketchPlugin_ConstraintMirror.h>
34 #include <SketchPlugin_ConstraintParallel.h>
35 #include <SketchPlugin_ConstraintPerpendicular.h>
36 #include <SketchPlugin_ConstraintRadius.h>
37 #include <SketchPlugin_ConstraintRigid.h>
38 #include <SketchPlugin_Trim.h>
39 #include <SketchPlugin_Split.h>
40 #include <SketchPlugin_ConstraintTangent.h>
41 #include <SketchPlugin_ConstraintVertical.h>
42 #include <SketcherPrs_Tools.h>
43 //--------------------------------------------------------------------------------------
44 #include <ModelAPI_CompositeFeature.h>
45 #include <ModelAPI_ResultConstruction.h>
46 #include <ModelHighAPI_Double.h>
47 #include <ModelHighAPI_Dumper.h>
48 #include <ModelHighAPI_RefAttr.h>
49 #include <ModelHighAPI_Selection.h>
50 #include <ModelHighAPI_Services.h>
51 #include <ModelHighAPI_Tools.h>
52 //--------------------------------------------------------------------------------------
53 #include "SketchAPI_Arc.h"
54 #include "SketchAPI_MacroArc.h"
55 #include "SketchAPI_Circle.h"
56 #include "SketchAPI_IntersectionPoint.h"
57 #include "SketchAPI_Line.h"
58 #include "SketchAPI_MacroCircle.h"
59 #include "SketchAPI_Mirror.h"
60 #include "SketchAPI_Point.h"
61 #include "SketchAPI_Projection.h"
62 #include "SketchAPI_Rectangle.h"
63 #include "SketchAPI_Rotation.h"
64 #include "SketchAPI_Translation.h"
65 //--------------------------------------------------------------------------------------
66 SketchAPI_Sketch::SketchAPI_Sketch(
67 const std::shared_ptr<ModelAPI_Feature> & theFeature)
68 : ModelHighAPI_Interface(theFeature)
73 SketchAPI_Sketch::SketchAPI_Sketch(
74 const std::shared_ptr<ModelAPI_Feature> & theFeature,
75 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
76 : ModelHighAPI_Interface(theFeature)
83 SketchAPI_Sketch::SketchAPI_Sketch(
84 const std::shared_ptr<ModelAPI_Feature> & theFeature,
85 const ModelHighAPI_Selection & theExternal)
86 : ModelHighAPI_Interface(theFeature)
89 setExternal(theExternal);
93 SketchAPI_Sketch::SketchAPI_Sketch(
94 const std::shared_ptr<ModelAPI_Feature> & theFeature,
95 std::shared_ptr<ModelAPI_Object> thePlaneObject)
96 : ModelHighAPI_Interface(theFeature)
99 setExternal(thePlaneObject);
103 SketchAPI_Sketch::~SketchAPI_Sketch()
108 //--------------------------------------------------------------------------------------
109 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
111 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
114 //--------------------------------------------------------------------------------------
115 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
117 fillAttribute(thePlane->origin(), myorigin);
118 fillAttribute(thePlane->dirX(), mydirX);
119 fillAttribute(thePlane->normal(), mynormal);
124 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
126 fillAttribute(theExternal, myexternal);
131 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
133 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
134 ModelHighAPI_Selection aSel(aRes);
138 //--------------------------------------------------------------------------------------
139 void SketchAPI_Sketch::setValue(
140 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
141 const ModelHighAPI_Double & theValue)
143 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
145 // theConstraint->execute();
148 //--------------------------------------------------------------------------------------
149 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
151 const_cast<SketchAPI_Sketch*>(this)->execute();
153 std::list<ModelHighAPI_Selection> aSelectionList;
155 ResultConstructionPtr aResultConstruction =
156 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
157 if (aResultConstruction.get() == NULL)
158 return aSelectionList;
160 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
161 aSelectionList.push_back(
162 ModelHighAPI_Selection(aResultConstruction,
163 aResultConstruction->face(anIndex)));
166 return aSelectionList;
169 //--------------------------------------------------------------------------------------
170 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
171 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
173 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
174 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
177 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
178 const ModelHighAPI_Selection & theExternal)
180 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
181 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
184 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
185 const std::string & theExternalName)
187 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
189 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
192 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
193 std::shared_ptr<ModelAPI_Object> thePlaneObject)
195 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
196 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
200 //--------------------------------------------------------------------------------------
201 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
202 double theX, double theY)
204 std::shared_ptr<ModelAPI_Feature> aFeature =
205 compositeFeature()->addFeature(SketchPlugin_Point::ID());
206 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
208 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
209 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
211 std::shared_ptr<ModelAPI_Feature> aFeature =
212 compositeFeature()->addFeature(SketchPlugin_Point::ID());
213 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
215 std::shared_ptr<SketchAPI_Point>
216 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
218 std::shared_ptr<ModelAPI_Feature> aFeature =
219 compositeFeature()->addFeature(SketchPlugin_Point::ID());
220 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
222 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
224 std::shared_ptr<ModelAPI_Feature> aFeature =
225 compositeFeature()->addFeature(SketchPlugin_Point::ID());
226 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
229 //--------------------------------------------------------------------------------------
230 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
231 const ModelHighAPI_Selection & theExternal)
233 std::shared_ptr<ModelAPI_Feature> aFeature =
234 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
235 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
237 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
238 const std::string & theExternalName)
240 std::shared_ptr<ModelAPI_Feature> aFeature =
241 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
242 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
245 //--------------------------------------------------------------------------------------
246 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
247 double theX2, double theY2)
249 std::shared_ptr<ModelAPI_Feature> aFeature =
250 compositeFeature()->addFeature(SketchPlugin_Line::ID());
251 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
253 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
254 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
255 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
257 std::shared_ptr<ModelAPI_Feature> aFeature =
258 compositeFeature()->addFeature(SketchPlugin_Line::ID());
259 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
261 std::shared_ptr<SketchAPI_Line>
262 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
264 std::shared_ptr<ModelAPI_Feature> aFeature =
265 compositeFeature()->addFeature(SketchPlugin_Line::ID());
266 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
268 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
270 std::shared_ptr<ModelAPI_Feature> aFeature =
271 compositeFeature()->addFeature(SketchPlugin_Line::ID());
272 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
275 //--------------------------------------------------------------------------------------
276 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
277 double theX2, double theY2)
279 std::shared_ptr<ModelAPI_Feature> aFeature =
280 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
281 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
283 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
284 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
285 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
287 std::shared_ptr<ModelAPI_Feature> aFeature =
288 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
289 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
292 //--------------------------------------------------------------------------------------
293 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
297 std::shared_ptr<ModelAPI_Feature> aFeature =
298 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
299 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
302 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
303 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
306 std::shared_ptr<ModelAPI_Feature> aFeature =
307 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
308 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
311 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
316 std::shared_ptr<ModelAPI_Feature> aFeature =
317 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
318 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
319 thePassedX, thePassedY));
322 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
323 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
324 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
326 std::shared_ptr<ModelAPI_Feature> aFeature =
327 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
328 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
331 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
332 double theX2, double theY2,
333 double theX3, double theY3)
335 std::shared_ptr<ModelAPI_Feature> aFeature =
336 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
337 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
342 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
343 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
344 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
345 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
347 std::shared_ptr<ModelAPI_Feature> aFeature =
348 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
349 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
352 std::shared_ptr<SketchAPI_Circle>
353 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
355 std::shared_ptr<ModelAPI_Feature> aFeature =
356 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
357 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
360 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
362 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
363 std::shared_ptr<ModelAPI_Feature> aFeature =
364 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
365 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
368 //--------------------------------------------------------------------------------------
369 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
370 double theStartX, double theStartY,
371 double theEndX, double theEndY,
374 std::shared_ptr<ModelAPI_Feature> aFeature =
375 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
376 return ArcPtr(new SketchAPI_Arc(aFeature,
377 theCenterX, theCenterY,
378 theStartX, theStartY,
383 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
384 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
385 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
386 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
389 std::shared_ptr<ModelAPI_Feature> aFeature =
390 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
391 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
394 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
395 double theEndX, double theEndY,
396 double thePassedX, double thePassedY)
398 std::shared_ptr<ModelAPI_Feature> aFeature =
399 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
400 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
401 theStartX, theStartY,
403 thePassedX, thePassedY));
406 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
407 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
408 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
409 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
411 std::shared_ptr<ModelAPI_Feature> aFeature =
412 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
413 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
416 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
417 const ModelHighAPI_RefAttr& theTangentPoint,
418 double theEndX, double theEndY,
421 std::shared_ptr<ModelAPI_Feature> aFeature =
422 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
423 return MacroArcPtr(new SketchAPI_MacroArc(
424 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
427 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
428 const ModelHighAPI_RefAttr& theTangentPoint,
429 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
432 std::shared_ptr<ModelAPI_Feature> aFeature =
433 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
434 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
437 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
439 std::shared_ptr<ModelAPI_Feature> aFeature =
440 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
441 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
444 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
446 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
447 std::shared_ptr<ModelAPI_Feature> aFeature =
448 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
449 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
452 //--------------------------------------------------------------------------------------
453 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
454 const ModelHighAPI_Selection & theExternalFeature)
456 std::shared_ptr<ModelAPI_Feature> aFeature =
457 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
458 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
461 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
462 const std::string & theExternalName)
464 std::shared_ptr<ModelAPI_Feature> aFeature =
465 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
466 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
469 //--------------------------------------------------------------------------------------
470 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
471 const ModelHighAPI_RefAttr & theMirrorLine,
472 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
474 std::shared_ptr<ModelAPI_Feature> aFeature =
475 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
476 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
479 //--------------------------------------------------------------------------------------
480 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
481 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
482 const ModelHighAPI_RefAttr & thePoint1,
483 const ModelHighAPI_RefAttr & thePoint2,
484 const ModelHighAPI_Integer & theNumberOfObjects,
487 std::shared_ptr<ModelAPI_Feature> aFeature =
488 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
489 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
490 thePoint2, theNumberOfObjects, theFullValue));
493 //--------------------------------------------------------------------------------------
494 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
495 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
496 const ModelHighAPI_RefAttr & theCenter,
497 const ModelHighAPI_Double & theAngle,
498 const ModelHighAPI_Integer & theNumberOfObjects,
501 std::shared_ptr<ModelAPI_Feature> aFeature =
502 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
504 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
505 theAngle, theNumberOfObjects, theFullValue));
508 //--------------------------------------------------------------------------------------
509 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
510 const ModelHighAPI_Reference& theFeature,
511 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
513 std::shared_ptr<ModelAPI_Feature> aFeature =
514 compositeFeature()->addFeature(SketchPlugin_Split::ID());
515 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
517 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
518 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
519 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
520 fillAttribute(thePositionPoint, aPointAttr);
523 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
526 //--------------------------------------------------------------------------------------
527 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
528 const ModelHighAPI_Reference& theFeature,
529 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
531 std::shared_ptr<ModelAPI_Feature> aFeature =
532 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
533 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
535 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
536 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
537 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
538 fillAttribute(thePositionPoint, aPointAttr);
541 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
544 //--------------------------------------------------------------------------------------
545 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
546 const ModelHighAPI_RefAttr & theLine1,
547 const ModelHighAPI_RefAttr & theLine2,
548 const ModelHighAPI_Double & theValue)
550 std::shared_ptr<ModelAPI_Feature> aFeature =
551 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
552 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
553 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
554 // fill the value before llines to avoid calculation of angle value by the Angle feature
555 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
556 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
557 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
559 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
562 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
563 const ModelHighAPI_RefAttr & theLine1,
564 const ModelHighAPI_RefAttr & theLine2,
565 const ModelHighAPI_Double & theValue)
567 std::shared_ptr<ModelAPI_Feature> aFeature =
568 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
569 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
570 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
571 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
572 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
573 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
574 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
576 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
579 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
580 const ModelHighAPI_RefAttr & theLine1,
581 const ModelHighAPI_RefAttr & theLine2,
582 const ModelHighAPI_Double & theValue)
584 std::shared_ptr<ModelAPI_Feature> aFeature =
585 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
586 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
587 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
588 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
589 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
590 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
591 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
593 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
596 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
597 const ModelHighAPI_RefAttr & thePoint1,
598 const ModelHighAPI_RefAttr & thePoint2)
600 std::shared_ptr<ModelAPI_Feature> aFeature =
601 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
602 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
603 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
605 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
608 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
609 const ModelHighAPI_RefAttr & theLine1,
610 const ModelHighAPI_RefAttr & theLine2)
612 std::shared_ptr<ModelAPI_Feature> aFeature =
613 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
614 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
615 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
617 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
620 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
621 const ModelHighAPI_RefAttr & thePoint,
622 const ModelHighAPI_RefAttr & thePointOrLine,
623 const ModelHighAPI_Double & theValue)
625 std::shared_ptr<ModelAPI_Feature> aFeature =
626 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
627 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
628 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
629 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
631 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
634 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
635 const ModelHighAPI_RefAttr & theObject1,
636 const ModelHighAPI_RefAttr & theObject2)
638 std::shared_ptr<ModelAPI_Feature> aFeature =
639 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
640 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
641 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
643 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
646 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
647 const ModelHighAPI_RefAttr & thePoint)
649 std::shared_ptr<ModelAPI_Feature> aFeature =
650 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
651 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
652 apply(); // finish operation to remove Fillet feature correcly
653 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
656 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
657 const ModelHighAPI_RefAttr & thePoint,
658 const ModelHighAPI_Double & theRadius)
660 CompositeFeaturePtr aSketch = compositeFeature();
661 int aNbSubs = aSketch->numberOfSubs();
664 InterfacePtr aFilletFeature = setFillet(thePoint);
666 // set radius for just created arc
667 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
668 if (anArc->getKind() == SketchPlugin_Arc::ID())
669 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
671 return aFilletFeature;
674 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
675 const ModelHighAPI_RefAttr & theObject)
677 std::shared_ptr<ModelAPI_Feature> aFeature =
678 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
679 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
681 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
684 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
685 const ModelHighAPI_RefAttr & theLine)
687 std::shared_ptr<ModelAPI_Feature> aFeature =
688 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
689 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
691 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
694 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
695 const ModelHighAPI_RefAttr & theLine,
696 const ModelHighAPI_Double & theValue)
698 std::shared_ptr<ModelAPI_Feature> aFeature =
699 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
700 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
701 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
703 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
706 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
707 const ModelHighAPI_RefAttr & thePoint,
708 const ModelHighAPI_RefAttr & theLine)
710 std::shared_ptr<ModelAPI_Feature> aFeature =
711 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
712 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
713 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
715 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
718 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
719 const ModelHighAPI_RefAttr & theLine1,
720 const ModelHighAPI_RefAttr & theLine2)
722 std::shared_ptr<ModelAPI_Feature> aFeature =
723 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
724 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
725 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
727 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
730 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
731 const ModelHighAPI_RefAttr & theLine1,
732 const ModelHighAPI_RefAttr & theLine2)
734 std::shared_ptr<ModelAPI_Feature> aFeature =
735 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
736 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
737 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
739 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
742 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
743 const ModelHighAPI_RefAttr & theCircleOrArc,
744 const ModelHighAPI_Double & theValue)
746 std::shared_ptr<ModelAPI_Feature> aFeature =
747 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
748 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
749 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
751 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
754 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
755 const ModelHighAPI_RefAttr & theLine,
756 const ModelHighAPI_RefAttr & theCircle)
758 std::shared_ptr<ModelAPI_Feature> aFeature =
759 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
760 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
761 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
763 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
766 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
767 const ModelHighAPI_RefAttr & theLine)
769 std::shared_ptr<ModelAPI_Feature> aFeature =
770 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
771 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
773 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
776 //--------------------------------------------------------------------------------------
778 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
780 FeaturePtr aBase = feature();
781 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
782 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
783 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
784 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
785 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
786 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
787 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
789 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
792 //--------------------------------------------------------------------------------------
794 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
796 FeaturePtr aBase = feature();
797 const std::string& aDocName = theDumper.name(aBase->document());
799 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
800 if (anExternal->value()) {
801 theDumper << aBase << " = model.addSketch(" << aDocName <<
802 ", " << anExternal << ")" << std::endl;
804 // Sketch is base on a plane.
805 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
806 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
807 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
808 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
809 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
810 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
812 // Check the plane is coordinate plane
813 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
814 if(anExternal->context()) { // checking for selected planes
815 if (!aPlaneName.empty()
816 && anExternal->context()->data()
817 && anExternal->context()->data()->name() == aPlaneName) {
818 // dump sketch based on coordinate plane
819 theDumper << aBase << " = model.addSketch(" << aDocName
820 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
821 } else { // some other plane
822 theDumper << aBase << " = model.addSketch(" << aDocName <<
823 ", " << anExternal<< ")" << std::endl;
826 if (aPlaneName.empty()) {
827 // needs import additional module
828 theDumper.importModule("GeomAPI");
829 // dump plane parameters
830 const std::string& aSketchName = theDumper.name(aBase);
831 std::string anOriginName = aSketchName + "_origin";
832 std::string aNormalName = aSketchName + "_norm";
833 std::string aDirXName = aSketchName + "_dirx";
834 // use "\n" instead of std::endl to avoid automatic dumping sketch here
835 // and then dumplicate dumping it in the next line
836 theDumper << anOriginName << " = " << anOrigin << "\n"
837 << aNormalName << " = " << aNormal << "\n"
838 << aDirXName << " = " << aDirX << "\n";
839 // dump sketch based on arbitrary plane
840 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
841 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
843 // dump sketch based on coordinate plane
844 theDumper << aBase << " = model.addSketch(" << aDocName
845 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
850 // dump sketch's subfeatures
851 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
852 theDumper.processSubs(aCompFeat, true);