Back to index

salome-smesh  6.5.0
Public Member Functions | Private Slots | Private Attributes
StdMeshersGUI::GridAxisTab Class Reference

Widget defining the grid in one direction. More...

#include <StdMeshersGUI_CartesianParamCreator.h>

List of all members.

Public Member Functions

 GridAxisTab (QWidget *parent, const int axisIndex)
 Constructor.
 ~GridAxisTab ()
void setCoordinates (SMESH::double_array_var coords)
void setSpacing (SMESH::string_array_var funs, SMESH::double_array_var points)
bool checkParams (QString &msg, SMESH::SMESH_Hypothesis_var &hyp) const
bool isGridBySpacing () const
SMESH::double_arraygetCoordinates ()
void getSpacing (SMESH::string_array_out funs, SMESH::double_array_out points) const

Private Slots

void onInsert ()
void onDelete ()
void onMode (int)
void onStepChange ()
void updateButtons ()

Private Attributes

int myAxisIndex
QButtonGroup * myModeGroup
QTreeWidget * mySpacingTreeWdg
QListWidget * myCoordList
QPushButton * myInsertBtn
QPushButton * myDeleteBtn
SMESHGUI_SpinBox * myStepSpin
QLabel * myStepLabel
double myStep

Detailed Description

Widget defining the grid in one direction.

Definition at line 66 of file StdMeshersGUI_CartesianParamCreator.h.


Constructor & Destructor Documentation

StdMeshersGUI::GridAxisTab::GridAxisTab ( QWidget *  theParent,
const int  axisIndex 
)

Constructor.

Parameters:
theParent- Parent widget for this tab

Makes tab's look and feel

Definition at line 136 of file StdMeshersGUI_CartesianParamCreator.cxx.

                                                                  :
    QFrame( theParent ), myAxisIndex( axisIndex )
  {
    // 1) Grid definition mode
    myModeGroup = new QButtonGroup( this );
    QGroupBox* modeBox = new QGroupBox( tr( "GRID_DEF_MODE" ), this );
    QHBoxLayout* modeLay = new QHBoxLayout( modeBox );
    modeLay->setMargin( MARGIN );
    modeLay->setSpacing( SPACING );

    QRadioButton* coordModeBtn = new QRadioButton( tr( "SMESH_COORDINATES" ), modeBox );
    QRadioButton* spacModeBtn  = new QRadioButton( tr( "SPACING" ), modeBox );

    modeLay->addWidget( coordModeBtn );
    modeLay->addWidget( spacModeBtn );
    myModeGroup->addButton( coordModeBtn, COORD_BUT );
    myModeGroup->addButton( spacModeBtn,  SPACING_BUT );

    // 2) Buttons + Step
    myInsertBtn = new QPushButton( tr("INSERT"), this);
    myDeleteBtn = new QPushButton( tr("SMESH_BUT_DELETE"), this);

    myStepLabel = new QLabel( tr("COORD_STEP"));
    myStepSpin  = new SMESHGUI_SpinBox( this );
    myStepSpin->setAcceptNames( false ); // No Notebook variables allowed
    myStepSpin->RangeStepAndValidator();
    myStepSpin->SetStep( 1. );
    myStepSpin->SetValue( myStep = 1. );

    // 3) Coodrinates/Spacing group
    QFrame* csFrame = new QFrame( this );
    QVBoxLayout* scLay = new QVBoxLayout( csFrame );
    scLay->setMargin( 0 );
    scLay->setSpacing( SPACING );

    // 3.1) Spacing
    mySpacingTreeWdg = new QTreeWidget( csFrame );
    mySpacingTreeWdg->setColumnCount(2);
    mySpacingTreeWdg->setHeaderLabels( QStringList() << tr( "SMESH_RANGE" ) << QString( "f(t)" ));
    mySpacingTreeWdg->setColumnWidth( 1, 40 );
    mySpacingTreeWdg->setColumnWidth( 2, 30 );
    mySpacingTreeWdg->setItemDelegate( new LineDelegate( mySpacingTreeWdg ));
    scLay->addWidget( mySpacingTreeWdg );

    // 3.2) Coordinates
    myCoordList = new QListWidget( csFrame );
    myCoordList->setItemDelegate( new LineDelegate( myCoordList ));
    scLay->addWidget( myCoordList );

    // layouting

    QGridLayout* axisTabLayout = new QGridLayout( this );
    axisTabLayout->setMargin( MARGIN );
    axisTabLayout->setSpacing( SPACING );

    axisTabLayout->addWidget( modeBox    , 0, 0, 1, 3 );
    axisTabLayout->addWidget( myInsertBtn  , 1, 0, 1, 2 );
    axisTabLayout->addWidget( myDeleteBtn  , 2, 0, 1, 2 );
    axisTabLayout->addWidget( myStepLabel, 3, 0 );
    axisTabLayout->addWidget( myStepSpin , 3, 1 );
    axisTabLayout->addWidget( csFrame    , 1, 2, 4, 1 );

    axisTabLayout->setRowStretch( 4, 1 );

    // signals
    connect( myInsertBtn,      SIGNAL( clicked() ),             SLOT( onInsert() ));
    connect( myDeleteBtn,      SIGNAL( clicked() ),             SLOT( onDelete() ));
    connect( myModeGroup,      SIGNAL( buttonClicked ( int )),  SLOT( onMode(int)));
    connect( mySpacingTreeWdg, SIGNAL( itemSelectionChanged()), SLOT( updateButtons() ));
    connect( myCoordList,      SIGNAL( itemSelectionChanged()), SLOT( updateButtons() ));
    connect( myStepSpin,       SIGNAL( valueChanged(double)),   SLOT( onStepChange() ));
  }

Here is the call graph for this function:

Definition at line 71 of file StdMeshersGUI_CartesianParamCreator.h.

{}

Member Function Documentation

bool StdMeshersGUI::GridAxisTab::checkParams ( QString &  msg,
SMESH::SMESH_Hypothesis_var &  hyp 
) const

Definition at line 407 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    if ( isGridBySpacing() )
    {
      if ( mySpacingTreeWdg->topLevelItemCount() == 0 )
        return false; // how could it be?
      StdMeshers::StdMeshers_CartesianParameters3D_var h =
        StdMeshers::StdMeshers_CartesianParameters3D::_narrow( hyp );
      SMESH::string_array_var funs;
      SMESH::double_array_var points;
      getSpacing( funs.out(), points.out() );
      try {
        const char* axisName[3] = { "X", "Y", "Z" };
        SMESH::double_array_var coords =
          h->ComputeCoordinates(0.,1., funs, points, axisName[ myAxisIndex ]);
      }
      catch ( const SALOME::SALOME_Exception& ex ) {
        msg = (const char*) ex.details.text;
        return false;
      }
    }
    else
    {
      return myCoordList->count() > 1;
    }
    return true;
  }

Here is the call graph for this function:

Definition at line 378 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    SMESH::double_array_var coords = new SMESH::double_array;
    coords->length( myCoordList->count() );
    for ( size_t i = 0; i < coords->length(); ++i )
      coords[i] = coordFromItem( myCoordList->item( i ) );

    return coords._retn();
  }

Here is the call graph for this function:

void StdMeshersGUI::GridAxisTab::getSpacing ( SMESH::string_array_out  funs,
SMESH::double_array_out  points 
) const

Definition at line 388 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    funs =  new SMESH::string_array();
    points = new SMESH::double_array();
    funs->length( mySpacingTreeWdg->topLevelItemCount() );
    points->length( mySpacingTreeWdg->topLevelItemCount() + 1 );
    double t0, t1; QString fun;
    for ( size_t i = 0; i < funs->length(); ++i )
    {
      QTreeWidgetItem* item = mySpacingTreeWdg->topLevelItem( i );
      getFromItem( item, t0, t1, fun );
      points[i] = t0;
      funs[i] = fun.toLatin1().constData();
    }
    points[ points->length()-1 ] = 1.0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 373 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    return ( myModeGroup->checkedId() == SPACING_BUT );
  }

Here is the caller graph for this function:

void StdMeshersGUI::GridAxisTab::onDelete ( ) [private, slot]

Definition at line 257 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    if ( isGridBySpacing() )
    {
      QList<QTreeWidgetItem *> selItems = mySpacingTreeWdg->selectedItems();
      QTreeWidgetItem * item;
      foreach ( item, selItems )
      {
        int i = mySpacingTreeWdg->indexOfTopLevelItem( item );
        if ( i == 0 ) continue; 
        QTreeWidgetItem* prevItem = mySpacingTreeWdg->topLevelItem( i-1 );

        double t0, t1, t2; QString fun;
        getFromItem( item, t1, t2, fun );
        getFromItem( prevItem, t0, t1, fun );
        delete item;

        setToItem( t0, t2, fun, prevItem );
      }
    }
    else
    {
      if ( myCoordList->count() > 2 )
        if ( QListWidgetItem * item = myCoordList->currentItem() )
          delete item;
    }
    updateButtons();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshersGUI::GridAxisTab::onInsert ( ) [private, slot]

Definition at line 209 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    if ( isGridBySpacing() )
    {
      QTreeWidgetItem * item = mySpacingTreeWdg->currentItem();
      if ( !item ) item = mySpacingTreeWdg->topLevelItem( 0 );
      int i = mySpacingTreeWdg->indexOfTopLevelItem( item );

      double t0, t1; QString fun;
      getFromItem( item, t0, t1, fun );
      double t = 0.5 * ( t0 + t1 );
      setToItem( t0, t, fun, item );

      item = setToItem( t, t1, fun );
      if ( i == mySpacingTreeWdg->topLevelItemCount()-1 )
        mySpacingTreeWdg->addTopLevelItem( item );
      else
        mySpacingTreeWdg->insertTopLevelItem( i+1, item );
      mySpacingTreeWdg->setCurrentItem( item );
    }
    else
    {
      if ( myCoordList->count() == 0 )
      {
        myCoordList->addItem( coordToItem( 0 ));
      }
      else
      {
        double coord = coordFromItem( myCoordList->currentItem() ) + myStep;
        int i = myCoordList->currentRow();
        while ( i > 0 && coordFromItem( myCoordList->item( i-1 )) > coord )
          --i;
        while ( i < myCoordList->count() && coordFromItem( myCoordList->item( i )) < coord )
          ++i;
        const double tol = 1e-6;
        const bool isSame = 
          ( i < myCoordList->count() && coordFromItem( myCoordList->item( i )) - coord < tol ) ||
          ( i > 0 && coord - coordFromItem( myCoordList->item( i-1 )) < tol );
        if ( !isSame )
          myCoordList->insertItem( i, coordToItem( coord ));
        else if ( myStep < 0 )
          --i;
        myCoordList->setCurrentRow( i );
      }
    }
    updateButtons();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshersGUI::GridAxisTab::onMode ( int  isSpacing) [private, slot]

Definition at line 286 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    mySpacingTreeWdg->setShown( isSpacing );
    myCoordList->setShown( !isSpacing );
    myStepSpin->setShown( !isSpacing );
    myStepLabel->setShown( !isSpacing );
    if ( isSpacing )
    {
      if ( mySpacingTreeWdg->topLevelItemCount() == 0 )
      {
        QString spacing( "1" );
        if ( myCoordList->count() > 1 )
        {
          double c1 = coordFromItem( myCoordList->item( 1 ));
          double c0 = coordFromItem( myCoordList->item( 0 ));
          spacing = QString::number( c1 - c0 );
        }
        mySpacingTreeWdg->addTopLevelItem( setToItem( 0., 1., spacing ) );
      }
      myCoordList->clear();
    }
    else
    {
      mySpacingTreeWdg->clear();
      if ( myCoordList->count() == 0 )
        myCoordList->addItem( coordToItem( 0 ));
    }
    updateButtons();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshersGUI::GridAxisTab::onStepChange ( ) [private, slot]

Definition at line 316 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    if ( fabs( myStepSpin->GetValue() ) < 1e-100 )
    {
      double delta = myStepSpin->singleStep() * ( myStep > myStepSpin->GetValue() ? -1 : +1 );
      myStepSpin->SetValue( myStepSpin->GetValue() + delta );
    }
    myStep = myStepSpin->GetValue();
  }

Here is the caller graph for this function:

void StdMeshersGUI::GridAxisTab::setCoordinates ( SMESH::double_array_var  coords)

Definition at line 350 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    myCoordList->clear();
    for ( size_t i = 0; i < coords->length(); ++i )
      myCoordList->addItem( coordToItem( coords[i] ));

    myModeGroup->button( COORD_BUT )->setChecked( true );
    onMode( COORD_BUT );
  }

Here is the call graph for this function:

void StdMeshersGUI::GridAxisTab::setSpacing ( SMESH::string_array_var  funs,
SMESH::double_array_var  points 
)

Definition at line 360 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    mySpacingTreeWdg->clear();
    if ( funs->length() == points->length() - 1 )
    {
      for ( size_t i = 1; i < points->length(); ++i )
        mySpacingTreeWdg->addTopLevelItem
          ( setToItem( points[i-1], points[i], (const char*) funs[i-1] ));
    }
    myModeGroup->button( SPACING_BUT )->setChecked( true );
    onMode( SPACING_BUT );
  }

Here is the call graph for this function:

Definition at line 326 of file StdMeshersGUI_CartesianParamCreator.cxx.

  {
    bool insertEnable = false, deleteEnable = false;
    if ( isGridBySpacing() )
    {
      insertEnable = true;
      const int nbSelected = mySpacingTreeWdg->selectedItems().count();
      if ( nbSelected > 0 )
      {
        // we delete a current range by uniting it with the previous
        int i = mySpacingTreeWdg->indexOfTopLevelItem(  mySpacingTreeWdg->currentItem() );
        deleteEnable = ( i > 0 );
      }
    }
    else
    {
      const int nbSelected = myCoordList->selectedItems().count();
      insertEnable = ( nbSelected || myCoordList->count() < 2 );
      deleteEnable = ( nbSelected && myCoordList->count() > 2 );
    }
    myInsertBtn->setEnabled( insertEnable );
    myDeleteBtn->setEnabled( deleteEnable );
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 90 of file StdMeshersGUI_CartesianParamCreator.h.

Definition at line 93 of file StdMeshersGUI_CartesianParamCreator.h.

Definition at line 95 of file StdMeshersGUI_CartesianParamCreator.h.

Definition at line 94 of file StdMeshersGUI_CartesianParamCreator.h.

QButtonGroup* StdMeshersGUI::GridAxisTab::myModeGroup [private]

Definition at line 91 of file StdMeshersGUI_CartesianParamCreator.h.

Definition at line 92 of file StdMeshersGUI_CartesianParamCreator.h.

Definition at line 98 of file StdMeshersGUI_CartesianParamCreator.h.

Definition at line 97 of file StdMeshersGUI_CartesianParamCreator.h.

SMESHGUI_SpinBox* StdMeshersGUI::GridAxisTab::myStepSpin [private]

Definition at line 96 of file StdMeshersGUI_CartesianParamCreator.h.


The documentation for this class was generated from the following files: