Salome HOME
Copyright update 2020
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshDlg.cxx
1 // Copyright (C) 2007-2020  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 #include <QtxToolButton.h>
35
36 // Qt includes
37 #include <QCheckBox>
38 #include <QComboBox>
39 #include <QCursor>
40 #include <QGridLayout>
41 #include <QGroupBox>
42 #include <QLabel>
43 #include <QListWidget>
44 #include <QMenu>
45 #include <QPushButton>
46 #include <QTabWidget>
47 #include <QToolButton>
48 #include <QVBoxLayout>
49
50 #include <Standard_Integer.hxx>
51
52 #define SPACING 6
53 #define MARGIN  11
54
55 /*!
56  * \brief Tab for tab widget containing controls for definition of 
57  * algorithms and hypotheses
58 */ 
59
60 //================================================================================
61 /*!
62  * \brief Constructor
63   * \param theParent - Parent widget for this tab
64  * 
65  * Makes tab's look and feel
66  */
67 //================================================================================ 
68 SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
69   : QFrame( theParent )
70 {
71   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
72   QIcon aCreateIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO" ) ) );
73   QIcon aEditIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_HYPO_EDIT" ) ) );
74   QIcon aPlusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_PLUS" ) ) );
75   QIcon aMinusIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_MINUS" ) ) );
76   
77   // Algorifm
78   QLabel* anAlgoLbl = new QLabel( tr( "ALGORITHM" ), this );
79   myHypCombo[ Algo ] = new QtxToolButton( this );
80   
81   // Hypothesis
82   QLabel* aHypLbl = new QLabel( tr( "HYPOTHESIS" ), this );
83   myHypCombo[ MainHyp ] = new QtxToolButton( this );
84   myHypCombo[ MainHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
85   myCreateHypBtn[ MainHyp ] = new QToolButton( this );
86   myCreateHypBtn[ MainHyp ]->setIcon( aCreateIcon );
87   myEditHypBtn[ MainHyp ] = new QToolButton( this );
88   myEditHypBtn[ MainHyp ]->setIcon( aEditIcon );
89
90   // Line
91   QFrame* aLine = new QFrame( this );
92   aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
93
94   // Add. hypothesis
95   QLabel* anAddHypLbl = new QLabel( tr( "ADD_HYPOTHESIS" ), this );
96   myHypCombo[ AddHyp ] = new QtxToolButton( this );
97   myHypCombo[ AddHyp ]->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
98   myCreateHypBtn[ AddHyp ] = new QToolButton( this );
99   myCreateHypBtn[ AddHyp ]->setIcon( aCreateIcon );
100   myEditHypBtn[ AddHyp ] = new QToolButton( this );
101   myEditHypBtn[ AddHyp ]->setIcon( aEditIcon );
102   myEditHypBtn[ MoreAddHyp ] = new QToolButton( this );
103   myEditHypBtn[ MoreAddHyp ]->setIcon( aEditIcon );
104
105   myAddHypList = new QListWidget( this );
106   myMoreAddHypBtn = new QToolButton( this );
107   myMoreAddHypBtn->setIcon( aPlusIcon );
108   myLessAddHypBtn = new QToolButton( this );
109   myLessAddHypBtn->setIcon( aMinusIcon );
110
111   // Fill layout
112   QGridLayout* aLay = new QGridLayout( this );
113   aLay->setMargin( MARGIN );
114   aLay->setSpacing( SPACING );
115
116   aLay->addWidget( anAlgoLbl, 0, 0 );
117   aLay->addWidget( myHypCombo[ Algo ], 0, 1 );
118   aLay->addWidget( aHypLbl, 1, 0 );
119   aLay->addWidget( myHypCombo[ MainHyp ], 1, 1 );
120   aLay->addWidget( myCreateHypBtn[ MainHyp ], 1, 2 );
121   aLay->addWidget( myEditHypBtn[ MainHyp ], 1, 3 );
122   aLay->addWidget( aLine, 2, 0, 1, 4 );
123   aLay->addWidget( anAddHypLbl, 3, 0 );
124   aLay->addWidget( myHypCombo[ AddHyp ], 3, 1 );
125   aLay->addWidget( myCreateHypBtn[ AddHyp ], 3, 2 );
126   aLay->addWidget( myEditHypBtn[ AddHyp ], 3, 3 );
127   aLay->addWidget( myAddHypList, 4, 1, 2, 1 );
128   aLay->addWidget( myMoreAddHypBtn, 4, 2 );
129   aLay->addWidget( myEditHypBtn[ MoreAddHyp ], 4, 3 );
130   aLay->addWidget( myLessAddHypBtn, 5, 2 );
131
132   aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ), 6, 0 );
133
134   // Connect signals and slots
135   for ( int i = MainHyp; i <= AddHyp; i++ )
136   {
137     connect( myCreateHypBtn[ i ], SIGNAL( clicked() )       ,  SLOT( onCreateHyp() ) );
138     connect( myEditHypBtn[ i ]  , SIGNAL( clicked() )       ,  SLOT( onEditHyp() ) );
139     connect( myHypCombo[ i ]    , SIGNAL( activated( int ) ),  SLOT( onHyp( int ) ) );
140   }
141   connect( myHypCombo[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
142
143   connect( myAddHypList, SIGNAL( currentRowChanged( int ) ), SLOT( onHyp( int ) ) );
144   connect( myEditHypBtn[ MoreAddHyp ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
145   connect( myMoreAddHypBtn, SIGNAL( clicked() ), SLOT( onMoreAddHyp() ));
146   connect( myLessAddHypBtn, SIGNAL( clicked() ), SLOT( onLessAddHyp() ));
147
148   // Initialize controls
149
150   setAvailableHyps( Algo, QStringList() );
151   setAvailableHyps( MainHyp, QStringList() );
152   setAvailableHyps( AddHyp, QStringList() );
153 }
154
155 //================================================================================
156 /*!
157  * \brief Destructor
158  */
159 //================================================================================ 
160 SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
161 {
162 }
163
164 //================================================================================
165 /*!
166  * \brief Adds an item in a control corresponding to \a type
167  *  \param [in] txt - item text
168  *  \param [in] type - HypType
169  *  \param [in] index - index of item in a list of items
170  *  \param [in] isGroup - is the item a group title
171  */
172 //================================================================================
173 void SMESHGUI_MeshTab::addItem( const QString& txt,
174                                 const int      type,
175                                 const int      index,
176                                 const bool     isGroup )
177 {
178   if ( type <= AddHyp )
179   {
180     if ( isGroup )
181     {
182       myHypCombo[ type ]->addSeparator( txt.mid( 6 ) );
183     }
184     else
185     {
186       myHypCombo[ type ]->addItem( txt, QVariant( index ));
187     }
188     //myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) );
189   }
190   else
191   {
192     QListWidgetItem* item = new QListWidgetItem( 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.addGroup( 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   // groups
577   myCreateGroupsCheck = new QCheckBox( tr( "CREATE_ALL_GROUPS" ), this );
578   myCreateGroupsCheck->setChecked( true );
579
580   // Create tab widget
581
582   myTabWg = new QTabWidget( mainFrame() );
583   myTabs[ Dim0D ] = new SMESHGUI_MeshTab( myTabWg );
584   myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
585   myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
586   myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
587   myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
588   myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
589   myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
590   myTabWg->addTab( myTabs[ Dim0D ], tr( "DIM_0D" ) );
591
592   // Hypotheses Sets
593   myHypoSetButton = new QToolButton( mainFrame() );
594   myHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
595   myHypoSetButton->setEnabled( false );
596   myHypoSetButton->setSizePolicy( QSizePolicy::MinimumExpanding, 
597                                   myHypoSetButton->sizePolicy().verticalPolicy() );
598   
599   // Fill layout
600   QGridLayout* aLay = new QGridLayout( mainFrame() );
601   aLay->setMargin( 0 );
602   aLay->setSpacing( SPACING );
603
604   aLay->addWidget( objectWg( Obj,  Label ),   0, 0 );
605   aLay->addWidget( objectWg( Obj,  Btn ),     0, 1 );
606   aLay->addWidget( objectWg( Obj,  Control ), 0, 2 );
607   aLay->addWidget( objectWg( Mesh, Label ),   1, 0 );
608   aLay->addWidget( objectWg( Mesh, Btn ),     1, 1 );
609   aLay->addWidget( objectWg( Mesh, Control ), 1, 2 );
610   aLay->addWidget( objectWg( Geom, Label ),   2, 0 );
611   aLay->addWidget( objectWg( Geom, Btn ),     2, 1 );
612   aLay->addWidget( objectWg( Geom, Control ), 2, 2 );
613   aLay->addWidget( anMeshTypeLbl,             3, 0 );
614   aLay->addWidget( myMeshType,                3, 2 );
615   aLay->addWidget( myCreateGroupsCheck,       4, 0, 1, 3 );
616   aLay->addWidget( myTabWg,                   6, 0, 1, 3 );
617   aLay->addWidget( myHypoSetButton,           7, 0, 1, 3 );
618   aLay->setRowMinimumHeight( 4, 20 );
619
620   myMeshType->clear();
621
622   // Connect signals and slots
623   connect( myMeshType, SIGNAL( activated( int ) ), SLOT( onChangedMeshType( int ) ) );
624   // Disable controls if necessary
625   setObjectShown( Mesh, false );
626   if ( theToCreate )
627   {
628     setWindowTitle( tr( "CREATE_MESH" ) );
629     objectWg( Obj, Btn )->hide();
630     if ( theIsMesh )
631       setWindowTitle( tr( "CREATE_MESH" ) );
632     else
633     {
634       setWindowTitle( tr( "CREATE_SUBMESH" ) );
635       setObjectShown( Mesh, true );
636     }
637   }
638   else
639   {
640     setWindowTitle( tr( "EDIT_MESH_SUBMESH" ) );
641     objectWg( Mesh, Btn )->hide();
642     objectWg( Geom, Btn )->hide();
643   }
644   setTitile( theToCreate, theIsMesh );
645 }
646
647 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
648 {
649 }
650
651 //================================================================================
652 /*!
653  * \brief Set dialog title
654  */
655 //================================================================================
656 void SMESHGUI_MeshDlg::setTitile( const bool theToCreate, const bool theIsMesh )
657 {
658   if ( theToCreate )
659   {
660     setWindowTitle( tr( theIsMesh ? "CREATE_MESH" : "CREATE_SUBMESH" ));
661   }
662   else
663   {
664     setWindowTitle( tr( theIsMesh ? "EDIT_MESH" : "EDIT_SUBMESH") );
665   }
666   myCreateGroupsCheck-> setVisible( theToCreate && theIsMesh );
667 }
668
669 //================================================================================
670 /*!
671  * \brief Gets tab with given id
672   * \param theId - Tab identifier. Possible values are in "Dimensions" enumeration
673   * \retval SMESHGUI_MeshTab* - pointer to the tab or null if given parameter is 
674   * invalid
675  * 
676  * Gets tab containing controls for definition of algorithms and AddHypotheses
677  */
678 //================================================================================
679 SMESHGUI_MeshTab* SMESHGUI_MeshDlg::tab( const int theId ) const
680 {
681   return ( theId >= Dim0D && theId <= Dim3D ? myTabs[ theId ] : 0 );
682 }
683
684 //================================================================================
685 /*!
686  * \brief Resets all dialog fields
687  */
688 //================================================================================  
689 void SMESHGUI_MeshDlg::reset()
690 {
691   clearSelection();
692   myTabs[ Dim0D ]->reset();
693   myTabs[ Dim1D ]->reset();
694   myTabs[ Dim2D ]->reset();
695   myTabs[ Dim3D ]->reset();
696 }
697
698 //================================================================================
699 /*!
700  * \brief Sets current tab
701  */
702 //================================================================================    
703 void SMESHGUI_MeshDlg::setCurrentTab( const int theId  )
704 {
705   myTabWg->setCurrentIndex( Dim3D - theId );
706 }
707
708 //================================================================================
709 /*!
710  * \brief Enable/disable tabs
711   * \param int - maximum possible dimension
712  */
713 //================================================================================
714 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
715 {
716   const int DIM = maxDim;
717   for ( int dim = Dim0D; dim <= Dim3D; ++dim ) {
718     bool enable = ( dim <= DIM );
719     if ( !enable ) {
720       myTabs[ dim ]->reset();
721       disableTab( dim );
722     }
723     else {
724       enableTab( dim );
725     }
726   }
727   // deselect desabled tab
728   if ( !myTabWg->isTabEnabled( myTabWg->currentIndex() ) )
729     setCurrentTab( DIM );
730 }
731
732 //================================================================================
733 /*!
734  * \brief Sets list of available Sets of Hypotheses
735  */
736 //================================================================================
737 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
738 {
739   QMenu* aHypoSetPopup = myHypoSetButton->menu();
740   if ( !aHypoSetPopup ) {
741     aHypoSetPopup = new QMenu( myHypoSetButton );
742     connect( aHypoSetPopup, SIGNAL( triggered( QAction* ) ), SLOT( onHypoSetPopup( QAction* ) ) );
743     myHypoSetButton->setMenu( aHypoSetPopup );
744     myHypoSetButton->setPopupMode( QToolButton::InstantPopup );
745   }
746   aHypoSetPopup->clear();
747   for ( int i = 0, n = theSets.count(); i < n; i++ )
748   {
749     QAction* action = new QAction( tr( theSets[ i ].toUtf8().data() ));
750     action->setData( theSets[ i ] );
751     aHypoSetPopup->addAction( action );
752   }
753   myHypoSetButton->setEnabled( !aHypoSetPopup->isEmpty() );
754 }
755
756 //================================================================================
757 /*!
758  * \brief Emits hypoSet signal
759  * 
760  * SLOT is called when a hypotheses set is selected. Emits hypoSet
761  * signal to notify operation about this event
762  */
763 //================================================================================
764 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
765 {
766   emit hypoSet( a->data().toString() );
767 }
768   
769 //================================================================================
770 /*!
771  * \brief Enable showing of the popup when Geometry selection btn is clicked
772   * \param enable - true to enable
773  */
774 //================================================================================
775
776 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
777
778 void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
779 {
780   if ( QToolButton* selBtn = qobject_cast<QToolButton*>( objectWg( Geom, Btn )))
781   {
782     if ( enable ) {
783       if ( ! myGeomPopup ) {
784         myGeomPopup = new QMenu();
785         myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )->setData( DIRECT_GEOM_INDEX );
786         myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )->setData( GEOM_BY_MESH_INDEX );
787         connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
788         connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
789       }
790     }
791     else {
792       disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
793       if ( myGeomPopup ) {
794         delete myGeomPopup;
795         myGeomPopup = 0;
796       }
797     }
798   }
799 }
800
801
802 //================================================================================
803 /*!
804  * \brief Disable tab
805  * \param int - tab ID
806  */
807 //================================================================================
808 void SMESHGUI_MeshDlg::disableTab(const int theTabId)
809 {
810   myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
811 }
812
813 //================================================================================
814 /*!
815  * \brief Enable tabs
816  * \param int - tab ID
817  */
818 //================================================================================
819 void SMESHGUI_MeshDlg::enableTab(const int theTabId)
820 {
821   myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
822   if ( theTabId == Dim3D ) {
823     QMenu* aHypoSetPopup = myHypoSetButton->menu();
824     myHypoSetButton->setEnabled( aHypoSetPopup && !aHypoSetPopup->actions().isEmpty() );
825   }
826 }
827
828 //================================================================================
829 /*!
830  * \brief Check if tab enabled
831  * \param int - tab ID
832  */
833 //================================================================================
834 bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const
835 {
836   return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
837 }
838
839 //================================================================================
840 /*!
841  * \brief Return index of a current tab
842  * \return tab ID
843  */
844 //================================================================================
845 int SMESHGUI_MeshDlg::currentTab() const
846 {
847   return Dim3D - myTabWg->currentIndex();
848 }
849
850 //================================================================================
851 /*!
852  * \brief SLOT called when a Geom selection button is clicked
853  */
854 //================================================================================
855 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
856 {
857   if ( myGeomPopup && isBtnOn )
858     myGeomPopup->exec( QCursor::pos() );
859 }
860
861 //================================================================================
862 /*!
863  * \brief SLOT called when a item of Geom selection popup is chosen
864  */
865 //================================================================================
866 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
867 {
868   emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
869 }
870
871 //================================================================================
872 /*!
873  * \brief Return ID of an active selection button
874  */
875 //================================================================================
876 int SMESHGUI_MeshDlg::getActiveObject()
877 {
878   for (int i = 0; i < 3; ++i )
879     if ( isObjectShown( i ) &&
880          (( QToolButton* )objectWg( i, Btn ))->isChecked())
881       return i;
882   return -1;
883 }
884 //================================================================================
885 /*!
886  * \brief Sets available types of mesh
887  * \param theTypeMesh - list of available types of mesh
888  */
889 //================================================================================
890 void SMESHGUI_MeshDlg::setAvailableMeshType( const QStringList& theTypeMesh )
891 {
892   myMeshType->clear();
893   myMeshType->addItems(theTypeMesh);
894 }
895 //================================================================================
896 /*!
897  * \brief Emits selectMeshType( const int, const int ) signal
898  *
899  * SLOT is called when a combo box "mesh type" is selected.
900  */
901 //================================================================================
902 void SMESHGUI_MeshDlg::onChangedMeshType( const int isIndex )
903 {
904   emit selectMeshType( Dim3D - myTabWg->currentIndex(), isIndex );
905 }
906 //================================================================================
907 /*!
908  * \brief Get current index types of mesh
909  */
910 //================================================================================
911 int SMESHGUI_MeshDlg::currentMeshType( )
912 {
913   return myMeshType->currentIndex( );
914 }
915 //================================================================================
916 /*!
917  * \brief Set current index types of mesh
918  */
919 //================================================================================
920 void SMESHGUI_MeshDlg::setCurrentMeshType( const int theIndex )
921 {
922   if ( theIndex < myMeshType->count() )
923     myMeshType->setCurrentIndex( theIndex );
924   else
925     myMeshType->setCurrentIndex( 0 );
926 }
927
928 //================================================================================
929 /*!
930  * \brief Return state of "Create all Groups on Geometry" check-box
931  */
932 //================================================================================
933
934 bool SMESHGUI_MeshDlg::toCreateAllGroups()
935 {
936   return myCreateGroupsCheck->isChecked();
937 }