-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
{
if(MYDEBUG) MESSAGE("SMESH_Mesh::~SMESH_Mesh");
- // avoid usual removal of elements while processing RemoveHypothesis( algo ) event
- SMESHDS_SubMeshIteratorPtr smIt = _myMeshDS->SubMeshes();
- while ( smIt->more() )
- const_cast<SMESHDS_SubMesh*>( smIt->next() )->Clear();
+ if ( _myDocument ) // avoid destructing _myMeshDS from ~SMESH_Gen()
+ _myDocument->RemoveMesh( _id );
+ _myDocument = 0;
+
+ // remove self from studyContext
+ if ( _gen )
+ {
+ StudyContextStruct * studyContext = _gen->GetStudyContext();
+ studyContext->mapMesh.erase( _id );
+ }
+
+ _myMeshDS->ClearMesh();
// issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
// Notify event listeners at least that something happens
if ( _callUp) delete _callUp;
_callUp = 0;
- // remove self from studyContext
- if ( _gen )
- {
- StudyContextStruct * studyContext = _gen->GetStudyContext();
- studyContext->mapMesh.erase( _id );
- }
- if ( _myDocument )
- _myDocument->RemoveMesh( _id );
- _myDocument = 0;
-
if ( _myMeshDS ) {
// delete _myMeshDS, in a thread in order not to block closing a study with large meshes
#ifndef WIN32
// Reading groups (sub-meshes are out of scope of MED import functionality)
std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
- int anId;
std::list<TNameAndType>::iterator name_type = aGroupNames.begin();
for ( ; name_type != aGroupNames.end(); name_type++ )
{
- SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
+ SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str() );
if ( aGroup ) {
SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
if ( aGroupDS ) {
SMESH_Hypothesis::Hypothesis_Status
SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
int anHypId,
- std::string* anError ) throw(SALOME_Exception)
+ std::string* anError )
{
Unexpect aCatch(SalomeException);
if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
SMESH_Hypothesis::Hypothesis_Status
SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
- int anHypId) throw( SALOME_Exception )
+ int anHypId)
{
Unexpect aCatch(SalomeException);
if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
const std::list<const SMESHDS_Hypothesis*>&
SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
- throw(SALOME_Exception)
{
return _myMeshDS->GetHypothesis(aSubShape);
}
*/
//=============================================================================
-const std::list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
+const std::list<SMESHDS_Command*> & SMESH_Mesh::GetLog()
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetScript()->GetCommands();
*
*/
//=============================================================================
-void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
+void SMESH_Mesh::ClearLog()
{
Unexpect aCatch(SalomeException);
_myMeshDS->GetScript()->Clear();
//=============================================================================
SMESH_subMesh * SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
- throw(SALOME_Exception)
{
int index = _myMeshDS->ShapeToIndex(aSubShape);
if ( !index && aSubShape.IsNull() )
//=============================================================================
SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
- throw(SALOME_Exception)
{
int index = _myMeshDS->ShapeToIndex(aSubShape);
return GetSubMeshContaining( index );
//=============================================================================
SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
-throw(SALOME_Exception)
{
SMESH_subMesh *aSubMesh = _subMeshHolder->Get( aShapeID );
-
return aSubMesh;
}
std::list<SMESH_subMesh*>
SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
- throw(SALOME_Exception)
{
std::list<SMESH_subMesh*> found;
// algorithm parameter
if (algo)
{
- // look trough hypotheses used by algo
+ // look through hypotheses used by algo
const SMESH_HypoFilter* hypoKind;
if (( hypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() ))) {
std::list <const SMESHDS_Hypothesis * > usedHyps;
if ( !GetMeshDS()->IsUsedHypothesis( hyp ))
return;
- if (_callUp && hyp)
- _callUp->HypothesisModified( hyp->GetID() );
+ int nbEntities = ( _myMeshDS->NbNodes() + _myMeshDS->NbElements() );
+ if ( hyp && _callUp && !_callUp->IsLoaded() ) // for not loaded mesh (#16648)
+ {
+ _callUp->HypothesisModified( hyp->GetID(), /*updateIcons=*/true );
+ nbEntities = ( _myMeshDS->NbNodes() + _myMeshDS->NbElements() ); // after loading mesh
+ }
SMESH_Algo *algo;
const SMESH_HypoFilter* compatibleHypoKind;
}
HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty
GetMeshDS()->Modified();
+
+ int newNbEntities = ( _myMeshDS->NbNodes() + _myMeshDS->NbElements() );
+ if ( hyp && _callUp )
+ _callUp->HypothesisModified( hyp->GetID(), newNbEntities != nbEntities );
}
//=============================================================================
* Auto color functionality
*/
//=============================================================================
-void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
+void SMESH_Mesh::SetAutoColor(bool theAutoColor)
{
Unexpect aCatch(SalomeException);
_isAutoColor = theAutoColor;
}
-bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
+bool SMESH_Mesh::GetAutoColor()
{
Unexpect aCatch(SalomeException);
return _isAutoColor;
* \param [in] theAutoGroups - boolean parameter for creating/not creating
* the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
* the typical use is auto_groups=false.
- * \param [in] theMinor - define the minor version (y, where version is x.y.z) of MED file format.
- * The theMinor must be between 0 and the current minor version of MED file library.
- * If theMinor is equal to -1, the minor version is not changed (default).
- * The major version (x, where version is x.y.z) cannot be changed.
+ * \param [in] theVersion - define the minor (xy, where version is x.y.z) of MED file format.
+ * If theVersion is equal to -1, the minor version is not changed (default).
* \param [in] meshPart - mesh data to export
* \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
- * - 1D if all mesh nodes lie on OX coordinate axis, or
- * - 2D if all mesh nodes lie on XOY coordinate plane, or
- * - 3D in the rest cases.
- * If \a theAutoDimension is \c false, the space dimension is always 3.
+ * - 1D if all mesh nodes lie on OX coordinate axis, or
+ * - 2D if all mesh nodes lie on XOY coordinate plane, or
+ * - 3D in the rest cases.
+ * If \a theAutoDimension is \c false, the space dimension is always 3.
* \param [in] theAddODOnVertices - to create 0D elements on all vertices
* \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413)
+ * \param [in] ZTolerance - tolerance in Z direction. If Z coordinate of a node is close to zero
+ * within a given tolerance, the coordinate is set to zero.
+ * If \a ZTolerance is negative, the node coordinates are kept as is.
* \return int - mesh index in the file
*/
//================================================================================
-void SMESH_Mesh::ExportMED(const char * file,
- const char* theMeshName,
+void SMESH_Mesh::ExportMED(const char * file,
+ const char* theMeshName,
bool theAutoGroups,
int theVersion,
const SMESHDS_Mesh* meshPart,
bool theAutoDimension,
bool theAddODOnVertices,
+ double theZTolerance,
bool theAllElemsToGroup)
- throw(SALOME_Exception)
{
MESSAGE("MED_VERSION:"<< theVersion);
SMESH_TRY;
myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetAutoDimension( theAutoDimension );
myWriter.AddODOnVertices ( theAddODOnVertices );
- if ( !theMeshName )
+ myWriter.SetZTolerance ( theZTolerance );
+ if ( !theMeshName )
myWriter.SetMeshId ( _id );
else {
myWriter.SetMeshId ( -1 );
void SMESH_Mesh::ExportSAUV(const char *file,
const char* theMeshName,
bool theAutoGroups)
- throw(SALOME_Exception)
{
std::string medfilename(file);
medfilename += ".med";
system(cmd.c_str());
ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
/*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
- /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
+ /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
#ifdef WIN32
cmd = "%PYTHONBIN% ";
#else
//================================================================================
void SMESH_Mesh::ExportDAT(const char * file,
- const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
+ const SMESHDS_Mesh* meshPart)
{
Unexpect aCatch(SalomeException);
DriverDAT_W_SMDS_Mesh myWriter;
//================================================================================
void SMESH_Mesh::ExportUNV(const char * file,
- const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
+ const SMESHDS_Mesh* meshPart)
{
Unexpect aCatch(SalomeException);
DriverUNV_W_SMDS_Mesh myWriter;
void SMESH_Mesh::ExportSTL(const char * file,
const bool isascii,
const char * name,
- const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
+ const SMESHDS_Mesh* meshPart)
{
Unexpect aCatch(SalomeException);
DriverSTL_W_SMDS_Mesh myWriter;
*/
//================================================================================
-int SMESH_Mesh::NbNodes() const throw(SALOME_Exception)
+int SMESH_Mesh::NbNodes() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->NbNodes();
*/
//================================================================================
-int SMESH_Mesh::Nb0DElements() const throw(SALOME_Exception)
+int SMESH_Mesh::Nb0DElements() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().Nb0DElements();
*/
//================================================================================
-int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbEdges(order);
*/
//================================================================================
-int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbFaces(order);
*/
//================================================================================
-int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbTriangles(order);
*/
//================================================================================
-int SMESH_Mesh::NbBiQuadTriangles() const throw(SALOME_Exception)
+int SMESH_Mesh::NbBiQuadTriangles() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbBiQuadTriangles();
*/
//================================================================================
-int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
*/
//================================================================================
-int SMESH_Mesh::NbBiQuadQuadrangles() const throw(SALOME_Exception)
+int SMESH_Mesh::NbBiQuadQuadrangles() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbBiQuadQuadrangles();
*/
//================================================================================
-int SMESH_Mesh::NbPolygons(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbPolygons(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbPolygons(order);
*/
//================================================================================
-int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbVolumes(order);
*/
//================================================================================
-int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbTetras(order);
*/
//================================================================================
-int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbHexas(order);
*/
//================================================================================
-int SMESH_Mesh::NbTriQuadraticHexas() const throw(SALOME_Exception)
+int SMESH_Mesh::NbTriQuadraticHexas() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbTriQuadHexas();
*/
//================================================================================
-int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbPyramids(order);
*/
//================================================================================
-int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
+int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbPrisms(order);
}
-int SMESH_Mesh::NbQuadPrisms() const throw (SALOME_Exception)
+int SMESH_Mesh::NbQuadPrisms() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbQuadPrisms();
}
-int SMESH_Mesh::NbBiQuadPrisms() const throw (SALOME_Exception)
+int SMESH_Mesh::NbBiQuadPrisms() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbBiQuadPrisms();
*/
//================================================================================
-int SMESH_Mesh::NbHexagonalPrisms() const throw(SALOME_Exception)
+int SMESH_Mesh::NbHexagonalPrisms() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbHexPrisms();
*/
//================================================================================
-int SMESH_Mesh::NbPolyhedrons() const throw(SALOME_Exception)
+int SMESH_Mesh::NbPolyhedrons() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbPolyhedrons();
*/
//================================================================================
-int SMESH_Mesh::NbBalls() const throw(SALOME_Exception)
+int SMESH_Mesh::NbBalls() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->GetMeshInfo().NbBalls();
*/
//================================================================================
-int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception)
+int SMESH_Mesh::NbSubMesh() const
{
Unexpect aCatch(SalomeException);
return _myMeshDS->NbSubMesh();
return theShape.IsSame(_myMeshDS->ShapeToMesh() );
}
+//=======================================================================
+//function : GetShapeByEntry
+//purpose : return TopoDS_Shape by its study entry
+//=======================================================================
+
+TopoDS_Shape SMESH_Mesh::GetShapeByEntry(const std::string& entry) const
+{
+ return _callUp ? _callUp->GetShapeByEntry( entry ) : TopoDS_Shape();
+}
+
//=============================================================================
/*!
*
SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
const char* theName,
- int& theId,
+ const int theId,
const TopoDS_Shape& theShape,
const SMESH_PredicatePtr& thePredicate)
{
- if (_mapGroup.count(_groupId))
+ if ( _mapGroup.count( theId ))
return NULL;
- theId = _groupId;
- SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape, thePredicate);
+ int id = ( theId < 0 ) ? _groupId : theId;
+ SMESH_Group* aGroup = new SMESH_Group ( id, this, theType, theName, theShape, thePredicate );
GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
- _mapGroup[_groupId++] = aGroup;
+ _mapGroup[ id ] = aGroup;
+ _groupId = 1 + _mapGroup.rbegin()->first;
return aGroup;
}
*/
//================================================================================
-SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exception)
+SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS)
{
- if ( !groupDS )
+ if ( !groupDS )
throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup(): NULL SMESHDS_GroupBase"));
std::map <int, SMESH_Group*>::iterator i_g = _mapGroup.find( groupDS->GetID() );
/*!
* \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
* \retval bool - true if new SMESH_Groups have been created
- *
+ *
*/
//================================================================================
_mapGroup[_groupId] = new SMESH_Group( groupDS );
}
if ( !_mapGroup.empty() )
- _groupId = _mapGroup.rbegin()->first + 1;
+ _groupId = 1 + _mapGroup.rbegin()->first;
return nbGroups < _mapGroup.size();
}
*/
//=============================================================================
-SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
+SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID) const
{
- if (_mapGroup.find(theGroupID) == _mapGroup.end())
+ std::map <int, SMESH_Group*>::const_iterator id_grp = _mapGroup.find( theGroupID );
+ if ( id_grp == _mapGroup.end() )
return NULL;
- return _mapGroup[theGroupID];
+ return id_grp->second;
}
bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const
{
- if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
+ if ( _mySubMeshOrder.empty() || theListToSort.size() < 2 )
return true;
-
- bool res = false;
- std::vector<SMESH_subMesh*> onlyOrderedList, smVec;
- // collect all ordered submeshes in one list as pointers
+
+ // collect all ordered sub-meshes in smVec as pointers
// and get their positions within theListToSort
+
+ std::vector<SMESH_subMesh*> smVec;
typedef std::vector<SMESH_subMesh*>::iterator TPosInList;
- std::map< int, TPosInList > sortedPos;
+ std::map< size_t, size_t > sortedPos; // index in theListToSort to order
TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
+ bool needSort = false;
for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
{
const TListOfInt& listOfId = *listIdsIt;
smVec.push_back( sm );
if ( sm->GetSubMeshDS() && sm->GetSubMeshDS()->IsComplexSubmesh() )
{
+ smVec.reserve( smVec.size() + sm->GetSubMeshDS()->NbSubMeshes() );
SMESHDS_SubMeshIteratorPtr smdsIt = sm->GetSubMeshDS()->GetSubMeshIterator();
while ( smdsIt->more() )
{
// find smVec items in theListToSort
for ( size_t i = 0; i < smVec.size(); ++i )
{
- TPosInList smPos = find( smBeg, smEnd, smVec[i] );
- if ( smPos != smEnd ) {
- sortedPos[ std::distance( smBeg, smPos )] = smPos;
- if ( sortedPos.size() > onlyOrderedList.size() )
- onlyOrderedList.push_back( smVec[i] );
+ TPosInList smPos = find( smBeg, smEnd, smVec[i] ); // position in theListToSort
+ if ( smPos != smEnd )
+ {
+ size_t posInList = std::distance( smBeg, smPos );
+ size_t order = sortedPos.size();
+ sortedPos.insert( std::make_pair( posInList, order ));
+ if ( posInList != order )
+ needSort = true;
}
}
}
- if (onlyOrderedList.size() < 2)
- return res;
- res = true;
+ if ( ! needSort )
+ return false;
- std::vector<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
- std::vector<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
+ // set sm of sortedPos from theListToSort to front of orderedSM
+ // and the rest of theListToSort to orderedSM end
- // iterate on ordered sub-meshes and insert them in detected positions
- std::map< int, TPosInList >::iterator i_pos = sortedPos.begin();
- for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
- *(i_pos->second) = *onlyBIt;
+ std::vector<SMESH_subMesh*> orderedSM;
+ orderedSM.reserve( theListToSort.size() );
+ orderedSM.resize( sortedPos.size() );
- return res;
+ size_t iPrev = 0;
+ sortedPos.insert( std::make_pair( theListToSort.size(), sortedPos.size() ));
+ for ( const auto & pos_order : sortedPos )
+ {
+ const size_t& posInList = pos_order.first;
+ const size_t& order = pos_order.second;
+ if ( order < sortedPos.size() - 1 )
+ orderedSM[ order ] = theListToSort[ posInList ];
+
+ if ( iPrev < posInList )
+ orderedSM.insert( orderedSM.end(),
+ theListToSort.begin() + iPrev,
+ theListToSort.begin() + posInList );
+ iPrev = posInList + 1;
+ }
+
+ theListToSort.swap( orderedSM );
+
+ return true;
}
//================================================================================