0019562: EDF 695 SMESH : Possibility to replace nodes of a cell without destroying the cell. New method DoubleNodes() has been added

This commit is contained in:
sln 2008-11-21 11:01:20 +00:00
parent 028686967b
commit 02737e49ed
2 changed files with 92 additions and 0 deletions

View File

@ -7678,3 +7678,92 @@ SMESH_MeshEditor::FindMatchingNodes(set<const SMDS_MeshElement*>& theSide1,
return SEW_OK;
}
/*!
\brief Creates a hole in a mesh by doubling the nodes of some particular elements
\param theNodes - identifiers of nodes to be doubled
\param theModifiedElems - identifiers of elements to be updated by the new (doubled)
nodes. If list of element identifiers is empty then nodes are doubled but
they not assigned to elements
\return TRUE if operation has been completed successfully, FALSE otherwise
*/
bool SMESH_MeshEditor::DoubleNodes( const std::list< int >& theListOfNodes,
const std::list< int >& theListOfModifiedElems )
{
myLastCreatedElems.Clear();
myLastCreatedNodes.Clear();
if ( theListOfNodes.size() == 0 )
return false;
SMESHDS_Mesh* aMeshDS = GetMeshDS();
if ( !aMeshDS )
return false;
// iterate through nodes and duplicate them
std::map< const SMDS_MeshNode*, const SMDS_MeshNode* > anOldNodeToNewNode;
std::list< int >::const_iterator aNodeIter;
for ( aNodeIter = theListOfNodes.begin(); aNodeIter != theListOfNodes.end(); ++aNodeIter )
{
int aCurr = *aNodeIter;
SMDS_MeshNode* aNode = (SMDS_MeshNode*)aMeshDS->FindNode( aCurr );
if ( !aNode )
continue;
// duplicate node
const SMDS_MeshNode* aNewNode = aMeshDS->AddNode( aNode->X(), aNode->Y(), aNode->Z() );
if ( aNewNode )
{
anOldNodeToNewNode[ aNode ] = aNewNode;
myLastCreatedNodes.Append( aNewNode );
}
}
// Create map of new nodes for modified elements
std::map< SMDS_MeshElement*, vector<const SMDS_MeshNode*> > anElemToNodes;
std::list< int >::const_iterator anElemIter;
for ( anElemIter = theListOfModifiedElems.begin();
anElemIter != theListOfModifiedElems.end(); ++anElemIter )
{
int aCurr = *anElemIter;
SMDS_MeshElement* anElem = (SMDS_MeshElement*)aMeshDS->FindElement( aCurr );
if ( !anElem )
continue;
vector<const SMDS_MeshNode*> aNodeArr( anElem->NbNodes() );
SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
int ind = 0;
while ( anIter->more() )
{
SMDS_MeshNode* aCurrNode = (SMDS_MeshNode*)anIter->next();
if ( aCurr && anOldNodeToNewNode.find( aCurrNode ) != anOldNodeToNewNode.end() )
{
const SMDS_MeshNode* aNewNode = anOldNodeToNewNode[ aCurrNode ];
aNodeArr[ ind++ ] = aNewNode;
}
else
aNodeArr[ ind++ ] = aCurrNode;
}
anElemToNodes[ anElem ] = aNodeArr;
}
// Change nodes of elements
std::map< SMDS_MeshElement*, vector<const SMDS_MeshNode*> >::iterator
anElemToNodesIter = anElemToNodes.begin();
for ( ; anElemToNodesIter != anElemToNodes.end(); ++anElemToNodesIter )
{
const SMDS_MeshElement* anElem = anElemToNodesIter->first;
vector<const SMDS_MeshNode*> aNodeArr = anElemToNodesIter->second;
if ( anElem )
aMeshDS->ChangeElementNodes( anElem, &aNodeArr[ 0 ], anElem->NbNodes() );
}
return true;
}

View File

@ -506,6 +506,9 @@ public:
const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
bool DoubleNodes( const std::list< int >& theListOfNodes,
const std::list< int >& theListOfModifiedElems );
private: