Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_CartesianParamCreator.cxx
1 // Copyright (C) 2007-2012  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.
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 // File   : StdMeshersGUI_CartesianParamCreator.cxx
24 // Author : Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "StdMeshersGUI_CartesianParamCreator.h"
28
29 #include <SMESHGUI.h>
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32 #include <SMESHGUI_SpinBox.h>
33
34 // IDL includes
35 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
36
37 // SALOME GUI includes
38 #include <SalomeApp_Tools.h>
39 #include <SalomeApp_IntSpinBox.h>
40 #include <QtxComboBox.h>
41
42 // Qt includes
43 #include <QAbstractItemModel>
44 #include <QApplication>
45 #include <QButtonGroup>
46 #include <QGridLayout>
47 #include <QGroupBox>
48 #include <QHBoxLayout>
49 #include <QLabel>
50 #include <QLineEdit>
51 #include <QListWidget>
52 #include <QModelIndex>
53 #include <QRadioButton>
54 #include <QString>
55 #include <QStyleOptionViewItem>
56 #include <QTreeWidget>
57 #include <QTreeWidgetItem>
58 #include <QVBoxLayout>
59 #include <QPushButton>
60 #include <QTabWidget>
61
62 #define SPACING 6
63 #define MARGIN  11
64
65 namespace StdMeshersGUI
66 {
67   enum { COORD_BUT = 0, SPACING_BUT };
68
69   //================================================================================
70   /*!
71    * \brief get spacing definition from a tree item
72    */
73   //================================================================================
74
75   void getFromItem(QTreeWidgetItem * item, double& t0, double& t1, QString& fun )
76   {
77     if ( item )
78     {
79       t0 = item->text( 0 ).split(' ')[0].toDouble();
80       t1 = item->data( 0, Qt::UserRole ).toDouble();
81       fun = item->text( 1 );
82     }
83   }
84
85   //================================================================================
86   /*!
87    * \brief set spacing definition to a tree item
88    */
89   //================================================================================
90
91   QTreeWidgetItem* setToItem(double t0, double t1, const QString& fun, QTreeWidgetItem * item)
92   {
93     if ( !item ) item = new QTreeWidgetItem;
94     item->setText( 0, QString( "%1 - %2" ).arg( t0 ).arg( t1 ));
95     item->setData( 0, Qt::UserRole, t1 );
96     item->setText( 1, fun );
97     item->setFlags( item->flags() | Qt::ItemIsEditable );
98     return item;
99   }
100
101   //================================================================================
102   /*!
103    * \brief Retrieves coordinate value from a list item
104    */
105   //================================================================================
106
107   double coordFromItem( QListWidgetItem * item )
108   {
109     return item ? item->data( Qt::UserRole ).toDouble() : 0;
110   }
111
112   //================================================================================
113   /*!
114    * \brief Sets coordinate value to a list item
115    */
116   //================================================================================
117
118   QListWidgetItem* coordToItem( double coord, QListWidgetItem * item )
119   {
120     if ( !item ) item = new QListWidgetItem;
121     item->setText( QString::number( coord ));
122     item->setData( Qt::UserRole, coord );
123     item->setFlags( item->flags() | Qt::ItemIsEditable );
124     return item;
125   }
126
127   //================================================================================
128   /*!
129    * \brief Constructor
130    * \param theParent - Parent widget for this tab
131    * 
132    * Makes tab's look and feel
133    */
134   //================================================================================
135
136   GridAxisTab::GridAxisTab( QWidget* theParent,const int axisIndex ):
137     QFrame( theParent ), myAxisIndex( axisIndex )
138   {
139     // 1) Grid definition mode
140     myModeGroup = new QButtonGroup( this );
141     QGroupBox* modeBox = new QGroupBox( tr( "GRID_DEF_MODE" ), this );
142     QHBoxLayout* modeLay = new QHBoxLayout( modeBox );
143     modeLay->setMargin( MARGIN );
144     modeLay->setSpacing( SPACING );
145
146     QRadioButton* coordModeBtn = new QRadioButton( tr( "SMESH_COORDINATES" ), modeBox );
147     QRadioButton* spacModeBtn  = new QRadioButton( tr( "SPACING" ), modeBox );
148
149     modeLay->addWidget( coordModeBtn );
150     modeLay->addWidget( spacModeBtn );
151     myModeGroup->addButton( coordModeBtn, COORD_BUT );
152     myModeGroup->addButton( spacModeBtn,  SPACING_BUT );
153
154     // 2) Buttons + Step
155     myInsertBtn = new QPushButton( tr("INSERT"), this);
156     myDeleteBtn = new QPushButton( tr("SMESH_BUT_DELETE"), this);
157
158     myStepLabel = new QLabel( tr("COORD_STEP"));
159     myStepSpin  = new SMESHGUI_SpinBox( this );
160     myStepSpin->setAcceptNames( false ); // No Notebook variables allowed
161     myStepSpin->RangeStepAndValidator();
162     myStepSpin->SetStep( 1. );
163     myStepSpin->SetValue( myStep = 1. );
164
165     // 3) Coodrinates/Spacing group
166     QFrame* csFrame = new QFrame( this );
167     QVBoxLayout* scLay = new QVBoxLayout( csFrame );
168     scLay->setMargin( 0 );
169     scLay->setSpacing( SPACING );
170
171     // 3.1) Spacing
172     mySpacingTreeWdg = new QTreeWidget( csFrame );
173     mySpacingTreeWdg->setColumnCount(2);
174     mySpacingTreeWdg->setHeaderLabels( QStringList() << tr( "SMESH_RANGE" ) << QString( "f(t)" ));
175     mySpacingTreeWdg->setColumnWidth( 1, 40 );
176     mySpacingTreeWdg->setColumnWidth( 2, 30 );
177     mySpacingTreeWdg->setItemDelegate( new LineDelegate( mySpacingTreeWdg ));
178     scLay->addWidget( mySpacingTreeWdg );
179
180     // 3.2) Coordinates
181     myCoordList = new QListWidget( csFrame );
182     myCoordList->setItemDelegate( new LineDelegate( myCoordList ));
183     scLay->addWidget( myCoordList );
184
185     // layouting
186
187     QGridLayout* axisTabLayout = new QGridLayout( this );
188     axisTabLayout->setMargin( MARGIN );
189     axisTabLayout->setSpacing( SPACING );
190
191     axisTabLayout->addWidget( modeBox    , 0, 0, 1, 3 );
192     axisTabLayout->addWidget( myInsertBtn  , 1, 0, 1, 2 );
193     axisTabLayout->addWidget( myDeleteBtn  , 2, 0, 1, 2 );
194     axisTabLayout->addWidget( myStepLabel, 3, 0 );
195     axisTabLayout->addWidget( myStepSpin , 3, 1 );
196     axisTabLayout->addWidget( csFrame    , 1, 2, 4, 1 );
197
198     axisTabLayout->setRowStretch( 4, 1 );
199
200     // signals
201     connect( myInsertBtn,      SIGNAL( clicked() ),             SLOT( onInsert() ));
202     connect( myDeleteBtn,      SIGNAL( clicked() ),             SLOT( onDelete() ));
203     connect( myModeGroup,      SIGNAL( buttonClicked ( int )),  SLOT( onMode(int)));
204     connect( mySpacingTreeWdg, SIGNAL( itemSelectionChanged()), SLOT( updateButtons() ));
205     connect( myCoordList,      SIGNAL( itemSelectionChanged()), SLOT( updateButtons() ));
206     connect( myStepSpin,       SIGNAL( valueChanged(double)),   SLOT( onStepChange() ));
207   }
208
209   void GridAxisTab::onInsert()
210   {
211     if ( isGridBySpacing() )
212     {
213       QTreeWidgetItem * item = mySpacingTreeWdg->currentItem();
214       if ( !item ) item = mySpacingTreeWdg->topLevelItem( 0 );
215       int i = mySpacingTreeWdg->indexOfTopLevelItem( item );
216
217       double t0, t1; QString fun;
218       getFromItem( item, t0, t1, fun );
219       double t = 0.5 * ( t0 + t1 );
220       setToItem( t0, t, fun, item );
221
222       item = setToItem( t, t1, fun );
223       if ( i == mySpacingTreeWdg->topLevelItemCount()-1 )
224         mySpacingTreeWdg->addTopLevelItem( item );
225       else
226         mySpacingTreeWdg->insertTopLevelItem( i+1, item );
227       mySpacingTreeWdg->setCurrentItem( item );
228     }
229     else
230     {
231       if ( myCoordList->count() == 0 )
232       {
233         myCoordList->addItem( coordToItem( 0 ));
234       }
235       else
236       {
237         double coord = coordFromItem( myCoordList->currentItem() ) + myStep;
238         int i = myCoordList->currentRow();
239         while ( i > 0 && coordFromItem( myCoordList->item( i-1 )) > coord )
240           --i;
241         while ( i < myCoordList->count() && coordFromItem( myCoordList->item( i )) < coord )
242           ++i;
243         const double tol = 1e-6;
244         const bool isSame = 
245           ( i < myCoordList->count() && coordFromItem( myCoordList->item( i )) - coord < tol ) ||
246           ( i > 0 && coord - coordFromItem( myCoordList->item( i-1 )) < tol );
247         if ( !isSame )
248           myCoordList->insertItem( i, coordToItem( coord ));
249         else if ( myStep < 0 )
250           --i;
251         myCoordList->setCurrentRow( i );
252       }
253     }
254     updateButtons();
255   }
256
257   void GridAxisTab::onDelete()
258   {
259     if ( isGridBySpacing() )
260     {
261       QList<QTreeWidgetItem *> selItems = mySpacingTreeWdg->selectedItems();
262       QTreeWidgetItem * item;
263       foreach ( item, selItems )
264       {
265         int i = mySpacingTreeWdg->indexOfTopLevelItem( item );
266         if ( i == 0 ) continue; 
267         QTreeWidgetItem* prevItem = mySpacingTreeWdg->topLevelItem( i-1 );
268
269         double t0, t1, t2; QString fun;
270         getFromItem( item, t1, t2, fun );
271         getFromItem( prevItem, t0, t1, fun );
272         delete item;
273
274         setToItem( t0, t2, fun, prevItem );
275       }
276     }
277     else
278     {
279       if ( myCoordList->count() > 2 )
280         if ( QListWidgetItem * item = myCoordList->currentItem() )
281           delete item;
282     }
283     updateButtons();
284   }
285
286   void GridAxisTab::onMode(int isSpacing)
287   {
288     mySpacingTreeWdg->setShown( isSpacing );
289     myCoordList->setShown( !isSpacing );
290     myStepSpin->setShown( !isSpacing );
291     myStepLabel->setShown( !isSpacing );
292     if ( isSpacing )
293     {
294       if ( mySpacingTreeWdg->topLevelItemCount() == 0 )
295       {
296         QString spacing( "1" );
297         if ( myCoordList->count() > 1 )
298         {
299           double c1 = coordFromItem( myCoordList->item( 1 ));
300           double c0 = coordFromItem( myCoordList->item( 0 ));
301           spacing = QString::number( c1 - c0 );
302         }
303         mySpacingTreeWdg->addTopLevelItem( setToItem( 0., 1., spacing ) );
304       }
305       myCoordList->clear();
306     }
307     else
308     {
309       mySpacingTreeWdg->clear();
310       if ( myCoordList->count() == 0 )
311         myCoordList->addItem( coordToItem( 0 ));
312     }
313     updateButtons();
314   }
315
316   void GridAxisTab::onStepChange()
317   {
318     if ( fabs( myStepSpin->GetValue() ) < 1e-100 )
319     {
320       double delta = myStepSpin->singleStep() * ( myStep > myStepSpin->GetValue() ? -1 : +1 );
321       myStepSpin->SetValue( myStepSpin->GetValue() + delta );
322     }
323     myStep = myStepSpin->GetValue();
324   }
325
326   void GridAxisTab::updateButtons()
327   {
328     bool insertEnable = false, deleteEnable = false;
329     if ( isGridBySpacing() )
330     {
331       insertEnable = true;
332       const int nbSelected = mySpacingTreeWdg->selectedItems().count();
333       if ( nbSelected > 0 )
334       {
335         // we delete a current range by uniting it with the previous
336         int i = mySpacingTreeWdg->indexOfTopLevelItem(  mySpacingTreeWdg->currentItem() );
337         deleteEnable = ( i > 0 );
338       }
339     }
340     else
341     {
342       const int nbSelected = myCoordList->selectedItems().count();
343       insertEnable = ( nbSelected || myCoordList->count() < 2 );
344       deleteEnable = ( nbSelected && myCoordList->count() > 2 );
345     }
346     myInsertBtn->setEnabled( insertEnable );
347     myDeleteBtn->setEnabled( deleteEnable );
348   }
349
350   void GridAxisTab::setCoordinates( SMESH::double_array_var coords )
351   {
352     myCoordList->clear();
353     for ( size_t i = 0; i < coords->length(); ++i )
354       myCoordList->addItem( coordToItem( coords[i] ));
355
356     myModeGroup->button( COORD_BUT )->setChecked( true );
357     onMode( COORD_BUT );
358   }
359
360   void GridAxisTab::setSpacing( SMESH::string_array_var funs, SMESH::double_array_var points )
361   {
362     mySpacingTreeWdg->clear();
363     if ( funs->length() == points->length() - 1 )
364     {
365       for ( size_t i = 1; i < points->length(); ++i )
366         mySpacingTreeWdg->addTopLevelItem
367           ( setToItem( points[i-1], points[i], (const char*) funs[i-1] ));
368     }
369     myModeGroup->button( SPACING_BUT )->setChecked( true );
370     onMode( SPACING_BUT );
371   }
372
373   bool GridAxisTab::isGridBySpacing() const
374   {
375     return ( myModeGroup->checkedId() == SPACING_BUT );
376   }
377
378   SMESH::double_array* GridAxisTab::getCoordinates()
379   {
380     SMESH::double_array_var coords = new SMESH::double_array;
381     coords->length( myCoordList->count() );
382     for ( size_t i = 0; i < coords->length(); ++i )
383       coords[i] = coordFromItem( myCoordList->item( i ) );
384
385     return coords._retn();
386   }
387
388   void GridAxisTab::getSpacing(SMESH::string_array_out funs,
389                                SMESH::double_array_out points) const
390   {
391     funs =  new SMESH::string_array();
392     points = new SMESH::double_array();
393     funs->length( mySpacingTreeWdg->topLevelItemCount() );
394     points->length( mySpacingTreeWdg->topLevelItemCount() + 1 );
395     double t0, t1; QString fun;
396     for ( size_t i = 0; i < funs->length(); ++i )
397     {
398       QTreeWidgetItem* item = mySpacingTreeWdg->topLevelItem( i );
399       getFromItem( item, t0, t1, fun );
400       points[i] = t0;
401       funs[i] = fun.toLatin1().constData();
402     }
403     points[ points->length()-1 ] = 1.0;
404   }
405
406
407   bool GridAxisTab::checkParams(QString& msg, SMESH::SMESH_Hypothesis_var& hyp) const
408   {
409     if ( isGridBySpacing() )
410     {
411       if ( mySpacingTreeWdg->topLevelItemCount() == 0 )
412         return false; // how could it be?
413       StdMeshers::StdMeshers_CartesianParameters3D_var h =
414         StdMeshers::StdMeshers_CartesianParameters3D::_narrow( hyp );
415       SMESH::string_array_var funs;
416       SMESH::double_array_var points;
417       getSpacing( funs.out(), points.out() );
418       try {
419         const char* axisName[3] = { "X", "Y", "Z" };
420         SMESH::double_array_var coords =
421           h->ComputeCoordinates(0.,1., funs, points, axisName[ myAxisIndex ]);
422       }
423       catch ( const SALOME::SALOME_Exception& ex ) {
424         msg = (const char*) ex.details.text;
425         return false;
426       }
427     }
428     else
429     {
430       return myCoordList->count() > 1;
431     }
432     return true;
433   }
434
435   LineDelegate::LineDelegate( QWidget* parent ):
436     QItemDelegate( parent ),
437     mySpacingTreeWdg( qobject_cast<QTreeWidget*>( parent )),
438     myCoordList( qobject_cast<QListWidget*>( parent ))
439   {
440   }
441
442   QWidget* LineDelegate::createEditor( QWidget*                    parent,
443                                        const QStyleOptionViewItem& opt,
444                                        const QModelIndex&          index) const
445   {
446     QWidget* w = 0;
447     if ( mySpacingTreeWdg )
448     {
449       if ( index.column() == 0 &&
450            index.row() != mySpacingTreeWdg->topLevelItemCount()-1 )
451       {
452         SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox( parent );
453         sb->setAcceptNames( false ); // No Notebook variables allowed
454         sb->setFrame( false );
455         w = sb;
456       }
457       if ( index.column() == 1 ) {
458         w = new QLineEdit( parent );
459       }
460     }
461     else
462     {
463       SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox( parent );
464       sb->setAcceptNames( false ); // No Notebook variables allowed
465       sb->setFrame( false );
466       const double tol = 1e-5;
467       double from = index.row() ? coordFromItem( myCoordList->item( index.row()-1 ))+tol : -1e+6;
468       double to = index.row() == myCoordList->count()-1 ? 1e+6 : coordFromItem( myCoordList->item( index.row()+1 ))-tol;
469       sb->RangeStepAndValidator( from, to, 0.01 );
470       w = sb;
471     }
472     return w;
473   }
474
475   void LineDelegate::setEditorData ( QWidget * editor, const QModelIndex & index ) const
476   {
477     if ( mySpacingTreeWdg && index.column() == 0 )
478     {
479       double t0, t1, t2=1.0; QString fun;
480       QTreeWidgetItem* item = mySpacingTreeWdg->topLevelItem( index.row() );
481       getFromItem( item, t0, t1, fun );
482       if ( index.row() != mySpacingTreeWdg->topLevelItemCount()-1 )
483       {
484         item = mySpacingTreeWdg->topLevelItem( index.row()+1 );
485         getFromItem( item, t1, t2, fun );
486       }
487       const double tol = 1e-3;
488       SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( editor );
489       sb->RangeStepAndValidator( t0 + tol, t2 - tol, 0.01 );
490       sb->SetValue( t1 );
491     }
492     else
493     {
494       QItemDelegate::setEditorData( editor, index );
495     }
496   }
497   void LineDelegate::setModelData( QWidget*            editor,
498                                    QAbstractItemModel* model,
499                                    const QModelIndex&  index ) const
500   {
501     if ( mySpacingTreeWdg )
502     {
503       if ( index.column() == 0 )
504       {
505         if ( index.row() != mySpacingTreeWdg->topLevelItemCount()-1 )
506         {
507           SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( editor );
508           double t0, t1, t = sb->GetValue(); QString fun;
509
510           QTreeWidgetItem* item = mySpacingTreeWdg->topLevelItem( index.row() );
511           getFromItem( item, t0, t1, fun );
512           setToItem( t0, t, fun, item );
513
514           item = mySpacingTreeWdg->topLevelItem( index.row() + 1 );
515           getFromItem( item, t0, t1, fun );
516           setToItem( t, t1, fun, item );
517         }
518       }
519       else if ( !qobject_cast<QLineEdit*>(editor)->text().trimmed().isEmpty() )
520       {
521         QItemDelegate::setModelData( editor, model, index );
522       }
523     }
524     else
525     {
526       SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( editor );
527       coordToItem( sb->GetValue(), myCoordList->item( index.row() ));
528     }
529   }
530
531 } // namespace StdMeshersGUI
532
533
534 StdMeshersGUI_CartesianParamCreator::StdMeshersGUI_CartesianParamCreator(const QString& aHypType)
535   : StdMeshersGUI_StdHypothesisCreator( aHypType ),
536     myThreshold( 0 )
537 {
538   myAxisTabs[0] = 0;
539   myAxisTabs[1] = 0;
540   myAxisTabs[2] = 0;
541 }
542
543 StdMeshersGUI_CartesianParamCreator::~StdMeshersGUI_CartesianParamCreator()
544 {
545   if ( myAxisTabs[0] ) delete myAxisTabs[0];
546   if ( myAxisTabs[1] ) delete myAxisTabs[1];
547   if ( myAxisTabs[2] ) delete myAxisTabs[2];
548   myAxisTabs[0] = 0;
549   myAxisTabs[1] = 0;
550   myAxisTabs[2] = 0;
551 }
552
553 bool StdMeshersGUI_CartesianParamCreator::checkParams( QString& msg ) const
554 {
555   if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
556     return false;
557
558   if ( myName && myName->text().trimmed().isEmpty() )
559   {
560     msg = tr("SMESH_WRN_EMPTY_NAME");
561     return false;
562   }
563   if ( ! myThreshold->isValid( msg, true ))
564     return false;
565
566   SMESH::SMESH_Hypothesis_var hyp = hypothesis();
567   if ( !myAxisTabs[0]->checkParams( msg, hyp )) return false;
568   if ( !myAxisTabs[1]->checkParams( msg, hyp )) return false;
569   if ( !myAxisTabs[2]->checkParams( msg, hyp )) return false;
570
571   return true;
572 }
573
574 QFrame* StdMeshersGUI_CartesianParamCreator::buildFrame()
575 {
576   QFrame* fr = new QFrame();
577   //fr->setMinimumWidth(460);
578
579   QVBoxLayout* lay = new QVBoxLayout( fr );
580   lay->setMargin( 0 );
581   lay->setSpacing( SPACING );
582
583   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
584   lay->addWidget( GroupC1 );
585
586   StdMeshers::StdMeshers_NumberOfSegments_var h =
587     StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
588
589   QGridLayout* argGroupLayout = new QGridLayout( GroupC1 );
590   argGroupLayout->setSpacing( SPACING );
591   argGroupLayout->setMargin( MARGIN );
592   argGroupLayout->setColumnStretch( 0, 0 );
593   argGroupLayout->setColumnStretch( 1, 1 );
594
595   int row = 0;
596   // 0)  name
597   myName = 0;
598   if( isCreation() )
599   {
600     myName = new QLineEdit( GroupC1 );
601     argGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
602     argGroupLayout->addWidget( myName, row, 1 );
603     row++;
604   }
605
606   // 1)  threshold
607   argGroupLayout->addWidget( new QLabel( tr( "THRESHOLD" ), GroupC1 ), row, 0 );
608   myThreshold = new SMESHGUI_SpinBox( GroupC1 );
609   myThreshold->setAcceptNames( false ); // No Notebook variables allowed
610   myThreshold->RangeStepAndValidator( 1.1, 1e+10, 1., "length_precision" );
611   argGroupLayout->addWidget( myThreshold, row, 1 );
612   row++;
613   
614   // 2)  Grid definition
615   QTabWidget* tabWdg = new QTabWidget( fr );
616   myAxisTabs[ 0 ] = new StdMeshersGUI::GridAxisTab( tabWdg, 0 );
617   myAxisTabs[ 1 ] = new StdMeshersGUI::GridAxisTab( tabWdg, 1 );
618   myAxisTabs[ 2 ] = new StdMeshersGUI::GridAxisTab( tabWdg, 2 );
619   tabWdg->addTab( myAxisTabs[ 0 ], tr( "AXIS_X" ) );
620   tabWdg->addTab( myAxisTabs[ 1 ], tr( "AXIS_Y" ) );
621   tabWdg->addTab( myAxisTabs[ 2 ], tr( "AXIS_Z" ) );
622   argGroupLayout->addWidget( tabWdg, row, 0, 1, 2 );
623
624   return fr;
625 }
626
627 void StdMeshersGUI_CartesianParamCreator::retrieveParams() const
628 {
629   StdMeshers::StdMeshers_CartesianParameters3D_var h =
630     StdMeshers::StdMeshers_CartesianParameters3D::_narrow( initParamsHypothesis() );
631
632   if( myName )
633     myName->setText( hypName() );
634
635   QString varName = getVariableName( "SetSizeThreshold" );
636   if ( varName.isEmpty() )
637     myThreshold->setValue( h->GetSizeThreshold() );
638   else
639     myThreshold->setText( varName );
640
641   for ( int ax = 0; ax < 3; ++ax )
642   {
643     if ( h->IsGridBySpacing( ax ))
644     {
645       SMESH::string_array_var funs;
646       SMESH::double_array_var intPoints;
647       h->GetGridSpacing( funs.out(), intPoints.out(), ax );
648       myAxisTabs[ax]->setSpacing( funs, intPoints );
649     }
650     else
651     {
652       SMESH::double_array_var coords = h->GetGrid( ax );
653       myAxisTabs[ax]->setCoordinates( coords );
654     }
655   }
656   if ( dlg() )
657     dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
658 }
659
660 QString StdMeshersGUI_CartesianParamCreator::storeParams() const
661 {
662   StdMeshers::StdMeshers_CartesianParameters3D_var h =
663     StdMeshers::StdMeshers_CartesianParameters3D::_narrow( hypothesis() );
664
665   try
666   {
667     if( isCreation() )
668       SMESH::SetName( SMESH::FindSObject( h ), myName->text().toLatin1().constData() );
669
670     h->SetVarParameter( myThreshold->text().toLatin1().constData(), "SetSizeThreshold" );
671     h->SetSizeThreshold( myThreshold->text().toDouble() );
672
673     for ( int ax = 0; ax < 3; ++ax )
674     {
675       if ( myAxisTabs[ax]->isGridBySpacing())
676       {
677         SMESH::double_array_var intPoints;
678         SMESH::string_array_var funs;
679         myAxisTabs[ax]->getSpacing( funs.out(), intPoints.out() );
680         h->SetGridSpacing( funs, intPoints, ax );
681       }
682       else
683       {
684         SMESH::double_array_var coords = myAxisTabs[ax]->getCoordinates();
685         h->SetGrid( coords, ax );
686       }
687     }
688   }
689   catch(const SALOME::SALOME_Exception& ex)
690   {
691     SalomeApp_Tools::QtCatchCorbaException(ex);
692   }
693   return "";
694 }
695
696 QString StdMeshersGUI_CartesianParamCreator::helpPage() const
697 {
698   return "cartesian_algo_page.html#cartesian_hyp_anchor";
699 }