Salome HOME
3da2a523d93ee8060578475e091914952d0651e5
[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 <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
49 #include <map>
50
51 class 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   SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
75                                          SMESH::SMESH_Hypothesis_ptr anHyp)
76     throw (SALOME::SALOME_Exception);
77
78   SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
79                                             SMESH::SMESH_Hypothesis_ptr anHyp)
80     throw (SALOME::SALOME_Exception);
81
82   SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
83     throw (SALOME::SALOME_Exception);
84
85   SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject, const char* theName)
86     throw (SALOME::SALOME_Exception);
87
88   void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
89     throw (SALOME::SALOME_Exception);
90
91   SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName )
92     throw (SALOME::SALOME_Exception);
93   
94   SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType    theElemType,
95                                                    const char*           theName,
96                                                    GEOM::GEOM_Object_ptr theGeomObj )
97     throw (SALOME::SALOME_Exception);
98
99   void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
100     throw (SALOME::SALOME_Exception);
101   
102   void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
103     throw (SALOME::SALOME_Exception);
104   
105   SMESH::ListOfGroups* GetGroups()
106     throw (SALOME::SALOME_Exception);
107
108   SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
109                                       SMESH::SMESH_GroupBase_ptr theGroup2, 
110                                       const char* theName )
111     throw (SALOME::SALOME_Exception);
112   
113   SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
114                                           SMESH::SMESH_GroupBase_ptr theGroup2, 
115                                           const char* theName )
116     throw (SALOME::SALOME_Exception);
117   
118   SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
119                                     SMESH::SMESH_GroupBase_ptr theGroup2, 
120                                    const char* theName )
121     throw (SALOME::SALOME_Exception);
122
123 //    SMESH::string_array* GetLog(CORBA::Boolean clearAfterGet)
124 //      throw (SALOME::SALOME_Exception);
125
126   SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet)
127     throw (SALOME::SALOME_Exception);
128
129   SMESH::SMESH_MeshEditor_ptr GetMeshEditor();
130
131   SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer();
132
133   void ClearLog()
134     throw (SALOME::SALOME_Exception);
135
136   CORBA::Long GetId()
137     throw (SALOME::SALOME_Exception);
138
139   CORBA::Long GetStudyId()
140     throw (SALOME::SALOME_Exception);
141
142   // --- C++ interface
143   void SetImpl(::SMESH_Mesh* impl);
144   ::SMESH_Mesh& GetImpl();         // :: force no namespace here
145
146   SMESH_Gen_i* GetGen() { return _gen_i; }
147
148   int ImportUNVFile( const char* theFileName )
149     throw (SALOME::SALOME_Exception);
150
151   int ImportSTLFile( const char* theFileName )
152     throw (SALOME::SALOME_Exception);
153
154   /*!
155    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
156    */
157   SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName )
158     throw (SALOME::SALOME_Exception);
159
160   /*! Check group names for duplications.
161    *  Consider maximum group name length stored in MED file.
162    */
163   CORBA::Boolean HasDuplicatedGroupNamesMED();
164
165   void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion )
166     throw (SALOME::SALOME_Exception);
167   void ExportMED( const char* file, CORBA::Boolean auto_groups )
168     throw (SALOME::SALOME_Exception);
169
170   void ExportDAT( const char* file )
171     throw (SALOME::SALOME_Exception);
172   void ExportUNV( const char* file )
173     throw (SALOME::SALOME_Exception);
174   void ExportSTL( const char* file, const bool isascii )
175     throw (SALOME::SALOME_Exception);
176
177   SALOME_MED::MESH_ptr GetMEDMesh()
178     throw (SALOME::SALOME_Exception);
179
180   CORBA::Long NbNodes()
181     throw (SALOME::SALOME_Exception);
182
183   CORBA::Long NbElements()
184     throw (SALOME::SALOME_Exception);
185
186   CORBA::Long NbEdges()
187     throw (SALOME::SALOME_Exception);
188
189   CORBA::Long NbEdgesOfOrder(SMESH::ElementOrder order)
190     throw (SALOME::SALOME_Exception);
191
192   CORBA::Long NbFaces()
193     throw (SALOME::SALOME_Exception);
194
195   CORBA::Long NbFacesOfOrder(SMESH::ElementOrder order)
196     throw (SALOME::SALOME_Exception);
197
198   CORBA::Long NbTriangles()
199     throw (SALOME::SALOME_Exception);
200
201   CORBA::Long NbTrianglesOfOrder(SMESH::ElementOrder order)
202     throw (SALOME::SALOME_Exception);
203
204   CORBA::Long NbQuadrangles()
205     throw (SALOME::SALOME_Exception);
206
207   CORBA::Long NbQuadranglesOfOrder(SMESH::ElementOrder order)
208     throw (SALOME::SALOME_Exception);
209
210   CORBA::Long NbPolygons()
211     throw (SALOME::SALOME_Exception);
212
213   CORBA::Long NbVolumes()
214     throw (SALOME::SALOME_Exception);
215
216   CORBA::Long NbVolumesOfOrder(SMESH::ElementOrder order)
217     throw (SALOME::SALOME_Exception);
218
219   CORBA::Long NbTetras()
220     throw (SALOME::SALOME_Exception);
221
222   CORBA::Long NbTetrasOfOrder(SMESH::ElementOrder order)
223     throw (SALOME::SALOME_Exception);
224
225   CORBA::Long NbHexas()
226     throw (SALOME::SALOME_Exception);
227
228   CORBA::Long NbHexasOfOrder(SMESH::ElementOrder order)
229     throw (SALOME::SALOME_Exception);
230
231   CORBA::Long NbPyramids()
232     throw (SALOME::SALOME_Exception);
233
234   CORBA::Long NbPyramidsOfOrder(SMESH::ElementOrder order)
235     throw (SALOME::SALOME_Exception);
236
237   CORBA::Long NbPrisms()
238     throw (SALOME::SALOME_Exception);
239
240   CORBA::Long NbPrismsOfOrder(SMESH::ElementOrder order)
241     throw (SALOME::SALOME_Exception);
242
243   CORBA::Long NbPolyhedrons()
244     throw (SALOME::SALOME_Exception);
245
246   CORBA::Long NbSubMesh()
247     throw (SALOME::SALOME_Exception);
248
249   SMESH::long_array* GetElementsId()
250     throw (SALOME::SALOME_Exception);
251
252   SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType )
253     throw (SALOME::SALOME_Exception);
254   
255   SMESH::long_array* GetNodesId()
256     throw (SALOME::SALOME_Exception);
257   
258   SMESH::ElementType GetElementType( const CORBA::Long id, const bool iselem )
259     throw (SALOME::SALOME_Exception);
260   
261   /*!
262    * Returns ID of elements for given submesh
263    */
264   SMESH::long_array* GetSubMeshElementsId(const CORBA::Long ShapeID)
265     throw (SALOME::SALOME_Exception);
266
267   /*!
268    * Returns ID of nodes for given submesh
269    * If param all==true - returns all nodes, else -
270    * returns only nodes on shapes.
271    */
272   SMESH::long_array* GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
273     throw (SALOME::SALOME_Exception);
274   
275   /*!
276    * Returns type of elements for given submesh
277    */
278   SMESH::ElementType GetSubMeshElementType(const CORBA::Long ShapeID)
279     throw (SALOME::SALOME_Exception);
280   
281   char* Dump();
282   
283   // Internal methods not available through CORBA
284   // They are called by corresponding interface methods
285   SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
286                                                     SMESH::SMESH_Hypothesis_ptr anHyp);
287
288   SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
289                                                        SMESH::SMESH_Hypothesis_ptr anHyp);
290   
291   static SMESH::Hypothesis_Status
292   ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
293
294   int importMEDFile( const char* theFileName, const char* theMeshName );
295
296   SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
297
298   void removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
299                      GEOM::GEOM_Object_ptr theSubShapeObject );
300
301   SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType  theElemType,
302                                          const char*         theName,
303                                          const TopoDS_Shape& theShape = TopoDS_Shape());
304
305   void removeGroup( const int theId );
306
307   SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
308   // return an existing subMesh object for the shapeID. shapeID == submeshID.
309
310   const map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
311   // return an existing group object.
312
313   virtual SMESH::long_array* GetIDs();
314
315   CORBA::LongLong GetMeshPtr();
316
317
318   /*!
319    * Get XYZ coordinates of node as list of double
320    * If there is not node for given ID - returns empty list
321    */
322   SMESH::double_array* GetNodeXYZ(const CORBA::Long id);
323   
324   /*!
325    * For given node returns list of IDs of inverse elements
326    * If there is not node for given ID - returns empty list
327    */
328   SMESH::long_array* GetNodeInverseElements(const CORBA::Long id);
329
330   /*!
331    * If given element is node returns IDs of shape from position
332    * If there is not node for given ID - returns -1
333    */
334   CORBA::Long GetShapeID(const CORBA::Long id);
335
336   /*!
337    * For given element returns ID of result shape after 
338    * ::FindShape() from SMESH_MeshEditor
339    * If there is not element for given ID - returns -1
340    */
341   CORBA::Long GetShapeIDForElem(const CORBA::Long id);
342
343   /*!
344    * Returns number of nodes for given element
345    * If there is not element for given ID - returns -1
346    */
347   CORBA::Long GetElemNbNodes(const CORBA::Long id);
348
349   /*!
350    * Returns IDs of nodes of given element
351    */
352   SMESH::long_array* GetElemNodes(const CORBA::Long id);
353
354   /*!
355    * Returns ID of node by given index for given element
356    * If there is not element for given ID - returns -1
357    * If there is not node for given index - returns -2
358    */
359   CORBA::Long GetElemNode(const CORBA::Long id, const CORBA::Long index);
360   
361   /*!
362    * Returns true if given node is medium node
363    * in given quadratic element
364    */
365   CORBA::Boolean IsMediumNode(const CORBA::Long ide, const CORBA::Long idn);
366   
367   /*!
368    * Returns true if given node is medium node
369    * in one of quadratic elements
370    */
371   CORBA::Boolean IsMediumNodeOfAnyElem(const CORBA::Long idn,
372                                        SMESH::ElementType theElemType);
373   
374   /*!
375    * Returns number of edges for given element
376    */
377   CORBA::Long ElemNbEdges(const CORBA::Long id);
378   
379   /*!
380    * Returns number of faces for given element
381    */
382   CORBA::Long ElemNbFaces(const CORBA::Long id);
383   
384   /*!
385    * Returns true if given element is polygon
386    */
387   CORBA::Boolean IsPoly(const CORBA::Long id);
388   
389   /*!
390    * Returns true if given element is quadratic
391    */
392   CORBA::Boolean IsQuadratic(const CORBA::Long id);
393   
394   /*!
395    * Returns bary center for given element
396    */
397   SMESH::double_array* BaryCenter(const CORBA::Long id);
398
399
400   map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
401   map<int, ::SMESH_subMesh*> _mapSubMesh;   //NRI
402
403 private:
404   void CreateGroupServants();
405
406   static int myIdGenerator;
407   ::SMESH_Mesh* _impl;  // :: force no namespace here
408   SMESH_Gen_i* _gen_i;
409   int _id;          // id given by creator (unique within the creator instance)
410   int _studyId;
411   map<int, SMESH::SMESH_subMesh_ptr>    _mapSubMeshIor;
412   map<int, SMESH::SMESH_GroupBase_ptr>  _mapGroups;
413   map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
414 };
415
416 #endif
417