1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_MeshDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_MeshDlg.h"
30 // SALOME GUI includes
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
34 #include <QtxToolButton.h>
39 #include <QGridLayout>
42 #include <QListWidget>
44 #include <QPushButton>
46 #include <QToolButton>
47 #include <QVBoxLayout>
49 #include <Standard_Integer.hxx>
55 * \brief Tab for tab widget containing controls for definition of
56 * algorithms and hypotheses
59 //================================================================================
62 * \param theParent - Parent widget for this tab
64 * Makes tab's look and feel
66 //================================================================================
67 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
70 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
71 QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
72 QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
73 QIcon aPlusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_PLUS" ) ) );
74 QIcon aMinusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_MINUS" ) ) );
77 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
78 myHypCombo[ Algo ] = new QtxToolButton( this );
81 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
82 myHypCombo[ MainHyp ] = new QtxToolButton( this );
83 myHypCombo[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
84 myCreateHypBtn[ MainHyp ] = new QToolButton( this );
85 myCreateHypBtn[ MainHyp ]->setIcon( aCreateIcon );
86 myEditHypBtn[ MainHyp ] = new QToolButton( this );
87 myEditHypBtn[ MainHyp ]->setIcon( aEditIcon );
90 QFrame* aLine = new QFrame( this );
91 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
94 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
95 myHypCombo[ AddHyp ] = new QtxToolButton( this );
96 myHypCombo[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
97 myCreateHypBtn[ AddHyp ] = new QToolButton( this );
98 myCreateHypBtn[ AddHyp ]->setIcon( aCreateIcon );
99 myEditHypBtn[ AddHyp ] = new QToolButton( this );
100 myEditHypBtn[ AddHyp ]->setIcon( aEditIcon );
101 myEditHypBtn[ MoreAddHyp ] = new QToolButton( this );
102 myEditHypBtn[ MoreAddHyp ]->setIcon( aEditIcon );
104 myAddHypList = new QListWidget( this );
105 myMoreAddHypBtn = new QToolButton( this );
106 myMoreAddHypBtn->setIcon( aPlusIcon );
107 myLessAddHypBtn = new QToolButton( this );
108 myLessAddHypBtn->setIcon( aMinusIcon );
111 QGridLayout* aLay = new QGridLayout( this );
112 aLay->setMargin( MARGIN );
113 aLay->setSpacing( SPACING );
115 aLay->addWidget( anAlgoLbl, 0, 0 );
116 aLay->addWidget( myHypCombo[ Algo ], 0, 1 );
117 aLay->addWidget( aHypLbl, 1, 0 );
118 aLay->addWidget( myHypCombo[ MainHyp ], 1, 1 );
119 aLay->addWidget( myCreateHypBtn[ MainHyp ], 1, 2 );
120 aLay->addWidget( myEditHypBtn[ MainHyp ], 1, 3 );
121 aLay->addWidget( aLine, 2, 0, 1, 4 );
122 aLay->addWidget( anAddHypLbl, 3, 0 );
123 aLay->addWidget( myHypCombo[ AddHyp ], 3, 1 );
124 aLay->addWidget( myCreateHypBtn[ AddHyp ], 3, 2 );
125 aLay->addWidget( myEditHypBtn[ AddHyp ], 3, 3 );
126 aLay->addWidget( myAddHypList, 4, 1, 2, 1 );
127 aLay->addWidget( myMoreAddHypBtn, 4, 2 );
128 aLay->addWidget( myEditHypBtn[ MoreAddHyp ], 4, 3 );
129 aLay->addWidget( myLessAddHypBtn, 5, 2 );
131 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 6, 0 );
133 // Connect signals and slots
134 for ( int i = MainHyp; i <= AddHyp; i++ )
136 connect( myCreateHypBtn[ i ], SIGNAL( clicked() ) , SLOT( onCreateHyp() ) );
137 connect( myEditHypBtn[ i ] , SIGNAL( clicked() ) , SLOT( onEditHyp() ) );
138 connect( myHypCombo[ i ] , SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
140 connect( myHypCombo[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
142 connect( myAddHypList, SIGNAL( currentRowChanged( int ) ), SLOT( onHyp( int ) ) );
143 connect( myEditHypBtn[ MoreAddHyp ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
144 connect( myMoreAddHypBtn, SIGNAL( clicked() ), SLOT( onMoreAddHyp() ));
145 connect( myLessAddHypBtn, SIGNAL( clicked() ), SLOT( onLessAddHyp() ));
147 // Initialize controls
149 setAvailableHyps( Algo, QStringList() );
150 setAvailableHyps( MainHyp, QStringList() );
151 setAvailableHyps( AddHyp, QStringList() );
154 //================================================================================
158 //================================================================================
159 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
163 //================================================================================
165 * \brief Adds an item in a control corresponding to \a type
166 * \param [in] txt - item text
167 * \param [in] type - HypType
168 * \param [in] index - index of item in a list of items
169 * \param [in] isGroup - is the item a group title
171 //================================================================================
172 void SMESHGUI_MeshTab::addItem( const QString& txt,
177 if ( type <= AddHyp )
181 myHypCombo[ type ]->addSeparator( txt.mid( 6 ) );
185 myHypCombo[ type ]->addItem( txt, QVariant( index ));
187 //myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) );
191 QListWidgetItem* item = new QListWidgetItem( txt, myAddHypList );
192 item->setData( Qt::UserRole, QVariant( index ));
196 //================================================================================
198 * \brief Returns index of hyp of a given type
200 //================================================================================
201 int SMESHGUI_MeshTab::getCurrentIndex( const int type, const bool curByType ) const
203 if ( type <= AddHyp )
205 return myHypCombo[ type ]->itemData( myHypCombo[ type ]->currentIndex() ).toInt();
209 int row = curByType ? ( type - AddHyp - 1 ) : myAddHypList->currentRow();
210 if ( QListWidgetItem* item = myAddHypList->item( row ))
211 return item->data( Qt::UserRole ).toInt();
216 //================================================================================
218 * \brief Sets available hypothesis or algorithms
219 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
220 * \param theHyps - list of available hypothesis names
222 * Sets available main or additional hypothesis for this tab
224 //================================================================================
225 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
227 myAvailableHypTypes[ theId ] = theHyps;
229 bool enable = ! theHyps.isEmpty();
230 if ( theId == Algo ) // fill list of algos
232 myHypCombo[ Algo ]->clear();
235 addItem( tr( "NONE"), Algo, 0 );
236 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
237 addItem( theHyps[i], Algo, i+1, theHyps[i].startsWith( "GROUP:" ));
238 myHypCombo[ Algo ]->setCurrentIndex( 0 );
241 else // enable buttons
243 myCreateHypBtn[ theId ]->setEnabled( enable );
244 myEditHypBtn [ theId ]->setEnabled( false );
246 myHypCombo[ theId ]->setEnabled( enable );
249 //================================================================================
251 * \brief Sets existing hypothesis
252 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
253 * \param theHyps - list of available hypothesis names
254 * \param theDefaultAvlbl - \c true means that the algorithm can work w/o hypothesis
255 * with some default parameters
257 * Sets existing main or additional hypothesis for this tab
259 //================================================================================
260 void SMESHGUI_MeshTab::setExistingHyps( const int theId,
261 const QStringList& theHyps,
262 bool theDefaultAvlbl)
266 bool enable = ! myAvailableHypTypes[ theId ].isEmpty();
267 myHypCombo[ theId ]->clear();
270 QString none = tr( theDefaultAvlbl ? "DEFAULT" : ( theId == AddHyp ) ? "NONE" : "NONE" );
271 addItem( none, theId, 0 );
272 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
273 addItem( theHyps[i], theId, i+1 );
274 myHypCombo[ theId ]->setCurrentIndex( 0 );
276 myHypCombo [ theId ]->setEnabled( enable );
277 myEditHypBtn[ theId ]->setEnabled( false );
278 if ( theId == AddHyp )
280 myAddHypList->clear();
281 myEditHypBtn[ MoreAddHyp ]->setEnabled( false );
282 myMoreAddHypBtn->setEnabled( false );
283 myLessAddHypBtn->setEnabled( false );
288 //================================================================================
290 * \brief Adds hypothesis in combo box of available ones
291 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
292 * \param theHyp - name of hypothesis to be added
294 * Adds hypothesis in combo box of available ones. This method is called by operation
295 * after creation of new hypothesis.
297 //================================================================================
298 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
300 int index = myHypCombo[ theId ]->count();
301 if ( theId == AddHyp )
302 index += myAddHypList->count();
303 addItem( theHyp, theId, index );
304 myHypCombo[ theId ]->setCurrentIndex( myHypCombo[ theId ]->count() - 1 );
305 myEditHypBtn[ theId ]->setEnabled( true );
306 myHypCombo[ theId ]->setEnabled( true );
307 if ( theId == AddHyp )
308 myMoreAddHypBtn->setEnabled( true );
311 //================================================================================
313 * \brief Sets current hypothesis
314 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
315 * \param theIndex - index of hypothesis to be set as current
317 * Sets current hypothesis
319 //================================================================================
320 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
322 if ( theId <= AddHyp )
324 if ( theIndex >= 0 && theIndex < myHypCombo[ theId ]->count() )
326 myHypCombo[ theId ]->setCurrentIndex( theIndex );
327 if ( myEditHypBtn[ theId ] )
328 myEditHypBtn[ theId ]->setEnabled( theIndex > 0 );
329 if ( theId == AddHyp )
330 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
333 else // more than one additional hyp assigned
337 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
338 for ( int i = 1, nb = myHypCombo[ AddHyp ]->count(); i < nb; ++i )
340 int curIndex = myHypCombo[ AddHyp ]->itemData( i ).toInt();
341 if ( theIndex == curIndex )
343 addItem( myHypCombo[ AddHyp ]->itemText( i ), theId, theIndex );
344 myHypCombo[ AddHyp ]->removeItem( i );
351 myAddHypList->clear();
356 //================================================================================
358 * \brief Gets current hypothesis
359 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
360 * \retval int - index of current hypothesis
362 * Gets current hypothesis
363 * Use theId > AddHyp to get more than selected addetional hyps (see nbAddHypTypes()).
365 //================================================================================
366 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
368 return getCurrentIndex( theId, /*curByType=*/true );
371 //================================================================================
373 * \brief Returns nb of selected supplementary additional hypotheses
375 * Access to their indices is via currentHyp( AddHyp + i ) where i is within the
376 * range 0 <= i < this->nbAddHypTypes()
378 //================================================================================
379 int SMESHGUI_MeshTab::nbAddHypTypes() const
381 return myAddHypList->count();
384 //================================================================================
386 * \brief Emits createHyp( const int ) signal
388 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
389 * createHyp( const int ) signal
391 //================================================================================
392 void SMESHGUI_MeshTab::onCreateHyp()
394 bool isMainHyp = ( sender() == myCreateHypBtn[ MainHyp ]);
396 QtxMenu aPopup( this );
398 QStringList aHypNames = isMainHyp ?
399 myAvailableHypTypes[ MainHyp ] : myAvailableHypTypes[ AddHyp ];
401 QList<QAction*> actions;
402 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
405 if ( aHypNames[ i ].startsWith( "GROUP:" ))
407 aPopup.addGroup( aHypNames[ i ].mid( 6 ));
411 a = aPopup.addAction( aHypNames[ i ] );
415 QAction* a = aPopup.exec( QCursor::pos() );
417 emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
420 //================================================================================
422 * \brief Emits editHyp( const int ) signal
424 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
425 * editHyp( const int ) signal
427 //================================================================================
428 void SMESHGUI_MeshTab::onEditHyp()
430 const QObject* aSender = sender();
431 int aHypType = MainHyp;
432 for ( ; aHypType <= MoreAddHyp; ++aHypType )
433 if ( aSender == myEditHypBtn[ aHypType ])
435 emit editHyp( Min( aHypType, AddHyp ),
436 getCurrentIndex( aHypType ) - 1 ); // - 1 because there is NONE on the top
439 //================================================================================
441 * \brief Updates "Edit hypothesis" button state
443 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
444 * if current hypothesis is <None>, enables otherwise.
445 * If an algorithm changed, emits selectAlgo( theIndex ) signal
447 //================================================================================
448 void SMESHGUI_MeshTab::onHyp( int theIndex )
450 QObject* aSender = sender();
452 if ( QComboBox* cb = qobject_cast< QComboBox* >( aSender ))
454 // don't allow selecting a group title
455 if ( cb->itemData( theIndex, Qt::AccessibleDescriptionRole ) == "separator" )
457 cb->setCurrentIndex( theIndex+1 );
462 if ( aSender == myHypCombo[ Algo ] )
464 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
466 else if ( aSender == myAddHypList )
468 myEditHypBtn[ MoreAddHyp ]->setEnabled( theIndex >= 0 );
469 myLessAddHypBtn ->setEnabled( theIndex >= 0 );
473 int type = ( aSender == myHypCombo[ MainHyp ] ? MainHyp : AddHyp );
474 myEditHypBtn[ type ]->setEnabled( theIndex > 0 );
476 if ( type == AddHyp )
477 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
481 //================================================================================
483 * \brief Adds a current additional hyp to myAddHypList
485 * SLOT called when myMoreAddHypBtn ("plus") clicked
487 //================================================================================
488 void SMESHGUI_MeshTab::onMoreAddHyp()
490 int hypIndex = currentHyp( AddHyp );
493 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
494 int comboIndex = myHypCombo[ AddHyp ]->currentIndex();
495 addItem( myHypCombo[ AddHyp ]->itemText( comboIndex ), MoreAddHyp, hypIndex );
497 myHypCombo[ AddHyp ]->removeItem( comboIndex );
498 myHypCombo[ AddHyp ]->setCurrentIndex( 0 );
500 myMoreAddHypBtn->setEnabled( false );
501 myEditHypBtn[ AddHyp ]->setEnabled( false );
505 //================================================================================
507 * \brief Removes a current additional hyp from myAddHypList
509 * SLOT called when myLessAddHypBtn ("minus") clicked
511 //================================================================================
512 void SMESHGUI_MeshTab::onLessAddHyp()
514 if ( QListWidgetItem * item = myAddHypList->currentItem() )
516 // move a hyp from myAddHypList to myHypCombo[ AddHyp ]
517 int hypIndex = item->data( Qt::UserRole ).toInt();
518 addItem( item->text(), AddHyp, hypIndex );
519 delete item;//myAddHypList->takeItem( myAddHypList->currentRow() );
523 //================================================================================
525 * \brief Resets all tab fields
527 * Resets all tab fields
529 //================================================================================
530 void SMESHGUI_MeshTab::reset()
532 for ( int i = Algo; i <= AddHyp; i++ )
534 myHypCombo[ i ]->setCurrentIndex( 0 );
535 if ( myEditHypBtn[ i ] )
536 myEditHypBtn[ i ]->setEnabled( false );
541 * \brief Dialog for mech creation or editing
543 * This dialog is used for mech creation or editing.
546 //================================================================================
549 * \param theToCreate - if this parameter is true then dialog is used for creation,
550 * for editing otherwise
551 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
552 * for sub-mesh otherwise
554 * Makes dialog's look and feel
556 //================================================================================
557 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
558 : SMESHGUI_Dialog( 0, false, true )
560 // Create top controls
562 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
564 createObject( tr( "NAME" ), mainFrame(), Obj );
565 setNameIndication( Obj, OneName );
566 setReadOnly( Obj, false );
568 createObject( tr( "MESH" ), mainFrame(), Mesh );
570 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
573 QLabel* anMeshTypeLbl = new QLabel( tr( "MESH_TYPE" ), this );
574 myMeshType = new QComboBox( this );
578 myTabWg = new QTabWidget( mainFrame() );
579 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
580 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
581 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
582 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
583 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
584 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
585 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
586 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
589 myHypoSetButton = new QToolButton( mainFrame() );
590 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
591 myHypoSetButton->setEnabled( false );
592 myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding,
593 myHypoSetButton->sizePolicy().verticalPolicy() );
596 QGridLayout* aLay = new QGridLayout( mainFrame() );
597 aLay->setMargin( 0 );
598 aLay->setSpacing( SPACING );
600 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
601 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
602 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
603 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
604 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
605 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
606 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
607 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
608 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
609 aLay->addWidget( anMeshTypeLbl, 3, 0 );
610 aLay->addWidget( myMeshType, 3, 2 );
611 aLay->addWidget( myTabWg, 5, 0, 1, 3 );
612 aLay->addWidget( myHypoSetButton, 6, 0, 1, 3 );
613 aLay->setRowMinimumHeight( 3, 20 );
617 // Connect signals and slots
618 connect( myMeshType, SIGNAL( activated( int ) ), SLOT( onChangedMeshType( int ) ) );
619 // Disable controls if necessary
620 setObjectShown( Mesh, false );
623 setWindowTitle( tr( "CREATE_MESH" ) );
624 objectWg( Obj, Btn )->hide();
626 setWindowTitle( tr( "CREATE_MESH" ) );
629 setWindowTitle( tr( "CREATE_SUBMESH" ) );
630 setObjectShown( Mesh, true );
635 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
636 objectWg( Mesh, Btn )->hide();
637 objectWg( Geom, Btn )->hide();
639 setTitile( theToCreate, theIsMesh );
642 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
646 //================================================================================
648 * \brief Set dialog title
650 //================================================================================
651 void SMESHGUI_MeshDlg::setTitile( const bool theToCreate, const bool theIsMesh )
655 setWindowTitle( tr( theIsMesh ? "CREATE_MESH" : "CREATE_SUBMESH" ));
659 setWindowTitle( tr( theIsMesh ? "EDIT_MESH" : "EDIT_SUBMESH") );
664 //================================================================================
666 * \brief Gets tab with given id
667 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
668 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
671 * Gets tab containing controls for definition of algorithms and AddHypotheses
673 //================================================================================
674 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
676 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
679 //================================================================================
681 * \brief Resets all dialog fields
683 //================================================================================
684 void SMESHGUI_MeshDlg::reset()
687 myTabs[ Dim0D ]->reset();
688 myTabs[ Dim1D ]->reset();
689 myTabs[ Dim2D ]->reset();
690 myTabs[ Dim3D ]->reset();
693 //================================================================================
695 * \brief Sets current tab
697 //================================================================================
698 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
700 myTabWg->setCurrentIndex( Dim3D - theId );
703 //================================================================================
705 * \brief Enable/disable tabs
706 * \param int - maximum possible dimension
708 //================================================================================
709 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
711 const int DIM = maxDim;
712 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
713 bool enable = ( dim <= DIM );
715 myTabs[ dim ]->reset();
722 // deselect desabled tab
723 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
724 setCurrentTab( DIM );
727 //================================================================================
729 * \brief Sets list of available Sets of Hypotheses
731 //================================================================================
732 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
734 QMenu* aHypoSetPopup = myHypoSetButton->menu();
735 if ( !aHypoSetPopup ) {
736 aHypoSetPopup = new QMenu( myHypoSetButton );
737 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
738 myHypoSetButton->setMenu( aHypoSetPopup );
739 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
741 aHypoSetPopup->clear();
742 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
743 aHypoSetPopup->addAction( theSets[ i ] );
745 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
748 //================================================================================
750 * \brief Emits hypoSet signal
752 * SLOT is called when a hypotheses set is selected. Emits hypoSet
753 * signal to notify operation about this event
755 //================================================================================
756 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
758 emit hypoSet( a->text() );
761 //================================================================================
763 * \brief Enable showing of the popup when Geometry selection btn is clicked
764 * \param enable - true to enable
766 //================================================================================
768 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
770 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
772 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
775 if ( ! myGeomPopup ) {
776 myGeomPopup = new QMenu();
777 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
778 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
779 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
780 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
784 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
794 //================================================================================
797 * \param int - tab ID
799 //================================================================================
800 void SMESHGUI_MeshDlg::disableTab(const int theTabId)
802 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
805 //================================================================================
808 * \param int - tab ID
810 //================================================================================
811 void SMESHGUI_MeshDlg::enableTab(const int theTabId)
813 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
814 if ( theTabId == Dim3D ) {
815 QMenu* aHypoSetPopup = myHypoSetButton->menu();
816 myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
820 //================================================================================
822 * \brief Check if tab enabled
823 * \param int - tab ID
825 //================================================================================
826 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const
828 return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
831 //================================================================================
833 * \brief Return index of a current tab
836 //================================================================================
837 int SMESHGUI_MeshDlg::currentTab() const
839 return Dim3D - myTabWg->currentIndex();
842 //================================================================================
844 * \brief SLOT called when a Geom selection button is clicked
846 //================================================================================
847 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
849 if ( myGeomPopup && isBtnOn )
850 myGeomPopup->exec( QCursor::pos() );
853 //================================================================================
855 * \brief SLOT called when a item of Geom selection popup is chosen
857 //================================================================================
858 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
860 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
863 //================================================================================
865 * \brief Return ID of an active selection button
867 //================================================================================
868 int SMESHGUI_MeshDlg::getActiveObject()
870 for (int i = 0; i < 3; ++i )
871 if ( isObjectShown( i ) &&
872 (( QToolButton* )objectWg( i, Btn ))->isChecked())
876 //================================================================================
878 * \brief Sets available types of mesh
879 * \param theTypeMesh - list of available types of mesh
881 //================================================================================
882 void SMESHGUI_MeshDlg::setAvailableMeshType( const QStringList& theTypeMesh )
885 myMeshType->addItems(theTypeMesh);
887 //================================================================================
889 * \brief Emits selectMeshType( const int, const int ) signal
891 * SLOT is called when a combo box "mesh type" is selected.
893 //================================================================================
894 void SMESHGUI_MeshDlg::onChangedMeshType( const int isIndex )
896 emit selectMeshType( Dim3D - myTabWg->currentIndex(), isIndex );
898 //================================================================================
900 * \brief Get current index types of mesh
902 //================================================================================
903 int SMESHGUI_MeshDlg::currentMeshType( )
905 return myMeshType->currentIndex( );
907 //================================================================================
909 * \brief Set current index types of mesh
911 //================================================================================
912 void SMESHGUI_MeshDlg::setCurrentMeshType( const int theIndex )
914 if ( theIndex < myMeshType->count() )
915 myMeshType->setCurrentIndex( theIndex );
917 myMeshType->setCurrentIndex( 0 );