1 // Copyright (C) 2007-2008 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.
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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_MeshDlg.cxx
24 // 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 ] : 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
356 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
358 createObject( tr( "NAME" ), mainFrame(), Obj );
359 setNameIndication( Obj, OneName );
360 setReadOnly( Obj, false );
362 createObject( tr( "MESH" ), mainFrame(), Mesh );
364 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
369 myTabWg = new QTabWidget( mainFrame() );
370 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
371 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
372 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
373 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
374 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
375 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
376 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
377 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
380 myHypoSetButton = new QToolButton( mainFrame() );
381 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
382 myHypoSetButton->setEnabled( false );
383 myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding,
384 myHypoSetButton->sizePolicy().verticalPolicy() );
387 QGridLayout* aLay = new QGridLayout( mainFrame() );
388 aLay->setMargin( 0 );
389 aLay->setSpacing( SPACING );
391 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
392 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
393 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
394 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
395 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
396 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
397 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
398 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
399 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
400 aLay->addWidget( myTabWg, 4, 0, 1, 3 );
401 aLay->addWidget( myHypoSetButton, 5, 0, 1, 3 );
402 aLay->setRowMinimumHeight( 3, 20 );
404 // Disable controls if necessary
405 setObjectShown( Mesh, false );
408 setWindowTitle( tr( "CREATE_MESH" ) );
409 objectWg( Obj, Btn )->hide();
411 setWindowTitle( tr( "CREATE_MESH" ) );
414 setWindowTitle( tr( "CREATE_SUBMESH" ) );
415 setObjectShown( Mesh, true );
420 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
421 objectWg( Mesh, Btn )->hide();
422 objectWg( Geom, Btn )->hide();
426 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
430 //================================================================================
432 * \brief Gets tab with given id
433 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
434 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
437 * Gets tab containing controls for definition of algorithms and AddHypotheses
439 //================================================================================
440 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
442 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
445 //================================================================================
447 * \brief Resets all dialog fields
449 //================================================================================
450 void SMESHGUI_MeshDlg::reset()
453 myTabs[ Dim0D ]->reset();
454 myTabs[ Dim1D ]->reset();
455 myTabs[ Dim2D ]->reset();
456 myTabs[ Dim3D ]->reset();
459 //================================================================================
461 * \brief Sets curent tab
463 //================================================================================
464 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
466 myTabWg->setCurrentIndex( Dim3D - theId );
469 //================================================================================
471 * \brief Enable/disable tabs
472 * \param int - maximum possible dimention
474 //================================================================================
476 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
478 const int DIM = maxDim;
479 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
480 bool enable = ( dim <= DIM );
482 myTabs[ dim ]->reset();
483 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ dim ] ), enable );
485 // deselect desabled tab
486 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
487 setCurrentTab( DIM );
490 //================================================================================
492 * \brief Sets list of available Sets of Hypotheses
494 //================================================================================
496 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
498 QMenu* aHypoSetPopup = myHypoSetButton->menu();
499 if ( !aHypoSetPopup ) {
500 aHypoSetPopup = new QMenu( myHypoSetButton );
501 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
502 myHypoSetButton->setMenu( aHypoSetPopup );
503 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
505 aHypoSetPopup->clear();
506 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
507 aHypoSetPopup->addAction( theSets[ i ] );
509 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
512 //================================================================================
514 * \brief Emits hypoSet signal
516 * SLOT is called when a hypotheses set is selected. Emits hypoSet
517 * signal to notify operation about this event
519 //================================================================================
521 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
523 emit hypoSet( a->text() );
526 //================================================================================
528 * \brief Enable showing of the popup when Geometry selection btn is clicked
529 * \param enable - true to enable
531 //================================================================================
533 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
535 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
537 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
540 if ( ! myGeomPopup ) {
541 myGeomPopup = new QMenu();
542 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
543 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
544 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
545 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
549 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
559 //================================================================================
562 * \param int - tab ID
564 //================================================================================
565 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
566 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
569 //================================================================================
572 * \param int - tab ID
574 //================================================================================
575 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
576 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
579 //================================================================================
581 * \brief Check if tab enabled
582 * \param int - tab ID
584 //================================================================================
585 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const {
586 myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
589 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
591 if ( myGeomPopup && isBtnOn )
592 myGeomPopup->exec( QCursor::pos() );
595 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
597 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
600 int SMESHGUI_MeshDlg::getActiveObject()
602 for (int i = 0; i < 3; ++i )
603 if ( isObjectShown( i ) &&
604 (( QToolButton* )objectWg( i, Btn ))->isChecked())