Salome HOME
7920e9adcb6ae0507c090760e53de259e1d60d9d
[modules/geom.git] / src / XAO / XAO_BrepGeometry.hxx
1 // Copyright (C) 2013-2014  CEA/DEN, EDF R&D, OPEN CASCADE
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
18 //
19 // Author : Frederic Pons (OpenCascade)
20
21 #ifndef __XAO_BREPGEOMETRY_HXX__
22 #define __XAO_BREPGEOMETRY_HXX__
23
24 #include <string>
25 #include <vector>
26
27 #include <TopoDS_Shape.hxx>
28
29 #include "XAO.hxx"
30 #include "XAO_XaoUtils.hxx"
31 #include "XAO_Geometry.hxx"
32
33 #ifdef WIN32
34 #pragma warning(disable:4290) // Warning Exception ...
35 #endif
36
37
38 namespace XAO
39 {
40     /**
41      * @class BrepGeometry
42      * Representation of a BRep Geometry.
43      */
44     class XAO_EXPORT BrepGeometry : public Geometry
45     {
46     public:
47         /**
48          * Default Constructor.
49          */
50         BrepGeometry();
51
52         /**
53          * Constructor.
54          * @param name the name of the geometry.
55          */
56         BrepGeometry(const std::string& name);
57
58         virtual ~BrepGeometry() {}
59
60         /**
61          * Gets the format of the geometry.
62          * @return the format of the geometry.
63          */
64         virtual const XAO::Format getFormat() { return XAO::BREP; }
65
66         /**
67          * Gets the shape as a string.
68          * @return the shape as a string.
69          */
70         virtual const std::string getShapeString();
71
72         /**
73          * Sets the shape from a string.
74          * @param shape the shape as a string.
75          */
76         virtual void setShapeString(const std::string& shape);
77
78 #ifdef SWIG
79         %pythoncode %{
80         def setShape(self, shape):
81             if shape is not None and 'GetShapeStream' in dir(shape):
82                 self.setShapeString(shape.GetShapeStream())
83             else:
84                 raise XAO_Exception("Cannot set shape")
85         %}
86 #endif
87
88         /**
89          * Gets the shape as a TopoDS_Shape.
90          * @return the TopoDS_Shape.
91          */
92         TopoDS_Shape getTopoDS_Shape();
93
94         /**
95          * Sets the shape from a TopoDS_Shape.
96          * @param shape the TopoDS_Shape to set.
97          */
98         void setTopoDS_Shape(const TopoDS_Shape& shape);
99
100         /**
101          * Gives the two extrimities of an edge.
102          * @param edgeIndex the index of the edge.
103          * @param vertexA
104          * @param vertexB
105          */
106         void getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB);
107
108         /**
109          * Gets the number of wires of a face (including holes).
110          * @param faceIndex the index of the face.
111          * @return the number of wires.
112          */
113         const int countFaceWires(const int& faceIndex);
114
115         /**
116          * Gets the indices of the wires of the face.
117          * @param faceIndex the index of the face.
118          * @param wireIndex the index of the wire.
119          * @return the list of wires for the given face.
120          */
121         std::vector<int> getFaceEdges(const int& faceIndex, const int& wireIndex);
122
123         /**
124          * Gets the number of shells of a solid (including cavities).
125          * @param solidIndex the index of the solid.
126          * @return the number of shells.
127          */
128         const int countSolidShells(const int& solidIndex);
129
130         /**
131          * Gets the indices of the shells of the solids.
132          * @param solidIndex the index of the solid.
133          * @param shellIndex the index of the shell (for the given solid).
134          * @return the list of shells for the given solid.
135          */
136         std::vector<int> getSolidFaces(const int& solidIndex, const int& shellIndex);
137
138         /**
139          * Gets the coordinates of a vertex.
140          * @param vertexIndex the index of the vertex.
141          * @param xCoord the X coordinate.
142          * @param yCoord the Y coordinate.
143          * @param zCoord the Z coordinate.
144          */
145         void getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord)
146         throw (XAO_Exception);
147
148         /**
149          * Gets the length of an edge.
150          * @param index the index of the edge.
151          * @return the length of the edge.
152          */
153         const double getEdgeLength(const int& index);
154
155         /**
156          * Gets the are of a face.
157          * @param index the index of a face.
158          * @return the area of the face.
159          */
160         const double getFaceArea(const int& index);
161
162         /**
163          * Gets the volume of a solid.
164          * @param index the index of the solid.
165          * @return the volume of the solid.
166          */
167         const double getSolidVolume(const int& index);
168
169         /**
170          * Gets the ID of a vertex.
171          * @param index the index of the vertex.
172          * @return the ID of the vertex.
173          */
174         const int getVertexID(const int& index);
175
176         /**
177          * Gets the ID of an edge.
178          * @param index the index of the edge.
179          * @return the ID of the edge.
180          */
181         const int getEdgeID(const int& index);
182
183         /**
184          * Gets the ID of a face.
185          * @param index the index of the face.
186          * @return the ID of the face.
187          */
188         const int getFaceID(const int& index);
189
190         /**
191          * Gets the ID of a solid.
192          * @param index the index of the solid.
193          * @return the ID of the solid.
194          */
195         const int getSolidID(const int& index);
196
197         /**
198          * Sets the ID of a vertex.
199          * @param index the index of the vertex to set.
200          * @param id the id to set.
201          */
202         void setVertexID(const int& index, const int& id);
203
204         /**
205          * Sets the ID of an edge.
206          * @param index the index of the edge to set.
207          * @param id the id to set.
208          */
209         void setEdgeID(const int& index, const int& id);
210
211         /**
212          * Sets the ID of a face.
213          * @param index the index of the face to set.
214          * @param id the id to set.
215          */
216         void setFaceID(const int& index, const int& id);
217
218         /**
219          * Sets the ID of a solid.
220          * @param index the index of the solid to set.
221          * @param id the id to set.
222          */
223         void setSolidID(const int& index, const int& id);
224
225         /**
226          * Finds a vertex with its ID.
227          * @param id the ID of the vertex.
228          * @return the index of the vertex.
229          */
230         const int findVertex(const int& id);
231
232         /**
233          * Finds an edge with its ID.
234          * @param id the ID of the edge.
235          * @return the index of the edge.
236          */
237         const int findEdge(const int& id);
238
239         /**
240          * Finds a face with its ID.
241          * @param id the ID of the face.
242          * @return the index of the face.
243          */
244         const int findFace(const int& id);
245
246         /**
247          * Finds a solid with its ID.
248          * @param id the ID of the solid.
249          * @return th index of the solid.
250          */
251         const int findSolid(const int& id);
252
253         /**
254          * Finds the name of a vertex with its ID.
255          * @param id the ID of the vertex.
256          * @return the name of the vertex.
257          */
258         const std::string findVertexName(const int& id);
259
260         /**
261          * Finds the name of an edge with its ID.
262          * @param id the ID of the edge.
263          * @return the name of the edge.
264          */
265         const std::string findEdgeName(const int& id);
266
267         /**
268          * Finds the name of a face with its ID.
269          * @param id the ID of the face.
270          * @return the name of the face.
271          */
272         const std::string findFaceName(const int& id);
273
274         /**
275          * Finds the name of a solid with its ID.
276          * @param id the ID of the solid.
277          * @return the name of the solid.
278          */
279         const std::string findSolidName(const int& id);
280
281         /**
282          * Changes the name of a vertex.
283          * @param id the ID of the vertex.
284          * @param name the name to set.
285          */
286         void changeVertexName(const int& id, const std::string& name) throw (XAO_Exception);
287
288         /**
289          * Changes the name of an edge.
290          * @param id the ID of the edge
291          * @param name the name to set.
292          */
293         void changeEdgeName(const int& id, const std::string& name) throw (XAO_Exception);
294
295         /**
296          * Changes the name of a face.
297          * @param id the ID of the face.
298          * @param name the name to set.
299          */
300         void changeFaceName(const int& id, const std::string& name) throw (XAO_Exception);
301
302         /**
303          * Changes the name of a solid.
304          * @param id the ID of the solid.
305          * @param name the name to set.
306          */
307         void changeSolidName(const int& id, const std::string& name) throw (XAO_Exception);
308
309     private:
310         void initIds();
311         void initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList);
312         TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
313             throw (XAO_Exception);
314         const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType);
315         std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
316         const int findElement(const XAO::Dimension& dim, const int& id)
317             throw (XAO_Exception);
318
319     private:
320         TopoDS_Shape m_shape;
321     };
322 }
323
324 #endif // __XAO_BREPGEOMETRY_HXX__