1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
23 * Copyright (C) 2005 CEA/DEN, EDF R&D
27 * File : SMESHGUI_MeshDlg.cxx
28 * Author : Sergey LITONIN
32 #include "SMESHGUI_MeshDlg.h"
34 #include <SUIT_Session.h>
38 #include <qlineedit.h>
39 #include <qtabwidget.h>
40 #include <qgroupbox.h>
41 #include <qtoolbutton.h>
44 #include <qcombobox.h>
45 #include <qpopupmenu.h>
47 #include <qpushbutton.h>
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 )
63 : QFrame( theParent ),
66 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
67 QIconSet aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
68 QIconSet aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
71 QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
72 myHyp[ Algo ] = new QComboBox( this );
75 QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
76 myHyp[ MainHyp ] = new QComboBox( this );
77 myHyp[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
78 myCreateHyp[ MainHyp ] = new QToolButton( this );
79 myCreateHyp[ MainHyp ]->setIconSet( aCreateIcon );
80 myEditHyp[ MainHyp ] = new QToolButton( this );
81 myEditHyp[ MainHyp ]->setIconSet( aEditIcon );
84 QFrame* aLine = new QFrame( this );
85 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
88 QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
89 myHyp[ AddHyp ] = new QComboBox( this );
90 myHyp[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
91 myCreateHyp[ AddHyp ] = new QToolButton( this );
92 myCreateHyp[ AddHyp ]->setIconSet( aCreateIcon );
93 myEditHyp[ AddHyp ] = new QToolButton( this );
94 myEditHyp[ AddHyp ]->setIconSet( aEditIcon );
97 QGridLayout* aLay = new QGridLayout( this, 5, 4, 5, 5 );
98 aLay->addWidget( anAlgoLbl, 0, 0 );
99 aLay->addWidget( myHyp[ Algo ], 0, 1 );
100 aLay->addWidget( aHypLbl, 1, 0 );
101 aLay->addWidget( myHyp[ MainHyp ], 1, 1 );
102 aLay->addWidget( myCreateHyp[ MainHyp ], 1, 2 );
103 aLay->addWidget( myEditHyp[ MainHyp ], 1, 3 );
104 aLay->addMultiCellWidget( aLine, 2, 2, 0, 3 );
105 aLay->addWidget( anAddHypLbl, 3, 0 );
106 aLay->addWidget( myHyp[ AddHyp ], 3, 1 );
107 aLay->addWidget( myCreateHyp[ AddHyp ], 3, 2 );
108 aLay->addWidget( myEditHyp[ AddHyp ], 3, 3 );
109 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 4, 0 );
111 // Connect signals and slots
112 for ( int i = MainHyp; i <= AddHyp; i++ )
114 connect( myCreateHyp[ i ], SIGNAL( clicked() ), SLOT( onCreateHyp() ) );
115 connect( myEditHyp[ i ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
116 connect( myHyp[ i ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
118 connect( myHyp[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
120 // Initialize controls
122 setAvailableHyps( Algo, QStringList() );
123 setAvailableHyps( MainHyp, QStringList() );
124 setAvailableHyps( AddHyp, QStringList() );
127 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
133 //================================================================================
135 * \brief Sets available hypothesis or algorithms
136 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
137 * \param theHyps - list of available hypothesis names
139 * Sets available main or additional hypothesis for this tab
141 //================================================================================
142 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
144 myAvailableHyps[ theId ] = theHyps;
146 bool enable = ! theHyps.isEmpty();
149 myHyp[ Algo ]->clear();
150 myHyp[ Algo ]->insertItem( tr( "NONE" ) );
151 myHyp[ Algo ]->insertStringList( theHyps );
152 myHyp[ Algo ]->setCurrentItem( 0 );
155 myCreateHyp[ theId ]->setEnabled( enable );
156 myEditHyp[ theId ]->setEnabled( false );
158 myHyp[ theId ]->setEnabled( enable );
161 //================================================================================
163 * \brief Sets existing hypothesis
164 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
165 * \param theHyps - list of available hypothesis names
167 * Sets existing main or additional hypothesis for this tab
169 //================================================================================
170 void SMESHGUI_MeshTab::setExistingHyps( const int theId, const QStringList& theHyps )
174 myHyp[ theId ]->clear();
175 myHyp[ theId ]->insertItem( tr( "NONE" ) );
176 myHyp[ theId ]->insertStringList( theHyps );
177 myHyp[ theId ]->setCurrentItem( 0 );
178 myHyp[ theId ]->setEnabled( !theHyps.isEmpty() );
179 myEditHyp[ theId ]->setEnabled( false );
183 //================================================================================
185 * \brief Adds hypothesis in combo box of available ones
186 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
187 * \param theHyp - name of hypothesis to be added
189 * Adds hypothesis in combo box of available ones. This method is called by operation
190 * after creation of new hypothesis.
192 //================================================================================
193 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
195 myHyp[ theId ]->insertItem( theHyp );
196 myHyp[ theId ]->setCurrentItem( myHyp[ theId ]->count() - 1 );
197 myEditHyp[ theId ]->setEnabled( true );
200 //================================================================================
202 * \brief Renames hypothesis
203 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
204 * \param theIndex - index of hypothesis to be renamed
205 * \param theNewName - new name of hypothesis to be renamed
209 //================================================================================
210 void SMESHGUI_MeshTab::renameHyp( const int theId,
212 const QString& theNewName )
214 if ( theIndex > 0 && theIndex < myHyp[ theId ]->count() )
215 myHyp[ theId ]->changeItem( theNewName, theIndex );
218 //================================================================================
220 * \brief Sets current hypothesis
221 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
222 * \param theIndex - index of hypothesis to be set as current
224 * Sets current hypothesis
226 //================================================================================
227 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
229 if ( theIndex >= 0 && theIndex < myHyp[ theId ]->count() )
231 myHyp[ theId ]->setCurrentItem( theIndex );
232 if ( myEditHyp[ theId ] )
233 myEditHyp[ theId ]->setEnabled( theIndex > 0 );
237 //================================================================================
239 * \brief Gets current hypothesis
240 * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
241 * \retval int - index of current hypothesis
243 * Gets current hypothesis
245 //================================================================================
246 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
248 return myHyp[ theId ]->currentItem();
251 //================================================================================
253 * \brief Emits createHyp( const int ) signal
255 * SLOT called when "Create hypothesis" button clicked specifies sender and emits
256 * createHyp( const int ) signal
258 //================================================================================
259 void SMESHGUI_MeshTab::onCreateHyp()
261 const QObject* aSender = sender();
265 myPopup = new QPopupMenu( 0 );
266 connect( myPopup, SIGNAL( activated( int ) ), SLOT( onPopupItem( int ) ) );
269 QStringList aHypNames;
270 if ( aSender == myCreateHyp[ MainHyp ] )
272 aHypNames = myAvailableHyps[ MainHyp ];
273 myPopup->setName( "MainHypPopup" );
277 aHypNames = myAvailableHyps[ AddHyp ];
278 myPopup->setName( "AddHypPopup" );
282 for ( int i = 0, n = aHypNames.count(); i < n; i++ )
283 myPopup->insertItem( aHypNames[ i ], i );
285 myPopup->exec( QCursor::pos() );
288 //================================================================================
290 * \brief Emits editHyp( const int ) signal
292 * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
293 * editHyp( const int ) signal
295 //================================================================================
296 void SMESHGUI_MeshTab::onEditHyp()
298 const QObject* aSender = sender();
299 int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
300 emit editHyp( aHypType, myHyp[ aHypType ]->currentItem() - 1 ); // - 1 because there is NONE on the top
303 //================================================================================
305 * \brief Updates "Edit hypothesis" button state
307 * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
308 * if current hypothesis is <None>, enables otherwise.
309 * If an algorithm changed, emits selectAlgo( theIndex ) signal
311 //================================================================================
312 void SMESHGUI_MeshTab::onHyp( int theIndex )
314 const QObject* aSender = sender();
315 if ( aSender == myHyp[ Algo ] )
316 emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
318 int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
319 myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
323 //================================================================================
325 * \brief Emits createHyp signal
327 * SLOT called when item of popup for hypothesis creation is activated. Emits
328 * createHyp signal to notify operation obout this event
330 //================================================================================
331 void SMESHGUI_MeshTab::onPopupItem( int theId )
333 const QObject* aSender = sender();
335 emit createHyp( strcmp( aSender->name(), "MainHypPopup" ) == 0 ? MainHyp : AddHyp, theId );
338 //================================================================================
340 * \brief Resets all tab fields
342 * Resets all tab fields
344 //================================================================================
345 void SMESHGUI_MeshTab::reset()
347 for ( int i = Algo; i <= AddHyp; i++ )
349 myHyp[ i ]->setCurrentItem( 0 );
350 if ( myEditHyp[ i ] )
351 myEditHyp[ i ]->setEnabled( false );
356 * \brief Dialog for mech creation or editing
358 * This dialog is used for mech creation or editing.
361 //================================================================================
364 * \param theToCreate - if this parameter is true then dialog is used for creation,
365 * for editing otherwise
366 * \param theIsMesh - if this parameter is true then dialog is used for mesh,
367 * for sub-mesh otherwise
369 * Makes dialog's look and feel
371 //================================================================================
372 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
373 : SMESHGUI_Dialog( 0, false, true )
375 // Create top controls
377 QGroupBox* aGrp = new QGroupBox( 3, Qt::Horizontal, mainFrame() );
378 aGrp->setFrameStyle( QFrame::NoFrame );
379 aGrp->setInsideMargin( 0 );
381 createObject( tr( "NAME" ), aGrp, Obj );
382 setNameIndication( Obj, OneName );
383 setReadOnly( Obj, false );
385 createObject( tr( "MESH" ), aGrp, Mesh );
387 createObject( tr( "GEOMETRY" ), aGrp, Geom );
392 myTabWg = new QTabWidget( mainFrame() );
393 myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
394 myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
395 myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
396 myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
397 myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
398 myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
401 myHypoSetPopup = new QPopupMenu();
402 QButton* aHypoSetButton = new QPushButton( mainFrame(), "aHypoSetButton");
403 aHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
406 QVBoxLayout* aLay = new QVBoxLayout( mainFrame(), 0, 5 );
407 aLay->addWidget( aGrp );
408 aLay->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum) );
409 aLay->addWidget( myTabWg );
410 aLay->addWidget( aHypoSetButton );
412 // Disable controls if necessary
413 setObjectShown( Mesh, false );
416 setCaption( tr( "CREATE_MESH" ) );
417 objectWg( Obj, Btn )->hide();
419 setCaption( tr( "CREATE_MESH" ) );
422 setCaption( tr( "CREATE_SUBMESH" ) );
423 setObjectShown( Mesh, true );
428 setCaption( tr( "EDIT_MESH_SUBMESH" ) );
429 objectWg( Mesh, Btn )->hide();
430 objectWg( Geom, Btn )->hide();
433 // Connect signals and slots
434 connect( aHypoSetButton, SIGNAL( clicked() ), SLOT( onHypoSetButton() ) );
435 connect( myHypoSetPopup, SIGNAL( activated( int ) ), SLOT( onHypoSetPopup( int ) ) );
438 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
440 if ( myHypoSetPopup )
441 delete myHypoSetPopup;
444 //================================================================================
446 * \brief Gets tab with given id
447 * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
448 * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is
451 * Gets tab containing controls for definition of algorithms and AddHypotheses
453 //================================================================================
454 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
456 return ( theId >= Dim1D && theId <= Dim3D ? myTabs[ theId ] : 0 );
459 //================================================================================
461 * \brief Resets all dialog fields
463 //================================================================================
464 void SMESHGUI_MeshDlg::reset()
467 myTabs[ Dim1D ]->reset();
468 myTabs[ Dim2D ]->reset();
469 myTabs[ Dim3D ]->reset();
472 //================================================================================
474 * \brief Sets curent tab
476 //================================================================================
477 void SMESHGUI_MeshDlg::setCurrentTab( const int theId )
479 myTabWg->setCurrentPage( Dim3D - theId );
482 //================================================================================
484 * \brief Enable/disable tabs
485 * \param int - maximum possible dimention
487 //================================================================================
489 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
491 for ( int i = Dim1D; i <= Dim3D; ++i ) {
493 bool enable = ( dim <= maxDim );
495 myTabs[ i ]->reset();
496 if ( myTabs[ i ] == myTabWg->currentPage() && i != Dim1D)
497 // deselect desebled tab
498 myTabWg->setCurrentPage( i - 1 );
500 myTabWg->setTabEnabled( myTabs[ i ], enable );
504 //================================================================================
506 * \brief Sets list of available Sets of Hypotheses
508 //================================================================================
510 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
512 myHypoSetPopup->clear();
513 for ( int i = 0, n = theSets.count(); i < n; i++ ) {
514 myHypoSetPopup->insertItem( theSets[ i ], i );
518 //================================================================================
520 * \brief Emits hypoSet signal
522 * SLOT is called when a hypotheses set is selected. Emits hypoSet
523 * signal to notify operation about this event
525 //================================================================================
527 void SMESHGUI_MeshDlg::onHypoSetPopup( int theIndex )
529 emit hypoSet( myHypoSetPopup->text( theIndex ));
532 //================================================================================
534 * \brief Shows myHypoSetPopup
536 //================================================================================
538 void SMESHGUI_MeshDlg::onHypoSetButton()
540 myHypoSetPopup->exec( QCursor::pos() );
543 //================================================================================
545 * \brief Enable showing of the popup when Geometry selection btn is clicked
546 * \param enable - true to enable
548 //================================================================================
550 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
552 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
554 if ( QButton* selBtn = dynamic_cast<QButton*>( objectWg( Geom, Btn )))
556 disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
558 if ( ! myGeomPopup ) {
559 myGeomPopup = new QPopupMenu();
560 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
561 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
562 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
564 connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
569 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
571 if ( myGeomPopup && isBtnOn )
572 myGeomPopup->exec( QCursor::pos() );
575 void SMESHGUI_MeshDlg::onGeomPopup( int index )
577 emit geomSelectionByMesh( index == GEOM_BY_MESH_INDEX );