From 78fb42dc3ea751d55039317d05b7e96ff86c0931 Mon Sep 17 00:00:00 2001 From: ptv Date: Mon, 15 Dec 2008 12:33:24 +0000 Subject: [PATCH] IMP19942 - Convert group on geometry into group of elements --- doc/salome/gui/SMESH/input/editing_groups.doc | 16 +++- idl/SMESH_Mesh.idl | 6 ++ src/SMESH/SMESH_Mesh.cxx | 38 ++++++++ src/SMESH/SMESH_Mesh.hxx | 1 + src/SMESHGUI/SMESHGUI.cxx | 36 +++++++ src/SMESHGUI/SMESHGUI_GroupDlg.cxx | 96 +++++++++---------- src/SMESHGUI/SMESHGUI_GroupDlg.h | 6 +- src/SMESHGUI/SMESHGUI_Selection.cxx | 25 +++++ src/SMESHGUI/SMESHGUI_Selection.h | 1 + src/SMESHGUI/SMESH_msg_en.ts | 16 ++++ src/SMESH_I/SMESH_2smeshpy.cxx | 10 +- src/SMESH_I/SMESH_Group_i.cxx | 24 +++-- src/SMESH_I/SMESH_Mesh_i.cxx | 68 +++++++++++++ src/SMESH_I/SMESH_Mesh_i.hxx | 2 + src/SMESH_SWIG/smeshDC.py | 5 + 15 files changed, 286 insertions(+), 64 deletions(-) diff --git a/doc/salome/gui/SMESH/input/editing_groups.doc b/doc/salome/gui/SMESH/input/editing_groups.doc index 3a69e757a..b5031468a 100644 --- a/doc/salome/gui/SMESH/input/editing_groups.doc +++ b/doc/salome/gui/SMESH/input/editing_groups.doc @@ -21,7 +21,21 @@ remove the elements forming it. For more information see group. +\n To convert an existing group on geometry into standalone group +of elements and modify: +
    +
  1. Select your group on geometry in the Object Browser and in the \b Mesh menu click +the Edit Group as Standalone item.
  2. + +\image html image74.gif +
    "Edit Group as Standalone" button
    + +The group on geometry will be converted into standalone group and can +be modified as group of elements +
  3. Click the \b Apply or Apply and Close button to confirm modification of the +group.
  4. +
    See Also a sample TUI Script of an \ref tui_edit_group "Edit Group" operation. -*/ \ No newline at end of file +*/ diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 76859da14..d55204ef4 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -358,6 +358,12 @@ module SMESH in string name ) raises (SALOME::SALOME_Exception); + /*! + * Convert group on geometry into standalone group + */ + SMESH_Group ConvertToStandalone( in SMESH_GroupOnGeom theGeomGroup ) + raises (SALOME::SALOME_Exception); + /*! * Add hypothesis to the mesh, under a particular subShape * (or the main shape itself) diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index d8d8ea780..a07089b8d 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1479,3 +1479,41 @@ SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem { return _myMeshDS->GetElementType( id, iselem ); } + +//============================================================================= +/*! + * \brief Convert group on geometry into standalone group + */ +//============================================================================= + +SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID ) +{ + SMESH_Group* aGroup = 0; + std::map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID ); + if ( itg == _mapGroup.end() ) + return aGroup; + + SMESH_Group* anOldGrp = (*itg).second; + SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS(); + if ( !anOldGrp || !anOldGrpDS ) + return aGroup; + + // create new standalone group + aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() ); + _mapGroup[theGroupID] = aGroup; + + SMESHDS_Group* aNewGrpDS = dynamic_cast( aGroup->GetGroupDS() ); + GetMeshDS()->RemoveGroup( anOldGrpDS ); + GetMeshDS()->AddGroup( aNewGrpDS ); + + // add elements (or nodes) into new created group + SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements(); + while ( anItr->more() ) + aNewGrpDS->Add( (anItr->next())->GetID() ); + + // remove old group + delete anOldGrp; + + return aGroup; +} + diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index c07961fa8..8ba8f082c 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -236,6 +236,7 @@ public: void RemoveGroup (const int theGroupID); + SMESH_Group* ConvertToStandalone ( int theGroupID ); SMDSAbs_ElementType GetElementType( const int id, const bool iselem ); diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index aa9d98862..5d40a3c72 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -1876,6 +1876,36 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) break; } + case 815: // Edit GEOM GROUP as standalone + { + if ( !vtkwnd ) + { + SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), + tr( "NOT_A_VTK_VIEWER" ) ); + break; + } + + if(checkLock(aStudy)) break; + EmitSignalDeactivateDialog(); + + LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr(); + SALOME_ListIO selected; + if( aSel ) + aSel->selectedObjects( selected ); + + SALOME_ListIteratorOfListIO It (selected); + for ( ; It.More(); It.Next() ) + { + SMESH::SMESH_GroupOnGeom_var aGroup = + SMESH::IObjectToInterface(It.Value()); + if (!aGroup->_is_nil()) { + SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true ); + aDlg->show(); + } + } + break; + } + case 810: // Union Groups case 811: // Intersect groups case 812: // Cut groups @@ -2606,6 +2636,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createSMESHAction( 801, "CREATE_GROUP", "ICON_CREATE_GROUP" ); createSMESHAction( 802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" ); createSMESHAction( 803, "EDIT_GROUP", "ICON_EDIT_GROUP" ); + createSMESHAction( 815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" ); createSMESHAction( 804, "ADD" ); createSMESHAction( 805, "REMOVE" ); createSMESHAction( 810, "UN_GROUP", "ICON_UNION" ); @@ -2744,6 +2775,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createMenu( 806, meshId, -1 ); createMenu( 802, meshId, -1 ); createMenu( 803, meshId, -1 ); + createMenu( 815, meshId, -1 ); createMenu( separator(), meshId, -1 ); createMenu( 810, meshId, -1 ); createMenu( 811, meshId, -1 ); @@ -2842,6 +2874,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createTool( 806, meshTb ); createTool( 802, meshTb ); createTool( 803, meshTb ); + //createTool( 815, meshTb ); createTool( separator(), meshTb ); createTool( 900, meshTb ); createTool( 902, meshTb ); @@ -2942,6 +2975,8 @@ void SMESHGUI::initialize( CAM_Application* app ) createPopupItem( 704, OB, mesh, "&& isComputable"); // EDIT_MESHSUBMESH createPopupItem( 704, OB, subMesh, "&& isComputable" ); // EDIT_MESHSUBMESH createPopupItem( 803, OB, group ); // EDIT_GROUP + createPopupItem( 815, OB, group, "&& groupType = 'GroupOnGeom'" ); // EDIT_GROUP + popupMgr()->insert( separator(), -1, 0 ); createPopupItem( 701, OB, mesh, "&& isComputable" ); // COMPUTE createPopupItem( 711, OB, mesh, "&& isComputable" ); // PRECOMPUTE @@ -2974,6 +3009,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createPopupItem( 803, View, group ); // EDIT_GROUP createPopupItem( 804, View, elems ); // ADD createPopupItem( 805, View, elems ); // REMOVE + popupMgr()->insert( separator(), -1, 0 ); createPopupItem( 214, View, mesh_group ); // UPDATE createPopupItem( 900, View, mesh_group ); // ADV_INFO diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index 884373dcf..74176f0bc 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -126,7 +126,8 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, // purpose : //================================================================================= SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, - SMESH::SMESH_GroupBase_ptr theGroup ) + SMESH::SMESH_GroupBase_ptr theGroup, + const bool theIsConvert ) : QDialog( SMESH::GetDesktop( theModule ) ), mySMESHGUI( theModule ), mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), @@ -136,7 +137,7 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, { initDialog( false ); if ( !theGroup->_is_nil() ) - init( theGroup ); + init( theGroup, theIsConvert ); else { mySelectSubMesh->setEnabled( false ); @@ -510,7 +511,8 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh) // function : Init() // purpose : //================================================================================= -void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup) +void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup, + const bool theIsConvert) { restoreShowEntityMode(); myMesh = theGroup->GetMesh(); @@ -537,23 +539,27 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup) myTypeGroup->button(aType)->setChecked(true); myGroup = SMESH::SMESH_Group::_narrow( theGroup ); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup ); - if (!myGroup->_is_nil()) - { - // NPAL19389: create a group with a selection in another group - // set actor of myMesh, if it is visible, else set - // actor of myGroup, if it is visible, else try - // any visible actor of group or submesh of myMesh - // commented, because an attempt to set selection on not displayed cells leads to error - //SetAppropriateActor(); - myActor = SMESH::FindActorByObject(myMesh); - if ( !myActor ) - myActor = SMESH::FindActorByObject(myGroup); - SMESH::SetPickable(myActor); + if (myGroup->_is_nil() && myGroupOnGeom->_is_nil()) + return; + + // NPAL19389: create a group with a selection in another group + // set actor of myMesh, if it is visible, else set + // actor of theGroup, if it is visible, else try + // any visible actor of group or submesh of myMesh + // commented, because an attempt to set selection on not displayed cells leads to error + //SetAppropriateActor(); + myActor = SMESH::FindActorByObject(myMesh); + if ( !myActor ) + myActor = SMESH::FindActorByObject(theGroup); + SMESH::SetPickable(myActor); - myGrpTypeGroup->button(0)->setChecked(true); - onGrpTypeChanged(0); + int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1)); + myGrpTypeGroup->button(grpType)->setChecked(true); + onGrpTypeChanged(grpType); + if ( grpType == 0 ) { myCurrentLineEdit = 0; myElements->clear(); setSelectionMode(aType); @@ -562,8 +568,8 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup) setShowEntityMode(); // depends on myTypeId myIdList.clear(); - if (!myGroup->IsEmpty()) { - SMESH::long_array_var anElements = myGroup->GetListOfID(); + if (!theGroup->IsEmpty()) { + SMESH::long_array_var anElements = theGroup->GetListOfID(); int k = anElements->length(); for (int i = 0; i < k; i++) { myIdList.append(anElements[i]); @@ -574,38 +580,19 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup) } else { - myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup ); - - if ( !myGroupOnGeom->_is_nil() ) + QString aShapeName( "" ); + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape(); + if (!aGroupShape->_is_nil()) { - // NPAL19389: create a group with a selection in another group - // set actor of myMesh, if it is visible, else set - // actor of myGroupOnGeom, if it is visible, else try - // any visible actor of group or submesh of myMesh - // commented, because an attempt to set selection on not displayed cells leads to error - //SetAppropriateActor(); - myActor = SMESH::FindActorByObject(myMesh); - if ( !myActor ) - myActor = SMESH::FindActorByObject(myGroupOnGeom); - SMESH::SetPickable(myActor); - - myGrpTypeGroup->button(1)->setChecked(true); - onGrpTypeChanged(1); - - QString aShapeName( "" ); - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape(); - if (!aGroupShape->_is_nil()) - { - _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry()); - aShapeName = aGroupShapeSO->GetName().c_str(); - } - myGeomGroupLine->setText( aShapeName ); - myNameChanged = true; - myName->blockSignals(true); - myName->setText( "Group On " + aShapeName); - myName->blockSignals(false); + _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry()); + aShapeName = aGroupShapeSO->GetName().c_str(); } + myGeomGroupLine->setText( aShapeName ); + myNameChanged = true; + myName->blockSignals(true); + myName->setText( "Group On " + aShapeName); + myName->blockSignals(false); } } @@ -755,6 +742,17 @@ bool SMESHGUI_GroupDlg::onApply() mySelectionMgr->clearSelected(); + if (myGroup->_is_nil()) { // creation or conversion + // check if group on geometry is not null + if (!CORBA::is_nil(myGroupOnGeom)) { + if (myMesh->_is_nil()) + return false; + myGroup = myMesh->ConvertToStandalone( myGroupOnGeom ); + // nullify pointer, because object become dead + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + } + } + if (myGroup->_is_nil()) { // creation if (myMesh->_is_nil()) return false; diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.h b/src/SMESHGUI/SMESHGUI_GroupDlg.h index 76c34f686..fb6b9dcf0 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.h +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.h @@ -69,7 +69,8 @@ public: SMESHGUI_GroupDlg( SMESHGUI*, SMESH::SMESH_Mesh_ptr = SMESH::SMESH_Mesh::_nil() ); SMESHGUI_GroupDlg( SMESHGUI*, - SMESH::SMESH_GroupBase_ptr ); + SMESH::SMESH_GroupBase_ptr, + const bool theIsConvert = false ); ~SMESHGUI_GroupDlg(); static QString GetDefaultName( const QString& ); @@ -112,7 +113,8 @@ private slots: private: void initDialog( bool ); void init( SMESH::SMESH_Mesh_ptr ); - void init( SMESH::SMESH_GroupBase_ptr ); + void init( SMESH::SMESH_GroupBase_ptr, + const bool theIsConvert = false ); void closeEvent( QCloseEvent* ); void enterEvent( QEvent* ); void hideEvent( QHideEvent* ); /* ESC key */ diff --git a/src/SMESHGUI/SMESHGUI_Selection.cxx b/src/SMESHGUI/SMESHGUI_Selection.cxx index 4711f1d10..7fc015a75 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.cxx +++ b/src/SMESHGUI/SMESHGUI_Selection.cxx @@ -116,6 +116,7 @@ QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const else if ( p=="hasReference" ) val = QVariant( hasReference( ind ) ); else if ( p=="isImported" ) val = QVariant( isImported( ind ) ); else if ( p=="facesOrientationMode" ) val = QVariant( facesOrientationMode( ind ) ); + else if ( p=="groupType" ) val = QVariant( groupType( ind ) ); if( val.isValid() ) return val; @@ -523,3 +524,27 @@ bool SMESHGUI_Selection::isImported( const int ind ) const */ return res; } + +//======================================================================= +//function : groupType +//purpose : +//======================================================================= + +QString SMESHGUI_Selection::groupType( int ind ) const +{ + QString e = entry( ind ); + _PTR(SObject) SO = SMESH::GetActiveStudyDocument()->FindObjectID( e.toLatin1().constData() ); + QString type; + if( SO ) + { + CORBA::Object_var obj = SMESH::SObjectToObject( SO ); + + SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( obj ); + SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( obj ); + if( !aGroup->_is_nil() ) + type = QString( "Group" ); + else if ( !aGroupOnGeom->_is_nil() ) + type = QString( "GroupOnGeom" ); + } + return type; +} diff --git a/src/SMESHGUI/SMESHGUI_Selection.h b/src/SMESHGUI/SMESHGUI_Selection.h index dfcac17f6..4bb5144e8 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.h +++ b/src/SMESHGUI/SMESHGUI_Selection.h @@ -65,6 +65,7 @@ public: virtual QList entityMode( int ) const; virtual QString controlMode( int ) const; virtual QString facesOrientationMode( int ) const; + virtual QString groupType( int ) const; SMESH_Actor* getActor( int ) const; diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index f99e4cb4d..1d4854fa5 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -250,6 +250,10 @@ MEN_EDIT_GROUP Edit Group + + MEN_EDIT_GEOMGROUP_AS_GROUP + Edit Group as Standalone + MEN_EDIT_HYPO Edit Hypothesis @@ -1020,6 +1024,10 @@ so that the application may crash. Do you wish to continue visualization?SMESH_EDIT_GROUP_TITLE Edit Group + + SMESH_EDIT_GEOMGROUP_AS_GROUP_TITLE + Edit Group as Standalone + SMESH_EDIT_HYPOTHESES Hypotheses Assignation @@ -2004,6 +2012,10 @@ Consider saving your work before application crash STB_EDIT_GROUP Edit Group + + STB_EDIT_GEOMGROUP_AS_GROUP + Edit Group as Standalone + STB_EDIT_HYPO Edit Hypothesis @@ -2472,6 +2484,10 @@ Consider saving your work before application crash TOP_EDIT_GROUP Edit Group + + TOP_EDIT_GEOMGROUP_AS_GROUP + Edit Group as Standalone + TOP_EDIT_HYPO Edit Hypothesis diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index 4a9979ea8..179275305 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -830,7 +830,13 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) theCommand->SetArg( 1, grp ); } else { - AddMeshAccess( theCommand ); + _pyID type = theCommand->GetArg( 1 ); + _pyID name = theCommand->GetArg( 2 ); + theCommand->SetMethod( "GroupOnGeom" ); + theCommand->RemoveArgs(); + theCommand->SetArg( 1, grp ); + theCommand->SetArg( 2, name ); + theCommand->SetArg( 3, type ); } } // ---------------------------------------------------------------------- @@ -908,7 +914,7 @@ bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand ) "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes", "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces", "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor", - "Clear" + "Clear", "ConvertToStandalone" ,"" }; // <- mark of end sameMethods.Insert( names ); } diff --git a/src/SMESH_I/SMESH_Group_i.cxx b/src/SMESH_I/SMESH_Group_i.cxx index 35276984d..254c38751 100644 --- a/src/SMESH_I/SMESH_Group_i.cxx +++ b/src/SMESH_I/SMESH_Group_i.cxx @@ -119,20 +119,24 @@ SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const void SMESH_GroupBase_i::SetName( const char* theName ) { - // Update Python script - TPythonDump() << _this() << ".SetName( '" << theName << "' )"; - // Perform renaming ::SMESH_Group* aGroup = GetSmeshGroup(); - if (aGroup) { - aGroup->SetName(theName); - - // Update group name in a study - SMESH_Gen_i* aGen = myMeshServant->GetGen(); - aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName ); + if (!aGroup) { + MESSAGE("can't set name of a vague group"); return; } - MESSAGE("can't set name of a vague group"); + + if ( aGroup->GetName() && !strcmp( aGroup->GetName(), theName ) ) + return; // nothing to rename + + aGroup->SetName(theName); + + // Update group name in a study + SMESH_Gen_i* aGen = myMeshServant->GetGen(); + aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName ); + + // Update Python script + TPythonDump() << _this() << ".SetName( '" << theName << "' )"; } //============================================================================= diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index ed84d70f0..8d5d82783 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -1629,6 +1629,74 @@ void SMESH_Mesh_i::CheckGeomGroupModif() } } +//============================================================================= +/*! + * \brief Create standalone group instead if group on geometry + * + */ +//============================================================================= + +SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGroup ) +{ + SMESH::SMESH_Group_var aGroup; + if ( theGroup->_is_nil() ) + return aGroup._retn(); + + Unexpect aCatch(SALOME_SalomeException); + + SMESH_GroupBase_i* aGroupToRem = + dynamic_cast( SMESH_Gen_i::GetServant( theGroup ).in() ); + if ( !aGroupToRem ) + return aGroup._retn(); + + int anId = aGroupToRem->GetLocalID(); + if ( !_impl->ConvertToStandalone( anId ) ) + return aGroup._retn(); + + SMESH_GroupBase_i* aGroupImpl; + aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId ); + + + // remove old instance of group from own map + _mapGroups.erase( anId ); + + SALOMEDS::StudyBuilder_var builder; + SALOMEDS::SObject_var aGroupSO; + SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); + if ( !aStudy->_is_nil() ) { + builder = aStudy->NewBuilder(); + aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup ); + if ( !aGroupSO->_is_nil() ) { + + // remove reference to geometry + SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO); + for ( ; chItr->More(); chItr->Next() ) + // Remove group's child SObject + builder->RemoveObject( chItr->Value() ); + + // Update Python script + TPythonDump() << aGroupSO << " = " << _this() << ".ConvertToStandalone( " + << aGroupSO << " )"; + } + } + + // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i + SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl ); + aGroupImpl->Register(); + // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i + + // remember new group in own map + aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() ); + _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup ); + + // register CORBA object for persistence + //int nextId = _gen_i->RegisterObject( aGroup ); + //if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId); + builder->SetIOR( aGroupSO, _gen_i->GetORB()->object_to_string( aGroup ) ); + + return aGroup._retn(); +} + //============================================================================= /*! * diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 684cbd534..a26c6e0f6 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -151,6 +151,8 @@ public: throw (SALOME::SALOME_Exception); + SMESH::SMESH_Group_ptr ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGeomGroup ); + // SMESH::string_array* GetLog(CORBA::Boolean clearAfterGet) // throw (SALOME::SALOME_Exception); diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index faa079cee..f5d53e574 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -1310,6 +1310,11 @@ class Mesh: return self.mesh.CreateDimGroup(groups, elem_type, name) + ## Convert group on geom into standalone group + # @ingroup l2_grps_delete + def ConvertToStandalone(self, group): + return self.mesh.ConvertToStandalone(group) + # Get some info about mesh: # ------------------------ -- 2.30.2