1 // Name : ConstructionAPI_Point.cpp
5 // 29/03/16 - Sergey POKHODENKO - Creation of the file
7 #include "ConstructionAPI_Point.h"
9 #include <GeomAPI_Shape.h>
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Selection.h>
13 #include <ModelHighAPI_Tools.h>
15 //==================================================================================================
16 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
17 : ModelHighAPI_Interface(theFeature)
22 //==================================================================================================
23 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
24 const ModelHighAPI_Double& theX,
25 const ModelHighAPI_Double& theY,
26 const ModelHighAPI_Double& theZ)
27 : ModelHighAPI_Interface(theFeature)
30 setByXYZ(theX, theY, theZ);
34 /*//==================================================================================================
35 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
36 const ModelHighAPI_Selection& theEdge,
37 const ModelHighAPI_Double& theDistanceValue,
38 const bool theDistancePercent,
39 const bool theReverse)
40 : ModelHighAPI_Interface(theFeature)
43 setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
47 //==================================================================================================
48 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49 const ModelHighAPI_Selection& theObject1,
50 const ModelHighAPI_Selection& theObject2)
51 : ModelHighAPI_Interface(theFeature)
54 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
55 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
57 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
58 // If first object is vertex and second object is face then set by projection.
59 setByProjection(theObject1, theObject2);
60 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
61 // If both objects are edges then set by lines intersection.
62 setByLinesIntersection(theObject1, theObject2);
63 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
64 // If first object is edge and second object is face then set by line and plane intersection.
65 setByLineAndPlaneIntersection(theObject1, theObject2);
70 //==================================================================================================
71 ConstructionAPI_Point::~ConstructionAPI_Point()
76 //==================================================================================================
77 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
78 const ModelHighAPI_Double& theY,
79 const ModelHighAPI_Double& theZ)
81 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
82 fillAttribute(theX, myx);
83 fillAttribute(theY, myy);
84 fillAttribute(theZ, myz);
89 /*//==================================================================================================
90 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
91 const ModelHighAPI_Double& theDistanceValue,
92 const bool theDistancePercent,
93 const bool theReverse)
95 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
96 fillAttribute(theEdge, myedge);
97 fillAttribute(theDistanceValue, mydistanceValue);
98 fillAttribute(theDistancePercent, mydistancePercent);
99 fillAttribute(theReverse, myreverse);
104 //==================================================================================================
105 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
106 const ModelHighAPI_Selection& theFace)
108 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
109 fillAttribute(theVertex, mypoint);
110 fillAttribute(theFace, myplane);
115 //==================================================================================================
116 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
117 const ModelHighAPI_Selection& theEdge2)
119 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
120 fillAttribute(theEdge1, myfirstLine);
121 fillAttribute(theEdge2, mysecondLine);
126 //==================================================================================================
127 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
128 const ModelHighAPI_Selection& theFace)
130 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
131 fillAttribute(theEdge, myintersectionLine);
132 fillAttribute(theFace, myintersectionPlane);
137 //==================================================================================================
138 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
140 // TODO: all types of points
142 FeaturePtr aBase = feature();
143 const std::string& aDocName = theDumper.name(aBase->document());
145 AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Point::X());
146 AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Point::Y());
147 AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Point::Z());
148 theDumper << aBase << " = model.addPoint(" << aDocName << ", "
149 << anAttrX << ", " << anAttrY << ", " << anAttrZ << ")" << std::endl;
152 //==================================================================================================
153 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
154 const ModelHighAPI_Double& theX,
155 const ModelHighAPI_Double& theY,
156 const ModelHighAPI_Double& theZ)
158 // TODO(spo): check that thePart is not empty
159 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
160 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
163 /*//==================================================================================================
164 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
165 const ModelHighAPI_Selection& theEdge,
166 const ModelHighAPI_Double& theDistanceValue,
167 const bool theDistancePercent,
168 const bool theReverse)
170 // TODO(spo): check that thePart is not empty
171 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
172 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
175 //==================================================================================================
176 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
177 const ModelHighAPI_Selection& theObject1,
178 const ModelHighAPI_Selection& theObject2)
180 // TODO(spo): check that thePart is not empty
181 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
182 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));