Salome HOME
fdf90a30b400efc9238ac50e352d69dc58f7744b
[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 #include <map>
46 #ifdef WNT
47 #include <hash_map>
48 #endif
49
50 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
51 #ifdef __GNUC__
52   #if __GNUC__ < 3
53     #include <hash_map.h>
54     namespace gstd { using ::hash_map; }; // inherit globals
55   #else
56     #include <ext/hash_map>
57     #if __GNUC_MINOR__ == 0
58       namespace gstd = std;               // GCC 3.0
59     #else
60       namespace gstd = ::__gnu_cxx;       // GCC 3.1 and later
61     #endif
62   #endif
63 #else      // ...  there are other compilers, right?
64   namespace gstd = std;
65 #endif
66
67 class SMESHDS_GroupBase;
68
69 class SMESHDS_Mesh:public SMDS_Mesh{
70 public:
71   SMESHDS_Mesh(int MeshID);
72   void ShapeToMesh(const TopoDS_Shape & S);
73   bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
74   bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
75   
76   virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
77   virtual SMDS_MeshNode * AddNode(double x, double y, double z);
78   
79   virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
80   virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
81                                        const SMDS_MeshNode * n2, 
82                                        int ID);
83   virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
84                                  const SMDS_MeshNode * n2);
85   
86   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
87   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
88                                        const SMDS_MeshNode * n2,
89                                        const SMDS_MeshNode * n3, 
90                                        int ID);
91   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
92                                  const SMDS_MeshNode * n2,
93                                  const SMDS_MeshNode * n3);
94
95   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
96   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
97                                        const SMDS_MeshNode * n2,
98                                        const SMDS_MeshNode * n3,
99                                        const SMDS_MeshNode * n4, 
100                                        int ID);
101   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
102                                  const SMDS_MeshNode * n2,
103                                  const SMDS_MeshNode * n3,
104                                  const SMDS_MeshNode * n4);
105
106   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
107   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
108                                            const SMDS_MeshNode * n2,
109                                            const SMDS_MeshNode * n3,
110                                            const SMDS_MeshNode * n4, 
111                                            int ID);
112   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
113                                      const SMDS_MeshNode * n2,
114                                      const SMDS_MeshNode * n3,
115                                      const SMDS_MeshNode * n4);
116
117   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
118   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
119                                            const SMDS_MeshNode * n2,
120                                            const SMDS_MeshNode * n3,
121                                            const SMDS_MeshNode * n4,
122                                            const SMDS_MeshNode * n5, 
123                                            int ID);
124   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
125                                      const SMDS_MeshNode * n2,
126                                      const SMDS_MeshNode * n3,
127                                      const SMDS_MeshNode * n4,
128                                      const SMDS_MeshNode * n5);
129
130   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
131   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
132                                            const SMDS_MeshNode * n2,
133                                            const SMDS_MeshNode * n3,
134                                            const SMDS_MeshNode * n4,
135                                            const SMDS_MeshNode * n5,
136                                            const SMDS_MeshNode * n6, 
137                                            int ID);
138   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
139                                      const SMDS_MeshNode * n2,
140                                      const SMDS_MeshNode * n3,
141                                      const SMDS_MeshNode * n4,
142                                      const SMDS_MeshNode * n5,
143                                      const SMDS_MeshNode * n6);
144
145   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
146   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
147                                            const SMDS_MeshNode * n2,
148                                            const SMDS_MeshNode * n3,
149                                            const SMDS_MeshNode * n4,
150                                            const SMDS_MeshNode * n5,
151                                            const SMDS_MeshNode * n6,
152                                            const SMDS_MeshNode * n7,
153                                            const SMDS_MeshNode * n8, 
154                                            int ID);
155   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
156                                      const SMDS_MeshNode * n2,
157                                      const SMDS_MeshNode * n3,
158                                      const SMDS_MeshNode * n4,
159                                      const SMDS_MeshNode * n5,
160                                      const SMDS_MeshNode * n6,
161                                      const SMDS_MeshNode * n7,
162                                      const SMDS_MeshNode * n8);
163   
164   virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
165                                                  const int        ID);
166
167   virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
168                                                  const int                         ID);
169
170   virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
171
172   virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
173                            (std::vector<int> nodes_ids,
174                             std::vector<int> quantities,
175                             const int        ID);
176
177   virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
178                            (std::vector<const SMDS_MeshNode*> nodes,
179                             std::vector<int>                  quantities,
180                             const int                         ID);
181
182   virtual SMDS_MeshVolume* AddPolyhedralVolume
183                            (std::vector<const SMDS_MeshNode*> nodes,
184                             std::vector<int>                  quantities);
185
186   void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
187   virtual void RemoveNode(const SMDS_MeshNode *);
188   void RemoveElement(const SMDS_MeshElement *);
189   bool ChangeElementNodes(const SMDS_MeshElement * elem,
190                           const SMDS_MeshNode    * nodes[],
191                           const int                nbnodes);
192   bool ChangePolygonNodes(const SMDS_MeshElement * elem,
193                           std::vector<const SMDS_MeshNode*> nodes);
194   bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
195                              std::vector<const SMDS_MeshNode*> nodes,
196                              std::vector<int>                  quantities);
197   void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
198
199   void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
200   void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S);
201   void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S);
202   void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
203   void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
204   void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
205                              const TopoDS_Shape & S);
206   void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
207                                const TopoDS_Shape & S);
208   TopoDS_Shape ShapeToMesh() const;
209   bool HasMeshElements(const TopoDS_Shape & S);
210   SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
211   SMESHDS_SubMesh * MeshElements(const int Index);
212   std::list<int> SubMeshIndices();
213   const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
214   { return myShapeIndexToSubMesh; }
215
216   bool HasHypothesis(const TopoDS_Shape & S);
217   const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
218   SMESHDS_Script * GetScript();
219   void ClearScript();
220   int ShapeToIndex(const TopoDS_Shape & aShape) const;
221   TopoDS_Shape IndexToShape(int ShapeIndex);
222
223   SMESHDS_SubMesh * NewSubMesh(int Index);
224   int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
225   void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
226   void SetNodeOnFace(SMDS_MeshNode * aNode, int Index);
227   void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index);
228   void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
229   void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
230
231   void AddGroup (SMESHDS_GroupBase* theGroup)      { myGroups.insert(theGroup); }
232   void RemoveGroup (SMESHDS_GroupBase* theGroup)   { myGroups.erase(theGroup); }
233   int GetNbGroups() const                      { return myGroups.size(); }
234   const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
235
236   bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
237
238   ~SMESHDS_Mesh();
239   
240 private:
241 #ifndef WNT
242   struct HashTopoDS_Shape{
243     size_t operator()(const TopoDS_Shape& S) const {
244       return S.HashCode(2147483647);
245     }
246   };
247 #else
248   typedef gstd::hash_compare< TopoDS_Shape, less<TopoDS_Shape> > HashTopoDS;
249
250   class HashTopoDS_Shape : public HashTopoDS {
251   public:
252   
253     size_t operator()(const TopoDS_Shape& S) const {
254       return S.HashCode(2147483647);
255     }
256
257         bool operator()(const TopoDS_Shape& S1,const TopoDS_Shape& S2) const {
258                 return S1==S2;
259         }
260   };
261
262
263
264 #endif
265
266   typedef std::list<const SMESHDS_Hypothesis*> THypList;
267
268 #ifndef WNT
269   typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
270 #else
271   typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
272 #endif
273
274   ShapeToHypothesis          myShapeToHypothesis;
275
276   int                        myMeshID;
277   TopoDS_Shape               myShape;
278
279   typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
280   TShapeIndexToSubMesh myShapeIndexToSubMesh;
281
282   TopTools_IndexedMapOfShape myIndexToShape;
283
284   typedef std::set<SMESHDS_GroupBase*> TGroups;
285   TGroups myGroups;
286
287   SMESHDS_Script*            myScript;
288 };
289
290
291 #endif