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