+ // remove sub-meshes referring a removed sub-shapes (if main shape still exists)
+ SALOMEDS::StudyBuilder_var builder = _gen_i->getStudyServant()->NewBuilder();
+ GEOM::GEOM_Object_var mainGO = GetShapeToMesh();
+ SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( SMESH::SMESH_Mesh_var( _this() ));
+ if ( !mainGO->_is_nil() && !meshSO->_is_nil() )
+ {
+ SALOMEDS::SObject_wrap rootSO, geomRefSO, geomSO;
+ for ( CORBA::Long tag = SMESH::Tag_FirstSubMesh; tag <= SMESH::Tag_LastSubMesh; ++tag )
+ if ( meshSO->FindSubObject( tag, rootSO.inout() ))
+ {
+ int nbValid = 0, nbRemoved = 0;
+ SALOMEDS::ChildIterator_wrap chItr = _gen_i->getStudyServant()->NewChildIterator( rootSO );
+ for ( ; chItr->More(); chItr->Next() )
+ {
+ SALOMEDS::SObject_wrap smSO = chItr->Value(); // sub-mesh SO
+ if ( !smSO->_is_nil() &&
+ smSO->FindSubObject( SMESH::Tag_RefOnShape, geomRefSO.inout() ) &&
+ geomRefSO->ReferencedObject( geomSO.inout() )) // find geometry by reference
+ {
+ CORBA::Object_var geomObj = _gen_i->SObjectToObject( geomSO );
+ GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( geomObj );
+ if ( !geom->_non_existent() )
+ {
+ ++nbValid;
+ continue; // keep the sub-mesh
+ }
+ }
+ CORBA::Object_var smObj = _gen_i->SObjectToObject( smSO );
+ SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( smObj );
+ if ( !sm->_is_nil() && !sm->_non_existent() )
+ {
+ GEOM::GEOM_Object_var smGeom = sm->GetSubShape();
+ if ( smGeom->_is_nil() )
+ {
+ RemoveSubMesh( sm );
+ ++nbRemoved;
+ }
+ }
+ else
+ {
+ if ( _preMeshInfo )
+ _preMeshInfo->ForgetAllData(); // unknown hypothesis modified
+ builder->RemoveObjectWithChildren( smSO ); // sub-shape removed before loading SMESH
+ ++nbRemoved;
+ }
+ }
+ if ( /*nbRemoved > 0 &&*/ nbValid == 0 )
+ builder->RemoveObjectWithChildren( rootSO );
+ }
+ }
+
+ // check for removed sub-shapes and convert geom dependent groups into standalone ones
+ std::map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
+ while ( i_gr != _mapGroups.end())
+ {
+ SMESH::SMESH_GroupBase_ptr group = i_gr->second;
+ ++i_gr;
+ SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( group ), refSO, geomSO;
+ SMESH::SMESH_GroupOnGeom_var onGeom = SMESH::SMESH_GroupOnGeom::_narrow ( group );
+ SMESH::SMESH_GroupOnFilter_var onFilt = SMESH::SMESH_GroupOnFilter::_narrow( group );
+ bool isValidGeom = false;
+ if ( !onGeom->_is_nil() )
+ {
+ isValidGeom = ( ! GEOM::GEOM_Object_var( onGeom->GetShape() )->_is_nil() ); // check TopoDS
+ if ( !isValidGeom ) // check reference
+ {
+ isValidGeom = ( ! groupSO->_is_nil() &&
+ groupSO->FindSubObject( SMESH::Tag_RefOnShape, refSO.inout() ) &&
+ refSO->ReferencedObject( geomSO.inout() ) &&
+ ! geomSO->_is_nil() &&
+ !CORBA::is_nil( CORBA::Object_var( geomSO->GetObject() )));
+ }
+ }
+ else if ( !onFilt->_is_nil() )
+ {
+ isValidGeom = isValidGeomFilter( onFilt->GetFilter() );
+ }
+ else // standalone
+ {
+ isValidGeom = ( !groupSO->_is_nil() &&
+ !groupSO->FindSubObject( SMESH::Tag_RefOnShape, refSO.inout() ));
+ }
+ if ( !isValidGeom )
+ {
+ if ( !IsLoaded() || group->IsEmpty() )
+ {
+ RemoveGroup( group );
+ }
+ else if ( !onGeom->_is_nil() || !onFilt->_is_nil() )
+ {
+ SMESH::SMESH_Group_var ( ConvertToStandalone( group ));
+ }
+ else // is it possible?
+ {
+ builder->RemoveObjectWithChildren( refSO );
+ }
+ }
+ }
+
+