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