1 // Copyright (C) 2007-2013 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_Gen)
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)
39 #include "SMESH_Hypothesis.hxx"
40 #include "SMESH_Mesh.hxx"
41 #include "SMESH_subMesh.hxx"
43 #include "SALOME_GenericObj_i.hh"
46 class SMESH_GroupBase_i;
47 class SMESH_subMesh_i;
48 class SMESH_PreMeshInfo;
52 class SMESH_I_EXPORT SMESH_Mesh_i:
53 public virtual POA_SMESH::SMESH_Mesh,
54 public virtual SALOME::GenericObj_i
57 SMESH_Mesh_i(const SMESH_Mesh_i&);
59 SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
61 CORBA::Long studyId );
63 virtual ~SMESH_Mesh_i();
67 void SetShape( GEOM::GEOM_Object_ptr theShapeObject )
68 throw (SALOME::SALOME_Exception);
70 CORBA::Boolean HasShapeToMesh()
71 throw (SALOME::SALOME_Exception);
73 GEOM::GEOM_Object_ptr GetShapeToMesh()
74 throw (SALOME::SALOME_Exception);
76 CORBA::Boolean IsLoaded()
77 throw (SALOME::SALOME_Exception);
80 throw (SALOME::SALOME_Exception);
83 throw (SALOME::SALOME_Exception);
85 void ClearSubMesh(CORBA::Long ShapeID)
86 throw (SALOME::SALOME_Exception);
88 SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
89 SMESH::SMESH_Hypothesis_ptr anHyp)
90 throw (SALOME::SALOME_Exception);
92 SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
93 SMESH::SMESH_Hypothesis_ptr anHyp)
94 throw (SALOME::SALOME_Exception);
96 SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
97 throw (SALOME::SALOME_Exception);
99 SMESH::submesh_array* GetSubMeshes()
100 throw (SALOME::SALOME_Exception);
102 SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject, const char* theName)
103 throw (SALOME::SALOME_Exception);
105 void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
106 throw (SALOME::SALOME_Exception);
108 SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName )
109 throw (SALOME::SALOME_Exception);
111 SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType theElemType,
113 GEOM::GEOM_Object_ptr theGeomObj )
114 throw (SALOME::SALOME_Exception);
116 SMESH::SMESH_GroupOnFilter_ptr CreateGroupFromFilter(SMESH::ElementType theElemType,
118 SMESH::Filter_ptr theFilter )
119 throw (SALOME::SALOME_Exception);
121 void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
122 throw (SALOME::SALOME_Exception);
124 void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
125 throw (SALOME::SALOME_Exception);
127 SMESH::ListOfGroups* GetGroups()
128 throw (SALOME::SALOME_Exception);
130 CORBA::Long NbGroups()
131 throw (SALOME::SALOME_Exception);
133 SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
134 SMESH::SMESH_GroupBase_ptr theGroup2,
135 const char* theName )
136 throw (SALOME::SALOME_Exception);
138 SMESH::SMESH_Group_ptr UnionListOfGroups( const SMESH::ListOfGroups& theGroups,
140 throw (SALOME::SALOME_Exception);
142 SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
143 SMESH::SMESH_GroupBase_ptr theGroup2,
144 const char* theName )
145 throw (SALOME::SALOME_Exception);
147 SMESH::SMESH_Group_ptr IntersectListOfGroups( const SMESH::ListOfGroups& theGroups,
148 const char* theName )
149 throw (SALOME::SALOME_Exception);
151 SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
152 SMESH::SMESH_GroupBase_ptr theGroup2,
153 const char* theName )
154 throw (SALOME::SALOME_Exception);
156 SMESH::SMESH_Group_ptr CutListOfGroups( const SMESH::ListOfGroups& theMainGroups,
157 const SMESH::ListOfGroups& theToolGroups,
158 const char* theName )
159 throw (SALOME::SALOME_Exception);
161 SMESH::SMESH_Group_ptr CreateDimGroup( const SMESH::ListOfGroups& theGroups,
162 SMESH::ElementType theElemType,
163 const char* theName )
164 throw (SALOME::SALOME_Exception);
167 SMESH::SMESH_Group_ptr ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroupOn )
168 throw (SALOME::SALOME_Exception);
170 SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet)
171 throw (SALOME::SALOME_Exception);
173 SMESH::SMESH_MeshEditor_ptr GetMeshEditor() throw (SALOME::SALOME_Exception);
175 SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer() throw (SALOME::SALOME_Exception);
177 CORBA::Boolean HasModificationsToDiscard() throw (SALOME::SALOME_Exception);
179 void ClearLog() throw (SALOME::SALOME_Exception);
181 CORBA::Long GetId() throw (SALOME::SALOME_Exception);
183 CORBA::Long GetStudyId() throw (SALOME::SALOME_Exception);
187 void SetImpl(::SMESH_Mesh* impl);
188 ::SMESH_Mesh& GetImpl(); // :: force no namespace here
190 SMESH_Gen_i* GetGen() { return _gen_i; }
192 int ImportUNVFile( const char* theFileName )
193 throw (SALOME::SALOME_Exception);
195 int ImportSTLFile( const char* theFileName )
196 throw (SALOME::SALOME_Exception);
198 SMESH::ComputeError* ImportGMFFile( const char* theFileName,
199 bool theMakeRequiredGroups)
200 throw (SALOME::SALOME_Exception);
203 * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
205 SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName )
206 throw (SALOME::SALOME_Exception);
208 SMESH::DriverMED_ReadStatus ImportCGNSFile( const char* theFileName,
209 const int theMeshIndex,
210 std::string& theMeshName)
211 throw (SALOME::SALOME_Exception);
216 void SetAutoColor(CORBA::Boolean theAutoColor)
217 throw (SALOME::SALOME_Exception);
219 CORBA::Boolean GetAutoColor()
220 throw (SALOME::SALOME_Exception);
222 /*! Check group names for duplications.
223 * Consider maximum group name length stored in MED file.
225 CORBA::Boolean HasDuplicatedGroupNamesMED();
227 * Return string representation of a MED file version comprising nbDigits
229 char* GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits);
231 void ExportToMEDX( const char* file,
232 CORBA::Boolean auto_groups,
233 SMESH::MED_VERSION version,
234 CORBA::Boolean overwrite,
235 CORBA::Boolean autoDimension=true) throw (SALOME::SALOME_Exception);
236 void ExportToMED ( const char* file,
237 CORBA::Boolean auto_groups,
238 SMESH::MED_VERSION version ) throw (SALOME::SALOME_Exception);
239 void ExportMED ( const char* file,
240 CORBA::Boolean auto_groups ) throw (SALOME::SALOME_Exception);
242 void ExportSAUV( const char* file, CORBA::Boolean auto_groups ) throw (SALOME::SALOME_Exception);
244 void ExportDAT( const char* file ) throw (SALOME::SALOME_Exception);
245 void ExportUNV( const char* file ) throw (SALOME::SALOME_Exception);
246 void ExportSTL( const char* file, bool isascii ) throw (SALOME::SALOME_Exception);
247 void ExportCGNS(SMESH::SMESH_IDSource_ptr meshPart,
249 CORBA::Boolean overwrite) throw (SALOME::SALOME_Exception);
250 void ExportGMF(SMESH::SMESH_IDSource_ptr meshPart,
252 CORBA::Boolean withRequiredGroups) throw (SALOME::SALOME_Exception);
254 void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
256 CORBA::Boolean auto_groups,
257 SMESH::MED_VERSION version,
258 CORBA::Boolean overwrite,
259 CORBA::Boolean autoDim=true) throw (SALOME::SALOME_Exception);
260 void ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart,
261 const char* file) throw (SALOME::SALOME_Exception);
262 void ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart,
263 const char* file) throw (SALOME::SALOME_Exception);
264 void ExportPartToSTL(SMESH::SMESH_IDSource_ptr meshPart,
266 CORBA::Boolean isascii) throw (SALOME::SALOME_Exception);
268 SALOME_MED::MESH_ptr GetMEDMesh()
269 throw (SALOME::SALOME_Exception);
271 CORBA::Long NbNodes()
272 throw (SALOME::SALOME_Exception);
274 CORBA::Long NbElements()
275 throw (SALOME::SALOME_Exception);
277 CORBA::Long Nb0DElements()
278 throw (SALOME::SALOME_Exception);
280 CORBA::Long NbBalls()
281 throw (SALOME::SALOME_Exception);
283 CORBA::Long NbEdges()
284 throw (SALOME::SALOME_Exception);
286 CORBA::Long NbEdgesOfOrder(SMESH::ElementOrder order)
287 throw (SALOME::SALOME_Exception);
289 CORBA::Long NbFaces()
290 throw (SALOME::SALOME_Exception);
292 CORBA::Long NbFacesOfOrder(SMESH::ElementOrder order)
293 throw (SALOME::SALOME_Exception);
295 CORBA::Long NbTriangles()
296 throw (SALOME::SALOME_Exception);
298 CORBA::Long NbTrianglesOfOrder(SMESH::ElementOrder order)
299 throw (SALOME::SALOME_Exception);
301 CORBA::Long NbBiQuadTriangles()
302 throw (SALOME::SALOME_Exception);
304 CORBA::Long NbQuadrangles()
305 throw (SALOME::SALOME_Exception);
307 CORBA::Long NbQuadranglesOfOrder(SMESH::ElementOrder order)
308 throw (SALOME::SALOME_Exception);
310 CORBA::Long NbBiQuadQuadrangles()
311 throw (SALOME::SALOME_Exception);
313 CORBA::Long NbPolygons()
314 throw (SALOME::SALOME_Exception);
316 CORBA::Long NbVolumes()
317 throw (SALOME::SALOME_Exception);
319 CORBA::Long NbVolumesOfOrder(SMESH::ElementOrder order)
320 throw (SALOME::SALOME_Exception);
322 CORBA::Long NbTetras()
323 throw (SALOME::SALOME_Exception);
325 CORBA::Long NbTetrasOfOrder(SMESH::ElementOrder order)
326 throw (SALOME::SALOME_Exception);
328 CORBA::Long NbHexas()
329 throw (SALOME::SALOME_Exception);
331 CORBA::Long NbHexasOfOrder(SMESH::ElementOrder order)
332 throw (SALOME::SALOME_Exception);
334 CORBA::Long NbTriQuadraticHexas()
335 throw (SALOME::SALOME_Exception);
337 CORBA::Long NbPyramids()
338 throw (SALOME::SALOME_Exception);
340 CORBA::Long NbPyramidsOfOrder(SMESH::ElementOrder order)
341 throw (SALOME::SALOME_Exception);
343 CORBA::Long NbPrisms()
344 throw (SALOME::SALOME_Exception);
346 CORBA::Long NbPrismsOfOrder(SMESH::ElementOrder order)
347 throw (SALOME::SALOME_Exception);
349 CORBA::Long NbHexagonalPrisms()
350 throw (SALOME::SALOME_Exception);
352 CORBA::Long NbPolyhedrons()
353 throw (SALOME::SALOME_Exception);
355 CORBA::Long NbSubMesh()
356 throw (SALOME::SALOME_Exception);
358 SMESH::long_array* GetElementsId()
359 throw (SALOME::SALOME_Exception);
361 SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType )
362 throw (SALOME::SALOME_Exception);
364 SMESH::long_array* GetNodesId()
365 throw (SALOME::SALOME_Exception);
367 SMESH::ElementType GetElementType( CORBA::Long id, bool iselem )
368 throw (SALOME::SALOME_Exception);
370 SMESH::EntityType GetElementGeomType( CORBA::Long id )
371 throw (SALOME::SALOME_Exception);
374 * Returns ID of elements for given submesh
376 SMESH::long_array* GetSubMeshElementsId(CORBA::Long ShapeID)
377 throw (SALOME::SALOME_Exception);
380 * Returns ID of nodes for given submesh
381 * If param all==true - returns all nodes, else -
382 * returns only nodes on shapes.
384 SMESH::long_array* GetSubMeshNodesId(CORBA::Long ShapeID, CORBA::Boolean all)
385 throw (SALOME::SALOME_Exception);
388 * Returns type of elements for given submesh
390 SMESH::ElementType GetSubMeshElementType(CORBA::Long ShapeID)
391 throw (SALOME::SALOME_Exception);
395 // Create groups of elements preventing computation of a sub-shape
396 SMESH::ListOfGroups* MakeGroupsOfBadInputElements( int theSubShapeID,
397 const char* theGroupName)
398 throw (SALOME::SALOME_Exception);
400 // Internal methods not available through CORBA
401 // They are called by corresponding interface methods
402 SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
403 SMESH::SMESH_Hypothesis_ptr anHyp);
405 SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
406 SMESH::SMESH_Hypothesis_ptr anHyp);
408 static SMESH::Hypothesis_Status
409 ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
411 static void PrepareForWriting (const char* file, bool overwrite = true);
413 //int importMEDFile( const char* theFileName, const char* theMeshName );
415 SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
417 bool removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
418 GEOM::GEOM_Object_ptr theSubShapeObject );
420 SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType theElemType,
422 const TopoDS_Shape& theShape = TopoDS_Shape(),
423 const SMESH_PredicatePtr& thePred = SMESH_PredicatePtr());
425 void removeGroup( const int theId );
427 SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
428 // return an existing subMesh object for the shapeID. shapeID == submeshID.
430 const std::map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
431 // return existing group objects
433 void onHypothesisModified();
434 // callback from _impl to forget not loaded mesh data (issue 0021208)
436 void checkMeshLoaded();
439 * \brief Update hypotheses assigned to geom groups if the latter change
441 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
443 void CheckGeomGroupModif();
445 CORBA::LongLong GetMeshPtr();
448 * \brief Assure that all groups are published
450 void CreateGroupServants();
453 * \brief Return groups cantained in _mapGroups by their IDs
455 SMESH::ListOfGroups* GetGroups(const std::list<int>& groupIDs) const;
458 * Get XYZ coordinates of node as list of double
459 * If there is not node for given ID - returns empty list
461 SMESH::double_array* GetNodeXYZ(CORBA::Long id);
464 * For given node returns list of IDs of inverse elements
465 * If there is not node for given ID - returns empty list
467 SMESH::long_array* GetNodeInverseElements(CORBA::Long id);
470 * \brief Return position of a node on shape
472 SMESH::NodePosition* GetNodePosition(CORBA::Long NodeID);
475 * \brief Return position of an element on shape
477 SMESH::ElementPosition GetElementPosition(CORBA::Long ElemID);
480 * If given element is node returns IDs of shape from position
481 * If there is not node for given ID - returns -1
483 CORBA::Long GetShapeID(CORBA::Long id);
486 * For given element returns ID of result shape after
487 * ::FindShape() from SMESH_MeshEditor
488 * If there is not element for given ID - returns -1
490 CORBA::Long GetShapeIDForElem(CORBA::Long id);
493 * Returns number of nodes for given element
494 * If there is not element for given ID - returns -1
496 CORBA::Long GetElemNbNodes(CORBA::Long id);
499 * Returns IDs of nodes of given element
501 SMESH::long_array* GetElemNodes(CORBA::Long id);
504 * Returns ID of node by given index for given element
505 * If there is not element for given ID - returns -1
506 * If there is not node for given index - returns -2
508 CORBA::Long GetElemNode(CORBA::Long id, CORBA::Long index);
511 * Returns true if given node is medium node
512 * in given quadratic element
514 CORBA::Boolean IsMediumNode(CORBA::Long ide, CORBA::Long idn);
517 * Returns true if given node is medium node
518 * in one of quadratic elements
520 CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn,
521 SMESH::ElementType theElemType);
524 * Returns number of edges for given element
526 CORBA::Long ElemNbEdges(CORBA::Long id);
529 * Returns number of faces for given element
531 CORBA::Long ElemNbFaces(CORBA::Long id);
533 * Returns nodes of given face (counted from zero) for given element.
535 SMESH::long_array* GetElemFaceNodes(CORBA::Long elemId, CORBA::Short faceIndex);
538 * Returns an element based on all given nodes.
540 CORBA::Long FindElementByNodes(const SMESH::long_array& nodes);
543 * Returns true if given element is polygon
545 CORBA::Boolean IsPoly(CORBA::Long id);
548 * Returns true if given element is quadratic
550 CORBA::Boolean IsQuadratic(CORBA::Long id);
553 * Returns diameter of ball discrete element or zero in case of an invalid \a id
555 CORBA::Double GetBallDiameter(CORBA::Long id);
558 * Returns bary center for given element
560 SMESH::double_array* BaryCenter(CORBA::Long id);
563 * Returns information about imported MED file
565 virtual SALOME_MED::MedFileInfo* GetMEDFileInfo();
568 * Sets list of notebook variables used for Mesh operations separated by ":" symbol
570 void SetParameters (const char* theParameters);
573 * Returns list of notebook variables used for Mesh operations separated by ":" symbol
575 char* GetParameters();
578 * Returns list of notebook variables used for last Mesh operation
580 SMESH::string_array* GetLastParameters();
583 * Collect statistic of mesh elements given by iterator
585 static void CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
586 SMESH::long_array& theInfo);
589 * \brief Return submesh objects list in meshing order
591 virtual SMESH::submesh_array_array* GetMeshOrder();
593 * \brief Set submesh object order
595 virtual ::CORBA::Boolean SetMeshOrder(const SMESH::submesh_array_array& theSubMeshArray);
598 // =========================
599 // SMESH_IDSource interface
600 // =========================
602 virtual SMESH::long_array* GetIDs();
604 * Returns statistic of mesh elements
605 * Result array of number enityties
606 * Inherited from SMESH_IDSource
608 virtual SMESH::long_array* GetMeshInfo();
610 * Returns types of elements it contains
612 virtual SMESH::array_of_ElementType* GetTypes();
616 virtual SMESH::SMESH_Mesh_ptr GetMesh();
618 * Returns false if GetMeshInfo() returns incorrect information that may
619 * happen if mesh data is not yet fully loaded from the file of study.
621 bool IsMeshInfoCorrect();
623 std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
624 std::map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
627 std::string prepareMeshNameAndGroups( const char* file, CORBA::Boolean overwrite );
630 * Check and correct names of mesh groups
632 void checkGroupNames();
635 * Convert submesh ids into submesh interfaces
637 void convertMeshOrder(const TListOfListOfInt& theIdsOrder,
638 SMESH::submesh_array_array& theSubMeshOrder,
639 const bool theIsDump);
643 static int _idGenerator;
644 ::SMESH_Mesh* _impl; // :: force no namespace here
646 int _id; // id given by creator (unique within the creator instance)
648 std::map<int, SMESH::SMESH_subMesh_ptr> _mapSubMeshIor;
649 std::map<int, SMESH::SMESH_GroupBase_ptr> _mapGroups;
650 std::map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
651 SALOME_MED::MedFileInfo_var _medFileInfo;
652 SMESH_PreMeshInfo* _preMeshInfo; // mesh info before full loading from study file
654 SMESH_PreMeshInfo* & changePreMeshInfo() { return _preMeshInfo; }
655 friend class SMESH_PreMeshInfo;
659 // Data used to track changes of GEOM groups
660 struct TGeomGroupData {
661 // keep study entry but not ior because GEOM_Object actually changes if
662 // number of items in a group varies (1) <-> (>1)
663 std::string _groupEntry;
664 std::set<int> _indices; // indices of group items within group's main shape
665 CORBA::Object_ptr _smeshObject; // SMESH object depending on GEOM group
667 std::list<TGeomGroupData> _geomGroupData;
670 * Remember GEOM group data
672 void addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
673 CORBA::Object_ptr theSmeshObj);
675 * Remove GEOM group data relating to removed smesh object
677 void removeGeomGroupData(CORBA::Object_ptr theSmeshObj);
679 * \brief Return new group contents if it has been changed and update group data
681 TopoDS_Shape newGroupShape( TGeomGroupData & groupData);