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