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