Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include "ConstructionAPI_Point.h"
21
22 #include <GeomAPI_Shape.h>
23
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
27
28 //==================================================================================================
29 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
31 {
32   initialize();
33 }
34
35 //==================================================================================================
36 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37                                              const ModelHighAPI_Double& theX,
38                                              const ModelHighAPI_Double& theY,
39                                              const ModelHighAPI_Double& theZ)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if(initialize()) {
43     setByXYZ(theX, theY, theZ);
44   }
45 }
46
47 /*//==================================================================================================
48 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49                                              const ModelHighAPI_Selection& theEdge,
50                                              const ModelHighAPI_Double& theDistanceValue,
51                                              const bool theDistancePercent,
52                                              const bool theReverse)
53 : ModelHighAPI_Interface(theFeature)
54 {
55   if(initialize()) {
56     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
57   }
58 }
59
60 //==================================================================================================
61 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62                                              const ModelHighAPI_Selection& theObject1,
63                                              const ModelHighAPI_Selection& theObject2)
64 : ModelHighAPI_Interface(theFeature)
65 {
66   if(initialize()) {
67     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
68     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
69
70     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
71       // If first object is vertex and second object is face then set by projection.
72       setByProjection(theObject1, theObject2);
73     } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
74       // If both objects are edges then set by lines intersection.
75       setByLinesIntersection(theObject1, theObject2);
76     } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
77       // If first object is edge and second object is face then set by line and plane intersection.
78       setByLineAndPlaneIntersection(theObject1, theObject2);
79     }
80   }
81 }*/
82
83 //==================================================================================================
84 ConstructionAPI_Point::~ConstructionAPI_Point()
85 {
86
87 }
88
89 //==================================================================================================
90 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
91                                      const ModelHighAPI_Double& theY,
92                                      const ModelHighAPI_Double& theZ)
93 {
94   //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
95   fillAttribute(theX, myx);
96   fillAttribute(theY, myy);
97   fillAttribute(theZ, myz);
98
99   execute(false);
100 }
101
102 /*//==================================================================================================
103 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
104                                                 const ModelHighAPI_Double& theDistanceValue,
105                                                 const bool theDistancePercent,
106                                                 const bool theReverse)
107 {
108   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
109   fillAttribute(theEdge, myedge);
110   fillAttribute(theDistanceValue, mydistanceValue);
111   fillAttribute(theDistancePercent, mydistancePercent);
112   fillAttribute(theReverse, myreverse);
113
114   execute();
115 }
116
117 //==================================================================================================
118 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
119                                             const ModelHighAPI_Selection& theFace)
120 {
121   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
122   fillAttribute(theVertex, mypoint);
123   fillAttribute(theFace, myplane);
124
125   execute();
126 }
127
128 //==================================================================================================
129 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
130                                                    const ModelHighAPI_Selection& theEdge2)
131 {
132   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
133   fillAttribute(theEdge1, myfirstLine);
134   fillAttribute(theEdge2, mysecondLine);
135
136   execute();
137 }
138
139 //==================================================================================================
140 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
141                                                           const ModelHighAPI_Selection& theFace)
142 {
143   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
144   fillAttribute(theEdge, myintersectionLine);
145   fillAttribute(theFace, myintersectionPlane);
146
147   execute();
148 }*/
149
150 //==================================================================================================
151 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
152 {
153   // TODO: all types of points
154
155   FeaturePtr aBase = feature();
156   const std::string& aDocName = theDumper.name(aBase->document());
157
158   AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Point::X());
159   AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Point::Y());
160   AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Point::Z());
161   theDumper << aBase << " = model.addPoint(" << aDocName << ", "
162             << anAttrX << ", " << anAttrY << ", " << anAttrZ << ")" << std::endl;
163 }
164
165 //==================================================================================================
166 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
167                   const ModelHighAPI_Double& theX,
168                   const ModelHighAPI_Double& theY,
169                   const ModelHighAPI_Double& theZ)
170 {
171   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
172   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
173 }
174
175 /*//==================================================================================================
176 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
177                   const ModelHighAPI_Selection& theEdge,
178                   const ModelHighAPI_Double& theDistanceValue,
179                   const bool theDistancePercent,
180                   const bool theReverse)
181 {
182   // TODO(spo): check that thePart is not empty
183   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
184   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
185 }
186
187 //==================================================================================================
188 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
189                   const ModelHighAPI_Selection& theObject1,
190                   const ModelHighAPI_Selection& theObject2)
191 {
192   // TODO(spo): check that thePart is not empty
193   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
194   return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
195 }*/