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_Selection.h>
12 #include <ModelHighAPI_Tools.h>
16 /*static GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr);
17 static GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection);*/
19 //==================================================================================================
20 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
21 : ModelHighAPI_Interface(theFeature)
26 //==================================================================================================
27 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
28 const ModelHighAPI_Double& theX,
29 const ModelHighAPI_Double& theY,
30 const ModelHighAPI_Double& theZ)
31 : ModelHighAPI_Interface(theFeature)
34 setByXYZ(theX, theY, theZ);
38 /*//==================================================================================================
39 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
40 const ModelHighAPI_Selection& theEdge,
41 const ModelHighAPI_Double& theDistanceValue,
42 const bool theDistancePercent,
43 const bool theReverse)
44 : ModelHighAPI_Interface(theFeature)
47 setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
51 //==================================================================================================
52 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
53 const ModelHighAPI_Selection& theObject1,
54 const ModelHighAPI_Selection& theObject2)
55 : ModelHighAPI_Interface(theFeature)
58 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
59 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
61 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
62 // If first object is vertex and second object is face then set by projection.
63 setByProjection(theObject1, theObject2);
64 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
65 // If both objects are edges then set by lines intersection.
66 setByLinesIntersection(theObject1, theObject2);
67 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
68 // If first object is edge and second object is face then set by line and plane intersection.
69 setByLineAndPlaneIntersection(theObject1, theObject2);
74 //==================================================================================================
75 ConstructionAPI_Point::~ConstructionAPI_Point()
80 //==================================================================================================
81 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
82 const ModelHighAPI_Double& theY,
83 const ModelHighAPI_Double& theZ)
85 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
86 fillAttribute(theX, myx);
87 fillAttribute(theY, myy);
88 fillAttribute(theZ, myz);
93 /*//==================================================================================================
94 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
95 const ModelHighAPI_Double& theDistanceValue,
96 const bool theDistancePercent,
97 const bool theReverse)
99 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
100 fillAttribute(theEdge, myedge);
101 fillAttribute(theDistanceValue, mydistanceValue);
102 fillAttribute(theDistancePercent, mydistancePercent);
103 fillAttribute(theReverse, myreverse);
108 //==================================================================================================
109 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
110 const ModelHighAPI_Selection& theFace)
112 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
113 fillAttribute(theVertex, mypoint);
114 fillAttribute(theFace, myplane);
119 //==================================================================================================
120 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
121 const ModelHighAPI_Selection& theEdge2)
123 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
124 fillAttribute(theEdge1, myfirstLine);
125 fillAttribute(theEdge2, mysecondLine);
130 //==================================================================================================
131 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
132 const ModelHighAPI_Selection& theFace)
134 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
135 fillAttribute(theEdge, myintersectionLine);
136 fillAttribute(theFace, myintersectionPlane);
141 //==================================================================================================
142 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
143 const ModelHighAPI_Double& theX,
144 const ModelHighAPI_Double& theY,
145 const ModelHighAPI_Double& theZ)
147 // TODO(spo): check that thePart is not empty
148 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
149 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
152 /*//==================================================================================================
153 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
154 const ModelHighAPI_Selection& theEdge,
155 const ModelHighAPI_Double& theDistanceValue,
156 const bool theDistancePercent,
157 const bool theReverse)
159 // TODO(spo): check that thePart is not empty
160 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
161 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
164 //==================================================================================================
165 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
166 const ModelHighAPI_Selection& theObject1,
167 const ModelHighAPI_Selection& theObject2)
169 // TODO(spo): check that thePart is not empty
170 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
171 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
174 //==================================================================================================
175 GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr)
177 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
179 std::string aShapeTypeStr = theShapeTypeStr;
180 std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower);
182 if(theShapeTypeStr == "compound") {
183 aShapeType = GeomAPI_Shape::COMPOUND;
184 } else if(theShapeTypeStr == "compsolid") {
185 aShapeType = GeomAPI_Shape::COMPSOLID;
186 } else if(theShapeTypeStr == "solid") {
187 aShapeType = GeomAPI_Shape::SOLID;
188 } else if(theShapeTypeStr == "shell") {
189 aShapeType = GeomAPI_Shape::SHELL;
190 } else if(theShapeTypeStr == "face") {
191 aShapeType = GeomAPI_Shape::FACE;
192 } else if(theShapeTypeStr == "wire") {
193 aShapeType = GeomAPI_Shape::WIRE;
194 } else if(theShapeTypeStr == "edge") {
195 aShapeType = GeomAPI_Shape::EDGE;
196 } else if(theShapeTypeStr == "vertex") {
197 aShapeType = GeomAPI_Shape::VERTEX;
198 } else if(theShapeTypeStr == "shape") {
199 aShapeType = GeomAPI_Shape::SHAPE;
205 //==================================================================================================
206 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
208 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
210 switch(theSelection.variantType()) {
211 case ModelHighAPI_Selection::VT_ResultSubShapePair: {
212 ResultSubShapePair aPair = theSelection.resultSubShapePair();
213 GeomShapePtr aShape = aPair.second;
215 aShape = aPair.first->shape();
220 aShapeType = aShape->shapeType();
223 case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: {
224 TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair();
225 std::string aType = aPair.first;
226 aShapeType = shapeTypeByStr(aType);