fix PAL15156 (Mesh to pass through a point works wrong for the second mesh)

This commit is contained in:
eap 2007-03-05 15:31:12 +00:00
parent 6e57255bd6
commit a8ab9d5bcc

View File

@ -152,8 +152,10 @@ namespace {
struct TNodeSearcherDeleter : public SMESH_subMeshEventListener struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
{ {
TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ) // won't be deleted by submesh SMESH_Mesh* myMesh;
{} //!< Constructor
TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
myMesh(0) {}
//!< Delete myNodeSearcher //!< Delete myNodeSearcher
static void Delete() static void Delete()
{ {
@ -166,18 +168,17 @@ namespace {
{ {
if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) { if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
Delete(); Delete();
// delete self from all submeshes Unset( sm->GetFather() );
if ( SMESH_subMesh* myMainSubMesh = sm->GetFather()->GetSubMeshContaining(1) ) {
const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
TDependsOnMap::const_iterator sm;
for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
sm->second->DeleteEventListener( this );
} }
} }
} //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
//!< set self on all submeshes
void Set(SMESH_Mesh* mesh) void Set(SMESH_Mesh* mesh)
{ {
if ( myMesh && myMesh != mesh ) {
Delete();
Unset( myMesh );
}
myMesh = mesh;
if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) { if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn(); const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
TDependsOnMap::const_iterator sm; TDependsOnMap::const_iterator sm;
@ -185,6 +186,16 @@ namespace {
sm->second->SetEventListener( this, 0, sm->second ); sm->second->SetEventListener( this, 0, sm->second );
} }
} }
//!< delete self from all submeshes
void Unset(SMESH_Mesh* mesh)
{
if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
TDependsOnMap::const_iterator sm;
for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
sm->second->DeleteEventListener( this );
}
}
}; };
} }
@ -1903,7 +1914,7 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
{ {
// We keep myNodeSearcher until any mesh modification: // We keep myNodeSearcher until any mesh modification:
// 1) initData() deletes myNodeSearcher at any edition, // 1) initData() deletes myNodeSearcher at any edition,
// 2) TNodeSearcherDeleter - at any mesh compute event // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
initData(); initData();
@ -1911,11 +1922,11 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID ); const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
if ( !node ) if ( !node )
{ {
static TNodeSearcherDeleter deleter;
deleter.Set( myMesh );
if ( !myNodeSearcher ) { if ( !myNodeSearcher ) {
::SMESH_MeshEditor anEditor( myMesh ); ::SMESH_MeshEditor anEditor( myMesh );
myNodeSearcher = anEditor.GetNodeSearcher(); myNodeSearcher = anEditor.GetNodeSearcher();
static TNodeSearcherDeleter deleter;
deleter.Set( myMesh );
} }
gp_Pnt p( x,y,z ); gp_Pnt p( x,y,z );
node = myNodeSearcher->FindClosestTo( p ); node = myNodeSearcher->FindClosestTo( p );