]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHDS/SMESHDS_Mesh.hxx
Salome HOME
First executable version
[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 "SMESH_SMESHDS.hxx"
31
32 #include "SMDS_Mesh.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMDS_MeshEdge.hxx"
35 #include "SMDS_MeshFace.hxx"
36 #include "SMDS_MeshVolume.hxx"
37 #include "SMESHDS_Hypothesis.hxx"
38 #include "SMESHDS_SubMesh.hxx"
39 #include "SMESHDS_Script.hxx"
40
41 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TopoDS_Solid.hxx>
44 #include <TopoDS_Shell.hxx>
45 #include <TopoDS_Face.hxx>
46 #include <TopoDS_Vertex.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <map>
49 #ifdef WNT
50 #include <hash_map>
51 #endif
52
53 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
54 #ifdef __GNUC__
55   #if __GNUC__ < 3
56     #include <hash_map.h>
57     namespace gstd { using ::hash_map; }; // inherit globals
58   #elif __GNUC__ == 3
59     #include <ext/hash_map>
60     #if __GNUC_MINOR__ == 0
61       namespace gstd = std;               // GCC 3.0
62     #else
63       namespace gstd = ::__gnu_cxx;       // GCC 3.1 and later
64     #endif
65   #else                                   // GCC 4.0 and later
66     #include <ext/hash_map>
67     namespace gstd = ::__gnu_cxx;
68   #endif
69 #else      // ...  there are other compilers, right?
70   namespace gstd = std;
71 #endif
72
73 class SMESHDS_GroupBase;
74
75 class SMESHDS_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 SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Solid & S);
207   void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S, double u=0., double v=0.);
208   void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S, double u=0.);
209   void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
210   void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
211   void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
212                              const TopoDS_Shape & S);
213   void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
214                                const TopoDS_Shape & S);
215   TopoDS_Shape ShapeToMesh() const;
216   bool HasMeshElements(const TopoDS_Shape & S);
217   SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
218   SMESHDS_SubMesh * MeshElements(const int Index);
219   std::list<int> SubMeshIndices();
220   const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
221   { return myShapeIndexToSubMesh; }
222
223   bool HasHypothesis(const TopoDS_Shape & S);
224   const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
225   SMESHDS_Script * GetScript();
226   void ClearScript();
227   int ShapeToIndex(const TopoDS_Shape & aShape) const;
228   TopoDS_Shape IndexToShape(int ShapeIndex);
229
230   SMESHDS_SubMesh * NewSubMesh(int Index);
231   int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
232   void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
233   void SetNodeOnFace(SMDS_MeshNode * aNode, int Index , double u=0., double v=0.);
234   void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index , double u=0.);
235   void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
236   void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
237
238   void AddGroup (SMESHDS_GroupBase* theGroup)      { myGroups.insert(theGroup); }
239   void RemoveGroup (SMESHDS_GroupBase* theGroup)   { myGroups.erase(theGroup); }
240   int GetNbGroups() const                      { return myGroups.size(); }
241   const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
242
243   bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
244
245   ~SMESHDS_Mesh();
246   
247 private:
248 #ifndef WNT
249   struct HashTopoDS_Shape{
250     size_t operator()(const TopoDS_Shape& S) const {
251       return S.HashCode(2147483647);
252     }
253   };
254 #else
255   typedef gstd::hash_compare< TopoDS_Shape, less<TopoDS_Shape> > HashTopoDS;
256
257   class HashTopoDS_Shape : public HashTopoDS {
258   public:
259   
260     size_t operator()(const TopoDS_Shape& S) const {
261       return S.HashCode(2147483647);
262     }
263
264         bool operator()(const TopoDS_Shape& S1,const TopoDS_Shape& S2) const {
265                 return S1==S2;
266         }
267   };
268
269
270
271 #endif
272
273   void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index )
274   {
275     //Update or build submesh
276     map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
277     if ( it == myShapeIndexToSubMesh.end() )
278       it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh() )).first;
279     it->second->AddNode( aNode ); // add aNode to submesh
280   }
281
282   typedef std::list<const SMESHDS_Hypothesis*> THypList;
283
284 #ifndef WNT
285   typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
286 #else
287   typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
288 #endif
289
290   ShapeToHypothesis          myShapeToHypothesis;
291
292   int                        myMeshID;
293   TopoDS_Shape               myShape;
294
295   typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
296   TShapeIndexToSubMesh myShapeIndexToSubMesh;
297
298   TopTools_IndexedMapOfShape myIndexToShape;
299
300   typedef std::set<SMESHDS_GroupBase*> TGroups;
301   TGroups myGroups;
302
303   SMESHDS_Script*            myScript;
304 };
305
306
307 #endif