Salome HOME
Replaced NMTTools map with NCollection map for removing dependencies from GEOM module.
[modules/smesh.git] / src / SMESH / SMESH_Mesh.hxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
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   : SMESH_Mesh.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef _SMESH_MESH_HXX_
30 #define _SMESH_MESH_HXX_
31
32 #include "SMESH_Hypothesis.hxx"
33 //#include "SMESH_subMesh.hxx"
34
35 #include "SMESHDS_Document.hxx"
36 #include "SMESHDS_Mesh.hxx"
37 #include "SMESHDS_Command.hxx"
38 #include "SMDSAbs_ElementType.hxx"
39
40 //#include "NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx"
41 #include "SMESH_IndexedDataMapOfShapeIndexedMapOfShape.hxx"
42
43 #include "Utils_SALOME_Exception.hxx"
44
45 #include <TopExp.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopoDS.hxx>
48 #include <TopoDS_Iterator.hxx>
49 #include <TopoDS_Compound.hxx>
50 #include <TopoDS_CompSolid.hxx>
51 #include <TopoDS_Solid.hxx>
52 #include <TopoDS_Shell.hxx>
53 #include <TopoDS_Face.hxx>
54 #include <TopoDS_Wire.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Vertex.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TopTools_IndexedMapOfShape.hxx>
59 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
60
61 #include <vector>
62 #include <list>
63 #include <map>
64
65 #include <string>
66 #include <iostream>
67
68 class SMESH_Gen;
69 class SMESH_Group;
70 class TopTools_ListOfShape;
71 class SMESH_subMesh;
72 class SMESH_HypoFilter;
73
74 //typedef NMTTools_IndexedDataMapOfShapeIndexedMapOfShape IndexedMapOfChain;
75 typedef SMESH_IndexedDataMapOfShapeIndexedMapOfShape IndexedMapOfChain;
76
77 class SMESH_Mesh
78 {
79   SMESH_Mesh();
80   SMESH_Mesh(const SMESH_Mesh&);
81 public:
82   SMESH_Mesh(int localId, int studyId, SMESH_Gen * gen,
83              SMESHDS_Document * myDocument);
84   
85   virtual ~SMESH_Mesh();
86   
87   void ShapeToMesh(const TopoDS_Shape & aShape);
88   
89   int UNVToMesh(const char* theFileName);
90   /*!
91    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
92    */
93   int MEDToMesh(const char* theFileName, const char* theMeshName);
94   
95   int STLToMesh(const char* theFileName);
96
97   SMESH_Hypothesis::Hypothesis_Status
98   AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
99     throw(SALOME_Exception);
100   
101   SMESH_Hypothesis::Hypothesis_Status
102   RemoveHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
103     throw(SALOME_Exception);
104   
105   const list <const SMESHDS_Hypothesis * >&
106   GetHypothesisList(const TopoDS_Shape & aSubShape) const
107     throw(SALOME_Exception);
108
109   const SMESH_Hypothesis * GetHypothesis(const TopoDS_Shape &    aSubShape,
110                                          const SMESH_HypoFilter& aFilter,
111                                          const bool              andAncestors) const;
112   
113   bool GetHypotheses(const TopoDS_Shape &                aSubShape,
114                      const SMESH_HypoFilter&             aFilter,
115                      list <const SMESHDS_Hypothesis * >& aHypList,
116                      const bool                          andAncestors) const;
117
118   const list<SMESHDS_Command*> & GetLog() throw(SALOME_Exception);
119   
120   void ClearLog() throw(SALOME_Exception);
121   
122   int GetId();
123   
124   SMESHDS_Mesh * GetMeshDS();
125   
126   SMESH_Gen *GetGen();
127   
128   SMESH_subMesh *GetSubMesh(const TopoDS_Shape & aSubShape)
129     throw(SALOME_Exception);
130   
131   SMESH_subMesh *GetSubMeshContaining(const TopoDS_Shape & aSubShape)
132     throw(SALOME_Exception);
133   
134   SMESH_subMesh *GetSubMeshContaining(const int aShapeID)
135     throw(SALOME_Exception);
136   
137   const list < SMESH_subMesh * >&
138   GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
139     throw(SALOME_Exception);
140   
141   bool IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
142                         const TopoDS_Shape & aSubShape);
143   // Return True if anHyp is used to mesh aSubShape
144   
145   bool IsNotConformAllowed() const;
146   // check if a hypothesis alowing notconform mesh is present
147   
148   bool IsMainShape(const TopoDS_Shape& theShape) const;
149
150   const TopTools_ListOfShape& GetAncestors(const TopoDS_Shape& theSubShape) const;
151   // return list of ancestors of theSubShape in the order
152   // that lower dimention shapes come first.
153   
154   void ExportMED(const char *file, 
155                  const char* theMeshName = NULL, 
156                  bool theAutoGroups = true, 
157                  int theVersion = 0) 
158     throw(SALOME_Exception);
159
160   void ExportDAT(const char *file) throw(SALOME_Exception);
161   void ExportUNV(const char *file) throw(SALOME_Exception);
162   void ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception);
163   
164   int NbNodes() throw(SALOME_Exception);
165   
166   int NbEdges() throw(SALOME_Exception);
167   
168   int NbFaces() throw(SALOME_Exception);
169   
170   int NbTriangles() throw(SALOME_Exception);
171   
172   int NbQuadrangles() throw(SALOME_Exception);
173
174   int NbPolygons() throw(SALOME_Exception);
175   
176   int NbVolumes() throw(SALOME_Exception);
177   
178   int NbTetras() throw(SALOME_Exception);
179   
180   int NbHexas() throw(SALOME_Exception);
181   
182   int NbPyramids() throw(SALOME_Exception);
183
184   int NbPrisms() throw(SALOME_Exception);
185   
186   int NbPolyhedrons() throw(SALOME_Exception);
187   
188   int NbSubMesh() throw(SALOME_Exception);
189   
190   int NbGroup() const { return _mapGroup.size(); }
191   
192   SMESH_Group* AddGroup (const SMDSAbs_ElementType theType,
193                          const char*               theName,
194                          int&                      theId,
195                          const TopoDS_Shape&       theShape=TopoDS_Shape());
196   
197   SMESH_Group* GetGroup (const int theGroupID);
198   
199   list<int> GetGroupIds();
200   
201   void RemoveGroup (const int theGroupID);
202
203   // Propagation hypothesis management
204
205   const SMESH_Hypothesis* IsLocal1DHypothesis (const TopoDS_Shape& theEdge);
206   // Returns a local 1D hypothesis used for theEdge.
207
208   bool IsPropagationHypothesis (const TopoDS_Shape& theEdge);
209   // Returns true, if a local Propagation hypothesis is set directly on <theEdge>
210
211   bool IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
212                                TopoDS_Shape&       theMainEdge);
213   // Returns true, if a local 1D hypothesis is
214   // propagated on <theEdge> from some other edge.
215   // Returns through <theMainEdge> the edge, from
216   // which the 1D hypothesis is propagated on <theEdge>
217
218   bool IsReversedInChain (const TopoDS_Shape& theEdge,
219                           const TopoDS_Shape& theMainEdge);
220   // Returns true if theEdge should be reversed to be
221   // co-directed with theMainEdge
222
223   bool RebuildPropagationChains();
224   bool RemovePropagationChain (const TopoDS_Shape& theMainEdge);
225   bool BuildPropagationChain (const TopoDS_Shape& theMainEdge);
226   
227   SMDSAbs_ElementType GetElementType( const int id, const bool iselem );
228
229   //
230   
231   ostream& Dump(ostream & save);
232   
233 private:
234   // Propagation hypothesis management
235   void CleanMeshOnPropagationChain(const TopoDS_Shape& theMainEdge);
236   //
237   
238 private:
239   int                        _id;           // id given by creator (unique within the creator instance)
240   int                        _studyId;
241   int                        _idDoc;        // id given by SMESHDS_Document
242   int                        _groupId;      // id generator for group objects
243   bool                       _isShapeToMesh;// set to true when a shape is given (only once)
244   list <SMESH_subMesh *>     _subMeshesUsingHypothesisList;
245   SMESHDS_Document *         _myDocument;
246   SMESHDS_Mesh *             _myMeshDS;
247   map <int, SMESH_subMesh *> _mapSubMesh;
248   map <int, SMESH_Group *>   _mapGroup;
249   SMESH_Gen *                _gen;
250   
251   TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;
252
253   IndexedMapOfChain _mapPropagationChains; // Propagation hypothesis management
254 };
255
256 #endif