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