Salome HOME
Fixed the crash on moving Group down and edit it in the issue #1862
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // Name   : ConstructionAPI_Point.cpp
4 // Purpose:
5 //
6 // History:
7 // 29/03/16 - Sergey POKHODENKO - Creation of the file
8
9 #include "ConstructionAPI_Point.h"
10
11 #include <GeomAPI_Shape.h>
12
13 #include <ModelHighAPI_Dumper.h>
14 #include <ModelHighAPI_Selection.h>
15 #include <ModelHighAPI_Tools.h>
16
17 //==================================================================================================
18 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
19 : ModelHighAPI_Interface(theFeature)
20 {
21   initialize();
22 }
23
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)
30 {
31   if(initialize()) {
32     setByXYZ(theX, theY, theZ);
33   }
34 }
35
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)
43 {
44   if(initialize()) {
45     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
46   }
47 }
48
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)
54 {
55   if(initialize()) {
56     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
57     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
58
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);
68     }
69   }
70 }*/
71
72 //==================================================================================================
73 ConstructionAPI_Point::~ConstructionAPI_Point()
74 {
75
76 }
77
78 //==================================================================================================
79 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
80                                      const ModelHighAPI_Double& theY,
81                                      const ModelHighAPI_Double& theZ)
82 {
83   //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
84   fillAttribute(theX, myx);
85   fillAttribute(theY, myy);
86   fillAttribute(theZ, myz);
87
88   execute(false);
89 }
90
91 /*//==================================================================================================
92 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
93                                                 const ModelHighAPI_Double& theDistanceValue,
94                                                 const bool theDistancePercent,
95                                                 const bool theReverse)
96 {
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);
102
103   execute();
104 }
105
106 //==================================================================================================
107 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
108                                             const ModelHighAPI_Selection& theFace)
109 {
110   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
111   fillAttribute(theVertex, mypoint);
112   fillAttribute(theFace, myplane);
113
114   execute();
115 }
116
117 //==================================================================================================
118 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
119                                                    const ModelHighAPI_Selection& theEdge2)
120 {
121   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
122   fillAttribute(theEdge1, myfirstLine);
123   fillAttribute(theEdge2, mysecondLine);
124
125   execute();
126 }
127
128 //==================================================================================================
129 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
130                                                           const ModelHighAPI_Selection& theFace)
131 {
132   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
133   fillAttribute(theEdge, myintersectionLine);
134   fillAttribute(theFace, myintersectionPlane);
135
136   execute();
137 }*/
138
139 //==================================================================================================
140 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
141 {
142   // TODO: all types of points
143
144   FeaturePtr aBase = feature();
145   const std::string& aDocName = theDumper.name(aBase->document());
146
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;
152 }
153
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)
159 {
160   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
161   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
162 }
163
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)
170 {
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));
174 }
175
176 //==================================================================================================
177 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
178                   const ModelHighAPI_Selection& theObject1,
179                   const ModelHighAPI_Selection& theObject2)
180 {
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));
184 }*/