Salome HOME
Cange std::hash_map on NCollection data map
[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
49 #include <NCollection_DataMap.hxx>
50 #include <map>
51 /*
52  * Using of native haah_map isn't portable and don't work on WIN32 platform.
53  * So this functionality implement on new NCollection_DataMap technology
54  */
55 #include "SMESHDS_DataMapOfShape.hxx"
56
57 class SMESHDS_GroupBase;
58
59 class SMESHDS_EXPORT SMESHDS_Mesh:public SMDS_Mesh{
60 public:
61   SMESHDS_Mesh(int MeshID);
62   void ShapeToMesh(const TopoDS_Shape & S);
63   bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
64   bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
65   
66   virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
67   virtual SMDS_MeshNode * AddNode(double x, double y, double z);
68   
69   virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
70   virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
71                                        const SMDS_MeshNode * n2, 
72                                        int ID);
73   virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
74                                  const SMDS_MeshNode * n2);
75   
76   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
77   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
78                                        const SMDS_MeshNode * n2,
79                                        const SMDS_MeshNode * n3, 
80                                        int ID);
81   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
82                                  const SMDS_MeshNode * n2,
83                                  const SMDS_MeshNode * n3);
84
85   virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
86   virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
87                                        const SMDS_MeshNode * n2,
88                                        const SMDS_MeshNode * n3,
89                                        const SMDS_MeshNode * n4, 
90                                        int ID);
91   virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
92                                  const SMDS_MeshNode * n2,
93                                  const SMDS_MeshNode * n3,
94                                  const SMDS_MeshNode * n4);
95
96   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
97   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
98                                            const SMDS_MeshNode * n2,
99                                            const SMDS_MeshNode * n3,
100                                            const SMDS_MeshNode * n4, 
101                                            int ID);
102   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
103                                      const SMDS_MeshNode * n2,
104                                      const SMDS_MeshNode * n3,
105                                      const SMDS_MeshNode * n4);
106
107   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
108   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
109                                            const SMDS_MeshNode * n2,
110                                            const SMDS_MeshNode * n3,
111                                            const SMDS_MeshNode * n4,
112                                            const SMDS_MeshNode * n5, 
113                                            int ID);
114   virtual SMDS_MeshVolume* AddVolume(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
120   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
121   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
122                                            const SMDS_MeshNode * n2,
123                                            const SMDS_MeshNode * n3,
124                                            const SMDS_MeshNode * n4,
125                                            const SMDS_MeshNode * n5,
126                                            const SMDS_MeshNode * n6, 
127                                            int ID);
128   virtual SMDS_MeshVolume* AddVolume(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                                      const SMDS_MeshNode * n6);
134
135   virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
136   virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
137                                            const SMDS_MeshNode * n2,
138                                            const SMDS_MeshNode * n3,
139                                            const SMDS_MeshNode * n4,
140                                            const SMDS_MeshNode * n5,
141                                            const SMDS_MeshNode * n6,
142                                            const SMDS_MeshNode * n7,
143                                            const SMDS_MeshNode * n8, 
144                                            int ID);
145   virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
146                                      const SMDS_MeshNode * n2,
147                                      const SMDS_MeshNode * n3,
148                                      const SMDS_MeshNode * n4,
149                                      const SMDS_MeshNode * n5,
150                                      const SMDS_MeshNode * n6,
151                                      const SMDS_MeshNode * n7,
152                                      const SMDS_MeshNode * n8);
153   
154   virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
155                                                  const int        ID);
156
157   virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
158                                                  const int                         ID);
159
160   virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
161
162   virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
163                            (std::vector<int> nodes_ids,
164                             std::vector<int> quantities,
165                             const int        ID);
166
167   virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
168                            (std::vector<const SMDS_MeshNode*> nodes,
169                             std::vector<int>                  quantities,
170                             const int                         ID);
171
172   virtual SMDS_MeshVolume* AddPolyhedralVolume
173                            (std::vector<const SMDS_MeshNode*> nodes,
174                             std::vector<int>                  quantities);
175
176   void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
177   virtual void RemoveNode(const SMDS_MeshNode *);
178   void RemoveElement(const SMDS_MeshElement *);
179   bool ChangeElementNodes(const SMDS_MeshElement * elem,
180                           const SMDS_MeshNode    * nodes[],
181                           const int                nbnodes);
182   bool ChangePolygonNodes(const SMDS_MeshElement * elem,
183                           std::vector<const SMDS_MeshNode*> nodes);
184   bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
185                              std::vector<const SMDS_MeshNode*> nodes,
186                              std::vector<int>                  quantities);
187   void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
188
189   void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
190   void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Solid & S);
191   void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S, double u=0., double v=0.);
192   void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S, double u=0.);
193   void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
194   void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
195   void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
196                              const TopoDS_Shape & S);
197   void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
198                                const TopoDS_Shape & S);
199   TopoDS_Shape ShapeToMesh() const;
200   bool HasMeshElements(const TopoDS_Shape & S);
201   SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
202   SMESHDS_SubMesh * MeshElements(const int Index);
203   std::list<int> SubMeshIndices();
204   const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
205   { return myShapeIndexToSubMesh; }
206
207   bool HasHypothesis(const TopoDS_Shape & S);
208   const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
209   SMESHDS_Script * GetScript();
210   void ClearScript();
211   int ShapeToIndex(const TopoDS_Shape & aShape) const;
212   TopoDS_Shape IndexToShape(int ShapeIndex);
213
214   SMESHDS_SubMesh * NewSubMesh(int Index);
215   int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
216   void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
217   void SetNodeOnFace(SMDS_MeshNode * aNode, int Index , double u=0., double v=0.);
218   void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index , double u=0.);
219   void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
220   void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
221
222   void AddGroup (SMESHDS_GroupBase* theGroup)      { myGroups.insert(theGroup); }
223   void RemoveGroup (SMESHDS_GroupBase* theGroup)   { myGroups.erase(theGroup); }
224   int GetNbGroups() const                      { return myGroups.size(); }
225   const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
226
227   bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
228
229   ~SMESHDS_Mesh();
230   
231 private:
232   void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index )
233   {
234     //Update or build submesh
235     map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
236     if ( it == myShapeIndexToSubMesh.end() )
237       it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh() )).first;
238     it->second->AddNode( aNode ); // add aNode to submesh
239   }
240
241   /*int HashCode( const TopoDS_Shape& S, const Standard_Integer theUpper ) const
242   {
243       return S.HashCode(2147483647);
244   }*/ 
245
246   typedef std::list<const SMESHDS_Hypothesis*> THypList;
247
248   typedef NCollection_DataMap< TopoDS_Shape, THypList > ShapeToHypothesis;
249
250   ShapeToHypothesis          myShapeToHypothesis;
251
252   int                        myMeshID;
253   TopoDS_Shape               myShape;
254
255   typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
256   TShapeIndexToSubMesh myShapeIndexToSubMesh;
257
258   TopTools_IndexedMapOfShape myIndexToShape;
259
260   typedef std::set<SMESHDS_GroupBase*> TGroups;
261   TGroups myGroups;
262
263   SMESHDS_Script*            myScript;
264 };
265
266
267 #endif