Salome HOME
Merge with version on tag OCC-V2_1_0d
[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     namespace gstd { using ::hash_map; }; // inherit globals
51   #else
52     #include <ext/hash_map>
53     #if __GNUC_MINOR__ == 0
54       namespace gstd = std;               // GCC 3.0
55     #else
56       namespace gstd = ::__gnu_cxx;       // GCC 3.1 and later
57     #endif
58   #endif
59 #else      // ...  there are other compilers, right?
60   namespace gstd = std;
61 #endif
62
63 class SMESHDS_GroupBase;
64
65 class SMESHDS_Mesh:public SMDS_Mesh{
66 public:
67   SMESHDS_Mesh(int MeshID);
68   void ShapeToMesh(const TopoDS_Shape & S);
69   bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
70   bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
71   
72   virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
73   virtual SMDS_MeshNode * AddNode(double x, double y, double z);
74   
75   virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
76   virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
77                                        const SMDS_MeshNode * n2, 
78                                        int ID);
79   virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
80                                  const SMDS_MeshNode * n2);
81   
82   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
83   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
84                                        const SMDS_MeshNode * n2,
85                                        const SMDS_MeshNode * n3, 
86                                        int ID);
87   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
88                                  const SMDS_MeshNode * n2,
89                                  const SMDS_MeshNode * n3);
90
91   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
92   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
93                                        const SMDS_MeshNode * n2,
94                                        const SMDS_MeshNode * n3,
95                                        const SMDS_MeshNode * n4, 
96                                        int ID);
97   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
98                                  const SMDS_MeshNode * n2,
99                                  const SMDS_MeshNode * n3,
100                                  const SMDS_MeshNode * n4);
101
102   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
103   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
104                                            const SMDS_MeshNode * n2,
105                                            const SMDS_MeshNode * n3,
106                                            const SMDS_MeshNode * n4, 
107                                            int ID);
108   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
109                                      const SMDS_MeshNode * n2,
110                                      const SMDS_MeshNode * n3,
111                                      const SMDS_MeshNode * n4);
112
113   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
114   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
115                                            const SMDS_MeshNode * n2,
116                                            const SMDS_MeshNode * n3,
117                                            const SMDS_MeshNode * n4,
118                                            const SMDS_MeshNode * n5, 
119                                            int ID);
120   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
121                                      const SMDS_MeshNode * n2,
122                                      const SMDS_MeshNode * n3,
123                                      const SMDS_MeshNode * n4,
124                                      const SMDS_MeshNode * n5);
125
126   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
127   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
128                                            const SMDS_MeshNode * n2,
129                                            const SMDS_MeshNode * n3,
130                                            const SMDS_MeshNode * n4,
131                                            const SMDS_MeshNode * n5,
132                                            const SMDS_MeshNode * n6, 
133                                            int ID);
134   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
135                                      const SMDS_MeshNode * n2,
136                                      const SMDS_MeshNode * n3,
137                                      const SMDS_MeshNode * n4,
138                                      const SMDS_MeshNode * n5,
139                                      const SMDS_MeshNode * n6);
140
141   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
142   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
143                                            const SMDS_MeshNode * n2,
144                                            const SMDS_MeshNode * n3,
145                                            const SMDS_MeshNode * n4,
146                                            const SMDS_MeshNode * n5,
147                                            const SMDS_MeshNode * n6,
148                                            const SMDS_MeshNode * n7,
149                                            const SMDS_MeshNode * n8, 
150                                            int ID);
151   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
152                                      const SMDS_MeshNode * n2,
153                                      const SMDS_MeshNode * n3,
154                                      const SMDS_MeshNode * n4,
155                                      const SMDS_MeshNode * n5,
156                                      const SMDS_MeshNode * n6,
157                                      const SMDS_MeshNode * n7,
158                                      const SMDS_MeshNode * n8);
159   
160   void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
161   virtual void RemoveNode(const SMDS_MeshNode *);
162   void RemoveElement(const SMDS_MeshElement *);
163   bool ChangeElementNodes(const SMDS_MeshElement * elem,
164                           const SMDS_MeshNode    * nodes[],
165                           const int                nbnodes);
166   void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
167
168   void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
169   void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S);
170   void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S);
171   void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
172   void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
173   void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
174                              const TopoDS_Shape & S);
175   void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
176                                const TopoDS_Shape & S);
177   TopoDS_Shape ShapeToMesh() const;
178   bool HasMeshElements(const TopoDS_Shape & S);
179   SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S);
180   SMESHDS_SubMesh * MeshElements(const int Index);
181   list<int> SubMeshIndices();
182   const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
183   { return myShapeIndexToSubMesh; }
184
185   bool HasHypothesis(const TopoDS_Shape & S);
186   const list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
187   SMESHDS_Script * GetScript();
188   void ClearScript();
189   int ShapeToIndex(const TopoDS_Shape & aShape);
190   TopoDS_Shape IndexToShape(int ShapeIndex);
191
192   SMESHDS_SubMesh * NewSubMesh(int Index);
193   int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
194   void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
195   void SetNodeOnFace(SMDS_MeshNode * aNode, int Index);
196   void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index);
197   void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
198   void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
199
200   void AddGroup (SMESHDS_GroupBase* theGroup)      { myGroups.insert(theGroup); }
201   void RemoveGroup (SMESHDS_GroupBase* theGroup)   { myGroups.erase(theGroup); }
202   int GetNbGroups() const                      { return myGroups.size(); }
203   const set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
204
205   bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
206
207   ~SMESHDS_Mesh();
208   
209 private:
210   struct HashTopoDS_Shape{
211     size_t operator()(const TopoDS_Shape& S) const {
212       return S.HashCode(2147483647);
213     }
214   };
215   typedef std::list<const SMESHDS_Hypothesis*> THypList;
216   typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
217   ShapeToHypothesis          myShapeToHypothesis;
218
219   int                        myMeshID;
220   TopoDS_Shape               myShape;
221   TopTools_IndexedMapOfShape myIndexToShape;
222   map<int,SMESHDS_SubMesh*>  myShapeIndexToSubMesh;
223   set<SMESHDS_GroupBase*>        myGroups;
224   SMESHDS_Script*            myScript;
225 };
226
227
228 #endif