From: sln Date: Wed, 26 Nov 2008 15:29:10 +0000 (+0000) Subject: 0019939: EDF 762 SMESH : Definition of groups from other existing groups X-Git-Tag: Phase8_Part1_16122008~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=634461f414dcb9b6ccd07df76c9d7bb9ddfe3bcc;p=modules%2Fsmesh.git 0019939: EDF 762 SMESH : Definition of groups from other existing groups ?Union of two groups?, ?Union of two groups? and ?Cut of two groups? dialog boxes are updated for supporting works with several groups instead of two groups only New ?Create group of underlying entities? dialog box is provided. It is intended for creating groups of entities from existing groups of superior dimensions (groups of nodes from group of faces, for example). Dialog contains 1) line edit for defining name of new group, 2) combo-box for defining dimension of elements (nodes, edges, etc), 3) list-box for defining source groups --- diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 5fb5edaa2..07f2044b3 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -1879,29 +1879,38 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) } break; } - + case 810: // Union Groups case 811: // Intersect groups case 812: // Cut groups { - if ( !vtkwnd ) - { - SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), - tr( "NOT_A_VTK_VIEWER" ) ); + if ( checkLock( aStudy ) ) break; - } + EmitSignalDeactivateDialog(); + + SMESHGUI_GroupOpDlg* aDlg = 0; + if ( theCommandID == 810 ) + aDlg = new SMESHGUI_UnionGroupsDlg( this ); + else if ( theCommandID == 811 ) + aDlg = new SMESHGUI_IntersectGroupsDlg( this ); + else + aDlg = new SMESHGUI_CutGroupsDlg( this ); + + aDlg->show(); + + break; + } + + case 814: // Create groups of entities from existing groups of superior dimensions + { if ( checkLock( aStudy ) ) break; EmitSignalDeactivateDialog(); + SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this ); + aDlg->show(); - int aMode; - if ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION; - else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT; - else aMode = SMESHGUI_GroupOpDlg::CUT; - - ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show(); break; } @@ -2605,6 +2614,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createSMESHAction( 810, "UN_GROUP", "ICON_UNION" ); createSMESHAction( 811, "INT_GROUP", "ICON_INTERSECT" ); createSMESHAction( 812, "CUT_GROUP", "ICON_CUT" ); + createSMESHAction( 814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" ); createSMESHAction( 813, "DEL_GROUP", "ICON_DEL_GROUP" ); createSMESHAction( 900, "ADV_INFO", "ICON_ADV_INFO" ); createSMESHAction( 902, "STD_INFO", "ICON_STD_INFO" ); @@ -2741,6 +2751,8 @@ void SMESHGUI::initialize( CAM_Application* app ) createMenu( 811, meshId, -1 ); createMenu( 812, meshId, -1 ); createMenu( separator(), meshId, -1 ); + createMenu( 814, meshId, -1 ); + createMenu( separator(), meshId, -1 ); createMenu( 813, meshId, -1 ); createMenu( separator(), meshId, -1 ); createMenu( 900, meshId, -1 ); diff --git a/src/SMESHGUI/SMESHGUI_GroupOpDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupOpDlg.cxx index 919fa2f9b..796fcb0b7 100644 --- a/src/SMESHGUI/SMESHGUI_GroupOpDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupOpDlg.cxx @@ -53,6 +53,11 @@ #include #include #include +#include +#include +#include +#include +#include #define SPACING 6 #define MARGIN 11 @@ -62,32 +67,17 @@ * Description : Perform boolean operations on groups */ -//======================================================================= -// name : SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg -// Purpose : Constructor -//======================================================================= -SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule, const int theMode ) +/*! + \brief Constructor + \param theModule pointer on module instance +*/ +SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule ) : QDialog( SMESH::GetDesktop( theModule ) ), mySMESHGUI( theModule ), mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ) { setModal(false); - myMode = theMode; - - if (myMode == UNION) { - setWindowTitle(tr("UNION_OF_TWO_GROUPS")); - myHelpFileName = "using_operations_on_groups_page.html#union_anchor"; - } - else if (myMode == INTERSECT) { - setWindowTitle(tr("INTERSECTION_OF_TWO_GROUPS")); - myHelpFileName = "using_operations_on_groups_page.html#intersection_anchor"; - } - else { - setWindowTitle(tr("CUT_OF_TWO_GROUPS")); - myHelpFileName = "using_operations_on_groups_page.html#cut_anchor"; - } - mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); QVBoxLayout* aDlgLay = new QVBoxLayout (this); @@ -103,11 +93,12 @@ SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule, const int theMode Init(); } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::createMainFrame -// Purpose : Create frame containing dialog's input fields -//======================================================================= -QWidget* SMESHGUI_GroupOpDlg::createMainFrame (QWidget* theParent) +/*! + \brief Creates frame containing dialog's input fields + \param theParent parent widget + \return pointer on created widget +*/ +QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent ) { QWidget* aMainGrp = new QWidget(theParent); QVBoxLayout* aLay = new QVBoxLayout(aMainGrp); @@ -127,46 +118,64 @@ QWidget* SMESHGUI_GroupOpDlg::createMainFrame (QWidget* theParent) aNameGrpLayout->addWidget(myNameEdit); // ------------------------------------------------------ - QGroupBox* anArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp); - QGridLayout* anArgGrpLayout = new QGridLayout(anArgGrp); - anArgGrpLayout->setMargin(MARGIN); - anArgGrpLayout->setSpacing(SPACING); + myArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp); - QLabel* aObj1Lab = new QLabel(myMode == CUT ? tr("MAIN_OBJECT") :tr("OBJECT_1"), anArgGrp); - myBtn1 = new QPushButton(anArgGrp); - myEdit1 = new QLineEdit(anArgGrp); - myEdit1->setAlignment( Qt::AlignLeft ); - QLabel* aObj2Lab = new QLabel(myMode == CUT ? tr("TOOL_OBJECT") :tr("OBJECT_2"), anArgGrp); - myBtn2 = new QPushButton(anArgGrp); - myEdit2 = new QLineEdit(anArgGrp); - myEdit2->setAlignment( Qt::AlignLeft ); - - myEdit1->setReadOnly(true); - myEdit2->setReadOnly(true); + // ------------------------------------------------------ + + QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this); + QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox); + aColorBoxLayout->setMargin(MARGIN); + aColorBoxLayout->setSpacing(SPACING); - QPixmap aPix (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT"))); - myBtn1->setIcon(aPix); - myBtn2->setIcon(aPix); + QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox ); + myColorBtn = new QtxColorButton(aColorBox); + myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding, + myColorBtn->sizePolicy().verticalPolicy() ); - anArgGrpLayout->addWidget(aObj1Lab, 0, 0); - anArgGrpLayout->addWidget(myBtn1, 0, 1); - anArgGrpLayout->addWidget(myEdit1, 0, 2); - anArgGrpLayout->addWidget(aObj2Lab, 1, 0); - anArgGrpLayout->addWidget(myBtn2, 1, 1); - anArgGrpLayout->addWidget(myEdit2, 1, 2); + aColorBoxLayout->addWidget(aColorLab); + aColorBoxLayout->addWidget(myColorBtn); // ------------------------------------------------------ - aLay->addWidget(aNameGrp); - aLay->addWidget(anArgGrp); + aLay->addWidget( aNameGrp ); + aLay->addWidget( myArgGrp ); + aLay->addWidget( aColorBox ); return aMainGrp; } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::createButtonFrame -// Purpose : Create frame containing buttons -//======================================================================= +/*! + \brief Gets pointer on arguments group box + \return pointer on arguments group box +*/ +QGroupBox* SMESHGUI_GroupOpDlg::getArgGrp() const +{ + return myArgGrp; +} + +/*! + \brief Sets help file name + \param theFName help file name +*/ +void SMESHGUI_GroupOpDlg::setHelpFileName( const QString& theFName ) +{ + myHelpFileName = theFName; +} + +/*! + \brief Gets pointer to the module instance + \return pointer to the module instance +*/ +SMESHGUI* SMESHGUI_GroupOpDlg::getSMESHGUI() const +{ + return mySMESHGUI; +} + +/*! + \brief Create frame containing buttons + \param theParent parent widget + \return pointer to the created frame +*/ QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent) { QGroupBox* aFrame = new QGroupBox(theParent); @@ -197,75 +206,95 @@ QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent) return aFrame; } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg -// Purpose : Destructor -//======================================================================= +/*! + \brief Destructor +*/ SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg() { } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::Init -// Purpose : Init dialog fields, connect signals and slots, show dialog -//======================================================================= +/*! + \brief Init dialog fields, connect signals and slots, show dialog +*/ void SMESHGUI_GroupOpDlg::Init() { mySMESHGUI->SetActiveDialogBox((QDialog*)this); - myFocusWg = myEdit1; - - myGroup1 = SMESH::SMESH_GroupBase::_nil(); - myGroup2 = SMESH::SMESH_GroupBase::_nil(); - + // selection and SMESHGUI connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone())); connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate())); connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(ClickOnClose())); - connect(myBtn1, SIGNAL(clicked()), this, SLOT(onFocusChanged())); - connect(myBtn2, SIGNAL(clicked()), this, SLOT(onFocusChanged())); - // set selection mode if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode(ActorSelection); mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP)); } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::isValid -// Purpose : Verify validity of input data -//======================================================================= -bool SMESHGUI_GroupOpDlg::isValid() +/*! + \brief Validate list of groups used for operation. Checks whether they corresponds + to the same face and have one type + \param theListGrp input list of groups + \return TRUE if groups are valid, FALSE otherwise +*/ +bool SMESHGUI_GroupOpDlg::isValid( const QList& theListGrp ) { - // Verify validity of group name - if (myNameEdit->text() == "") { - SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), - tr("EMPTY_NAME")); + if ( theListGrp.isEmpty() ) + { + SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"), + tr("INCORRECT_ARGUMENTS") ); return false; } - // Verufy wheter arguments speciffiyed - if (myGroup1->_is_nil() || myGroup2->_is_nil()) { - SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), - tr("INCORRECT_ARGUMENTS")); - return false; - } + int aMeshId = -1, aGrpType = -1; + QList::const_iterator anIter; + for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter ) + { + SMESH::SMESH_GroupBase_var aGrp = *anIter; + if ( CORBA::is_nil( aGrp ) ) + continue; // nonsence + + SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh(); + if ( CORBA::is_nil( aMesh ) ) + continue; + + // mesh id + int aCurrId = aMesh->GetId(); + if ( aMeshId == -1 ) + aMeshId = aCurrId; + else + { + if ( aMeshId != aCurrId ) + { + aMeshId = -1; // different meshes + break; + } + } - // Verify whether arguments belongs to same mesh - SMESH::SMESH_Mesh_ptr aMesh1 = myGroup1->GetMesh(); - SMESH::SMESH_Mesh_ptr aMesh2 = myGroup2->GetMesh(); + // group type + int aCurrType = aGrp->GetType(); + if ( aGrpType == -1 ) + aGrpType = aCurrType; + else + { + if ( aGrpType != aCurrType ) + { + aGrpType = -1; // different types + break; + } + } - int aMeshId1 = !aMesh1->_is_nil() ? aMesh1->GetId() : -1; - int aMeshId2 = !aMesh2->_is_nil() ? aMesh2->GetId() : -1; + } - if (aMeshId1 != aMeshId2 || aMeshId1 == -1) { + if ( aMeshId == -1 ) + { SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), tr("DIFF_MESHES")); return false; } - // Verify whether groups have same types of entities - if (myGroup1->GetType() != myGroup2->GetType()) { + if ( aGrpType == -1 ) + { SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), tr("DIFF_TYPES")); return false; @@ -274,63 +303,33 @@ bool SMESHGUI_GroupOpDlg::isValid() return true; } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::onApply -// Purpose : SLOT called when "Apply" button pressed. -//======================================================================= -bool SMESHGUI_GroupOpDlg::onApply() -{ - if (!isValid() || mySMESHGUI->isActiveStudyLocked()) - return false; - - SMESH::SMESH_Mesh_ptr aMesh = myGroup1->GetMesh(); - QString aName = myNameEdit->text(); - SMESH::SMESH_Group_ptr aNewGrp = SMESH::SMESH_Group::_nil(); - - if (myMode == UNION) aNewGrp = aMesh->UnionGroups(myGroup1, myGroup2, aName.toLatin1().data()); - else if (myMode == INTERSECT) aNewGrp = aMesh->IntersectGroups(myGroup1, myGroup2, aName.toLatin1().data()); - else aNewGrp = aMesh->CutGroups(myGroup1, myGroup2, aName.toLatin1().data()); - - if (!aNewGrp->_is_nil()) { - mySMESHGUI->updateObjBrowser(true); - reset(); - return true; - } else { - SUIT_MessageBox::critical(this, tr("SMESH_ERROR"), - tr("SMESH_OPERATION_FAILED")); - return false; - } -} - -//======================================================================= -// name : SMESHGUI_GroupOpDlg::onOk -// Purpose : SLOT called when "Ok" button pressed. -//======================================================================= +/*! + \brief SLOT called when "Ok" button pressed performs operation and closes dialog box +*/ void SMESHGUI_GroupOpDlg::onOk() { - if (onApply()) + if ( onApply() ) onClose(); } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::onClose -// Purpose : SLOT called when "Close" button pressed. Close dialog -//======================================================================= +/*! + \brief SLOT called when "Close" button pressed closes dialog +*/ void SMESHGUI_GroupOpDlg::onClose() { if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode(ActorSelection); - disconnect(mySelectionMgr, 0, this, 0); - disconnect(mySMESHGUI, 0, this, 0); + disconnect( mySelectionMgr, 0, this, 0 ); + disconnect( mySMESHGUI, 0, this, 0 ); mySMESHGUI->ResetState(); mySelectionMgr->clearFilters(); + reset(); reject(); } -//================================================================================= -// function : onHelp() -// purpose : -//================================================================================= +/*! + \brief SLOT called when "Help" button pressed shows "Help" page +*/ void SMESHGUI_GroupOpDlg::onHelp() { LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); @@ -351,54 +350,108 @@ void SMESHGUI_GroupOpDlg::onHelp() } } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::onSelectionDone -// Purpose : SLOT called when selection changed -//======================================================================= -void SMESHGUI_GroupOpDlg::onSelectionDone() +/*! + \brief Gets list of currently selected groups from selection manager + \param theOutList out list of groups + \param theOutNames out list of group of group names + \return TRUE if operation theOutList is not empty, FALSE otherwise +*/ +bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList& theOutList, + QStringList& theOutNames ) { - if (myFocusWg == myEdit1) - myGroup1 = SMESH::SMESH_GroupBase::_nil(); - else - myGroup2 = SMESH::SMESH_GroupBase::_nil(); + theOutList.clear(); - myFocusWg->setText(""); + theOutList.clear(); + theOutNames.clear(); - SALOME_ListIO aList; - mySelectionMgr->selectedObjects(aList); - - if (aList.Extent() == 1) { + SALOME_ListIO aListIO; + mySelectionMgr->selectedObjects( aListIO ); + SALOME_ListIteratorOfListIO anIter ( aListIO ); + for ( ; anIter.More(); anIter.Next()) + { SMESH::SMESH_GroupBase_var aGroup = - SMESH::IObjectToInterface(aList.First()); - - if (!aGroup->_is_nil()) + SMESH::IObjectToInterface(anIter.Value()); + if ( !aGroup->_is_nil()) { - myFocusWg->setText(aGroup->GetName()); - myFocusWg->setCursorPosition( 0 ); - - if (myFocusWg == myEdit1) - myGroup1 = aGroup; - else - myGroup2 = aGroup; + theOutList.append( aGroup ); + theOutNames.append( aGroup->GetName() ); } } + + return theOutList.count() > 0; +} + +/*! + \brief Converts QT-list of group to the list acceptable by IDL interface + \param theIn input list + \return list acceptable by IDL interface +*/ +SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert( + const QList& theIn ) +{ + SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups(); + aList->length( theIn.count() ); + + QList::const_iterator anIter = theIn.begin(); + for ( int i = 0; anIter != theIn.end(); ++anIter, ++i ) + aList[ i ] = *anIter; + + return aList._retn(); +} + +/*! + \brief Get color to be assigned to group + \return color to be assigned to group +*/ +SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const +{ + QColor aQColor = myColorBtn->color(); + + SALOMEDS::Color aColor; + aColor.R = (float)aQColor.red() / 255.0; + aColor.G = (float)aQColor.green() / 255.0; + aColor.B = (float)aQColor.blue() / 255.0; + + return aColor; } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::onDeactivate -// Purpose : SLOT called when dialog must be deativated -//======================================================================= +/*! + \brief SLOT, called when selection is changed. Current implementation does + nothing. The method should be redefined in derived classes to update + corresponding GUI controls +*/ +void SMESHGUI_GroupOpDlg::onSelectionDone() +{ +} + +/*! + \brief Calls onSelectionDone() and setVisible() method of base class + \param visible the visible state of the dialog +*/ +void SMESHGUI_GroupOpDlg::setVisible( bool visible ) +{ + if ( visible ) + { + onSelectionDone(); + resize( minimumSizeHint().width(), sizeHint().height() ); + } + QDialog::setVisible( visible ); +} + +/*! + \brief SLOT called when dialog must be deativated +*/ void SMESHGUI_GroupOpDlg::onDeactivate() { setEnabled(false); mySelectionMgr->clearFilters(); } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::enterEvent -// Purpose : Event filter -//======================================================================= -void SMESHGUI_GroupOpDlg::enterEvent (QEvent*) +/*! + \brief Event filter updates selection mode and selection filter. This virtual method + is redefined from the base class it is called when dialog obtains input focus +*/ +void SMESHGUI_GroupOpDlg::enterEvent(QEvent*) { mySMESHGUI->EmitSignalDeactivateDialog(); setEnabled(true); @@ -407,43 +460,49 @@ void SMESHGUI_GroupOpDlg::enterEvent (QEvent*) mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP)); } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::closeEvent -// purpose : -//======================================================================= -void SMESHGUI_GroupOpDlg::closeEvent (QCloseEvent*) +/*! + \brief Provides reaction on close event, closes the dialog box +*/ +void SMESHGUI_GroupOpDlg::closeEvent(QCloseEvent*) { onClose(); } -//======================================================================= -// name : SMESHGUI_GroupOpDlg::onFocusChanged -// Purpose : SLOT. Called when "Select" button pressed. -//======================================================================= -void SMESHGUI_GroupOpDlg::onFocusChanged() -{ - const QObject* aSender = sender(); - myFocusWg = aSender == myBtn1 ? myEdit1 : myEdit2; - onSelectionDone(); -} - -//======================================================================= -// name : SMESHGUI_GroupOpDlg::reset -// Purpose : Rest state of dialog -//======================================================================= +/*! + \brief Resets state of the dialog, initializes its fields with default value, etc. + Usually called by onApply() slot to reinitialize dialog fields. This virtual method + should be redefined in derived class to update its own fileds +*/ void SMESHGUI_GroupOpDlg::reset() { myNameEdit->setText(""); - myEdit1->setText(""); - myEdit2->setText(""); - myFocusWg = myEdit1; myNameEdit->setFocus(); } -//================================================================================= -// function : keyPressEvent() -// purpose : -//================================================================================= +/*! + \brief Gets name of group to be created + \return name of group to be created + \sa setName() +*/ +QString SMESHGUI_GroupOpDlg::getName() const +{ + return myNameEdit->text(); +} + +/*! + \brief Sets name of group to be created + \param theName name of group to be created + \sa getName() +*/ +void SMESHGUI_GroupOpDlg::setName( const QString& theName ) +{ + myNameEdit->setText( theName ); +} + +/*! + \brief Provides reaction on “F1” button pressing + \param e key press event +*/ void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e ) { QDialog::keyPressEvent( e ); @@ -455,3 +514,535 @@ void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e ) onHelp(); } } + +/*! + \brief This virtual slot does nothing and should be redefined in derived classes + \return return false; +*/ +bool SMESHGUI_GroupOpDlg::onApply() +{ + return false; +} + +// === === === === === === === === === === === === === === === === === === === === === + +/*! + \brief Constructor + \param theModule module +*/ +SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule ) +: SMESHGUI_GroupOpDlg( theModule ) +{ + setWindowTitle(tr("UNION_OF_GROUPS")); + setHelpFileName( "using_operations_on_groups_page.html#union_anchor" ); + + QGroupBox* anArgGrp = getArgGrp(); + myListWg = new QListWidget( anArgGrp ); + + QHBoxLayout* aLay = new QHBoxLayout( anArgGrp ); + aLay->addWidget( myListWg ); +} + +/*! + \brief Destructor +*/ +SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg() +{ +} + +/*! + \brief This virtual method redefined from the base class resets state + of the dialog, initializes its fields with default value, etc. +*/ +void SMESHGUI_UnionGroupsDlg::reset() +{ + SMESHGUI_GroupOpDlg::reset(); + myListWg->clear(); + myGroups.clear(); +} + +/*! + \brief SLOT called when apply button is pressed performs operation + \return TRUE if operation has been completed successfully, FALSE otherwise +*/ +bool SMESHGUI_UnionGroupsDlg::onApply() +{ + if ( getSMESHGUI()->isActiveStudyLocked()) + return false; + + // Verify validity of group name + if ( getName() == "" ) + { + SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), + SMESHGUI_GroupOpDlg::tr("EMPTY_NAME")); + return false; + } + + if ( !isValid( myGroups ) ) + return false; + + SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh(); + QString aName = getName(); + + bool aRes = false; + try + { + SMESH::ListOfGroups_var aList = convert( myGroups ); + SMESH::SMESH_Group_var aNewGrp = + aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() ); + if ( !CORBA::is_nil( aNewGrp ) ) + { + aNewGrp->SetColor( getColor() ); + aRes = true; + } + } + catch( ... ) + { + aRes = false; + } + + if ( aRes ) + { + getSMESHGUI()->updateObjBrowser(true); + reset(); + return true; + } + else + { + SUIT_MessageBox::critical(this, tr("SMESH_ERROR"), + tr("SMESH_OPERATION_FAILED")); + return false; + } +} + +/*! + \brief SLOT, called when selection is changed, updates corresponding GUI controls +*/ +void SMESHGUI_UnionGroupsDlg::onSelectionDone() +{ + QStringList aNames; + getSelectedGroups( myGroups, aNames ); + myListWg->clear(); + myListWg->addItems( aNames ); +} + +// === === === === === === === === === === === === === === === === === === === === === + +/*! + \brief Constructor + \param theModule module +*/ +SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule ) +: SMESHGUI_GroupOpDlg( theModule ) +{ + setWindowTitle(tr("INTERSECTION_OF_GROUPS")); + setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" ); + + QGroupBox* anArgGrp = getArgGrp(); + myListWg = new QListWidget( anArgGrp ); + + QHBoxLayout* aLay = new QHBoxLayout( anArgGrp ); + aLay->addWidget( myListWg ); +} + +/*! + \brief Destructor +*/ +SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg() +{ +} + +/*! + \brief This virtual method redefined from the base class resets state + of the dialog, initializes its fields with default value, etc. +*/ +void SMESHGUI_IntersectGroupsDlg::reset() +{ + SMESHGUI_GroupOpDlg::reset(); + myListWg->clear(); + myGroups.clear(); +} + +/*! + \brief SLOT called when apply button is pressed performs operation + \return TRUE if operation has been completed successfully, FALSE otherwise +*/ +bool SMESHGUI_IntersectGroupsDlg::onApply() +{ + if ( getSMESHGUI()->isActiveStudyLocked()) + return false; + + // Verify validity of group name + if ( getName() == "" ) + { + SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), + SMESHGUI_GroupOpDlg::tr("EMPTY_NAME")); + return false; + } + + if ( !isValid( myGroups ) ) + return false; + + SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh(); + QString aName = getName(); + + bool aRes = false; + try + { + SMESH::ListOfGroups_var aList = convert( myGroups ); + SMESH::SMESH_Group_var aNewGrp = + aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() ); + if ( !CORBA::is_nil( aNewGrp ) ) + { + aNewGrp->SetColor( getColor() ); + aRes = true; + } + } + catch( ... ) + { + aRes = false; + } + + if ( aRes ) + { + getSMESHGUI()->updateObjBrowser(true); + reset(); + return true; + } + else + { + SUIT_MessageBox::critical(this, tr("SMESH_ERROR"), + tr("SMESH_OPERATION_FAILED")); + return false; + } +} + +/*! + \brief SLOT, called when selection is changed, updates corresponding GUI controls +*/ +void SMESHGUI_IntersectGroupsDlg::onSelectionDone() +{ + QStringList aNames; + getSelectedGroups( myGroups, aNames ); + myListWg->clear(); + myListWg->addItems( aNames ); +} + +// === === === === === === === === === === === === === === === === === === === === === + +/*! + \brief Constructor + \param theModule module +*/ +SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule ) +: SMESHGUI_GroupOpDlg( theModule ) +{ + setWindowTitle(tr("CUT_OF_GROUPS")); + setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" ); + + QGroupBox* anArgGrp = getArgGrp(); + + QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT"))); + + // frame 1 + QFrame* aFrame1 = new QFrame( anArgGrp ); + QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 ); + aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myBtn1 = new QPushButton( aFrame1 ); + myBtn1->setIcon(aPix); + myListWg1 = new QListWidget( aFrame1 ); + + QGridLayout* aLay1 = new QGridLayout( aFrame1 ); + aLay1->setSpacing( SPACING ); + aLay1->addWidget( aLbl1, 0, 0 ); + aLay1->addWidget( myBtn1, 0, 1 ); + aLay1->addWidget( myListWg1, 1, 0, 1, 2 ); + //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); + //aLay1->addItem( aHSpacer1, 0, 2 ); + + + // frame 2 + QFrame* aFrame2 = new QFrame( anArgGrp ); + QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 ); + aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myBtn2 = new QPushButton( aFrame2 ); + myBtn2->setIcon(aPix); + myListWg2 = new QListWidget( aFrame2 ); + + QGridLayout* aLay2 = new QGridLayout( aFrame2 ); + aLay2->setSpacing( SPACING ); + aLay2->addWidget( aLbl2, 0, 0 ); + aLay2->addWidget( myBtn2, 0, 1 ); + aLay2->addWidget( myListWg2, 1, 0, 1, 2 ); + //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); + //aLay2->addItem( aHSpacer2, 0, 2 ); + + // create button group + + QButtonGroup* aGrp = new QButtonGroup( anArgGrp ); + aGrp->addButton( myBtn1, 0 ); + aGrp->addButton( myBtn2, 1 ); + myBtn1->setCheckable( true ); + myBtn2->setCheckable( true ); + aGrp->setExclusive( true ); + myBtn1->setChecked( true ); + + // fill layout + QHBoxLayout* aLay = new QHBoxLayout( anArgGrp ); + aLay->setSpacing( SPACING ); + aLay->addWidget( aFrame1 ); + aLay->addWidget( aFrame2 ); +} + +/*! + \brief Destructor +*/ +SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg() +{ +} + +/*! + \brief This virtual method redefined from the base class resets state + of the dialog, initializes its fields with default value, etc. +*/ +void SMESHGUI_CutGroupsDlg::reset() +{ + SMESHGUI_GroupOpDlg::reset(); + + myListWg1->clear(); + myGroups1.clear(); + + myListWg2->clear(); + myGroups2.clear(); +} + +/*! + \brief SLOT called when apply button is pressed performs operation + \return TRUE if operation has been completed successfully, FALSE otherwise +*/ +bool SMESHGUI_CutGroupsDlg::onApply() +{ + if ( getSMESHGUI()->isActiveStudyLocked()) + return false; + + // Verify validity of group name + if ( getName() == "" ) + { + SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), + SMESHGUI_GroupOpDlg::tr("EMPTY_NAME")); + return false; + } + + if ( myGroups1.isEmpty() || myGroups2.isEmpty() ) + { + SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"), + SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") ); + return false; + } + + QList aGroups = myGroups1; + QList::iterator anIter; + for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter ) + aGroups.append( *anIter ); + + if ( !isValid( aGroups ) ) + return false; + + SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh(); + QString aName = getName(); + + bool aRes = false; + try + { + SMESH::ListOfGroups_var aList1 = convert( myGroups1 ); + SMESH::ListOfGroups_var aList2 = convert( myGroups2 ); + SMESH::SMESH_Group_var aNewGrp = + aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() ); + if ( !CORBA::is_nil( aNewGrp ) ) + { + aNewGrp->SetColor( getColor() ); + aRes = true; + } + } + catch( ... ) + { + aRes = false; + } + + if ( aRes ) + { + getSMESHGUI()->updateObjBrowser(true); + reset(); + return true; + } + else + { + SUIT_MessageBox::critical(this, tr("SMESH_ERROR"), + tr("SMESH_OPERATION_FAILED")); + return false; + } +} + +/*! + \brief SLOT, called when selection is changed, updates corresponding GUI controls +*/ +void SMESHGUI_CutGroupsDlg::onSelectionDone() +{ + QStringList aNames; + if ( myBtn2->isChecked() ) + { + getSelectedGroups( myGroups2, aNames ); + myListWg2->clear(); + myListWg2->addItems( aNames ); + } + else + { + getSelectedGroups( myGroups1, aNames ); + myListWg1->clear(); + myListWg1->addItems( aNames ); + } +} + +// === === === === === === === === === === === === === === === === === === === === === + +/*! + \brief Constructor + \param theModule module +*/ +SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule ) +: SMESHGUI_GroupOpDlg( theModule ) +{ + setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) ); + setHelpFileName( "using_operations_on_groups_page.html#underlying_anchor" ); + + QGroupBox* anArgGrp = getArgGrp(); + + QLabel* aLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp ); + + myCombo = new QComboBox( anArgGrp ); + static QStringList anItems; + if ( anItems.isEmpty() ) + { + anItems.append( tr( "NODE" ) ); + anItems.append( tr( "EDGE" ) ); + anItems.append( tr( "FACE" ) ); + anItems.append( tr( "VOLUME" ) ); + } + myCombo->addItems( anItems ); + myCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + myListWg = new QListWidget( anArgGrp ); + + // layout + QGridLayout* aLay = new QGridLayout( anArgGrp ); + aLay->setSpacing( SPACING ); + aLay->addWidget( aLbl, 0, 0 ); + aLay->addWidget( myCombo, 0, 1 ); + aLay->addWidget( myListWg, 1, 0, 1, 2 ); +} + +/*! + \brief Destructor +*/ +SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg() +{ +} + +/*! + \brief This virtual method redefined from the base class resets state + of the dialog, initializes its fields with default value, etc. +*/ +void SMESHGUI_DimGroupDlg::reset() +{ + SMESHGUI_GroupOpDlg::reset(); + myListWg->clear(); + myGroups.clear(); +} + +/*! + \brief Gets elements type + \return elements type + \sa setElementType() +*/ +SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const +{ + return (SMESH::ElementType)( myCombo->currentIndex() + 1 ); +} + +/*! + \brief Sets elements type + \param theElemType elements type + \sa getElementType() +*/ +void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType ) +{ + myCombo->setCurrentIndex( theElemType - 1 ); +} + +/*! + \brief SLOT called when apply button is pressed performs operation + \return TRUE if operation has been completed successfully, FALSE otherwise +*/ +bool SMESHGUI_DimGroupDlg::onApply() +{ + if ( getSMESHGUI()->isActiveStudyLocked()) + return false; + + // Verify validity of group name + if ( getName() == "" ) + { + SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"), + SMESHGUI_GroupOpDlg::tr("EMPTY_NAME")); + return false; + } + + if ( !isValid( myGroups ) ) + return false; + + SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh(); + QString aName = getName(); + + bool aRes = false; + try + { + SMESH::ListOfGroups_var aList = convert( myGroups ); + SMESH::ElementType anElemType = getElementType(); + SMESH::SMESH_Group_var aNewGrp = + aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData() ); + if ( !CORBA::is_nil( aNewGrp ) ) + { + aNewGrp->SetColor( getColor() ); + aRes = true; + } + } + catch( ... ) + { + aRes = false; + } + + if ( aRes ) + { + getSMESHGUI()->updateObjBrowser(true); + reset(); + return true; + } + else + { + SUIT_MessageBox::critical(this, tr("SMESH_ERROR"), + tr("SMESH_OPERATION_FAILED")); + return false; + } +} + +/*! + \brief SLOT, called when selection is changed, updates corresponding GUI controls +*/ +void SMESHGUI_DimGroupDlg::onSelectionDone() +{ + QStringList aNames; + getSelectedGroups( myGroups, aNames ); + myListWg->clear(); + myListWg->addItems( aNames ); +} + + diff --git a/src/SMESHGUI/SMESHGUI_GroupOpDlg.h b/src/SMESHGUI/SMESHGUI_GroupOpDlg.h index 3c37a2602..0c9cb2aeb 100644 --- a/src/SMESHGUI/SMESHGUI_GroupOpDlg.h +++ b/src/SMESHGUI/SMESHGUI_GroupOpDlg.h @@ -37,6 +37,10 @@ #include CORBA_SERVER_HEADER(SMESH_Group) class QPushButton; +class QtxColorButton; +class QComboBox; +class QListWidget; +class QGroupBox; class QLineEdit; class SMESHGUI; class LightApp_SelectionMgr; @@ -52,14 +56,37 @@ class SMESHGUI_EXPORT SMESHGUI_GroupOpDlg : public QDialog Q_OBJECT public: - enum { UNION, INTERSECT, CUT }; + //enum { UNION, INTERSECT, CUT }; public: - SMESHGUI_GroupOpDlg( SMESHGUI*, const int ); + SMESHGUI_GroupOpDlg( SMESHGUI* ); virtual ~SMESHGUI_GroupOpDlg(); void Init(); - + +protected slots: + + virtual bool onApply(); + virtual void onSelectionDone(); + virtual void setVisible ( bool visible ); + +protected: + + virtual void reset(); + + QString getName() const; + void setName( const QString& theName ); + + QGroupBox* getArgGrp() const; + void setHelpFileName( const QString& theFName ); + SMESHGUI* getSMESHGUI() const; + bool isValid( const QList& theListGrp ); + bool getSelectedGroups( QList& theOutList, + QStringList& theOutNames ); + SMESH::ListOfGroups* convert( const QList& ); + + SALOMEDS::Color getColor() const; + private: void closeEvent( QCloseEvent* ); void enterEvent( QEvent* ); @@ -67,20 +94,15 @@ private: private slots: void onOk(); - bool onApply(); void onClose(); void onHelp(); void onDeactivate(); - void onSelectionDone(); - void onFocusChanged(); private: QWidget* createButtonFrame( QWidget* ); QWidget* createMainFrame ( QWidget* ); - bool isValid(); - void reset(); - + private: QPushButton* myOkBtn; QPushButton* myApplyBtn; @@ -88,22 +110,129 @@ private: QPushButton* myHelpBtn; QLineEdit* myNameEdit; - QLineEdit* myEdit1; - QLineEdit* myEdit2; - QPushButton* myBtn1; - QPushButton* myBtn2; + QGroupBox* myArgGrp; + QtxColorButton* myColorBtn; SMESHGUI* mySMESHGUI; LightApp_SelectionMgr* mySelectionMgr; - int myMode; SVTK_Selector* mySelector; - QLineEdit* myFocusWg; - - SMESH::SMESH_GroupBase_var myGroup1; - SMESH::SMESH_GroupBase_var myGroup2; - QString myHelpFileName; }; +/* + Class : SMESHGUI_UnionGroupsDlg + Description : Perform union of several groups +*/ + +class SMESHGUI_EXPORT SMESHGUI_UnionGroupsDlg : public SMESHGUI_GroupOpDlg +{ + Q_OBJECT + +public: + + SMESHGUI_UnionGroupsDlg( SMESHGUI* ); + virtual ~SMESHGUI_UnionGroupsDlg(); + +protected slots: + virtual bool onApply(); + virtual void onSelectionDone(); + +protected: + virtual void reset(); + +private: + QListWidget* myListWg; + QList myGroups; +}; + +/* + Class : SMESHGUI_IntersectGroupsDlg + Description : Perform intersection of several groups +*/ + +class SMESHGUI_EXPORT SMESHGUI_IntersectGroupsDlg : public SMESHGUI_GroupOpDlg +{ + Q_OBJECT + +public: + + SMESHGUI_IntersectGroupsDlg( SMESHGUI* ); + virtual ~SMESHGUI_IntersectGroupsDlg(); + +protected slots: + virtual bool onApply(); + virtual void onSelectionDone(); + +protected: + virtual void reset(); + +private: + QListWidget* myListWg; + QList myGroups; +}; + +/* + Class : SMESHGUI_CutGroupsDlg + Description : Perform cut of several groups +*/ + +class SMESHGUI_EXPORT SMESHGUI_CutGroupsDlg : public SMESHGUI_GroupOpDlg +{ + Q_OBJECT + +public: + + SMESHGUI_CutGroupsDlg( SMESHGUI* ); + virtual ~SMESHGUI_CutGroupsDlg(); + +protected slots: + virtual bool onApply(); + virtual void onSelectionDone(); + +protected: + virtual void reset(); + +private: + QPushButton* myBtn1; + QPushButton* myBtn2; + QListWidget* myListWg1; + QListWidget* myListWg2; + QList myGroups1; + QList myGroups2; +}; + +/* + Class : SMESHGUI_DimGroupDlg + Description : Dialog for creating groups of entities from existing + groups of superior dimensions +*/ + +class SMESHGUI_EXPORT SMESHGUI_DimGroupDlg : public SMESHGUI_GroupOpDlg +{ + Q_OBJECT + +public: + + SMESHGUI_DimGroupDlg( SMESHGUI* ); + virtual ~SMESHGUI_DimGroupDlg(); + + SMESH::ElementType getElementType() const; + void setElementType( const SMESH::ElementType& theElemType ); + +protected: + virtual void reset(); + +protected slots: + virtual bool onApply(); + virtual void onSelectionDone(); + +private: + QComboBox* myCombo; + QListWidget* myListWg; + QList myGroups; +}; + #endif // SMESHGUI_GROUPOPDLG_H + + diff --git a/src/SMESHGUI/SMESH_images.ts b/src/SMESHGUI/SMESH_images.ts index 4b89ca687..c8a223159 100644 --- a/src/SMESHGUI/SMESH_images.ts +++ b/src/SMESHGUI/SMESH_images.ts @@ -402,5 +402,9 @@ ICON_CLEAR_MESH mesh_clear.png + + ICON_UNDERLYING_ELEMS + mesh_extractGroup.png + diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index e681b0894..c03686d56 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -586,6 +586,10 @@ MEN_UN_GROUP Union Groups + + MEN_UNDERLYING_ELEMS + Group of underlying entities + MEN_UPDATE Update @@ -2276,6 +2280,10 @@ Consider saving your work before application crash STB_UN_GROUP Union Groups + + STB_UNDERLYING_ELEMS + Create groups of entities from existing groups of superior dimensions + STB_UPDATE Update @@ -2736,6 +2744,10 @@ Consider saving your work before application crash TOP_UN_GROUP Union Groups + + TOP_UNDERLYING_ELEMS + Create groups of entities from existing groups of superior dimensions + TOP_UPDATE Update @@ -3754,10 +3766,6 @@ Please enter correct value and try again ARGUMENTS Arguments - - CUT_OF_TWO_GROUPS - Cut of two groups - DIFF_MESHES Arguments of operation are not correctly specified @@ -3780,14 +3788,6 @@ Please specify non-empty name and try again Arguments of operation are not specified Please specify them and try again - - INTERSECTION_OF_TWO_GROUPS - Intersection of two groups - - - MAIN_OBJECT - Main object - NAME Name @@ -3813,6 +3813,62 @@ Please specify them and try again Union of two groups + + SMESHGUI_UnionGroupsDlg + + UNION_OF_GROUPS + Union of groups + + + + SMESHGUI_DimGroupDlg + + CREATE_GROUP_OF_UNDERLYING_ELEMS + Create group of underlying entities + + + ELEMENTS_TYPE + Elements type + + + NODE + Node + + + EDGE + Edge + + + FACE + Face + + + VOLUME + Volume + + + + SMESHGUI_IntersectGroupsDlg + + INTERSECTION_OF_GROUPS + Intersection of groups + + + + SMESHGUI_CutGroupsDlg + + CUT_OF_GROUPS + Cut of groups + + + MAIN_OBJECT + Main object + + + TOOL_OBJECT + Tool object + + SMESHGUI_MakeNodeAtPointDlg