Salome HOME
PAL10332 - references are interpreted as original objects in filters, dialogs, etc.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_aParameter.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESHGUI_aParameter.cxx
25 //  Module : SMESH
26 //  $Header$
27
28 #include "SMESHGUI_aParameter.h"
29
30 #include <qspinbox.h>
31 #include <qvalidator.h>
32 #include <qlineedit.h>
33 #include <qtextedit.h>
34 #include <qcombobox.h>
35 #include <qcheckbox.h>
36 #include <qtable.h>
37 #include <qvalidator.h>
38 #include <qpushbutton.h>
39 #include <qlayout.h>
40
41 #include <QtxDblSpinBox.h>
42
43 SMESHGUI_aParameter::~SMESHGUI_aParameter() {}
44
45 QString SMESHGUI_aParameter::sigValueChanged() const
46 {
47   return QString::null;
48 }
49
50 //=================================================================================
51 // class    : SMESHGUI_intParameter
52 // purpose  :
53 //=================================================================================
54 SMESHGUI_intParameter::SMESHGUI_intParameter (const int      theInitValue,
55                                               const QString& theLabel,
56                                               const int      theBottom,
57                                               const int      theTop)
58      :SMESHGUI_aParameter(theLabel),
59        _top(theTop), _bottom(theBottom), _initValue(theInitValue),
60        _newValue( theInitValue )
61 {
62 }
63 SMESHGUI_aParameter::Type SMESHGUI_intParameter::GetType() const
64 {
65   return SMESHGUI_aParameter::INT;
66 }
67 bool SMESHGUI_intParameter::GetNewInt (int & theValue) const
68 {
69   theValue = _newValue;
70   return _newValue != _initValue;
71 }
72 bool SMESHGUI_intParameter::GetNewDouble (double & Value) const
73 {
74   return false;
75 }
76 bool SMESHGUI_intParameter::GetNewText (QString & Value) const
77 {
78   return false;
79 }
80
81 QWidget* SMESHGUI_intParameter::CreateWidget( QWidget* parent ) const
82 {
83   return new QSpinBox( parent );
84 }
85   
86 void SMESHGUI_intParameter::InitializeWidget (QWidget* theQWidget) const
87 {
88   QSpinBox * aSpin = dynamic_cast< QSpinBox *>(theQWidget);
89   if (aSpin) {
90     aSpin->setMinValue(_bottom);
91     aSpin->setMaxValue(_top);
92     aSpin->setValue(_initValue);
93   }
94 }
95 void SMESHGUI_intParameter::TakeValue (QWidget* theQWidget)
96 {
97   QSpinBox * aSpin = dynamic_cast< QSpinBox *>(theQWidget);
98   if (aSpin)
99     _newValue = aSpin->value();
100 }
101
102 QString SMESHGUI_intParameter::sigValueChanged() const
103 {
104   return SIGNAL( valueChanged( int ) );
105 }
106
107 //=================================================================================
108 // class    : SMESHGUI_doubleParameter
109 // purpose  :
110 //=================================================================================
111 SMESHGUI_doubleParameter::SMESHGUI_doubleParameter (const double   theInitValue,
112                                                     const QString& theLabel,
113                                                     const double   theBottom,
114                                                     const double   theTop,
115                                                     const double   theStep,
116                                                     const int      theDecimals)
117      :SMESHGUI_aParameter(theLabel),
118        _top(theTop), _bottom(theBottom), _step(theStep),
119        _initValue(theInitValue), _decimals(theDecimals)
120 {
121 }
122 SMESHGUI_aParameter::Type SMESHGUI_doubleParameter::GetType() const
123 {
124   return SMESHGUI_aParameter::DOUBLE;
125 }
126 bool SMESHGUI_doubleParameter::GetNewInt (int & theValue) const
127 {
128   return false;
129 }
130 bool SMESHGUI_doubleParameter::GetNewDouble (double & Value) const
131 {
132   Value = _newValue;
133   return _newValue != _initValue;
134 }
135 bool SMESHGUI_doubleParameter::GetNewText (QString & Value) const
136 {
137   return false;
138 }
139
140 QWidget* SMESHGUI_doubleParameter::CreateWidget( QWidget* parent ) const
141 {
142   return new QtxDblSpinBox( parent );
143 }
144
145 void SMESHGUI_doubleParameter::InitializeWidget (QWidget* theQWidget) const
146 {
147   QtxDblSpinBox* aSpin = dynamic_cast<QtxDblSpinBox*>(theQWidget);
148   if (aSpin) {
149     aSpin->setPrecision(_decimals);
150 #ifdef NEW_GUI
151     aSpin->setDblPrecision(_bottom);
152 #endif
153     aSpin->setRange(_bottom, _top);
154     aSpin->setValue(_initValue);
155     aSpin->setLineStep(_step);
156   }
157 }
158 void SMESHGUI_doubleParameter::TakeValue (QWidget* theQWidget)
159 {
160   QtxDblSpinBox* aSpin = dynamic_cast<QtxDblSpinBox*>(theQWidget);
161   if (aSpin)
162     _newValue = aSpin->value();
163 }
164
165 QString SMESHGUI_doubleParameter::sigValueChanged() const
166 {
167   return SIGNAL( valueChanged( double ) );
168 }
169
170 //=================================================================================
171 // class    : SMESHGUI_strParameter
172 // purpose  :
173 //=================================================================================
174 SMESHGUI_strParameter::SMESHGUI_strParameter (const QString& theInitValue,
175                                               const QString& theLabel)
176      :SMESHGUI_aParameter(theLabel),
177       _initValue(theInitValue)
178 {
179 }
180 SMESHGUI_aParameter::Type SMESHGUI_strParameter::GetType() const
181 {
182   return SMESHGUI_aParameter::STRING;
183 }
184 bool SMESHGUI_strParameter::GetNewInt (int & theValue) const
185 {
186   return false;
187 }
188 bool SMESHGUI_strParameter::GetNewDouble (double & Value) const
189 {
190   return false;
191 }
192 bool SMESHGUI_strParameter::GetNewText (QString & theValue) const
193 {
194   theValue = _newValue;
195   return _newValue != _initValue;
196 }
197
198 QWidget* SMESHGUI_strParameter::CreateWidget( QWidget* parent ) const
199 {
200   return new QLineEdit( parent );
201 }
202
203 void SMESHGUI_strParameter::InitializeWidget (QWidget* theQWidget) const
204 {
205   QLineEdit* anEdit = dynamic_cast< QLineEdit* >(theQWidget);
206   if (anEdit) {
207     anEdit->setText(_initValue);
208   }
209 }
210 void SMESHGUI_strParameter::TakeValue (QWidget* theQWidget)
211 {
212   QLineEdit* anEdit = dynamic_cast< QLineEdit* >(theQWidget);
213   if (anEdit)
214     _newValue = anEdit->text();
215 }
216
217 QString SMESHGUI_strParameter::sigValueChanged() const
218 {
219   return SIGNAL( textChanged( const QString& ) );
220 }
221
222
223
224 //=================================================================================
225 // class    : SMESHGUI_dependParameter
226 // purpose  :
227 //=================================================================================
228 SMESHGUI_dependParameter::SMESHGUI_dependParameter( const QString& label )
229 : SMESHGUI_aParameter( label )
230 {
231 }
232
233 const SMESHGUI_dependParameter::ShownMap& SMESHGUI_dependParameter::shownMap() const
234 {
235   return myShownMap;
236 }
237
238 SMESHGUI_dependParameter::ShownMap& SMESHGUI_dependParameter::shownMap()
239 {
240   return myShownMap;
241 }
242
243
244   
245
246
247 //=================================================================================
248 // class    : SMESHGUI_enumParameter
249 // purpose  :
250 //=================================================================================
251 SMESHGUI_enumParameter::SMESHGUI_enumParameter( const QStringList& values,
252                                                 const int initValue,
253                                                 const QString& label )
254 : SMESHGUI_dependParameter( label ),
255   myInitValue( initValue ),
256   myValue( initValue ),
257   myValues( values )
258 {
259 }
260
261 SMESHGUI_enumParameter::~SMESHGUI_enumParameter()
262 {
263 }
264
265 SMESHGUI_aParameter::Type SMESHGUI_enumParameter::GetType() const
266 {
267   return SMESHGUI_aParameter::ENUM;
268 }
269
270 bool SMESHGUI_enumParameter::GetNewInt( int& v ) const
271 {
272   v = myValue;
273   return myValue!=myInitValue;
274 }
275
276 bool SMESHGUI_enumParameter::GetNewDouble( double& ) const
277 {
278   return false;
279 }
280
281 bool SMESHGUI_enumParameter::GetNewText( QString& v ) const
282 {
283   bool res = myValue>=0 && myValue<Count();
284
285   if( res )
286     v = myValues[ myValue ];
287
288   return res && v!=myInitValue;
289 }
290
291 QWidget* SMESHGUI_enumParameter::CreateWidget( QWidget* parent ) const
292 {
293   return new QComboBox( parent );
294 }
295
296 void SMESHGUI_enumParameter::InitializeWidget( QWidget* w ) const
297 {
298   if( w && w->inherits( "QComboBox" ) )
299   {
300     QComboBox* c = ( QComboBox* ) w;
301     c->clear();
302     c->insertStringList( myValues );
303     c->setCurrentItem( myInitValue );
304   }
305 }
306
307 void SMESHGUI_enumParameter::TakeValue( QWidget* w )
308 {
309   if( w && w->inherits( "QComboBox" ) )
310   {
311     QComboBox* c = ( QComboBox* ) w;
312     myValue = c->currentItem();
313   }
314 }
315
316 int SMESHGUI_enumParameter::Count() const
317 {
318   return myValues.count();
319 }
320
321 QString SMESHGUI_enumParameter::sigValueChanged() const
322 {
323   return SIGNAL( activated( int ) );
324 }
325
326
327 //=================================================================================
328 // class    : SMESHGUI_boolParameter
329 // purpose  :
330 //=================================================================================
331 SMESHGUI_boolParameter::SMESHGUI_boolParameter( const bool initValue,
332                                                 const QString& label )
333 : SMESHGUI_dependParameter( label ),
334   myInitValue( initValue ),
335   myValue( myInitValue )
336 {
337 }
338
339 SMESHGUI_boolParameter::~SMESHGUI_boolParameter()
340 {
341 }
342
343 SMESHGUI_aParameter::Type SMESHGUI_boolParameter::GetType() const
344 {
345   return BOOL;
346 }
347
348 bool SMESHGUI_boolParameter::GetNewInt( int& v ) const
349 {
350   if( myValue )
351     v = 1;
352   else
353     v = 0;
354   return v!=myInitValue;
355 }
356
357 bool SMESHGUI_boolParameter::GetNewDouble( double& ) const
358 {
359   return false;
360 }
361
362 bool SMESHGUI_boolParameter::GetNewText( QString& ) const
363 {
364   return false;
365 }
366
367 QWidget* SMESHGUI_boolParameter::CreateWidget( QWidget* parent ) const
368 {
369   return new QCheckBox( parent );
370 }
371
372 void SMESHGUI_boolParameter::InitializeWidget( QWidget* w ) const
373 {
374   if( w && w->inherits( "QCheckBox" ) )
375   {
376     QCheckBox* box = ( QCheckBox* )w;
377     box->setChecked( myInitValue );
378   }
379 }
380
381 void SMESHGUI_boolParameter::TakeValue( QWidget* w )
382 {
383   if( w && w->inherits( "QCheckBox" ) )
384   {
385     QCheckBox* box = ( QCheckBox* )w;
386     myValue = box->isChecked();
387   }  
388 }
389
390 QString SMESHGUI_boolParameter::sigValueChanged() const
391 {
392   return SIGNAL( stateChanged( int ) );
393 }
394
395
396
397
398 //=================================================================================
399 // class    : SMESHGUI_doubleItem
400 // purpose  : Custom table item which contains double and has double validator
401 //=================================================================================
402 class SMESHGUI_doubleItem: public QTableItem
403 {
404 public:
405   SMESHGUI_doubleItem( QTable*, EditType, const double );
406   virtual ~SMESHGUI_doubleItem();
407
408   void setValidator( const double, const double, const int );
409   void validator( double&, double&, int& );
410   virtual QWidget* createEditor() const;
411
412 private:
413   QDoubleValidator*  myValidator;
414 };
415
416 SMESHGUI_doubleItem::SMESHGUI_doubleItem( QTable* t, EditType e, const double num )
417 : QTableItem( t, e, QString( "%1" ).arg( num ) ),
418   myValidator( new QDoubleValidator( 0.0, 1.0, 3, t ) )
419 {
420 }
421
422 SMESHGUI_doubleItem::~SMESHGUI_doubleItem()
423 {
424 }
425
426 void SMESHGUI_doubleItem::setValidator( const double bot, const double top, const int dec )
427 {
428   myValidator->setBottom( bot );
429   myValidator->setTop( top );
430   myValidator->setDecimals( dec );
431 }
432
433 void SMESHGUI_doubleItem::validator( double& bot, double& top, int& dec )
434 {
435   bot = myValidator->bottom();
436   top = myValidator->top();
437   dec = myValidator->decimals();
438 }
439
440 QWidget* SMESHGUI_doubleItem::createEditor() const
441 {
442   QWidget* res = QTableItem::createEditor();
443   if( res && res->inherits( "QLineEdit" ) )
444   {
445     QLineEdit* l = ( QLineEdit* )res;
446     l->setValidator( myValidator );
447   }
448   return res;
449 }
450
451
452 //=================================================================================
453 // class    : SMESHGUI_Table
454 // purpose  :
455 //=================================================================================
456 SMESHGUI_Table::SMESHGUI_Table( int numRows, int numCols, QWidget* parent, const char* name )
457 : QTable( numRows, numCols, parent, name )
458 {
459 }
460
461 SMESHGUI_Table::~SMESHGUI_Table()
462 {
463 }
464
465 QSize SMESHGUI_Table::sizeHint() const
466 {
467   if( cachedSizeHint().isValid() )
468     return cachedSizeHint();
469
470   constPolish();
471
472   QSize sh = QScrollView::sizeHint();
473   if( sh.width()<400 )
474     sh.setWidth( 400 );
475   if( sh.height()<200 )
476     sh.setHeight( 200 );
477
478   setCachedSizeHint( sh );
479   return sh;
480 }
481
482 void SMESHGUI_Table::stopEditing()
483 {
484   endEdit( currEditRow(), currEditCol(), false, false );
485 }
486
487 void SMESHGUI_Table::validator( const int row, const int col, double& minV, double& maxV, int& dec )
488 {
489   SMESHGUI_doubleItem* it = dynamic_cast<SMESHGUI_doubleItem*>( item( row, col ) );
490   if( it )
491     it->validator( minV, maxV, dec );
492 }
493
494 void SMESHGUI_Table::setValidator( const double minV, const double maxV, const int dec,
495                                    const int rmin, const int rmax,
496                                    const int cmin, const int cmax )
497 {
498   int r1 = rmin>=0 ? rmin : 0,
499       r2 = rmax>=0 ? rmax : numRows(),
500       c1 = cmin>=0 ? cmin : 0,
501       c2 = cmax>=0 ? cmax : numCols();
502
503   for( int i=r1; i<=r2; i++ )
504     for( int j=c1; j<=c2; j++ )
505     {
506       SMESHGUI_doubleItem* it = dynamic_cast<SMESHGUI_doubleItem*>( item( i, j ) );
507       if( it )
508         it->setValidator( minV, maxV, dec );
509     }
510 }
511
512
513
514 //=================================================================================
515 // class    : SMESHGUI_TableFrame
516 // purpose  :
517 //=================================================================================
518 SMESHGUI_TableFrame::SMESHGUI_TableFrame( QWidget* parent )
519 : QFrame( parent )
520 {
521   QVBoxLayout* main = new QVBoxLayout( this, 0, 0 );
522
523   myTable = new SMESHGUI_Table( 1, 1, this );
524   
525   QFrame* aButFrame = new QFrame( this );
526   QHBoxLayout* butLay = new QHBoxLayout( aButFrame, 5, 5 );
527
528   myAddColumn = new QPushButton( "Add column", aButFrame );
529
530   myRemoveColumn = new QPushButton( "Remove column", aButFrame );
531
532   myAddRow = new QPushButton( "Add row", aButFrame );
533
534   myRemoveRow = new QPushButton( "Remove row", aButFrame );
535
536   butLay->addWidget( myAddColumn, 0 );
537   butLay->addWidget( myRemoveColumn, 0 );
538   butLay->addWidget( myAddRow, 0 );
539   butLay->addWidget( myRemoveRow, 0 );
540   butLay->addStretch( 1 );
541
542   main->addWidget( myTable, 1 );
543   main->addWidget( aButFrame, 0 );
544
545   connect( myAddColumn,    SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
546   connect( myRemoveColumn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
547   connect( myAddRow,       SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
548   connect( myRemoveRow,    SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
549 }
550
551 SMESHGUI_TableFrame::~SMESHGUI_TableFrame()
552 {
553 }
554
555 SMESHGUI_Table* SMESHGUI_TableFrame::table() const
556 {
557   return myTable;
558 }
559
560 void SMESHGUI_TableFrame::setShown( const Button b, const bool sh )
561 {
562   if( button( b ) )
563     button( b )->setShown( sh );
564 }
565
566 bool SMESHGUI_TableFrame::isShown( const Button b ) const
567 {
568   bool res = false;
569   if( button( b ) )
570     res = button( b )->isShown();
571   return res;
572 }
573
574 QButton* SMESHGUI_TableFrame::button( const Button b ) const
575 {
576   QButton* res = 0;
577   switch( b )
578   {
579     case ADD_COLUMN:
580       res = myAddColumn;
581       break;
582
583     case REMOVE_COLUMN:
584       res = myRemoveColumn;
585       break;
586
587     case ADD_ROW:
588       res = myAddRow;
589       break;
590
591     case REMOVE_ROW:
592       res = myRemoveRow;
593       break;
594   }
595   return res;
596 }
597
598 void SMESHGUI_TableFrame::onButtonClicked()
599 {
600   if( sender()==button( ADD_COLUMN ) )
601     emit toEdit( ADD_COLUMN, table()->currentColumn() );
602     
603   else if( sender()==button( REMOVE_COLUMN ) )
604     emit toEdit( REMOVE_COLUMN, table()->currentColumn() );
605     
606   else if( sender()==button( ADD_ROW ) )
607     emit toEdit( ADD_ROW, table()->currentRow() );
608     
609   else if( sender()==button( REMOVE_ROW ) )
610     emit toEdit( REMOVE_ROW, table()->currentRow() );
611 }
612
613
614 //=================================================================================
615 // class    : SMESHGUI_tableParameter
616 // purpose  :
617 //=================================================================================
618 SMESHGUI_tableParameter::SMESHGUI_tableParameter( const double init,
619                                                   const QString& label )
620 : SMESHGUI_aParameter( label ),
621   myInitValue( init ),
622   myColsInt( 1 ),
623   myRowsInt( 1 ),
624   myEditCols( false ),
625   myEditRows( false )
626 {
627 }
628
629 SMESHGUI_tableParameter::~SMESHGUI_tableParameter()
630 {
631 }
632
633 SMESHGUI_aParameter::Type SMESHGUI_tableParameter::GetType() const
634 {
635   return TABLE;
636 }
637
638 bool SMESHGUI_tableParameter::GetNewInt( int& ) const
639 {
640   return false;
641 }
642
643 bool SMESHGUI_tableParameter::GetNewDouble( double& ) const
644 {
645   return false;
646 }
647
648 bool SMESHGUI_tableParameter::GetNewText( QString& ) const
649 {
650   return false;
651 }
652
653 QWidget* SMESHGUI_tableParameter::CreateWidget( QWidget* par ) const
654 {
655   SMESHGUI_TableFrame* t = new SMESHGUI_TableFrame( par );
656   connect( t,    SIGNAL( toEdit( SMESHGUI_TableFrame::Button, int ) ),
657            this, SLOT  ( onEdit( SMESHGUI_TableFrame::Button, int ) ) );
658   
659   update( t );
660   return t;
661 }
662
663 void SMESHGUI_tableParameter::setItems( QWidget* w,
664                                         int old_row, int new_row,
665                                         int old_col, int new_col ) const
666 {
667   if( w && w->inherits( "SMESHGUI_TableFrame" ) )
668   {
669     QTable* tab = ( ( SMESHGUI_TableFrame* )w )->table();
670     
671     if( old_row<0 )
672       old_row = 0;
673     if( new_row<0 )
674       new_row = tab->numRows();
675     if( old_col<0 )
676       old_col = 0;
677     if( new_col<0 )
678       new_col = tab->numCols();
679     
680     for( int i=old_row, m=new_row; i<m; i++ )
681       for( int j=0, n=new_col; j<n; j++ )
682         tab->setItem( i, j, new SMESHGUI_doubleItem( tab, QTableItem::WhenCurrent, myInitValue ) );
683     
684     for( int i=0, m=new_row; i<m; i++ )
685       for( int j=old_col, n=new_col; j<n; j++ )
686         tab->setItem( i, j, new SMESHGUI_doubleItem( tab, QTableItem::WhenCurrent, myInitValue ) );
687
688     for( int j=old_col; j<new_col; j++ )
689       tab->setColumnWidth( j, 50 );
690   }
691 }
692
693 void SMESHGUI_tableParameter::InitializeWidget( QWidget* w ) const
694 {
695   setItems( w );
696
697   if( w && w->inherits( "SMESHGUI_TableFrame" ) )
698   {
699     SMESHGUI_Table* tab = ( ( SMESHGUI_TableFrame* )w )->table();
700     tab->stopEditing();
701
702     int col = tab->numCols(),
703         row = tab->numRows();
704     
705     for( int i=0, m=row; i<m; i++ )
706       for( int j=0, n=col; j<n; j++ )
707         if( row*j+i<myData.length() )
708           tab->item( i, j )->setText( QString( "%1" ).arg( myData[row*j+i] ) );
709   }
710 }
711
712 void SMESHGUI_tableParameter::TakeValue( QWidget* w )
713 {
714   if( w && w->inherits( "SMESHGUI_TableFrame" ) )
715   {
716     QTable* tab = ( ( SMESHGUI_TableFrame* )w )->table();
717
718     int col = tab->numCols(),
719         row = tab->numRows();
720
721     myData.length( col*row );
722     for( int i=0; i<row; i++ )
723       for( int j=0; j<col; j++ )
724         myData[ col*i+j ] = tab->text( i, j ).toDouble();
725   }
726 }
727
728 void SMESHGUI_tableParameter::data( SMESH::double_array& v ) const
729 {
730   v = myData;
731 }
732
733 void SMESHGUI_tableParameter::setData( const SMESH::double_array& d )
734 {
735   myData = d;
736 }
737
738 void SMESHGUI_tableParameter::update( QWidget* w ) const
739 {
740   if( w && w->inherits( "SMESHGUI_TableFrame" ) )
741   {
742     SMESHGUI_TableFrame* tabfr = ( SMESHGUI_TableFrame* ) w;
743     SMESHGUI_Table* tab = tabfr->table();
744
745     int old_col = tab->numCols(),
746         old_row = tab->numRows();
747         
748     int col = myColsInt, row = myRowsInt;
749     if( myCols.get() )
750       myCols->GetNewInt( col );
751         
752     if( myRows.get() )
753       myRows->GetNewInt( row );
754
755     if( col<=0 )
756       col = 1;
757     if( row<=0 )
758       row = 1;
759
760     if( col!=tab->numCols() )
761       tab->setNumCols( col );
762
763     if( row!=tab->numRows() )
764       tab->setNumRows( row );
765
766     tabfr->setShown( SMESHGUI_TableFrame::ADD_COLUMN, myEditCols );
767     tabfr->setShown( SMESHGUI_TableFrame::REMOVE_COLUMN, myEditCols );
768     tabfr->setShown( SMESHGUI_TableFrame::ADD_ROW, myEditRows );
769     tabfr->setShown( SMESHGUI_TableFrame::REMOVE_ROW, myEditRows );
770
771     setItems( w, old_row, row, old_col, col );
772
773     QMap< int, QString >::const_iterator aNIt = myColNames.begin(),
774                                          aNLast = myColNames.end();
775     for( ; aNIt!=aNLast; aNIt++ )
776       tab->horizontalHeader()->setLabel( aNIt.key(), aNIt.data() );
777     
778     ValidatorsMap::const_iterator anIt = myValidators.begin(),
779                                   aLast = myValidators.end();
780     for( ; anIt!=aLast; anIt++ )
781     {
782       int row = anIt.key(), dec;
783       double minV, maxV;
784       validator( row, minV, maxV, dec );
785       tab->setValidator( minV, maxV, dec, -1, -1, col, col );
786     }
787
788     QSize s = tab->sizeHint();
789     tab->resize( s.width(), s.height() );
790   }
791 }
792
793 void SMESHGUI_tableParameter::setColCount( const int c, QWidget* w )
794 {
795   myColsInt = c;
796   update( w );
797 }
798
799 void SMESHGUI_tableParameter::setRowCount( const int c, QWidget* w )
800 {
801   myRowsInt = c;
802   update( w );
803 }
804
805 void SMESHGUI_tableParameter::setColCount( const SMESHGUI_aParameterPtr p, QWidget* w )
806 {
807   if( p.get() )
808   {
809     myCols = p;
810     update( w );
811   }
812 }
813
814 void SMESHGUI_tableParameter::setRowCount( const SMESHGUI_aParameterPtr p, QWidget* w )
815 {
816   if( p.get() )
817   {
818     myRows = p;
819     update( w );
820   }
821 }
822
823 QString SMESHGUI_tableParameter::sigValueChanged() const
824 {
825   return SIGNAL( valueChanged( int, int ) );
826 }
827
828 void SMESHGUI_tableParameter::setValidator( const int ind, const double minV, const double maxV, const int dec )
829 {
830   ValidatorInfo inf;
831   inf.myMin = minV;
832   inf.myMax = maxV;
833   inf.myDecimals = dec;
834   myValidators[ ind ] = inf;
835 }
836
837 void SMESHGUI_tableParameter::validator( const int ind, double& minV, double& maxV, int& dec ) const
838 {
839   if( myValidators.contains( ind ) )
840   {
841     const ValidatorInfo& inf = myValidators[ ind ];
842     minV = inf.myMin;
843     maxV = inf.myMax;
844     dec = inf.myDecimals;
845   }
846 }
847
848 void SMESHGUI_tableParameter::setEditCols( const bool ed )
849 {
850   myEditCols = ed;
851 }
852
853 void SMESHGUI_tableParameter::setEditRows( const bool ed )
854 {
855   myEditRows = ed;
856 }
857
858 void SMESHGUI_tableParameter::setColName( const int ind, const QString& name )
859 {
860   myColNames.insert( ind, name );
861 }
862
863 QString SMESHGUI_tableParameter::colName( const int ind ) const
864 {
865   if( myColNames.contains( ind ) )
866     return myColNames[ ind ];
867   else
868     return QString::null;
869 }
870
871 void SMESHGUI_tableParameter::onEdit( SMESHGUI_TableFrame::Button b, int n )
872 {
873   if( sender() && sender()->inherits( "SMESHGUI_TableFrame" ) )
874   {
875     SMESHGUI_TableFrame* fr = ( SMESHGUI_TableFrame* )sender();
876     SMESHGUI_Table* tab = fr->table();
877
878     switch( b )
879     {
880       case SMESHGUI_TableFrame::ADD_COLUMN:
881       {
882         if( !myEditCols || myCols.get() )
883           return;
884
885         myColsInt++; update( fr );
886         if( n>=0 )
887           for( int i=0; i<myRowsInt; i++ )
888             for( int j=myColsInt-1; j>=n; j-- )
889               if( j==n )
890                 tab->setText( i, j, QString( "%1" ).arg( myInitValue ) );
891               else
892                 tab->setText( i, j, tab->text( i, j-1 ) );
893         break;
894       }
895       
896       case SMESHGUI_TableFrame::REMOVE_COLUMN:
897       {
898         if( !myEditCols || myCols.get() || myColsInt<=1 )
899           return;
900
901         if( n>=0 )
902           for( int i=0; i<myRowsInt; i++ )
903             for( int j=n; j<myColsInt-1; j++ )
904               tab->setText( i, j, tab->text( i, j+1 ) );
905         myColsInt--; update( fr );
906
907         break;
908       }
909       
910       case SMESHGUI_TableFrame::ADD_ROW:
911       {
912         if( !myEditRows || myRows.get() )
913           return;
914
915         myRowsInt++; update( fr );
916         if( n>=0 )
917           for( int i=myRowsInt-1; i>=n; i-- )
918             for( int j=0; j<myColsInt; j++ )
919               if( i==n )
920                 tab->setText( i, j, QString( "%1" ).arg( myInitValue ) );
921               else
922                 tab->setText( i, j, tab->text( i-1, j ) );
923         break;        
924       }
925       
926       case SMESHGUI_TableFrame::REMOVE_ROW:
927       {
928         if( !myEditRows || myRows.get() || myRowsInt<=1 )
929           return;
930
931         if( n>=0 )
932           for( int i=n; i<myRowsInt-1; i++ )
933             for( int j=0; j<myColsInt; j++ )
934               tab->setText( i, j, tab->text( i+1, j ) );
935         myRowsInt--; update( fr );
936
937         break;
938       }
939     }
940   }
941 }