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
64 #else // ... there are other compilers, right?
68 #if defined WNT && defined WIN32 && defined SMESHDS_EXPORTS
69 #define SMESHDS_WNT_EXPORT __declspec( dllexport )
71 #define SMESHDS_WNT_EXPORT
74 class SMESHDS_GroupBase;
76 class SMESHDS_WNT_EXPORT SMESHDS_Mesh:public SMDS_Mesh{
78 SMESHDS_Mesh(int MeshID);
79 void ShapeToMesh(const TopoDS_Shape & S);
80 bool AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H);
81 bool RemoveHypothesis(const TopoDS_Shape & S, const SMESHDS_Hypothesis * H);
83 virtual SMDS_MeshNode* AddNodeWithID(double x, double y, double z, int ID);
84 virtual SMDS_MeshNode * AddNode(double x, double y, double z);
86 virtual SMDS_MeshEdge* AddEdgeWithID(int n1, int n2, int ID);
87 virtual SMDS_MeshEdge* AddEdgeWithID(const SMDS_MeshNode * n1,
88 const SMDS_MeshNode * n2,
90 virtual SMDS_MeshEdge* AddEdge(const SMDS_MeshNode * n1,
91 const SMDS_MeshNode * n2);
93 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int ID);
94 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
95 const SMDS_MeshNode * n2,
96 const SMDS_MeshNode * n3,
98 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
99 const SMDS_MeshNode * n2,
100 const SMDS_MeshNode * n3);
102 virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, int n4, int ID);
103 virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshNode * n1,
104 const SMDS_MeshNode * n2,
105 const SMDS_MeshNode * n3,
106 const SMDS_MeshNode * n4,
108 virtual SMDS_MeshFace* AddFace(const SMDS_MeshNode * n1,
109 const SMDS_MeshNode * n2,
110 const SMDS_MeshNode * n3,
111 const SMDS_MeshNode * n4);
113 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int ID);
114 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
115 const SMDS_MeshNode * n2,
116 const SMDS_MeshNode * n3,
117 const SMDS_MeshNode * n4,
119 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
120 const SMDS_MeshNode * n2,
121 const SMDS_MeshNode * n3,
122 const SMDS_MeshNode * n4);
124 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID);
125 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
126 const SMDS_MeshNode * n2,
127 const SMDS_MeshNode * n3,
128 const SMDS_MeshNode * n4,
129 const SMDS_MeshNode * n5,
131 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
132 const SMDS_MeshNode * n2,
133 const SMDS_MeshNode * n3,
134 const SMDS_MeshNode * n4,
135 const SMDS_MeshNode * n5);
137 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID);
138 virtual SMDS_MeshVolume* AddVolumeWithID(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* 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);
152 virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID);
153 virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshNode * n1,
154 const SMDS_MeshNode * n2,
155 const SMDS_MeshNode * n3,
156 const SMDS_MeshNode * n4,
157 const SMDS_MeshNode * n5,
158 const SMDS_MeshNode * n6,
159 const SMDS_MeshNode * n7,
160 const SMDS_MeshNode * n8,
162 virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshNode * n1,
163 const SMDS_MeshNode * n2,
164 const SMDS_MeshNode * n3,
165 const SMDS_MeshNode * n4,
166 const SMDS_MeshNode * n5,
167 const SMDS_MeshNode * n6,
168 const SMDS_MeshNode * n7,
169 const SMDS_MeshNode * n8);
171 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<int> nodes_ids,
174 virtual SMDS_MeshFace* AddPolygonalFaceWithID (std::vector<const SMDS_MeshNode*> nodes,
177 virtual SMDS_MeshFace* AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes);
179 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
180 (std::vector<int> nodes_ids,
181 std::vector<int> quantities,
184 virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID
185 (std::vector<const SMDS_MeshNode*> nodes,
186 std::vector<int> quantities,
189 virtual SMDS_MeshVolume* AddPolyhedralVolume
190 (std::vector<const SMDS_MeshNode*> nodes,
191 std::vector<int> quantities);
193 void MoveNode(const SMDS_MeshNode *, double x, double y, double z);
194 virtual void RemoveNode(const SMDS_MeshNode *);
195 void RemoveElement(const SMDS_MeshElement *);
196 bool ChangeElementNodes(const SMDS_MeshElement * elem,
197 const SMDS_MeshNode * nodes[],
199 bool ChangePolygonNodes(const SMDS_MeshElement * elem,
200 std::vector<const SMDS_MeshNode*> nodes);
201 bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
202 std::vector<const SMDS_MeshNode*> nodes,
203 std::vector<int> quantities);
204 void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
206 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Shell & S);
207 void SetNodeInVolume(SMDS_MeshNode * aNode, const TopoDS_Solid & S);
208 void SetNodeOnFace(SMDS_MeshNode * aNode, const TopoDS_Face & S, double u=0., double v=0.);
209 void SetNodeOnEdge(SMDS_MeshNode * aNode, const TopoDS_Edge & S, double u=0.);
210 void SetNodeOnVertex(SMDS_MeshNode * aNode, const TopoDS_Vertex & S);
211 void UnSetNodeOnShape(const SMDS_MeshNode * aNode);
212 void SetMeshElementOnShape(const SMDS_MeshElement * anElt,
213 const TopoDS_Shape & S);
214 void UnSetMeshElementOnShape(const SMDS_MeshElement * anElt,
215 const TopoDS_Shape & S);
216 TopoDS_Shape ShapeToMesh() const;
217 bool HasMeshElements(const TopoDS_Shape & S);
218 SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S) const;
219 SMESHDS_SubMesh * MeshElements(const int Index);
220 std::list<int> SubMeshIndices();
221 const std::map<int,SMESHDS_SubMesh*>& SubMeshes()
222 { return myShapeIndexToSubMesh; }
224 bool HasHypothesis(const TopoDS_Shape & S);
225 const std::list<const SMESHDS_Hypothesis*>& GetHypothesis(const TopoDS_Shape & S) const;
226 SMESHDS_Script * GetScript();
228 int ShapeToIndex(const TopoDS_Shape & aShape) const;
229 TopoDS_Shape IndexToShape(int ShapeIndex);
231 SMESHDS_SubMesh * NewSubMesh(int Index);
232 int AddCompoundSubmesh(const TopoDS_Shape& S, TopAbs_ShapeEnum type = TopAbs_SHAPE);
233 void SetNodeInVolume(const SMDS_MeshNode * aNode, int Index);
234 void SetNodeOnFace(SMDS_MeshNode * aNode, int Index , double u=0., double v=0.);
235 void SetNodeOnEdge(SMDS_MeshNode * aNode, int Index , double u=0.);
236 void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
237 void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
239 void AddGroup (SMESHDS_GroupBase* theGroup) { myGroups.insert(theGroup); }
240 void RemoveGroup (SMESHDS_GroupBase* theGroup) { myGroups.erase(theGroup); }
241 int GetNbGroups() const { return myGroups.size(); }
242 const std::set<SMESHDS_GroupBase*>& GetGroups() const { return myGroups; }
244 bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const;
250 struct HashTopoDS_Shape{
251 size_t operator()(const TopoDS_Shape& S) const {
252 return S.HashCode(2147483647);
256 typedef gstd::hash_compare< TopoDS_Shape, less<TopoDS_Shape> > HashTopoDS;
258 class HashTopoDS_Shape : public HashTopoDS {
261 size_t operator()(const TopoDS_Shape& S) const {
262 return S.HashCode(2147483647);
265 bool operator()(const TopoDS_Shape& S1,const TopoDS_Shape& S2) const {
274 void addNodeToSubmesh( const SMDS_MeshNode* aNode, int Index )
276 //Update or build submesh
277 map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
278 if ( it == myShapeIndexToSubMesh.end() )
279 it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh() )).first;
280 it->second->AddNode( aNode ); // add aNode to submesh
283 typedef std::list<const SMESHDS_Hypothesis*> THypList;
286 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
288 typedef gstd::hash_map<TopoDS_Shape,THypList,HashTopoDS_Shape> ShapeToHypothesis;
291 ShapeToHypothesis myShapeToHypothesis;
294 TopoDS_Shape myShape;
296 typedef std::map<int,SMESHDS_SubMesh*> TShapeIndexToSubMesh;
297 TShapeIndexToSubMesh myShapeIndexToSubMesh;
299 TopTools_IndexedMapOfShape myIndexToShape;
301 typedef std::set<SMESHDS_GroupBase*> TGroups;
304 SMESHDS_Script* myScript;