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 email : webmaster.salome@opencascade.com<mailto: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_ConstraintEqual.h>
28 #include <SketchPlugin_Fillet.h>
29 #include <SketchPlugin_ConstraintHorizontal.h>
30 #include <SketchPlugin_ConstraintLength.h>
31 #include <SketchPlugin_ConstraintMiddle.h>
32 #include <SketchPlugin_ConstraintMirror.h>
33 #include <SketchPlugin_ConstraintParallel.h>
34 #include <SketchPlugin_ConstraintPerpendicular.h>
35 #include <SketchPlugin_ConstraintRadius.h>
36 #include <SketchPlugin_ConstraintRigid.h>
37 #include <SketchPlugin_Trim.h>
38 #include <SketchPlugin_Split.h>
39 #include <SketchPlugin_ConstraintTangent.h>
40 #include <SketchPlugin_ConstraintVertical.h>
41 #include <SketcherPrs_Tools.h>
42 //--------------------------------------------------------------------------------------
43 #include <ModelAPI_CompositeFeature.h>
44 #include <ModelAPI_ResultConstruction.h>
45 #include <ModelHighAPI_Double.h>
46 #include <ModelHighAPI_Dumper.h>
47 #include <ModelHighAPI_RefAttr.h>
48 #include <ModelHighAPI_Selection.h>
49 #include <ModelHighAPI_Services.h>
50 #include <ModelHighAPI_Tools.h>
51 //--------------------------------------------------------------------------------------
52 #include "SketchAPI_Arc.h"
53 #include "SketchAPI_MacroArc.h"
54 #include "SketchAPI_Circle.h"
55 #include "SketchAPI_IntersectionPoint.h"
56 #include "SketchAPI_Line.h"
57 #include "SketchAPI_MacroCircle.h"
58 #include "SketchAPI_Mirror.h"
59 #include "SketchAPI_Point.h"
60 #include "SketchAPI_Projection.h"
61 #include "SketchAPI_Rectangle.h"
62 #include "SketchAPI_Rotation.h"
63 #include "SketchAPI_Translation.h"
64 //--------------------------------------------------------------------------------------
65 SketchAPI_Sketch::SketchAPI_Sketch(
66 const std::shared_ptr<ModelAPI_Feature> & theFeature)
67 : ModelHighAPI_Interface(theFeature)
72 SketchAPI_Sketch::SketchAPI_Sketch(
73 const std::shared_ptr<ModelAPI_Feature> & theFeature,
74 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
75 : ModelHighAPI_Interface(theFeature)
82 SketchAPI_Sketch::SketchAPI_Sketch(
83 const std::shared_ptr<ModelAPI_Feature> & theFeature,
84 const ModelHighAPI_Selection & theExternal)
85 : ModelHighAPI_Interface(theFeature)
88 setExternal(theExternal);
92 SketchAPI_Sketch::SketchAPI_Sketch(
93 const std::shared_ptr<ModelAPI_Feature> & theFeature,
94 std::shared_ptr<ModelAPI_Object> thePlaneObject)
95 : ModelHighAPI_Interface(theFeature)
98 setExternal(thePlaneObject);
102 SketchAPI_Sketch::~SketchAPI_Sketch()
107 //--------------------------------------------------------------------------------------
108 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
110 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
113 //--------------------------------------------------------------------------------------
114 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
116 fillAttribute(thePlane->origin(), myorigin);
117 fillAttribute(thePlane->dirX(), mydirX);
118 fillAttribute(thePlane->normal(), mynormal);
123 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
125 fillAttribute(theExternal, myexternal);
130 void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
132 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
133 ModelHighAPI_Selection aSel(aRes);
137 //--------------------------------------------------------------------------------------
138 void SketchAPI_Sketch::setValue(
139 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
140 const ModelHighAPI_Double & theValue)
142 fillAttribute(theValue, theConstraint->feature()->real(SketchPlugin_Constraint::VALUE()));
144 // theConstraint->execute();
147 //--------------------------------------------------------------------------------------
148 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
150 const_cast<SketchAPI_Sketch*>(this)->execute();
152 std::list<ModelHighAPI_Selection> aSelectionList;
154 ResultConstructionPtr aResultConstruction =
155 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(feature()->firstResult());
156 if (aResultConstruction.get() == NULL)
157 return aSelectionList;
159 for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) {
160 aSelectionList.push_back(
161 ModelHighAPI_Selection(aResultConstruction,
162 aResultConstruction->face(anIndex)));
165 return aSelectionList;
168 //--------------------------------------------------------------------------------------
169 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
170 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
172 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
173 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
176 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
177 const ModelHighAPI_Selection & theExternal)
179 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
180 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
183 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
184 const std::string & theExternalName)
186 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
188 new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
191 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
192 std::shared_ptr<ModelAPI_Object> thePlaneObject)
194 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
195 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
199 //--------------------------------------------------------------------------------------
200 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
201 double theX, double theY)
203 std::shared_ptr<ModelAPI_Feature> aFeature =
204 compositeFeature()->addFeature(SketchPlugin_Point::ID());
205 return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
207 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
208 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
210 std::shared_ptr<ModelAPI_Feature> aFeature =
211 compositeFeature()->addFeature(SketchPlugin_Point::ID());
212 return PointPtr(new SketchAPI_Point(aFeature, thePoint));
214 std::shared_ptr<SketchAPI_Point>
215 SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
217 std::shared_ptr<ModelAPI_Feature> aFeature =
218 compositeFeature()->addFeature(SketchPlugin_Point::ID());
219 return PointPtr(new SketchAPI_Point(aFeature, theExternal));
221 std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
223 std::shared_ptr<ModelAPI_Feature> aFeature =
224 compositeFeature()->addFeature(SketchPlugin_Point::ID());
225 return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
228 //--------------------------------------------------------------------------------------
229 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
230 const ModelHighAPI_Selection & theExternal)
232 std::shared_ptr<ModelAPI_Feature> aFeature =
233 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
234 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternal));
236 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
237 const std::string & theExternalName)
239 std::shared_ptr<ModelAPI_Feature> aFeature =
240 compositeFeature()->addFeature(SketchPlugin_IntersectionPoint::ID());
241 return IntersectionPointPtr(new SketchAPI_IntersectionPoint(aFeature, theExternalName));
244 //--------------------------------------------------------------------------------------
245 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1,
246 double theX2, double theY2)
248 std::shared_ptr<ModelAPI_Feature> aFeature =
249 compositeFeature()->addFeature(SketchPlugin_Line::ID());
250 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
252 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
253 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
254 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
256 std::shared_ptr<ModelAPI_Feature> aFeature =
257 compositeFeature()->addFeature(SketchPlugin_Line::ID());
258 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
260 std::shared_ptr<SketchAPI_Line>
261 SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
263 std::shared_ptr<ModelAPI_Feature> aFeature =
264 compositeFeature()->addFeature(SketchPlugin_Line::ID());
265 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
267 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
269 std::shared_ptr<ModelAPI_Feature> aFeature =
270 compositeFeature()->addFeature(SketchPlugin_Line::ID());
271 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
274 //--------------------------------------------------------------------------------------
275 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1,
276 double theX2, double theY2)
278 std::shared_ptr<ModelAPI_Feature> aFeature =
279 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
280 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
282 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
283 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
284 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
286 std::shared_ptr<ModelAPI_Feature> aFeature =
287 compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
288 return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
291 //--------------------------------------------------------------------------------------
292 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
296 std::shared_ptr<ModelAPI_Feature> aFeature =
297 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
298 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
301 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
302 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
305 std::shared_ptr<ModelAPI_Feature> aFeature =
306 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
307 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
310 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
315 std::shared_ptr<ModelAPI_Feature> aFeature =
316 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
317 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
318 thePassedX, thePassedY));
321 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
322 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
323 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
325 std::shared_ptr<ModelAPI_Feature> aFeature =
326 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
327 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
330 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
331 double theX2, double theY2,
332 double theX3, double theY3)
334 std::shared_ptr<ModelAPI_Feature> aFeature =
335 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
336 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
341 std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
342 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
343 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
344 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
346 std::shared_ptr<ModelAPI_Feature> aFeature =
347 compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
348 return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
351 std::shared_ptr<SketchAPI_Circle>
352 SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
354 std::shared_ptr<ModelAPI_Feature> aFeature =
355 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
356 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
359 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
361 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
362 std::shared_ptr<ModelAPI_Feature> aFeature =
363 compositeFeature()->addFeature(SketchPlugin_Circle::ID());
364 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
367 //--------------------------------------------------------------------------------------
368 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
369 double theStartX, double theStartY,
370 double theEndX, double theEndY,
373 std::shared_ptr<ModelAPI_Feature> aFeature =
374 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
375 return ArcPtr(new SketchAPI_Arc(aFeature,
376 theCenterX, theCenterY,
377 theStartX, theStartY,
382 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(
383 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
384 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
385 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
388 std::shared_ptr<ModelAPI_Feature> aFeature =
389 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
390 return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed));
393 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, double theStartY,
394 double theEndX, double theEndY,
395 double thePassedX, double thePassedY)
397 std::shared_ptr<ModelAPI_Feature> aFeature =
398 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
399 return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
400 theStartX, theStartY,
402 thePassedX, thePassedY));
405 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
406 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
407 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
408 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
410 std::shared_ptr<ModelAPI_Feature> aFeature =
411 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
412 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
415 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
416 const ModelHighAPI_RefAttr& theTangentPoint,
417 double theEndX, double theEndY,
420 std::shared_ptr<ModelAPI_Feature> aFeature =
421 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
422 return MacroArcPtr(new SketchAPI_MacroArc(
423 aFeature, theTangentPoint, theEndX, theEndY, theInversed));
426 std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
427 const ModelHighAPI_RefAttr& theTangentPoint,
428 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
431 std::shared_ptr<ModelAPI_Feature> aFeature =
432 compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
433 return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
436 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal)
438 std::shared_ptr<ModelAPI_Feature> aFeature =
439 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
440 return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
443 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
445 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
446 std::shared_ptr<ModelAPI_Feature> aFeature =
447 compositeFeature()->addFeature(SketchPlugin_Arc::ID());
448 return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
451 //--------------------------------------------------------------------------------------
452 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
453 const ModelHighAPI_Selection & theExternalFeature)
455 std::shared_ptr<ModelAPI_Feature> aFeature =
456 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
457 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalFeature));
460 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
461 const std::string & theExternalName)
463 std::shared_ptr<ModelAPI_Feature> aFeature =
464 compositeFeature()->addFeature(SketchPlugin_Projection::ID());
465 return ProjectionPtr(new SketchAPI_Projection(aFeature, theExternalName));
468 //--------------------------------------------------------------------------------------
469 std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
470 const ModelHighAPI_RefAttr & theMirrorLine,
471 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
473 std::shared_ptr<ModelAPI_Feature> aFeature =
474 compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
475 return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
478 //--------------------------------------------------------------------------------------
479 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
480 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
481 const ModelHighAPI_RefAttr & thePoint1,
482 const ModelHighAPI_RefAttr & thePoint2,
483 const ModelHighAPI_Integer & theNumberOfObjects,
486 std::shared_ptr<ModelAPI_Feature> aFeature =
487 compositeFeature()->addFeature(SketchPlugin_MultiTranslation::ID());
488 return TranslationPtr(new SketchAPI_Translation(aFeature, theObjects, thePoint1,
489 thePoint2, theNumberOfObjects, theFullValue));
492 //--------------------------------------------------------------------------------------
493 std::shared_ptr<SketchAPI_Rotation> SketchAPI_Sketch::addRotation(
494 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
495 const ModelHighAPI_RefAttr & theCenter,
496 const ModelHighAPI_Double & theAngle,
497 const ModelHighAPI_Integer & theNumberOfObjects,
500 std::shared_ptr<ModelAPI_Feature> aFeature =
501 compositeFeature()->addFeature(SketchPlugin_MultiRotation::ID());
503 new SketchAPI_Rotation(aFeature, theObjects, theCenter,
504 theAngle, theNumberOfObjects, theFullValue));
507 //--------------------------------------------------------------------------------------
508 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addSplit(
509 const ModelHighAPI_Reference& theFeature,
510 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
512 std::shared_ptr<ModelAPI_Feature> aFeature =
513 compositeFeature()->addFeature(SketchPlugin_Split::ID());
514 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Split::SELECTED_OBJECT()));
516 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Split::SELECTED_POINT());
517 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
518 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
519 fillAttribute(thePositionPoint, aPointAttr);
522 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
525 //--------------------------------------------------------------------------------------
526 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
527 const ModelHighAPI_Reference& theFeature,
528 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint)
530 std::shared_ptr<ModelAPI_Feature> aFeature =
531 compositeFeature()->addFeature(SketchPlugin_Trim::ID());
532 fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT()));
534 AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT());
535 if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
536 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
537 fillAttribute(thePositionPoint, aPointAttr);
540 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
543 //--------------------------------------------------------------------------------------
544 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngle(
545 const ModelHighAPI_RefAttr & theLine1,
546 const ModelHighAPI_RefAttr & theLine2,
547 const ModelHighAPI_Double & theValue)
549 std::shared_ptr<ModelAPI_Feature> aFeature =
550 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
551 fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
552 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
553 // fill the value before llines to avoid calculation of angle value by the Angle feature
554 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
555 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
556 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
558 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
561 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleComplementary(
562 const ModelHighAPI_RefAttr & theLine1,
563 const ModelHighAPI_RefAttr & theLine2,
564 const ModelHighAPI_Double & theValue)
566 std::shared_ptr<ModelAPI_Feature> aFeature =
567 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
568 fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
569 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
570 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
571 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
572 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
573 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
575 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
578 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setAngleBackward(
579 const ModelHighAPI_RefAttr & theLine1,
580 const ModelHighAPI_RefAttr & theLine2,
581 const ModelHighAPI_Double & theValue)
583 std::shared_ptr<ModelAPI_Feature> aFeature =
584 compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
585 fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
586 aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
587 fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
588 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
589 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
590 // fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
592 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
595 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCoincident(
596 const ModelHighAPI_RefAttr & thePoint1,
597 const ModelHighAPI_RefAttr & thePoint2)
599 std::shared_ptr<ModelAPI_Feature> aFeature =
600 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
601 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
602 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
604 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
607 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setCollinear(
608 const ModelHighAPI_RefAttr & theLine1,
609 const ModelHighAPI_RefAttr & theLine2)
611 std::shared_ptr<ModelAPI_Feature> aFeature =
612 compositeFeature()->addFeature(SketchPlugin_ConstraintCollinear::ID());
613 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
614 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
616 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
619 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setDistance(
620 const ModelHighAPI_RefAttr & thePoint,
621 const ModelHighAPI_RefAttr & thePointOrLine,
622 const ModelHighAPI_Double & theValue)
624 std::shared_ptr<ModelAPI_Feature> aFeature =
625 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
626 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
627 fillAttribute(thePointOrLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
628 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
630 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
633 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setEqual(
634 const ModelHighAPI_RefAttr & theObject1,
635 const ModelHighAPI_RefAttr & theObject2)
637 std::shared_ptr<ModelAPI_Feature> aFeature =
638 compositeFeature()->addFeature(SketchPlugin_ConstraintEqual::ID());
639 fillAttribute(theObject1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
640 fillAttribute(theObject2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
642 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
645 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFillet(
646 const ModelHighAPI_RefAttr & thePoint)
648 std::shared_ptr<ModelAPI_Feature> aFeature =
649 compositeFeature()->addFeature(SketchPlugin_Fillet::ID());
650 fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID()));
651 apply(); // finish operation to remove Fillet feature correcly
652 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
655 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFilletWithRadius(
656 const ModelHighAPI_RefAttr & thePoint,
657 const ModelHighAPI_Double & theRadius)
659 CompositeFeaturePtr aSketch = compositeFeature();
660 int aNbSubs = aSketch->numberOfSubs();
663 InterfacePtr aFilletFeature = setFillet(thePoint);
665 // set radius for just created arc
666 FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1);
667 if (anArc->getKind() == SketchPlugin_Arc::ID())
668 setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius));
670 return aFilletFeature;
673 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setFixed(
674 const ModelHighAPI_RefAttr & theObject)
676 std::shared_ptr<ModelAPI_Feature> aFeature =
677 compositeFeature()->addFeature(SketchPlugin_ConstraintRigid::ID());
678 fillAttribute(theObject, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
680 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
683 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setHorizontal(
684 const ModelHighAPI_RefAttr & theLine)
686 std::shared_ptr<ModelAPI_Feature> aFeature =
687 compositeFeature()->addFeature(SketchPlugin_ConstraintHorizontal::ID());
688 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
690 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
693 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setLength(
694 const ModelHighAPI_RefAttr & theLine,
695 const ModelHighAPI_Double & theValue)
697 std::shared_ptr<ModelAPI_Feature> aFeature =
698 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
699 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
700 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
702 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
705 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setMiddlePoint(
706 const ModelHighAPI_RefAttr & thePoint,
707 const ModelHighAPI_RefAttr & theLine)
709 std::shared_ptr<ModelAPI_Feature> aFeature =
710 compositeFeature()->addFeature(SketchPlugin_ConstraintMiddle::ID());
711 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
712 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
714 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
717 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setParallel(
718 const ModelHighAPI_RefAttr & theLine1,
719 const ModelHighAPI_RefAttr & theLine2)
721 std::shared_ptr<ModelAPI_Feature> aFeature =
722 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
723 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
724 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
726 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
729 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setPerpendicular(
730 const ModelHighAPI_RefAttr & theLine1,
731 const ModelHighAPI_RefAttr & theLine2)
733 std::shared_ptr<ModelAPI_Feature> aFeature =
734 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
735 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
736 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
738 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
741 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setRadius(
742 const ModelHighAPI_RefAttr & theCircleOrArc,
743 const ModelHighAPI_Double & theValue)
745 std::shared_ptr<ModelAPI_Feature> aFeature =
746 compositeFeature()->addFeature(SketchPlugin_ConstraintRadius::ID());
747 fillAttribute(theCircleOrArc, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
748 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
750 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
753 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setTangent(
754 const ModelHighAPI_RefAttr & theLine,
755 const ModelHighAPI_RefAttr & theCircle)
757 std::shared_ptr<ModelAPI_Feature> aFeature =
758 compositeFeature()->addFeature(SketchPlugin_ConstraintTangent::ID());
759 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
760 fillAttribute(theCircle, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
762 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
765 std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::setVertical(
766 const ModelHighAPI_RefAttr & theLine)
768 std::shared_ptr<ModelAPI_Feature> aFeature =
769 compositeFeature()->addFeature(SketchPlugin_ConstraintVertical::ID());
770 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
772 return InterfacePtr(new ModelHighAPI_Interface(aFeature));
775 //--------------------------------------------------------------------------------------
777 std::shared_ptr<GeomAPI_Pnt2d> SketchAPI_Sketch::to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
779 FeaturePtr aBase = feature();
780 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
781 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
782 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
783 aBase->attribute(SketchPlugin_Sketch::NORM_ID()));
784 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
785 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()));
786 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
788 return thePoint->to2D(aC->pnt(), aX->dir(), aY);
791 //--------------------------------------------------------------------------------------
793 void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
795 FeaturePtr aBase = feature();
796 const std::string& aDocName = theDumper.name(aBase->document());
798 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
799 if (anExternal->value()) {
800 theDumper << aBase << " = model.addSketch(" << aDocName <<
801 ", " << anExternal << ")" << std::endl;
803 // Sketch is base on a plane.
804 std::shared_ptr<GeomAPI_Pnt> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
805 aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID()))->pnt();
806 std::shared_ptr<GeomAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
807 aBase->attribute(SketchPlugin_Sketch::NORM_ID()))->dir();
808 std::shared_ptr<GeomAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
809 aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
811 // Check the plane is coordinate plane
812 std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
813 if(anExternal->context()) { // checking for selected planes
814 if (!aPlaneName.empty()
815 && anExternal->context()->data()
816 && anExternal->context()->data()->name() == aPlaneName) {
817 // dump sketch based on coordinate plane
818 theDumper << aBase << " = model.addSketch(" << aDocName
819 << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
820 } else { // some other plane
821 theDumper << aBase << " = model.addSketch(" << aDocName <<
822 ", " << anExternal<< ")" << std::endl;
825 if (aPlaneName.empty()) {
826 // needs import additional module
827 theDumper.importModule("GeomAPI");
828 // dump plane parameters
829 const std::string& aSketchName = theDumper.name(aBase);
830 std::string anOriginName = aSketchName + "_origin";
831 std::string aNormalName = aSketchName + "_norm";
832 std::string aDirXName = aSketchName + "_dirx";
833 // use "\n" instead of std::endl to avoid automatic dumping sketch here
834 // and then dumplicate dumping it in the next line
835 theDumper << anOriginName << " = " << anOrigin << "\n"
836 << aNormalName << " = " << aNormal << "\n"
837 << aDirXName << " = " << aDirX << "\n";
838 // dump sketch based on arbitrary plane
839 theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
840 << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
842 // dump sketch based on coordinate plane
843 theDumper << aBase << " = model.addSketch(" << aDocName
844 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
849 // dump sketch's subfeatures
850 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
851 theDumper.processSubs(aCompFeat, true);