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