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