+ if ( theGroup->_is_nil() )
+ return;
+
+ SMESH_GroupBase_i* aGroup =
+ dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
+ if ( !aGroup )
+ return;
+
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ // Remove group's SObject
+ SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
+ if ( !aGroupSO->_is_nil() )
+ aStudy->NewBuilder()->RemoveObject( aGroupSO );
+ }
+
+ // Remove the group from SMESH data structures
+ removeGroup( aGroup->GetLocalID() );
+}
+
+//=============================================================================
+/*! RemoveGroupWithContents
+ * Remove group with its contents
+ */
+//=============================================================================
+void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
+ throw (SALOME::SALOME_Exception)
+{
+ if ( theGroup->_is_nil() )
+ return;
+
+ SMESH_GroupBase_i* aGroup =
+ dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
+ if ( !aGroup )
+ return;
+
+ SMESH::long_array_var anIds = aGroup->GetListOfID();
+ SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
+
+ if ( aGroup->GetType() == SMESH::NODE )
+ aMeshEditor->RemoveNodes( anIds );
+ else
+ aMeshEditor->RemoveElements( anIds );
+
+ RemoveGroup( theGroup );
+}
+
+//=============================================================================
+/*! UnionGroups
+ * New group is created. All mesh elements that are
+ * present in initial groups are added to the new one
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
+ SMESH::SMESH_GroupBase_ptr theGroup2,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ try
+ {
+ SMESH::SMESH_Group_var aResGrp;
+
+ if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
+ theGroup1->GetType() != theGroup2->GetType() )
+ return SMESH::SMESH_Group::_nil();
+
+ aResGrp = CreateGroup( theGroup1->GetType(), theName );
+ if ( aResGrp->_is_nil() )
+ return SMESH::SMESH_Group::_nil();
+
+ SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+ SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+
+ TColStd_MapOfInteger aResMap;
+
+ for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+ aResMap.Add( anIds1[ i1 ] );
+
+ for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+ aResMap.Add( anIds2[ i2 ] );
+
+ SMESH::long_array_var aResIds = new SMESH::long_array;
+ aResIds->length( aResMap.Extent() );
+
+ int resI = 0;
+ TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
+ for( ; anIter.More(); anIter.Next() )
+ aResIds[ resI++ ] = anIter.Key();
+
+ aResGrp->Add( aResIds );
+
+ return aResGrp._retn();
+ }
+ catch( ... )
+ {
+ return SMESH::SMESH_Group::_nil();
+ }
+}
+
+//=============================================================================
+/*! IntersectGroups
+ * New group is created. All mesh elements that are
+ * present in both initial groups are added to the new one.
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
+ SMESH::SMESH_GroupBase_ptr theGroup2,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::SMESH_Group_var aResGrp;
+
+ if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
+ theGroup1->GetType() != theGroup2->GetType() )
+ return aResGrp;
+
+ aResGrp = CreateGroup( theGroup1->GetType(), theName );
+ if ( aResGrp->_is_nil() )
+ return aResGrp;
+
+ SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+ SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+
+ TColStd_MapOfInteger aMap1;
+
+ for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+ aMap1.Add( anIds1[ i1 ] );
+
+ TColStd_SequenceOfInteger aSeq;
+
+ for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+ if ( aMap1.Contains( anIds2[ i2 ] ) )
+ aSeq.Append( anIds2[ i2 ] );
+
+ SMESH::long_array_var aResIds = new SMESH::long_array;
+ aResIds->length( aSeq.Length() );
+
+ for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
+ aResIds[ resI ] = aSeq( resI + 1 );
+
+ aResGrp->Add( aResIds );
+
+ return aResGrp._retn();
+}
+
+//=============================================================================
+/*! CutGroups
+ * New group is created. All mesh elements that are present in
+ * main group but do not present in tool group are added to the new one
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
+ SMESH::SMESH_GroupBase_ptr theGroup2,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::SMESH_Group_var aResGrp;
+
+ if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
+ theGroup1->GetType() != theGroup2->GetType() )
+ return aResGrp;
+
+ aResGrp = CreateGroup( theGroup1->GetType(), theName );
+ if ( aResGrp->_is_nil() )
+ return aResGrp;
+
+ SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+ SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+
+ TColStd_MapOfInteger aMap2;
+
+ for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+ aMap2.Add( anIds2[ i2 ] );
+
+
+ TColStd_SequenceOfInteger aSeq;
+ for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+ if ( !aMap2.Contains( anIds1[ i1 ] ) )
+ aSeq.Append( anIds1[ i1 ] );
+
+ SMESH::long_array_var aResIds = new SMESH::long_array;
+ aResIds->length( aSeq.Length() );
+
+ for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
+ aResIds[ resI ] = aSeq( resI + 1 );
+
+ aResGrp->Add( aResIds );
+
+ return aResGrp._retn();