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