1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
3 // Name : ConstructionAPI_Point.cpp
7 // 29/03/16 - Sergey POKHODENKO - Creation of the file
9 #include "ConstructionAPI_Point.h"
11 #include <GeomAPI_Shape.h>
13 #include <ModelHighAPI_Dumper.h>
14 #include <ModelHighAPI_Selection.h>
15 #include <ModelHighAPI_Tools.h>
17 //==================================================================================================
18 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
19 : ModelHighAPI_Interface(theFeature)
24 //==================================================================================================
25 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
26 const ModelHighAPI_Double& theX,
27 const ModelHighAPI_Double& theY,
28 const ModelHighAPI_Double& theZ)
29 : ModelHighAPI_Interface(theFeature)
32 setByXYZ(theX, theY, theZ);
36 /*//==================================================================================================
37 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
38 const ModelHighAPI_Selection& theEdge,
39 const ModelHighAPI_Double& theDistanceValue,
40 const bool theDistancePercent,
41 const bool theReverse)
42 : ModelHighAPI_Interface(theFeature)
45 setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
49 //==================================================================================================
50 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
51 const ModelHighAPI_Selection& theObject1,
52 const ModelHighAPI_Selection& theObject2)
53 : ModelHighAPI_Interface(theFeature)
56 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
57 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
59 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
60 // If first object is vertex and second object is face then set by projection.
61 setByProjection(theObject1, theObject2);
62 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
63 // If both objects are edges then set by lines intersection.
64 setByLinesIntersection(theObject1, theObject2);
65 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
66 // If first object is edge and second object is face then set by line and plane intersection.
67 setByLineAndPlaneIntersection(theObject1, theObject2);
72 //==================================================================================================
73 ConstructionAPI_Point::~ConstructionAPI_Point()
78 //==================================================================================================
79 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
80 const ModelHighAPI_Double& theY,
81 const ModelHighAPI_Double& theZ)
83 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
84 fillAttribute(theX, myx);
85 fillAttribute(theY, myy);
86 fillAttribute(theZ, myz);
91 /*//==================================================================================================
92 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
93 const ModelHighAPI_Double& theDistanceValue,
94 const bool theDistancePercent,
95 const bool theReverse)
97 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
98 fillAttribute(theEdge, myedge);
99 fillAttribute(theDistanceValue, mydistanceValue);
100 fillAttribute(theDistancePercent, mydistancePercent);
101 fillAttribute(theReverse, myreverse);
106 //==================================================================================================
107 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
108 const ModelHighAPI_Selection& theFace)
110 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
111 fillAttribute(theVertex, mypoint);
112 fillAttribute(theFace, myplane);
117 //==================================================================================================
118 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
119 const ModelHighAPI_Selection& theEdge2)
121 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
122 fillAttribute(theEdge1, myfirstLine);
123 fillAttribute(theEdge2, mysecondLine);
128 //==================================================================================================
129 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
130 const ModelHighAPI_Selection& theFace)
132 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
133 fillAttribute(theEdge, myintersectionLine);
134 fillAttribute(theFace, myintersectionPlane);
139 //==================================================================================================
140 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
142 // TODO: all types of points
144 FeaturePtr aBase = feature();
145 const std::string& aDocName = theDumper.name(aBase->document());
147 AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Point::X());
148 AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Point::Y());
149 AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Point::Z());
150 theDumper << aBase << " = model.addPoint(" << aDocName << ", "
151 << anAttrX << ", " << anAttrY << ", " << anAttrZ << ")" << std::endl;
154 //==================================================================================================
155 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
156 const ModelHighAPI_Double& theX,
157 const ModelHighAPI_Double& theY,
158 const ModelHighAPI_Double& theZ)
160 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
161 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
164 /*//==================================================================================================
165 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
166 const ModelHighAPI_Selection& theEdge,
167 const ModelHighAPI_Double& theDistanceValue,
168 const bool theDistancePercent,
169 const bool theReverse)
171 // TODO(spo): check that thePart is not empty
172 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
173 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
176 //==================================================================================================
177 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
178 const ModelHighAPI_Selection& theObject1,
179 const ModelHighAPI_Selection& theObject2)
181 // TODO(spo): check that thePart is not empty
182 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
183 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));