1 // Copyright (C) 2007-2013 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
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>
35 #include <QVBoxLayout>
36 #include <QGridLayout>
40 #include <QToolButton>
44 #include <QPushButton>
50 * \brief Tab for tab widget containing controls for definition of
51 * algorithms and hypotheses
54 //================================================================================
57 * \param theParent - Parent widget for this tab
59 * Makes tab's look and feel
61 //================================================================================
62 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
65 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
66 QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
67 QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
70 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
71 myHyp[ Algo ] = new QComboBox( this );
74 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
75 myHyp[ MainHyp ] = new QComboBox( this );
76 myHyp[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
77 myCreateHyp[ MainHyp ] = new QToolButton( this );
78 myCreateHyp[ MainHyp ]->setIcon( aCreateIcon );
79 myEditHyp[ MainHyp ] = new QToolButton( this );
80 myEditHyp[ MainHyp ]->setIcon( aEditIcon );
83 QFrame* aLine = new QFrame( this );
84 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
87 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
88 myHyp[ AddHyp ] = new QComboBox( this );
89 myHyp[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
90 myCreateHyp[ AddHyp ] = new QToolButton( this );
91 myCreateHyp[ AddHyp ]->setIcon( aCreateIcon );
92 myEditHyp[ AddHyp ] = new QToolButton( this );
93 myEditHyp[ AddHyp ]->setIcon( aEditIcon );
96 QGridLayout* aLay = new QGridLayout( this );
97 aLay->setMargin( MARGIN );
98 aLay->setSpacing( SPACING );
100 aLay->addWidget( anAlgoLbl, 0, 0 );
101 aLay->addWidget( myHyp[ Algo ], 0, 1 );
102 aLay->addWidget( aHypLbl, 1, 0 );
103 aLay->addWidget( myHyp[ MainHyp ], 1, 1 );
104 aLay->addWidget( myCreateHyp[ MainHyp ], 1, 2 );
105 aLay->addWidget( myEditHyp[ MainHyp ], 1, 3 );
106 aLay->addWidget( aLine, 2, 0, 1, 4 );
107 aLay->addWidget( anAddHypLbl, 3, 0 );
108 aLay->addWidget( myHyp[ AddHyp ], 3, 1 );
109 aLay->addWidget( myCreateHyp[ AddHyp ], 3, 2 );
110 aLay->addWidget( myEditHyp[ AddHyp ], 3, 3 );
111 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 4, 0 );
113 // Connect signals and slots
114 for ( int i = MainHyp; i <= AddHyp; i++ )
116 connect( myCreateHyp[ i ], SIGNAL( clicked() ) , SLOT( onCreateHyp() ) );
117 connect( myEditHyp[ i ] , SIGNAL( clicked() ) , SLOT( onEditHyp() ) );
118 connect( myHyp[ i ] , SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
120 connect( myHyp[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
122 // Initialize controls
124 setAvailableHyps( Algo, QStringList() );
125 setAvailableHyps( MainHyp, QStringList() );
126 setAvailableHyps( AddHyp, QStringList() );
129 //================================================================================
133 //================================================================================
134 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
138 //================================================================================
140 * \brief Sets available hypothesis or algorithms
141 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
142 * \param theHyps - list of available hypothesis names
144 * Sets available main or additional hypothesis for this tab
146 //================================================================================
147 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
149 myAvailableHyps[ theId ] = theHyps;
151 bool enable = ! theHyps.isEmpty();
154 myHyp[ Algo ]->clear();
155 myHyp[ Algo ]->addItem( tr( "NONE" ) );
156 myHyp[ Algo ]->addItems( theHyps );
157 myHyp[ Algo ]->setCurrentIndex( 0 );
160 myCreateHyp[ theId ]->setEnabled( enable );
161 myEditHyp[ theId ]->setEnabled( false );
163 myHyp[ theId ]->setEnabled( enable );
166 //================================================================================
168 * \brief Sets existing hypothesis
169 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
170 * \param theHyps - list of available hypothesis names
172 * Sets existing main or additional hypothesis for this tab
174 //================================================================================
175 void SMESHGUI_MeshTab::setExistingHyps( const int theId, const QStringList& theHyps )
179 myHyp[ theId ]->clear();
180 myHyp[ theId ]->addItem( tr( "NONE" ) );
181 myHyp[ theId ]->addItems( theHyps );
182 myHyp[ theId ]->setCurrentIndex( 0 );
183 myHyp[ theId ]->setEnabled( !theHyps.isEmpty() );
184 myEditHyp[ theId ]->setEnabled( false );
188 //================================================================================
190 * \brief Adds hypothesis in combo box of available ones
191 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
192 * \param theHyp - name of hypothesis to be added
194 * Adds hypothesis in combo box of available ones. This method is called by operation
195 * after creation of new hypothesis.
197 //================================================================================
198 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
200 myHyp[ theId ]->addItem( theHyp );
201 myHyp[ theId ]->setCurrentIndex( myHyp[ theId ]->count() - 1 );
202 myEditHyp[ theId ]->setEnabled( true );
203 myHyp[ theId ]->setEnabled( true );
206 //================================================================================
208 * \brief Renames hypothesis
209 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
210 * \param theIndex - index of hypothesis to be renamed
211 * \param theNewName - new name of hypothesis to be renamed
215 //================================================================================
216 void SMESHGUI_MeshTab::renameHyp( const int theId,
218 const QString& theNewName )
220 if ( theIndex > 0 && theIndex < myHyp[ theId ]->count() )
221 myHyp[ theId ]->setItemText( theIndex, theNewName );
224 //================================================================================
226 * \brief Sets current hypothesis
227 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
228 * \param theIndex - index of hypothesis to be set as current
230 * Sets current hypothesis
232 //================================================================================
233 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
235 if ( theIndex >= 0 && theIndex < myHyp[ theId ]->count() )
237 myHyp[ theId ]->setCurrentIndex( theIndex );
238 if ( myEditHyp[ theId ] )
239 myEditHyp[ theId ]->setEnabled( theIndex > 0 );
243 //================================================================================
245 * \brief Gets current hypothesis
246 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
247 * \retval int - index of current hypothesis
249 * Gets current hypothesis
251 //================================================================================
252 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
254 return myHyp[ theId ]->currentIndex();
257 //================================================================================
259 * \brief Emits createHyp( const int ) signal
261 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
262 * createHyp( const int ) signal
264 //================================================================================
265 void SMESHGUI_MeshTab::onCreateHyp()
267 bool isMainHyp = sender() == myCreateHyp[ MainHyp ];
269 QMenu aPopup( this );
271 QStringList aHypNames = isMainHyp ?
272 myAvailableHyps[ MainHyp ] : myAvailableHyps[ AddHyp ];
274 QList<QAction*> actions;
275 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
276 actions.append( aPopup.addAction( aHypNames[ i ] ) );
278 QAction* a = aPopup.exec( QCursor::pos() );
280 emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
283 //================================================================================
285 * \brief Emits editHyp( const int ) signal
287 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
288 * editHyp( const int ) signal
290 //================================================================================
291 void SMESHGUI_MeshTab::onEditHyp()
293 const QObject* aSender = sender();
294 int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
295 emit editHyp( aHypType, myHyp[ aHypType ]->currentIndex() - 1 ); // - 1 because there is NONE on the top
298 //================================================================================
300 * \brief Updates "Edit hypothesis" button state
302 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
303 * if current hypothesis is <None>, enables otherwise.
304 * If an algorithm changed, emits selectAlgo( theIndex ) signal
306 //================================================================================
307 void SMESHGUI_MeshTab::onHyp( int theIndex )
309 const QObject* aSender = sender();
310 if ( aSender == myHyp[ Algo ] )
311 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
313 int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
314 myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
318 //================================================================================
320 * \brief Resets all tab fields
322 * Resets all tab fields
324 //================================================================================
325 void SMESHGUI_MeshTab::reset()
327 for ( int i = Algo; i <= AddHyp; i++ )
329 myHyp[ i ]->setCurrentIndex( 0 );
330 if ( myEditHyp[ i ] )
331 myEditHyp[ i ]->setEnabled( false );
336 * \brief Dialog for mech creation or editing
338 * This dialog is used for mech creation or editing.
341 //================================================================================
344 * \param theToCreate - if this parameter is true then dialog is used for creation,
345 * for editing otherwise
346 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
347 * for sub-mesh otherwise
349 * Makes dialog's look and feel
351 //================================================================================
352 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
353 : SMESHGUI_Dialog( 0, false, true )
355 // Create top controls
357 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
359 createObject( tr( "NAME" ), mainFrame(), Obj );
360 setNameIndication( Obj, OneName );
361 setReadOnly( Obj, false );
363 createObject( tr( "MESH" ), mainFrame(), Mesh );
365 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
370 myTabWg = new QTabWidget( mainFrame() );
371 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
372 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
373 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
374 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
375 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
376 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
377 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
378 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
381 myHypoSetButton = new QToolButton( mainFrame() );
382 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
383 myHypoSetButton->setEnabled( false );
384 myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding,
385 myHypoSetButton->sizePolicy().verticalPolicy() );
388 QGridLayout* aLay = new QGridLayout( mainFrame() );
389 aLay->setMargin( 0 );
390 aLay->setSpacing( SPACING );
392 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
393 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
394 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
395 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
396 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
397 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
398 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
399 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
400 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
401 aLay->addWidget( myTabWg, 4, 0, 1, 3 );
402 aLay->addWidget( myHypoSetButton, 5, 0, 1, 3 );
403 aLay->setRowMinimumHeight( 3, 20 );
405 // Disable controls if necessary
406 setObjectShown( Mesh, false );
409 setWindowTitle( tr( "CREATE_MESH" ) );
410 objectWg( Obj, Btn )->hide();
412 setWindowTitle( tr( "CREATE_MESH" ) );
415 setWindowTitle( tr( "CREATE_SUBMESH" ) );
416 setObjectShown( Mesh, true );
421 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
422 objectWg( Mesh, Btn )->hide();
423 objectWg( Geom, Btn )->hide();
427 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
431 //================================================================================
433 * \brief Gets tab with given id
434 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
435 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
438 * Gets tab containing controls for definition of algorithms and AddHypotheses
440 //================================================================================
441 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
443 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
446 //================================================================================
448 * \brief Resets all dialog fields
450 //================================================================================
451 void SMESHGUI_MeshDlg::reset()
454 myTabs[ Dim0D ]->reset();
455 myTabs[ Dim1D ]->reset();
456 myTabs[ Dim2D ]->reset();
457 myTabs[ Dim3D ]->reset();
460 //================================================================================
462 * \brief Sets curent tab
464 //================================================================================
465 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
467 myTabWg->setCurrentIndex( Dim3D - theId );
470 //================================================================================
472 * \brief Enable/disable tabs
473 * \param int - maximum possible dimention
475 //================================================================================
477 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
479 const int DIM = maxDim;
480 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
481 bool enable = ( dim <= DIM );
483 myTabs[ dim ]->reset();
490 // deselect desabled tab
491 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
492 setCurrentTab( DIM );
495 //================================================================================
497 * \brief Sets list of available Sets of Hypotheses
499 //================================================================================
501 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
503 QMenu* aHypoSetPopup = myHypoSetButton->menu();
504 if ( !aHypoSetPopup ) {
505 aHypoSetPopup = new QMenu( myHypoSetButton );
506 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
507 myHypoSetButton->setMenu( aHypoSetPopup );
508 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
510 aHypoSetPopup->clear();
511 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
512 aHypoSetPopup->addAction( theSets[ i ] );
514 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
517 //================================================================================
519 * \brief Emits hypoSet signal
521 * SLOT is called when a hypotheses set is selected. Emits hypoSet
522 * signal to notify operation about this event
524 //================================================================================
526 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
528 emit hypoSet( a->text() );
531 //================================================================================
533 * \brief Enable showing of the popup when Geometry selection btn is clicked
534 * \param enable - true to enable
536 //================================================================================
538 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
540 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
542 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
545 if ( ! myGeomPopup ) {
546 myGeomPopup = new QMenu();
547 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
548 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
549 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
550 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
554 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
564 //================================================================================
567 * \param int - tab ID
569 //================================================================================
570 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
571 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
572 if ( theTabId == Dim3D ) myHypoSetButton->setEnabled( false );
575 //================================================================================
578 * \param int - tab ID
580 //================================================================================
581 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
582 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
583 if ( theTabId == Dim3D ) {
584 QMenu* aHypoSetPopup = myHypoSetButton->menu();
585 myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
589 //================================================================================
591 * \brief Check if tab enabled
592 * \param int - tab ID
594 //================================================================================
595 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const {
596 return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
599 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
601 if ( myGeomPopup && isBtnOn )
602 myGeomPopup->exec( QCursor::pos() );
605 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
607 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
610 int SMESHGUI_MeshDlg::getActiveObject()
612 for (int i = 0; i < 3; ++i )
613 if ( isObjectShown( i ) &&
614 (( QToolButton* )objectWg( i, Btn ))->isChecked())