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