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