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