Salome HOME
management of closing windows
[modules/filter.git] / src / FILTERGUI / SelectParams.cxx
index 181a4f710aabf52c0ec97568344bd09d8b98ad73..60ddc5468aef8c62725e406c4ed1535ff07a4b8f 100644 (file)
 SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
                           const char* name,
                           bool modal, WFlags fl)
-  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),  _size(128)
+  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),  _size(1024),_sel(sel)
 {
-  // Allocate histogram arrays
-  _x = new double[_size];
-  _y = new double[_size];
-
   if(sel){
+
     // read reference field values
     ::MEDMEM::MED *med = sel->getMED();
 
@@ -56,9 +53,11 @@ SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
     _inputMesh = sel->getMesh();
     _inputField = sel->getField();
     _inputTS = sel->getTimeStep();
+
     // if no reference field selection: throw exception
     if( _inputMesh.isNull() || _inputField.isNull() ){
       MESSAGE("Select an input Field in MED file before filtering!!");
+      delete sel;
       throw SALOME_Exception("Salome Exception");
     }
 
@@ -80,6 +79,10 @@ SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
     throw SALOME_Exception("Salome Exception");
   }
 
+  // Allocate histogram arrays
+  _x = new double[_size];
+  _y = new double[_size];
+
 }
 
 SelectParams::~SelectParams()
@@ -95,6 +98,7 @@ SelectParams::~SelectParams()
     delete _myDField->getSupport();
     delete _myDField;
   }
+  delete _sel;
 }
 
 void SelectParams::buildFrame()
@@ -154,6 +158,16 @@ void SelectParams::buildFrame()
   _myGroupLayout->addWidget( _myFunc, row, 0 );
   row++;
 
+  // 01)  histogram size (line edit)
+  _myHSize = new QButtonGroup( tr(""), _GroupC1 );
+  _myHSize->setExclusive( true );
+  _myHSize->setColumnLayout( 0, Qt::Horizontal );
+  QGridLayout* shLay = new QGridLayout( _myHSize->layout() );
+  shLay->addWidget( _myLSH = new QLabel( tr("FILTER_SIZE_HISTO") , _myHSize ), 0, 0 );
+  shLay->addWidget( _myLESH = new QLineEdit( "1024", _myHSize ), 0, 1 );
+  _myGroupLayout->addWidget( _myHSize, row, 0 );
+  row++;
+
   // 1)  display histogram button (pushbutton)
   _myHisto = new QPushButton( "", _GroupC1 );
   _myHisto->setText(tr("FILTER_DISPLAY_HISTO"));
@@ -256,10 +270,10 @@ void SelectParams::buildFrame()
   _buttonHelp->setText(tr("FILTER_BUT_HELP" ));
   _buttonHelp->setAutoDefault(TRUE);
   _GroupButtonsLayout->addWidget(_buttonHelp, 0, 2);
-  _buttonClose = new QPushButton(_GroupButtons, "buttonClose");
-  _buttonClose->setText(tr("FILTER_BUT_CLOSE" ));
-  _buttonClose->setAutoDefault(TRUE);
-  _GroupButtonsLayout->addWidget(_buttonClose, 0, 1);
+  _buttonCancel = new QPushButton(_GroupButtons, "buttonCancel");
+  _buttonCancel->setText(tr("FILTER_BUT_CANCEL" ));
+  _buttonCancel->setAutoDefault(TRUE);
+  _GroupButtonsLayout->addWidget(_buttonCancel, 0, 1);
   _myGroupLayout->addWidget( _GroupButtons, row, 0 );
   _GroupButtons->setDisabled(true);
   row++;
@@ -294,6 +308,7 @@ void SelectParams::buildFrame()
   _myHistoSThresh = _myPlot->insertCurve( QString() );
   _myPlot->setCurvePen( _myHistoSThresh, QPen( Qt::black, 1 ) );
 
+  connect( _myLESH, SIGNAL(returnPressed()), this, SLOT(enterSHisto()));
   connect( _myHisto, SIGNAL(clicked()), this, SLOT(updateHisto()));
   connect( _myLinear, SIGNAL(clicked()), this, SLOT(scaleSelected()));
   connect( _myLog, SIGNAL(clicked()), this, SLOT(scaleSelected()));
@@ -306,14 +321,28 @@ void SelectParams::buildFrame()
   connect( _myPlot, SIGNAL(plotMouseMoved(const QMouseEvent &)), this, SLOT(moveThresh(const QMouseEvent &)));
   connect( _myOFB, SIGNAL(clicked()), this, SLOT(getOutFileName()));
   connect( _myProc, SIGNAL(clicked()), this, SLOT(process()));
-  connect(_buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnClose()));
+  connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
   connect(_buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
 
   _GroupC2->setMinimumSize( 500, 500 );
   _GroupC2->setMaximumSize( 500, 500 );
   setMinimumSize( 750, 500 );
   setMaximumSize( 750, 500 );
-  this->show();  /* displays Dialog */
+//   this->show();  /* displays Dialog */
+}
+
+void SelectParams::enterSHisto()
+{
+  // Deallocate old histogram arrays
+  delete _x;
+  delete _y;
+
+  // get new histogram size
+  _size = atoi(_myLESH->text());
+
+  // Allocate new histogram arrays
+  _x = new double[_size];
+  _y = new double[_size];
 }
 
 void SelectParams::scaleSelected()
@@ -426,11 +455,11 @@ void SelectParams::calcHisto()
 
 void SelectParams::displayHisto()
 {
+  // associate values to curve
+  _myPlot->setCurveData( _myHistoCurve, _x, _y, _size );
   // give extrema values for each axis
   _myPlot->setAxisScale( _myPlot->curveXAxis( _myHistoCurve ), _xmin, _xmax );
   _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax );
-  // associate values to curve
-  _myPlot->setCurveData( _myHistoCurve, _x, _y, _size );
   if( _myLinear->isChecked() )
     _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None );
   else
@@ -566,6 +595,9 @@ void SelectParams::process()
 
   // have to call ensight driver MED to generate output MED file from filtoo output
 
+  // close the window
+  accept();
+
 }
 
 void SelectParams::calcRateRed()
@@ -573,7 +605,6 @@ void SelectParams::calcRateRed()
   int i1, i2, i;
   int atot=0, asel=0, atot1;
   double rateRed=0.0;
-  char strth[128];
 
   // calculate reduction rate depend on reference area defined by threshold values
   i1 = (int)((double)_size * ( _fthresh - _xmin ) / ( _xmax - _xmin ));
@@ -615,7 +646,7 @@ void SelectParams::calcRateRed()
 
 }
 
-void SelectParams::ClickOnClose()
+void SelectParams::ClickOnCancel()
 {
   MESSAGE("click on Cancel");
   reject();