Salome HOME
c503c16fa9c0885473a0ee4c8a672a558cb832d5
[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_Selection.h>
12 #include <ModelHighAPI_Tools.h>
13
14 //==================================================================================================
15 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
17 {
18   initialize();
19 }
20
21 //==================================================================================================
22 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
23                                              const ModelHighAPI_Double& theX,
24                                              const ModelHighAPI_Double& theY,
25                                              const ModelHighAPI_Double& theZ)
26 : ModelHighAPI_Interface(theFeature)
27 {
28   if(initialize()) {
29     setByXYZ(theX, theY, theZ);
30   }
31 }
32
33 /*//==================================================================================================
34 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35                                              const ModelHighAPI_Selection& theEdge,
36                                              const ModelHighAPI_Double& theDistanceValue,
37                                              const bool theDistancePercent,
38                                              const bool theReverse)
39 : ModelHighAPI_Interface(theFeature)
40 {
41   if(initialize()) {
42     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
43   }
44 }
45
46 //==================================================================================================
47 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
48                                              const ModelHighAPI_Selection& theObject1,
49                                              const ModelHighAPI_Selection& theObject2)
50 : ModelHighAPI_Interface(theFeature)
51 {
52   if(initialize()) {
53     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
54     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
55
56     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
57       // If first object is vertex and second object is face then set by projection.
58       setByProjection(theObject1, theObject2);
59     } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
60       // If both objects are edges then set by lines intersection.
61       setByLinesIntersection(theObject1, theObject2);
62     } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
63       // If first object is edge and second object is face then set by line and plane intersection.
64       setByLineAndPlaneIntersection(theObject1, theObject2);
65     }
66   }
67 }*/
68
69 //==================================================================================================
70 ConstructionAPI_Point::~ConstructionAPI_Point()
71 {
72
73 }
74
75 //==================================================================================================
76 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
77                                      const ModelHighAPI_Double& theY,
78                                      const ModelHighAPI_Double& theZ)
79 {
80   //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
81   fillAttribute(theX, myx);
82   fillAttribute(theY, myy);
83   fillAttribute(theZ, myz);
84
85   execute();
86 }
87
88 /*//==================================================================================================
89 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
90                                                 const ModelHighAPI_Double& theDistanceValue,
91                                                 const bool theDistancePercent,
92                                                 const bool theReverse)
93 {
94   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
95   fillAttribute(theEdge, myedge);
96   fillAttribute(theDistanceValue, mydistanceValue);
97   fillAttribute(theDistancePercent, mydistancePercent);
98   fillAttribute(theReverse, myreverse);
99
100   execute();
101 }
102
103 //==================================================================================================
104 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
105                                             const ModelHighAPI_Selection& theFace)
106 {
107   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
108   fillAttribute(theVertex, mypoint);
109   fillAttribute(theFace, myplane);
110
111   execute();
112 }
113
114 //==================================================================================================
115 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
116                                                    const ModelHighAPI_Selection& theEdge2)
117 {
118   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
119   fillAttribute(theEdge1, myfirstLine);
120   fillAttribute(theEdge2, mysecondLine);
121
122   execute();
123 }
124
125 //==================================================================================================
126 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
127                                                           const ModelHighAPI_Selection& theFace)
128 {
129   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
130   fillAttribute(theEdge, myintersectionLine);
131   fillAttribute(theFace, myintersectionPlane);
132
133   execute();
134 }*/
135
136 //==================================================================================================
137 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
138                   const ModelHighAPI_Double& theX,
139                   const ModelHighAPI_Double& theY,
140                   const ModelHighAPI_Double& theZ)
141 {
142   // TODO(spo): check that thePart is not empty
143   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
144   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
145 }
146
147 /*//==================================================================================================
148 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
149                   const ModelHighAPI_Selection& theEdge,
150                   const ModelHighAPI_Double& theDistanceValue,
151                   const bool theDistancePercent,
152                   const bool theReverse)
153 {
154   // TODO(spo): check that thePart is not empty
155   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
156   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
157 }
158
159 //==================================================================================================
160 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
161                   const ModelHighAPI_Selection& theObject1,
162                   const ModelHighAPI_Selection& theObject2)
163 {
164   // TODO(spo): check that thePart is not empty
165   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
166   return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
167 }*/