1 // SMESH SMESHDS : management of mesh data and SMESH document
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHDS_Mesh.hxx
27 #ifndef _SMESHDS_Mesh_HeaderFile
28 #define _SMESHDS_Mesh_HeaderFile
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"
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>
50 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
54 namespace gstd { using ::hash_map; }; // inherit globals
56 #include <ext/hash_map>
57 #if __GNUC_MINOR__ == 0
58 namespace gstd = std; // GCC 3.0
60 namespace gstd = ::__gnu_cxx; // GCC 3.1 and later
63 #else // ... there are other compilers, right?
67 class SMESHDS_GroupBase;
69 class SMESHDS_Mesh:public SMDS_Mesh{
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);
76 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
77 virtual SMDS_MeshNode * AddNode(double x, double y, double z);
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,
83 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
84 const SMDS_MeshNode * n2);
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,
91 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
92 const SMDS_MeshNode * n2,
93 const SMDS_MeshNode * n3);
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,
101 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
102 const SMDS_MeshNode * n2,
103 const SMDS_MeshNode * n3,
104 const SMDS_MeshNode * n4);
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,
112 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
113 const SMDS_MeshNode * n2,
114 const SMDS_MeshNode * n3,
115 const SMDS_MeshNode * n4);
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,
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);
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,
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);
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,
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);
164 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
167 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
170 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
172 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
173 (std::vector<int> nodes_ids,
174 std::vector<int> quantities,
177 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
178 (std::vector<const SMDS_MeshNode*> nodes,
179 std::vector<int> quantities,
182 virtual SMDS_MeshVolume* AddPolyhedralVolume
183 (std::vector<const SMDS_MeshNode*> nodes,
184 std::vector<int> quantities);
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[],
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);
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; }
216 bool HasHypothesis(const TopoDS_Shape & S);
217 const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
218 SMESHDS_Script * GetScript();
220 int ShapeToIndex(const TopoDS_Shape & aShape) const;
221 TopoDS_Shape IndexToShape(int ShapeIndex);
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);
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; }
236 bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
242 struct HashTopoDS_Shape{
243 size_t operator()(const TopoDS_Shape& S) const {
244 return S.HashCode(2147483647);
248 typedef gstd::hash_compare< TopoDS_Shape, less<TopoDS_Shape> > HashTopoDS;
250 class HashTopoDS_Shape : public HashTopoDS {
253 size_t operator()(const TopoDS_Shape& S) const {
254 return S.HashCode(2147483647);
257 bool operator()(const TopoDS_Shape& S1,const TopoDS_Shape& S2) const {
266 typedef std::list<const SMESHDS_Hypothesis*> THypList;
269 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
271 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
274 ShapeToHypothesis myShapeToHypothesis;
277 TopoDS_Shape myShape;
279 typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
280 TShapeIndexToSubMesh myShapeIndexToSubMesh;
282 TopTools_IndexedMapOfShape myIndexToShape;
284 typedef std::set<SMESHDS_GroupBase*> TGroups;
287 SMESHDS_Script* myScript;