+ // restore groups on geometry
+ for ( size_t i = 0; i < groupsData.size(); ++i )
+ {
+ const TGroupOnGeomData& data = groupsData[i];
+ if ( data._shape.IsNull() )
+ continue;
+
+ std::map<int, SMESH::SMESH_GroupBase_ptr>::iterator i2g = _mapGroups.find( data._oldID );
+ if ( i2g == _mapGroups.end() ) continue;
+
+ SMESH_GroupBase_i* gr_i = SMESH::DownCast<SMESH_GroupBase_i*>( i2g->second );
+ if ( !gr_i ) continue;
+
+ SMESH_Group* g = _impl->AddGroup( data._type, data._name.c_str(), data._oldID, data._shape );
+ if ( !g )
+ _mapGroups.erase( i2g );
+ else
+ g->GetGroupDS()->SetColor( data._color );
+ }
+
+ if ( !sameTopology )
+ {
+ std::map< int, int >::iterator o2n = old2newIDs.begin();
+ for ( ; o2n != old2newIDs.end(); ++o2n )
+ {
+ int newID = o2n->second, oldID = o2n->first;
+ if ( newID == oldID || !_mapSubMesh.count( oldID ))
+ continue;
+ if ( newID > 0 )
+ {
+ _mapSubMesh [ newID ] = _impl->GetSubMeshContaining( newID );
+ _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
+ _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
+ }
+ _mapSubMesh. erase(oldID);
+ _mapSubMesh_i. erase(oldID);
+ _mapSubMeshIor.erase(oldID);
+ if ( newID > 0 )
+ _mapSubMesh_i [ newID ]->changeLocalId( newID );
+ }
+ }
+
+ // update _mapSubMesh
+ std::map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
+ for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
+ i_sm->second = _impl->GetSubMesh( meshDS->IndexToShape( i_sm->first ));
+ }
+
+ if ( !sameTopology )
+ {
+ // remove invalid study sub-objects
+ CheckGeomGroupModif();
+ }
+
+ _gen_i->UpdateIcons( me );
+
+ if ( !isBreakLink && isShaper )
+ {
+ SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( me );
+ if ( !meshSO->_is_nil() )
+ _gen_i->SetPixMap(meshSO, "ICON_SMESH_TREE_GEOM_MODIF");
+ }
+}
+
+//=============================================================================
+/*!
+ * \brief Update objects depending on changed geom groups
+ *
+ * NPAL16168: geometrical group edition from a submesh don't modify mesh computation
+ * issue 0020210: Update of a smesh group after modification of the associated geom group
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::CheckGeomGroupModif()
+{
+ // 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() )