Salome HOME
Debug
[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 //
27 #ifndef _SMESH_MESH_I_HXX_
28 #define _SMESH_MESH_I_HXX_
29
30 #include "SMESH.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_ParameterizedObject.hxx"
45
46 class SMESH_Gen_i;
47 class SMESH_GroupBase_i;
48 class SMESH_subMesh_i;
49
50 #include <map>
51
52 class SMESH_I_EXPORT SMESH_Mesh_i:
53   public virtual POA_SMESH::SMESH_Mesh,
54   public virtual SALOME_ParameterizedObject
55 {
56   SMESH_Mesh_i();
57   SMESH_Mesh_i(const SMESH_Mesh_i&);
58 public:
59   SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
60                 SMESH_Gen_i*            myGen_i,
61                 CORBA::Long             studyId,
62                 SALOME::Notebook_ptr    theNotebook );
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   void ClearSubMesh(CORBA::Long ShapeID)
80     throw (SALOME::SALOME_Exception);
81
82   SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
83                                          SMESH::SMESH_Hypothesis_ptr anHyp)
84     throw (SALOME::SALOME_Exception);
85
86   SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
87                                             SMESH::SMESH_Hypothesis_ptr anHyp)
88     throw (SALOME::SALOME_Exception);
89
90   SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
91     throw (SALOME::SALOME_Exception);
92
93   SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject, const char* theName)
94     throw (SALOME::SALOME_Exception);
95
96   void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
97     throw (SALOME::SALOME_Exception);
98
99   SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName )
100     throw (SALOME::SALOME_Exception);
101   
102   SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType    theElemType,
103                                                    const char*           theName,
104                                                    GEOM::GEOM_Object_ptr theGeomObj )
105     throw (SALOME::SALOME_Exception);
106
107   void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
108     throw (SALOME::SALOME_Exception);
109   
110   void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
111     throw (SALOME::SALOME_Exception);
112   
113   SMESH::ListOfGroups* GetGroups()
114     throw (SALOME::SALOME_Exception);
115
116   CORBA::Long NbGroups()
117     throw (SALOME::SALOME_Exception);
118
119   SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
120                                       SMESH::SMESH_GroupBase_ptr theGroup2, 
121                                       const char* theName )
122     throw (SALOME::SALOME_Exception);
123
124   SMESH::SMESH_Group_ptr UnionListOfGroups( const SMESH::ListOfGroups& theGroups, 
125                                             const char* theName)
126     throw (SALOME::SALOME_Exception);
127   
128   SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
129                                           SMESH::SMESH_GroupBase_ptr theGroup2, 
130                                           const char* theName )
131     throw (SALOME::SALOME_Exception);
132
133   SMESH::SMESH_Group_ptr IntersectListOfGroups( const SMESH::ListOfGroups&  theGroups, 
134                                                 const char* theName )
135     throw (SALOME::SALOME_Exception);
136   
137   SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
138                                     SMESH::SMESH_GroupBase_ptr theGroup2, 
139                                     const char* theName )
140     throw (SALOME::SALOME_Exception);
141
142   SMESH::SMESH_Group_ptr CutListOfGroups( const SMESH::ListOfGroups& theMainGroups, 
143                                           const SMESH::ListOfGroups& theToolGroups, 
144                                           const char* theName )
145   throw (SALOME::SALOME_Exception);
146
147   SMESH::SMESH_Group_ptr CreateDimGroup( const SMESH::ListOfGroups& theGroups, 
148                                          SMESH::ElementType theElemType, 
149                                          const char* theName )
150   throw (SALOME::SALOME_Exception);
151   
152
153   SMESH::SMESH_Group_ptr ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGeomGroup );
154
155 //    SMESH::string_array* GetLog(CORBA::Boolean clearAfterGet)
156 //      throw (SALOME::SALOME_Exception);
157
158   SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet)
159     throw (SALOME::SALOME_Exception);
160
161   SMESH::SMESH_MeshEditor_ptr GetMeshEditor();
162
163   SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer();
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 ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion )
211     throw (SALOME::SALOME_Exception);
212   void ExportMED( const char* file, CORBA::Boolean auto_groups )
213     throw (SALOME::SALOME_Exception);
214
215   void ExportDAT( const char* file )
216     throw (SALOME::SALOME_Exception);
217   void ExportUNV( const char* file )
218     throw (SALOME::SALOME_Exception);
219   void ExportSTL( const char* file, bool isascii )
220     throw (SALOME::SALOME_Exception);
221
222   SALOME_MED::MESH_ptr GetMEDMesh()
223     throw (SALOME::SALOME_Exception);
224
225   CORBA::Long NbNodes()
226     throw (SALOME::SALOME_Exception);
227
228   CORBA::Long NbElements()
229     throw (SALOME::SALOME_Exception);
230
231   CORBA::Long Nb0DElements()
232     throw (SALOME::SALOME_Exception);
233
234   CORBA::Long NbEdges()
235     throw (SALOME::SALOME_Exception);
236
237   CORBA::Long NbEdgesOfOrder(SMESH::ElementOrder order)
238     throw (SALOME::SALOME_Exception);
239
240   CORBA::Long NbFaces()
241     throw (SALOME::SALOME_Exception);
242
243   CORBA::Long NbFacesOfOrder(SMESH::ElementOrder order)
244     throw (SALOME::SALOME_Exception);
245
246   CORBA::Long NbTriangles()
247     throw (SALOME::SALOME_Exception);
248
249   CORBA::Long NbTrianglesOfOrder(SMESH::ElementOrder order)
250     throw (SALOME::SALOME_Exception);
251
252   CORBA::Long NbQuadrangles()
253     throw (SALOME::SALOME_Exception);
254
255   CORBA::Long NbQuadranglesOfOrder(SMESH::ElementOrder order)
256     throw (SALOME::SALOME_Exception);
257
258   CORBA::Long NbPolygons()
259     throw (SALOME::SALOME_Exception);
260
261   CORBA::Long NbVolumes()
262     throw (SALOME::SALOME_Exception);
263
264   CORBA::Long NbVolumesOfOrder(SMESH::ElementOrder order)
265     throw (SALOME::SALOME_Exception);
266
267   CORBA::Long NbTetras()
268     throw (SALOME::SALOME_Exception);
269
270   CORBA::Long NbTetrasOfOrder(SMESH::ElementOrder order)
271     throw (SALOME::SALOME_Exception);
272
273   CORBA::Long NbHexas()
274     throw (SALOME::SALOME_Exception);
275
276   CORBA::Long NbHexasOfOrder(SMESH::ElementOrder order)
277     throw (SALOME::SALOME_Exception);
278
279   CORBA::Long NbPyramids()
280     throw (SALOME::SALOME_Exception);
281
282   CORBA::Long NbPyramidsOfOrder(SMESH::ElementOrder order)
283     throw (SALOME::SALOME_Exception);
284
285   CORBA::Long NbPrisms()
286     throw (SALOME::SALOME_Exception);
287
288   CORBA::Long NbPrismsOfOrder(SMESH::ElementOrder order)
289     throw (SALOME::SALOME_Exception);
290
291   CORBA::Long NbPolyhedrons()
292     throw (SALOME::SALOME_Exception);
293
294   CORBA::Long NbSubMesh()
295     throw (SALOME::SALOME_Exception);
296
297   SMESH::long_array* GetElementsId()
298     throw (SALOME::SALOME_Exception);
299
300   SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType )
301     throw (SALOME::SALOME_Exception);
302   
303   SMESH::long_array* GetNodesId()
304     throw (SALOME::SALOME_Exception);
305   
306   SMESH::ElementType GetElementType( CORBA::Long id, bool iselem )
307     throw (SALOME::SALOME_Exception);
308   
309   /*!
310    * Returns ID of elements for given submesh
311    */
312   SMESH::long_array* GetSubMeshElementsId(CORBA::Long ShapeID)
313     throw (SALOME::SALOME_Exception);
314
315   /*!
316    * Returns ID of nodes for given submesh
317    * If param all==true - returns all nodes, else -
318    * returns only nodes on shapes.
319    */
320   SMESH::long_array* GetSubMeshNodesId(CORBA::Long ShapeID, CORBA::Boolean all)
321     throw (SALOME::SALOME_Exception);
322   
323   /*!
324    * Returns type of elements for given submesh
325    */
326   SMESH::ElementType GetSubMeshElementType(CORBA::Long ShapeID)
327     throw (SALOME::SALOME_Exception);
328   
329   char* Dump();
330   
331   // Internal methods not available through CORBA
332   // They are called by corresponding interface methods
333   SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
334                                                     SMESH::SMESH_Hypothesis_ptr anHyp);
335
336   SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
337                                                        SMESH::SMESH_Hypothesis_ptr anHyp);
338   
339   static SMESH::Hypothesis_Status
340   ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
341
342   static void PrepareForWriting (const char* file);
343
344   //int importMEDFile( const char* theFileName, const char* theMeshName );
345
346   SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
347
348   void removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
349                      GEOM::GEOM_Object_ptr theSubShapeObject );
350
351   SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType  theElemType,
352                                          const char*         theName,
353                                          const TopoDS_Shape& theShape = TopoDS_Shape());
354
355   void removeGroup( const int theId );
356
357   SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
358   // return an existing subMesh object for the shapeID. shapeID == submeshID.
359
360   const std::map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
361   // return an existing group object.
362
363   /*!
364    * \brief Update hypotheses assigned to geom groups if the latter change
365    * 
366    * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
367    */
368   void CheckGeomGroupModif();
369
370   virtual SMESH::long_array* GetIDs();
371
372   CORBA::LongLong GetMeshPtr();
373
374   /*!
375    * \brief Assure that all groups are published
376    */
377   void CreateGroupServants();
378
379   /*!
380    * \brief Return groups cantained in _mapGroups by their IDs
381    */
382   SMESH::ListOfGroups* GetGroups(const std::list<int>& groupIDs) const;
383
384   /*!
385    * Get XYZ coordinates of node as list of double
386    * If there is not node for given ID - returns empty list
387    */
388   SMESH::double_array* GetNodeXYZ(CORBA::Long id);
389   
390   /*!
391    * For given node returns list of IDs of inverse elements
392    * If there is not node for given ID - returns empty list
393    */
394   SMESH::long_array* GetNodeInverseElements(CORBA::Long id);
395
396   /*!
397    * \brief Return position of a node on shape
398    */
399   SMESH::NodePosition* GetNodePosition(CORBA::Long NodeID);
400
401   /*!
402    * If given element is node returns IDs of shape from position
403    * If there is not node for given ID - returns -1
404    */
405   CORBA::Long GetShapeID(CORBA::Long id);
406
407   /*!
408    * For given element returns ID of result shape after 
409    * ::FindShape() from SMESH_MeshEditor
410    * If there is not element for given ID - returns -1
411    */
412   CORBA::Long GetShapeIDForElem(CORBA::Long id);
413
414   /*!
415    * Returns number of nodes for given element
416    * If there is not element for given ID - returns -1
417    */
418   CORBA::Long GetElemNbNodes(CORBA::Long id);
419
420   /*!
421    * Returns IDs of nodes of given element
422    */
423   SMESH::long_array* GetElemNodes(CORBA::Long id);
424
425   /*!
426    * Returns ID of node by given index for given element
427    * If there is not element for given ID - returns -1
428    * If there is not node for given index - returns -2
429    */
430   CORBA::Long GetElemNode(CORBA::Long id, CORBA::Long index);
431   
432   /*!
433    * Returns true if given node is medium node
434    * in given quadratic element
435    */
436   CORBA::Boolean IsMediumNode(CORBA::Long ide, CORBA::Long idn);
437   
438   /*!
439    * Returns true if given node is medium node
440    * in one of quadratic elements
441    */
442   CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn,
443                                        SMESH::ElementType theElemType);
444   
445   /*!
446    * Returns number of edges for given element
447    */
448   CORBA::Long ElemNbEdges(CORBA::Long id);
449   
450   /*!
451    * Returns number of faces for given element
452    */
453   CORBA::Long ElemNbFaces(CORBA::Long id);
454   
455   /*!
456    * Returns true if given element is polygon
457    */
458   CORBA::Boolean IsPoly(CORBA::Long id);
459   
460   /*!
461    * Returns true if given element is quadratic
462    */
463   CORBA::Boolean IsQuadratic(CORBA::Long id);
464   
465   /*!
466    * Returns bary center for given element
467    */
468   SMESH::double_array* BaryCenter(CORBA::Long id);
469
470   /*!
471    * Returns information about imported MED file
472    */
473   virtual SALOME_MED::MedFileInfo* GetMEDFileInfo();
474
475   /*!
476    * Get internal entry of mesh
477    */
478   virtual char* GetEntry();
479
480   /*!
481    * Get name of the component
482    */
483   virtual char* GetComponent();
484
485   /*!
486    * Get validity status of mesh
487    */
488   virtual CORBA::Boolean IsValid();
489
490   /*!
491    * Sets list of notebook variables used for Mesh operations
492    */
493   virtual void SetParameters( SALOME::Notebook_ptr theNotebook, const SALOME::StringArray& theParameters );
494   
495   /*!
496    * Returns list of notebook variables used for Mesh operations
497    */
498   virtual SALOME::StringArray* GetParameters();
499
500   /*!
501    * Update mesh according to the SALOME Notebook
502    */
503   virtual void Update( SALOME::Notebook_ptr theNotebook );
504
505   /*!
506    * Update string attribute of mesh
507    */
508   virtual void UpdateStringAttribute( const SALOME::StringArray& theParameters );
509
510   /*!
511    * Store dependencies for mesh
512    */
513   virtual void StoreDependencies( SALOME::Notebook_ptr theNotebook );
514
515   /*!
516    * Returns statistic of mesh elements
517    * Result array of number enityties
518    * Inherited from SMESH_IDSource
519    */
520   virtual SMESH::long_array* GetMeshInfo();
521
522   /*!
523    * Collect statistic of mesh elements given by iterator
524    */
525   static void CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
526                               SMESH::long_array&         theInfo);
527                           
528   
529   std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
530   std::map<int, ::SMESH_subMesh*> _mapSubMesh;   //NRI
531
532 private:
533   /*!
534    * Check and correct names of mesh groups
535    */
536   void checkGroupNames();
537
538   /*!
539    * Store dependencies for mesh
540    */
541   virtual void StoreDependenciesForShape( SALOME::Notebook_ptr theNotebook,
542                                           GEOM::GEOM_Object_ptr theShapeObject,
543                                           bool theIsStoreShape );
544
545 private:
546
547   static int myIdGenerator;
548   ::SMESH_Mesh* _impl;  // :: force no namespace here
549   SMESH_Gen_i* _gen_i;
550   int _id;          // id given by creator (unique within the creator instance)
551   int _studyId;
552   std::map<int, SMESH::SMESH_subMesh_ptr>    _mapSubMeshIor;
553   std::map<int, SMESH::SMESH_GroupBase_ptr>  _mapGroups;
554   std::map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
555   SALOME_MED::MedFileInfo_var myFileInfo;
556
557 private:
558
559   // Data used to track changes of GEOM groups
560   struct TGeomGroupData {
561     // keep study entry and not ior because GEOM_Object actually changes if
562     // number of items in a group varies (1) <-> (>1)
563     std::string       _groupEntry;
564     std::set<int>     _indices; // indices of group items within group's main shape
565     CORBA::Object_ptr _smeshObject; // SMESH object depending on GEOM group
566   };
567   std::list<TGeomGroupData> _geomGroupData;
568
569   /*!
570    * Remember GEOM group data
571    */
572   void addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
573                         CORBA::Object_ptr     theSmeshObj);
574   /*!
575    * Remove GEOM group data relating to removed smesh object
576    */
577   void removeGeomGroupData(CORBA::Object_ptr theSmeshObj);
578   /*!
579    * \brief Return new group contents if it has been changed and update group data
580    */
581   TopoDS_Shape newGroupShape( TGeomGroupData & groupData);
582   
583 };
584
585 #endif
586