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