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_Line.h"
32 //--------------------------------------------------------------------------------------
33 SketchAPI_Sketch::SketchAPI_Sketch(
34 const std::shared_ptr<ModelAPI_Feature> & theFeature)
35 : ModelHighAPI_Interface(theFeature)
40 SketchAPI_Sketch::SketchAPI_Sketch(
41 const std::shared_ptr<ModelAPI_Feature> & theFeature,
42 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
43 : ModelHighAPI_Interface(theFeature)
50 SketchAPI_Sketch::SketchAPI_Sketch(
51 const std::shared_ptr<ModelAPI_Feature> & theFeature,
52 const ModelHighAPI_Selection & theExternal)
53 : ModelHighAPI_Interface(theFeature)
56 setExternal(theExternal);
60 SketchAPI_Sketch::~SketchAPI_Sketch()
65 //--------------------------------------------------------------------------------------
66 std::shared_ptr<ModelAPI_CompositeFeature> SketchAPI_Sketch::compositeFeature() const
68 return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
71 //--------------------------------------------------------------------------------------
72 void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
74 fillAttribute(thePlane->origin(), myorigin);
75 fillAttribute(thePlane->dirX(), mydirX);
76 fillAttribute(thePlane->normal(), mynormal);
81 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
83 fillAttribute(theExternal, myexternal);
88 //--------------------------------------------------------------------------------------
89 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
90 const std::shared_ptr<GeomAPI_Ax3> & thePlane)
92 // TODO(spo): check that thePart is not empty
93 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
94 return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane));
97 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
98 const ModelHighAPI_Selection & theExternal)
100 // TODO(spo): check that thePart is not empty
101 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
102 return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
105 //--------------------------------------------------------------------------------------
106 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
108 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
109 return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2));
111 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
112 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
113 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
115 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
116 return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint));
118 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
120 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
121 return LinePtr(new SketchAPI_Line(aFeature, theExternal));
123 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
125 // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
126 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
127 return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
130 //--------------------------------------------------------------------------------------
131 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
132 const ModelHighAPI_RefAttr & thePoint1,
133 const ModelHighAPI_RefAttr & thePoint2)
135 std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
136 fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
137 fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
142 //--------------------------------------------------------------------------------------
143 void SketchAPI_Sketch::setValue(
144 const std::shared_ptr<ModelAPI_Feature> & theConstraint,
145 const ModelHighAPI_Double & theValue)
147 fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
150 //--------------------------------------------------------------------------------------