4 * Copyright (C) 2005 CEA/DEN, EDF R&D
8 * File : SMESHGUI_MeshDlg.cxx
9 * Author : Sergey LITONIN
13 #include "SMESHGUI_MeshDlg.h"
15 #include <SUIT_Session.h>
19 #include <qlineedit.h>
20 #include <qtabwidget.h>
21 #include <qgroupbox.h>
22 #include <qtoolbutton.h>
25 #include <qcombobox.h>
26 #include <qpopupmenu.h>
28 #include <qpushbutton.h>
31 * \brief Tab for tab widget containing controls for definition of
32 * algorithms and hypotheses
35 //================================================================================
38 * \param theParent - Parent widget for this tab
40 * Makes tab's look and feel
42 //================================================================================
43 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
44 : QFrame( theParent ),
47 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
48 QIconSet aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
49 QIconSet aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
52 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
53 myHyp[ Algo ] = new QComboBox( this );
56 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
57 myHyp[ MainHyp ] = new QComboBox( this );
58 myHyp[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
59 myCreateHyp[ MainHyp ] = new QToolButton( this );
60 myCreateHyp[ MainHyp ]->setIconSet( aCreateIcon );
61 myEditHyp[ MainHyp ] = new QToolButton( this );
62 myEditHyp[ MainHyp ]->setIconSet( aEditIcon );
65 QFrame* aLine = new QFrame( this );
66 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
69 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
70 myHyp[ AddHyp ] = new QComboBox( this );
71 myHyp[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
72 myCreateHyp[ AddHyp ] = new QToolButton( this );
73 myCreateHyp[ AddHyp ]->setIconSet( aCreateIcon );
74 myEditHyp[ AddHyp ] = new QToolButton( this );
75 myEditHyp[ AddHyp ]->setIconSet( aEditIcon );
78 QGridLayout* aLay = new QGridLayout( this, 5, 4, 5, 5 );
79 aLay->addWidget( anAlgoLbl, 0, 0 );
80 aLay->addWidget( myHyp[ Algo ], 0, 1 );
81 aLay->addWidget( aHypLbl, 1, 0 );
82 aLay->addWidget( myHyp[ MainHyp ], 1, 1 );
83 aLay->addWidget( myCreateHyp[ MainHyp ], 1, 2 );
84 aLay->addWidget( myEditHyp[ MainHyp ], 1, 3 );
85 aLay->addMultiCellWidget( aLine, 2, 2, 0, 3 );
86 aLay->addWidget( anAddHypLbl, 3, 0 );
87 aLay->addWidget( myHyp[ AddHyp ], 3, 1 );
88 aLay->addWidget( myCreateHyp[ AddHyp ], 3, 2 );
89 aLay->addWidget( myEditHyp[ AddHyp ], 3, 3 );
90 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 4, 0 );
92 // Connect signals and slots
93 for ( int i = MainHyp; i <= AddHyp; i++ )
95 connect( myCreateHyp[ i ], SIGNAL( clicked() ), SLOT( onCreateHyp() ) );
96 connect( myEditHyp[ i ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
97 connect( myHyp[ i ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
100 // Initialize controls
102 setAvailableHyps( Algo, QStringList() );
103 setAvailableHyps( MainHyp, QStringList() );
104 setAvailableHyps( AddHyp, QStringList() );
107 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
113 //================================================================================
115 * \brief Sets available hypothesis or algorithms
116 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
117 * \param theHyps - list of available hypothesis names
119 * Sets available main or additional hypothesis for this tab
121 //================================================================================
122 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
124 myAvailableHyps[ theId ] = theHyps;
127 myHyp[ Algo ]->clear();
128 myHyp[ Algo ]->insertItem( tr( "NONE" ) );
129 myHyp[ Algo ]->insertStringList( theHyps );
130 myHyp[ Algo ]->setCurrentItem( 0 );
134 //================================================================================
136 * \brief Sets existing hypothesis
137 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
138 * \param theHyps - list of available hypothesis names
140 * Sets existing main or additional hypothesis for this tab
142 //================================================================================
143 void SMESHGUI_MeshTab::setExistingHyps( const int theId, const QStringList& theHyps )
147 myHyp[ theId ]->clear();
148 myHyp[ theId ]->insertItem( tr( "NONE" ) );
149 myHyp[ theId ]->insertStringList( theHyps );
150 myHyp[ theId ]->setCurrentItem( 0 );
151 myEditHyp[ theId ]->setEnabled( false );
155 //================================================================================
157 * \brief Adds hypothesis in combo box of available ones
158 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
159 * \param theHyp - name of hypothesis to be added
161 * Adds hypothesis in combo box of available ones. This method is called by operation
162 * after creation of new hypothesis.
164 //================================================================================
165 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
167 myHyp[ theId ]->insertItem( theHyp );
168 myHyp[ theId ]->setCurrentItem( myHyp[ theId ]->count() - 1 );
169 myEditHyp[ theId ]->setEnabled( true );
172 //================================================================================
174 * \brief Renames hypothesis
175 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
176 * \param theIndex - index of hypothesis to be renamed
177 * \param theNewName - new name of hypothesis to be renamed
181 //================================================================================
182 void SMESHGUI_MeshTab::renameHyp( const int theId,
184 const QString& theNewName )
186 if ( theIndex > 0 && theIndex < myHyp[ theId ]->count() )
187 myHyp[ theId ]->changeItem( theNewName, theIndex );
190 //================================================================================
192 * \brief Sets current hypothesis
193 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
194 * \param theIndex - index of hypothesis to be set as current
196 * Sets current hypothesis
198 //================================================================================
199 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
201 if ( theIndex >= 0 && theIndex < myHyp[ theId ]->count() )
203 myHyp[ theId ]->setCurrentItem( theIndex );
204 if ( myEditHyp[ theId ] )
205 myEditHyp[ theId ]->setEnabled( theIndex > 0 );
209 //================================================================================
211 * \brief Gets current hypothesis
212 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
213 * \retval int - index of current hypothesis
215 * Gets current hypothesis
217 //================================================================================
218 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
220 return myHyp[ theId ]->currentItem();
223 //================================================================================
225 * \brief Emits createHyp( const int ) signal
227 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
228 * createHyp( const int ) signal
230 //================================================================================
231 void SMESHGUI_MeshTab::onCreateHyp()
233 const QObject* aSender = sender();
237 myPopup = new QPopupMenu( 0 );
238 connect( myPopup, SIGNAL( activated( int ) ), SLOT( onPopupItem( int ) ) );
241 QStringList aHypNames;
242 if ( aSender == myCreateHyp[ MainHyp ] )
244 aHypNames = myAvailableHyps[ MainHyp ];
245 myPopup->setName( "MainHypPopup" );
249 aHypNames = myAvailableHyps[ AddHyp ];
250 myPopup->setName( "AddHypPopup" );
254 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
255 myPopup->insertItem( aHypNames[ i ], i );
257 myPopup->exec( QCursor::pos() );
260 //================================================================================
262 * \brief Emits editHyp( const int ) signal
264 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
265 * editHyp( const int ) signal
267 //================================================================================
268 void SMESHGUI_MeshTab::onEditHyp()
270 const QObject* aSender = sender();
271 int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
272 emit editHyp( aHypType, myHyp[ aHypType ]->currentItem() );
275 //================================================================================
277 * \brief Updates "Edit hypothesis" button state
279 * SLOT called when current hypothesis changed disables "Edit hypothesis" button
280 * if current hypothesis is <None>, enables otherwise
282 //================================================================================
283 void SMESHGUI_MeshTab::onHyp( int theIndex )
285 const QObject* aSender = sender();
286 int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
287 myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
290 //================================================================================
292 * \brief Emits createHyp signal
294 * SLOT called when item of popup for hypothesis creation is activated. Emits
295 * createHyp signal to notify operation obout this event
297 //================================================================================
298 void SMESHGUI_MeshTab::onPopupItem( int theId )
300 const QObject* aSender = sender();
302 emit createHyp( strcmp( aSender->name(), "MainHypPopup" ) == 0 ? MainHyp : AddHyp, theId );
305 //================================================================================
307 * \brief Resets all tab fields
309 * Resets all tab fields
311 //================================================================================
312 void SMESHGUI_MeshTab::reset()
314 for ( int i = Algo; i <= AddHyp; i++ )
316 myHyp[ i ]->setCurrentItem( 0 );
317 if ( myEditHyp[ i ] )
318 myEditHyp[ i ]->setEnabled( false );
323 * \brief Dialog for mech creation or editing
325 * This dialog is used for mech creation or editing.
328 //================================================================================
331 * \param theToCreate - if this parameter is true then dialog is used for creation,
332 * for editing otherwise
333 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
334 * for sub-mesh otherwise
336 * Makes dialog's look and feel
338 //================================================================================
339 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
340 : SMESHGUI_Dialog( 0, false, true )
342 // Create top controls
344 QGroupBox* aGrp = new QGroupBox( 3, Qt::Horizontal, mainFrame() );
345 aGrp->setFrameStyle( QFrame::NoFrame );
346 aGrp->setInsideMargin( 0 );
348 createObject( tr( "NAME" ), aGrp, Obj );
349 setNameIndication( Obj, OneName );
350 setReadOnly( Obj, false );
352 createObject( tr( "MESH" ), aGrp, Mesh );
354 createObject( tr( "GEOMETRY" ), aGrp, Geom );
358 myTabWg = new QTabWidget( mainFrame() );
359 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
360 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
361 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
362 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
363 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
364 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
367 myHypoSetPopup = new QPopupMenu();
368 QButton* aHypoSetButton = new QPushButton( mainFrame(), "aHypoSetButton");
369 aHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
372 QVBoxLayout* aLay = new QVBoxLayout( mainFrame(), 0, 5 );
373 aLay->addWidget( aGrp );
374 aLay->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum) );
375 aLay->addWidget( myTabWg );
376 aLay->addWidget( aHypoSetButton );
378 // Disable controls if necessary
379 setObjectShown( Mesh, false );
382 setCaption( tr( "CREATE_MESH" ) );
383 objectWg( Obj, Btn )->hide();
385 setCaption( tr( "CREATE_MESH" ) );
388 setCaption( tr( "CREATE_SUBMESH" ) );
389 setObjectShown( Mesh, true );
394 setCaption( tr( "EDIT_MESH_SUBMESH" ) );
395 objectWg( Mesh, Btn )->hide();
396 objectWg( Geom, Btn )->hide();
399 // Connect signals and slots
400 connect( aHypoSetButton, SIGNAL( clicked() ), SLOT( onHypoSetButton() ) );
401 connect( myHypoSetPopup, SIGNAL( activated( int ) ), SLOT( onHypoSetPopup( int ) ) );
404 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
406 if ( myHypoSetPopup )
407 delete myHypoSetPopup;
410 //================================================================================
412 * \brief Gets tab with given id
413 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
414 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
417 * Gets tab containing controls for definition of algorithms and AddHypotheses
419 //================================================================================
420 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
422 return ( theId >= Dim1D && theId <= Dim3D ? myTabs[ theId ] : 0 );
425 //================================================================================
427 * \brief Resets all dialog fields
429 //================================================================================
430 void SMESHGUI_MeshDlg::reset()
433 myTabs[ Dim1D ]->reset();
434 myTabs[ Dim2D ]->reset();
435 myTabs[ Dim3D ]->reset();
438 //================================================================================
440 * \brief Sets curent tab
442 //================================================================================
443 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
445 myTabWg->setCurrentPage( theId );
448 //================================================================================
450 * \brief Enable/disable tabs
451 * \param int - maximum possible dimention
453 //================================================================================
455 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
457 for ( int i = Dim1D; i <= Dim3D; ++i ) {
459 bool enable = ( dim <= maxDim );
461 myTabs[ i ]->reset();
462 myTabWg->setTabEnabled( myTabs[ i ], enable );
466 //================================================================================
468 * \brief Sets list of available Sets of Hypotheses
470 //================================================================================
472 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
474 myHypoSetPopup->clear();
475 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
476 myHypoSetPopup->insertItem( theSets[ i ], i );
480 //================================================================================
482 * \brief Emits hypoSet signal
484 * SLOT is called when a hypotheses set is selected. Emits hypoSet
485 * signal to notify operation about this event
487 //================================================================================
489 void SMESHGUI_MeshDlg::onHypoSetPopup( int theIndex )
491 emit hypoSet( myHypoSetPopup->text( theIndex ));
494 //================================================================================
496 * \brief Shows myHypoSetPopup
498 //================================================================================
500 void SMESHGUI_MeshDlg::onHypoSetButton()
502 myHypoSetPopup->exec( QCursor::pos() );