1 // Copyright (C) 2007-2016 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>
38 #include <QGridLayout>
41 #include <QListWidget>
43 #include <QPushButton>
45 #include <QToolButton>
46 #include <QVBoxLayout>
48 #include <Standard_Integer.hxx>
54 * \brief Tab for tab widget containing controls for definition of
55 * algorithms and hypotheses
58 //================================================================================
61 * \param theParent - Parent widget for this tab
63 * Makes tab's look and feel
65 //================================================================================
66 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
69 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
70 QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
71 QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
72 QIcon aPlusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_PLUS" ) ) );
73 QIcon aMinusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_MINUS" ) ) );
76 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
77 myHypCombo[ Algo ] = new QComboBox( this );
80 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
81 myHypCombo[ MainHyp ] = new QComboBox( this );
82 myHypCombo[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
83 myCreateHypBtn[ MainHyp ] = new QToolButton( this );
84 myCreateHypBtn[ MainHyp ]->setIcon( aCreateIcon );
85 myEditHypBtn[ MainHyp ] = new QToolButton( this );
86 myEditHypBtn[ MainHyp ]->setIcon( aEditIcon );
89 QFrame* aLine = new QFrame( this );
90 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
93 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
94 myHypCombo[ AddHyp ] = new QComboBox( this );
95 myHypCombo[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
96 myCreateHypBtn[ AddHyp ] = new QToolButton( this );
97 myCreateHypBtn[ AddHyp ]->setIcon( aCreateIcon );
98 myEditHypBtn[ AddHyp ] = new QToolButton( this );
99 myEditHypBtn[ AddHyp ]->setIcon( aEditIcon );
100 myEditHypBtn[ MoreAddHyp ] = new QToolButton( this );
101 myEditHypBtn[ MoreAddHyp ]->setIcon( aEditIcon );
103 myAddHypList = new QListWidget( this );
104 myMoreAddHypBtn = new QToolButton( this );
105 myMoreAddHypBtn->setIcon( aPlusIcon );
106 myLessAddHypBtn = new QToolButton( this );
107 myLessAddHypBtn->setIcon( aMinusIcon );
110 QGridLayout* aLay = new QGridLayout( this );
111 aLay->setMargin( MARGIN );
112 aLay->setSpacing( SPACING );
114 aLay->addWidget( anAlgoLbl, 0, 0 );
115 aLay->addWidget( myHypCombo[ Algo ], 0, 1 );
116 aLay->addWidget( aHypLbl, 1, 0 );
117 aLay->addWidget( myHypCombo[ MainHyp ], 1, 1 );
118 aLay->addWidget( myCreateHypBtn[ MainHyp ], 1, 2 );
119 aLay->addWidget( myEditHypBtn[ MainHyp ], 1, 3 );
120 aLay->addWidget( aLine, 2, 0, 1, 4 );
121 aLay->addWidget( anAddHypLbl, 3, 0 );
122 aLay->addWidget( myHypCombo[ AddHyp ], 3, 1 );
123 aLay->addWidget( myCreateHypBtn[ AddHyp ], 3, 2 );
124 aLay->addWidget( myEditHypBtn[ AddHyp ], 3, 3 );
125 aLay->addWidget( myAddHypList, 4, 1, 2, 1 );
126 aLay->addWidget( myMoreAddHypBtn, 4, 2 );
127 aLay->addWidget( myEditHypBtn[ MoreAddHyp ], 4, 3 );
128 aLay->addWidget( myLessAddHypBtn, 5, 2 );
129 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 6, 0 );
131 // Connect signals and slots
132 for ( int i = MainHyp; i <= AddHyp; i++ )
134 connect( myCreateHypBtn[ i ], SIGNAL( clicked() ) , SLOT( onCreateHyp() ) );
135 connect( myEditHypBtn[ i ] , SIGNAL( clicked() ) , SLOT( onEditHyp() ) );
136 connect( myHypCombo[ i ] , SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
138 connect( myHypCombo[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
140 connect( myAddHypList, SIGNAL( currentRowChanged( int ) ), SLOT( onHyp( int ) ) );
141 connect( myEditHypBtn[ MoreAddHyp ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
142 connect( myMoreAddHypBtn, SIGNAL( clicked() ), SLOT( onMoreAddHyp() ));
143 connect( myLessAddHypBtn, SIGNAL( clicked() ), SLOT( onLessAddHyp() ));
145 // Initialize controls
147 setAvailableHyps( Algo, QStringList() );
148 setAvailableHyps( MainHyp, QStringList() );
149 setAvailableHyps( AddHyp, QStringList() );
152 //================================================================================
156 //================================================================================
157 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
161 //================================================================================
163 * \brief Adds an item in a control corresponding to \a type
164 * \param [in] txt - item text
165 * \param [in] type - HypType
166 * \param [in] index - index of item in a list of items
167 * \param [in] isGroup - is the item a group title
169 //================================================================================
171 void SMESHGUI_MeshTab::addItem( const QString& txt,
176 const char* prefix = " ";
177 if ( type <= AddHyp )
181 int idx = myHypCombo[ type ]->count();
182 myHypCombo[ type ]->addItem( txt.mid( 6 ), QVariant( index ));
183 myHypCombo[ type ]->setItemData( idx, "separator", Qt::AccessibleDescriptionRole );
187 myHypCombo[ type ]->addItem( prefix + txt, QVariant( index ));
189 //myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) );
193 QListWidgetItem* item = new QListWidgetItem( prefix + txt, myAddHypList );
194 item->setData( Qt::UserRole, QVariant( index ));
198 //================================================================================
200 * \brief Returns index of hyp of a given type
202 //================================================================================
204 int SMESHGUI_MeshTab::getCurrentIndex( const int type, const bool curByType ) const
206 if ( type <= AddHyp )
208 return myHypCombo[ type ]->itemData( myHypCombo[ type ]->currentIndex() ).toInt();
212 int row = curByType ? ( type - AddHyp - 1 ) : myAddHypList->currentRow();
213 if ( QListWidgetItem* item = myAddHypList->item( row ))
214 return item->data( Qt::UserRole ).toInt();
219 //================================================================================
221 * \brief Sets available hypothesis or algorithms
222 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
223 * \param theHyps - list of available hypothesis names
225 * Sets available main or additional hypothesis for this tab
227 //================================================================================
228 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
230 myAvailableHypTypes[ theId ] = theHyps;
232 bool enable = ! theHyps.isEmpty();
233 if ( theId == Algo ) // fill list of algos
235 myHypCombo[ Algo ]->clear();
238 addItem( tr( "NONE"), Algo, 0 );
239 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
240 addItem( theHyps[i], Algo, i+1, theHyps[i].startsWith( "GROUP:" ));
241 myHypCombo[ Algo ]->setCurrentIndex( 0 );
244 else // enable buttons
246 myCreateHypBtn[ theId ]->setEnabled( enable );
247 myEditHypBtn [ theId ]->setEnabled( false );
249 myHypCombo[ theId ]->setEnabled( enable );
252 //================================================================================
254 * \brief Sets existing hypothesis
255 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
256 * \param theHyps - list of available hypothesis names
257 * \param theDefaultAvlbl - \c true means that the algorithm can work w/o hypothesis
258 * with some default parameters
260 * Sets existing main or additional hypothesis for this tab
262 //================================================================================
263 void SMESHGUI_MeshTab::setExistingHyps( const int theId,
264 const QStringList& theHyps,
265 bool theDefaultAvlbl)
269 bool enable = ! myAvailableHypTypes[ theId ].isEmpty();
270 myHypCombo[ theId ]->clear();
273 QString none = tr( theDefaultAvlbl ? "DEFAULT" : ( theId == AddHyp ) ? "NONE" : "NONE" );
274 addItem( none, theId, 0 );
275 for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
276 addItem( theHyps[i], theId, i+1 );
277 myHypCombo[ theId ]->setCurrentIndex( 0 );
279 myHypCombo [ theId ]->setEnabled( enable );
280 myEditHypBtn[ theId ]->setEnabled( false );
281 if ( theId == AddHyp )
283 myAddHypList->clear();
284 myEditHypBtn[ MoreAddHyp ]->setEnabled( false );
285 myMoreAddHypBtn->setEnabled( false );
286 myLessAddHypBtn->setEnabled( false );
291 //================================================================================
293 * \brief Adds hypothesis in combo box of available ones
294 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
295 * \param theHyp - name of hypothesis to be added
297 * Adds hypothesis in combo box of available ones. This method is called by operation
298 * after creation of new hypothesis.
300 //================================================================================
301 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
303 int index = myHypCombo[ theId ]->count();
304 if ( theId == AddHyp )
305 index += myAddHypList->count();
306 addItem( theHyp, theId, index );
307 myHypCombo[ theId ]->setCurrentIndex( myHypCombo[ theId ]->count() - 1 );
308 myEditHypBtn[ theId ]->setEnabled( true );
309 myHypCombo[ theId ]->setEnabled( true );
310 if ( theId == AddHyp )
311 myMoreAddHypBtn->setEnabled( true );
314 //================================================================================
316 * \brief Renames hypothesis
317 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
318 * \param theIndex - index of hypothesis to be renamed
319 * \param theNewName - new name of hypothesis to be renamed
323 //================================================================================
324 // void SMESHGUI_MeshTab::renameHyp( const int theId,
325 // const int theIndex,
326 // const QString& theNewName )
328 // if ( theIndex > 0 && theIndex < myHypCombo[ theId ]->count() )
329 // myHypCombo[ theId ]->setItemText( theIndex, theNewName );
332 //================================================================================
334 * \brief Sets current hypothesis
335 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
336 * \param theIndex - index of hypothesis to be set as current
338 * Sets current hypothesis
340 //================================================================================
341 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
343 if ( theId <= AddHyp )
345 if ( theIndex >= 0 && theIndex < myHypCombo[ theId ]->count() )
347 myHypCombo[ theId ]->setCurrentIndex( theIndex );
348 if ( myEditHypBtn[ theId ] )
349 myEditHypBtn[ theId ]->setEnabled( theIndex > 0 );
350 if ( theId == AddHyp )
351 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
354 else // more than one additional hyp assigned
358 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
359 for ( int i = 1, nb = myHypCombo[ AddHyp ]->count(); i < nb; ++i )
361 int curIndex = myHypCombo[ AddHyp ]->itemData( i ).toInt();
362 if ( theIndex == curIndex )
364 addItem( myHypCombo[ AddHyp ]->itemText( i ), theId, theIndex );
365 myHypCombo[ AddHyp ]->removeItem( i );
372 myAddHypList->clear();
377 //================================================================================
379 * \brief Gets current hypothesis
380 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
381 * \retval int - index of current hypothesis
383 * Gets current hypothesis
384 * Use theId > AddHyp to get more than selected addetional hyps (see nbAddHypTypes()).
386 //================================================================================
387 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
389 return getCurrentIndex( theId, /*curByType=*/true );
392 //================================================================================
394 * \brief Returns nb of selected supplementary additional hypotheses
396 * Access to their indices is via currentHyp( AddHyp + i ) where i is within the
397 * range 0 <= i < this->nbAddHypTypes()
399 //================================================================================
401 int SMESHGUI_MeshTab::nbAddHypTypes() const
403 return myAddHypList->count();
406 //================================================================================
408 * \brief Emits createHyp( const int ) signal
410 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
411 * createHyp( const int ) signal
413 //================================================================================
414 void SMESHGUI_MeshTab::onCreateHyp()
416 bool isMainHyp = ( sender() == myCreateHypBtn[ MainHyp ]);
418 QtxMenu aPopup( this );
420 QStringList aHypNames = isMainHyp ?
421 myAvailableHypTypes[ MainHyp ] : myAvailableHypTypes[ AddHyp ];
423 QList<QAction*> actions;
424 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
427 if ( aHypNames[ i ].startsWith( "GROUP:" ))
429 aPopup.appendGroupTitle( aHypNames[ i ].mid( 6 ));
433 a = aPopup.addAction( aHypNames[ i ] );
437 QAction* a = aPopup.exec( QCursor::pos() );
439 emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
442 //================================================================================
444 * \brief Emits editHyp( const int ) signal
446 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
447 * editHyp( const int ) signal
449 //================================================================================
450 void SMESHGUI_MeshTab::onEditHyp()
452 const QObject* aSender = sender();
453 int aHypType = MainHyp;
454 for ( ; aHypType <= MoreAddHyp; ++aHypType )
455 if ( aSender == myEditHypBtn[ aHypType ])
457 emit editHyp( Min( aHypType, AddHyp ),
458 getCurrentIndex( aHypType ) - 1 ); // - 1 because there is NONE on the top
461 //================================================================================
463 * \brief Updates "Edit hypothesis" button state
465 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
466 * if current hypothesis is <None>, enables otherwise.
467 * If an algorithm changed, emits selectAlgo( theIndex ) signal
469 //================================================================================
470 void SMESHGUI_MeshTab::onHyp( int theIndex )
472 QObject* aSender = sender();
474 if ( QComboBox* cb = qobject_cast< QComboBox* >( aSender ))
476 // don't allow selecting a group title
477 if ( cb->itemData( theIndex, Qt::AccessibleDescriptionRole ) == "separator" )
479 cb->setCurrentIndex( theIndex+1 );
484 if ( aSender == myHypCombo[ Algo ] )
486 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
488 else if ( aSender == myAddHypList )
490 myEditHypBtn[ MoreAddHyp ]->setEnabled( theIndex >= 0 );
491 myLessAddHypBtn ->setEnabled( theIndex >= 0 );
495 int type = ( aSender == myHypCombo[ MainHyp ] ? MainHyp : AddHyp );
496 myEditHypBtn[ type ]->setEnabled( theIndex > 0 );
498 if ( type == AddHyp )
499 myMoreAddHypBtn ->setEnabled( theIndex > 0 );
503 //================================================================================
505 * \brief Adds a current additional hyp to myAddHypList
507 * SLOT called when myMoreAddHypBtn ("plus") clicked
509 //================================================================================
511 void SMESHGUI_MeshTab::onMoreAddHyp()
513 int hypIndex = currentHyp( AddHyp );
516 // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
517 int comboIndex = myHypCombo[ AddHyp ]->currentIndex();
518 addItem( myHypCombo[ AddHyp ]->itemText( comboIndex ), MoreAddHyp, hypIndex );
520 myHypCombo[ AddHyp ]->removeItem( comboIndex );
521 myHypCombo[ AddHyp ]->setCurrentIndex( 0 );
523 myMoreAddHypBtn->setEnabled( false );
524 myEditHypBtn[ AddHyp ]->setEnabled( false );
528 //================================================================================
530 * \brief Removes a current additional hyp from myAddHypList
532 * SLOT called when myLessAddHypBtn ("minus") clicked
534 //================================================================================
536 void SMESHGUI_MeshTab::onLessAddHyp()
538 if ( QListWidgetItem * item = myAddHypList->currentItem() )
540 // move a hyp from myAddHypList to myHypCombo[ AddHyp ]
541 int hypIndex = item->data( Qt::UserRole ).toInt();
542 addItem( item->text(), AddHyp, hypIndex );
543 delete item;//myAddHypList->takeItem( myAddHypList->currentRow() );
547 //================================================================================
549 * \brief Resets all tab fields
551 * Resets all tab fields
553 //================================================================================
554 void SMESHGUI_MeshTab::reset()
556 for ( int i = Algo; i <= AddHyp; i++ )
558 myHypCombo[ i ]->setCurrentIndex( 0 );
559 if ( myEditHypBtn[ i ] )
560 myEditHypBtn[ i ]->setEnabled( false );
565 * \brief Dialog for mech creation or editing
567 * This dialog is used for mech creation or editing.
570 //================================================================================
573 * \param theToCreate - if this parameter is true then dialog is used for creation,
574 * for editing otherwise
575 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
576 * for sub-mesh otherwise
578 * Makes dialog's look and feel
580 //================================================================================
581 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
582 : SMESHGUI_Dialog( 0, false, true )
584 // Create top controls
586 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
588 createObject( tr( "NAME" ), mainFrame(), Obj );
589 setNameIndication( Obj, OneName );
590 setReadOnly( Obj, false );
592 createObject( tr( "MESH" ), mainFrame(), Mesh );
594 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
597 QLabel* anMeshTypeLbl = new QLabel( tr( "MESH_TYPE" ), this );
598 myMeshType = new QComboBox( this );
602 myTabWg = new QTabWidget( mainFrame() );
603 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
604 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
605 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
606 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
607 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
608 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
609 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
610 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
613 myHypoSetButton = new QToolButton( mainFrame() );
614 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
615 myHypoSetButton->setEnabled( false );
616 myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding,
617 myHypoSetButton->sizePolicy().verticalPolicy() );
620 QGridLayout* aLay = new QGridLayout( mainFrame() );
621 aLay->setMargin( 0 );
622 aLay->setSpacing( SPACING );
624 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
625 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
626 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
627 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
628 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
629 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
630 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
631 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
632 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
633 aLay->addWidget( anMeshTypeLbl, 3, 0 );
634 aLay->addWidget( myMeshType, 3, 2 );
635 aLay->addWidget( myTabWg, 5, 0, 1, 3 );
636 aLay->addWidget( myHypoSetButton, 6, 0, 1, 3 );
637 aLay->setRowMinimumHeight( 3, 20 );
641 // Connect signals and slots
642 connect( myMeshType, SIGNAL( activated( int ) ), SLOT( onChangedMeshType( int ) ) );
643 // Disable controls if necessary
644 setObjectShown( Mesh, false );
647 setWindowTitle( tr( "CREATE_MESH" ) );
648 objectWg( Obj, Btn )->hide();
650 setWindowTitle( tr( "CREATE_MESH" ) );
653 setWindowTitle( tr( "CREATE_SUBMESH" ) );
654 setObjectShown( Mesh, true );
659 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
660 objectWg( Mesh, Btn )->hide();
661 objectWg( Geom, Btn )->hide();
663 setTitile( theToCreate, theIsMesh );
666 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
670 //================================================================================
672 * \brief Set dialog title
674 //================================================================================
676 void SMESHGUI_MeshDlg::setTitile( const bool theToCreate, const bool theIsMesh )
680 setWindowTitle( tr( theIsMesh ? "CREATE_MESH" : "CREATE_SUBMESH" ));
684 setWindowTitle( tr( theIsMesh ? "EDIT_MESH" : "EDIT_SUBMESH") );
689 //================================================================================
691 * \brief Gets tab with given id
692 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
693 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
696 * Gets tab containing controls for definition of algorithms and AddHypotheses
698 //================================================================================
699 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
701 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
704 //================================================================================
706 * \brief Resets all dialog fields
708 //================================================================================
709 void SMESHGUI_MeshDlg::reset()
712 myTabs[ Dim0D ]->reset();
713 myTabs[ Dim1D ]->reset();
714 myTabs[ Dim2D ]->reset();
715 myTabs[ Dim3D ]->reset();
718 //================================================================================
720 * \brief Sets curent tab
722 //================================================================================
723 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
725 myTabWg->setCurrentIndex( Dim3D - theId );
728 //================================================================================
730 * \brief Enable/disable tabs
731 * \param int - maximum possible dimention
733 //================================================================================
735 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
737 const int DIM = maxDim;
738 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
739 bool enable = ( dim <= DIM );
741 myTabs[ dim ]->reset();
748 // deselect desabled tab
749 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
750 setCurrentTab( DIM );
753 //================================================================================
755 * \brief Sets list of available Sets of Hypotheses
757 //================================================================================
759 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
761 QMenu* aHypoSetPopup = myHypoSetButton->menu();
762 if ( !aHypoSetPopup ) {
763 aHypoSetPopup = new QMenu( myHypoSetButton );
764 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
765 myHypoSetButton->setMenu( aHypoSetPopup );
766 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
768 aHypoSetPopup->clear();
769 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
770 aHypoSetPopup->addAction( theSets[ i ] );
772 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
775 //================================================================================
777 * \brief Emits hypoSet signal
779 * SLOT is called when a hypotheses set is selected. Emits hypoSet
780 * signal to notify operation about this event
782 //================================================================================
784 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
786 emit hypoSet( a->text() );
789 //================================================================================
791 * \brief Enable showing of the popup when Geometry selection btn is clicked
792 * \param enable - true to enable
794 //================================================================================
796 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
798 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
800 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
803 if ( ! myGeomPopup ) {
804 myGeomPopup = new QMenu();
805 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
806 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
807 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
808 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
812 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
822 //================================================================================
825 * \param int - tab ID
827 //================================================================================
828 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
829 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
830 if ( theTabId == Dim3D ) myHypoSetButton->setEnabled( false );
833 //================================================================================
836 * \param int - tab ID
838 //================================================================================
839 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
840 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
841 if ( theTabId == Dim3D ) {
842 QMenu* aHypoSetPopup = myHypoSetButton->menu();
843 myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
847 //================================================================================
849 * \brief Check if tab enabled
850 * \param int - tab ID
852 //================================================================================
853 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const {
854 return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
857 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
859 if ( myGeomPopup && isBtnOn )
860 myGeomPopup->exec( QCursor::pos() );
863 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
865 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
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 myMeshType->setCurrentIndex( theIndex );