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