Salome HOME
Merging from V3_2_6pre4
[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_SMESH.hxx"
33
34 #include "SMESH_Hypothesis.hxx"
35 //#include "SMESH_subMesh.hxx"
36
37 #include "SMESHDS_Document.hxx"
38 #include "SMESHDS_Mesh.hxx"
39 #include "SMESHDS_Command.hxx"
40 #include "SMDSAbs_ElementType.hxx"
41
42 //#include "NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx"
43 #include "SMESH_IndexedDataMapOfShapeIndexedMapOfShape.hxx"
44
45 #include "Utils_SALOME_Exception.hxx"
46
47 #include <TopExp.hxx>
48 #include <TopExp_Explorer.hxx>
49 #include <TopoDS.hxx>
50 #include <TopoDS_Iterator.hxx>
51 #include <TopoDS_Compound.hxx>
52 #include <TopoDS_CompSolid.hxx>
53 #include <TopoDS_Solid.hxx>
54 #include <TopoDS_Shell.hxx>
55 #include <TopoDS_Face.hxx>
56 #include <TopoDS_Wire.hxx>
57 #include <TopoDS_Edge.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopTools_IndexedMapOfShape.hxx>
61 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
62
63 #include <vector>
64 #include <list>
65 #include <map>
66
67 #include <string>
68 #include <iostream>
69
70 class SMESH_Gen;
71 class SMESH_Group;
72 class TopTools_ListOfShape;
73 class SMESH_subMesh;
74 class SMESH_HypoFilter;
75 class TopoDS_Solid;
76
77 typedef SMESH_IndexedDataMapOfShapeIndexedMapOfShape IndexedMapOfChain;
78
79 class SMESH_EXPORT SMESH_Mesh
80 {
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   /*!
91    * \brief Set geometry to be meshed
92    */
93   void ShapeToMesh(const TopoDS_Shape & aShape);
94   /*!
95    * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
96    */
97   TopoDS_Shape GetShapeToMesh() const;
98   /*!
99    * \brief Return true if there is a geometry to be meshed, not PseudoShape()
100    */
101   bool HasShapeToMesh() const { return _isShapeToMesh; }
102   /*!
103    * \brief Return a solid which is returned by GetShapeToMesh() if
104    *        a real geometry to be meshed was not set
105    */
106   static const TopoDS_Solid& PseudoShape();
107
108
109   int UNVToMesh(const char* theFileName);
110   /*!
111    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
112    */
113   int MEDToMesh(const char* theFileName, const char* theMeshName);
114   
115   int STLToMesh(const char* theFileName);
116
117   SMESH_Hypothesis::Hypothesis_Status
118   AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
119     throw(SALOME_Exception);
120   
121   SMESH_Hypothesis::Hypothesis_Status
122   RemoveHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
123     throw(SALOME_Exception);
124   
125   const list <const SMESHDS_Hypothesis * >&
126   GetHypothesisList(const TopoDS_Shape & aSubShape) const
127     throw(SALOME_Exception);
128
129   const SMESH_Hypothesis * GetHypothesis(const TopoDS_Shape &    aSubShape,
130                                          const SMESH_HypoFilter& aFilter,
131                                          const bool              andAncestors) const;
132   
133   int GetHypotheses(const TopoDS_Shape &                aSubShape,
134                     const SMESH_HypoFilter&             aFilter,
135                     list <const SMESHDS_Hypothesis * >& aHypList,
136                     const bool                          andAncestors) const;
137
138   const list<SMESHDS_Command*> & GetLog() throw(SALOME_Exception);
139   
140   void ClearLog() throw(SALOME_Exception);
141   
142   int GetId()                { return _id; }
143   
144   SMESHDS_Mesh * GetMeshDS() { return _myMeshDS; }
145   
146   SMESH_Gen *GetGen()        { return _gen; }
147   
148   SMESH_subMesh *GetSubMesh(const TopoDS_Shape & aSubShape)
149     throw(SALOME_Exception);
150   
151   SMESH_subMesh *GetSubMeshContaining(const TopoDS_Shape & aSubShape)
152     throw(SALOME_Exception);
153   
154   SMESH_subMesh *GetSubMeshContaining(const int aShapeID)
155     throw(SALOME_Exception);
156   
157   void NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp);
158   // Say all submeshes that theChangedHyp has been modified
159
160   const list < SMESH_subMesh * >&
161   GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
162     throw(SALOME_Exception);
163   
164   bool IsUsedHypothesis(SMESHDS_Hypothesis *  anHyp,
165                         const SMESH_subMesh * aSubMesh);
166   // Return True if anHyp is used to mesh aSubShape
167   
168   bool IsNotConformAllowed() const;
169   // check if a hypothesis alowing notconform mesh is present
170   
171   bool IsMainShape(const TopoDS_Shape& theShape) const;
172
173   const TopTools_ListOfShape& GetAncestors(const TopoDS_Shape& theSubShape) const;
174   // return list of ancestors of theSubShape in the order
175   // that lower dimention shapes come first.
176
177   /*! Check group names for duplications.
178    *  Consider maximum group name length stored in MED file.
179    */
180   bool HasDuplicatedGroupNamesMED();
181
182   void ExportMED(const char *file, 
183                  const char* theMeshName = NULL, 
184                  bool theAutoGroups = true, 
185                  int theVersion = 0) 
186     throw(SALOME_Exception);
187
188   void ExportDAT(const char *file) throw(SALOME_Exception);
189   void ExportUNV(const char *file) throw(SALOME_Exception);
190   void ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception);
191   
192   int NbNodes() throw(SALOME_Exception);
193   
194   /*!
195    * ElementOrder points out entities of what order are requested
196    */
197   enum ElementOrder {
198     ORDER_ANY,          /*! entities of any order */
199     ORDER_LINEAR,       /*! entities of 1st order */
200     ORDER_QUADRATIC     /*! entities of 2nd order */
201   };
202
203   int NbEdges(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
204   
205   int NbFaces(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
206   
207   int NbTriangles(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
208   
209   int NbQuadrangles(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
210
211   int NbPolygons() throw(SALOME_Exception);
212   
213   int NbVolumes(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
214   
215   int NbTetras(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
216   
217   int NbHexas(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
218   
219   int NbPyramids(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
220
221   int NbPrisms(ElementOrder order = ORDER_ANY) throw(SALOME_Exception);
222   
223   int NbPolyhedrons() throw(SALOME_Exception);
224   
225   int NbSubMesh() throw(SALOME_Exception);
226   
227   int NbGroup() const { return _mapGroup.size(); }
228   
229   SMESH_Group* AddGroup (const SMDSAbs_ElementType theType,
230                          const char*               theName,
231                          int&                      theId,
232                          const TopoDS_Shape&       theShape=TopoDS_Shape());
233   
234   SMESH_Group* GetGroup (const int theGroupID);
235   
236   list<int> GetGroupIds();
237   
238   void RemoveGroup (const int theGroupID);
239
240   // Propagation hypothesis management
241
242   const SMESH_Hypothesis* IsLocal1DHypothesis (const TopoDS_Shape& theEdge);
243   // Returns a local 1D hypothesis used for theEdge.
244
245   bool IsPropagationHypothesis (const TopoDS_Shape& theEdge);
246   // Returns true, if a local Propagation hypothesis is set directly on <theEdge>
247
248   bool IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
249                                TopoDS_Shape&       theMainEdge);
250   // Returns true, if a local 1D hypothesis is
251   // propagated on <theEdge> from some other edge.
252   // Returns through <theMainEdge> the edge, from
253   // which the 1D hypothesis is propagated on <theEdge>
254
255   bool IsReversedInChain (const TopoDS_Shape& theEdge,
256                           const TopoDS_Shape& theMainEdge);
257   // Returns true if theEdge should be reversed to be
258   // co-directed with theMainEdge
259
260   bool RebuildPropagationChains();
261   bool RemovePropagationChain (const TopoDS_Shape& theMainEdge);
262   bool BuildPropagationChain (const TopoDS_Shape& theMainEdge);
263   
264   SMDSAbs_ElementType GetElementType( const int id, const bool iselem );
265
266   //
267   
268   ostream& Dump(ostream & save);
269   
270 private:
271   // Propagation hypothesis management
272   void CleanMeshOnPropagationChain(const TopoDS_Shape& theMainEdge);
273   //
274   
275 protected:
276   int                        _id;           // id given by creator (unique within the creator instance)
277   int                        _studyId;
278   int                        _idDoc;        // id given by SMESHDS_Document
279   int                        _groupId;      // id generator for group objects
280   bool                       _isShapeToMesh;// set to true when a shape is given (only once)
281   list <SMESH_subMesh *>     _subMeshesUsingHypothesisList;
282   SMESHDS_Document *         _myDocument;
283   SMESHDS_Mesh *             _myMeshDS;
284   map <int, SMESH_subMesh *> _mapSubMesh;
285   map <int, SMESH_Group *>   _mapGroup;
286   SMESH_Gen *                _gen;
287   
288   TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;
289
290   IndexedMapOfChain _mapPropagationChains; // Propagation hypothesis management
291
292 protected:
293   SMESH_Mesh() {};
294   SMESH_Mesh(const SMESH_Mesh&) {};
295 };
296
297 #endif