Salome HOME
22483: EDF 2772 SMESH: Define several 3D viscous layer hypotheses on the same Geometry
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_MeshDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_MeshDlg.h"
29
30 // SALOME GUI includes
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33
34 // Qt includes
35 #include <QComboBox>
36 #include <QCursor>
37 #include <QGridLayout>
38 #include <QGroupBox>
39 #include <QLabel>
40 #include <QListWidget>
41 #include <QMenu>
42 #include <QPushButton>
43 #include <QTabWidget>
44 #include <QToolButton>
45 #include <QVBoxLayout>
46
47 #include <Standard_Integer.hxx>
48
49 #define SPACING 6
50 #define MARGIN  11
51
52 /*!
53  * \brief Tab for tab widget containing controls for definition of 
54  * algorithms and hypotheses
55 */ 
56
57 //================================================================================
58 /*!
59  * \brief Constructor
60   * \param theParent - Parent widget for this tab
61  * 
62  * Makes tab's look and feel
63  */
64 //================================================================================ 
65 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
66   : QFrame( theParent )
67 {
68   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
69   QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
70   QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
71   QIcon aPlusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_PLUS" ) ) );
72   QIcon aMinusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_MINUS" ) ) );
73   
74   // Algorifm
75   QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
76   myHypCombo[ Algo ] = new QComboBox( this );
77   
78   // Hypothesis
79   QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
80   myHypCombo[ MainHyp ] = new QComboBox( this );
81   myHypCombo[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
82   myCreateHypBtn[ MainHyp ] = new QToolButton( this );
83   myCreateHypBtn[ MainHyp ]->setIcon( aCreateIcon );
84   myEditHypBtn[ MainHyp ] = new QToolButton( this );
85   myEditHypBtn[ MainHyp ]->setIcon( aEditIcon );
86
87   // Line
88   QFrame* aLine = new QFrame( this );
89   aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
90
91   // Add. hypothesis
92   QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
93   myHypCombo[ AddHyp ] = new QComboBox( this );
94   myHypCombo[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
95   myCreateHypBtn[ AddHyp ] = new QToolButton( this );
96   myCreateHypBtn[ AddHyp ]->setIcon( aCreateIcon );
97   myEditHypBtn[ AddHyp ] = new QToolButton( this );
98   myEditHypBtn[ AddHyp ]->setIcon( aEditIcon );
99   myEditHypBtn[ MoreAddHyp ] = new QToolButton( this );
100   myEditHypBtn[ MoreAddHyp ]->setIcon( aEditIcon );
101
102   myAddHypList = new QListWidget( this );
103   myMoreAddHypBtn = new QToolButton( this );
104   myMoreAddHypBtn->setIcon( aPlusIcon );
105   myLessAddHypBtn = new QToolButton( this );
106   myLessAddHypBtn->setIcon( aMinusIcon );
107
108   // Fill layout
109   QGridLayout* aLay = new QGridLayout( this );
110   aLay->setMargin( MARGIN );
111   aLay->setSpacing( SPACING );
112
113   aLay->addWidget( anAlgoLbl, 0, 0 );
114   aLay->addWidget( myHypCombo[ Algo ], 0, 1 );
115   aLay->addWidget( aHypLbl, 1, 0 );
116   aLay->addWidget( myHypCombo[ MainHyp ], 1, 1 );
117   aLay->addWidget( myCreateHypBtn[ MainHyp ], 1, 2 );
118   aLay->addWidget( myEditHypBtn[ MainHyp ], 1, 3 );
119   aLay->addWidget( aLine, 2, 0, 1, 4 );
120   aLay->addWidget( anAddHypLbl, 3, 0 );
121   aLay->addWidget( myHypCombo[ AddHyp ], 3, 1 );
122   aLay->addWidget( myCreateHypBtn[ AddHyp ], 3, 2 );
123   aLay->addWidget( myEditHypBtn[ AddHyp ], 3, 3 );
124   aLay->addWidget( myAddHypList, 4, 1, 2, 1 );
125   aLay->addWidget( myMoreAddHypBtn, 4, 2 );
126   aLay->addWidget( myEditHypBtn[ MoreAddHyp ], 4, 3 );
127   aLay->addWidget( myLessAddHypBtn, 5, 2 );
128   aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 6, 0 );
129
130   // Connect signals and slots
131   for ( int i = MainHyp; i <= AddHyp; i++ )
132   {
133     connect( myCreateHypBtn[ i ], SIGNAL( clicked() )       ,  SLOT( onCreateHyp() ) );
134     connect( myEditHypBtn[ i ]  , SIGNAL( clicked() )       ,  SLOT( onEditHyp() ) );
135     connect( myHypCombo[ i ]    , SIGNAL( activated( int ) ),  SLOT( onHyp( int ) ) );
136   }
137   connect( myHypCombo[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
138
139   connect( myAddHypList, SIGNAL( currentRowChanged( int ) ), SLOT( onHyp( int ) ) );
140   connect( myEditHypBtn[ MoreAddHyp ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
141   connect( myMoreAddHypBtn, SIGNAL( clicked() ), SLOT( onMoreAddHyp() ));
142   connect( myLessAddHypBtn, SIGNAL( clicked() ), SLOT( onLessAddHyp() ));
143
144   // Initialize controls
145
146   setAvailableHyps( Algo, QStringList() );
147   setAvailableHyps( MainHyp, QStringList() );
148   setAvailableHyps( AddHyp, QStringList() );
149 }
150
151 //================================================================================
152 /*!
153  * \brief Destructor
154  */
155 //================================================================================ 
156 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
157 {
158 }
159
160 //================================================================================
161 /*!
162  * \brief Adds an item in a control corresponding to \a type
163  *  \param [in] txt - item text
164  *  \param [in] type - HypType
165  *  \param [in] index - index of item in a list of items
166  */
167 //================================================================================
168
169 void SMESHGUI_MeshTab::addItem( const QString& txt, const int type, const int index )
170 {
171   if ( type <= AddHyp )
172   {
173     myHypCombo[ type ]->addItem( txt, QVariant( index ));
174   }
175   else
176   {
177     QListWidgetItem* item = new QListWidgetItem( txt, myAddHypList );
178     item->setData( Qt::UserRole, QVariant( index ));
179   }
180 }
181
182 //================================================================================
183 /*!
184  * \brief Returns index of hyp of a given type
185  */
186 //================================================================================
187
188 int SMESHGUI_MeshTab::getCurrentIndex( const int type, const bool curByType ) const
189 {
190   if ( type <= AddHyp )
191   {
192     return myHypCombo[ type ]->itemData( myHypCombo[ type ]->currentIndex() ).toInt();
193   }
194   else
195   {
196     int row = curByType ? ( type - AddHyp - 1 ) : myAddHypList->currentRow();
197     if ( QListWidgetItem* item = myAddHypList->item( row ))
198       return item->data( Qt::UserRole ).toInt();
199   }
200   return -1;
201 }
202
203 //================================================================================
204 /*!
205  * \brief Sets available hypothesis or algorithms
206   * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
207   * \param theHyps - list of available hypothesis names
208  * 
209  * Sets available main or additional hypothesis for this tab
210  */
211 //================================================================================
212 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
213 {
214   myAvailableHypTypes[ theId ] = theHyps;
215
216   bool enable = ! theHyps.isEmpty();
217   if ( theId == Algo ) // fill list of algos
218   {
219     myHypCombo[ Algo ]->clear();
220     if ( enable )
221     {
222       addItem( tr( "NONE"), Algo, 0 );
223       for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
224         addItem( theHyps[i], Algo, i+1 );
225       myHypCombo[ Algo ]->setCurrentIndex( 0 );
226     }
227   }
228   else // enable buttons
229   {
230     myCreateHypBtn[ theId ]->setEnabled( enable );
231     myEditHypBtn  [ theId ]->setEnabled( false );
232   }
233   myHypCombo[ theId ]->setEnabled( enable );
234 }
235
236 //================================================================================
237 /*!
238  * \brief Sets existing hypothesis
239  * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
240  * \param theHyps - list of available hypothesis names
241  * \param theDefaultAvlbl - \c true means that the algorithm can work w/o hypothesis
242  *                          with some default parameters
243  *
244  * Sets existing main or additional hypothesis for this tab
245  */
246 //================================================================================
247 void SMESHGUI_MeshTab::setExistingHyps( const int          theId,
248                                         const QStringList& theHyps,
249                                         bool               theDefaultAvlbl)
250 {
251   if ( theId != Algo )
252   {
253     bool enable = ! myAvailableHypTypes[ theId ].isEmpty();
254     myHypCombo[ theId ]->clear();
255     if ( enable )
256     {
257       QString none = tr( theDefaultAvlbl ? "DEFAULT" : ( theId == AddHyp ) ? "NONE" : "NONE" );
258       addItem( none, theId, 0 );
259       for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
260         addItem( theHyps[i], theId, i+1 );
261       myHypCombo[ theId ]->setCurrentIndex( 0 );
262     }
263     myHypCombo  [ theId ]->setEnabled( enable );
264     myEditHypBtn[ theId ]->setEnabled( false );
265     if ( theId == AddHyp )
266     {
267       myAddHypList->clear();
268       myEditHypBtn[ MoreAddHyp ]->setEnabled( false );
269       myMoreAddHypBtn->setEnabled( false );
270       myLessAddHypBtn->setEnabled( false );
271     }
272   }
273 }
274
275 //================================================================================
276 /*!
277  * \brief Adds hypothesis in combo box of available ones
278  * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
279  * \param theHyp - name of hypothesis to be added
280  *
281  * Adds hypothesis in combo box of available ones. This method is called by operation
282  * after creation of new hypothesis.
283  */
284 //================================================================================
285 void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
286 {
287   int index = myHypCombo[ theId ]->count();
288   if ( theId == AddHyp )
289     index += myAddHypList->count();
290   addItem( theHyp, theId, index );
291   myHypCombo[ theId ]->setCurrentIndex( myHypCombo[ theId ]->count() - 1 );
292   myEditHypBtn[ theId ]->setEnabled( true );
293   myHypCombo[ theId ]->setEnabled( true );
294   if ( theId == AddHyp )
295     myMoreAddHypBtn->setEnabled( true );
296 }
297
298 //================================================================================
299 /*!
300  * \brief Renames hypothesis
301  * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
302  * \param theIndex - index of hypothesis to be renamed
303  * \param theNewName - new name of hypothesis to be renamed
304  *
305  * Renames hypothesis
306  */
307 //================================================================================
308 // void SMESHGUI_MeshTab::renameHyp( const int theId,
309 //                                   const int theIndex,
310 //                                   const QString& theNewName )
311 // {
312 //   if ( theIndex > 0 && theIndex < myHypCombo[ theId ]->count() )
313 //     myHypCombo[ theId ]->setItemText( theIndex, theNewName );
314 // }
315
316 //================================================================================
317 /*!
318  * \brief Sets current hypothesis
319  * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
320  * \param theIndex - index of hypothesis to be set as current
321  *
322  * Sets current hypothesis
323  */
324 //================================================================================
325 void SMESHGUI_MeshTab::setCurrentHyp( const int theId, const int theIndex )
326 {
327   if ( theId <= AddHyp )
328   {
329     if ( theIndex >= 0 && theIndex < myHypCombo[ theId ]->count() )
330     {
331       myHypCombo[ theId ]->setCurrentIndex( theIndex );
332       if ( myEditHypBtn[ theId ] )
333         myEditHypBtn[ theId ]->setEnabled( theIndex > 0 );
334       if ( theId == AddHyp )
335         myMoreAddHypBtn      ->setEnabled( theIndex > 0 );
336     }
337   }
338   else // more than one additional hyp assigned
339   {
340     // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
341     for ( int i = 1, nb = myHypCombo[ AddHyp ]->count(); i < nb; ++i )
342     {
343       int curIndex = myHypCombo[ AddHyp ]->itemData( i ).toInt();
344       if ( theIndex == curIndex )
345       {
346         addItem( myHypCombo[ AddHyp ]->itemText( i ), theId, theIndex );
347         myHypCombo[ AddHyp ]->removeItem( i );
348         break;
349       }
350     }
351   }
352 }
353
354 //================================================================================
355 /*!
356  * \brief Gets current hypothesis
357   * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
358   * \retval int - index of current hypothesis
359  * 
360  * Gets current hypothesis
361  * Use theId > AddHyp to get more than selected addetional hyps (see nbAddHypTypes()).
362  */
363 //================================================================================
364 int SMESHGUI_MeshTab::currentHyp( const int theId ) const
365 {
366   return getCurrentIndex( theId, /*curByType=*/true );
367 }
368
369 //================================================================================
370 /*!
371  * \brief Returns nb of selected supplementary additional hypotheses
372  * 
373  * Access to their indices is via currentHyp( AddHyp + i ) where i is within the
374  * range 0 <= i < this->nbAddHypTypes()
375  */
376 //================================================================================
377
378 int SMESHGUI_MeshTab::nbAddHypTypes() const
379 {
380   return myAddHypList->count();
381 }
382
383 //================================================================================
384 /*!
385  * \brief Emits createHyp( const int ) signal
386  * 
387  * SLOT called when "Create hypothesis" button clicked specifies sender and emits
388  * createHyp( const int ) signal
389  */
390 //================================================================================
391 void SMESHGUI_MeshTab::onCreateHyp()
392 {
393   bool isMainHyp = ( sender() == myCreateHypBtn[ MainHyp ]);
394
395   QMenu aPopup( this );
396   
397   QStringList aHypNames = isMainHyp ? 
398     myAvailableHypTypes[ MainHyp ] : myAvailableHypTypes[ AddHyp ];
399
400   QList<QAction*> actions;
401   for ( int i = 0, n = aHypNames.count(); i < n; i++ )
402     actions.append( aPopup.addAction( aHypNames[ i ] ) );
403
404   QAction* a = aPopup.exec( QCursor::pos() );
405   if ( a )
406     emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
407 }
408
409 //================================================================================
410 /*!
411  * \brief Emits editHyp( const int ) signal
412  * 
413  * SLOT called when "Edit hypothesis" button clicked specifies sender and emits
414  * editHyp( const int ) signal
415  */
416 //================================================================================
417 void SMESHGUI_MeshTab::onEditHyp()
418 {
419   const QObject* aSender = sender();
420   int aHypType = MainHyp;
421   for ( ; aHypType <= MoreAddHyp; ++aHypType )
422     if ( aSender == myEditHypBtn[ aHypType ])
423       break;
424   emit editHyp( Min( aHypType, AddHyp ),
425                 getCurrentIndex( aHypType ) - 1 );  // - 1 because there is NONE on the top
426 }
427
428 //================================================================================
429 /*!
430  * \brief Updates "Edit hypothesis" button state
431  * 
432  * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
433  * if current hypothesis is <None>, enables otherwise.
434  * If an algorithm changed, emits selectAlgo( theIndex ) signal
435  */
436 //================================================================================
437 void SMESHGUI_MeshTab::onHyp( int theIndex )
438 {
439   const QObject* aSender = sender();
440   if ( aSender == myHypCombo[ Algo ] )
441   {
442     emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
443   }
444   else if ( aSender == myAddHypList )
445   {
446     myEditHypBtn[ MoreAddHyp ]->setEnabled( theIndex >= 0 );
447     myLessAddHypBtn           ->setEnabled( theIndex >= 0 );
448   }
449   else
450   {
451     int type = ( aSender == myHypCombo[ MainHyp ] ? MainHyp : AddHyp );
452     myEditHypBtn[ type ]->setEnabled( theIndex > 0 );
453
454     if ( type == AddHyp )
455       myMoreAddHypBtn   ->setEnabled( theIndex > 0 );
456   }
457 }
458
459 //================================================================================
460 /*!
461  * \brief Adds a current additional hyp to myAddHypList
462  * 
463  * SLOT called when myMoreAddHypBtn ("plus") clicked
464  */
465 //================================================================================
466
467 void SMESHGUI_MeshTab::onMoreAddHyp()
468 {
469   int hypIndex = currentHyp( AddHyp );
470   if ( hypIndex > 0 )
471   {
472     // move a hyp from myHypCombo[ AddHyp ] to myAddHypList
473     int comboIndex = myHypCombo[ AddHyp ]->currentIndex();
474     addItem( myHypCombo[ AddHyp ]->itemText( comboIndex ), MoreAddHyp, hypIndex );
475
476     myHypCombo[ AddHyp ]->removeItem( comboIndex );
477     myHypCombo[ AddHyp ]->setCurrentIndex( 0 );
478
479     myMoreAddHypBtn->setEnabled( false );
480     myEditHypBtn[ AddHyp ]->setEnabled( false );
481   }
482 }
483
484 //================================================================================
485 /*!
486  * \brief Removes a current additional hyp from myAddHypList
487  * 
488  * SLOT called when myLessAddHypBtn ("minus") clicked
489  */
490 //================================================================================
491
492 void SMESHGUI_MeshTab::onLessAddHyp()
493 {
494   if ( QListWidgetItem * item = myAddHypList->currentItem() )
495   {
496     // move a hyp from myAddHypList to myHypCombo[ AddHyp ]
497     int hypIndex = item->data( Qt::UserRole ).toInt();
498     addItem( item->text(), AddHyp, hypIndex );
499     delete item;//myAddHypList->takeItem( myAddHypList->currentRow() );
500   }
501 }
502
503 //================================================================================
504 /*!
505  * \brief Resets all tab fields
506  *
507  * Resets all tab fields
508  */
509 //================================================================================
510 void SMESHGUI_MeshTab::reset()
511 {
512   for ( int i = Algo; i <= AddHyp; i++ )
513   {
514     myHypCombo[ i ]->setCurrentIndex( 0 );
515     if ( myEditHypBtn[ i ] )
516       myEditHypBtn[ i ]->setEnabled( false );
517   }
518 }
519
520 /*!
521  * \brief Dialog for mech creation or editing
522  *
523  *  This dialog is used for mech creation or editing. 
524 */
525
526 //================================================================================
527 /*!
528  * \brief Constructor
529   * \param theToCreate - if this parameter is true then dialog is used for creation,
530   * for editing otherwise
531   * \param theIsMesh - if this parameter is true then dialog is used for mesh,
532   * for sub-mesh otherwise
533  * 
534  * Makes dialog's look and feel
535  */
536 //================================================================================
537 SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh )
538 : SMESHGUI_Dialog( 0, false, true )
539 {
540   // Create top controls
541
542   setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
543   // name 
544   createObject( tr( "NAME" ), mainFrame(), Obj );
545   setNameIndication( Obj, OneName );
546   setReadOnly( Obj, false );
547   // mesh
548   createObject( tr( "MESH" ), mainFrame(), Mesh );
549   // geometry
550   createObject( tr( "GEOMETRY" ), mainFrame(), Geom );
551   myGeomPopup = 0;
552   // mesh type
553   QLabel* anMeshTypeLbl = new QLabel( tr( "MESH_TYPE" ), this );
554   myMeshType = new QComboBox( this );
555   
556   // Create tab widget
557   
558   myTabWg = new QTabWidget( mainFrame() );
559   myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
560   myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
561   myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
562   myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
563   myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
564   myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
565   myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
566   myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
567
568   // Hypotheses Sets
569   myHypoSetButton = new QToolButton( mainFrame() );
570   myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
571   myHypoSetButton->setEnabled( false );
572   myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding, 
573                                   myHypoSetButton->sizePolicy().verticalPolicy() );
574   
575   // Fill layout
576   QGridLayout* aLay = new QGridLayout( mainFrame() );
577   aLay->setMargin( 0 );
578   aLay->setSpacing( SPACING );
579
580   aLay->addWidget( objectWg( Obj,  Label ),   0, 0 );
581   aLay->addWidget( objectWg( Obj,  Btn ),     0, 1 );
582   aLay->addWidget( objectWg( Obj,  Control ), 0, 2 );
583   aLay->addWidget( objectWg( Mesh, Label ),   1, 0 );
584   aLay->addWidget( objectWg( Mesh, Btn ),     1, 1 );
585   aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
586   aLay->addWidget( objectWg( Geom, Label ),   2, 0 );
587   aLay->addWidget( objectWg( Geom, Btn ),     2, 1 );
588   aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
589   aLay->addWidget( anMeshTypeLbl,             3, 0 );
590   aLay->addWidget( myMeshType,                3, 2 );
591   aLay->addWidget( myTabWg,                   5, 0, 1, 3 );
592   aLay->addWidget( myHypoSetButton,           6, 0, 1, 3 );
593   aLay->setRowMinimumHeight( 3, 20 );
594
595   myMeshType->clear();
596
597   // Connect signals and slots
598   connect( myMeshType, SIGNAL( activated( int ) ), SLOT( onChangedMeshType( int ) ) );
599   // Disable controls if necessary
600   setObjectShown( Mesh, false );
601   if ( theToCreate )
602   {
603     setWindowTitle( tr( "CREATE_MESH" ) );
604     objectWg( Obj, Btn )->hide();
605     if ( theIsMesh )
606       setWindowTitle( tr( "CREATE_MESH" ) );
607     else
608     {
609       setWindowTitle( tr( "CREATE_SUBMESH" ) );
610       setObjectShown( Mesh, true );
611     }
612   }
613   else
614   {
615     setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
616     objectWg( Mesh, Btn )->hide();
617     objectWg( Geom, Btn )->hide();
618   }
619 }
620
621 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
622 {
623 }
624
625 //================================================================================
626 /*!
627  * \brief Gets tab with given id
628   * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
629   * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is 
630   * invalid
631  * 
632  * Gets tab containing controls for definition of algorithms and AddHypotheses
633  */
634 //================================================================================
635 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
636 {
637   return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
638 }
639
640 //================================================================================
641 /*!
642  * \brief Resets all dialog fields
643  */
644 //================================================================================  
645 void SMESHGUI_MeshDlg::reset()
646 {
647   clearSelection();
648   myTabs[ Dim0D ]->reset();
649   myTabs[ Dim1D ]->reset();
650   myTabs[ Dim2D ]->reset();
651   myTabs[ Dim3D ]->reset();
652 }
653
654 //================================================================================
655 /*!
656  * \brief Sets curent tab
657  */
658 //================================================================================    
659 void SMESHGUI_MeshDlg::setCurrentTab( const int theId  )
660 {
661   myTabWg->setCurrentIndex( Dim3D - theId );
662 }
663
664 //================================================================================
665 /*!
666  * \brief Enable/disable tabs
667   * \param int - maximum possible dimention
668  */
669 //================================================================================
670
671 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
672 {
673   const int DIM = maxDim;
674   for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
675     bool enable = ( dim <= DIM );
676     if ( !enable ) {
677       myTabs[ dim ]->reset();
678       disableTab( dim );
679     }
680     else {
681       enableTab( dim );
682     }
683   }
684   // deselect desabled tab
685   if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
686     setCurrentTab( DIM );
687 }
688
689 //================================================================================
690 /*!
691  * \brief Sets list of available Sets of Hypotheses
692  */
693 //================================================================================
694
695 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
696 {
697   QMenu* aHypoSetPopup = myHypoSetButton->menu();
698   if ( !aHypoSetPopup ) {
699     aHypoSetPopup = new QMenu( myHypoSetButton );
700     connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
701     myHypoSetButton->setMenu( aHypoSetPopup );
702     myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
703   }
704   aHypoSetPopup->clear();
705   for ( int i = 0, n = theSets.count(); i < n; i++ ) {
706     aHypoSetPopup->addAction( theSets[ i ] );
707   }
708   myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
709 }
710
711 //================================================================================
712 /*!
713  * \brief Emits hypoSet signal
714  * 
715  * SLOT is called when a hypotheses set is selected. Emits hypoSet
716  * signal to notify operation about this event
717  */
718 //================================================================================
719
720 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
721 {
722   emit hypoSet( a->text() );
723 }
724   
725 //================================================================================
726 /*!
727  * \brief Enable showing of the popup when Geometry selection btn is clicked
728   * \param enable - true to enable
729  */
730 //================================================================================
731
732 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
733
734 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
735 {
736   if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
737   {
738     if ( enable ) {
739       if ( ! myGeomPopup ) {
740         myGeomPopup = new QMenu();
741         myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
742         myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
743         connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
744         connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
745       }
746     }
747     else {
748       disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
749       if ( myGeomPopup ) {
750         delete myGeomPopup;
751         myGeomPopup = 0;
752       }
753     }
754   }
755 }
756
757
758 //================================================================================
759 /*!
760  * \brief Disable tab
761  * \param int - tab ID
762  */
763 //================================================================================
764 void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
765   myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
766   if ( theTabId == Dim3D ) myHypoSetButton->setEnabled( false );
767 }
768
769 //================================================================================
770 /*!
771  * \brief Enable tabs
772  * \param int - tab ID
773  */
774 //================================================================================
775 void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
776   myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
777   if ( theTabId == Dim3D ) {
778     QMenu* aHypoSetPopup = myHypoSetButton->menu();
779     myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
780   }
781 }
782
783 //================================================================================
784 /*!
785  * \brief Check if tab enabled
786  * \param int - tab ID
787  */
788 //================================================================================
789 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const {
790   return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
791 }
792
793 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
794 {
795   if ( myGeomPopup && isBtnOn )
796     myGeomPopup->exec( QCursor::pos() );
797 }
798
799 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
800 {
801   emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
802 }
803
804 int SMESHGUI_MeshDlg::getActiveObject()
805 {
806   for (int i = 0; i < 3; ++i )
807     if ( isObjectShown( i ) &&
808          (( QToolButton* )objectWg( i, Btn ))->isChecked())
809       return i;
810   return -1;
811 }
812 //================================================================================
813 /*!
814  * \brief Sets available types of mesh
815  * \param theTypeMesh - list of available types of mesh
816  */
817 //================================================================================
818 void SMESHGUI_MeshDlg::setAvailableMeshType( const QStringList& theTypeMesh )
819 {
820   myMeshType->clear();
821   myMeshType->addItems(theTypeMesh);
822 }
823 //================================================================================
824 /*!
825  * \brief Emits selectMeshType( const int, const int ) signal
826  *
827  * SLOT is called when a combo box "mesh type" is selected.
828  */
829 //================================================================================
830 void SMESHGUI_MeshDlg::onChangedMeshType( const int isIndex )
831 {
832   emit selectMeshType( Dim3D - myTabWg->currentIndex(), isIndex );
833 }
834 //================================================================================
835 /*!
836  * \brief Get current index types of mesh
837  */
838 //================================================================================
839 int SMESHGUI_MeshDlg::currentMeshType( )
840 {
841   return myMeshType->currentIndex( );
842 }
843 //================================================================================
844 /*!
845  * \brief Set current index types of mesh
846  */
847 //================================================================================
848 void SMESHGUI_MeshDlg::setCurrentMeshType( const int theIndex )
849 {
850   myMeshType->setCurrentIndex( theIndex );
851 }