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