Salome HOME
IMP19942 - Convert group on geometry into group of elements
[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   void Clear()
78     throw (SALOME::SALOME_Exception);
79
80   void ClearSubMesh(CORBA::Long ShapeID)
81     throw (SALOME::SALOME_Exception);
82
83   SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
84                                          SMESH::SMESH_Hypothesis_ptr anHyp)
85     throw (SALOME::SALOME_Exception);
86
87   SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
88                                             SMESH::SMESH_Hypothesis_ptr anHyp)
89     throw (SALOME::SALOME_Exception);
90
91   SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
92     throw (SALOME::SALOME_Exception);
93
94   SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject, const char* theName)
95     throw (SALOME::SALOME_Exception);
96
97   void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
98     throw (SALOME::SALOME_Exception);
99
100   SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName )
101     throw (SALOME::SALOME_Exception);
102   
103   SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType    theElemType,
104                                                    const char*           theName,
105                                                    GEOM::GEOM_Object_ptr theGeomObj )
106     throw (SALOME::SALOME_Exception);
107
108   void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
109     throw (SALOME::SALOME_Exception);
110   
111   void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
112     throw (SALOME::SALOME_Exception);
113   
114   SMESH::ListOfGroups* GetGroups()
115     throw (SALOME::SALOME_Exception);
116
117   CORBA::Long NbGroups()
118     throw (SALOME::SALOME_Exception);
119
120   SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
121                                       SMESH::SMESH_GroupBase_ptr theGroup2, 
122                                       const char* theName )
123     throw (SALOME::SALOME_Exception);
124
125   SMESH::SMESH_Group_ptr UnionListOfGroups( const SMESH::ListOfGroups& theGroups, 
126                                             const char* theName)
127     throw (SALOME::SALOME_Exception);
128   
129   SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
130                                           SMESH::SMESH_GroupBase_ptr theGroup2, 
131                                           const char* theName )
132     throw (SALOME::SALOME_Exception);
133
134   SMESH::SMESH_Group_ptr IntersectListOfGroups( const SMESH::ListOfGroups&  theGroups, 
135                                                 const char* theName )
136     throw (SALOME::SALOME_Exception);
137   
138   SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
139                                     SMESH::SMESH_GroupBase_ptr theGroup2, 
140                                     const char* theName )
141     throw (SALOME::SALOME_Exception);
142
143   SMESH::SMESH_Group_ptr CutListOfGroups( const SMESH::ListOfGroups& theMainGroups, 
144                                           const SMESH::ListOfGroups& theToolGroups, 
145                                           const char* theName )
146   throw (SALOME::SALOME_Exception);
147
148   SMESH::SMESH_Group_ptr CreateDimGroup( const SMESH::ListOfGroups& theGroups, 
149                                          SMESH::ElementType theElemType, 
150                                          const char* theName )
151   throw (SALOME::SALOME_Exception);
152   
153
154   SMESH::SMESH_Group_ptr ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGeomGroup );
155
156 //    SMESH::string_array* GetLog(CORBA::Boolean clearAfterGet)
157 //      throw (SALOME::SALOME_Exception);
158
159   SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet)
160     throw (SALOME::SALOME_Exception);
161
162   SMESH::SMESH_MeshEditor_ptr GetMeshEditor();
163
164   SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer();
165
166   void ClearLog()
167     throw (SALOME::SALOME_Exception);
168
169   CORBA::Long GetId()
170     throw (SALOME::SALOME_Exception);
171
172   CORBA::Long GetStudyId()
173     throw (SALOME::SALOME_Exception);
174
175   // --- C++ interface
176   void SetImpl(::SMESH_Mesh* impl);
177   ::SMESH_Mesh& GetImpl();         // :: force no namespace here
178
179   SMESH_Gen_i* GetGen() { return _gen_i; }
180
181   int ImportUNVFile( const char* theFileName )
182     throw (SALOME::SALOME_Exception);
183
184   int ImportSTLFile( const char* theFileName )
185     throw (SALOME::SALOME_Exception);
186
187   /*!
188    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
189    */
190   SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName )
191     throw (SALOME::SALOME_Exception);
192
193   /*!
194    *  Auto color
195    */
196   void SetAutoColor(CORBA::Boolean theAutoColor)
197     throw (SALOME::SALOME_Exception);
198
199   CORBA::Boolean GetAutoColor()
200     throw (SALOME::SALOME_Exception);
201
202   /*! Check group names for duplications.
203    *  Consider maximum group name length stored in MED file.
204    */
205   CORBA::Boolean HasDuplicatedGroupNamesMED();
206   /*!
207    * Return string representation of a MED file version comprising nbDigits
208    */
209   char* GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits);
210
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 NbEdges()
233     throw (SALOME::SALOME_Exception);
234
235   CORBA::Long NbEdgesOfOrder(SMESH::ElementOrder order)
236     throw (SALOME::SALOME_Exception);
237
238   CORBA::Long NbFaces()
239     throw (SALOME::SALOME_Exception);
240
241   CORBA::Long NbFacesOfOrder(SMESH::ElementOrder order)
242     throw (SALOME::SALOME_Exception);
243
244   CORBA::Long NbTriangles()
245     throw (SALOME::SALOME_Exception);
246
247   CORBA::Long NbTrianglesOfOrder(SMESH::ElementOrder order)
248     throw (SALOME::SALOME_Exception);
249
250   CORBA::Long NbQuadrangles()
251     throw (SALOME::SALOME_Exception);
252
253   CORBA::Long NbQuadranglesOfOrder(SMESH::ElementOrder order)
254     throw (SALOME::SALOME_Exception);
255
256   CORBA::Long NbPolygons()
257     throw (SALOME::SALOME_Exception);
258
259   CORBA::Long NbVolumes()
260     throw (SALOME::SALOME_Exception);
261
262   CORBA::Long NbVolumesOfOrder(SMESH::ElementOrder order)
263     throw (SALOME::SALOME_Exception);
264
265   CORBA::Long NbTetras()
266     throw (SALOME::SALOME_Exception);
267
268   CORBA::Long NbTetrasOfOrder(SMESH::ElementOrder order)
269     throw (SALOME::SALOME_Exception);
270
271   CORBA::Long NbHexas()
272     throw (SALOME::SALOME_Exception);
273
274   CORBA::Long NbHexasOfOrder(SMESH::ElementOrder order)
275     throw (SALOME::SALOME_Exception);
276
277   CORBA::Long NbPyramids()
278     throw (SALOME::SALOME_Exception);
279
280   CORBA::Long NbPyramidsOfOrder(SMESH::ElementOrder order)
281     throw (SALOME::SALOME_Exception);
282
283   CORBA::Long NbPrisms()
284     throw (SALOME::SALOME_Exception);
285
286   CORBA::Long NbPrismsOfOrder(SMESH::ElementOrder order)
287     throw (SALOME::SALOME_Exception);
288
289   CORBA::Long NbPolyhedrons()
290     throw (SALOME::SALOME_Exception);
291
292   CORBA::Long NbSubMesh()
293     throw (SALOME::SALOME_Exception);
294
295   SMESH::long_array* GetElementsId()
296     throw (SALOME::SALOME_Exception);
297
298   SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType )
299     throw (SALOME::SALOME_Exception);
300   
301   SMESH::long_array* GetNodesId()
302     throw (SALOME::SALOME_Exception);
303   
304   SMESH::ElementType GetElementType( CORBA::Long id, bool iselem )
305     throw (SALOME::SALOME_Exception);
306   
307   /*!
308    * Returns ID of elements for given submesh
309    */
310   SMESH::long_array* GetSubMeshElementsId(CORBA::Long ShapeID)
311     throw (SALOME::SALOME_Exception);
312
313   /*!
314    * Returns ID of nodes for given submesh
315    * If param all==true - returns all nodes, else -
316    * returns only nodes on shapes.
317    */
318   SMESH::long_array* GetSubMeshNodesId(CORBA::Long ShapeID, CORBA::Boolean all)
319     throw (SALOME::SALOME_Exception);
320   
321   /*!
322    * Returns type of elements for given submesh
323    */
324   SMESH::ElementType GetSubMeshElementType(CORBA::Long ShapeID)
325     throw (SALOME::SALOME_Exception);
326   
327   char* Dump();
328   
329   // Internal methods not available through CORBA
330   // They are called by corresponding interface methods
331   SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
332                                                     SMESH::SMESH_Hypothesis_ptr anHyp);
333
334   SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
335                                                        SMESH::SMESH_Hypothesis_ptr anHyp);
336   
337   static SMESH::Hypothesis_Status
338   ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
339
340   static void PrepareForWriting (const char* file);
341
342   //int importMEDFile( const char* theFileName, const char* theMeshName );
343
344   SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
345
346   void removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
347                      GEOM::GEOM_Object_ptr theSubShapeObject );
348
349   SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType  theElemType,
350                                          const char*         theName,
351                                          const TopoDS_Shape& theShape = TopoDS_Shape());
352
353   void removeGroup( const int theId );
354
355   SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
356   // return an existing subMesh object for the shapeID. shapeID == submeshID.
357
358   const std::map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
359   // return an existing group object.
360
361   /*!
362    * \brief Update hypotheses assigned to geom groups if the latter change
363    * 
364    * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
365    */
366   void CheckGeomGroupModif();
367
368   virtual SMESH::long_array* GetIDs();
369
370   CORBA::LongLong GetMeshPtr();
371
372   /*!
373    * \brief Assure that all groups are published
374    */
375   void CreateGroupServants();
376
377   /*!
378    * \brief Return groups cantained in _mapGroups by their IDs
379    */
380   SMESH::ListOfGroups* GetGroups(const std::list<int>& groupIDs) const;
381
382   /*!
383    * Get XYZ coordinates of node as list of double
384    * If there is not node for given ID - returns empty list
385    */
386   SMESH::double_array* GetNodeXYZ(CORBA::Long id);
387   
388   /*!
389    * For given node returns list of IDs of inverse elements
390    * If there is not node for given ID - returns empty list
391    */
392   SMESH::long_array* GetNodeInverseElements(CORBA::Long id);
393
394   /*!
395    * \brief Return position of a node on shape
396    */
397   SMESH::NodePosition* GetNodePosition(CORBA::Long NodeID);
398
399   /*!
400    * If given element is node returns IDs of shape from position
401    * If there is not node for given ID - returns -1
402    */
403   CORBA::Long GetShapeID(CORBA::Long id);
404
405   /*!
406    * For given element returns ID of result shape after 
407    * ::FindShape() from SMESH_MeshEditor
408    * If there is not element for given ID - returns -1
409    */
410   CORBA::Long GetShapeIDForElem(CORBA::Long id);
411
412   /*!
413    * Returns number of nodes for given element
414    * If there is not element for given ID - returns -1
415    */
416   CORBA::Long GetElemNbNodes(CORBA::Long id);
417
418   /*!
419    * Returns IDs of nodes of given element
420    */
421   SMESH::long_array* GetElemNodes(CORBA::Long id);
422
423   /*!
424    * Returns ID of node by given index for given element
425    * If there is not element for given ID - returns -1
426    * If there is not node for given index - returns -2
427    */
428   CORBA::Long GetElemNode(CORBA::Long id, CORBA::Long index);
429   
430   /*!
431    * Returns true if given node is medium node
432    * in given quadratic element
433    */
434   CORBA::Boolean IsMediumNode(CORBA::Long ide, CORBA::Long idn);
435   
436   /*!
437    * Returns true if given node is medium node
438    * in one of quadratic elements
439    */
440   CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn,
441                                        SMESH::ElementType theElemType);
442   
443   /*!
444    * Returns number of edges for given element
445    */
446   CORBA::Long ElemNbEdges(CORBA::Long id);
447   
448   /*!
449    * Returns number of faces for given element
450    */
451   CORBA::Long ElemNbFaces(CORBA::Long id);
452   
453   /*!
454    * Returns true if given element is polygon
455    */
456   CORBA::Boolean IsPoly(CORBA::Long id);
457   
458   /*!
459    * Returns true if given element is quadratic
460    */
461   CORBA::Boolean IsQuadratic(CORBA::Long id);
462   
463   /*!
464    * Returns bary center for given element
465    */
466   SMESH::double_array* BaryCenter(CORBA::Long id);
467
468   /*!
469    * Returns information about imported MED file
470    */
471   virtual SALOME_MED::MedFileInfo* GetMEDFileInfo();
472
473   std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
474   std::map<int, ::SMESH_subMesh*> _mapSubMesh;   //NRI
475
476 private:
477   /*!
478    * Check and correct names of mesh groups
479    */
480   void checkGroupNames();
481
482 private:
483
484   static int myIdGenerator;
485   ::SMESH_Mesh* _impl;  // :: force no namespace here
486   SMESH_Gen_i* _gen_i;
487   int _id;          // id given by creator (unique within the creator instance)
488   int _studyId;
489   std::map<int, SMESH::SMESH_subMesh_ptr>    _mapSubMeshIor;
490   std::map<int, SMESH::SMESH_GroupBase_ptr>  _mapGroups;
491   std::map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
492   SALOME_MED::MedFileInfo_var myFileInfo;
493 };
494
495 #endif
496