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_Solid.hxx>
42 #include <TopoDS_Shell.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopoDS_Edge.hxx>
51 //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more.
55 namespace gstd { using ::hash_map; }; // inherit globals
57 #include <ext/hash_map>
58 #if __GNUC_MINOR__ == 0
59 namespace gstd = std; // GCC 3.0
61 namespace gstd = ::__gnu_cxx; // GCC 3.1 and later
63 #else // GCC 4.0 and later
64 #include <ext/hash_map>
65 namespace gstd = ::__gnu_cxx;
67 #else // ... there are other compilers, right?
71 #if defined WNT && defined WIN32 && defined SMESHDS_EXPORTS
72 #define SMESHDS_WNT_EXPORT __declspec( dllexport )
74 #define SMESHDS_WNT_EXPORT
77 class SMESHDS_GroupBase;
79 class SMESHDS_WNT_EXPORT SMESHDS_Mesh:public SMDS_Mesh{
81 SMESHDS_Mesh(int MeshID);
82 void ShapeToMesh(const TopoDS_Shape & S);
83 bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
84 bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
86 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
87 virtual SMDS_MeshNode * AddNode(double x, double y, double z);
89 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
90 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
91 const SMDS_MeshNode * n2,
93 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
94 const SMDS_MeshNode * n2);
96 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
97 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
98 const SMDS_MeshNode * n2,
99 const SMDS_MeshNode * n3,
101 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
102 const SMDS_MeshNode * n2,
103 const SMDS_MeshNode * n3);
105 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
106 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
107 const SMDS_MeshNode * n2,
108 const SMDS_MeshNode * n3,
109 const SMDS_MeshNode * n4,
111 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
112 const SMDS_MeshNode * n2,
113 const SMDS_MeshNode * n3,
114 const SMDS_MeshNode * n4);
116 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
117 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
118 const SMDS_MeshNode * n2,
119 const SMDS_MeshNode * n3,
120 const SMDS_MeshNode * n4,
122 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
123 const SMDS_MeshNode * n2,
124 const SMDS_MeshNode * n3,
125 const SMDS_MeshNode * n4);
127 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, 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,
134 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
135 const SMDS_MeshNode * n2,
136 const SMDS_MeshNode * n3,
137 const SMDS_MeshNode * n4,
138 const SMDS_MeshNode * n5);
140 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
141 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
142 const SMDS_MeshNode * n2,
143 const SMDS_MeshNode * n3,
144 const SMDS_MeshNode * n4,
145 const SMDS_MeshNode * n5,
146 const SMDS_MeshNode * n6,
148 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
149 const SMDS_MeshNode * n2,
150 const SMDS_MeshNode * n3,
151 const SMDS_MeshNode * n4,
152 const SMDS_MeshNode * n5,
153 const SMDS_MeshNode * n6);
155 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
156 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
157 const SMDS_MeshNode * n2,
158 const SMDS_MeshNode * n3,
159 const SMDS_MeshNode * n4,
160 const SMDS_MeshNode * n5,
161 const SMDS_MeshNode * n6,
162 const SMDS_MeshNode * n7,
163 const SMDS_MeshNode * n8,
165 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
166 const SMDS_MeshNode * n2,
167 const SMDS_MeshNode * n3,
168 const SMDS_MeshNode * n4,
169 const SMDS_MeshNode * n5,
170 const SMDS_MeshNode * n6,
171 const SMDS_MeshNode * n7,
172 const SMDS_MeshNode * n8);
174 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
177 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
180 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
182 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
183 (std::vector<int> nodes_ids,
184 std::vector<int> quantities,
187 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
188 (std::vector<const SMDS_MeshNode*> nodes,
189 std::vector<int> quantities,
192 virtual SMDS_MeshVolume* AddPolyhedralVolume
193 (std::vector<const SMDS_MeshNode*> nodes,
194 std::vector<int> quantities);
196 void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
197 virtual void RemoveNode(const SMDS_MeshNode *);
198 void RemoveElement(const SMDS_MeshElement *);
199 bool ChangeElementNodes(const SMDS_MeshElement * elem,
200 const SMDS_MeshNode * nodes[],
202 bool ChangePolygonNodes(const SMDS_MeshElement * elem,
203 std::vector<const SMDS_MeshNode*> nodes);
204 bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
205 std::vector<const SMDS_MeshNode*> nodes,
206 std::vector<int> quantities);
207 void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
209 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
210 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Solid & S);
211 void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S, double u=0., double v=0.);
212 void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S, double u=0.);
213 void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
214 void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
215 void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
216 const TopoDS_Shape & S);
217 void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
218 const TopoDS_Shape & S);
219 TopoDS_Shape ShapeToMesh() const;
220 bool HasMeshElements(const TopoDS_Shape & S);
221 SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
222 SMESHDS_SubMesh * MeshElements(const int Index);
223 std::list<int> SubMeshIndices();
224 const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
225 { return myShapeIndexToSubMesh; }
227 bool HasHypothesis(const TopoDS_Shape & S);
228 const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
229 SMESHDS_Script * GetScript();
231 int ShapeToIndex(const TopoDS_Shape & aShape) const;
232 TopoDS_Shape IndexToShape(int ShapeIndex);
234 SMESHDS_SubMesh * NewSubMesh(int Index);
235 int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
236 void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
237 void SetNodeOnFace(SMDS_MeshNode * aNode, int Index , double u=0., double v=0.);
238 void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index , double u=0.);
239 void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
240 void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
242 void AddGroup (SMESHDS_GroupBase* theGroup) { myGroups.insert(theGroup); }
243 void RemoveGroup (SMESHDS_GroupBase* theGroup) { myGroups.erase(theGroup); }
244 int GetNbGroups() const { return myGroups.size(); }
245 const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
247 bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
253 struct HashTopoDS_Shape{
254 size_t operator()(const TopoDS_Shape& S) const {
255 return S.HashCode(2147483647);
259 typedef gstd::hash_compare< TopoDS_Shape, less<TopoDS_Shape> > HashTopoDS;
261 class HashTopoDS_Shape : public HashTopoDS {
264 size_t operator()(const TopoDS_Shape& S) const {
265 return S.HashCode(2147483647);
268 bool operator()(const TopoDS_Shape& S1,const TopoDS_Shape& S2) const {
277 void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index )
279 //Update or build submesh
280 map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
281 if ( it == myShapeIndexToSubMesh.end() )
282 it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh() )).first;
283 it->second->AddNode( aNode ); // add aNode to submesh
286 typedef std::list<const SMESHDS_Hypothesis*> THypList;
289 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
291 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
294 ShapeToHypothesis myShapeToHypothesis;
297 TopoDS_Shape myShape;
299 typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
300 TShapeIndexToSubMesh myShapeIndexToSubMesh;
302 TopTools_IndexedMapOfShape myIndexToShape;
304 typedef std::set<SMESHDS_GroupBase*> TGroups;
307 SMESHDS_Script* myScript;