Salome HOME
Issue 0020514: EDF 1110 SMESH : Export many meshes in one Med File
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 //  File   : SMESH_Mesh_i.hxx
24 //  Author : Paul RASCLE, EDF
25 //  Module : SMESH
26 //
27 #ifndef _SMESH_MESH_I_HXX_
28 #define _SMESH_MESH_I_HXX_
29
30 #include "SMESH.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_I_EXPORT 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   void Clear()
76     throw (SALOME::SALOME_Exception);
77
78   void ClearSubMesh(CORBA::Long ShapeID)
79     throw (SALOME::SALOME_Exception);
80
81   SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
82                                          SMESH::SMESH_Hypothesis_ptr anHyp)
83     throw (SALOME::SALOME_Exception);
84
85   SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
86                                             SMESH::SMESH_Hypothesis_ptr anHyp)
87     throw (SALOME::SALOME_Exception);
88
89   SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
90     throw (SALOME::SALOME_Exception);
91
92   SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject, const char* theName)
93     throw (SALOME::SALOME_Exception);
94
95   void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
96     throw (SALOME::SALOME_Exception);
97
98   SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName )
99     throw (SALOME::SALOME_Exception);
100   
101   SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType    theElemType,
102                                                    const char*           theName,
103                                                    GEOM::GEOM_Object_ptr theGeomObj )
104     throw (SALOME::SALOME_Exception);
105
106   void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
107     throw (SALOME::SALOME_Exception);
108   
109   void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
110     throw (SALOME::SALOME_Exception);
111   
112   SMESH::ListOfGroups* GetGroups()
113     throw (SALOME::SALOME_Exception);
114
115   CORBA::Long NbGroups()
116     throw (SALOME::SALOME_Exception);
117
118   SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
119                                       SMESH::SMESH_GroupBase_ptr theGroup2, 
120                                       const char* theName )
121     throw (SALOME::SALOME_Exception);
122
123   SMESH::SMESH_Group_ptr UnionListOfGroups( const SMESH::ListOfGroups& theGroups, 
124                                             const char* theName)
125     throw (SALOME::SALOME_Exception);
126   
127   SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
128                                           SMESH::SMESH_GroupBase_ptr theGroup2, 
129                                           const char* theName )
130     throw (SALOME::SALOME_Exception);
131
132   SMESH::SMESH_Group_ptr IntersectListOfGroups( const SMESH::ListOfGroups&  theGroups, 
133                                                 const char* theName )
134     throw (SALOME::SALOME_Exception);
135   
136   SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
137                                     SMESH::SMESH_GroupBase_ptr theGroup2, 
138                                     const char* theName )
139     throw (SALOME::SALOME_Exception);
140
141   SMESH::SMESH_Group_ptr CutListOfGroups( const SMESH::ListOfGroups& theMainGroups, 
142                                           const SMESH::ListOfGroups& theToolGroups, 
143                                           const char* theName )
144   throw (SALOME::SALOME_Exception);
145
146   SMESH::SMESH_Group_ptr CreateDimGroup( const SMESH::ListOfGroups& theGroups, 
147                                          SMESH::ElementType theElemType, 
148                                          const char* theName )
149   throw (SALOME::SALOME_Exception);
150   
151
152   SMESH::SMESH_Group_ptr ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGeomGroup );
153
154 //    SMESH::string_array* GetLog(CORBA::Boolean clearAfterGet)
155 //      throw (SALOME::SALOME_Exception);
156
157   SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet)
158     throw (SALOME::SALOME_Exception);
159
160   SMESH::SMESH_MeshEditor_ptr GetMeshEditor();
161
162   SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer();
163
164   void ClearLog()
165     throw (SALOME::SALOME_Exception);
166
167   CORBA::Long GetId()
168     throw (SALOME::SALOME_Exception);
169
170   CORBA::Long GetStudyId()
171     throw (SALOME::SALOME_Exception);
172
173   // --- C++ interface
174   void SetImpl(::SMESH_Mesh* impl);
175   ::SMESH_Mesh& GetImpl();         // :: force no namespace here
176
177   SMESH_Gen_i* GetGen() { return _gen_i; }
178
179   int ImportUNVFile( const char* theFileName )
180     throw (SALOME::SALOME_Exception);
181
182   int ImportSTLFile( const char* theFileName )
183     throw (SALOME::SALOME_Exception);
184
185   /*!
186    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
187    */
188   SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName )
189     throw (SALOME::SALOME_Exception);
190
191   /*!
192    *  Auto color
193    */
194   void SetAutoColor(CORBA::Boolean theAutoColor)
195     throw (SALOME::SALOME_Exception);
196
197   CORBA::Boolean GetAutoColor()
198     throw (SALOME::SALOME_Exception);
199
200   /*! Check group names for duplications.
201    *  Consider maximum group name length stored in MED file.
202    */
203   CORBA::Boolean HasDuplicatedGroupNamesMED();
204   /*!
205    * Return string representation of a MED file version comprising nbDigits
206    */
207   char* GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits);
208
209   void ExportToMEDX( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion, CORBA::Boolean overwrite )
210     throw (SALOME::SALOME_Exception);
211   void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion )
212     throw (SALOME::SALOME_Exception);
213   void ExportMED( const char* file, CORBA::Boolean auto_groups )
214     throw (SALOME::SALOME_Exception);
215
216   void ExportDAT( const char* file )
217     throw (SALOME::SALOME_Exception);
218   void ExportUNV( const char* file )
219     throw (SALOME::SALOME_Exception);
220   void ExportSTL( const char* file, bool isascii )
221     throw (SALOME::SALOME_Exception);
222
223   SALOME_MED::MESH_ptr GetMEDMesh()
224     throw (SALOME::SALOME_Exception);
225
226   CORBA::Long NbNodes()
227     throw (SALOME::SALOME_Exception);
228
229   CORBA::Long NbElements()
230     throw (SALOME::SALOME_Exception);
231
232   CORBA::Long Nb0DElements()
233     throw (SALOME::SALOME_Exception);
234
235   CORBA::Long NbEdges()
236     throw (SALOME::SALOME_Exception);
237
238   CORBA::Long NbEdgesOfOrder(SMESH::ElementOrder order)
239     throw (SALOME::SALOME_Exception);
240
241   CORBA::Long NbFaces()
242     throw (SALOME::SALOME_Exception);
243
244   CORBA::Long NbFacesOfOrder(SMESH::ElementOrder order)
245     throw (SALOME::SALOME_Exception);
246
247   CORBA::Long NbTriangles()
248     throw (SALOME::SALOME_Exception);
249
250   CORBA::Long NbTrianglesOfOrder(SMESH::ElementOrder order)
251     throw (SALOME::SALOME_Exception);
252
253   CORBA::Long NbQuadrangles()
254     throw (SALOME::SALOME_Exception);
255
256   CORBA::Long NbQuadranglesOfOrder(SMESH::ElementOrder order)
257     throw (SALOME::SALOME_Exception);
258
259   CORBA::Long NbPolygons()
260     throw (SALOME::SALOME_Exception);
261
262   CORBA::Long NbVolumes()
263     throw (SALOME::SALOME_Exception);
264
265   CORBA::Long NbVolumesOfOrder(SMESH::ElementOrder order)
266     throw (SALOME::SALOME_Exception);
267
268   CORBA::Long NbTetras()
269     throw (SALOME::SALOME_Exception);
270
271   CORBA::Long NbTetrasOfOrder(SMESH::ElementOrder order)
272     throw (SALOME::SALOME_Exception);
273
274   CORBA::Long NbHexas()
275     throw (SALOME::SALOME_Exception);
276
277   CORBA::Long NbHexasOfOrder(SMESH::ElementOrder order)
278     throw (SALOME::SALOME_Exception);
279
280   CORBA::Long NbPyramids()
281     throw (SALOME::SALOME_Exception);
282
283   CORBA::Long NbPyramidsOfOrder(SMESH::ElementOrder order)
284     throw (SALOME::SALOME_Exception);
285
286   CORBA::Long NbPrisms()
287     throw (SALOME::SALOME_Exception);
288
289   CORBA::Long NbPrismsOfOrder(SMESH::ElementOrder order)
290     throw (SALOME::SALOME_Exception);
291
292   CORBA::Long NbPolyhedrons()
293     throw (SALOME::SALOME_Exception);
294
295   CORBA::Long NbSubMesh()
296     throw (SALOME::SALOME_Exception);
297
298   SMESH::long_array* GetElementsId()
299     throw (SALOME::SALOME_Exception);
300
301   SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType )
302     throw (SALOME::SALOME_Exception);
303   
304   SMESH::long_array* GetNodesId()
305     throw (SALOME::SALOME_Exception);
306   
307   SMESH::ElementType GetElementType( CORBA::Long id, bool iselem )
308     throw (SALOME::SALOME_Exception);
309   
310   /*!
311    * Returns ID of elements for given submesh
312    */
313   SMESH::long_array* GetSubMeshElementsId(CORBA::Long ShapeID)
314     throw (SALOME::SALOME_Exception);
315
316   /*!
317    * Returns ID of nodes for given submesh
318    * If param all==true - returns all nodes, else -
319    * returns only nodes on shapes.
320    */
321   SMESH::long_array* GetSubMeshNodesId(CORBA::Long ShapeID, CORBA::Boolean all)
322     throw (SALOME::SALOME_Exception);
323   
324   /*!
325    * Returns type of elements for given submesh
326    */
327   SMESH::ElementType GetSubMeshElementType(CORBA::Long ShapeID)
328     throw (SALOME::SALOME_Exception);
329   
330   char* Dump();
331   
332   // Internal methods not available through CORBA
333   // They are called by corresponding interface methods
334   SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
335                                                     SMESH::SMESH_Hypothesis_ptr anHyp);
336
337   SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
338                                                        SMESH::SMESH_Hypothesis_ptr anHyp);
339   
340   static SMESH::Hypothesis_Status
341   ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
342
343   static void PrepareForWriting (const char* file, bool overwrite = true);
344
345   //int importMEDFile( const char* theFileName, const char* theMeshName );
346
347   SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
348
349   void removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
350                      GEOM::GEOM_Object_ptr theSubShapeObject );
351
352   SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType  theElemType,
353                                          const char*         theName,
354                                          const TopoDS_Shape& theShape = TopoDS_Shape());
355
356   void removeGroup( const int theId );
357
358   SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
359   // return an existing subMesh object for the shapeID. shapeID == submeshID.
360
361   const std::map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
362   // return an existing group object.
363
364   /*!
365    * \brief Update hypotheses assigned to geom groups if the latter change
366    * 
367    * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
368    */
369   void CheckGeomGroupModif();
370
371   virtual SMESH::long_array* GetIDs();
372
373   CORBA::LongLong GetMeshPtr();
374
375   /*!
376    * \brief Assure that all groups are published
377    */
378   void CreateGroupServants();
379
380   /*!
381    * \brief Return groups cantained in _mapGroups by their IDs
382    */
383   SMESH::ListOfGroups* GetGroups(const std::list<int>& groupIDs) const;
384
385   /*!
386    * Get XYZ coordinates of node as list of double
387    * If there is not node for given ID - returns empty list
388    */
389   SMESH::double_array* GetNodeXYZ(CORBA::Long id);
390   
391   /*!
392    * For given node returns list of IDs of inverse elements
393    * If there is not node for given ID - returns empty list
394    */
395   SMESH::long_array* GetNodeInverseElements(CORBA::Long id);
396
397   /*!
398    * \brief Return position of a node on shape
399    */
400   SMESH::NodePosition* GetNodePosition(CORBA::Long NodeID);
401
402   /*!
403    * If given element is node returns IDs of shape from position
404    * If there is not node for given ID - returns -1
405    */
406   CORBA::Long GetShapeID(CORBA::Long id);
407
408   /*!
409    * For given element returns ID of result shape after 
410    * ::FindShape() from SMESH_MeshEditor
411    * If there is not element for given ID - returns -1
412    */
413   CORBA::Long GetShapeIDForElem(CORBA::Long id);
414
415   /*!
416    * Returns number of nodes for given element
417    * If there is not element for given ID - returns -1
418    */
419   CORBA::Long GetElemNbNodes(CORBA::Long id);
420
421   /*!
422    * Returns IDs of nodes of given element
423    */
424   SMESH::long_array* GetElemNodes(CORBA::Long id);
425
426   /*!
427    * Returns ID of node by given index for given element
428    * If there is not element for given ID - returns -1
429    * If there is not node for given index - returns -2
430    */
431   CORBA::Long GetElemNode(CORBA::Long id, CORBA::Long index);
432   
433   /*!
434    * Returns true if given node is medium node
435    * in given quadratic element
436    */
437   CORBA::Boolean IsMediumNode(CORBA::Long ide, CORBA::Long idn);
438   
439   /*!
440    * Returns true if given node is medium node
441    * in one of quadratic elements
442    */
443   CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn,
444                                        SMESH::ElementType theElemType);
445   
446   /*!
447    * Returns number of edges for given element
448    */
449   CORBA::Long ElemNbEdges(CORBA::Long id);
450   
451   /*!
452    * Returns number of faces for given element
453    */
454   CORBA::Long ElemNbFaces(CORBA::Long id);
455   
456   /*!
457    * Returns true if given element is polygon
458    */
459   CORBA::Boolean IsPoly(CORBA::Long id);
460   
461   /*!
462    * Returns true if given element is quadratic
463    */
464   CORBA::Boolean IsQuadratic(CORBA::Long id);
465   
466   /*!
467    * Returns bary center for given element
468    */
469   SMESH::double_array* BaryCenter(CORBA::Long id);
470
471   /*!
472    * Returns information about imported MED file
473    */
474   virtual SALOME_MED::MedFileInfo* GetMEDFileInfo();
475
476   /*!
477    * Sets list of notebook variables used for Mesh operations separated by ":" symbol
478    */
479   void SetParameters (const char* theParameters);
480   
481   /*!
482    * Returns list of notebook variables used for Mesh operations separated by ":" symbol
483    */
484   char* GetParameters();
485
486   /*!
487    * Returns list of notebook variables used for last Mesh operation
488    */
489   SMESH::string_array* GetLastParameters();
490
491
492   /*!
493    * Returns statistic of mesh elements
494    * Result array of number enityties
495    * Inherited from SMESH_IDSource
496    */
497   virtual SMESH::long_array* GetMeshInfo();
498
499   /*!
500    * Collect statistic of mesh elements given by iterator
501    */
502   static void CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
503                               SMESH::long_array&         theInfo);
504                           
505
506   /*!
507    * \brief Return submesh objects list in meshing order
508    */
509   virtual SMESH::submesh_array_array* GetMeshOrder();
510   /*!
511    * \brief Set submesh object order
512    */
513   virtual ::CORBA::Boolean SetMeshOrder(const SMESH::submesh_array_array& theSubMeshArray);
514
515   
516   std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
517   std::map<int, ::SMESH_subMesh*> _mapSubMesh;   //NRI
518
519 private:
520   /*!
521    * Check and correct names of mesh groups
522    */
523   void checkGroupNames();
524
525   /*!
526    * Convert submesh ids into submesh interfaces
527    */
528   void convertMeshOrder(const TListOfListOfInt&     theIdsOrder,
529                         SMESH::submesh_array_array& theSubMeshOrder,
530                         const bool                  theIsDump);
531
532 private:
533
534   static int myIdGenerator;
535   ::SMESH_Mesh* _impl;  // :: force no namespace here
536   SMESH_Gen_i* _gen_i;
537   int _id;          // id given by creator (unique within the creator instance)
538   int _studyId;
539   std::map<int, SMESH::SMESH_subMesh_ptr>    _mapSubMeshIor;
540   std::map<int, SMESH::SMESH_GroupBase_ptr>  _mapGroups;
541   std::map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
542   SALOME_MED::MedFileInfo_var myFileInfo;
543
544 private:
545
546   // Data used to track changes of GEOM groups
547   struct TGeomGroupData {
548     // keep study entry and not ior because GEOM_Object actually changes if
549     // number of items in a group varies (1) <-> (>1)
550     std::string       _groupEntry;
551     std::set<int>     _indices; // indices of group items within group's main shape
552     CORBA::Object_ptr _smeshObject; // SMESH object depending on GEOM group
553   };
554   std::list<TGeomGroupData> _geomGroupData;
555
556   /*!
557    * Remember GEOM group data
558    */
559   void addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
560                         CORBA::Object_ptr     theSmeshObj);
561   /*!
562    * Remove GEOM group data relating to removed smesh object
563    */
564   void removeGeomGroupData(CORBA::Object_ptr theSmeshObj);
565   /*!
566    * \brief Return new group contents if it has been changed and update group data
567    */
568   TopoDS_Shape newGroupShape( TGeomGroupData & groupData);
569   
570 };
571
572 #endif
573