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>
30 * \brief Tab for tab widget containing controls for definition of
31 * algorithms and hypotheses
34 //================================================================================
37 * \param theParent - Parent widget for this tab
39 * Makes tab's look and feel
41 //================================================================================
42 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
43 : QFrame( theParent ),
46 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
47 QIconSet aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
48 QIconSet aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
51 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
52 myHyp[ Algo ] = new QComboBox( this );
55 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
56 myHyp[ MainHyp ] = new QComboBox( this );
57 myHyp[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
58 myCreateHyp[ MainHyp ] = new QToolButton( this );
59 myCreateHyp[ MainHyp ]->setIconSet( aCreateIcon );
60 myEditHyp[ MainHyp ] = new QToolButton( this );
61 myEditHyp[ MainHyp ]->setIconSet( aEditIcon );
64 QFrame* aLine = new QFrame( this );
65 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
68 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
69 myHyp[ AddHyp ] = new QComboBox( this );
70 myHyp[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
71 myCreateHyp[ AddHyp ] = new QToolButton( this );
72 myCreateHyp[ AddHyp ]->setIconSet( aCreateIcon );
73 myEditHyp[ AddHyp ] = new QToolButton( this );
74 myEditHyp[ AddHyp ]->setIconSet( aEditIcon );
77 QGridLayout* aLay = new QGridLayout( this, 5, 4, 5, 5 );
78 aLay->addWidget( anAlgoLbl, 0, 0 );
79 aLay->addWidget( myHyp[ Algo ], 0, 1 );
80 aLay->addWidget( aHypLbl, 1, 0 );
81 aLay->addWidget( myHyp[ MainHyp ], 1, 1 );
82 aLay->addWidget( myCreateHyp[ MainHyp ], 1, 2 );
83 aLay->addWidget( myEditHyp[ MainHyp ], 1, 3 );
84 aLay->addMultiCellWidget( aLine, 2, 2, 0, 3 );
85 aLay->addWidget( anAddHypLbl, 3, 0 );
86 aLay->addWidget( myHyp[ AddHyp ], 3, 1 );
87 aLay->addWidget( myCreateHyp[ AddHyp ], 3, 2 );
88 aLay->addWidget( myEditHyp[ AddHyp ], 3, 3 );
89 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 4, 0 );
91 // Connect signals and slots
92 for ( int i = MainHyp; i <= AddHyp; i++ )
94 connect( myCreateHyp[ i ], SIGNAL( clicked() ), SLOT( onCreateHyp() ) );
95 connect( myEditHyp[ i ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
96 connect( myHyp[ i ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
99 // Initialize controls
101 setAvailableHyps( Algo, QStringList() );
102 setAvailableHyps( MainHyp, QStringList() );
103 setAvailableHyps( AddHyp, QStringList() );
106 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
112 //================================================================================
114 * \brief Sets available hypothesis or algorithms
115 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
116 * \param theHyps - list of available hypothesis names
118 * Sets available main or additional hypothesis for this tab
120 //================================================================================
121 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
123 myAvailableHyps[ theId ] = theHyps;
126 myHyp[ Algo ]->clear();
127 myHyp[ Algo ]->insertItem( tr( "NONE" ) );
128 myHyp[ Algo ]->insertStringList( theHyps );
129 myHyp[ Algo ]->setCurrentItem( 0 );
133 //================================================================================
135 * \brief Sets existing hypothesis
136 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
137 * \param theHyps - list of available hypothesis names
139 * Sets existing main or additional hypothesis for this tab
141 //================================================================================
142 void SMESHGUI_MeshTab::setExistingHyps( const int theId, const QStringList& theHyps )
146 myHyp[ theId ]->clear();
147 myHyp[ theId ]->insertItem( tr( "NONE" ) );
148 myHyp[ theId ]->insertStringList( theHyps );
149 myHyp[ theId ]->setCurrentItem( 0 );
150 myEditHyp[ theId ]->setEnabled( false );
154 //================================================================================
156 * \brief Adds hypothesis in combo box of available ones
157 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
158 * \param theHyp - name of hypothesis to be added
160 * Adds hypothesis in combo box of available ones. This method is called by operation
161 * after creation of new hypothesis.
163 //================================================================================
164 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
166 myHyp[ theId ]->insertItem( theHyp );
167 myHyp[ theId ]->setCurrentItem( myHyp[ theId ]->count() - 1 );
168 myEditHyp[ theId ]->setEnabled( true );
171 //================================================================================
173 * \brief Renames hypothesis
174 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
175 * \param theIndex - index of hypothesis to be renamed
176 * \param theNewName - new name of hypothesis to be renamed
180 //================================================================================
181 void SMESHGUI_MeshTab::renameHyp( const int theId,
183 const QString& theNewName )
185 if ( theIndex > 0 && theIndex < myHyp[ theId ]->count() )
186 myHyp[ theId ]->changeItem( theNewName, theIndex );
189 //================================================================================
191 * \brief Sets current hypothesis
192 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
193 * \param theIndex - index of hypothesis to be set as current
195 * Sets current hypothesis
197 //================================================================================
198 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
200 if ( theIndex >= 0 && theIndex < myHyp[ theId ]->count() )
202 myHyp[ theId ]->setCurrentItem( theIndex );
203 if ( myEditHyp[ theId ] )
204 myEditHyp[ theId ]->setEnabled( theIndex > 0 );
208 //================================================================================
210 * \brief Gets current hypothesis
211 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
212 * \retval int - index of current hypothesis
214 * Gets current hypothesis
216 //================================================================================
217 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
219 return myHyp[ theId ]->currentItem();
222 //================================================================================
224 * \brief Emits createHyp( const int ) signal
226 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
227 * createHyp( const int ) signal
229 //================================================================================
230 void SMESHGUI_MeshTab::onCreateHyp()
232 const QObject* aSender = sender();
236 myPopup = new QPopupMenu( 0 );
237 connect( myPopup, SIGNAL( activated( int ) ), SLOT( onPopupItem( int ) ) );
240 QStringList aHypNames;
241 if ( aSender == myCreateHyp[ MainHyp ] )
243 aHypNames = myAvailableHyps[ MainHyp ];
244 myPopup->setName( "MainHypPopup" );
248 aHypNames = myAvailableHyps[ AddHyp ];
249 myPopup->setName( "AddHypPopup" );
253 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
254 myPopup->insertItem( aHypNames[ i ], i );
256 myPopup->exec( QCursor::pos() );
259 //================================================================================
261 * \brief Emits editHyp( const int ) signal
263 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
264 * editHyp( const int ) signal
266 //================================================================================
267 void SMESHGUI_MeshTab::onEditHyp()
269 const QObject* aSender = sender();
270 int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
271 emit editHyp( aHypType, myHyp[ aHypType ]->currentItem() );
274 //================================================================================
276 * \brief Updates "Edit hypothesis" button state
278 * SLOT called when current hypothesis changed disables "Edit hypothesis" button
279 * if current hypothesis is <None>, enables otherwise
281 //================================================================================
282 void SMESHGUI_MeshTab::onHyp( int theIndex )
284 const QObject* aSender = sender();
285 int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
286 myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
289 //================================================================================
291 * \brief Emits createHyp signal
293 * SLOT called when item of popup for hypothesis creation is activated. Emits
294 * createHyp signal to notify operation obout this event
296 //================================================================================
297 void SMESHGUI_MeshTab::onPopupItem( int theId )
299 const QObject* aSender = sender();
301 emit createHyp( strcmp( aSender->name(), "MainHypPopup" ) == 0 ? MainHyp : AddHyp, theId );
304 //================================================================================
306 * \brief Resets all tab fields
308 * Resets all tab fields
310 //================================================================================
311 void SMESHGUI_MeshTab::reset()
313 for ( int i = Algo; i <= AddHyp; i++ )
315 myHyp[ i ]->setCurrentItem( 0 );
316 if ( myEditHyp[ i ] )
317 myEditHyp[ i ]->setEnabled( false );
322 * \brief Dialog for mech creation or editing
324 * This dialog is used for mech creation or editing.
327 //================================================================================
330 * \param theToCreate - if this parameter is true then dialog is used for creation,
331 * for editing otherwise
332 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
333 * for sub-mesh otherwise
335 * Makes dialog's look and feel
337 //================================================================================
338 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
339 : SMESHGUI_Dialog( 0, false, true )
341 // Create top controls
343 QGroupBox* aGrp = new QGroupBox( 3, Qt::Horizontal, mainFrame() );
344 aGrp->setFrameStyle( QFrame::NoFrame );
345 aGrp->setInsideMargin( 0 );
347 createObject( tr( "NAME" ), aGrp, Obj );
348 setNameIndication( Obj, OneName );
349 setReadOnly( Obj, false );
351 createObject( tr( "MESH" ), aGrp, Mesh );
353 createObject( tr( "GEOMETRY" ), aGrp, Geom );
357 myTabWg = new QTabWidget( mainFrame() );
358 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
359 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
360 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
361 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
362 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
363 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
367 QVBoxLayout* aLay = new QVBoxLayout( mainFrame(), 0, 5 );
368 aLay->addWidget( aGrp );
369 aLay->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum) );
370 aLay->addWidget( myTabWg );
372 // Disable controls if necessary
373 setObjectShown( Mesh, false );
376 setCaption( tr( "CREATE_MESH" ) );
377 objectWg( Obj, Btn )->hide();
379 setCaption( tr( "CREATE_MESH" ) );
382 setCaption( tr( "CREATE_SUBMESH" ) );
383 setObjectShown( Mesh, true );
388 setCaption( tr( "EDIT_MESH_SUBMESH" ) );
389 objectWg( Mesh, Btn )->hide();
390 objectWg( Geom, Btn )->hide();
394 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
398 //================================================================================
400 * \brief Gets tab with given id
401 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
402 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
405 * Gets tab containing controls for definition of algorithms and AddHypotheses
407 //================================================================================
408 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
410 return ( theId >= Dim1D && theId <= Dim3D ? myTabs[ theId ] : 0 );
413 //================================================================================
415 * \brief Resets all dialog fields
417 //================================================================================
418 void SMESHGUI_MeshDlg::reset()
421 myTabs[ Dim1D ]->reset();
422 myTabs[ Dim2D ]->reset();
423 myTabs[ Dim3D ]->reset();
426 //================================================================================
428 * \brief Sets curent tab
430 //================================================================================
431 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
433 myTabWg->setCurrentPage( theId );