X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMDS%2FSMDS_Mesh.cxx;h=f2aee846a6efbc854b55b3f766e3cdafa4c8d689;hb=f5e84513cda0eda53672cc9d3b1124323b4aa26d;hp=a117394b97b6184a957ae21c9622fc836441c2ef;hpb=8d297d6698f361d4f2dde723050bcfbaea050920;p=modules%2Fsmesh.git diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index a117394b9..f2aee846a 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2020 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 @@ -68,7 +68,7 @@ int SMDS_Mesh::chunkSize = 1024; */ //================================================================================ -int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) +int SMDS_Mesh::CheckMemory(const bool doNotRaise) { return -1; #if !defined WIN32 && !defined __APPLE__ @@ -831,6 +831,8 @@ SMDS_Mesh::AddPolygonalFaceWithID (const std::vector & nod { if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + if ( nodes.empty() ) + throw std::invalid_argument("Polygon without nodes is forbidden"); if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { cell->init( SMDSEntity_Polygon, nodes ); @@ -874,6 +876,8 @@ SMDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector & const int ID) { if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + if ( nodes.empty() ) + throw std::invalid_argument("Polygon without nodes is forbidden"); if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { cell->init( SMDSEntity_Quad_Polygon, nodes ); @@ -1044,6 +1048,31 @@ bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh) return found; } +//======================================================================= +//function : ChangePolyhedronNodes +//purpose : +//======================================================================= + +bool SMDS_Mesh::ChangePolyhedronNodes(const SMDS_MeshElement * element, + const std::vector& nodes, + const std::vector& quantities) +{ + // keep current nodes of element + std::set oldNodes( element->begin_nodes(), element->end_nodes() ); + + // change nodes + bool Ok = false; + if ( const SMDS_MeshVolume* vol = DownCast( element )) + Ok = vol->ChangeNodes( nodes, quantities ); + + if ( Ok ) + { + setMyModified(); + updateInverseElements( element, &nodes[0], nodes.size(), oldNodes ); + } + return Ok; +} + //======================================================================= //function : ChangeElementNodes //purpose : @@ -1062,14 +1091,30 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, Ok = cell->ChangeNodes(nodes, nbnodes); if ( Ok ) + { setMyModified(); + updateInverseElements( element, nodes, nbnodes, oldNodes ); + } + return Ok; +} - if ( Ok && GetGrid()->HasLinks() ) // update InverseElements +//======================================================================= +//function : updateInverseElements +//purpose : update InverseElements when element changes node +//======================================================================= + +void SMDS_Mesh::updateInverseElements( const SMDS_MeshElement * element, + const SMDS_MeshNode* const* nodes, + const int nbnodes, + std::set& oldNodes ) +{ + if ( GetGrid()->HasLinks() ) // update InverseElements { std::set::iterator it; // AddInverseElement to new nodes - for ( int i = 0; i < nbnodes; i++ ) { + for ( int i = 0; i < nbnodes; i++ ) + { it = oldNodes.find( nodes[i] ); if ( it == oldNodes.end() ) // new node @@ -1086,7 +1131,6 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, } } - return Ok; } const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node) @@ -1542,8 +1586,9 @@ SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator() const SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) const { + int nbElems = myCellFactory->CompactChangePointers() ? -1 : myInfo.NbElements( type ); return myCellFactory->GetIterator< SMDS_ElemIterator >( new SMDS_MeshElement::GeomFilter( type ), - myInfo.NbElements( type )); + nbElems); } SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const @@ -1552,8 +1597,9 @@ SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) c { return myNodeFactory->GetIterator< SMDS_ElemIterator >( new SMDS_MeshElement::NonNullFilter ); } + int nbElems = myCellFactory->CompactChangePointers() ? -1 : myInfo.NbElements( type ); return myCellFactory->GetIterator( new SMDS_MeshElement::EntityFilter( type ), - myInfo.NbElements( type )); + nbElems); } /////////////////////////////////////////////////////////////////////////////// @@ -1571,8 +1617,9 @@ SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const return myNodeFactory->GetIterator< TIterator >( new SMDS_MeshElement::NonNullFilter ); default: + int nbElems = myCellFactory->CompactChangePointers() ? -1 : myInfo.NbElements( type ); return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( type ), - myInfo.NbElements( type )); + nbElems); } return SMDS_ElemIteratorPtr(); } @@ -1584,8 +1631,9 @@ SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const { typedef SMDS_EdgeIterator TIterator; + int nbElems = myCellFactory->CompactChangePointers() ? -1 : myInfo.NbEdges(); return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( SMDSAbs_Edge ), - myInfo.NbEdges()); + nbElems); } /////////////////////////////////////////////////////////////////////////////// @@ -1595,8 +1643,9 @@ SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const { typedef SMDS_FaceIterator TIterator; + int nbElems = myCellFactory->CompactChangePointers() ? -1 : myInfo.NbFaces(); return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( SMDSAbs_Face ), - myInfo.NbFaces()); + nbElems); } /////////////////////////////////////////////////////////////////////////////// @@ -1606,9 +1655,10 @@ SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const { typedef SMDS_VolumeIterator TIterator; + int nbElems = myCellFactory->CompactChangePointers() ? -1 : myInfo.NbVolumes(); return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( SMDSAbs_Volume ), - myInfo.NbVolumes()); + nbElems ); } SMDS_NodeIteratorPtr SMDS_Mesh::shapeNodesIterator(int shapeID, @@ -2913,8 +2963,7 @@ void SMDS_Mesh::CompactMesh() { this->myCompactTime = this->myModifTime; - bool idsChange = ( myNodeFactory->CompactChangePointers() || - myCellFactory->CompactChangePointers() ); + bool idsChange = HasNumerationHoles(); if ( idsChange ) { std::set< SMDS_ElementHolder* >::iterator holder = myElemHolders.begin(); @@ -2974,6 +3023,7 @@ void SMDS_Mesh::Modified() { if (this->myModified) { + myGrid->Modified(); this->myModifTime++; myModified = false; } @@ -2990,6 +3040,13 @@ bool SMDS_Mesh::IsCompacted() return ( this->myCompactTime == this->myModifTime ); } +//! are there holes in elements or nodes numeration +bool SMDS_Mesh::HasNumerationHoles() +{ + return ( myNodeFactory->CompactChangePointers() || + myCellFactory->CompactChangePointers() ); +} + void SMDS_Mesh::setNbShapes( size_t nbShapes ) { myNodeFactory->SetNbShapes( nbShapes );