1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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 "SMESH_Hypothesis.hxx"
32 #include "SMESH_Mesh.hxx"
33 #include "SMESH_subMesh.hxx"
34 #include "SMDS_ElemIterator.hxx"
36 #include <SALOME_GenericObj_i.hh>
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SMESH_Gen)
39 #include CORBA_SERVER_HEADER(SMESH_Mesh)
40 #include CORBA_SERVER_HEADER(SMESH_Group)
41 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
42 #include CORBA_CLIENT_HEADER(GEOM_Gen)
47 class SMESH_GroupBase_i;
48 class SMESH_subMesh_i;
49 class SMESH_PreMeshInfo;
50 class SMESH_MeshEditor_i;
51 class DriverMED_W_Field;
54 class SMESH_I_EXPORT SMESH_Mesh_i:
55 public virtual POA_SMESH::SMESH_Mesh,
56 public virtual SALOME::GenericObj_i
59 SMESH_Mesh_i(const SMESH_Mesh_i&);
61 SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
62 SMESH_Gen_i* myGen_i );
64 virtual ~SMESH_Mesh_i();
68 void SetShape( GEOM::GEOM_Object_ptr theShapeObject );
70 CORBA::Boolean HasShapeToMesh();
72 GEOM::GEOM_Object_ptr GetShapeToMesh();
74 virtual void ReplaceShape(GEOM::GEOM_Object_ptr theNewGeom);
76 CORBA::Boolean IsLoaded();
82 void ClearSubMesh(CORBA::Long ShapeID);
84 SMESH::Hypothesis_Status AddHypothesis(GEOM::GEOM_Object_ptr aSubShape,
85 SMESH::SMESH_Hypothesis_ptr anHyp,
86 CORBA::String_out anErrorText);
88 SMESH::Hypothesis_Status RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShape,
89 SMESH::SMESH_Hypothesis_ptr anHyp);
91 SMESH::ListOfHypothesis* GetHypothesisList(GEOM::GEOM_Object_ptr aSubShape);
93 SMESH::submesh_array* GetSubMeshes();
95 SMESH::SMESH_subMesh_ptr GetSubMesh(GEOM::GEOM_Object_ptr aSubShape, const char* theName);
97 void RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh );
99 SMESH::SMESH_Group_ptr CreateGroup( SMESH::ElementType theElemType, const char* theName );
101 SMESH::SMESH_GroupOnGeom_ptr CreateGroupFromGEOM(SMESH::ElementType theElemType,
103 GEOM::GEOM_Object_ptr theGeomObj );
105 SMESH::SMESH_GroupOnFilter_ptr CreateGroupFromFilter(SMESH::ElementType theElemType,
107 SMESH::Filter_ptr theFilter );
109 void RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup );
111 void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup );
113 SMESH::ListOfGroups* GetGroups();
115 CORBA::Long NbGroups();
117 SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
118 SMESH::SMESH_GroupBase_ptr theGroup2,
119 const char* theName );
121 SMESH::SMESH_Group_ptr UnionListOfGroups( const SMESH::ListOfGroups& theGroups,
122 const char* theName);
124 SMESH::SMESH_Group_ptr IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
125 SMESH::SMESH_GroupBase_ptr theGroup2,
126 const char* theName );
128 SMESH::SMESH_Group_ptr IntersectListOfGroups( const SMESH::ListOfGroups& theGroups,
129 const char* theName );
131 SMESH::SMESH_Group_ptr CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
132 SMESH::SMESH_GroupBase_ptr theGroup2,
133 const char* theName );
135 SMESH::SMESH_Group_ptr CutListOfGroups( const SMESH::ListOfGroups& theMainGroups,
136 const SMESH::ListOfGroups& theToolGroups,
137 const char* theName );
139 SMESH::SMESH_Group_ptr CreateDimGroup( const SMESH::ListOfIDSources& theGroups,
140 SMESH::ElementType theElemType,
142 SMESH::NB_COMMON_NODES_ENUM theNbCommonNodes,
143 CORBA::Boolean theUnderlyingOnly );
145 SMESH::ListOfGroups* FaceGroupsSeparatedByEdges( CORBA::Double theSharpAngle,
146 CORBA::Boolean theCreateEdges,
147 CORBA::Boolean theUseExistingEdges );
149 SMESH::SMESH_Group_ptr ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroupOn );
151 SMESH::log_array* GetLog(CORBA::Boolean clearAfterGet);
153 SMESH::SMESH_MeshEditor_ptr GetMeshEditor();
155 SMESH::SMESH_MeshEditor_ptr GetMeshEditPreviewer();
157 CORBA::Boolean HasModificationsToDiscard();
165 void SetImpl(::SMESH_Mesh* impl);
166 ::SMESH_Mesh& GetImpl(); // :: force no namespace here
168 SMESH_Gen_i* GetGen() { return _gen_i; }
170 int ImportUNVFile( const char* theFileName );
172 int ImportSTLFile( const char* theFileName );
174 SMESH::ComputeError* ImportGMFFile( const char* theFileName,
175 bool theMakeRequiredGroups);
178 * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
180 SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName );
182 SMESH::DriverMED_ReadStatus ImportCGNSFile( const char* theFileName,
183 const int theMeshIndex,
184 std::string& theMeshName);
189 void SetAutoColor(CORBA::Boolean theAutoColor);
191 CORBA::Boolean GetAutoColor();
193 /*! Check group names for duplications.
194 * Consider maximum group name length stored in MED file.
196 CORBA::Boolean HasDuplicatedGroupNamesMED();
199 * Return string representation of a MED file version comprising nbDigits
201 char* GetVersionString(CORBA::Long minor, CORBA::Short nbDigits);
204 * Return the list of med versions compatibles for write/append,
205 * encoded in 10*major+minor (for instance, code for med 3.2.1 is 32)
207 SMESH::long_array* GetMEDVersionsCompatibleForAppend();
209 void ExportMED( const char* file,
210 CORBA::Boolean auto_groups,
212 CORBA::Boolean overwrite,
213 CORBA::Boolean autoDimension = true);
215 CORBA::LongLong ExportMEDCoupling(CORBA::Boolean auto_groups,
216 CORBA::Boolean autoDimension = true);
218 void ExportSAUV( const char* file, CORBA::Boolean auto_groups );
220 void ExportDAT( const char* file, const CORBA::Boolean renumber );
221 void ExportUNV( const char* file, const CORBA::Boolean renumber );
222 void ExportSTL( const char* file, bool isascii );
223 void ExportCGNS(SMESH::SMESH_IDSource_ptr meshPart,
225 CORBA::Boolean overwrite,
226 CORBA::Boolean groupElemsByType);
227 void ExportGMF(SMESH::SMESH_IDSource_ptr meshPart,
229 CORBA::Boolean withRequiredGroups);
232 template<class SPECLS>
233 void ExportPartToMEDCommon(SPECLS& speCls,
234 SMESH::SMESH_IDSource_ptr meshPart,
235 CORBA::Boolean auto_groups,
236 CORBA::Boolean autoDim,
237 const GEOM::ListOfFields& fields,
238 const char* geomAssocFields,
239 CORBA::Double ZTolerance,
240 CORBA::Boolean saveNumbers );
242 void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
244 CORBA::Boolean auto_groups,
246 CORBA::Boolean overwrite,
247 CORBA::Boolean autoDim,
248 const GEOM::ListOfFields& fields,
249 const char* geomAssocFields,
250 CORBA::Double ZTolerance,
251 CORBA::Boolean saveNumbers );
253 CORBA::LongLong ExportPartToMEDCoupling(SMESH::SMESH_IDSource_ptr meshPart,
254 CORBA::Boolean auto_groups,
255 CORBA::Boolean autoDim,
256 const GEOM::ListOfFields& fields,
257 const char* geomAssocFields,
258 CORBA::Double ZTolerance,
259 CORBA::Boolean saveNumbers);
261 void ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart,
263 CORBA::Boolean renumber);
264 void ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart,
266 CORBA::Boolean renumber);
267 void ExportPartToSTL(SMESH::SMESH_IDSource_ptr meshPart,
269 CORBA::Boolean isascii);
271 CORBA::Double GetComputeProgress();
273 SMESH::smIdType NbNodes();
275 SMESH::smIdType NbElements();
277 SMESH::smIdType Nb0DElements();
279 SMESH::smIdType NbBalls();
281 SMESH::smIdType NbEdges();
283 SMESH::smIdType NbEdgesOfOrder(SMESH::ElementOrder order);
285 SMESH::smIdType NbFaces();
287 SMESH::smIdType NbFacesOfOrder(SMESH::ElementOrder order);
289 SMESH::smIdType NbTriangles();
291 SMESH::smIdType NbTrianglesOfOrder(SMESH::ElementOrder order);
293 SMESH::smIdType NbBiQuadTriangles();
295 SMESH::smIdType NbQuadrangles();
297 SMESH::smIdType NbQuadranglesOfOrder(SMESH::ElementOrder order);
299 SMESH::smIdType NbBiQuadQuadrangles();
301 SMESH::smIdType NbPolygons();
303 SMESH::smIdType NbPolygonsOfOrder(SMESH::ElementOrder order = SMESH::ORDER_ANY);
305 SMESH::smIdType NbVolumes();
307 SMESH::smIdType NbVolumesOfOrder(SMESH::ElementOrder order);
309 SMESH::smIdType NbTetras();
311 SMESH::smIdType NbTetrasOfOrder(SMESH::ElementOrder order);
313 SMESH::smIdType NbHexas();
315 SMESH::smIdType NbHexasOfOrder(SMESH::ElementOrder order);
317 SMESH::smIdType NbTriQuadraticHexas();
319 SMESH::smIdType NbPyramids();
321 SMESH::smIdType NbPyramidsOfOrder(SMESH::ElementOrder order);
323 SMESH::smIdType NbPrisms();
325 SMESH::smIdType NbPrismsOfOrder(SMESH::ElementOrder order);
327 SMESH::smIdType NbHexagonalPrisms();
329 SMESH::smIdType NbPolyhedrons();
331 SMESH::smIdType NbSubMesh();
333 SMESH::smIdType_array* GetElementsId();
335 SMESH::smIdType_array* GetElementsByType( SMESH::ElementType theElemType );
337 SMESH::smIdType_array* GetNodesId();
339 SMESH::ElementType GetElementType( SMESH::smIdType id, bool iselem );
341 SMESH::EntityType GetElementGeomType( SMESH::smIdType id );
343 SMESH::GeometryType GetElementShape( SMESH::smIdType id );
346 * Returns ID of elements for given submesh
348 SMESH::smIdType_array* GetSubMeshElementsId(CORBA::Long ShapeID);
351 * Returns ID of nodes for given submesh
352 * If param all==true - returns all nodes, else -
353 * returns only nodes on shapes.
355 SMESH::smIdType_array* GetSubMeshNodesId(CORBA::Long ShapeID, CORBA::Boolean all);
358 * Returns type of elements for given submesh
360 SMESH::ElementType GetSubMeshElementType(CORBA::Long ShapeID);
364 // Create groups of elements preventing computation of a sub-shape
365 SMESH::ListOfGroups* MakeGroupsOfBadInputElements( int theSubShapeID,
366 const char* theGroupName);
368 // ===================================================
369 // Internal methods not available through CORBA
370 // They are called by corresponding interface methods
371 // ===================================================
373 SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShape,
374 SMESH::SMESH_Hypothesis_ptr anHyp,
375 std::string* anErrorText=0);
377 SMESH_Hypothesis::Hypothesis_Status removeHypothesis(GEOM::GEOM_Object_ptr aSubShape,
378 SMESH::SMESH_Hypothesis_ptr anHyp);
380 static SMESH::Hypothesis_Status
381 ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
383 static void PrepareForWriting (const char* file, bool overwrite = true);
385 //int importMEDFile( const char* theFileName, const char* theMeshName );
387 SMESH::SMESH_subMesh_ptr createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject );
389 bool removeSubMesh(SMESH::SMESH_subMesh_ptr theSubMesh,
390 GEOM::GEOM_Object_ptr theSubShapeObject );
392 SMESH::SMESH_GroupBase_ptr createGroup(SMESH::ElementType theElemType,
394 const int theID = -1,
395 const TopoDS_Shape& theShape = TopoDS_Shape(),
396 const SMESH_PredicatePtr& thePred = SMESH_PredicatePtr());
398 void removeGroup( const int theId );
400 SMESH::SMESH_subMesh_ptr getSubMesh(int shapeID);
401 // return an existing subMesh object for the shapeID. shapeID == submeshID.
403 const std::map<int, SMESH::SMESH_GroupBase_ptr>& getGroups() { return _mapGroups; }
404 // return existing group objects
406 void onHypothesisModified(int theHypID, bool updateIcons);
407 // callback from _impl to forget not loaded mesh data (issue 0021208)
410 * \brief Update data if geometry changes
414 void CheckGeomModif( bool isBreakLink = false );
416 * \brief Update hypotheses assigned to geom groups if the latter change
418 * NPAL16168: "geometrical group edition from a submesh don't modify mesh computation"
420 void CheckGeomGroupModif();
422 CORBA::LongLong GetMeshPtr();
425 * \brief Assure that all groups are published
427 void CreateGroupServants();
430 * \brief Return true if all sub-meshes are computed OK - to update an icon
435 // ====================================
436 // SMESH_Mesh interface (continuation)
437 // ====================================
440 * \brief Return groups cantained in _mapGroups by their IDs
442 SMESH::ListOfGroups* GetGroups(const std::list<int>& groupIDs) const;
445 * Get XYZ coordinates of node as list of double
446 * If there is not node for given ID - returns empty list
448 SMESH::double_array* GetNodeXYZ(SMESH::smIdType id);
451 * For given node returns list of IDs of inverse elements
452 * If there is not node for given ID - returns empty list
454 SMESH::smIdType_array* GetNodeInverseElements(SMESH::smIdType id,
455 SMESH::ElementType elemType);
458 * \brief Return position of a node on shape
460 SMESH::NodePosition* GetNodePosition(SMESH::smIdType NodeID);
463 * \brief Return position of an element on shape
465 SMESH::ElementPosition GetElementPosition(SMESH::smIdType ElemID);
468 * If given element is node returns IDs of shape from position
469 * If there is not node for given ID - returns -1
471 CORBA::Long GetShapeID(SMESH::smIdType id);
474 * For given element returns ID of result shape after
475 * ::FindShape() from SMESH_MeshEditor
476 * If there is not element for given ID - returns -1
478 CORBA::Long GetShapeIDForElem(SMESH::smIdType id);
481 * Returns number of nodes for given element
482 * If there is not element for given ID - returns -1
484 CORBA::Short GetElemNbNodes(SMESH::smIdType id);
487 * Returns IDs of nodes of given element
489 SMESH::smIdType_array* GetElemNodes(SMESH::smIdType id);
492 * Returns ID of node by given index for given element
493 * If there is not element for given ID - returns -1
494 * If there is not node for given index - returns -2
496 SMESH::smIdType GetElemNode(SMESH::smIdType id, CORBA::Short index);
499 * Returns true if given node is medium node
500 * in given quadratic element
502 CORBA::Boolean IsMediumNode(SMESH::smIdType ide, SMESH::smIdType idn);
505 * Returns true if given node is medium node
506 * in one of quadratic elements
508 CORBA::Boolean IsMediumNodeOfAnyElem(SMESH::smIdType idn,
509 SMESH::ElementType elemType);
512 * Returns number of edges for given element
514 CORBA::Long ElemNbEdges(SMESH::smIdType id);
517 * Returns number of faces for given element
519 CORBA::Long ElemNbFaces(SMESH::smIdType id);
521 * Returns nodes of given face (counted from zero) for given element.
523 SMESH::smIdType_array* GetElemFaceNodes(SMESH::smIdType elemId, CORBA::Short faceIndex);
526 * Returns three components of normal of given mesh face (or an empty array in KO case)
528 SMESH::double_array* GetFaceNormal(CORBA::Long faceId, CORBA::Boolean normalized);
531 * Returns an element based on all given nodes.
533 SMESH::smIdType FindElementByNodes(const SMESH::smIdType_array& nodes);
536 * Return elements including all given nodes.
538 SMESH::smIdType_array* GetElementsByNodes(const SMESH::smIdType_array& nodes,
539 SMESH::ElementType elemType);
542 * Returns true if given element is polygon
544 CORBA::Boolean IsPoly(SMESH::smIdType id);
547 * Returns true if given element is quadratic
549 CORBA::Boolean IsQuadratic(SMESH::smIdType id);
552 * Returns diameter of ball discrete element or zero in case of an invalid \a id
554 CORBA::Double GetBallDiameter(SMESH::smIdType id);
557 * Returns bary center for given element
559 SMESH::double_array* BaryCenter(SMESH::smIdType id);
562 * Returns information about imported MED file
564 virtual SMESH::MedFileInfo* GetMEDFileInfo();
567 * Persistence of file info
569 std::string FileInfoToString();
570 void FileInfoFromString(const std::string& info);
573 * Persistence of geometry tick
575 int& MainShapeTick() { return _mainShapeTick; }
579 * Sets list of notebook variables used for Mesh operations separated by ":" symbol
581 void SetParameters (const char* theParameters);
584 * Returns list of notebook variables used for Mesh operations separated by ":" symbol
586 char* GetParameters();
589 * Returns list of notebook variables used for last Mesh operation
591 SMESH::string_array* GetLastParameters();
594 * \brief Return \c true if a meshing order not yet set for a concurrent sub-mesh
596 CORBA::Boolean IsUnorderedSubMesh(CORBA::Long submeshID);
598 * \brief Return submesh objects list in meshing order
600 virtual SMESH::submesh_array_array* GetMeshOrder();
602 * \brief Set submesh object order
604 virtual ::CORBA::Boolean SetMeshOrder(const SMESH::submesh_array_array& theSubMeshArray);
608 * Collect statistic of mesh elements given by iterator
610 static void CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
611 SMESH::smIdType_array& theInfo);
613 * \brief Return iterator on elements of given type in given object
615 static SMDS_ElemIteratorPtr GetElements(SMESH::SMESH_IDSource_ptr obj,
616 SMESH::ElementType type);
618 // =========================
619 // SMESH_IDSource interface
620 // =========================
622 virtual SMESH::smIdType_array* GetIDs();
624 * Returns number of mesh elements of each \a EntityType
625 * Result array of number of elements per \a EntityType
626 * Inherited from SMESH_IDSource
628 virtual SMESH::smIdType_array* GetMeshInfo();
630 * Returns number of mesh elements of each \a ElementType
632 virtual SMESH::smIdType_array* GetNbElementsByType();
634 * Returns types of elements it contains
636 virtual SMESH::array_of_ElementType* GetTypes();
640 virtual SMESH::SMESH_Mesh_ptr GetMesh();
642 * Returns false if GetMeshInfo() returns incorrect information that may
643 * happen if mesh data is not yet fully loaded from the file of study.
645 bool IsMeshInfoCorrect();
647 * Returns mesh unstructed grid information.
649 virtual SALOMEDS::TMPFile* GetVtkUgStream();
652 std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
653 std::map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
656 std::string generateMeshName( );
657 std::string prepareMeshNameAndGroups( const char* file, CORBA::Boolean overwrite );
659 * Write GEOM fields to MED file
661 void exportMEDFields( DriverMED_W_Field & writer,
662 SMESHDS_Mesh* meshDS,
663 const GEOM::ListOfFields& fields,
664 const char* geomAssocFields);
667 * Check and correct names of mesh groups
669 void checkGroupNames();
672 * Convert submesh ids into submesh interfaces
674 void convertMeshOrder(const TListOfListOfInt& theIdsOrder,
675 SMESH::submesh_array_array& theSubMeshOrder,
676 const bool theIsDump);
679 * \brief Finds concurrent sub-meshes
681 TListOfListOfInt findConcurrentSubMeshes();
685 static int _idGenerator;
686 ::SMESH_Mesh* _impl; // :: force no namespace here
688 int _id; // id given by creator (unique within the creator instance)
690 std::map<int, SMESH::SMESH_subMesh_ptr> _mapSubMeshIor;
691 std::map<int, SMESH::SMESH_GroupBase_ptr> _mapGroups;
692 std::map<int, SMESH::SMESH_Hypothesis_ptr> _mapHypo;
693 SMESH_MeshEditor_i* _editor;
694 SMESH_MeshEditor_i* _previewEditor;
695 SMESH::MedFileInfo_var _medFileInfo;
696 SMESH_PreMeshInfo* _preMeshInfo; // mesh info before full loading from study file
698 SMESH_PreMeshInfo* & changePreMeshInfo() { return _preMeshInfo; }
699 friend class SMESH_PreMeshInfo;
703 // Data used to track changes of GEOM groups
704 struct TGeomGroupData {
705 // keep study entry but not ior because GEOM_Object actually changes if
706 // number of items in a group varies (1) <-> (>1)
707 std::string _groupEntry;
708 std::set<int> _indices; // indices of group items within group's main shape
709 CORBA::Object_var _smeshObject; // SMESH object depending on GEOM group
711 std::list<TGeomGroupData> _geomGroupData;
712 int _mainShapeTick; // to track modifications of the meshed shape
715 * Remember GEOM group data
717 void addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
718 CORBA::Object_ptr theSmeshObj);
720 * Remove GEOM group data relating to removed smesh object
722 void removeGeomGroupData(CORBA::Object_ptr theSmeshObj);
724 * Return new group contents if it has been changed and update group data
726 TopoDS_Shape newGroupShape( TGeomGroupData & groupData, int how );