Salome HOME
Keep compatible with gcc 2
[modules/smesh.git] / src / SMESHDS / SMESHDS_Mesh.hxx
1 //  SMESH SMESHDS : management of mesh data and SMESH document
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHDS_Mesh.hxx
25 //  Module : SMESH
26
27 #ifndef _SMESHDS_Mesh_HeaderFile
28 #define _SMESHDS_Mesh_HeaderFile
29
30 #include "SMDS_Mesh.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMDS_MeshEdge.hxx"
33 #include "SMDS_MeshFace.hxx"
34 #include "SMDS_MeshVolume.hxx"
35 #include "SMESHDS_Hypothesis.hxx"
36 #include "SMESHDS_SubMesh.hxx"
37 #include "SMESHDS_Script.hxx"
38
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Shell.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Vertex.hxx>
44 #include <TopoDS_Edge.hxx>
45
46 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
47 #ifdef __GNUC__
48 #if __GNUC__ < 3
49         #include <hash_map.h>
50 #else
51         #include <ext/hash_map>
52         using namespace __gnu_cxx;
53 #endif
54 #endif
55
56 using namespace std;
57
58 class SMESHDS_Mesh:public SMDS_Mesh
59 {
60
61   public:
62
63         SMESHDS_Mesh(int MeshID);
64         void ShapeToMesh(const TopoDS_Shape & S);
65         bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
66         bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
67         SMDS_MeshNode * AddNode(double x, double y, double z);
68         void RemoveNode(const SMDS_MeshNode *);
69         void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
70         SMDS_MeshEdge* AddEdge(
71                 const SMDS_MeshNode * n1,
72                 const SMDS_MeshNode * n2);
73         SMDS_MeshFace* AddFace(
74                 const SMDS_MeshNode * n1,
75                 const SMDS_MeshNode * n2,
76                 const SMDS_MeshNode * n3);
77         SMDS_MeshFace* AddFace(
78                 const SMDS_MeshNode * n1,
79                 const SMDS_MeshNode * n2,
80                 const SMDS_MeshNode * n3,
81                 const SMDS_MeshNode * n4);
82         SMDS_MeshVolume* AddVolume(
83                 const SMDS_MeshNode * n1,
84                 const SMDS_MeshNode * n2,
85                 const SMDS_MeshNode * n3,
86                 const SMDS_MeshNode * n4);
87         SMDS_MeshVolume* AddVolume(
88                 const SMDS_MeshNode * n1,
89                 const SMDS_MeshNode * n2,
90                 const SMDS_MeshNode * n3,
91                 const SMDS_MeshNode * n4,
92                 const SMDS_MeshNode * n5);
93         SMDS_MeshVolume* AddVolume(
94                 const SMDS_MeshNode * n1,
95                 const SMDS_MeshNode * n2,
96                 const SMDS_MeshNode * n3,
97                 const SMDS_MeshNode * n4,
98                 const SMDS_MeshNode * n5,
99                 const SMDS_MeshNode * n6);
100         SMDS_MeshVolume* AddVolume(
101                 const SMDS_MeshNode * n1,
102                 const SMDS_MeshNode * n2,
103                 const SMDS_MeshNode * n3,
104                 const SMDS_MeshNode * n4,
105                 const SMDS_MeshNode * n5,
106                 const SMDS_MeshNode * n6,
107                 const SMDS_MeshNode * n7,
108                 const SMDS_MeshNode * n8);
109         
110         void RemoveElement(const SMDS_MeshElement *);
111         void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
112         void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S);
113         void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S);
114         void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
115         void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
116         void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
117                 const TopoDS_Shape & S);
118         void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
119                 const TopoDS_Shape & S);
120         TopoDS_Shape ShapeToMesh() const;
121         bool HasMeshElements(const TopoDS_Shape & S);
122         SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S);
123         bool HasHypothesis(const TopoDS_Shape & S);
124         const list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
125         SMESHDS_Script * GetScript();
126         void ClearScript();
127         int ShapeToIndex(const TopoDS_Shape & aShape);
128         TopoDS_Shape IndexToShape(int ShapeIndex);
129         void NewSubMesh(int Index);
130         void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
131         void SetNodeOnFace(SMDS_MeshNode * aNode, int Index);
132         void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index);
133         void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
134         void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
135          ~SMESHDS_Mesh();
136
137   private:
138         struct HashTopoDS_Shape
139     {
140                 size_t operator()(const TopoDS_Shape& S) const {return S.HashCode(2147483647);}
141     };
142         typedef hash_map<TopoDS_Shape, list<const SMESHDS_Hypothesis*>,HashTopoDS_Shape > ShapeToHypothesis;
143         int myMeshID;
144         TopoDS_Shape myShape;
145         TopTools_IndexedMapOfShape myIndexToShape;
146         map<int,SMESHDS_SubMesh*> myShapeIndexToSubMesh;
147         ShapeToHypothesis myShapeToHypothesis;
148         SMESHDS_Script * myScript;
149 };
150 #endif