X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_MeshDlg.cxx;h=787a3446958e1c9436f05c32d6a9c8bb3c6f07af;hp=a381acde05148beca0aabdb3259b4ac85151d585;hb=6472eab132825fec572beda8276947593f85ffa1;hpb=0c5188fd2cf587b6c74c6adce920158f7edd4419 diff --git a/src/SMESHGUI/SMESHGUI_MeshDlg.cxx b/src/SMESHGUI/SMESHGUI_MeshDlg.cxx index a381acde0..787a34469 100644 --- a/src/SMESHGUI/SMESHGUI_MeshDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshDlg.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -30,8 +30,11 @@ // SALOME GUI includes #include #include +#include +#include // Qt includes +#include #include #include #include @@ -73,11 +76,11 @@ SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent ) // Algorifm QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this ); - myHypCombo[ Algo ] = new QComboBox( this ); + myHypCombo[ Algo ] = new QtxToolButton( this ); // Hypothesis QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this ); - myHypCombo[ MainHyp ] = new QComboBox( this ); + myHypCombo[ MainHyp ] = new QtxToolButton( this ); myHypCombo[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); myCreateHypBtn[ MainHyp ] = new QToolButton( this ); myCreateHypBtn[ MainHyp ]->setIcon( aCreateIcon ); @@ -90,7 +93,7 @@ SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent ) // Add. hypothesis QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this ); - myHypCombo[ AddHyp ] = new QComboBox( this ); + myHypCombo[ AddHyp ] = new QtxToolButton( this ); myHypCombo[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); myCreateHypBtn[ AddHyp ] = new QToolButton( this ); myCreateHypBtn[ AddHyp ]->setIcon( aCreateIcon ); @@ -125,6 +128,7 @@ SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent ) aLay->addWidget( myMoreAddHypBtn, 4, 2 ); aLay->addWidget( myEditHypBtn[ MoreAddHyp ], 4, 3 ); aLay->addWidget( myLessAddHypBtn, 5, 2 ); + aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 6, 0 ); // Connect signals and slots @@ -163,15 +167,25 @@ SMESHGUI_MeshTab::~SMESHGUI_MeshTab() * \param [in] txt - item text * \param [in] type - HypType * \param [in] index - index of item in a list of items + * \param [in] isGroup - is the item a group title */ //================================================================================ - -void SMESHGUI_MeshTab::addItem( const QString& txt, const int type, const int index ) +void SMESHGUI_MeshTab::addItem( const QString& txt, + const int type, + const int index, + const bool isGroup ) { if ( type <= AddHyp ) { - myHypCombo[ type ]->addItem( txt, QVariant( index )); - myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) ); + if ( isGroup ) + { + myHypCombo[ type ]->addSeparator( txt.mid( 6 ) ); + } + else + { + myHypCombo[ type ]->addItem( txt, QVariant( index )); + } + //myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) ); } else { @@ -185,7 +199,6 @@ void SMESHGUI_MeshTab::addItem( const QString& txt, const int type, const int in * \brief Returns index of hyp of a given type */ //================================================================================ - int SMESHGUI_MeshTab::getCurrentIndex( const int type, const bool curByType ) const { if ( type <= AddHyp ) @@ -222,7 +235,7 @@ void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& the { addItem( tr( "NONE"), Algo, 0 ); for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i ) - addItem( theHyps[i], Algo, i+1 ); + addItem( theHyps[i], Algo, i+1, theHyps[i].startsWith( "GROUP:" )); myHypCombo[ Algo ]->setCurrentIndex( 0 ); } } @@ -296,24 +309,6 @@ void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp ) myMoreAddHypBtn->setEnabled( true ); } -//================================================================================ -/*! - * \brief Renames hypothesis - * \param theId - identifier of hypothesis (main or additional, see HypType enumeration) - * \param theIndex - index of hypothesis to be renamed - * \param theNewName - new name of hypothesis to be renamed - * - * Renames hypothesis - */ -//================================================================================ -// void SMESHGUI_MeshTab::renameHyp( const int theId, -// const int theIndex, -// const QString& theNewName ) -// { -// if ( theIndex > 0 && theIndex < myHypCombo[ theId ]->count() ) -// myHypCombo[ theId ]->setItemText( theIndex, theNewName ); -// } - //================================================================================ /*! * \brief Sets current hypothesis @@ -338,17 +333,24 @@ void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex ) } else // more than one additional hyp assigned { - // move a hyp from myHypCombo[ AddHyp ] to myAddHypList - for ( int i = 1, nb = myHypCombo[ AddHyp ]->count(); i < nb; ++i ) + if ( theIndex > 0 ) { - int curIndex = myHypCombo[ AddHyp ]->itemData( i ).toInt(); - if ( theIndex == curIndex ) + // move a hyp from myHypCombo[ AddHyp ] to myAddHypList + for ( int i = 1, nb = myHypCombo[ AddHyp ]->count(); i < nb; ++i ) { - addItem( myHypCombo[ AddHyp ]->itemText( i ), theId, theIndex ); - myHypCombo[ AddHyp ]->removeItem( i ); - break; + int curIndex = myHypCombo[ AddHyp ]->itemData( i ).toInt(); + if ( theIndex == curIndex ) + { + addItem( myHypCombo[ AddHyp ]->itemText( i ), theId, theIndex ); + myHypCombo[ AddHyp ]->removeItem( i ); + break; + } } } + else + { + myAddHypList->clear(); + } } } @@ -375,7 +377,6 @@ int SMESHGUI_MeshTab::currentHyp( const int theId ) const * range 0 <= i < this->nbAddHypTypes() */ //================================================================================ - int SMESHGUI_MeshTab::nbAddHypTypes() const { return myAddHypList->count(); @@ -393,15 +394,25 @@ void SMESHGUI_MeshTab::onCreateHyp() { bool isMainHyp = ( sender() == myCreateHypBtn[ MainHyp ]); - QMenu aPopup( this ); + QtxMenu aPopup( this ); QStringList aHypNames = isMainHyp ? myAvailableHypTypes[ MainHyp ] : myAvailableHypTypes[ AddHyp ]; QList actions; for ( int i = 0, n = aHypNames.count(); i < n; i++ ) - actions.append( aPopup.addAction( aHypNames[ i ] ) ); - + { + QAction* a = 0; + if ( aHypNames[ i ].startsWith( "GROUP:" )) + { + aPopup.addGroup( aHypNames[ i ].mid( 6 )); + } + else + { + a = aPopup.addAction( aHypNames[ i ] ); + } + actions.append( a ); + } QAction* a = aPopup.exec( QCursor::pos() ); if ( a ) emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) ); @@ -437,7 +448,18 @@ void SMESHGUI_MeshTab::onEditHyp() //================================================================================ void SMESHGUI_MeshTab::onHyp( int theIndex ) { - const QObject* aSender = sender(); + QObject* aSender = sender(); + + if ( QComboBox* cb = qobject_cast< QComboBox* >( aSender )) + { + // don't allow selecting a group title + if ( cb->itemData( theIndex, Qt::AccessibleDescriptionRole ) == "separator" ) + { + cb->setCurrentIndex( theIndex+1 ); + return; + } + } + if ( aSender == myHypCombo[ Algo ] ) { emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top @@ -464,7 +486,6 @@ void SMESHGUI_MeshTab::onHyp( int theIndex ) * SLOT called when myMoreAddHypBtn ("plus") clicked */ //================================================================================ - void SMESHGUI_MeshTab::onMoreAddHyp() { int hypIndex = currentHyp( AddHyp ); @@ -489,7 +510,6 @@ void SMESHGUI_MeshTab::onMoreAddHyp() * SLOT called when myLessAddHypBtn ("minus") clicked */ //================================================================================ - void SMESHGUI_MeshTab::onLessAddHyp() { if ( QListWidgetItem * item = myAddHypList->currentItem() ) @@ -553,9 +573,12 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh // mesh type QLabel* anMeshTypeLbl = new QLabel( tr( "MESH_TYPE" ), this ); myMeshType = new QComboBox( this ); - + // groups + myCreateGroupsCheck = new QCheckBox( tr( "CREATE_ALL_GROUPS" ), this ); + myCreateGroupsCheck->setChecked( true ); + // Create tab widget - + myTabWg = new QTabWidget( mainFrame() ); myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg ); myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg ); @@ -589,9 +612,10 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh aLay->addWidget( objectWg( Geom, Control ), 2, 2 ); aLay->addWidget( anMeshTypeLbl, 3, 0 ); aLay->addWidget( myMeshType, 3, 2 ); - aLay->addWidget( myTabWg, 5, 0, 1, 3 ); - aLay->addWidget( myHypoSetButton, 6, 0, 1, 3 ); - aLay->setRowMinimumHeight( 3, 20 ); + aLay->addWidget( myCreateGroupsCheck, 4, 0, 1, 3 ); + aLay->addWidget( myTabWg, 6, 0, 1, 3 ); + aLay->addWidget( myHypoSetButton, 7, 0, 1, 3 ); + aLay->setRowMinimumHeight( 4, 20 ); myMeshType->clear(); @@ -617,12 +641,31 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh objectWg( Mesh, Btn )->hide(); objectWg( Geom, Btn )->hide(); } + setTitile( theToCreate, theIsMesh ); } SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg() { } +//================================================================================ +/*! + * \brief Set dialog title + */ +//================================================================================ +void SMESHGUI_MeshDlg::setTitile( const bool theToCreate, const bool theIsMesh ) +{ + if ( theToCreate ) + { + setWindowTitle( tr( theIsMesh ? "CREATE_MESH" : "CREATE_SUBMESH" )); + } + else + { + setWindowTitle( tr( theIsMesh ? "EDIT_MESH" : "EDIT_SUBMESH") ); + } + myCreateGroupsCheck-> setVisible( theToCreate && theIsMesh ); +} + //================================================================================ /*! * \brief Gets tab with given id @@ -654,7 +697,7 @@ void SMESHGUI_MeshDlg::reset() //================================================================================ /*! - * \brief Sets curent tab + * \brief Sets current tab */ //================================================================================ void SMESHGUI_MeshDlg::setCurrentTab( const int theId ) @@ -665,10 +708,9 @@ void SMESHGUI_MeshDlg::setCurrentTab( const int theId ) //================================================================================ /*! * \brief Enable/disable tabs - * \param int - maximum possible dimention + * \param int - maximum possible dimension */ //================================================================================ - void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim ) { const int DIM = maxDim; @@ -692,7 +734,6 @@ void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim ) * \brief Sets list of available Sets of Hypotheses */ //================================================================================ - void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets ) { QMenu* aHypoSetPopup = myHypoSetButton->menu(); @@ -703,8 +744,11 @@ void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets ) myHypoSetButton->setPopupMode( QToolButton::InstantPopup ); } aHypoSetPopup->clear(); - for ( int i = 0, n = theSets.count(); i < n; i++ ) { - aHypoSetPopup->addAction( theSets[ i ] ); + for ( int i = 0, n = theSets.count(); i < n; i++ ) + { + QAction* action = new QAction( tr( theSets[ i ].toUtf8().data() )); + action->setData( theSets[ i ] ); + aHypoSetPopup->addAction( action ); } myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() ); } @@ -717,10 +761,9 @@ void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets ) * signal to notify operation about this event */ //================================================================================ - void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a ) { - emit hypoSet( a->text() ); + emit hypoSet( a->data().toString() ); } //================================================================================ @@ -762,9 +805,9 @@ void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable ) * \param int - tab ID */ //================================================================================ -void SMESHGUI_MeshDlg::disableTab(const int theTabId) { +void SMESHGUI_MeshDlg::disableTab(const int theTabId) +{ myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false ); - if ( theTabId == Dim3D ) myHypoSetButton->setEnabled( false ); } //================================================================================ @@ -773,7 +816,8 @@ void SMESHGUI_MeshDlg::disableTab(const int theTabId) { * \param int - tab ID */ //================================================================================ -void SMESHGUI_MeshDlg::enableTab(const int theTabId) { +void SMESHGUI_MeshDlg::enableTab(const int theTabId) +{ myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true ); if ( theTabId == Dim3D ) { QMenu* aHypoSetPopup = myHypoSetButton->menu(); @@ -787,21 +831,48 @@ void SMESHGUI_MeshDlg::enableTab(const int theTabId) { * \param int - tab ID */ //================================================================================ -bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const { +bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const +{ return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) ); } +//================================================================================ +/*! + * \brief Return index of a current tab + * \return tab ID + */ +//================================================================================ +int SMESHGUI_MeshDlg::currentTab() const +{ + return Dim3D - myTabWg->currentIndex(); +} + +//================================================================================ +/*! + * \brief SLOT called when a Geom selection button is clicked + */ +//================================================================================ void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn) { if ( myGeomPopup && isBtnOn ) myGeomPopup->exec( QCursor::pos() ); } +//================================================================================ +/*! + * \brief SLOT called when a item of Geom selection popup is chosen + */ +//================================================================================ void SMESHGUI_MeshDlg::onGeomPopup( QAction* a ) { emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX ); } +//================================================================================ +/*! + * \brief Return ID of an active selection button + */ +//================================================================================ int SMESHGUI_MeshDlg::getActiveObject() { for (int i = 0; i < 3; ++i ) @@ -848,5 +919,19 @@ int SMESHGUI_MeshDlg::currentMeshType( ) //================================================================================ void SMESHGUI_MeshDlg::setCurrentMeshType( const int theIndex ) { - myMeshType->setCurrentIndex( theIndex ); + if ( theIndex < myMeshType->count() ) + myMeshType->setCurrentIndex( theIndex ); + else + myMeshType->setCurrentIndex( 0 ); +} + +//================================================================================ +/*! + * \brief Return state of "Create all Groups on Geometry" check-box + */ +//================================================================================ + +bool SMESHGUI_MeshDlg::toCreateAllGroups() +{ + return myCreateGroupsCheck->isChecked(); }