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_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)
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)
51 SketchAPI_Sketch::SketchAPI_Sketch(
52 const std::shared_ptr<ModelAPI_Feature> & theFeature,
53 const ModelHighAPI_Selection & theExternal)
54 : ModelHighAPI_Interface(theFeature)
57 setExternal(theExternal);
61 SketchAPI_Sketch::~SketchAPI_Sketch()
66 //--------------------------------------------------------------------------------------
67 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
69 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
72 //--------------------------------------------------------------------------------------
73 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
75 fillAttribute(thePlane->origin(), myorigin);
76 fillAttribute(thePlane->dirX(), mydirX);
77 fillAttribute(thePlane->normal(), mynormal);
82 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
84 fillAttribute(theExternal, myexternal);
89 //--------------------------------------------------------------------------------------
90 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
91 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
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));
98 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
99 const ModelHighAPI_Selection & theExternal)
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));
106 //--------------------------------------------------------------------------------------
107 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
109 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
110 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
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)
116 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
117 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
119 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
121 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
122 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
124 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
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));
131 //--------------------------------------------------------------------------------------
132 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
136 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
137 return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
140 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
143 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
144 return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
147 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
148 double theX2, double theY2,
149 double theX3, double theY3)
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));
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)
159 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID());
160 return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
163 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal)
165 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
166 return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
169 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
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));
176 //--------------------------------------------------------------------------------------
177 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
178 const ModelHighAPI_RefAttr & thePoint1,
179 const ModelHighAPI_RefAttr & thePoint2)
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()));
188 //--------------------------------------------------------------------------------------
189 void SketchAPI_Sketch::setValue(
190 const std::shared_ptr<ModelAPI_Feature> & theConstraint,
191 const ModelHighAPI_Double & theValue)
193 fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
196 //--------------------------------------------------------------------------------------