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