]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Sketch.cpp
Salome HOME
Fixed Test/TestSketcherAddCircle.py
[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 <SketchPlugin_Constraint.h>
11 #include <SketchPlugin_ConstraintAngle.h>
12 //#include <SketchPlugin_ConstraintBase.h>
13 #include <SketchPlugin_ConstraintCoincidence.h>
14 #include <SketchPlugin_ConstraintCollinear.h>
15 #include <SketchPlugin_ConstraintDistance.h>
16 #include <SketchPlugin_ConstraintEqual.h>
17 #include <SketchPlugin_ConstraintFillet.h>
18 #include <SketchPlugin_ConstraintHorizontal.h>
19 #include <SketchPlugin_ConstraintLength.h>
20 #include <SketchPlugin_ConstraintMiddle.h>
21 #include <SketchPlugin_ConstraintMirror.h>
22 #include <SketchPlugin_ConstraintParallel.h>
23 #include <SketchPlugin_ConstraintPerpendicular.h>
24 #include <SketchPlugin_ConstraintRadius.h>
25 #include <SketchPlugin_ConstraintRigid.h>
26 #include <SketchPlugin_ConstraintTangent.h>
27 #include <SketchPlugin_ConstraintVertical.h>
28 //--------------------------------------------------------------------------------------
29 #include <ModelAPI_CompositeFeature.h>
30 #include <ModelHighAPI_Tools.h>
31 #include "SketchAPI_Circle.h"
32 #include "SketchAPI_Line.h"
33 //--------------------------------------------------------------------------------------
34 SketchAPI_Sketch::SketchAPI_Sketch(
35     const std::shared_ptr<ModelAPI_Feature> & theFeature)
36 : ModelHighAPI_Interface(theFeature)
37 {
38   initialize();
39 }
40
41 SketchAPI_Sketch::SketchAPI_Sketch(
42     const std::shared_ptr<ModelAPI_Feature> & theFeature,
43     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
44 : ModelHighAPI_Interface(theFeature)
45 {
46   if (initialize()) {
47     setPlane(thePlane);
48   }
49 }
50
51 SketchAPI_Sketch::SketchAPI_Sketch(
52     const std::shared_ptr<ModelAPI_Feature> & theFeature,
53     const ModelHighAPI_Selection & theExternal)
54 : ModelHighAPI_Interface(theFeature)
55 {
56   if (initialize()) {
57     setExternal(theExternal);
58   }
59 }
60
61 SketchAPI_Sketch::~SketchAPI_Sketch()
62 {
63
64 }
65
66 //--------------------------------------------------------------------------------------
67 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
68 {
69   return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
70 }
71
72 //--------------------------------------------------------------------------------------
73 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
74 {
75   fillAttribute(thePlane->origin(), myorigin);
76   fillAttribute(thePlane->dirX(), mydirX);
77   fillAttribute(thePlane->normal(), mynormal);
78
79   execute();
80 }
81
82 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
83 {
84   fillAttribute(theExternal, myexternal);
85
86   execute();
87 }
88
89 //--------------------------------------------------------------------------------------
90 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
91                     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
92 {
93   // TODO(spo): check that thePart is not empty
94   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
95   return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
96 }
97
98 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
99                     const ModelHighAPI_Selection & theExternal)
100 {
101   // TODO(spo): check that thePart is not empty
102   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
103   return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
104 }
105
106 //--------------------------------------------------------------------------------------
107 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
108 {
109   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
110   return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
111 }
112 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
113     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
114     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
115 {
116   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
117   return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
118 }
119 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
120 {
121   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
122   return LinePtr(new SketchAPI_Line(aFeature, theExternal));
123 }
124 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
125 {
126   // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
127   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
128   return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
129 }
130
131 //--------------------------------------------------------------------------------------
132 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
133                                                               double theCenterY,
134                                                               double theRadius)
135 {
136   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
137   return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
138 }
139
140 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
141                                                               double theRadius)
142 {
143   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
144   return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
145 }
146
147 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
148                                                               double theX2, double theY2,
149                                                               double theX3, double theY3)
150 {
151   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
152   return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
153 }
154
155 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
156                                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
157                                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
158 {
159   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
160   return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
161 }
162
163 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
164 {
165   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
166   return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
167 }
168
169 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
170 {
171   // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
172   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
173   return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
174 }
175
176 //--------------------------------------------------------------------------------------
177 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
178     const ModelHighAPI_RefAttr & thePoint1,
179     const ModelHighAPI_RefAttr & thePoint2)
180 {
181   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
182   fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
183   fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
184   aFeature->execute();
185   return aFeature;
186 }
187
188 //--------------------------------------------------------------------------------------
189 void SketchAPI_Sketch::setValue(
190     const std::shared_ptr<ModelAPI_Feature> & theConstraint,
191     const ModelHighAPI_Double & theValue)
192 {
193   fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
194 }
195
196 //--------------------------------------------------------------------------------------