+
+//=======================================================================
+//function : Clear
+//purpose : remove the contents
+//=======================================================================
+
+void SMESHDS_SubMesh::Clear()
+{
+ if ( myParent && myParent->NbNodes() > 0 )
+ {
+ for ( size_t i = 0; i < myElements.size(); ++i )
+ {
+ if ( myElements[i] &&
+ myElements[i]->GetID() > 0 &&
+ myElements[i] == myParent->FindElement( myElements[i]->GetID() )) // not deleted
+ const_cast< SMDS_MeshElement* >( myElements[i] )->setShapeId( 0 );
+ }
+ for ( size_t i = 0; i < myNodes.size(); ++i )
+ {
+ if ( myNodes[i] &&
+ myNodes[i]->GetID() > 0 &&
+ myNodes[i] == myParent->FindNode( myNodes[i]->GetID() )) // not deleted
+ const_cast< SMDS_MeshNode* >( myNodes[i] )->setShapeId( 0 );
+ }
+ }
+
+ clearVector( myElements );
+ clearVector( myNodes );
+ myUnusedIdNodes = 0;
+ myUnusedIdElements = 0;
+ if ( NbSubMeshes() > 0 )
+ {
+ SMESHDS_SubMeshIteratorPtr sub = GetSubMeshIterator();
+ while ( sub->more() ) {
+ if ( SMESHDS_SubMesh* sm = (SMESHDS_SubMesh*) sub->next())
+ sm->Clear();
+ }
+ }
+}
+
+int SMESHDS_SubMesh::getSize()
+{
+ int c = NbNodes();
+ int d = NbElements();
+ return c+d;
+}
+
+void SMESHDS_SubMesh::compactList()
+{
+ if ( myUnusedIdElements > 0 )
+ {
+ std::vector<const SMDS_MeshElement*> newElems;
+ newElems.reserve( myElements.size() - myUnusedIdElements );
+ for ( size_t i = 0; i < myElements.size(); i++)
+ if ( myElements[i] )
+ {
+ SMDS_MeshElement* elem = (SMDS_MeshElement*)myElements[i];
+ elem->setIdInShape( newElems.size() );
+ newElems.push_back( elem );
+ }
+ myElements.swap(newElems);
+ myUnusedIdElements = 0;
+ }
+
+ if ( myUnusedIdNodes > 0 )
+ {
+ std::vector<const SMDS_MeshNode*> newNodes;
+ newNodes.reserve( myNodes.size() - myUnusedIdNodes );
+ for ( size_t i = 0; i < myNodes.size(); i++ )
+ if ( myNodes[i] )
+ {
+ SMDS_MeshNode* node = (SMDS_MeshNode*)myNodes[i];
+ node->setIdInShape( newNodes.size() );
+ newNodes.push_back( node );
+ }
+ myNodes.swap(newNodes);
+ myUnusedIdNodes = 0;
+ }
+}
+
+//=======================================================================
+//function : GetElement
+//purpose : Return an element by its IdInShape
+//=======================================================================
+
+const SMDS_MeshElement* SMESHDS_SubMesh::GetElement( size_t idInShape ) const
+{
+ return ( !IsComplexSubmesh() && idInShape < myElements.size() ) ? myElements[idInShape] : 0;
+}
+
+//=======================================================================
+//function : GetElement
+//purpose : Return a node by its IdInShape
+//=======================================================================
+
+const SMDS_MeshNode* SMESHDS_SubMesh::GetNode( size_t idInShape ) const
+{
+ return ( !IsComplexSubmesh() && idInShape < myNodes.size() ) ? myNodes[idInShape] : 0;
+}