diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index a29123bc9..646bbc658 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -61,6 +61,7 @@ module SMESH CHANGE_ELEMENT_NODES, CHANGE_POLYHEDRON_NODES, RENUMBER, + CLEAR_MESH, ADD_QUADEDGE, ADD_QUADTRIANGLE, ADD_QUADQUADRANGLE, diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index 02180dc5a..1283fb5e3 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -1843,6 +1843,20 @@ SMDS_Mesh::~SMDS_Mesh() itc++; } + if(myParent==NULL) + { + delete myNodeIDFactory; + delete myElementIDFactory; + } + else + { + SMDS_ElemIteratorPtr eIt = elementsIterator(); + while ( eIt->more() ) + myElementIDFactory->ReleaseID(eIt->next()->GetID()); + SMDS_NodeIteratorPtr itn = nodesIterator(); + while (itn->more()) + myNodeIDFactory->ReleaseID(itn->next()->GetID()); + } SetOfNodes::Iterator itn(myNodes); for (; itn.More(); itn.Next()) delete itn.Value(); @@ -1851,8 +1865,6 @@ SMDS_Mesh::~SMDS_Mesh() for (; ite.More(); ite.Next()) { SMDS_MeshElement* elem = ite.Value(); - if(myParent!=NULL) - myElementIDFactory->ReleaseID(elem->GetID()); delete elem; } @@ -1860,8 +1872,6 @@ SMDS_Mesh::~SMDS_Mesh() for (; itf.More(); itf.Next()) { SMDS_MeshElement* elem = itf.Value(); - if(myParent!=NULL) - myElementIDFactory->ReleaseID(elem->GetID()); delete elem; } @@ -1869,16 +1879,56 @@ SMDS_Mesh::~SMDS_Mesh() for (; itv.More(); itv.Next()) { SMDS_MeshElement* elem = itv.Value(); - if(myParent!=NULL) - myElementIDFactory->ReleaseID(elem->GetID()); delete elem; } - if(myParent==NULL) - { - delete myNodeIDFactory; - delete myElementIDFactory; +} + +//================================================================================ +/*! + * \brief Clear all data + */ +//================================================================================ + +void SMDS_Mesh::Clear() +{ + if (myParent!=NULL) { + SMDS_ElemIteratorPtr eIt = elementsIterator(); + while ( eIt->more() ) + myElementIDFactory->ReleaseID(eIt->next()->GetID()); + SMDS_NodeIteratorPtr itn = nodesIterator(); + while (itn->more()) + myNodeIDFactory->ReleaseID(itn->next()->GetID()); } + else { + myNodeIDFactory->Clear(); + myElementIDFactory->Clear(); + } + SMDS_VolumeIteratorPtr itv = volumesIterator(); + while (itv->more()) + delete itv->next(); + myVolumes.Clear(); + + SMDS_FaceIteratorPtr itf = facesIterator(); + while (itf->more()) + delete itf->next(); + myFaces.Clear(); + + SMDS_EdgeIteratorPtr ite = edgesIterator(); + while (ite->more()) + delete ite->next(); + myEdges.Clear(); + + SMDS_NodeIteratorPtr itn = nodesIterator(); + while (itn->more()) + delete itn->next(); + myNodes.Clear(); + + list::iterator itc=myChildren.begin(); + while(itc!=myChildren.end()) + (*itc)->Clear(); + + myInfo = SMDS_MeshInfo(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index c4c0098c2..b75ed3da7 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -429,6 +429,8 @@ public: * Implemented for fast cleaning of meshes. */ virtual void RemoveFreeElement(const SMDS_MeshElement * elem); + + virtual void Clear(); virtual bool RemoveFromParent(); virtual bool RemoveSubMesh(const SMDS_Mesh * aMesh); diff --git a/src/SMDS/SMDS_MeshElementIDFactory.cxx b/src/SMDS/SMDS_MeshElementIDFactory.cxx index cac5fc1c6..24c7b7c45 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.cxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.cxx @@ -167,3 +167,10 @@ SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const return SMDS_ElemIteratorPtr (new SMDS_Fact_MyElemIterator(myIDElements)); } + +void SMDS_MeshElementIDFactory::Clear() +{ + myIDElements.Clear(); + myMin = myMax = 0; + SMDS_MeshIDFactory::Clear(); +} diff --git a/src/SMDS/SMDS_MeshElementIDFactory.hxx b/src/SMDS/SMDS_MeshElementIDFactory.hxx index b78358f30..c783e4cab 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.hxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.hxx @@ -49,6 +49,7 @@ public: int GetMaxID() const; int GetMinID() const; SMDS_ElemIteratorPtr elementsIterator() const; + virtual void Clear(); private: void updateMinMax() const; void updateMinMax(int id) const diff --git a/src/SMDS/SMDS_MeshIDFactory.cxx b/src/SMDS/SMDS_MeshIDFactory.cxx index 989e42be3..1adbda4fb 100644 --- a/src/SMDS/SMDS_MeshIDFactory.cxx +++ b/src/SMDS/SMDS_MeshIDFactory.cxx @@ -81,3 +81,9 @@ void SMDS_MeshIDFactory::ReleaseID(const int ID) } } } + +void SMDS_MeshIDFactory::Clear() +{ + myMaxID = 0; + myPoolOfID.clear(); +} diff --git a/src/SMDS/SMDS_MeshIDFactory.hxx b/src/SMDS/SMDS_MeshIDFactory.hxx index 8e57247da..92783f117 100644 --- a/src/SMDS/SMDS_MeshIDFactory.hxx +++ b/src/SMDS/SMDS_MeshIDFactory.hxx @@ -35,9 +35,10 @@ class SMDS_EXPORT SMDS_MeshIDFactory:public SMDS_MeshObject { - public: - virtual int GetFreeID(); - virtual void ReleaseID(int ID); +public: + virtual int GetFreeID(); + virtual void ReleaseID(int ID); + virtual void Clear(); protected: SMDS_MeshIDFactory(); diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 4c3c0a6a0..c811621c0 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -212,46 +212,59 @@ const TopoDS_Solid& SMESH_Mesh::PseudoShape() void SMESH_Mesh::Clear() { - // clear sub-meshes; get ready to re-compute as a side-effect + // clear mesh data + _myMeshDS->ClearMesh(); - if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) - { + // update compute state of submeshes + if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) { SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, /*complexShapeFirst=*/false); - while ( smIt->more() ) - { + while ( smIt->more() ) { sm = smIt->next(); - TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); - if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID ) - // all other shapes depends on vertices so they are already cleaned - sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); - // to recompute even if failed sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); } } - // clear entities not on sub-meshes +// // clear sub-meshes; get ready to re-compute as a side-effect - SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator(); - while ( vIt->more() ) - _myMeshDS->RemoveFreeElement( vIt->next(), 0 ); +// if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) +// { +// SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, +// /*complexShapeFirst=*/false); +// while ( smIt->more() ) +// { +// sm = smIt->next(); +// TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); +// if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID ) +// // all other shapes depends on vertices so they are already cleaned +// sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); +// // to recompute even if failed +// sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); +// } +// } - SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator(); - while ( fIt->more() ) - _myMeshDS->RemoveFreeElement( fIt->next(), 0 ); +// // clear entities not on sub-meshes - SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator(); - while ( eIt->more() ) - _myMeshDS->RemoveFreeElement( eIt->next(), 0 ); +// SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator(); +// while ( vIt->more() ) +// _myMeshDS->RemoveFreeElement( vIt->next(), 0 ); - SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator(); - while ( nIt->more() ) { - const SMDS_MeshNode * node = nIt->next(); - if ( node->NbInverseElements() == 0 ) - _myMeshDS->RemoveFreeNode( node, 0 ); - else - _myMeshDS->RemoveNode(node); - } +// SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator(); +// while ( fIt->more() ) +// _myMeshDS->RemoveFreeElement( fIt->next(), 0 ); + +// SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator(); +// while ( eIt->more() ) +// _myMeshDS->RemoveFreeElement( eIt->next(), 0 ); + +// SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator(); +// while ( nIt->more() ) { +// const SMDS_MeshNode * node = nIt->next(); +// if ( node->NbInverseElements() == 0 ) +// _myMeshDS->RemoveFreeNode( node, 0 ); +// else +// _myMeshDS->RemoveNode(node); +// } } //======================================================================= diff --git a/src/SMESH/SMESH_subMesh.cxx b/src/SMESH/SMESH_subMesh.cxx index 8842e0464..8945f5e26 100644 --- a/src/SMESH/SMESH_subMesh.cxx +++ b/src/SMESH/SMESH_subMesh.cxx @@ -195,7 +195,7 @@ void SMESH_subMesh::SetIsAlwaysComputed(bool isAlCo) bool SMESH_subMesh::IsEmpty() const { if (SMESHDS_SubMesh * subMeshDS = ((SMESH_subMesh*)this)->GetSubMeshDS()) - return (!subMeshDS->GetNodes()->more() && !subMeshDS->GetElements()->more()); + return (!subMeshDS->NbElements() && !subMeshDS->NbNodes()); return true; } @@ -513,7 +513,8 @@ bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) cons int aShapeDim = SMESH_Gen::GetShapeDim(_subShape); if (aHypDim == 3 && aShapeDim == 3) { // check case of open shell - if (_subShape.ShapeType() == TopAbs_SHELL && !_subShape.Closed()) + //if (_subShape.ShapeType() == TopAbs_SHELL && !_subShape.Closed()) + if (_subShape.ShapeType() == TopAbs_SHELL && !BRep_Tool::IsClosed(_subShape)) return false; } if ( aHypDim <= aShapeDim ) diff --git a/src/SMESHClient/SMESH_Client.cxx b/src/SMESHClient/SMESH_Client.cxx index bb6e93318..9b40329f2 100644 --- a/src/SMESHClient/SMESH_Client.cxx +++ b/src/SMESHClient/SMESH_Client.cxx @@ -729,6 +729,10 @@ SMESH_Client::Update(bool theIsClear) case SMESH::ADD_QUADPENTAHEDRON: AddQuadPentasWithID ( mySMDSMesh, aSeq, anId ); break; case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID ( mySMDSMesh, aSeq, anId ); break; + case SMESH::CLEAR_MESH: + mySMDSMesh->Clear(); + break; + case SMESH::REMOVE_NODE: for( ; anElemId < aNbElems; anElemId++ ) mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) ); diff --git a/src/SMESHDS/SMESHDS_CommandType.hxx b/src/SMESHDS/SMESHDS_CommandType.hxx index 9a11105b1..d4200609e 100644 --- a/src/SMESHDS/SMESHDS_CommandType.hxx +++ b/src/SMESHDS/SMESHDS_CommandType.hxx @@ -46,6 +46,7 @@ enum SMESHDS_CommandType { SMESHDS_ChangeElementNodes, SMESHDS_ChangePolyhedronNodes, SMESHDS_Renumber, + SMESHDS_ClearAll, // special types for quadratic elements SMESHDS_AddQuadEdge, SMESHDS_AddQuadTriangle, diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index 18b13fc5d..da435996b 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -769,13 +769,11 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMe // Rm from group // Node can belong to several groups - if (!myGroups.empty()) { - set::iterator GrIt = myGroups.begin(); - for (; GrIt != myGroups.end(); GrIt++) { - SMESHDS_Group* group = dynamic_cast(*GrIt); - if (!group || group->IsEmpty()) continue; + set::iterator GrIt = myGroups.begin(); + for (; GrIt != myGroups.end(); GrIt++) { + SMESHDS_Group* group = dynamic_cast(*GrIt); + if (group && !group->IsEmpty()) group->SMDSGroup().Remove(elt); - } } // Rm from sub-mesh @@ -786,6 +784,33 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMe SMDS_Mesh::RemoveFreeElement(elt); } +//================================================================================ +/*! + * \brief Remove all data from the mesh + */ +//================================================================================ + +void SMESHDS_Mesh::ClearMesh() +{ + myScript->ClearMesh(); + SMDS_Mesh::Clear(); + + // clear submeshes + map::iterator sub, subEnd = myShapeIndexToSubMesh.end(); + for ( sub = myShapeIndexToSubMesh.begin(); sub != subEnd; ++sub ) + sub->second->Clear(); + + // clear groups + TGroups::iterator group, groupEnd = myGroups.end(); + for ( group = myGroups.begin(); group != groupEnd; ++group ) { + if ( SMESHDS_Group* g = dynamic_cast(*group)) { + SMDSAbs_ElementType groupType = g->GetType(); + g->Clear(); + g->SetType( groupType ); + } + } +} + //================================================================================ /*! * \brief return submesh by shape diff --git a/src/SMESHDS/SMESHDS_Mesh.hxx b/src/SMESHDS/SMESHDS_Mesh.hxx index 1cc122d46..f600112c3 100644 --- a/src/SMESHDS/SMESHDS_Mesh.hxx +++ b/src/SMESHDS/SMESHDS_Mesh.hxx @@ -382,6 +382,8 @@ public: void RemoveFreeNode(const SMDS_MeshNode *, SMESHDS_SubMesh *); void RemoveFreeElement(const SMDS_MeshElement *, SMESHDS_SubMesh *); + void ClearMesh(); + bool ChangeElementNodes(const SMDS_MeshElement * elem, const SMDS_MeshNode * nodes[], const int nbnodes); diff --git a/src/SMESHDS/SMESHDS_Script.cxx b/src/SMESHDS/SMESHDS_Script.cxx index d5eea6ecc..d04795b0b 100644 --- a/src/SMESHDS/SMESHDS_Script.cxx +++ b/src/SMESHDS/SMESHDS_Script.cxx @@ -317,7 +317,21 @@ void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int myIsModified = true; return; } - getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID ); + getCommand(SMESHDS_Renumber); +} + +//======================================================================= +//function : ClearMesh +//purpose : +//======================================================================= +void SMESHDS_Script::ClearMesh () +{ + if(myIsEmbeddedMode){ + myIsModified = true; + return; + } + Clear();// previous commands become useless to reproduce on client side + getCommand(SMESHDS_ClearAll); } //======================================================================= diff --git a/src/SMESHDS/SMESHDS_Script.hxx b/src/SMESHDS/SMESHDS_Script.hxx index 781fc9910..8706bfa22 100644 --- a/src/SMESHDS/SMESHDS_Script.hxx +++ b/src/SMESHDS/SMESHDS_Script.hxx @@ -93,6 +93,7 @@ class SMESHDS_EXPORT SMESHDS_Script std::vector nodes_ids, std::vector quantities); void Renumber (const bool isNodes, const int startID, const int deltaID); + void ClearMesh(); void Clear(); const std::list & GetCommands(); diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index 7cc19700d..0da2a95f8 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -311,3 +311,19 @@ SMESHDS_SubMeshIteratorPtr SMESHDS_SubMesh::GetSubMeshIterator() const ( new SMDS_SetIterator< const SMESHDS_SubMesh*, TIterator >( mySubMeshes.begin(), mySubMeshes.end())); } + +//======================================================================= +//function : Clear +//purpose : remove the contents +//======================================================================= + +void SMESHDS_SubMesh::Clear() +{ + myElements.clear(); + myNodes.clear(); + SMESHDS_SubMeshIteratorPtr sub = GetSubMeshIterator(); + while ( sub->more() ) { + if ( SMESHDS_SubMesh* sm = (SMESHDS_SubMesh*) sub->next()) + sm->Clear(); + } +} diff --git a/src/SMESHDS/SMESHDS_SubMesh.hxx b/src/SMESHDS/SMESHDS_SubMesh.hxx index bc0ccce2a..e42893368 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.hxx +++ b/src/SMESHDS/SMESHDS_SubMesh.hxx @@ -62,6 +62,9 @@ class SMESHDS_EXPORT SMESHDS_SubMesh SMDS_NodeIteratorPtr GetNodes() const; bool Contains(const SMDS_MeshElement * ME) const; // check if elem or node is in + // clear the contents + void Clear(); + private: //const SMDS_Mesh * myMesh; std::set myElements;