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
25 * Copyright (C) 2005 CEA/DEN, EDF R&D
29 * File : SMESHGUI_MeshDlg.cxx
30 * Author : Sergey LITONIN
34 #include "SMESHGUI_MeshDlg.h"
36 #include <SUIT_Session.h>
40 #include <qlineedit.h>
41 #include <qtabwidget.h>
42 #include <qgroupbox.h>
43 #include <qtoolbutton.h>
46 #include <qcombobox.h>
47 #include <qpopupmenu.h>
49 #include <qpushbutton.h>
52 * \brief Tab for tab widget containing controls for definition of
53 * algorithms and hypotheses
56 //================================================================================
59 * \param theParent - Parent widget for this tab
61 * Makes tab's look and feel
63 //================================================================================
64 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
65 : QFrame( theParent ),
68 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
69 QIconSet aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
70 QIconSet aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
73 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
74 myHyp[ Algo ] = new QComboBox( this );
77 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
78 myHyp[ MainHyp ] = new QComboBox( this );
79 myHyp[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
80 myCreateHyp[ MainHyp ] = new QToolButton( this );
81 myCreateHyp[ MainHyp ]->setIconSet( aCreateIcon );
82 myEditHyp[ MainHyp ] = new QToolButton( this );
83 myEditHyp[ MainHyp ]->setIconSet( aEditIcon );
86 QFrame* aLine = new QFrame( this );
87 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
90 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
91 myHyp[ AddHyp ] = new QComboBox( this );
92 myHyp[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
93 myCreateHyp[ AddHyp ] = new QToolButton( this );
94 myCreateHyp[ AddHyp ]->setIconSet( aCreateIcon );
95 myEditHyp[ AddHyp ] = new QToolButton( this );
96 myEditHyp[ AddHyp ]->setIconSet( aEditIcon );
99 QGridLayout* aLay = new QGridLayout( this, 5, 4, 5, 5 );
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->addMultiCellWidget( aLine, 2, 2, 0, 3 );
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 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
135 //================================================================================
137 * \brief Sets available hypothesis or algorithms
138 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
139 * \param theHyps - list of available hypothesis names
141 * Sets available main or additional hypothesis for this tab
143 //================================================================================
144 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
146 myAvailableHyps[ theId ] = theHyps;
148 bool enable = ! theHyps.isEmpty();
151 myHyp[ Algo ]->clear();
152 myHyp[ Algo ]->insertItem( tr( "NONE" ) );
153 myHyp[ Algo ]->insertStringList( theHyps );
154 myHyp[ Algo ]->setCurrentItem( 0 );
157 myCreateHyp[ theId ]->setEnabled( enable );
158 myEditHyp[ theId ]->setEnabled( false );
160 myHyp[ theId ]->setEnabled( enable );
163 //================================================================================
165 * \brief Sets existing hypothesis
166 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
167 * \param theHyps - list of available hypothesis names
169 * Sets existing main or additional hypothesis for this tab
171 //================================================================================
172 void SMESHGUI_MeshTab::setExistingHyps( const int theId, const QStringList& theHyps )
176 myHyp[ theId ]->clear();
177 myHyp[ theId ]->insertItem( tr( "NONE" ) );
178 myHyp[ theId ]->insertStringList( theHyps );
179 myHyp[ theId ]->setCurrentItem( 0 );
180 myHyp[ theId ]->setEnabled( !theHyps.isEmpty() );
181 myEditHyp[ theId ]->setEnabled( false );
185 //================================================================================
187 * \brief Adds hypothesis in combo box of available ones
188 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
189 * \param theHyp - name of hypothesis to be added
191 * Adds hypothesis in combo box of available ones. This method is called by operation
192 * after creation of new hypothesis.
194 //================================================================================
195 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
197 myHyp[ theId ]->insertItem( theHyp );
198 myHyp[ theId ]->setCurrentItem( myHyp[ theId ]->count() - 1 );
199 myEditHyp[ theId ]->setEnabled( true );
200 myHyp[ theId ]->setEnabled( true );
203 //================================================================================
205 * \brief Renames hypothesis
206 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
207 * \param theIndex - index of hypothesis to be renamed
208 * \param theNewName - new name of hypothesis to be renamed
212 //================================================================================
213 void SMESHGUI_MeshTab::renameHyp( const int theId,
215 const QString& theNewName )
217 if ( theIndex > 0 && theIndex < myHyp[ theId ]->count() )
218 myHyp[ theId ]->changeItem( theNewName, theIndex );
221 //================================================================================
223 * \brief Sets current hypothesis
224 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
225 * \param theIndex - index of hypothesis to be set as current
227 * Sets current hypothesis
229 //================================================================================
230 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
232 if ( theIndex >= 0 && theIndex < myHyp[ theId ]->count() )
234 myHyp[ theId ]->setCurrentItem( theIndex );
235 if ( myEditHyp[ theId ] )
236 myEditHyp[ theId ]->setEnabled( theIndex > 0 );
240 //================================================================================
242 * \brief Gets current hypothesis
243 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
244 * \retval int - index of current hypothesis
246 * Gets current hypothesis
248 //================================================================================
249 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
251 return myHyp[ theId ]->currentItem();
254 //================================================================================
256 * \brief Emits createHyp( const int ) signal
258 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
259 * createHyp( const int ) signal
261 //================================================================================
262 void SMESHGUI_MeshTab::onCreateHyp()
264 const QObject* aSender = sender();
268 myPopup = new QPopupMenu( 0 );
269 connect( myPopup, SIGNAL( activated( int ) ), SLOT( onPopupItem( int ) ) );
272 QStringList aHypNames;
273 if ( aSender == myCreateHyp[ MainHyp ] )
275 aHypNames = myAvailableHyps[ MainHyp ];
276 myPopup->setName( "MainHypPopup" );
280 aHypNames = myAvailableHyps[ AddHyp ];
281 myPopup->setName( "AddHypPopup" );
285 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
286 myPopup->insertItem( aHypNames[ i ], i );
288 myPopup->exec( QCursor::pos() );
291 //================================================================================
293 * \brief Emits editHyp( const int ) signal
295 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
296 * editHyp( const int ) signal
298 //================================================================================
299 void SMESHGUI_MeshTab::onEditHyp()
301 const QObject* aSender = sender();
302 int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
303 emit editHyp( aHypType, myHyp[ aHypType ]->currentItem() - 1 ); // - 1 because there is NONE on the top
306 //================================================================================
308 * \brief Updates "Edit hypothesis" button state
310 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
311 * if current hypothesis is <None>, enables otherwise.
312 * If an algorithm changed, emits selectAlgo( theIndex ) signal
314 //================================================================================
315 void SMESHGUI_MeshTab::onHyp( int theIndex )
317 const QObject* aSender = sender();
318 if ( aSender == myHyp[ Algo ] )
319 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
321 int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
322 myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
326 //================================================================================
328 * \brief Emits createHyp signal
330 * SLOT called when item of popup for hypothesis creation is activated. Emits
331 * createHyp signal to notify operation obout this event
333 //================================================================================
334 void SMESHGUI_MeshTab::onPopupItem( int theId )
336 const QObject* aSender = sender();
338 emit createHyp( strcmp( aSender->name(), "MainHypPopup" ) == 0 ? MainHyp : AddHyp, theId );
341 //================================================================================
343 * \brief Resets all tab fields
345 * Resets all tab fields
347 //================================================================================
348 void SMESHGUI_MeshTab::reset()
350 for ( int i = Algo; i <= AddHyp; i++ )
352 myHyp[ i ]->setCurrentItem( 0 );
353 if ( myEditHyp[ i ] )
354 myEditHyp[ i ]->setEnabled( false );
359 * \brief Dialog for mech creation or editing
361 * This dialog is used for mech creation or editing.
364 //================================================================================
367 * \param theToCreate - if this parameter is true then dialog is used for creation,
368 * for editing otherwise
369 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
370 * for sub-mesh otherwise
372 * Makes dialog's look and feel
374 //================================================================================
375 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
376 : SMESHGUI_Dialog( 0, false, true )
378 // Create top controls
380 QGroupBox* aGrp = new QGroupBox( 3, Qt::Horizontal, mainFrame() );
381 aGrp->setFrameStyle( QFrame::NoFrame );
382 aGrp->setInsideMargin( 0 );
384 createObject( tr( "NAME" ), aGrp, Obj );
385 setNameIndication( Obj, OneName );
386 setReadOnly( Obj, false );
388 createObject( tr( "MESH" ), aGrp, Mesh );
390 createObject( tr( "GEOMETRY" ), aGrp, Geom );
395 myTabWg = new QTabWidget( mainFrame() );
396 myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
397 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
398 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
399 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
400 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
401 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
402 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
403 myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
406 myHypoSetPopup = new QPopupMenu();
407 QButton* aHypoSetButton = new QPushButton( mainFrame(), "aHypoSetButton");
408 aHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
411 QVBoxLayout* aLay = new QVBoxLayout( mainFrame(), 0, 5 );
412 aLay->addWidget( aGrp );
413 aLay->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum) );
414 aLay->addWidget( myTabWg );
415 aLay->addWidget( aHypoSetButton );
417 // Disable controls if necessary
418 setObjectShown( Mesh, false );
421 setCaption( tr( "CREATE_MESH" ) );
422 objectWg( Obj, Btn )->hide();
424 setCaption( tr( "CREATE_MESH" ) );
427 setCaption( tr( "CREATE_SUBMESH" ) );
428 setObjectShown( Mesh, true );
433 setCaption( tr( "EDIT_MESH_SUBMESH" ) );
434 objectWg( Mesh, Btn )->hide();
435 objectWg( Geom, Btn )->hide();
438 // Connect signals and slots
439 connect( aHypoSetButton, SIGNAL( clicked() ), SLOT( onHypoSetButton() ) );
440 connect( myHypoSetPopup, SIGNAL( activated( int ) ), SLOT( onHypoSetPopup( int ) ) );
443 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
445 if ( myHypoSetPopup )
446 delete myHypoSetPopup;
449 //================================================================================
451 * \brief Gets tab with given id
452 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
453 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
456 * Gets tab containing controls for definition of algorithms and AddHypotheses
458 //================================================================================
459 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
461 return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
464 //================================================================================
466 * \brief Resets all dialog fields
468 //================================================================================
469 void SMESHGUI_MeshDlg::reset()
472 myTabs[ Dim0D ]->reset();
473 myTabs[ Dim1D ]->reset();
474 myTabs[ Dim2D ]->reset();
475 myTabs[ Dim3D ]->reset();
478 //================================================================================
480 * \brief Sets curent tab
482 //================================================================================
483 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
485 myTabWg->setCurrentPage( Dim3D - theId );
488 //================================================================================
490 * \brief Enable/disable tabs
491 * \param int - maximum possible dimention
493 //================================================================================
495 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
497 const int DIM = maxDim;
498 for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
499 bool enable = ( dim <= DIM );
501 myTabs[ dim ]->reset();
502 myTabWg->setTabEnabled( myTabs[ dim ], enable );
504 // deselect desabled tab
505 if ( !myTabWg->isTabEnabled( myTabWg->currentPage() ))
506 setCurrentTab( DIM - 1 );
509 //================================================================================
511 * \brief Sets list of available Sets of Hypotheses
513 //================================================================================
515 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
517 myHypoSetPopup->clear();
518 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
519 myHypoSetPopup->insertItem( theSets[ i ], i );
523 //================================================================================
525 * \brief Emits hypoSet signal
527 * SLOT is called when a hypotheses set is selected. Emits hypoSet
528 * signal to notify operation about this event
530 //================================================================================
532 void SMESHGUI_MeshDlg::onHypoSetPopup( int theIndex )
534 emit hypoSet( myHypoSetPopup->text( theIndex ));
537 //================================================================================
539 * \brief Shows myHypoSetPopup
541 //================================================================================
543 void SMESHGUI_MeshDlg::onHypoSetButton()
545 myHypoSetPopup->exec( QCursor::pos() );
548 //================================================================================
550 * \brief Enable showing of the popup when Geometry selection btn is clicked
551 * \param enable - true to enable
553 //================================================================================
555 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
557 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
559 if ( QButton* selBtn = dynamic_cast<QButton*>( objectWg( Geom, Btn )))
561 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
563 if ( ! myGeomPopup ) {
564 myGeomPopup = new QPopupMenu();
565 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
566 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
567 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
569 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
575 //================================================================================
578 * \param int - tab ID
580 //================================================================================
581 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
582 myTabWg->setTabEnabled( myTabs[ theTabId ], false );
585 //================================================================================
588 * \param int - tab ID
590 //================================================================================
591 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
592 myTabWg->setTabEnabled( myTabs[ theTabId ], true );
595 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
597 if ( myGeomPopup && isBtnOn )
598 myGeomPopup->exec( QCursor::pos() );
601 void SMESHGUI_MeshDlg::onGeomPopup( int index )
603 emit geomSelectionByMesh( index == GEOM_BY_MESH_INDEX );