Back to index

salome-smesh  6.5.0
StdMeshersGUI_CartesianParamCreator.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : StdMeshersGUI_CartesianParamCreator.cxx
00024 // Author : Open CASCADE S.A.S.
00025 // SMESH includes
00026 //
00027 #include "StdMeshersGUI_CartesianParamCreator.h"
00028 
00029 #include <SMESHGUI.h>
00030 #include <SMESHGUI_Utils.h>
00031 #include <SMESHGUI_HypothesesUtils.h>
00032 #include <SMESHGUI_SpinBox.h>
00033 
00034 // IDL includes
00035 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
00036 
00037 // SALOME GUI includes
00038 #include <SalomeApp_Tools.h>
00039 #include <SalomeApp_IntSpinBox.h>
00040 #include <QtxComboBox.h>
00041 
00042 // Qt includes
00043 #include <QAbstractItemModel>
00044 #include <QApplication>
00045 #include <QButtonGroup>
00046 #include <QGridLayout>
00047 #include <QGroupBox>
00048 #include <QHBoxLayout>
00049 #include <QLabel>
00050 #include <QLineEdit>
00051 #include <QListWidget>
00052 #include <QModelIndex>
00053 #include <QRadioButton>
00054 #include <QString>
00055 #include <QStyleOptionViewItem>
00056 #include <QTreeWidget>
00057 #include <QTreeWidgetItem>
00058 #include <QVBoxLayout>
00059 #include <QPushButton>
00060 #include <QTabWidget>
00061 
00062 #define SPACING 6
00063 #define MARGIN  11
00064 
00065 namespace StdMeshersGUI
00066 {
00067   enum { COORD_BUT = 0, SPACING_BUT };
00068 
00069   //================================================================================
00073   //================================================================================
00074 
00075   void getFromItem(QTreeWidgetItem * item, double& t0, double& t1, QString& fun )
00076   {
00077     if ( item )
00078     {
00079       t0 = item->text( 0 ).split(' ')[0].toDouble();
00080       t1 = item->data( 0, Qt::UserRole ).toDouble();
00081       fun = item->text( 1 );
00082     }
00083   }
00084 
00085   //================================================================================
00089   //================================================================================
00090 
00091   QTreeWidgetItem* setToItem(double t0, double t1, const QString& fun, QTreeWidgetItem * item)
00092   {
00093     if ( !item ) item = new QTreeWidgetItem;
00094     item->setText( 0, QString( "%1 - %2" ).arg( t0 ).arg( t1 ));
00095     item->setData( 0, Qt::UserRole, t1 );
00096     item->setText( 1, fun );
00097     item->setFlags( item->flags() | Qt::ItemIsEditable );
00098     return item;
00099   }
00100 
00101   //================================================================================
00105   //================================================================================
00106 
00107   double coordFromItem( QListWidgetItem * item )
00108   {
00109     return item ? item->data( Qt::UserRole ).toDouble() : 0;
00110   }
00111 
00112   //================================================================================
00116   //================================================================================
00117 
00118   QListWidgetItem* coordToItem( double coord, QListWidgetItem * item )
00119   {
00120     if ( !item ) item = new QListWidgetItem;
00121     item->setText( QString::number( coord ));
00122     item->setData( Qt::UserRole, coord );
00123     item->setFlags( item->flags() | Qt::ItemIsEditable );
00124     return item;
00125   }
00126 
00127   //================================================================================
00134   //================================================================================
00135 
00136   GridAxisTab::GridAxisTab( QWidget* theParent,const int axisIndex ):
00137     QFrame( theParent ), myAxisIndex( axisIndex )
00138   {
00139     // 1) Grid definition mode
00140     myModeGroup = new QButtonGroup( this );
00141     QGroupBox* modeBox = new QGroupBox( tr( "GRID_DEF_MODE" ), this );
00142     QHBoxLayout* modeLay = new QHBoxLayout( modeBox );
00143     modeLay->setMargin( MARGIN );
00144     modeLay->setSpacing( SPACING );
00145 
00146     QRadioButton* coordModeBtn = new QRadioButton( tr( "SMESH_COORDINATES" ), modeBox );
00147     QRadioButton* spacModeBtn  = new QRadioButton( tr( "SPACING" ), modeBox );
00148 
00149     modeLay->addWidget( coordModeBtn );
00150     modeLay->addWidget( spacModeBtn );
00151     myModeGroup->addButton( coordModeBtn, COORD_BUT );
00152     myModeGroup->addButton( spacModeBtn,  SPACING_BUT );
00153 
00154     // 2) Buttons + Step
00155     myInsertBtn = new QPushButton( tr("INSERT"), this);
00156     myDeleteBtn = new QPushButton( tr("SMESH_BUT_DELETE"), this);
00157 
00158     myStepLabel = new QLabel( tr("COORD_STEP"));
00159     myStepSpin  = new SMESHGUI_SpinBox( this );
00160     myStepSpin->setAcceptNames( false ); // No Notebook variables allowed
00161     myStepSpin->RangeStepAndValidator();
00162     myStepSpin->SetStep( 1. );
00163     myStepSpin->SetValue( myStep = 1. );
00164 
00165     // 3) Coodrinates/Spacing group
00166     QFrame* csFrame = new QFrame( this );
00167     QVBoxLayout* scLay = new QVBoxLayout( csFrame );
00168     scLay->setMargin( 0 );
00169     scLay->setSpacing( SPACING );
00170 
00171     // 3.1) Spacing
00172     mySpacingTreeWdg = new QTreeWidget( csFrame );
00173     mySpacingTreeWdg->setColumnCount(2);
00174     mySpacingTreeWdg->setHeaderLabels( QStringList() << tr( "SMESH_RANGE" ) << QString( "f(t)" ));
00175     mySpacingTreeWdg->setColumnWidth( 1, 40 );
00176     mySpacingTreeWdg->setColumnWidth( 2, 30 );
00177     mySpacingTreeWdg->setItemDelegate( new LineDelegate( mySpacingTreeWdg ));
00178     scLay->addWidget( mySpacingTreeWdg );
00179 
00180     // 3.2) Coordinates
00181     myCoordList = new QListWidget( csFrame );
00182     myCoordList->setItemDelegate( new LineDelegate( myCoordList ));
00183     scLay->addWidget( myCoordList );
00184 
00185     // layouting
00186 
00187     QGridLayout* axisTabLayout = new QGridLayout( this );
00188     axisTabLayout->setMargin( MARGIN );
00189     axisTabLayout->setSpacing( SPACING );
00190 
00191     axisTabLayout->addWidget( modeBox    , 0, 0, 1, 3 );
00192     axisTabLayout->addWidget( myInsertBtn  , 1, 0, 1, 2 );
00193     axisTabLayout->addWidget( myDeleteBtn  , 2, 0, 1, 2 );
00194     axisTabLayout->addWidget( myStepLabel, 3, 0 );
00195     axisTabLayout->addWidget( myStepSpin , 3, 1 );
00196     axisTabLayout->addWidget( csFrame    , 1, 2, 4, 1 );
00197 
00198     axisTabLayout->setRowStretch( 4, 1 );
00199 
00200     // signals
00201     connect( myInsertBtn,      SIGNAL( clicked() ),             SLOT( onInsert() ));
00202     connect( myDeleteBtn,      SIGNAL( clicked() ),             SLOT( onDelete() ));
00203     connect( myModeGroup,      SIGNAL( buttonClicked ( int )),  SLOT( onMode(int)));
00204     connect( mySpacingTreeWdg, SIGNAL( itemSelectionChanged()), SLOT( updateButtons() ));
00205     connect( myCoordList,      SIGNAL( itemSelectionChanged()), SLOT( updateButtons() ));
00206     connect( myStepSpin,       SIGNAL( valueChanged(double)),   SLOT( onStepChange() ));
00207   }
00208 
00209   void GridAxisTab::onInsert()
00210   {
00211     if ( isGridBySpacing() )
00212     {
00213       QTreeWidgetItem * item = mySpacingTreeWdg->currentItem();
00214       if ( !item ) item = mySpacingTreeWdg->topLevelItem( 0 );
00215       int i = mySpacingTreeWdg->indexOfTopLevelItem( item );
00216 
00217       double t0, t1; QString fun;
00218       getFromItem( item, t0, t1, fun );
00219       double t = 0.5 * ( t0 + t1 );
00220       setToItem( t0, t, fun, item );
00221 
00222       item = setToItem( t, t1, fun );
00223       if ( i == mySpacingTreeWdg->topLevelItemCount()-1 )
00224         mySpacingTreeWdg->addTopLevelItem( item );
00225       else
00226         mySpacingTreeWdg->insertTopLevelItem( i+1, item );
00227       mySpacingTreeWdg->setCurrentItem( item );
00228     }
00229     else
00230     {
00231       if ( myCoordList->count() == 0 )
00232       {
00233         myCoordList->addItem( coordToItem( 0 ));
00234       }
00235       else
00236       {
00237         double coord = coordFromItem( myCoordList->currentItem() ) + myStep;
00238         int i = myCoordList->currentRow();
00239         while ( i > 0 && coordFromItem( myCoordList->item( i-1 )) > coord )
00240           --i;
00241         while ( i < myCoordList->count() && coordFromItem( myCoordList->item( i )) < coord )
00242           ++i;
00243         const double tol = 1e-6;
00244         const bool isSame = 
00245           ( i < myCoordList->count() && coordFromItem( myCoordList->item( i )) - coord < tol ) ||
00246           ( i > 0 && coord - coordFromItem( myCoordList->item( i-1 )) < tol );
00247         if ( !isSame )
00248           myCoordList->insertItem( i, coordToItem( coord ));
00249         else if ( myStep < 0 )
00250           --i;
00251         myCoordList->setCurrentRow( i );
00252       }
00253     }
00254     updateButtons();
00255   }
00256 
00257   void GridAxisTab::onDelete()
00258   {
00259     if ( isGridBySpacing() )
00260     {
00261       QList<QTreeWidgetItem *> selItems = mySpacingTreeWdg->selectedItems();
00262       QTreeWidgetItem * item;
00263       foreach ( item, selItems )
00264       {
00265         int i = mySpacingTreeWdg->indexOfTopLevelItem( item );
00266         if ( i == 0 ) continue; 
00267         QTreeWidgetItem* prevItem = mySpacingTreeWdg->topLevelItem( i-1 );
00268 
00269         double t0, t1, t2; QString fun;
00270         getFromItem( item, t1, t2, fun );
00271         getFromItem( prevItem, t0, t1, fun );
00272         delete item;
00273 
00274         setToItem( t0, t2, fun, prevItem );
00275       }
00276     }
00277     else
00278     {
00279       if ( myCoordList->count() > 2 )
00280         if ( QListWidgetItem * item = myCoordList->currentItem() )
00281           delete item;
00282     }
00283     updateButtons();
00284   }
00285 
00286   void GridAxisTab::onMode(int isSpacing)
00287   {
00288     mySpacingTreeWdg->setShown( isSpacing );
00289     myCoordList->setShown( !isSpacing );
00290     myStepSpin->setShown( !isSpacing );
00291     myStepLabel->setShown( !isSpacing );
00292     if ( isSpacing )
00293     {
00294       if ( mySpacingTreeWdg->topLevelItemCount() == 0 )
00295       {
00296         QString spacing( "1" );
00297         if ( myCoordList->count() > 1 )
00298         {
00299           double c1 = coordFromItem( myCoordList->item( 1 ));
00300           double c0 = coordFromItem( myCoordList->item( 0 ));
00301           spacing = QString::number( c1 - c0 );
00302         }
00303         mySpacingTreeWdg->addTopLevelItem( setToItem( 0., 1., spacing ) );
00304       }
00305       myCoordList->clear();
00306     }
00307     else
00308     {
00309       mySpacingTreeWdg->clear();
00310       if ( myCoordList->count() == 0 )
00311         myCoordList->addItem( coordToItem( 0 ));
00312     }
00313     updateButtons();
00314   }
00315 
00316   void GridAxisTab::onStepChange()
00317   {
00318     if ( fabs( myStepSpin->GetValue() ) < 1e-100 )
00319     {
00320       double delta = myStepSpin->singleStep() * ( myStep > myStepSpin->GetValue() ? -1 : +1 );
00321       myStepSpin->SetValue( myStepSpin->GetValue() + delta );
00322     }
00323     myStep = myStepSpin->GetValue();
00324   }
00325 
00326   void GridAxisTab::updateButtons()
00327   {
00328     bool insertEnable = false, deleteEnable = false;
00329     if ( isGridBySpacing() )
00330     {
00331       insertEnable = true;
00332       const int nbSelected = mySpacingTreeWdg->selectedItems().count();
00333       if ( nbSelected > 0 )
00334       {
00335         // we delete a current range by uniting it with the previous
00336         int i = mySpacingTreeWdg->indexOfTopLevelItem(  mySpacingTreeWdg->currentItem() );
00337         deleteEnable = ( i > 0 );
00338       }
00339     }
00340     else
00341     {
00342       const int nbSelected = myCoordList->selectedItems().count();
00343       insertEnable = ( nbSelected || myCoordList->count() < 2 );
00344       deleteEnable = ( nbSelected && myCoordList->count() > 2 );
00345     }
00346     myInsertBtn->setEnabled( insertEnable );
00347     myDeleteBtn->setEnabled( deleteEnable );
00348   }
00349 
00350   void GridAxisTab::setCoordinates( SMESH::double_array_var coords )
00351   {
00352     myCoordList->clear();
00353     for ( size_t i = 0; i < coords->length(); ++i )
00354       myCoordList->addItem( coordToItem( coords[i] ));
00355 
00356     myModeGroup->button( COORD_BUT )->setChecked( true );
00357     onMode( COORD_BUT );
00358   }
00359 
00360   void GridAxisTab::setSpacing( SMESH::string_array_var funs, SMESH::double_array_var points )
00361   {
00362     mySpacingTreeWdg->clear();
00363     if ( funs->length() == points->length() - 1 )
00364     {
00365       for ( size_t i = 1; i < points->length(); ++i )
00366         mySpacingTreeWdg->addTopLevelItem
00367           ( setToItem( points[i-1], points[i], (const char*) funs[i-1] ));
00368     }
00369     myModeGroup->button( SPACING_BUT )->setChecked( true );
00370     onMode( SPACING_BUT );
00371   }
00372 
00373   bool GridAxisTab::isGridBySpacing() const
00374   {
00375     return ( myModeGroup->checkedId() == SPACING_BUT );
00376   }
00377 
00378   SMESH::double_array* GridAxisTab::getCoordinates()
00379   {
00380     SMESH::double_array_var coords = new SMESH::double_array;
00381     coords->length( myCoordList->count() );
00382     for ( size_t i = 0; i < coords->length(); ++i )
00383       coords[i] = coordFromItem( myCoordList->item( i ) );
00384 
00385     return coords._retn();
00386   }
00387 
00388   void GridAxisTab::getSpacing(SMESH::string_array_out funs,
00389                                SMESH::double_array_out points) const
00390   {
00391     funs =  new SMESH::string_array();
00392     points = new SMESH::double_array();
00393     funs->length( mySpacingTreeWdg->topLevelItemCount() );
00394     points->length( mySpacingTreeWdg->topLevelItemCount() + 1 );
00395     double t0, t1; QString fun;
00396     for ( size_t i = 0; i < funs->length(); ++i )
00397     {
00398       QTreeWidgetItem* item = mySpacingTreeWdg->topLevelItem( i );
00399       getFromItem( item, t0, t1, fun );
00400       points[i] = t0;
00401       funs[i] = fun.toLatin1().constData();
00402     }
00403     points[ points->length()-1 ] = 1.0;
00404   }
00405 
00406 
00407   bool GridAxisTab::checkParams(QString& msg, SMESH::SMESH_Hypothesis_var& hyp) const
00408   {
00409     if ( isGridBySpacing() )
00410     {
00411       if ( mySpacingTreeWdg->topLevelItemCount() == 0 )
00412         return false; // how could it be?
00413       StdMeshers::StdMeshers_CartesianParameters3D_var h =
00414         StdMeshers::StdMeshers_CartesianParameters3D::_narrow( hyp );
00415       SMESH::string_array_var funs;
00416       SMESH::double_array_var points;
00417       getSpacing( funs.out(), points.out() );
00418       try {
00419         const char* axisName[3] = { "X", "Y", "Z" };
00420         SMESH::double_array_var coords =
00421           h->ComputeCoordinates(0.,1., funs, points, axisName[ myAxisIndex ]);
00422       }
00423       catch ( const SALOME::SALOME_Exception& ex ) {
00424         msg = (const char*) ex.details.text;
00425         return false;
00426       }
00427     }
00428     else
00429     {
00430       return myCoordList->count() > 1;
00431     }
00432     return true;
00433   }
00434 
00435   LineDelegate::LineDelegate( QWidget* parent ):
00436     QItemDelegate( parent ),
00437     mySpacingTreeWdg( qobject_cast<QTreeWidget*>( parent )),
00438     myCoordList( qobject_cast<QListWidget*>( parent ))
00439   {
00440   }
00441 
00442   QWidget* LineDelegate::createEditor( QWidget*                    parent,
00443                                        const QStyleOptionViewItem& opt,
00444                                        const QModelIndex&          index) const
00445   {
00446     QWidget* w = 0;
00447     if ( mySpacingTreeWdg )
00448     {
00449       if ( index.column() == 0 &&
00450            index.row() != mySpacingTreeWdg->topLevelItemCount()-1 )
00451       {
00452         SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox( parent );
00453         sb->setAcceptNames( false ); // No Notebook variables allowed
00454         sb->setFrame( false );
00455         w = sb;
00456       }
00457       if ( index.column() == 1 ) {
00458         w = new QLineEdit( parent );
00459       }
00460     }
00461     else
00462     {
00463       SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox( parent );
00464       sb->setAcceptNames( false ); // No Notebook variables allowed
00465       sb->setFrame( false );
00466       const double tol = 1e-5;
00467       double from = index.row() ? coordFromItem( myCoordList->item( index.row()-1 ))+tol : -1e+6;
00468       double to = index.row() == myCoordList->count()-1 ? 1e+6 : coordFromItem( myCoordList->item( index.row()+1 ))-tol;
00469       sb->RangeStepAndValidator( from, to, 0.01 );
00470       w = sb;
00471     }
00472     return w;
00473   }
00474 
00475   void LineDelegate::setEditorData ( QWidget * editor, const QModelIndex & index ) const
00476   {
00477     if ( mySpacingTreeWdg && index.column() == 0 )
00478     {
00479       double t0, t1, t2=1.0; QString fun;
00480       QTreeWidgetItem* item = mySpacingTreeWdg->topLevelItem( index.row() );
00481       getFromItem( item, t0, t1, fun );
00482       if ( index.row() != mySpacingTreeWdg->topLevelItemCount()-1 )
00483       {
00484         item = mySpacingTreeWdg->topLevelItem( index.row()+1 );
00485         getFromItem( item, t1, t2, fun );
00486       }
00487       const double tol = 1e-3;
00488       SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( editor );
00489       sb->RangeStepAndValidator( t0 + tol, t2 - tol, 0.01 );
00490       sb->SetValue( t1 );
00491     }
00492     else
00493     {
00494       QItemDelegate::setEditorData( editor, index );
00495     }
00496   }
00497   void LineDelegate::setModelData( QWidget*            editor,
00498                                    QAbstractItemModel* model,
00499                                    const QModelIndex&  index ) const
00500   {
00501     if ( mySpacingTreeWdg )
00502     {
00503       if ( index.column() == 0 )
00504       {
00505         if ( index.row() != mySpacingTreeWdg->topLevelItemCount()-1 )
00506         {
00507           SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( editor );
00508           double t0, t1, t = sb->GetValue(); QString fun;
00509 
00510           QTreeWidgetItem* item = mySpacingTreeWdg->topLevelItem( index.row() );
00511           getFromItem( item, t0, t1, fun );
00512           setToItem( t0, t, fun, item );
00513 
00514           item = mySpacingTreeWdg->topLevelItem( index.row() + 1 );
00515           getFromItem( item, t0, t1, fun );
00516           setToItem( t, t1, fun, item );
00517         }
00518       }
00519       else if ( !qobject_cast<QLineEdit*>(editor)->text().trimmed().isEmpty() )
00520       {
00521         QItemDelegate::setModelData( editor, model, index );
00522       }
00523     }
00524     else
00525     {
00526       SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( editor );
00527       coordToItem( sb->GetValue(), myCoordList->item( index.row() ));
00528     }
00529   }
00530 
00531 } // namespace StdMeshersGUI
00532 
00533 
00534 StdMeshersGUI_CartesianParamCreator::StdMeshersGUI_CartesianParamCreator(const QString& aHypType)
00535   : StdMeshersGUI_StdHypothesisCreator( aHypType ),
00536     myThreshold( 0 )
00537 {
00538   myAxisTabs[0] = 0;
00539   myAxisTabs[1] = 0;
00540   myAxisTabs[2] = 0;
00541 }
00542 
00543 StdMeshersGUI_CartesianParamCreator::~StdMeshersGUI_CartesianParamCreator()
00544 {
00545   if ( myAxisTabs[0] ) delete myAxisTabs[0];
00546   if ( myAxisTabs[1] ) delete myAxisTabs[1];
00547   if ( myAxisTabs[2] ) delete myAxisTabs[2];
00548   myAxisTabs[0] = 0;
00549   myAxisTabs[1] = 0;
00550   myAxisTabs[2] = 0;
00551 }
00552 
00553 bool StdMeshersGUI_CartesianParamCreator::checkParams( QString& msg ) const
00554 {
00555   if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
00556     return false;
00557 
00558   if ( myName && myName->text().trimmed().isEmpty() )
00559   {
00560     msg = tr("SMESH_WRN_EMPTY_NAME");
00561     return false;
00562   }
00563   if ( ! myThreshold->isValid( msg, true ))
00564     return false;
00565 
00566   SMESH::SMESH_Hypothesis_var hyp = hypothesis();
00567   if ( !myAxisTabs[0]->checkParams( msg, hyp )) return false;
00568   if ( !myAxisTabs[1]->checkParams( msg, hyp )) return false;
00569   if ( !myAxisTabs[2]->checkParams( msg, hyp )) return false;
00570 
00571   return true;
00572 }
00573 
00574 QFrame* StdMeshersGUI_CartesianParamCreator::buildFrame()
00575 {
00576   QFrame* fr = new QFrame();
00577   //fr->setMinimumWidth(460);
00578 
00579   QVBoxLayout* lay = new QVBoxLayout( fr );
00580   lay->setMargin( 0 );
00581   lay->setSpacing( SPACING );
00582 
00583   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
00584   lay->addWidget( GroupC1 );
00585 
00586   StdMeshers::StdMeshers_NumberOfSegments_var h =
00587     StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
00588 
00589   QGridLayout* argGroupLayout = new QGridLayout( GroupC1 );
00590   argGroupLayout->setSpacing( SPACING );
00591   argGroupLayout->setMargin( MARGIN );
00592   argGroupLayout->setColumnStretch( 0, 0 );
00593   argGroupLayout->setColumnStretch( 1, 1 );
00594 
00595   int row = 0;
00596   // 0)  name
00597   myName = 0;
00598   if( isCreation() )
00599   {
00600     myName = new QLineEdit( GroupC1 );
00601     argGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
00602     argGroupLayout->addWidget( myName, row, 1 );
00603     row++;
00604   }
00605 
00606   // 1)  threshold
00607   argGroupLayout->addWidget( new QLabel( tr( "THRESHOLD" ), GroupC1 ), row, 0 );
00608   myThreshold = new SMESHGUI_SpinBox( GroupC1 );
00609   myThreshold->setAcceptNames( false ); // No Notebook variables allowed
00610   myThreshold->RangeStepAndValidator( 1.1, 1e+10, 1., "length_precision" );
00611   argGroupLayout->addWidget( myThreshold, row, 1 );
00612   row++;
00613   
00614   // 2)  Grid definition
00615   QTabWidget* tabWdg = new QTabWidget( fr );
00616   myAxisTabs[ 0 ] = new StdMeshersGUI::GridAxisTab( tabWdg, 0 );
00617   myAxisTabs[ 1 ] = new StdMeshersGUI::GridAxisTab( tabWdg, 1 );
00618   myAxisTabs[ 2 ] = new StdMeshersGUI::GridAxisTab( tabWdg, 2 );
00619   tabWdg->addTab( myAxisTabs[ 0 ], tr( "AXIS_X" ) );
00620   tabWdg->addTab( myAxisTabs[ 1 ], tr( "AXIS_Y" ) );
00621   tabWdg->addTab( myAxisTabs[ 2 ], tr( "AXIS_Z" ) );
00622   argGroupLayout->addWidget( tabWdg, row, 0, 1, 2 );
00623 
00624   return fr;
00625 }
00626 
00627 void StdMeshersGUI_CartesianParamCreator::retrieveParams() const
00628 {
00629   StdMeshers::StdMeshers_CartesianParameters3D_var h =
00630     StdMeshers::StdMeshers_CartesianParameters3D::_narrow( initParamsHypothesis() );
00631 
00632   if( myName )
00633     myName->setText( hypName() );
00634 
00635   QString varName = getVariableName( "SetSizeThreshold" );
00636   if ( varName.isEmpty() )
00637     myThreshold->setValue( h->GetSizeThreshold() );
00638   else
00639     myThreshold->setText( varName );
00640 
00641   for ( int ax = 0; ax < 3; ++ax )
00642   {
00643     if ( h->IsGridBySpacing( ax ))
00644     {
00645       SMESH::string_array_var funs;
00646       SMESH::double_array_var intPoints;
00647       h->GetGridSpacing( funs.out(), intPoints.out(), ax );
00648       myAxisTabs[ax]->setSpacing( funs, intPoints );
00649     }
00650     else
00651     {
00652       SMESH::double_array_var coords = h->GetGrid( ax );
00653       myAxisTabs[ax]->setCoordinates( coords );
00654     }
00655   }
00656   if ( dlg() )
00657     dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
00658 }
00659 
00660 QString StdMeshersGUI_CartesianParamCreator::storeParams() const
00661 {
00662   StdMeshers::StdMeshers_CartesianParameters3D_var h =
00663     StdMeshers::StdMeshers_CartesianParameters3D::_narrow( hypothesis() );
00664 
00665   try
00666   {
00667     if( isCreation() )
00668       SMESH::SetName( SMESH::FindSObject( h ), myName->text().toLatin1().constData() );
00669 
00670     h->SetVarParameter( myThreshold->text().toLatin1().constData(), "SetSizeThreshold" );
00671     h->SetSizeThreshold( myThreshold->text().toDouble() );
00672 
00673     for ( int ax = 0; ax < 3; ++ax )
00674     {
00675       if ( myAxisTabs[ax]->isGridBySpacing())
00676       {
00677         SMESH::double_array_var intPoints;
00678         SMESH::string_array_var funs;
00679         myAxisTabs[ax]->getSpacing( funs.out(), intPoints.out() );
00680         h->SetGridSpacing( funs, intPoints, ax );
00681       }
00682       else
00683       {
00684         SMESH::double_array_var coords = myAxisTabs[ax]->getCoordinates();
00685         h->SetGrid( coords, ax );
00686       }
00687     }
00688   }
00689   catch(const SALOME::SALOME_Exception& ex)
00690   {
00691     SalomeApp_Tools::QtCatchCorbaException(ex);
00692   }
00693   return "";
00694 }
00695 
00696 QString StdMeshersGUI_CartesianParamCreator::helpPage() const
00697 {
00698   return "cartesian_algo_page.html#cartesian_hyp_anchor";
00699 }