1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.
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
22 // File : SMESHGUI_MeshDlg.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MeshDlg.h"
29 // SALOME GUI includes
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
34 #include <QVBoxLayout>
35 #include <QGridLayout>
39 #include <QToolButton>
43 #include <QPushButton>
49 * \brief Tab for tab widget containing controls for definition of
50 * algorithms and hypotheses
53 //================================================================================
56 * \param theParent - Parent widget for this tab
58 * Makes tab's look and feel
60 //================================================================================
61 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
64 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
65 QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
66 QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
69 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
70 myHyp[ Algo ] = new QComboBox( this );
73 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
74 myHyp[ MainHyp ] = new QComboBox( this );
75 myHyp[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
76 myCreateHyp[ MainHyp ] = new QToolButton( this );
77 myCreateHyp[ MainHyp ]->setIcon( aCreateIcon );
78 myEditHyp[ MainHyp ] = new QToolButton( this );
79 myEditHyp[ MainHyp ]->setIcon( aEditIcon );
82 QFrame* aLine = new QFrame( this );
83 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
86 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
87 myHyp[ AddHyp ] = new QComboBox( this );
88 myHyp[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
89 myCreateHyp[ AddHyp ] = new QToolButton( this );
90 myCreateHyp[ AddHyp ]->setIcon( aCreateIcon );
91 myEditHyp[ AddHyp ] = new QToolButton( this );
92 myEditHyp[ AddHyp ]->setIcon( aEditIcon );
95 QGridLayout* aLay = new QGridLayout( this );
96 aLay->setMargin( MARGIN );
97 aLay->setSpacing( SPACING );
99 aLay->addWidget( anAlgoLbl, 0, 0 );
100 aLay->addWidget( myHyp[ Algo ], 0, 1 );
101 aLay->addWidget( aHypLbl, 1, 0 );
102 aLay->addWidget( myHyp[ MainHyp ], 1, 1 );
103 aLay->addWidget( myCreateHyp[ MainHyp ], 1, 2 );
104 aLay->addWidget( myEditHyp[ MainHyp ], 1, 3 );
105 aLay->addWidget( aLine, 2, 0, 1, 4 );
106 aLay->addWidget( anAddHypLbl, 3, 0 );
107 aLay->addWidget( myHyp[ AddHyp ], 3, 1 );
108 aLay->addWidget( myCreateHyp[ AddHyp ], 3, 2 );
109 aLay->addWidget( myEditHyp[ AddHyp ], 3, 3 );
110 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 4, 0 );
112 // Connect signals and slots
113 for ( int i = MainHyp; i <= AddHyp; i++ )
115 connect( myCreateHyp[ i ], SIGNAL( clicked() ), SLOT( onCreateHyp() ) );
116 connect( myEditHyp[ i ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
117 connect( myHyp[ i ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
119 connect( myHyp[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
121 // Initialize controls
123 setAvailableHyps( Algo, QStringList() );
124 setAvailableHyps( MainHyp, QStringList() );
125 setAvailableHyps( AddHyp, QStringList() );
128 //================================================================================
132 //================================================================================
133 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
137 //================================================================================
139 * \brief Sets available hypothesis or algorithms
140 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
141 * \param theHyps - list of available hypothesis names
143 * Sets available main or additional hypothesis for this tab
145 //================================================================================
146 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
148 myAvailableHyps[ theId ] = theHyps;
150 bool enable = ! theHyps.isEmpty();
153 myHyp[ Algo ]->clear();
154 myHyp[ Algo ]->addItem( tr( "NONE" ) );
155 myHyp[ Algo ]->addItems( theHyps );
156 myHyp[ Algo ]->setCurrentIndex( 0 );
159 myCreateHyp[ theId ]->setEnabled( enable );
160 myEditHyp[ theId ]->setEnabled( false );
162 myHyp[ theId ]->setEnabled( enable );
165 //================================================================================
167 * \brief Sets existing hypothesis
168 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
169 * \param theHyps - list of available hypothesis names
171 * Sets existing main or additional hypothesis for this tab
173 //================================================================================
174 void SMESHGUI_MeshTab::setExistingHyps( const int theId, const QStringList& theHyps )
178 myHyp[ theId ]->clear();
179 myHyp[ theId ]->addItem( tr( "NONE" ) );
180 myHyp[ theId ]->addItems( theHyps );
181 myHyp[ theId ]->setCurrentIndex( 0 );
182 myHyp[ theId ]->setEnabled( !theHyps.isEmpty() );
183 myEditHyp[ theId ]->setEnabled( false );
187 //================================================================================
189 * \brief Adds hypothesis in combo box of available ones
190 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
191 * \param theHyp - name of hypothesis to be added
193 * Adds hypothesis in combo box of available ones. This method is called by operation
194 * after creation of new hypothesis.
196 //================================================================================
197 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
199 myHyp[ theId ]->addItem( theHyp );
200 myHyp[ theId ]->setCurrentIndex( myHyp[ theId ]->count() - 1 );
201 myEditHyp[ theId ]->setEnabled( true );
202 myHyp[ theId ]->setEnabled( true );
205 //================================================================================
207 * \brief Renames hypothesis
208 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
209 * \param theIndex - index of hypothesis to be renamed
210 * \param theNewName - new name of hypothesis to be renamed
214 //================================================================================
215 void SMESHGUI_MeshTab::renameHyp( const int theId,
217 const QString& theNewName )
219 if ( theIndex > 0 && theIndex < myHyp[ theId ]->count() )
220 myHyp[ theId ]->setItemText( theIndex, theNewName );
223 //================================================================================
225 * \brief Sets current hypothesis
226 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
227 * \param theIndex - index of hypothesis to be set as current
229 * Sets current hypothesis
231 //================================================================================
232 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
234 if ( theIndex >= 0 && theIndex < myHyp[ theId ]->count() )
236 myHyp[ theId ]->setCurrentIndex( theIndex );
237 if ( myEditHyp[ theId ] )
238 myEditHyp[ theId ]->setEnabled( theIndex > 0 );
242 //================================================================================
244 * \brief Gets current hypothesis
245 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
246 * \retval int - index of current hypothesis
248 * Gets current hypothesis
250 //================================================================================
251 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
253 return myHyp[ theId ]->currentIndex();
256 //================================================================================
258 * \brief Emits createHyp( const int ) signal
260 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
261 * createHyp( const int ) signal
263 //================================================================================
264 void SMESHGUI_MeshTab::onCreateHyp()
266 bool isMainHyp = sender() == myCreateHyp[ MainHyp ];
268 QMenu aPopup( this );
270 QStringList aHypNames = isMainHyp ?
271 myAvailableHyps[ MainHyp ] : aHypNames = myAvailableHyps[ AddHyp ];
273 QList<QAction*> actions;
274 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
275 actions.append( aPopup.addAction( aHypNames[ i ] ) );
277 QAction* a = aPopup.exec( QCursor::pos() );
279 emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
282 //================================================================================
284 * \brief Emits editHyp( const int ) signal
286 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
287 * editHyp( const int ) signal
289 //================================================================================
290 void SMESHGUI_MeshTab::onEditHyp()
292 const QObject* aSender = sender();
293 int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
294 emit editHyp( aHypType, myHyp[ aHypType ]->currentIndex() - 1 ); // - 1 because there is NONE on the top
297 //================================================================================
299 * \brief Updates "Edit hypothesis" button state
301 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
302 * if current hypothesis is <None>, enables otherwise.
303 * If an algorithm changed, emits selectAlgo( theIndex ) signal
305 //================================================================================
306 void SMESHGUI_MeshTab::onHyp( int theIndex )
308 const QObject* aSender = sender();
309 if ( aSender == myHyp[ Algo ] )
310 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
312 int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
313 myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
317 //================================================================================
319 * \brief Resets all tab fields
321 * Resets all tab fields
323 //================================================================================
324 void SMESHGUI_MeshTab::reset()
326 for ( int i = Algo; i <= AddHyp; i++ )
328 myHyp[ i ]->setCurrentIndex( 0 );
329 if ( myEditHyp[ i ] )
330 myEditHyp[ i ]->setEnabled( false );
335 * \brief Dialog for mech creation or editing
337 * This dialog is used for mech creation or editing.
340 //================================================================================
343 * \param theToCreate - if this parameter is true then dialog is used for creation,
344 * for editing otherwise
345 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
346 * for sub-mesh otherwise
348 * Makes dialog's look and feel
350 //================================================================================
351 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
352 : SMESHGUI_Dialog( 0, false, true )
354 // Create top controls
357 createObject( tr( "NAME" ), mainFrame(), Obj );
358 setNameIndication( Obj, OneName );
359 setReadOnly( Obj, false );
361 createObject( tr( "MESH" ), mainFrame(), Mesh );
363 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
368 myTabWg = new QTabWidget( mainFrame() );
369 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
370 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
371 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
372 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
373 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
374 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
375 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
376 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
379 myHypoSetButton = new QToolButton( mainFrame() );
380 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
381 myHypoSetButton->setEnabled( false );
384 QGridLayout* aLay = new QGridLayout( mainFrame() );
385 aLay->setMargin( 0 );
386 aLay->setSpacing( SPACING );
388 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
389 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
390 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
391 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
392 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
393 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
394 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
395 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
396 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
397 aLay->addWidget( myTabWg, 4, 0, 1, 3 );
398 aLay->addWidget( myHypoSetButton, 5, 0, 1, 3 );
399 aLay->setRowMinimumHeight( 3, 20 );
401 // Disable controls if necessary
402 setObjectShown( Mesh, false );
405 setWindowTitle( tr( "CREATE_MESH" ) );
406 objectWg( Obj, Btn )->hide();
408 setWindowTitle( tr( "CREATE_MESH" ) );
411 setWindowTitle( tr( "CREATE_SUBMESH" ) );
412 setObjectShown( Mesh, true );
417 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
418 objectWg( Mesh, Btn )->hide();
419 objectWg( Geom, Btn )->hide();
423 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
427 //================================================================================
429 * \brief Gets tab with given id
430 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
431 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
434 * Gets tab containing controls for definition of algorithms and AddHypotheses
436 //================================================================================
437 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
439 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
442 //================================================================================
444 * \brief Resets all dialog fields
446 //================================================================================
447 void SMESHGUI_MeshDlg::reset()
450 myTabs[ Dim0D ]->reset();
451 myTabs[ Dim1D ]->reset();
452 myTabs[ Dim2D ]->reset();
453 myTabs[ Dim3D ]->reset();
456 //================================================================================
458 * \brief Sets curent tab
460 //================================================================================
461 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
463 myTabWg->setCurrentIndex( Dim3D - theId );
466 //================================================================================
468 * \brief Enable/disable tabs
469 * \param int - maximum possible dimention
471 //================================================================================
473 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
475 const int DIM = maxDim;
476 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
477 bool enable = ( dim <= DIM );
479 myTabs[ dim ]->reset();
480 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ dim ] ), enable );
482 // deselect desabled tab
483 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
484 setCurrentTab( DIM - 1 );
487 //================================================================================
489 * \brief Sets list of available Sets of Hypotheses
491 //================================================================================
493 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
495 QMenu* aHypoSetPopup = myHypoSetButton->menu();
496 if ( !aHypoSetPopup ) {
497 aHypoSetPopup = new QMenu( myHypoSetButton );
498 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
499 myHypoSetButton->setMenu( aHypoSetPopup );
500 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
502 aHypoSetPopup->clear();
503 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
504 aHypoSetPopup->addAction( theSets[ i ] );
506 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
509 //================================================================================
511 * \brief Emits hypoSet signal
513 * SLOT is called when a hypotheses set is selected. Emits hypoSet
514 * signal to notify operation about this event
516 //================================================================================
518 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
520 emit hypoSet( a->text() );
523 //================================================================================
525 * \brief Enable showing of the popup when Geometry selection btn is clicked
526 * \param enable - true to enable
528 //================================================================================
530 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
532 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
534 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
536 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
538 if ( ! myGeomPopup ) {
539 myGeomPopup = new QMenu();
540 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
541 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
542 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
544 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
550 //================================================================================
553 * \param int - tab ID
555 //================================================================================
556 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
557 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
560 //================================================================================
563 * \param int - tab ID
565 //================================================================================
566 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
567 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
570 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
572 if ( myGeomPopup && isBtnOn )
573 myGeomPopup->exec( QCursor::pos() );
576 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
578 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );