1 // Copyright (C) 2007-2020 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>
40 #include <QGridLayout>
43 #include <QListWidget>
45 #include <QPushButton>
47 #include <QToolButton>
48 #include <QVBoxLayout>
50 #include <Standard_Integer.hxx>
56 * \brief Tab for tab widget containing controls for definition of
57 * algorithms and hypotheses
60 //================================================================================
63 * \param theParent - Parent widget for this tab
65 * Makes tab's look and feel
67 //================================================================================
68 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
71 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
72 QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
73 QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
74 QIcon aPlusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_PLUS" ) ) );
75 QIcon aMinusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_MINUS" ) ) );
78 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
79 myHypCombo[ Algo ] = new QtxToolButton( this );
82 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
83 myHypCombo[ MainHyp ] = new QtxToolButton( this );
84 myHypCombo[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
85 myCreateHypBtn[ MainHyp ] = new QToolButton( this );
86 myCreateHypBtn[ MainHyp ]->setIcon( aCreateIcon );
87 myEditHypBtn[ MainHyp ] = new QToolButton( this );
88 myEditHypBtn[ MainHyp ]->setIcon( aEditIcon );
91 QFrame* aLine = new QFrame( this );
92 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
95 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
96 myHypCombo[ AddHyp ] = new QtxToolButton( this );
97 myHypCombo[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
98 myCreateHypBtn[ AddHyp ] = new QToolButton( this );
99 myCreateHypBtn[ AddHyp ]->setIcon( aCreateIcon );
100 myEditHypBtn[ AddHyp ] = new QToolButton( this );
101 myEditHypBtn[ AddHyp ]->setIcon( aEditIcon );
102 myEditHypBtn[ MoreAddHyp ] = new QToolButton( this );
103 myEditHypBtn[ MoreAddHyp ]->setIcon( aEditIcon );
105 myAddHypList = new QListWidget( this );
106 myMoreAddHypBtn = new QToolButton( this );
107 myMoreAddHypBtn->setIcon( aPlusIcon );
108 myLessAddHypBtn = new QToolButton( this );
109 myLessAddHypBtn->setIcon( aMinusIcon );
112 QGridLayout* aLay = new QGridLayout( this );
113 aLay->setMargin( MARGIN );
114 aLay->setSpacing( SPACING );
116 aLay->addWidget( anAlgoLbl, 0, 0 );
117 aLay->addWidget( myHypCombo[ Algo ], 0, 1 );
118 aLay->addWidget( aHypLbl, 1, 0 );
119 aLay->addWidget( myHypCombo[ MainHyp ], 1, 1 );
120 aLay->addWidget( myCreateHypBtn[ MainHyp ], 1, 2 );
121 aLay->addWidget( myEditHypBtn[ MainHyp ], 1, 3 );
122 aLay->addWidget( aLine, 2, 0, 1, 4 );
123 aLay->addWidget( anAddHypLbl, 3, 0 );
124 aLay->addWidget( myHypCombo[ AddHyp ], 3, 1 );
125 aLay->addWidget( myCreateHypBtn[ AddHyp ], 3, 2 );
126 aLay->addWidget( myEditHypBtn[ AddHyp ], 3, 3 );
127 aLay->addWidget( myAddHypList, 4, 1, 2, 1 );
128 aLay->addWidget( myMoreAddHypBtn, 4, 2 );
129 aLay->addWidget( myEditHypBtn[ MoreAddHyp ], 4, 3 );
130 aLay->addWidget( myLessAddHypBtn, 5, 2 );
132 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 6, 0 );
134 // Connect signals and slots
135 for ( int i = MainHyp; i <= AddHyp; i++ )
137 connect( myCreateHypBtn[ i ], SIGNAL( clicked() ) , SLOT( onCreateHyp() ) );
138 connect( myEditHypBtn[ i ] , SIGNAL( clicked() ) , SLOT( onEditHyp() ) );
139 connect( myHypCombo[ i ] , SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
141 connect( myHypCombo[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
143 connect( myAddHypList, SIGNAL( currentRowChanged( int ) ), SLOT( onHyp( int ) ) );
144 connect( myEditHypBtn[ MoreAddHyp ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
145 connect( myMoreAddHypBtn, SIGNAL( clicked() ), SLOT( onMoreAddHyp() ));
146 connect( myLessAddHypBtn, SIGNAL( clicked() ), SLOT( onLessAddHyp() ));
148 // Initialize controls
150 setAvailableHyps( Algo, QStringList() );
151 setAvailableHyps( MainHyp, QStringList() );
152 setAvailableHyps( AddHyp, QStringList() );
155 //================================================================================
159 //================================================================================
160 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
164 //================================================================================
166 * \brief Adds an item in a control corresponding to \a type
167 * \param [in] txt - item text
168 * \param [in] type - HypType
169 * \param [in] index - index of item in a list of items
170 * \param [in] isGroup - is the item a group title
172 //================================================================================
173 void SMESHGUI_MeshTab::addItem( const QString& txt,
178 if ( type <= AddHyp )
182 myHypCombo[ type ]->addSeparator( txt.mid( 6 ) );
186 myHypCombo[ type ]->addItem( txt, QVariant( index ));
188 //myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) );
192 QListWidgetItem* item = new QListWidgetItem( txt, myAddHypList );
193 item->setData( Qt::UserRole, QVariant( index ));
197 //================================================================================
199 * \brief Returns index of hyp of a given type
201 //================================================================================
202 int SMESHGUI_MeshTab::getCurrentIndex( const int type, const bool curByType ) const
204 if ( type <= AddHyp )
206 return myHypCombo[ type ]->itemData( myHypCombo[ type ]->currentIndex() ).toInt();
210 int row = curByType ? ( type - AddHyp - 1 ) : myAddHypList->currentRow();
211 if ( QListWidgetItem* item = myAddHypList->item( row ))
212 return item->data( Qt::UserRole ).toInt();
217 //================================================================================
219 * \brief Sets available hypothesis or algorithms
220 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
221 * \param theHyps - list of available hypothesis names
223 * Sets available main or additional hypothesis for this tab
225 //================================================================================
226 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
228 myAvailableHypTypes[ theId ] = theHyps;
230 bool enable = ! theHyps.isEmpty();
231 if ( theId == Algo ) // fill list of algos
233 myHypCombo[ Algo ]->clear();
236 addItem( tr( "NONE"), Algo, 0 );
237 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
238 addItem( theHyps[i], Algo, i+1, theHyps[i].startsWith( "GROUP:" ));
239 myHypCombo[ Algo ]->setCurrentIndex( 0 );
242 else // enable buttons
244 myCreateHypBtn[ theId ]->setEnabled( enable );
245 myEditHypBtn [ theId ]->setEnabled( false );
247 myHypCombo[ theId ]->setEnabled( enable );
250 //================================================================================
252 * \brief Sets existing hypothesis
253 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
254 * \param theHyps - list of available hypothesis names
255 * \param theDefaultAvlbl - \c true means that the algorithm can work w/o hypothesis
256 * with some default parameters
258 * Sets existing main or additional hypothesis for this tab
260 //================================================================================
261 void SMESHGUI_MeshTab::setExistingHyps( const int theId,
262 const QStringList& theHyps,
263 bool theDefaultAvlbl)
267 bool enable = ! myAvailableHypTypes[ theId ].isEmpty();
268 myHypCombo[ theId ]->clear();
271 QString none = tr( theDefaultAvlbl ? "DEFAULT" : ( theId == AddHyp ) ? "NONE" : "NONE" );
272 addItem( none, theId, 0 );
273 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
274 addItem( theHyps[i], theId, i+1 );
275 myHypCombo[ theId ]->setCurrentIndex( 0 );
277 myHypCombo [ theId ]->setEnabled( enable );
278 myEditHypBtn[ theId ]->setEnabled( false );
279 if ( theId == AddHyp )
281 myAddHypList->clear();
282 myEditHypBtn[ MoreAddHyp ]->setEnabled( false );
283 myMoreAddHypBtn->setEnabled( false );
284 myLessAddHypBtn->setEnabled( false );
289 //================================================================================
291 * \brief Adds hypothesis in combo box of available ones
292 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
293 * \param theHyp - name of hypothesis to be added
295 * Adds hypothesis in combo box of available ones. This method is called by operation
296 * after creation of new hypothesis.
298 //================================================================================
299 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
301 int index = myHypCombo[ theId ]->count();
302 if ( theId == AddHyp )
303 index += myAddHypList->count();
304 addItem( theHyp, theId, index );
305 myHypCombo[ theId ]->setCurrentIndex( myHypCombo[ theId ]->count() - 1 );
306 myEditHypBtn[ theId ]->setEnabled( true );
307 myHypCombo[ theId ]->setEnabled( true );
308 if ( theId == AddHyp )
309 myMoreAddHypBtn->setEnabled( true );
312 //================================================================================
314 * \brief Sets current hypothesis
315 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
316 * \param theIndex - index of hypothesis to be set as current
318 * Sets current hypothesis
320 //================================================================================
321 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
323 if ( theId <= AddHyp )
325 if ( theIndex >= 0 && theIndex < myHypCombo[ theId ]->count() )
327 myHypCombo[ theId ]->setCurrentIndex( theIndex );
328 if ( myEditHypBtn[ theId ] )
329 myEditHypBtn[ theId ]->setEnabled( theIndex > 0 );
330 if ( theId == AddHyp )
331 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
334 else // more than one additional hyp assigned
338 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
339 for ( int i = 1, nb = myHypCombo[ AddHyp ]->count(); i < nb; ++i )
341 int curIndex = myHypCombo[ AddHyp ]->itemData( i ).toInt();
342 if ( theIndex == curIndex )
344 addItem( myHypCombo[ AddHyp ]->itemText( i ), theId, theIndex );
345 myHypCombo[ AddHyp ]->removeItem( i );
352 myAddHypList->clear();
357 //================================================================================
359 * \brief Gets current hypothesis
360 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
361 * \retval int - index of current hypothesis
363 * Gets current hypothesis
364 * Use theId > AddHyp to get more than selected addetional hyps (see nbAddHypTypes()).
366 //================================================================================
367 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
369 return getCurrentIndex( theId, /*curByType=*/true );
372 //================================================================================
374 * \brief Returns nb of selected supplementary additional hypotheses
376 * Access to their indices is via currentHyp( AddHyp + i ) where i is within the
377 * range 0 <= i < this->nbAddHypTypes()
379 //================================================================================
380 int SMESHGUI_MeshTab::nbAddHypTypes() const
382 return myAddHypList->count();
385 //================================================================================
387 * \brief Emits createHyp( const int ) signal
389 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
390 * createHyp( const int ) signal
392 //================================================================================
393 void SMESHGUI_MeshTab::onCreateHyp()
395 bool isMainHyp = ( sender() == myCreateHypBtn[ MainHyp ]);
397 QtxMenu aPopup( this );
399 QStringList aHypNames = isMainHyp ?
400 myAvailableHypTypes[ MainHyp ] : myAvailableHypTypes[ AddHyp ];
402 QList<QAction*> actions;
403 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
406 if ( aHypNames[ i ].startsWith( "GROUP:" ))
408 aPopup.addGroup( aHypNames[ i ].mid( 6 ));
412 a = aPopup.addAction( aHypNames[ i ] );
416 QAction* a = aPopup.exec( QCursor::pos() );
418 emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
421 //================================================================================
423 * \brief Emits editHyp( const int ) signal
425 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
426 * editHyp( const int ) signal
428 //================================================================================
429 void SMESHGUI_MeshTab::onEditHyp()
431 const QObject* aSender = sender();
432 int aHypType = MainHyp;
433 for ( ; aHypType <= MoreAddHyp; ++aHypType )
434 if ( aSender == myEditHypBtn[ aHypType ])
436 emit editHyp( Min( aHypType, AddHyp ),
437 getCurrentIndex( aHypType ) - 1 ); // - 1 because there is NONE on the top
440 //================================================================================
442 * \brief Updates "Edit hypothesis" button state
444 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
445 * if current hypothesis is <None>, enables otherwise.
446 * If an algorithm changed, emits selectAlgo( theIndex ) signal
448 //================================================================================
449 void SMESHGUI_MeshTab::onHyp( int theIndex )
451 QObject* aSender = sender();
453 if ( QComboBox* cb = qobject_cast< QComboBox* >( aSender ))
455 // don't allow selecting a group title
456 if ( cb->itemData( theIndex, Qt::AccessibleDescriptionRole ) == "separator" )
458 cb->setCurrentIndex( theIndex+1 );
463 if ( aSender == myHypCombo[ Algo ] )
465 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
467 else if ( aSender == myAddHypList )
469 myEditHypBtn[ MoreAddHyp ]->setEnabled( theIndex >= 0 );
470 myLessAddHypBtn ->setEnabled( theIndex >= 0 );
474 int type = ( aSender == myHypCombo[ MainHyp ] ? MainHyp : AddHyp );
475 myEditHypBtn[ type ]->setEnabled( theIndex > 0 );
477 if ( type == AddHyp )
478 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
482 //================================================================================
484 * \brief Adds a current additional hyp to myAddHypList
486 * SLOT called when myMoreAddHypBtn ("plus") clicked
488 //================================================================================
489 void SMESHGUI_MeshTab::onMoreAddHyp()
491 int hypIndex = currentHyp( AddHyp );
494 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
495 int comboIndex = myHypCombo[ AddHyp ]->currentIndex();
496 addItem( myHypCombo[ AddHyp ]->itemText( comboIndex ), MoreAddHyp, hypIndex );
498 myHypCombo[ AddHyp ]->removeItem( comboIndex );
499 myHypCombo[ AddHyp ]->setCurrentIndex( 0 );
501 myMoreAddHypBtn->setEnabled( false );
502 myEditHypBtn[ AddHyp ]->setEnabled( false );
506 //================================================================================
508 * \brief Removes a current additional hyp from myAddHypList
510 * SLOT called when myLessAddHypBtn ("minus") clicked
512 //================================================================================
513 void SMESHGUI_MeshTab::onLessAddHyp()
515 if ( QListWidgetItem * item = myAddHypList->currentItem() )
517 // move a hyp from myAddHypList to myHypCombo[ AddHyp ]
518 int hypIndex = item->data( Qt::UserRole ).toInt();
519 addItem( item->text(), AddHyp, hypIndex );
520 delete item;//myAddHypList->takeItem( myAddHypList->currentRow() );
524 //================================================================================
526 * \brief Resets all tab fields
528 * Resets all tab fields
530 //================================================================================
531 void SMESHGUI_MeshTab::reset()
533 for ( int i = Algo; i <= AddHyp; i++ )
535 myHypCombo[ i ]->setCurrentIndex( 0 );
536 if ( myEditHypBtn[ i ] )
537 myEditHypBtn[ i ]->setEnabled( false );
542 * \brief Dialog for mech creation or editing
544 * This dialog is used for mech creation or editing.
547 //================================================================================
550 * \param theToCreate - if this parameter is true then dialog is used for creation,
551 * for editing otherwise
552 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
553 * for sub-mesh otherwise
555 * Makes dialog's look and feel
557 //================================================================================
558 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
559 : SMESHGUI_Dialog( 0, false, true )
561 // Create top controls
563 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
565 createObject( tr( "NAME" ), mainFrame(), Obj );
566 setNameIndication( Obj, OneName );
567 setReadOnly( Obj, false );
569 createObject( tr( "MESH" ), mainFrame(), Mesh );
571 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
574 QLabel* anMeshTypeLbl = new QLabel( tr( "MESH_TYPE" ), this );
575 myMeshType = new QComboBox( this );
577 myCreateGroupsCheck = new QCheckBox( tr( "CREATE_ALL_GROUPS" ), this );
578 myCreateGroupsCheck->setChecked( true );
582 myTabWg = new QTabWidget( mainFrame() );
583 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
584 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
585 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
586 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
587 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
588 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
589 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
590 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
593 myHypoSetButton = new QToolButton( mainFrame() );
594 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
595 myHypoSetButton->setEnabled( false );
596 myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding,
597 myHypoSetButton->sizePolicy().verticalPolicy() );
600 QGridLayout* aLay = new QGridLayout( mainFrame() );
601 aLay->setMargin( 0 );
602 aLay->setSpacing( SPACING );
604 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
605 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
606 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
607 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
608 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
609 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
610 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
611 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
612 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
613 aLay->addWidget( anMeshTypeLbl, 3, 0 );
614 aLay->addWidget( myMeshType, 3, 2 );
615 aLay->addWidget( myCreateGroupsCheck, 4, 0, 1, 3 );
616 aLay->addWidget( myTabWg, 6, 0, 1, 3 );
617 aLay->addWidget( myHypoSetButton, 7, 0, 1, 3 );
618 aLay->setRowMinimumHeight( 4, 20 );
622 // Connect signals and slots
623 connect( myMeshType, SIGNAL( activated( int ) ), SLOT( onChangedMeshType( int ) ) );
624 // Disable controls if necessary
625 setObjectShown( Mesh, false );
628 setWindowTitle( tr( "CREATE_MESH" ) );
629 objectWg( Obj, Btn )->hide();
631 setWindowTitle( tr( "CREATE_MESH" ) );
634 setWindowTitle( tr( "CREATE_SUBMESH" ) );
635 setObjectShown( Mesh, true );
640 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
641 objectWg( Mesh, Btn )->hide();
642 objectWg( Geom, Btn )->hide();
644 setTitile( theToCreate, theIsMesh );
647 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
651 //================================================================================
653 * \brief Set dialog title
655 //================================================================================
656 void SMESHGUI_MeshDlg::setTitile( const bool theToCreate, const bool theIsMesh )
660 setWindowTitle( tr( theIsMesh ? "CREATE_MESH" : "CREATE_SUBMESH" ));
664 setWindowTitle( tr( theIsMesh ? "EDIT_MESH" : "EDIT_SUBMESH") );
666 myCreateGroupsCheck-> setVisible( theToCreate && theIsMesh );
669 //================================================================================
671 * \brief Gets tab with given id
672 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
673 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
676 * Gets tab containing controls for definition of algorithms and AddHypotheses
678 //================================================================================
679 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
681 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
684 //================================================================================
686 * \brief Resets all dialog fields
688 //================================================================================
689 void SMESHGUI_MeshDlg::reset()
692 myTabs[ Dim0D ]->reset();
693 myTabs[ Dim1D ]->reset();
694 myTabs[ Dim2D ]->reset();
695 myTabs[ Dim3D ]->reset();
698 //================================================================================
700 * \brief Sets current tab
702 //================================================================================
703 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
705 myTabWg->setCurrentIndex( Dim3D - theId );
708 //================================================================================
710 * \brief Enable/disable tabs
711 * \param int - maximum possible dimension
713 //================================================================================
714 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
716 const int DIM = maxDim;
717 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
718 bool enable = ( dim <= DIM );
720 myTabs[ dim ]->reset();
727 // deselect desabled tab
728 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
729 setCurrentTab( DIM );
732 //================================================================================
734 * \brief Sets list of available Sets of Hypotheses
736 //================================================================================
737 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
739 QMenu* aHypoSetPopup = myHypoSetButton->menu();
740 if ( !aHypoSetPopup ) {
741 aHypoSetPopup = new QMenu( myHypoSetButton );
742 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
743 myHypoSetButton->setMenu( aHypoSetPopup );
744 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
746 aHypoSetPopup->clear();
747 for ( int i = 0, n = theSets.count(); i < n; i++ )
749 QAction* action = new QAction( tr( theSets[ i ].toUtf8().data() ));
750 action->setData( theSets[ i ] );
751 aHypoSetPopup->addAction( action );
753 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
756 //================================================================================
758 * \brief Emits hypoSet signal
760 * SLOT is called when a hypotheses set is selected. Emits hypoSet
761 * signal to notify operation about this event
763 //================================================================================
764 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
766 emit hypoSet( a->data().toString() );
769 //================================================================================
771 * \brief Enable showing of the popup when Geometry selection btn is clicked
772 * \param enable - true to enable
774 //================================================================================
776 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
778 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
780 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
783 if ( ! myGeomPopup ) {
784 myGeomPopup = new QMenu();
785 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
786 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
787 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
788 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
792 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
802 //================================================================================
805 * \param int - tab ID
807 //================================================================================
808 void SMESHGUI_MeshDlg::disableTab(const int theTabId)
810 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
813 //================================================================================
816 * \param int - tab ID
818 //================================================================================
819 void SMESHGUI_MeshDlg::enableTab(const int theTabId)
821 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
822 if ( theTabId == Dim3D ) {
823 QMenu* aHypoSetPopup = myHypoSetButton->menu();
824 myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
828 //================================================================================
830 * \brief Check if tab enabled
831 * \param int - tab ID
833 //================================================================================
834 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const
836 return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
839 //================================================================================
841 * \brief Return index of a current tab
844 //================================================================================
845 int SMESHGUI_MeshDlg::currentTab() const
847 return Dim3D - myTabWg->currentIndex();
850 //================================================================================
852 * \brief SLOT called when a Geom selection button is clicked
854 //================================================================================
855 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
857 if ( myGeomPopup && isBtnOn )
858 myGeomPopup->exec( QCursor::pos() );
861 //================================================================================
863 * \brief SLOT called when a item of Geom selection popup is chosen
865 //================================================================================
866 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
868 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
871 //================================================================================
873 * \brief Return ID of an active selection button
875 //================================================================================
876 int SMESHGUI_MeshDlg::getActiveObject()
878 for (int i = 0; i < 3; ++i )
879 if ( isObjectShown( i ) &&
880 (( QToolButton* )objectWg( i, Btn ))->isChecked())
884 //================================================================================
886 * \brief Sets available types of mesh
887 * \param theTypeMesh - list of available types of mesh
889 //================================================================================
890 void SMESHGUI_MeshDlg::setAvailableMeshType( const QStringList& theTypeMesh )
893 myMeshType->addItems(theTypeMesh);
895 //================================================================================
897 * \brief Emits selectMeshType( const int, const int ) signal
899 * SLOT is called when a combo box "mesh type" is selected.
901 //================================================================================
902 void SMESHGUI_MeshDlg::onChangedMeshType( const int isIndex )
904 emit selectMeshType( Dim3D - myTabWg->currentIndex(), isIndex );
906 //================================================================================
908 * \brief Get current index types of mesh
910 //================================================================================
911 int SMESHGUI_MeshDlg::currentMeshType( )
913 return myMeshType->currentIndex( );
915 //================================================================================
917 * \brief Set current index types of mesh
919 //================================================================================
920 void SMESHGUI_MeshDlg::setCurrentMeshType( const int theIndex )
922 if ( theIndex < myMeshType->count() )
923 myMeshType->setCurrentIndex( theIndex );
925 myMeshType->setCurrentIndex( 0 );
928 //================================================================================
930 * \brief Return state of "Create all Groups on Geometry" check-box
932 //================================================================================
934 bool SMESHGUI_MeshDlg::toCreateAllGroups()
936 return myCreateGroupsCheck->isChecked();