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