1 // Copyright (C) 2007-2014 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>
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();
152 if ( theId == Algo ) // fill list of algos
154 myHyp[ Algo ]->clear();
157 myHyp[ Algo ]->addItem( tr( "NONE" ) );
158 myHyp[ Algo ]->addItems( theHyps );
159 myHyp[ Algo ]->setCurrentIndex( 0 );
162 else // enable buttons
164 myCreateHyp[ theId ]->setEnabled( enable );
165 myEditHyp [ theId ]->setEnabled( false );
167 myHyp[ theId ]->setEnabled( enable );
170 //================================================================================
172 * \brief Sets existing hypothesis
173 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
174 * \param theHyps - list of available hypothesis names
175 * \param theDefaultAvlbl - \c true means that the algorithm can with w/o hypothesis
176 * with some default parameters
178 * Sets existing main or additional hypothesis for this tab
180 //================================================================================
181 void SMESHGUI_MeshTab::setExistingHyps( const int theId,
182 const QStringList& theHyps,
183 bool theDefaultAvlbl)
187 bool enable = ! myAvailableHyps[ theId ].isEmpty();
188 myHyp[ theId ]->clear();
191 QString none = tr( theDefaultAvlbl ? "DEFAULT" : ( theId == AddHyp ) ? "NONE" : "NONE" );
192 myHyp[ theId ]->addItem( none );
193 myHyp[ theId ]->addItems( theHyps );
194 myHyp[ theId ]->setCurrentIndex( 0 );
196 myHyp [ theId ]->setEnabled( enable );
197 myEditHyp[ theId ]->setEnabled( false );
201 //================================================================================
203 * \brief Adds hypothesis in combo box of available ones
204 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
205 * \param theHyp - name of hypothesis to be added
207 * Adds hypothesis in combo box of available ones. This method is called by operation
208 * after creation of new hypothesis.
210 //================================================================================
211 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
213 myHyp[ theId ]->addItem( theHyp );
214 myHyp[ theId ]->setCurrentIndex( myHyp[ theId ]->count() - 1 );
215 myEditHyp[ theId ]->setEnabled( true );
216 myHyp[ theId ]->setEnabled( true );
219 //================================================================================
221 * \brief Renames hypothesis
222 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
223 * \param theIndex - index of hypothesis to be renamed
224 * \param theNewName - new name of hypothesis to be renamed
228 //================================================================================
229 void SMESHGUI_MeshTab::renameHyp( const int theId,
231 const QString& theNewName )
233 if ( theIndex > 0 && theIndex < myHyp[ theId ]->count() )
234 myHyp[ theId ]->setItemText( theIndex, theNewName );
237 //================================================================================
239 * \brief Sets current hypothesis
240 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
241 * \param theIndex - index of hypothesis to be set as current
243 * Sets current hypothesis
245 //================================================================================
246 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
248 if ( theIndex >= 0 && theIndex < myHyp[ theId ]->count() )
250 myHyp[ theId ]->setCurrentIndex( theIndex );
251 if ( myEditHyp[ theId ] )
252 myEditHyp[ theId ]->setEnabled( theIndex > 0 );
256 //================================================================================
258 * \brief Gets current hypothesis
259 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
260 * \retval int - index of current hypothesis
262 * Gets current hypothesis
264 //================================================================================
265 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
267 return myHyp[ theId ]->currentIndex();
270 //================================================================================
272 * \brief Emits createHyp( const int ) signal
274 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
275 * createHyp( const int ) signal
277 //================================================================================
278 void SMESHGUI_MeshTab::onCreateHyp()
280 bool isMainHyp = sender() == myCreateHyp[ MainHyp ];
282 QMenu aPopup( this );
284 QStringList aHypNames = isMainHyp ?
285 myAvailableHyps[ MainHyp ] : myAvailableHyps[ AddHyp ];
287 QList<QAction*> actions;
288 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
289 actions.append( aPopup.addAction( aHypNames[ i ] ) );
291 QAction* a = aPopup.exec( QCursor::pos() );
293 emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
296 //================================================================================
298 * \brief Emits editHyp( const int ) signal
300 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
301 * editHyp( const int ) signal
303 //================================================================================
304 void SMESHGUI_MeshTab::onEditHyp()
306 const QObject* aSender = sender();
307 int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
308 emit editHyp( aHypType, myHyp[ aHypType ]->currentIndex() - 1 ); // - 1 because there is NONE on the top
311 //================================================================================
313 * \brief Updates "Edit hypothesis" button state
315 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
316 * if current hypothesis is <None>, enables otherwise.
317 * If an algorithm changed, emits selectAlgo( theIndex ) signal
319 //================================================================================
320 void SMESHGUI_MeshTab::onHyp( int theIndex )
322 const QObject* aSender = sender();
323 if ( aSender == myHyp[ Algo ] )
324 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
326 int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
327 myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
331 //================================================================================
333 * \brief Resets all tab fields
335 * Resets all tab fields
337 //================================================================================
338 void SMESHGUI_MeshTab::reset()
340 for ( int i = Algo; i <= AddHyp; i++ )
342 myHyp[ i ]->setCurrentIndex( 0 );
343 if ( myEditHyp[ i ] )
344 myEditHyp[ i ]->setEnabled( false );
349 * \brief Dialog for mech creation or editing
351 * This dialog is used for mech creation or editing.
354 //================================================================================
357 * \param theToCreate - if this parameter is true then dialog is used for creation,
358 * for editing otherwise
359 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
360 * for sub-mesh otherwise
362 * Makes dialog's look and feel
364 //================================================================================
365 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
366 : SMESHGUI_Dialog( 0, false, true )
368 // Create top controls
370 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
372 createObject( tr( "NAME" ), mainFrame(), Obj );
373 setNameIndication( Obj, OneName );
374 setReadOnly( Obj, false );
376 createObject( tr( "MESH" ), mainFrame(), Mesh );
378 createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
381 QLabel* anMeshTypeLbl = new QLabel( tr( "MESH_TYPE" ), this );
382 myMeshType = new QComboBox( this );
386 myTabWg = new QTabWidget( mainFrame() );
387 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
388 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
389 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
390 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
391 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
392 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
393 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
394 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
397 myHypoSetButton = new QToolButton( mainFrame() );
398 myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
399 myHypoSetButton->setEnabled( false );
400 myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding,
401 myHypoSetButton->sizePolicy().verticalPolicy() );
404 QGridLayout* aLay = new QGridLayout( mainFrame() );
405 aLay->setMargin( 0 );
406 aLay->setSpacing( SPACING );
408 aLay->addWidget( objectWg( Obj, Label ), 0, 0 );
409 aLay->addWidget( objectWg( Obj, Btn ), 0, 1 );
410 aLay->addWidget( objectWg( Obj, Control ), 0, 2 );
411 aLay->addWidget( objectWg( Mesh, Label ), 1, 0 );
412 aLay->addWidget( objectWg( Mesh, Btn ), 1, 1 );
413 aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
414 aLay->addWidget( objectWg( Geom, Label ), 2, 0 );
415 aLay->addWidget( objectWg( Geom, Btn ), 2, 1 );
416 aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
417 aLay->addWidget( anMeshTypeLbl, 3, 0 );
418 aLay->addWidget( myMeshType, 3, 2 );
419 aLay->addWidget( myTabWg, 5, 0, 1, 3 );
420 aLay->addWidget( myHypoSetButton, 6, 0, 1, 3 );
421 aLay->setRowMinimumHeight( 3, 20 );
425 // Connect signals and slots
426 connect( myMeshType, SIGNAL( activated( int ) ), SLOT( onChangedMeshType( int ) ) );
427 // Disable controls if necessary
428 setObjectShown( Mesh, false );
431 setWindowTitle( tr( "CREATE_MESH" ) );
432 objectWg( Obj, Btn )->hide();
434 setWindowTitle( tr( "CREATE_MESH" ) );
437 setWindowTitle( tr( "CREATE_SUBMESH" ) );
438 setObjectShown( Mesh, true );
443 setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
444 objectWg( Mesh, Btn )->hide();
445 objectWg( Geom, Btn )->hide();
449 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
453 //================================================================================
455 * \brief Gets tab with given id
456 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
457 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
460 * Gets tab containing controls for definition of algorithms and AddHypotheses
462 //================================================================================
463 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
465 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
468 //================================================================================
470 * \brief Resets all dialog fields
472 //================================================================================
473 void SMESHGUI_MeshDlg::reset()
476 myTabs[ Dim0D ]->reset();
477 myTabs[ Dim1D ]->reset();
478 myTabs[ Dim2D ]->reset();
479 myTabs[ Dim3D ]->reset();
482 //================================================================================
484 * \brief Sets curent tab
486 //================================================================================
487 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
489 myTabWg->setCurrentIndex( Dim3D - theId );
492 //================================================================================
494 * \brief Enable/disable tabs
495 * \param int - maximum possible dimention
497 //================================================================================
499 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
501 const int DIM = maxDim;
502 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
503 bool enable = ( dim <= DIM );
505 myTabs[ dim ]->reset();
512 // deselect desabled tab
513 if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
514 setCurrentTab( DIM );
517 //================================================================================
519 * \brief Sets list of available Sets of Hypotheses
521 //================================================================================
523 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
525 QMenu* aHypoSetPopup = myHypoSetButton->menu();
526 if ( !aHypoSetPopup ) {
527 aHypoSetPopup = new QMenu( myHypoSetButton );
528 connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
529 myHypoSetButton->setMenu( aHypoSetPopup );
530 myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
532 aHypoSetPopup->clear();
533 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
534 aHypoSetPopup->addAction( theSets[ i ] );
536 myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
539 //================================================================================
541 * \brief Emits hypoSet signal
543 * SLOT is called when a hypotheses set is selected. Emits hypoSet
544 * signal to notify operation about this event
546 //================================================================================
548 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
550 emit hypoSet( a->text() );
553 //================================================================================
555 * \brief Enable showing of the popup when Geometry selection btn is clicked
556 * \param enable - true to enable
558 //================================================================================
560 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
562 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
564 if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
567 if ( ! myGeomPopup ) {
568 myGeomPopup = new QMenu();
569 myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
570 myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
571 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
572 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
576 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
586 //================================================================================
589 * \param int - tab ID
591 //================================================================================
592 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
593 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
594 if ( theTabId == Dim3D ) myHypoSetButton->setEnabled( false );
597 //================================================================================
600 * \param int - tab ID
602 //================================================================================
603 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
604 myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
605 if ( theTabId == Dim3D ) {
606 QMenu* aHypoSetPopup = myHypoSetButton->menu();
607 myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
611 //================================================================================
613 * \brief Check if tab enabled
614 * \param int - tab ID
616 //================================================================================
617 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const {
618 return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
621 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
623 if ( myGeomPopup && isBtnOn )
624 myGeomPopup->exec( QCursor::pos() );
627 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
629 emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
632 int SMESHGUI_MeshDlg::getActiveObject()
634 for (int i = 0; i < 3; ++i )
635 if ( isObjectShown( i ) &&
636 (( QToolButton* )objectWg( i, Btn ))->isChecked())
640 //================================================================================
642 * \brief Sets available types of mesh
643 * \param theTypeMesh - list of available types of mesh
645 //================================================================================
646 void SMESHGUI_MeshDlg::setAvailableMeshType( const QStringList& theTypeMesh )
649 myMeshType->addItems(theTypeMesh);
651 //================================================================================
653 * \brief Emits selectMeshType( const int, const int ) signal
655 * SLOT is called when a combo box "mesh type" is selected.
657 //================================================================================
658 void SMESHGUI_MeshDlg::onChangedMeshType( const int isIndex )
660 emit selectMeshType( Dim3D - myTabWg->currentIndex(), isIndex );
662 //================================================================================
664 * \brief Get current index types of mesh
666 //================================================================================
667 int SMESHGUI_MeshDlg::currentMeshType( )
669 return myMeshType->currentIndex( );
671 //================================================================================
673 * \brief Set current index types of mesh
675 //================================================================================
676 void SMESHGUI_MeshDlg::setCurrentMeshType( const int theIndex )
678 myMeshType->setCurrentIndex( theIndex );