1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_Mesh_i.hxx
23 // Author : Paul RASCLE, EDF
26 #ifndef _SMESH_MESH_I_HXX_
27 #define _SMESH_MESH_I_HXX_
31 #include <SALOMEconfig.h>
32 #include CORBA_SERVER_HEADER(SMESH_Mesh)
33 #include CORBA_SERVER_HEADER(SMESH_Group)
34 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
35 #include CORBA_CLIENT_HEADER(GEOM_Gen)
36 #include CORBA_CLIENT_HEADER(MED)
38 #include "SMESH_Hypothesis.hxx"
39 #include "SMESH_Mesh.hxx"
40 //#include "SMESH_subMesh_i.hxx"
41 #include "SMESH_subMesh.hxx"
43 #include "SALOME_GenericObj_i.hh"
46 class SMESH_GroupBase_i;
47 class SMESH_subMesh_i;
51 class SMESH_I_EXPORT SMESH_Mesh_i:
52 public virtual POA_SMESH::SMESH_Mesh,
53 public virtual SALOME::GenericObj_i
56 SMESH_Mesh_i(const SMESH_Mesh_i&);
58 SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
60 CORBA::Long studyId );
62 virtual ~SMESH_Mesh_i();
65 void SetShape( GEOM::GEOM_Object_ptr theShapeObject )
66 throw (SALOME::SALOME_Exception);
68 CORBA::Boolean HasShapeToMesh()
69 throw (SALOME::SALOME_Exception);
71 GEOM::GEOM_Object_ptr GetShapeToMesh()
72 throw (SALOME::SALOME_Exception);
75 throw (SALOME::SALOME_Exception);
77 void ClearSubMesh(CORBA::Long ShapeID)
78 throw (SALOME::SALOME_Exception);
80 SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
81 SMESH::SMESH_Hypothesis_ptr anHyp)
82 throw (SALOME::SALOME_Exception);
84 SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
85 SMESH::SMESH_Hypothesis_ptr anHyp)
86 throw (SALOME::SALOME_Exception);
88 SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
89 throw (SALOME::SALOME_Exception);
91 SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject, const char* theName)
92 throw (SALOME::SALOME_Exception);
94 void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
95 throw (SALOME::SALOME_Exception);
97 SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName )
98 throw (SALOME::SALOME_Exception);
100 SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType theElemType,
102 GEOM::GEOM_Object_ptr theGeomObj )
103 throw (SALOME::SALOME_Exception);
105 void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
106 throw (SALOME::SALOME_Exception);
108 void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
109 throw (SALOME::SALOME_Exception);
111 SMESH::ListOfGroups* GetGroups()
112 throw (SALOME::SALOME_Exception);
114 CORBA::Long NbGroups()
115 throw (SALOME::SALOME_Exception);
117 SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
118 SMESH::SMESH_GroupBase_ptr theGroup2,
119 const char* theName )
120 throw (SALOME::SALOME_Exception);
122 SMESH::SMESH_Group_ptr UnionListOfGroups( const SMESH::ListOfGroups& theGroups,
124 throw (SALOME::SALOME_Exception);
126 SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
127 SMESH::SMESH_GroupBase_ptr theGroup2,
128 const char* theName )
129 throw (SALOME::SALOME_Exception);
131 SMESH::SMESH_Group_ptr IntersectListOfGroups( const SMESH::ListOfGroups& theGroups,
132 const char* theName )
133 throw (SALOME::SALOME_Exception);
135 SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
136 SMESH::SMESH_GroupBase_ptr theGroup2,
137 const char* theName )
138 throw (SALOME::SALOME_Exception);
140 SMESH::SMESH_Group_ptr CutListOfGroups( const SMESH::ListOfGroups& theMainGroups,
141 const SMESH::ListOfGroups& theToolGroups,
142 const char* theName )
143 throw (SALOME::SALOME_Exception);
145 SMESH::SMESH_Group_ptr CreateDimGroup( const SMESH::ListOfGroups& theGroups,
146 SMESH::ElementType theElemType,
147 const char* theName )
148 throw (SALOME::SALOME_Exception);
151 SMESH::SMESH_Group_ptr ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGeomGroup );
153 // SMESH::string_array* GetLog(CORBA::Boolean clearAfterGet)
154 // throw (SALOME::SALOME_Exception);
156 SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet)
157 throw (SALOME::SALOME_Exception);
159 SMESH::SMESH_MeshEditor_ptr GetMeshEditor();
161 SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer();
163 CORBA::Boolean HasModificationsToDiscard() throw (SALOME::SALOME_Exception);
166 throw (SALOME::SALOME_Exception);
169 throw (SALOME::SALOME_Exception);
171 CORBA::Long GetStudyId()
172 throw (SALOME::SALOME_Exception);
175 void SetImpl(::SMESH_Mesh* impl);
176 ::SMESH_Mesh& GetImpl(); // :: force no namespace here
178 SMESH_Gen_i* GetGen() { return _gen_i; }
180 int ImportUNVFile( const char* theFileName )
181 throw (SALOME::SALOME_Exception);
183 int ImportSTLFile( const char* theFileName )
184 throw (SALOME::SALOME_Exception);
187 * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
189 SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName )
190 throw (SALOME::SALOME_Exception);
195 void SetAutoColor(CORBA::Boolean theAutoColor)
196 throw (SALOME::SALOME_Exception);
198 CORBA::Boolean GetAutoColor()
199 throw (SALOME::SALOME_Exception);
201 /*! Check group names for duplications.
202 * Consider maximum group name length stored in MED file.
204 CORBA::Boolean HasDuplicatedGroupNamesMED();
206 * Return string representation of a MED file version comprising nbDigits
208 char* GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits);
210 void ExportToMEDX( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion, CORBA::Boolean overwrite )
211 throw (SALOME::SALOME_Exception);
212 void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion )
213 throw (SALOME::SALOME_Exception);
214 void ExportMED( const char* file, CORBA::Boolean auto_groups )
215 throw (SALOME::SALOME_Exception);
217 void ExportDAT( const char* file )
218 throw (SALOME::SALOME_Exception);
219 void ExportUNV( const char* file )
220 throw (SALOME::SALOME_Exception);
221 void ExportSTL( const char* file, bool isascii )
222 throw (SALOME::SALOME_Exception);
224 SALOME_MED::MESH_ptr GetMEDMesh()
225 throw (SALOME::SALOME_Exception);
227 CORBA::Long NbNodes()
228 throw (SALOME::SALOME_Exception);
230 CORBA::Long NbElements()
231 throw (SALOME::SALOME_Exception);
233 CORBA::Long Nb0DElements()
234 throw (SALOME::SALOME_Exception);
236 CORBA::Long NbEdges()
237 throw (SALOME::SALOME_Exception);
239 CORBA::Long NbEdgesOfOrder(SMESH::ElementOrder order)
240 throw (SALOME::SALOME_Exception);
242 CORBA::Long NbFaces()
243 throw (SALOME::SALOME_Exception);
245 CORBA::Long NbFacesOfOrder(SMESH::ElementOrder order)
246 throw (SALOME::SALOME_Exception);
248 CORBA::Long NbTriangles()
249 throw (SALOME::SALOME_Exception);
251 CORBA::Long NbTrianglesOfOrder(SMESH::ElementOrder order)
252 throw (SALOME::SALOME_Exception);
254 CORBA::Long NbQuadrangles()
255 throw (SALOME::SALOME_Exception);
257 CORBA::Long NbQuadranglesOfOrder(SMESH::ElementOrder order)
258 throw (SALOME::SALOME_Exception);
260 CORBA::Long NbPolygons()
261 throw (SALOME::SALOME_Exception);
263 CORBA::Long NbVolumes()
264 throw (SALOME::SALOME_Exception);
266 CORBA::Long NbVolumesOfOrder(SMESH::ElementOrder order)
267 throw (SALOME::SALOME_Exception);
269 CORBA::Long NbTetras()
270 throw (SALOME::SALOME_Exception);
272 CORBA::Long NbTetrasOfOrder(SMESH::ElementOrder order)
273 throw (SALOME::SALOME_Exception);
275 CORBA::Long NbHexas()
276 throw (SALOME::SALOME_Exception);
278 CORBA::Long NbHexasOfOrder(SMESH::ElementOrder order)
279 throw (SALOME::SALOME_Exception);
281 CORBA::Long NbPyramids()
282 throw (SALOME::SALOME_Exception);
284 CORBA::Long NbPyramidsOfOrder(SMESH::ElementOrder order)
285 throw (SALOME::SALOME_Exception);
287 CORBA::Long NbPrisms()
288 throw (SALOME::SALOME_Exception);
290 CORBA::Long NbPrismsOfOrder(SMESH::ElementOrder order)
291 throw (SALOME::SALOME_Exception);
293 CORBA::Long NbPolyhedrons()
294 throw (SALOME::SALOME_Exception);
296 CORBA::Long NbSubMesh()
297 throw (SALOME::SALOME_Exception);
299 SMESH::long_array* GetElementsId()
300 throw (SALOME::SALOME_Exception);
302 SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType )
303 throw (SALOME::SALOME_Exception);
305 SMESH::long_array* GetNodesId()
306 throw (SALOME::SALOME_Exception);
308 SMESH::ElementType GetElementType( CORBA::Long id, bool iselem )
309 throw (SALOME::SALOME_Exception);
311 SMESH::EntityType GetElementGeomType( CORBA::Long id )
312 throw (SALOME::SALOME_Exception);
315 * Returns ID of elements for given submesh
317 SMESH::long_array* GetSubMeshElementsId(CORBA::Long ShapeID)
318 throw (SALOME::SALOME_Exception);
321 * Returns ID of nodes for given submesh
322 * If param all==true - returns all nodes, else -
323 * returns only nodes on shapes.
325 SMESH::long_array* GetSubMeshNodesId(CORBA::Long ShapeID, CORBA::Boolean all)
326 throw (SALOME::SALOME_Exception);
329 * Returns type of elements for given submesh
331 SMESH::ElementType GetSubMeshElementType(CORBA::Long ShapeID)
332 throw (SALOME::SALOME_Exception);
336 // Internal methods not available through CORBA
337 // They are called by corresponding interface methods
338 SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
339 SMESH::SMESH_Hypothesis_ptr anHyp);
341 SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
342 SMESH::SMESH_Hypothesis_ptr anHyp);
344 static SMESH::Hypothesis_Status
345 ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
347 static void PrepareForWriting (const char* file, bool overwrite = true);
349 //int importMEDFile( const char* theFileName, const char* theMeshName );
351 SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
353 void removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
354 GEOM::GEOM_Object_ptr theSubShapeObject );
356 SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType theElemType,
358 const TopoDS_Shape& theShape = TopoDS_Shape());
360 void removeGroup( const int theId );
362 SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
363 // return an existing subMesh object for the shapeID. shapeID == submeshID.
365 const std::map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
366 // return an existing group object.
369 * \brief Update hypotheses assigned to geom groups if the latter change
371 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
373 void CheckGeomGroupModif();
375 CORBA::LongLong GetMeshPtr();
378 * \brief Assure that all groups are published
380 void CreateGroupServants();
383 * \brief Return groups cantained in _mapGroups by their IDs
385 SMESH::ListOfGroups* GetGroups(const std::list<int>& groupIDs) const;
388 * Get XYZ coordinates of node as list of double
389 * If there is not node for given ID - returns empty list
391 SMESH::double_array* GetNodeXYZ(CORBA::Long id);
394 * For given node returns list of IDs of inverse elements
395 * If there is not node for given ID - returns empty list
397 SMESH::long_array* GetNodeInverseElements(CORBA::Long id);
400 * \brief Return position of a node on shape
402 SMESH::NodePosition* GetNodePosition(CORBA::Long NodeID);
405 * If given element is node returns IDs of shape from position
406 * If there is not node for given ID - returns -1
408 CORBA::Long GetShapeID(CORBA::Long id);
411 * For given element returns ID of result shape after
412 * ::FindShape() from SMESH_MeshEditor
413 * If there is not element for given ID - returns -1
415 CORBA::Long GetShapeIDForElem(CORBA::Long id);
418 * Returns number of nodes for given element
419 * If there is not element for given ID - returns -1
421 CORBA::Long GetElemNbNodes(CORBA::Long id);
424 * Returns IDs of nodes of given element
426 SMESH::long_array* GetElemNodes(CORBA::Long id);
429 * Returns ID of node by given index for given element
430 * If there is not element for given ID - returns -1
431 * If there is not node for given index - returns -2
433 CORBA::Long GetElemNode(CORBA::Long id, CORBA::Long index);
436 * Returns true if given node is medium node
437 * in given quadratic element
439 CORBA::Boolean IsMediumNode(CORBA::Long ide, CORBA::Long idn);
442 * Returns true if given node is medium node
443 * in one of quadratic elements
445 CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn,
446 SMESH::ElementType theElemType);
449 * Returns number of edges for given element
451 CORBA::Long ElemNbEdges(CORBA::Long id);
454 * Returns number of faces for given element
456 CORBA::Long ElemNbFaces(CORBA::Long id);
458 * Returns nodes of given face (counted from zero) for given element.
460 SMESH::long_array* GetElemFaceNodes(CORBA::Long elemId, CORBA::Short faceIndex);
463 * Returns an element based on all given nodes.
465 CORBA::Long FindElementByNodes(const SMESH::long_array& nodes);
468 * Returns true if given element is polygon
470 CORBA::Boolean IsPoly(CORBA::Long id);
473 * Returns true if given element is quadratic
475 CORBA::Boolean IsQuadratic(CORBA::Long id);
478 * Returns bary center for given element
480 SMESH::double_array* BaryCenter(CORBA::Long id);
483 * Returns information about imported MED file
485 virtual SALOME_MED::MedFileInfo* GetMEDFileInfo();
488 * Sets list of notebook variables used for Mesh operations separated by ":" symbol
490 void SetParameters (const char* theParameters);
493 * Returns list of notebook variables used for Mesh operations separated by ":" symbol
495 char* GetParameters();
498 * Returns list of notebook variables used for last Mesh operation
500 SMESH::string_array* GetLastParameters();
503 * Collect statistic of mesh elements given by iterator
505 static void CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
506 SMESH::long_array& theInfo);
509 * \brief Return submesh objects list in meshing order
511 virtual SMESH::submesh_array_array* GetMeshOrder();
513 * \brief Set submesh object order
515 virtual ::CORBA::Boolean SetMeshOrder(const SMESH::submesh_array_array& theSubMeshArray);
518 // =========================
519 // SMESH_IDSource interface
520 // =========================
522 virtual SMESH::long_array* GetIDs();
524 * Returns statistic of mesh elements
525 * Result array of number enityties
526 * Inherited from SMESH_IDSource
528 virtual SMESH::long_array* GetMeshInfo();
530 * Returns types of elements it contains
532 virtual SMESH::array_of_ElementType* GetTypes();
536 virtual SMESH::SMESH_Mesh_ptr GetMesh();
539 std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
540 std::map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
544 * Check and correct names of mesh groups
546 void checkGroupNames();
549 * Convert submesh ids into submesh interfaces
551 void convertMeshOrder(const TListOfListOfInt& theIdsOrder,
552 SMESH::submesh_array_array& theSubMeshOrder,
553 const bool theIsDump);
557 static int myIdGenerator;
558 ::SMESH_Mesh* _impl; // :: force no namespace here
560 int _id; // id given by creator (unique within the creator instance)
562 std::map<int, SMESH::SMESH_subMesh_ptr> _mapSubMeshIor;
563 std::map<int, SMESH::SMESH_GroupBase_ptr> _mapGroups;
564 std::map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
565 SALOME_MED::MedFileInfo_var myFileInfo;
569 // Data used to track changes of GEOM groups
570 struct TGeomGroupData {
571 // keep study entry and not ior because GEOM_Object actually changes if
572 // number of items in a group varies (1) <-> (>1)
573 std::string _groupEntry;
574 std::set<int> _indices; // indices of group items within group's main shape
575 CORBA::Object_ptr _smeshObject; // SMESH object depending on GEOM group
577 std::list<TGeomGroupData> _geomGroupData;
580 * Remember GEOM group data
582 void addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
583 CORBA::Object_ptr theSmeshObj);
585 * Remove GEOM group data relating to removed smesh object
587 void removeGeomGroupData(CORBA::Object_ptr theSmeshObj);
589 * \brief Return new group contents if it has been changed and update group data
591 TopoDS_Shape newGroupShape( TGeomGroupData & groupData);