1 // Name : SketchAPI_Sketch.cpp
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Sketch.h"
9 //--------------------------------------------------------------------------------------
10 #include <SketchPlugin_Constraint.h>
11 #include <SketchPlugin_ConstraintAngle.h>
12 #include <SketchPlugin_ConstraintCoincidence.h>
13 #include <SketchPlugin_ConstraintCollinear.h>
14 #include <SketchPlugin_ConstraintDistance.h>
15 #include <SketchPlugin_ConstraintEqual.h>
16 #include <SketchPlugin_ConstraintFillet.h>
17 #include <SketchPlugin_ConstraintHorizontal.h>
18 #include <SketchPlugin_ConstraintLength.h>
19 #include <SketchPlugin_ConstraintMiddle.h>
20 #include <SketchPlugin_ConstraintMirror.h>
21 #include <SketchPlugin_ConstraintParallel.h>
22 #include <SketchPlugin_ConstraintPerpendicular.h>
23 #include <SketchPlugin_ConstraintRadius.h>
24 #include <SketchPlugin_ConstraintRigid.h>
25 #include <SketchPlugin_ConstraintTangent.h>
26 #include <SketchPlugin_ConstraintVertical.h>
27 //--------------------------------------------------------------------------------------
28 #include <ModelAPI_CompositeFeature.h>
29 #include <ModelHighAPI_RefAttr.h>
30 #include <ModelHighAPI_Selection.h>
31 #include <ModelHighAPI_Tools.h>
32 //--------------------------------------------------------------------------------------
33 #include "SketchAPI_Circle.h"
34 #include "SketchAPI_Line.h"
35 //--------------------------------------------------------------------------------------
36 SketchAPI_Sketch::SketchAPI_Sketch(
37 const std::shared_ptr<ModelAPI_Feature> & theFeature)
38 : ModelHighAPI_Interface(theFeature)
43 SketchAPI_Sketch::SketchAPI_Sketch(
44 const std::shared_ptr<ModelAPI_Feature> & theFeature,
45 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
46 : ModelHighAPI_Interface(theFeature)
53 SketchAPI_Sketch::SketchAPI_Sketch(
54 const std::shared_ptr<ModelAPI_Feature> & theFeature,
55 const ModelHighAPI_Selection & theExternal)
56 : ModelHighAPI_Interface(theFeature)
59 setExternal(theExternal);
63 SketchAPI_Sketch::~SketchAPI_Sketch()
68 //--------------------------------------------------------------------------------------
69 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
71 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
74 //--------------------------------------------------------------------------------------
75 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
77 fillAttribute(thePlane->origin(), myorigin);
78 fillAttribute(thePlane->dirX(), mydirX);
79 fillAttribute(thePlane->normal(), mynormal);
84 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
86 fillAttribute(theExternal, myexternal);
91 //--------------------------------------------------------------------------------------
92 void SketchAPI_Sketch::setValue(
93 const std::shared_ptr<ModelAPI_Feature> & theConstraint,
94 const ModelHighAPI_Double & theValue)
96 // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
97 fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
99 theConstraint->execute();
102 //--------------------------------------------------------------------------------------
103 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
104 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
106 // TODO(spo): check that thePart is not empty
107 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
108 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
111 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
112 const ModelHighAPI_Selection & theExternal)
114 // TODO(spo): check that thePart is not empty
115 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
116 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
119 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
120 const std::string & theExternalName)
122 // TODO(spo): check that thePart is not empty
123 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
124 return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
127 //--------------------------------------------------------------------------------------
128 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
130 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
131 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
133 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
134 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
135 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
137 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
138 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
140 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
142 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
143 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
145 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
147 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
148 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
149 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
152 //--------------------------------------------------------------------------------------
153 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
157 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
158 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
161 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
164 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
165 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
168 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
169 double theX2, double theY2,
170 double theX3, double theY3)
172 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
173 return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
176 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
177 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
178 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
180 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
181 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
184 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
186 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
187 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
190 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
192 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
193 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
194 return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
197 //--------------------------------------------------------------------------------------
198 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
199 const ModelHighAPI_RefAttr & thePoint1,
200 const ModelHighAPI_RefAttr & thePoint2)
202 std::shared_ptr<ModelAPI_Feature> aFeature =
203 compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
204 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
205 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
210 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
211 const ModelHighAPI_RefAttr & thePoint,
212 const ModelHighAPI_RefAttr & theLine,
213 const ModelHighAPI_Double & theValue)
215 std::shared_ptr<ModelAPI_Feature> aFeature =
216 compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
217 fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
218 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
219 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
224 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
225 const ModelHighAPI_RefAttr & theLine,
226 const ModelHighAPI_Double & theValue)
228 std::shared_ptr<ModelAPI_Feature> aFeature =
229 compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
230 fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
231 fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
236 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
237 const ModelHighAPI_RefAttr & theLine1,
238 const ModelHighAPI_RefAttr & theLine2)
240 std::shared_ptr<ModelAPI_Feature> aFeature =
241 compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
242 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
243 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
248 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
249 const ModelHighAPI_RefAttr & theLine1,
250 const ModelHighAPI_RefAttr & theLine2)
252 std::shared_ptr<ModelAPI_Feature> aFeature =
253 compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
254 fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
255 fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
259 //--------------------------------------------------------------------------------------