Salome HOME
93d70ed9364084374ae3a66768588f8fbccad2a8
[modules/shaper.git] / src / SketchAPI / SketchAPI_Sketch.cpp
1 // Name   : SketchAPI_Sketch.cpp
2 // Purpose: 
3 //
4 // History:
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
6
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)
17 {
18   initialize();
19 }
20
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)
25 {
26   if (initialize()) {
27     setPlane(thePlane);
28   }
29 }
30
31 SketchAPI_Sketch::SketchAPI_Sketch(
32     const std::shared_ptr<ModelAPI_Feature> & theFeature,
33     const ModelHighAPI_Selection & theExternal)
34 : ModelHighAPI_Interface(theFeature)
35 {
36   if (initialize()) {
37     setExternal(theExternal);
38   }
39 }
40
41 SketchAPI_Sketch::~SketchAPI_Sketch()
42 {
43
44 }
45
46 //--------------------------------------------------------------------------------------
47 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
48 {
49   return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
50 }
51
52 //--------------------------------------------------------------------------------------
53 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
54 {
55   fillAttribute(thePlane->origin(), myorigin);
56   fillAttribute(thePlane->dirX(), mydirX);
57   fillAttribute(thePlane->normal(), mynormal);
58
59   execute();
60 }
61
62 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
63 {
64   fillAttribute(theExternal, myexternal);
65
66   execute();
67 }
68
69 //--------------------------------------------------------------------------------------
70 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
71                     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
72 {
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));
76 }
77
78 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
79                     const ModelHighAPI_Selection & theExternal)
80 {
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));
84 }
85
86 //--------------------------------------------------------------------------------------
87 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
88 {
89   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
90   return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
91 }
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)
95 {
96   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
97   return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
98 }
99 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
100 {
101   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
102   return LinePtr(new SketchAPI_Line(aFeature, theExternal));
103 }
104 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
105 {
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));
109 }
110 //--------------------------------------------------------------------------------------