Salome HOME
Merge remote-tracking branch 'remotes/origin/HighLevelDump'
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
1 // Name   : ConstructionAPI_Point.cpp
2 // Purpose: 
3 //
4 // History:
5 // 29/03/16 - Sergey POKHODENKO - Creation of the file
6
7 #include "ConstructionAPI_Point.h"
8
9 #include <GeomAPI_Shape.h>
10
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Selection.h>
13 #include <ModelHighAPI_Tools.h>
14
15 //==================================================================================================
16 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
17 : ModelHighAPI_Interface(theFeature)
18 {
19   initialize();
20 }
21
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)
28 {
29   if(initialize()) {
30     setByXYZ(theX, theY, theZ);
31   }
32 }
33
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)
41 {
42   if(initialize()) {
43     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
44   }
45 }
46
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)
52 {
53   if(initialize()) {
54     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
55     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
56
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);
66     }
67   }
68 }*/
69
70 //==================================================================================================
71 ConstructionAPI_Point::~ConstructionAPI_Point()
72 {
73
74 }
75
76 //==================================================================================================
77 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
78                                      const ModelHighAPI_Double& theY,
79                                      const ModelHighAPI_Double& theZ)
80 {
81   //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
82   fillAttribute(theX, myx);
83   fillAttribute(theY, myy);
84   fillAttribute(theZ, myz);
85
86   execute(false);
87 }
88
89 /*//==================================================================================================
90 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
91                                                 const ModelHighAPI_Double& theDistanceValue,
92                                                 const bool theDistancePercent,
93                                                 const bool theReverse)
94 {
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);
100
101   execute();
102 }
103
104 //==================================================================================================
105 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
106                                             const ModelHighAPI_Selection& theFace)
107 {
108   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
109   fillAttribute(theVertex, mypoint);
110   fillAttribute(theFace, myplane);
111
112   execute();
113 }
114
115 //==================================================================================================
116 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
117                                                    const ModelHighAPI_Selection& theEdge2)
118 {
119   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
120   fillAttribute(theEdge1, myfirstLine);
121   fillAttribute(theEdge2, mysecondLine);
122
123   execute();
124 }
125
126 //==================================================================================================
127 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
128                                                           const ModelHighAPI_Selection& theFace)
129 {
130   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
131   fillAttribute(theEdge, myintersectionLine);
132   fillAttribute(theFace, myintersectionPlane);
133
134   execute();
135 }*/
136
137 //==================================================================================================
138 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
139 {
140   // TODO: all types of points
141
142   FeaturePtr aBase = feature();
143   const std::string& aDocName = theDumper.name(aBase->document());
144
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;
150 }
151
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)
157 {
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));
161 }
162
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)
169 {
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));
173 }
174
175 //==================================================================================================
176 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
177                   const ModelHighAPI_Selection& theObject1,
178                   const ModelHighAPI_Selection& theObject2)
179 {
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));
183 }*/