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