Salome HOME
PAL16631 (SALOME crash after a mesh computation failed due to lack of memory)
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.hxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
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_i.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef _SMESH_MESH_I_HXX_
30 #define _SMESH_MESH_I_HXX_
31
32 #include "SMESH.hxx"
33
34 #include <SALOMEconfig.h>
35 #include CORBA_SERVER_HEADER(SMESH_Mesh)
36 #include CORBA_SERVER_HEADER(SMESH_Group)
37 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
38 #include CORBA_CLIENT_HEADER(GEOM_Gen)
39 #include CORBA_CLIENT_HEADER(MED)
40
41 #include "SMESH_Hypothesis.hxx"
42 #include "SMESH_Mesh.hxx"
43 //#include "SMESH_subMesh_i.hxx"
44 #include "SMESH_subMesh.hxx"
45
46 #include "SALOME_GenericObj_i.hh"
47
48 class SMESH_Gen_i;
49 class SMESH_GroupBase_i;
50 class SMESH_subMesh_i;
51
52 #include <map>
53
54 class SMESH_I_EXPORT SMESH_Mesh_i:
55   public virtual POA_SMESH::SMESH_Mesh,
56   public virtual SALOME::GenericObj_i
57 {
58   SMESH_Mesh_i();
59   SMESH_Mesh_i(const SMESH_Mesh_i&);
60 public:
61   SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
62                 SMESH_Gen_i*            myGen_i,
63                 CORBA::Long             studyId );
64
65   virtual ~SMESH_Mesh_i();
66
67   // --- CORBA
68   void SetShape( GEOM::GEOM_Object_ptr theShapeObject )
69     throw (SALOME::SALOME_Exception);
70
71   CORBA::Boolean HasShapeToMesh()
72     throw (SALOME::SALOME_Exception);
73
74   GEOM::GEOM_Object_ptr GetShapeToMesh()
75     throw (SALOME::SALOME_Exception);
76
77   SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
78                                          SMESH::SMESH_Hypothesis_ptr anHyp)
79     throw (SALOME::SALOME_Exception);
80
81   SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
82                                             SMESH::SMESH_Hypothesis_ptr anHyp)
83     throw (SALOME::SALOME_Exception);
84
85   SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
86     throw (SALOME::SALOME_Exception);
87
88   SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject, const char* theName)
89     throw (SALOME::SALOME_Exception);
90
91   void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
92     throw (SALOME::SALOME_Exception);
93
94   SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName )
95     throw (SALOME::SALOME_Exception);
96   
97   SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType    theElemType,
98                                                    const char*           theName,
99                                                    GEOM::GEOM_Object_ptr theGeomObj )
100     throw (SALOME::SALOME_Exception);
101
102   void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
103     throw (SALOME::SALOME_Exception);
104   
105   void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
106     throw (SALOME::SALOME_Exception);
107   
108   SMESH::ListOfGroups* GetGroups()
109     throw (SALOME::SALOME_Exception);
110
111   SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
112                                       SMESH::SMESH_GroupBase_ptr theGroup2, 
113                                       const char* theName )
114     throw (SALOME::SALOME_Exception);
115   
116   SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
117                                           SMESH::SMESH_GroupBase_ptr theGroup2, 
118                                           const char* theName )
119     throw (SALOME::SALOME_Exception);
120   
121   SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
122                                     SMESH::SMESH_GroupBase_ptr theGroup2, 
123                                    const char* theName )
124     throw (SALOME::SALOME_Exception);
125
126 //    SMESH::string_array* GetLog(CORBA::Boolean clearAfterGet)
127 //      throw (SALOME::SALOME_Exception);
128
129   SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet)
130     throw (SALOME::SALOME_Exception);
131
132   SMESH::SMESH_MeshEditor_ptr GetMeshEditor();
133
134   SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer();
135
136   void ClearLog()
137     throw (SALOME::SALOME_Exception);
138
139   CORBA::Long GetId()
140     throw (SALOME::SALOME_Exception);
141
142   CORBA::Long GetStudyId()
143     throw (SALOME::SALOME_Exception);
144
145   // --- C++ interface
146   void SetImpl(::SMESH_Mesh* impl);
147   ::SMESH_Mesh& GetImpl();         // :: force no namespace here
148
149   SMESH_Gen_i* GetGen() { return _gen_i; }
150
151   int ImportUNVFile( const char* theFileName )
152     throw (SALOME::SALOME_Exception);
153
154   int ImportSTLFile( const char* theFileName )
155     throw (SALOME::SALOME_Exception);
156
157   /*!
158    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
159    */
160   SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName )
161     throw (SALOME::SALOME_Exception);
162
163   /*! Check group names for duplications.
164    *  Consider maximum group name length stored in MED file.
165    */
166   CORBA::Boolean HasDuplicatedGroupNamesMED();
167
168   void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion )
169     throw (SALOME::SALOME_Exception);
170   void ExportMED( const char* file, CORBA::Boolean auto_groups )
171     throw (SALOME::SALOME_Exception);
172
173   void ExportDAT( const char* file )
174     throw (SALOME::SALOME_Exception);
175   void ExportUNV( const char* file )
176     throw (SALOME::SALOME_Exception);
177   void ExportSTL( const char* file, bool isascii )
178     throw (SALOME::SALOME_Exception);
179
180   SALOME_MED::MESH_ptr GetMEDMesh()
181     throw (SALOME::SALOME_Exception);
182
183   CORBA::Long NbNodes()
184     throw (SALOME::SALOME_Exception);
185
186   CORBA::Long NbElements()
187     throw (SALOME::SALOME_Exception);
188
189   CORBA::Long NbEdges()
190     throw (SALOME::SALOME_Exception);
191
192   CORBA::Long NbEdgesOfOrder(SMESH::ElementOrder order)
193     throw (SALOME::SALOME_Exception);
194
195   CORBA::Long NbFaces()
196     throw (SALOME::SALOME_Exception);
197
198   CORBA::Long NbFacesOfOrder(SMESH::ElementOrder order)
199     throw (SALOME::SALOME_Exception);
200
201   CORBA::Long NbTriangles()
202     throw (SALOME::SALOME_Exception);
203
204   CORBA::Long NbTrianglesOfOrder(SMESH::ElementOrder order)
205     throw (SALOME::SALOME_Exception);
206
207   CORBA::Long NbQuadrangles()
208     throw (SALOME::SALOME_Exception);
209
210   CORBA::Long NbQuadranglesOfOrder(SMESH::ElementOrder order)
211     throw (SALOME::SALOME_Exception);
212
213   CORBA::Long NbPolygons()
214     throw (SALOME::SALOME_Exception);
215
216   CORBA::Long NbVolumes()
217     throw (SALOME::SALOME_Exception);
218
219   CORBA::Long NbVolumesOfOrder(SMESH::ElementOrder order)
220     throw (SALOME::SALOME_Exception);
221
222   CORBA::Long NbTetras()
223     throw (SALOME::SALOME_Exception);
224
225   CORBA::Long NbTetrasOfOrder(SMESH::ElementOrder order)
226     throw (SALOME::SALOME_Exception);
227
228   CORBA::Long NbHexas()
229     throw (SALOME::SALOME_Exception);
230
231   CORBA::Long NbHexasOfOrder(SMESH::ElementOrder order)
232     throw (SALOME::SALOME_Exception);
233
234   CORBA::Long NbPyramids()
235     throw (SALOME::SALOME_Exception);
236
237   CORBA::Long NbPyramidsOfOrder(SMESH::ElementOrder order)
238     throw (SALOME::SALOME_Exception);
239
240   CORBA::Long NbPrisms()
241     throw (SALOME::SALOME_Exception);
242
243   CORBA::Long NbPrismsOfOrder(SMESH::ElementOrder order)
244     throw (SALOME::SALOME_Exception);
245
246   CORBA::Long NbPolyhedrons()
247     throw (SALOME::SALOME_Exception);
248
249   CORBA::Long NbSubMesh()
250     throw (SALOME::SALOME_Exception);
251
252   SMESH::long_array* GetElementsId()
253     throw (SALOME::SALOME_Exception);
254
255   SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType )
256     throw (SALOME::SALOME_Exception);
257   
258   SMESH::long_array* GetNodesId()
259     throw (SALOME::SALOME_Exception);
260   
261   SMESH::ElementType GetElementType( CORBA::Long id, bool iselem )
262     throw (SALOME::SALOME_Exception);
263   
264   /*!
265    * Returns ID of elements for given submesh
266    */
267   SMESH::long_array* GetSubMeshElementsId(CORBA::Long ShapeID)
268     throw (SALOME::SALOME_Exception);
269
270   /*!
271    * Returns ID of nodes for given submesh
272    * If param all==true - returns all nodes, else -
273    * returns only nodes on shapes.
274    */
275   SMESH::long_array* GetSubMeshNodesId(CORBA::Long ShapeID, CORBA::Boolean all)
276     throw (SALOME::SALOME_Exception);
277   
278   /*!
279    * Returns type of elements for given submesh
280    */
281   SMESH::ElementType GetSubMeshElementType(CORBA::Long ShapeID)
282     throw (SALOME::SALOME_Exception);
283   
284   char* Dump();
285   
286   // Internal methods not available through CORBA
287   // They are called by corresponding interface methods
288   SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
289                                                     SMESH::SMESH_Hypothesis_ptr anHyp);
290
291   SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
292                                                        SMESH::SMESH_Hypothesis_ptr anHyp);
293   
294   static SMESH::Hypothesis_Status
295   ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
296
297   int importMEDFile( const char* theFileName, const char* theMeshName );
298
299   SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
300
301   void removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
302                      GEOM::GEOM_Object_ptr theSubShapeObject );
303
304   SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType  theElemType,
305                                          const char*         theName,
306                                          const TopoDS_Shape& theShape = TopoDS_Shape());
307
308   void removeGroup( const int theId );
309
310   SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
311   // return an existing subMesh object for the shapeID. shapeID == submeshID.
312
313   const map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
314   // return an existing group object.
315
316   /*!
317    * \brief Update hypotheses assigned to geom groups if the latter change
318    * 
319    * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
320    */
321   void CheckGeomGroupModif();
322
323   virtual SMESH::long_array* GetIDs();
324
325   CORBA::LongLong GetMeshPtr();
326
327
328   /*!
329    * Get XYZ coordinates of node as list of double
330    * If there is not node for given ID - returns empty list
331    */
332   SMESH::double_array* GetNodeXYZ(CORBA::Long id);
333   
334   /*!
335    * For given node returns list of IDs of inverse elements
336    * If there is not node for given ID - returns empty list
337    */
338   SMESH::long_array* GetNodeInverseElements(CORBA::Long id);
339
340   /*!
341    * If given element is node returns IDs of shape from position
342    * If there is not node for given ID - returns -1
343    */
344   CORBA::Long GetShapeID(CORBA::Long id);
345
346   /*!
347    * For given element returns ID of result shape after 
348    * ::FindShape() from SMESH_MeshEditor
349    * If there is not element for given ID - returns -1
350    */
351   CORBA::Long GetShapeIDForElem(CORBA::Long id);
352
353   /*!
354    * Returns number of nodes for given element
355    * If there is not element for given ID - returns -1
356    */
357   CORBA::Long GetElemNbNodes(CORBA::Long id);
358
359   /*!
360    * Returns IDs of nodes of given element
361    */
362   SMESH::long_array* GetElemNodes(CORBA::Long id);
363
364   /*!
365    * Returns ID of node by given index for given element
366    * If there is not element for given ID - returns -1
367    * If there is not node for given index - returns -2
368    */
369   CORBA::Long GetElemNode(CORBA::Long id, CORBA::Long index);
370   
371   /*!
372    * Returns true if given node is medium node
373    * in given quadratic element
374    */
375   CORBA::Boolean IsMediumNode(CORBA::Long ide, CORBA::Long idn);
376   
377   /*!
378    * Returns true if given node is medium node
379    * in one of quadratic elements
380    */
381   CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn,
382                                        SMESH::ElementType theElemType);
383   
384   /*!
385    * Returns number of edges for given element
386    */
387   CORBA::Long ElemNbEdges(CORBA::Long id);
388   
389   /*!
390    * Returns number of faces for given element
391    */
392   CORBA::Long ElemNbFaces(CORBA::Long id);
393   
394   /*!
395    * Returns true if given element is polygon
396    */
397   CORBA::Boolean IsPoly(CORBA::Long id);
398   
399   /*!
400    * Returns true if given element is quadratic
401    */
402   CORBA::Boolean IsQuadratic(CORBA::Long id);
403   
404   /*!
405    * Returns bary center for given element
406    */
407   SMESH::double_array* BaryCenter(CORBA::Long id);
408
409
410   map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
411   map<int, ::SMESH_subMesh*> _mapSubMesh;   //NRI
412
413 private:
414   void CreateGroupServants();
415
416   static int myIdGenerator;
417   ::SMESH_Mesh* _impl;  // :: force no namespace here
418   SMESH_Gen_i* _gen_i;
419   int _id;          // id given by creator (unique within the creator instance)
420   int _studyId;
421   map<int, SMESH::SMESH_subMesh_ptr>    _mapSubMeshIor;
422   map<int, SMESH::SMESH_GroupBase_ptr>  _mapGroups;
423   map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
424 };
425
426 #endif
427