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>
47 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
51 namespace gstd { using ::hash_map; }; // inherit globals
53 #include <ext/hash_map>
54 #if __GNUC_MINOR__ == 0
55 namespace gstd = std; // GCC 3.0
57 namespace gstd = ::__gnu_cxx; // GCC 3.1 and later
60 #else // ... there are other compilers, right?
64 class SMESHDS_GroupBase;
66 class SMESHDS_Mesh:public SMDS_Mesh{
68 SMESHDS_Mesh(int MeshID);
69 void ShapeToMesh(const TopoDS_Shape & S);
70 bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
71 bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
73 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
74 virtual SMDS_MeshNode * AddNode(double x, double y, double z);
76 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
77 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
78 const SMDS_MeshNode * n2,
80 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
81 const SMDS_MeshNode * n2);
83 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
84 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
85 const SMDS_MeshNode * n2,
86 const SMDS_MeshNode * n3,
88 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
89 const SMDS_MeshNode * n2,
90 const SMDS_MeshNode * n3);
92 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
93 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
94 const SMDS_MeshNode * n2,
95 const SMDS_MeshNode * n3,
96 const SMDS_MeshNode * n4,
98 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
99 const SMDS_MeshNode * n2,
100 const SMDS_MeshNode * n3,
101 const SMDS_MeshNode * n4);
103 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
104 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
105 const SMDS_MeshNode * n2,
106 const SMDS_MeshNode * n3,
107 const SMDS_MeshNode * n4,
109 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
110 const SMDS_MeshNode * n2,
111 const SMDS_MeshNode * n3,
112 const SMDS_MeshNode * n4);
114 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
115 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
116 const SMDS_MeshNode * n2,
117 const SMDS_MeshNode * n3,
118 const SMDS_MeshNode * n4,
119 const SMDS_MeshNode * n5,
121 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
122 const SMDS_MeshNode * n2,
123 const SMDS_MeshNode * n3,
124 const SMDS_MeshNode * n4,
125 const SMDS_MeshNode * n5);
127 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, 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 const SMDS_MeshNode * n6,
135 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
136 const SMDS_MeshNode * n2,
137 const SMDS_MeshNode * n3,
138 const SMDS_MeshNode * n4,
139 const SMDS_MeshNode * n5,
140 const SMDS_MeshNode * n6);
142 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
143 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
144 const SMDS_MeshNode * n2,
145 const SMDS_MeshNode * n3,
146 const SMDS_MeshNode * n4,
147 const SMDS_MeshNode * n5,
148 const SMDS_MeshNode * n6,
149 const SMDS_MeshNode * n7,
150 const SMDS_MeshNode * n8,
152 virtual SMDS_MeshVolume* AddVolume(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);
161 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
164 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
167 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
169 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
170 (std::vector<int> nodes_ids,
171 std::vector<int> quantities,
174 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
175 (std::vector<const SMDS_MeshNode*> nodes,
176 std::vector<int> quantities,
179 virtual SMDS_MeshVolume* AddPolyhedralVolume
180 (std::vector<const SMDS_MeshNode*> nodes,
181 std::vector<int> quantities);
183 void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
184 virtual void RemoveNode(const SMDS_MeshNode *);
185 void RemoveElement(const SMDS_MeshElement *);
186 bool ChangeElementNodes(const SMDS_MeshElement * elem,
187 const SMDS_MeshNode * nodes[],
189 bool ChangePolygonNodes(const SMDS_MeshElement * elem,
190 std::vector<const SMDS_MeshNode*> nodes);
191 bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
192 std::vector<const SMDS_MeshNode*> nodes,
193 std::vector<int> quantities);
194 void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
196 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
197 void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S);
198 void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S);
199 void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
200 void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
201 void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
202 const TopoDS_Shape & S);
203 void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
204 const TopoDS_Shape & S);
205 TopoDS_Shape ShapeToMesh() const;
206 bool HasMeshElements(const TopoDS_Shape & S);
207 SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
208 SMESHDS_SubMesh * MeshElements(const int Index);
209 std::list<int> SubMeshIndices();
210 const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
211 { return myShapeIndexToSubMesh; }
213 bool HasHypothesis(const TopoDS_Shape & S);
214 const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
215 SMESHDS_Script * GetScript();
217 int ShapeToIndex(const TopoDS_Shape & aShape) const;
218 TopoDS_Shape IndexToShape(int ShapeIndex);
220 SMESHDS_SubMesh * NewSubMesh(int Index);
221 int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
222 void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
223 void SetNodeOnFace(SMDS_MeshNode * aNode, int Index);
224 void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index);
225 void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
226 void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
228 void AddGroup (SMESHDS_GroupBase* theGroup) { myGroups.insert(theGroup); }
229 void RemoveGroup (SMESHDS_GroupBase* theGroup) { myGroups.erase(theGroup); }
230 int GetNbGroups() const { return myGroups.size(); }
231 const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
233 bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
238 struct HashTopoDS_Shape{
239 size_t operator()(const TopoDS_Shape& S) const {
240 return S.HashCode(2147483647);
243 typedef std::list<const SMESHDS_Hypothesis*> THypList;
244 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
245 ShapeToHypothesis myShapeToHypothesis;
248 TopoDS_Shape myShape;
250 typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
251 TShapeIndexToSubMesh myShapeIndexToSubMesh;
253 TopTools_IndexedMapOfShape myIndexToShape;
255 typedef std::set<SMESHDS_GroupBase*> TGroups;
258 SMESHDS_Script* myScript;