Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 theLocalId, 
83              int theStudyId, 
84              SMESH_Gen* theGen,
85              bool theIsEmbeddedMode,
86              SMESHDS_Document* theDocument);
87   
88   virtual ~SMESH_Mesh();
89   
90   void ShapeToMesh(const TopoDS_Shape & aShape);
91   
92   int UNVToMesh(const char* theFileName);
93   /*!
94    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
95    */
96   int MEDToMesh(const char* theFileName, const char* theMeshName);
97   
98   int STLToMesh(const char* theFileName);
99
100   SMESH_Hypothesis::Hypothesis_Status
101   AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
102     throw(SALOME_Exception);
103   
104   SMESH_Hypothesis::Hypothesis_Status
105   RemoveHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
106     throw(SALOME_Exception);
107   
108   const list <const SMESHDS_Hypothesis * >&
109   GetHypothesisList(const TopoDS_Shape & aSubShape) const
110     throw(SALOME_Exception);
111
112   const SMESH_Hypothesis * GetHypothesis(const TopoDS_Shape &    aSubShape,
113                                          const SMESH_HypoFilter& aFilter,
114                                          const bool              andAncestors) const;
115   
116   int GetHypotheses(const TopoDS_Shape &                aSubShape,
117                     const SMESH_HypoFilter&             aFilter,
118                     list <const SMESHDS_Hypothesis * >& aHypList,
119                     const bool                          andAncestors) const;
120
121   const list<SMESHDS_Command*> & GetLog() throw(SALOME_Exception);
122   
123   void ClearLog() throw(SALOME_Exception);
124   
125   int GetId();
126   
127   SMESHDS_Mesh * GetMeshDS();
128   
129   SMESH_Gen *GetGen();
130   
131   SMESH_subMesh *GetSubMesh(const TopoDS_Shape & aSubShape)
132     throw(SALOME_Exception);
133   
134   SMESH_subMesh *GetSubMeshContaining(const TopoDS_Shape & aSubShape)
135     throw(SALOME_Exception);
136   
137   SMESH_subMesh *GetSubMeshContaining(const int aShapeID)
138     throw(SALOME_Exception);
139   
140   void NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp);
141   // Say all submeshes that theChangedHyp has been modified
142
143   const list < SMESH_subMesh * >&
144   GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
145     throw(SALOME_Exception);
146   
147   bool IsUsedHypothesis(SMESHDS_Hypothesis *  anHyp,
148                         const SMESH_subMesh * aSubMesh);
149   // Return True if anHyp is used to mesh aSubShape
150   
151   bool IsNotConformAllowed() const;
152   // check if a hypothesis alowing notconform mesh is present
153   
154   bool IsMainShape(const TopoDS_Shape& theShape) const;
155
156   const TopTools_ListOfShape& GetAncestors(const TopoDS_Shape& theSubShape) const;
157   // return list of ancestors of theSubShape in the order
158   // that lower dimention shapes come first.
159
160   /*! Check group names for duplications.
161    *  Consider maximum group name length stored in MED file.
162    */
163   bool HasDuplicatedGroupNamesMED();
164
165   void ExportMED(const char *file, 
166                  const char* theMeshName = NULL, 
167                  bool theAutoGroups = true, 
168                  int theVersion = 0) 
169     throw(SALOME_Exception);
170
171   void ExportDAT(const char *file) throw(SALOME_Exception);
172   void ExportUNV(const char *file) throw(SALOME_Exception);
173   void ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception);
174   
175   int NbNodes() throw(SALOME_Exception);
176   
177   /*!
178    * ElementOrder points out entities of what order are requested
179    */
180   enum ElementOrder {
181     ORDER_ANY,          /*! entities of any order */
182     ORDER_LINEAR,       /*! entities of 1st order */
183     ORDER_QUADRATIC     /*! entities of 2nd order */
184   };
185
186   int NbEdges(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
187   
188   int NbFaces(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
189   
190   int NbTriangles(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
191   
192   int NbQuadrangles(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
193
194   int NbPolygons() throw(SALOME_Exception);
195   
196   int NbVolumes(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
197   
198   int NbTetras(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
199   
200   int NbHexas(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
201   
202   int NbPyramids(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
203
204   int NbPrisms(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
205   
206   int NbPolyhedrons() throw(SALOME_Exception);
207   
208   int NbSubMesh() throw(SALOME_Exception);
209   
210   int NbGroup() const { return _mapGroup.size(); }
211   
212   SMESH_Group* AddGroup (const SMDSAbs_ElementType theType,
213                          const char*               theName,
214                          int&                      theId,
215                          const TopoDS_Shape&       theShape=TopoDS_Shape());
216   
217   SMESH_Group* GetGroup (const int theGroupID);
218   
219   list<int> GetGroupIds();
220   
221   void RemoveGroup (const int theGroupID);
222
223   // Propagation hypothesis management
224
225   const SMESH_Hypothesis* IsLocal1DHypothesis (const TopoDS_Shape& theEdge);
226   // Returns a local 1D hypothesis used for theEdge.
227
228   bool IsPropagationHypothesis (const TopoDS_Shape& theEdge);
229   // Returns true, if a local Propagation hypothesis is set directly on <theEdge>
230
231   bool IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
232                                TopoDS_Shape&       theMainEdge);
233   // Returns true, if a local 1D hypothesis is
234   // propagated on <theEdge> from some other edge.
235   // Returns through <theMainEdge> the edge, from
236   // which the 1D hypothesis is propagated on <theEdge>
237
238   bool IsReversedInChain (const TopoDS_Shape& theEdge,
239                           const TopoDS_Shape& theMainEdge);
240   // Returns true if theEdge should be reversed to be
241   // co-directed with theMainEdge
242
243   bool RebuildPropagationChains();
244   bool RemovePropagationChain (const TopoDS_Shape& theMainEdge);
245   bool BuildPropagationChain (const TopoDS_Shape& theMainEdge);
246   
247   SMDSAbs_ElementType GetElementType( const int id, const bool iselem );
248
249   //
250   
251   ostream& Dump(ostream & save);
252   
253 private:
254   // Propagation hypothesis management
255   void CleanMeshOnPropagationChain(const TopoDS_Shape& theMainEdge);
256   //
257   
258 private:
259   int                        _id;           // id given by creator (unique within the creator instance)
260   int                        _studyId;
261   int                        _idDoc;        // id given by SMESHDS_Document
262   int                        _groupId;      // id generator for group objects
263   bool                       _isShapeToMesh;// set to true when a shape is given (only once)
264   list <SMESH_subMesh *>     _subMeshesUsingHypothesisList;
265   SMESHDS_Document *         _myDocument;
266   SMESHDS_Mesh *             _myMeshDS;
267   map <int, SMESH_subMesh *> _mapSubMesh;
268   map <int, SMESH_Group *>   _mapGroup;
269   SMESH_Gen *                _gen;
270   
271   TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;
272
273   IndexedMapOfChain _mapPropagationChains; // Propagation hypothesis management
274 };
275
276 #endif