1 // Name : SketchAPI_Sketch.cpp
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Sketch.h"
9 //--------------------------------------------------------------------------------------
10 #include <ModelAPI_CompositeFeature.h>
11 #include <ModelHighAPI_Tools.h>
12 #include "SketchAPI_Line.h"
13 //--------------------------------------------------------------------------------------
14 SketchAPI_Sketch::SketchAPI_Sketch(
15 const std::shared_ptr<ModelAPI_Feature> & theFeature)
16 : ModelHighAPI_Interface(theFeature)
21 SketchAPI_Sketch::SketchAPI_Sketch(
22 const std::shared_ptr<ModelAPI_Feature> & theFeature,
23 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
24 : ModelHighAPI_Interface(theFeature)
31 SketchAPI_Sketch::SketchAPI_Sketch(
32 const std::shared_ptr<ModelAPI_Feature> & theFeature,
33 const ModelHighAPI_Selection & theExternal)
34 : ModelHighAPI_Interface(theFeature)
37 setExternal(theExternal);
41 SketchAPI_Sketch::~SketchAPI_Sketch()
46 //--------------------------------------------------------------------------------------
47 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
49 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
52 //--------------------------------------------------------------------------------------
53 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
55 fillAttribute(thePlane->origin(), myorigin);
56 fillAttribute(thePlane->dirX(), mydirX);
57 fillAttribute(thePlane->normal(), mynormal);
62 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
64 fillAttribute(theExternal, myexternal);
69 //--------------------------------------------------------------------------------------
70 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
71 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
73 // TODO(spo): check that thePart is not empty
74 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
75 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
78 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
79 const ModelHighAPI_Selection & theExternal)
81 // TODO(spo): check that thePart is not empty
82 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
83 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
86 //--------------------------------------------------------------------------------------
87 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
89 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
90 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
92 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
93 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
94 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
96 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
97 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
99 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
101 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
102 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
104 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
106 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
107 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
108 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
111 //--------------------------------------------------------------------------------------