1 // Copyright (C) 2007-2014 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>
37 #include <QGridLayout>
40 #include <QListWidget>
42 #include <QPushButton>
44 #include <QToolButton>
45 #include <QVBoxLayout>
47 #include <Standard_Integer.hxx>
53 * \brief Tab for tab widget containing controls for definition of
54 * algorithms and hypotheses
57 //================================================================================
60 * \param theParent - Parent widget for this tab
62 * Makes tab's look and feel
64 //================================================================================
65 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
68 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
69 QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
70 QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
71 QIcon aPlusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_PLUS" ) ) );
72 QIcon aMinusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_MINUS" ) ) );
75 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
76 myHypCombo[ Algo ] = new QComboBox( this );
79 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
80 myHypCombo[ MainHyp ] = new QComboBox( this );
81 myHypCombo[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
82 myCreateHypBtn[ MainHyp ] = new QToolButton( this );
83 myCreateHypBtn[ MainHyp ]->setIcon( aCreateIcon );
84 myEditHypBtn[ MainHyp ] = new QToolButton( this );
85 myEditHypBtn[ MainHyp ]->setIcon( aEditIcon );
88 QFrame* aLine = new QFrame( this );
89 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
92 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
93 myHypCombo[ AddHyp ] = new QComboBox( this );
94 myHypCombo[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
95 myCreateHypBtn[ AddHyp ] = new QToolButton( this );
96 myCreateHypBtn[ AddHyp ]->setIcon( aCreateIcon );
97 myEditHypBtn[ AddHyp ] = new QToolButton( this );
98 myEditHypBtn[ AddHyp ]->setIcon( aEditIcon );
99 myEditHypBtn[ MoreAddHyp ] = new QToolButton( this );
100 myEditHypBtn[ MoreAddHyp ]->setIcon( aEditIcon );
102 myAddHypList = new QListWidget( this );
103 myMoreAddHypBtn = new QToolButton( this );
104 myMoreAddHypBtn->setIcon( aPlusIcon );
105 myLessAddHypBtn = new QToolButton( this );
106 myLessAddHypBtn->setIcon( aMinusIcon );
109 QGridLayout* aLay = new QGridLayout( this );
110 aLay->setMargin( MARGIN );
111 aLay->setSpacing( SPACING );
113 aLay->addWidget( anAlgoLbl, 0, 0 );
114 aLay->addWidget( myHypCombo[ Algo ], 0, 1 );
115 aLay->addWidget( aHypLbl, 1, 0 );
116 aLay->addWidget( myHypCombo[ MainHyp ], 1, 1 );
117 aLay->addWidget( myCreateHypBtn[ MainHyp ], 1, 2 );
118 aLay->addWidget( myEditHypBtn[ MainHyp ], 1, 3 );
119 aLay->addWidget( aLine, 2, 0, 1, 4 );
120 aLay->addWidget( anAddHypLbl, 3, 0 );
121 aLay->addWidget( myHypCombo[ AddHyp ], 3, 1 );
122 aLay->addWidget( myCreateHypBtn[ AddHyp ], 3, 2 );
123 aLay->addWidget( myEditHypBtn[ AddHyp ], 3, 3 );
124 aLay->addWidget( myAddHypList, 4, 1, 2, 1 );
125 aLay->addWidget( myMoreAddHypBtn, 4, 2 );
126 aLay->addWidget( myEditHypBtn[ MoreAddHyp ], 4, 3 );
127 aLay->addWidget( myLessAddHypBtn, 5, 2 );
128 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 6, 0 );
130 // Connect signals and slots
131 for ( int i = MainHyp; i <= AddHyp; i++ )
133 connect( myCreateHypBtn[ i ], SIGNAL( clicked() ) , SLOT( onCreateHyp() ) );
134 connect( myEditHypBtn[ i ] , SIGNAL( clicked() ) , SLOT( onEditHyp() ) );
135 connect( myHypCombo[ i ] , SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
137 connect( myHypCombo[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
139 connect( myAddHypList, SIGNAL( currentRowChanged( int ) ), SLOT( onHyp( int ) ) );
140 connect( myEditHypBtn[ MoreAddHyp ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
141 connect( myMoreAddHypBtn, SIGNAL( clicked() ), SLOT( onMoreAddHyp() ));
142 connect( myLessAddHypBtn, SIGNAL( clicked() ), SLOT( onLessAddHyp() ));
144 // Initialize controls
146 setAvailableHyps( Algo, QStringList() );
147 setAvailableHyps( MainHyp, QStringList() );
148 setAvailableHyps( AddHyp, QStringList() );
151 //================================================================================
155 //================================================================================
156 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
160 //================================================================================
162 * \brief Adds an item in a control corresponding to \a type
163 * \param [in] txt - item text
164 * \param [in] type - HypType
165 * \param [in] index - index of item in a list of items
167 //================================================================================
169 void SMESHGUI_MeshTab::addItem( const QString& txt, const int type, const int index )
171 if ( type <= AddHyp )
173 myHypCombo[ type ]->addItem( txt, QVariant( index ));
177 QListWidgetItem* item = new QListWidgetItem( txt, myAddHypList );
178 item->setData( Qt::UserRole, QVariant( index ));
182 //================================================================================
184 * \brief Returns index of hyp of a given type
186 //================================================================================
188 int SMESHGUI_MeshTab::getCurrentIndex( const int type, const bool curByType ) const
190 if ( type <= AddHyp )
192 return myHypCombo[ type ]->itemData( myHypCombo[ type ]->currentIndex() ).toInt();
196 int row = curByType ? ( type - AddHyp - 1 ) : myAddHypList->currentRow();
197 if ( QListWidgetItem* item = myAddHypList->item( row ))
198 return item->data( Qt::UserRole ).toInt();
203 //================================================================================
205 * \brief Sets available hypothesis or algorithms
206 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
207 * \param theHyps - list of available hypothesis names
209 * Sets available main or additional hypothesis for this tab
211 //================================================================================
212 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
214 myAvailableHypTypes[ theId ] = theHyps;
216 bool enable = ! theHyps.isEmpty();
217 if ( theId == Algo ) // fill list of algos
219 myHypCombo[ Algo ]->clear();
222 addItem( tr( "NONE"), Algo, 0 );
223 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
224 addItem( theHyps[i], Algo, i+1 );
225 myHypCombo[ Algo ]->setCurrentIndex( 0 );
228 else // enable buttons
230 myCreateHypBtn[ theId ]->setEnabled( enable );
231 myEditHypBtn [ theId ]->setEnabled( false );
233 myHypCombo[ theId ]->setEnabled( enable );
236 //================================================================================
238 * \brief Sets existing hypothesis
239 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
240 * \param theHyps - list of available hypothesis names
241 * \param theDefaultAvlbl - \c true means that the algorithm can work w/o hypothesis
242 * with some default parameters
244 * Sets existing main or additional hypothesis for this tab
246 //================================================================================
247 void SMESHGUI_MeshTab::setExistingHyps( const int theId,
248 const QStringList& theHyps,
249 bool theDefaultAvlbl)
253 bool enable = ! myAvailableHypTypes[ theId ].isEmpty();
254 myHypCombo[ theId ]->clear();
257 QString none = tr( theDefaultAvlbl ? "DEFAULT" : ( theId == AddHyp ) ? "NONE" : "NONE" );
258 addItem( none, theId, 0 );
259 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
260 addItem( theHyps[i], theId, i+1 );
261 myHypCombo[ theId ]->setCurrentIndex( 0 );
263 myHypCombo [ theId ]->setEnabled( enable );
264 myEditHypBtn[ theId ]->setEnabled( false );
265 if ( theId == AddHyp )
267 myAddHypList->clear();
268 myEditHypBtn[ MoreAddHyp ]->setEnabled( false );
269 myMoreAddHypBtn->setEnabled( false );
270 myLessAddHypBtn->setEnabled( false );
275 //================================================================================
277 * \brief Adds hypothesis in combo box of available ones
278 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
279 * \param theHyp - name of hypothesis to be added
281 * Adds hypothesis in combo box of available ones. This method is called by operation
282 * after creation of new hypothesis.
284 //================================================================================
285 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
287 int index = myHypCombo[ theId ]->count();
288 if ( theId == AddHyp )
289 index += myAddHypList->count();
290 addItem( theHyp, theId, index );
291 myHypCombo[ theId ]->setCurrentIndex( myHypCombo[ theId ]->count() - 1 );
292 myEditHypBtn[ theId ]->setEnabled( true );
293 myHypCombo[ theId ]->setEnabled( true );
294 if ( theId == AddHyp )
295 myMoreAddHypBtn->setEnabled( true );
298 //================================================================================
300 * \brief Renames hypothesis
301 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
302 * \param theIndex - index of hypothesis to be renamed
303 * \param theNewName - new name of hypothesis to be renamed
307 //================================================================================
308 // void SMESHGUI_MeshTab::renameHyp( const int theId,
309 // const int theIndex,
310 // const QString& theNewName )
312 // if ( theIndex > 0 && theIndex < myHypCombo[ theId ]->count() )
313 // myHypCombo[ theId ]->setItemText( theIndex, theNewName );
316 //================================================================================
318 * \brief Sets current hypothesis
319 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
320 * \param theIndex - index of hypothesis to be set as current
322 * Sets current hypothesis
324 //================================================================================
325 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
327 if ( theId <= AddHyp )
329 if ( theIndex >= 0 && theIndex < myHypCombo[ theId ]->count() )
331 myHypCombo[ theId ]->setCurrentIndex( theIndex );
332 if ( myEditHypBtn[ theId ] )
333 myEditHypBtn[ theId ]->setEnabled( theIndex > 0 );
334 if ( theId == AddHyp )
335 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
338 else // more than one additional hyp assigned
340 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
341 for ( int i = 1, nb = myHypCombo[ AddHyp ]->count(); i < nb; ++i )
343 int curIndex = myHypCombo[ AddHyp ]->itemData( i ).toInt();
344 if ( theIndex == curIndex )
346 addItem( myHypCombo[ AddHyp ]->itemText( i ), theId, theIndex );
347 myHypCombo[ AddHyp ]->removeItem( i );
354 //================================================================================
356 * \brief Gets current hypothesis
357 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
358 * \retval int - index of current hypothesis
360 * Gets current hypothesis
361 * Use theId > AddHyp to get more than selected addetional hyps (see nbAddHypTypes()).
363 //================================================================================
364 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
366 return getCurrentIndex( theId, /*curByType=*/true );
369 //================================================================================
371 * \brief Returns nb of selected supplementary additional hypotheses
373 * Access to their indices is via currentHyp( AddHyp + i ) where i is within the
374 * range 0 <= i < this->nbAddHypTypes()
376 //================================================================================
378 int SMESHGUI_MeshTab::nbAddHypTypes() const
380 return myAddHypList->count();
383 //================================================================================
385 * \brief Emits createHyp( const int ) signal
387 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
388 * createHyp( const int ) signal
390 //================================================================================
391 void SMESHGUI_MeshTab::onCreateHyp()
393 bool isMainHyp = ( sender() == myCreateHypBtn[ MainHyp ]);
395 QMenu aPopup( this );
397 QStringList aHypNames = isMainHyp ?
398 myAvailableHypTypes[ MainHyp ] : myAvailableHypTypes[ AddHyp ];
400 QList<QAction*> actions;
401 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
402 actions.append( aPopup.addAction( aHypNames[ i ] ) );
404 QAction* a = aPopup.exec( QCursor::pos() );
406 emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
409 //================================================================================
411 * \brief Emits editHyp( const int ) signal
413 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
414 * editHyp( const int ) signal
416 //================================================================================
417 void SMESHGUI_MeshTab::onEditHyp()
419 const QObject* aSender = sender();
420 int aHypType = MainHyp;
421 for ( ; aHypType <= MoreAddHyp; ++aHypType )
422 if ( aSender == myEditHypBtn[ aHypType ])
424 emit editHyp( Min( aHypType, AddHyp ),
425 getCurrentIndex( aHypType ) - 1 ); // - 1 because there is NONE on the top
428 //================================================================================
430 * \brief Updates "Edit hypothesis" button state
432 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
433 * if current hypothesis is <None>, enables otherwise.
434 * If an algorithm changed, emits selectAlgo( theIndex ) signal
436 //================================================================================
437 void SMESHGUI_MeshTab::onHyp( int theIndex )
439 const QObject* aSender = sender();
440 if ( aSender == myHypCombo[ Algo ] )
442 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
444 else if ( aSender == myAddHypList )
446 myEditHypBtn[ MoreAddHyp ]->setEnabled( theIndex >= 0 );
447 myLessAddHypBtn ->setEnabled( theIndex >= 0 );
451 int type = ( aSender == myHypCombo[ MainHyp ] ? MainHyp : AddHyp );
452 myEditHypBtn[ type ]->setEnabled( theIndex > 0 );
454 if ( type == AddHyp )
455 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
459 //================================================================================
461 * \brief Adds a current additional hyp to myAddHypList
463 * SLOT called when myMoreAddHypBtn ("plus") clicked
465 //================================================================================
467 void SMESHGUI_MeshTab::onMoreAddHyp()
469 int hypIndex = currentHyp( AddHyp );
472 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
473 int comboIndex = myHypCombo[ AddHyp ]->currentIndex();
474 addItem( myHypCombo[ AddHyp ]->itemText( comboIndex ), MoreAddHyp, hypIndex );
476 myHypCombo[ AddHyp ]->removeItem( comboIndex );
477 myHypCombo[ AddHyp ]->setCurrentIndex( 0 );
479 myMoreAddHypBtn->setEnabled( false );
480 myEditHypBtn[ AddHyp ]->setEnabled( false );
484 //================================================================================
486 * \brief Removes a current additional hyp from myAddHypList
488 * SLOT called when myLessAddHypBtn ("minus") clicked
490 //================================================================================
492 void SMESHGUI_MeshTab::onLessAddHyp()
494 if ( QListWidgetItem * item = myAddHypList->currentItem() )
496 // move a hyp from myAddHypList to myHypCombo[ AddHyp ]
497 int hypIndex = item->data( Qt::UserRole ).toInt();
498 addItem( item->text(), AddHyp, hypIndex );
499 delete item;//myAddHypList->takeItem( myAddHypList->currentRow() );
503 //================================================================================
505 * \brief Resets all tab fields
507 * Resets all tab fields
509 //================================================================================
510 void SMESHGUI_MeshTab::reset()
512 for ( int i = Algo; i <= AddHyp; i++ )
514 myHypCombo[ i ]->setCurrentIndex( 0 );
515 if ( myEditHypBtn[ i ] )
516 myEditHypBtn[ i ]->setEnabled( false );
521 * \brief Dialog for mech creation or editing
523 * This dialog is used for mech creation or editing.
526 //================================================================================
529 * \param theToCreate - if this parameter is true then dialog is used for creation,
530 * for editing otherwise
531 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
532 * for sub-mesh otherwise
534 * Makes dialog's look and feel
536 //================================================================================
537 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
538 : SMESHGUI_Dialog( 0, false, true )
540 // Create top controls
542 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
544 createObject( tr( "NAME" ), mainFrame(), Obj );
545 setNameIndication( Obj, OneName );
546 setReadOnly( Obj, false );
548 createObject( tr( "MESH" ), mainFrame(), Mesh );
550 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
553 QLabel* anMeshTypeLbl = new QLabel( tr( "MESH_TYPE" ), this );
554 myMeshType = new QComboBox( this );
558 myTabWg = new QTabWidget( mainFrame() );
559 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
560 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
561 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
562 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
563 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
564 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
565 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
566 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
569 myHypoSetButton = new QToolButton( mainFrame() );
570 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
571 myHypoSetButton->setEnabled( false );
572 myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding,
573 myHypoSetButton->sizePolicy().verticalPolicy() );
576 QGridLayout* aLay = new QGridLayout( mainFrame() );
577 aLay->setMargin( 0 );
578 aLay->setSpacing( SPACING );
580 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
581 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
582 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
583 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
584 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
585 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
586 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
587 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
588 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
589 aLay->addWidget( anMeshTypeLbl, 3, 0 );
590 aLay->addWidget( myMeshType, 3, 2 );
591 aLay->addWidget( myTabWg, 5, 0, 1, 3 );
592 aLay->addWidget( myHypoSetButton, 6, 0, 1, 3 );
593 aLay->setRowMinimumHeight( 3, 20 );
597 // Connect signals and slots
598 connect( myMeshType, SIGNAL( activated( int ) ), SLOT( onChangedMeshType( int ) ) );
599 // Disable controls if necessary
600 setObjectShown( Mesh, false );
603 setWindowTitle( tr( "CREATE_MESH" ) );
604 objectWg( Obj, Btn )->hide();
606 setWindowTitle( tr( "CREATE_MESH" ) );
609 setWindowTitle( tr( "CREATE_SUBMESH" ) );
610 setObjectShown( Mesh, true );
615 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
616 objectWg( Mesh, Btn )->hide();
617 objectWg( Geom, Btn )->hide();
621 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
625 //================================================================================
627 * \brief Gets tab with given id
628 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
629 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
632 * Gets tab containing controls for definition of algorithms and AddHypotheses
634 //================================================================================
635 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
637 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
640 //================================================================================
642 * \brief Resets all dialog fields
644 //================================================================================
645 void SMESHGUI_MeshDlg::reset()
648 myTabs[ Dim0D ]->reset();
649 myTabs[ Dim1D ]->reset();
650 myTabs[ Dim2D ]->reset();
651 myTabs[ Dim3D ]->reset();
654 //================================================================================
656 * \brief Sets curent tab
658 //================================================================================
659 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
661 myTabWg->setCurrentIndex( Dim3D - theId );
664 //================================================================================
666 * \brief Enable/disable tabs
667 * \param int - maximum possible dimention
669 //================================================================================
671 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
673 const int DIM = maxDim;
674 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
675 bool enable = ( dim <= DIM );
677 myTabs[ dim ]->reset();
684 // deselect desabled tab
685 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
686 setCurrentTab( DIM );
689 //================================================================================
691 * \brief Sets list of available Sets of Hypotheses
693 //================================================================================
695 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
697 QMenu* aHypoSetPopup = myHypoSetButton->menu();
698 if ( !aHypoSetPopup ) {
699 aHypoSetPopup = new QMenu( myHypoSetButton );
700 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
701 myHypoSetButton->setMenu( aHypoSetPopup );
702 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
704 aHypoSetPopup->clear();
705 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
706 aHypoSetPopup->addAction( theSets[ i ] );
708 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
711 //================================================================================
713 * \brief Emits hypoSet signal
715 * SLOT is called when a hypotheses set is selected. Emits hypoSet
716 * signal to notify operation about this event
718 //================================================================================
720 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
722 emit hypoSet( a->text() );
725 //================================================================================
727 * \brief Enable showing of the popup when Geometry selection btn is clicked
728 * \param enable - true to enable
730 //================================================================================
732 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
734 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
736 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
739 if ( ! myGeomPopup ) {
740 myGeomPopup = new QMenu();
741 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
742 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
743 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
744 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
748 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
758 //================================================================================
761 * \param int - tab ID
763 //================================================================================
764 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
765 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
766 if ( theTabId == Dim3D ) myHypoSetButton->setEnabled( false );
769 //================================================================================
772 * \param int - tab ID
774 //================================================================================
775 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
776 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
777 if ( theTabId == Dim3D ) {
778 QMenu* aHypoSetPopup = myHypoSetButton->menu();
779 myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
783 //================================================================================
785 * \brief Check if tab enabled
786 * \param int - tab ID
788 //================================================================================
789 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const {
790 return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
793 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
795 if ( myGeomPopup && isBtnOn )
796 myGeomPopup->exec( QCursor::pos() );
799 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
801 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
804 int SMESHGUI_MeshDlg::getActiveObject()
806 for (int i = 0; i < 3; ++i )
807 if ( isObjectShown( i ) &&
808 (( QToolButton* )objectWg( i, Btn ))->isChecked())
812 //================================================================================
814 * \brief Sets available types of mesh
815 * \param theTypeMesh - list of available types of mesh
817 //================================================================================
818 void SMESHGUI_MeshDlg::setAvailableMeshType( const QStringList& theTypeMesh )
821 myMeshType->addItems(theTypeMesh);
823 //================================================================================
825 * \brief Emits selectMeshType( const int, const int ) signal
827 * SLOT is called when a combo box "mesh type" is selected.
829 //================================================================================
830 void SMESHGUI_MeshDlg::onChangedMeshType( const int isIndex )
832 emit selectMeshType( Dim3D - myTabWg->currentIndex(), isIndex );
834 //================================================================================
836 * \brief Get current index types of mesh
838 //================================================================================
839 int SMESHGUI_MeshDlg::currentMeshType( )
841 return myMeshType->currentIndex( );
843 //================================================================================
845 * \brief Set current index types of mesh
847 //================================================================================
848 void SMESHGUI_MeshDlg::setCurrentMeshType( const int theIndex )
850 myMeshType->setCurrentIndex( theIndex );