diff --git a/slsDetectorGui/forms/form_scan.ui b/slsDetectorGui/forms/form_scan.ui index 67e8faf06..68321732c 100644 --- a/slsDetectorGui/forms/form_scan.ui +++ b/slsDetectorGui/forms/form_scan.ui @@ -101,7 +101,7 @@ - + <nobr>Defines scan range for a constant step size.</nobr> Constant Step Size diff --git a/slsDetectorGui/include/qScanWidget.h b/slsDetectorGui/include/qScanWidget.h index 192b95e5e..2da18a6ab 100644 --- a/slsDetectorGui/include/qScanWidget.h +++ b/slsDetectorGui/include/qScanWidget.h @@ -57,6 +57,7 @@ private: QPalette red; QString customTip; QString fileTip; + QString rangeTip; /**widgets needed for diff size types*/ QButtonGroup *btnGroup; @@ -116,8 +117,13 @@ void SetParameter(); void SetPrecision(int value); /** Set number of steps + * @param int num is the number of steps * */ -void SetNSteps(); +void SetNSteps(int num); + +/** Set range for scan + * */ +void SetRangeSteps(); /** Set custom steps * returns OK if set properly diff --git a/slsDetectorGui/src/qScanWidget.cpp b/slsDetectorGui/src/qScanWidget.cpp index 93bac7d02..208eda836 100644 --- a/slsDetectorGui/src/qScanWidget.cpp +++ b/slsDetectorGui/src/qScanWidget.cpp @@ -66,6 +66,7 @@ void qScanWidget::SetupWidgetWindow(){ red.setColor(QPalette::Active,QPalette::WindowText,Qt::red); fileTip = radioFile->toolTip(); customTip = radioCustom->toolTip(); + rangeTip = radioRange->toolTip(); //layout for the size widgets stackedLayout = new QStackedLayout; @@ -79,23 +80,36 @@ void qScanWidget::SetupWidgetWindow(){ spinFrom = new QDoubleSpinBox(widgetRange); lblTo = new QLabel("to",widgetRange); spinTo = new QDoubleSpinBox(widgetRange); - lblSize = new QLabel("Size",widgetRange); + lblSize = new QLabel("step size:",widgetRange); spinSize = new QDoubleSpinBox(widgetRange); lblFrom->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); + lblFrom->setToolTip(rangeTip); spinFrom->setValue(0); + spinFrom->setToolTip(rangeTip); + spinFrom->setMaximum(1000000); lblTo->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); + lblTo->setToolTip(rangeTip); spinTo->setValue(1); + spinTo->setToolTip(rangeTip); + spinTo->setMaximum(1000000); lblSize->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); + lblSize->setToolTip(rangeTip); + lblSize->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); + lblSize->setFixedWidth(67); spinSize->setValue(1); - layoutRange->addItem(new QSpacerItem(50,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); + spinSize->setToolTip(rangeTip); + layoutRange->addItem(new QSpacerItem(40,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); layoutRange->addWidget(lblFrom); + layoutRange->addItem(new QSpacerItem(5,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); layoutRange->addWidget(spinFrom); + layoutRange->addItem(new QSpacerItem(5,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); layoutRange->addWidget(lblTo); + layoutRange->addItem(new QSpacerItem(5,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); layoutRange->addWidget(spinTo); - layoutRange->addItem(new QSpacerItem(20,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); + layoutRange->addItem(new QSpacerItem(30,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); layoutRange->addWidget(lblSize); layoutRange->addWidget(spinSize); - layoutRange->addItem(new QSpacerItem(50,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); + layoutRange->addItem(new QSpacerItem(40,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); // Custom Values Layout @@ -106,13 +120,10 @@ void qScanWidget::SetupWidgetWindow(){ btnCustom = new QPushButton("Delete",widgetCustom); comboCustom->setEditable(true); comboCustom->setCompleter(false); - QDoubleValidator *validate = new QDoubleValidator(comboCustom); - comboCustom->setValidator(validate); - radioCustom->setToolTip("Measures only at specific values listed by the user.
" - "Number of entries is restricted to Number of Steps field."); - comboCustom->setToolTip("Measures only at specific values listed by the user.
" - "Number of entries is restricted to Number of Steps field."); + comboCustom->setValidator(new QDoubleValidator(comboCustom)); + comboCustom->setToolTip(customTip); btnCustom->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); + btnCustom->setToolTip("Deletes current position from list and reduces Number of Positions by 1."); layoutCustom->addItem(new QSpacerItem(160,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); layoutCustom->addWidget(comboCustom); layoutCustom->addItem(new QSpacerItem(5,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); @@ -126,9 +137,11 @@ void qScanWidget::SetupWidgetWindow(){ layoutFile->addItem(new QSpacerItem(50,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); dispFile = new QLineEdit(widgetFile); dispFile->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); + dispFile->setToolTip(fileTip); layoutFile->addWidget(dispFile); btnFile = new QPushButton("Browse",widgetFile); btnFile->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); + btnFile->setToolTip(fileTip); layoutFile->addWidget(btnFile); layoutFile->addItem(new QSpacerItem(50,20,QSizePolicy::Fixed,QSizePolicy::Fixed)); @@ -157,12 +170,14 @@ void qScanWidget::Initialization(){ connect(dispParameter, SIGNAL(editingFinished()), this, SLOT(SetParameter())); //sizewidgets connect(btnGroup, SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(EnableSizeWidgets())); -// connect(radioRange, SIGNAL(toggled(bool)),this,SLOT(EnableSizeWidgets())); //numsteps - connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps())); + connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); //precision connect(spinPrecision, SIGNAL(valueChanged(int)), this, SLOT(SetPrecision(int))); //range values + connect(spinFrom, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + connect(spinTo, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); //custom values connect(comboCustom, SIGNAL(currentIndexChanged(int)), this, SLOT(SetCustomSteps())); connect(btnCustom, SIGNAL(clicked()), this, SLOT(DeleteCustomSteps())); @@ -179,6 +194,9 @@ void qScanWidget::EnableSizeWidgets(){ #ifdef VERBOSE cout << "Entering enable size widgets" << endl; #endif + //setting to defaults is not done here as this is called even if mode changes + //so only if its to change the size widget type, its set to default for the others + //scan is none if(!comboScript->currentIndex()){ radioCustom->setText("Specific Values"); @@ -194,15 +212,26 @@ void qScanWidget::EnableSizeWidgets(){ } else{ // Steps are enabled for all except Range step size - lblSteps->setEnabled(!radioRange->isChecked()); - spinSteps->setEnabled(!radioRange->isChecked()); + /**lblSteps->setEnabled(!radioRange->isChecked()); + spinSteps->setEnabled(!radioRange->isChecked());*/ //range values if(radioRange->isChecked()){ #ifdef VERBOSE cout << "Constant Range Values" << endl; #endif - stackedLayout->setCurrentIndex(RangeValues); - /**refresh this part*/ + radioCustom->setText("Specific Values"); + radioCustom->setPalette(normal); + radioCustom->setToolTip(customTip); + comboCustom->setToolTip(customTip); + + radioFile->setPalette(normal); + radioFile->setText("Values from File:"); + radioFile->setToolTip(fileTip); + dispFile->setToolTip(fileTip); + btnFile->setToolTip(fileTip); + + stackedLayout->setCurrentIndex(RangeValues); + SetRangeSteps(); } //custom values else if(radioCustom->isChecked()){ @@ -218,9 +247,9 @@ void qScanWidget::EnableSizeWidgets(){ //change it back as this list is what will be loaded. //also numstpes could have been changed in other modes too - disconnect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps())); + disconnect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); spinSteps ->setValue(comboCustom->count()); - connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps())); + connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); stackedLayout->setCurrentIndex(CustomValues); //only for custom steps out here because many signals go through @@ -228,9 +257,12 @@ void qScanWidget::EnableSizeWidgets(){ if(SetCustomSteps()==qDefs::OK){ char cNum[200];sprintf(cNum,"%d",actualNumSteps); char cId[5];sprintf(cId,"%d",id); - qDefs::InfoMessage(string("Scan Level ")+string(cId)+(" - ")+string(" Number of positions added from list : ")+string(cNum),"ScanWidget"); + qDefs::InfoMessage(string("Scan Level ")+string(cId)+ + string(": Specific Values

Number of positions added: ")+ + string(cNum)+string(""),"ScanWidget"); } } + //file values else{ #ifdef VERBOSE @@ -271,8 +303,10 @@ void qScanWidget::SetMode(int mode){ // If anything other than None is selected if(mode){ // Steps are enabled for all except Range step size - lblSteps->setEnabled(!radioRange->isChecked()); - spinSteps->setEnabled(!radioRange->isChecked()); + /**lblSteps->setEnabled(!radioRange->isChecked()); + spinSteps->setEnabled(!radioRange->isChecked());*/ + lblSteps->setEnabled(true); + spinSteps->setEnabled(true); // Custom Script only enables the first layout with addnl parameters etc if(mode==CustomScript){ dispScript->setEnabled(true); @@ -283,6 +317,7 @@ void qScanWidget::SetMode(int mode){ group->setEnabled(true); lblPrecision->setEnabled(true); spinPrecision->setEnabled(true); + } //set the group box widgets @@ -331,7 +366,9 @@ int qScanWidget::SetScan(int mode){ break; } - if(mode!=CustomScript){ + if((mode==CustomScript)&&((script=="")||(script=="none"))){ + return qDefs::OK; + }else{ if((mode!=myDet->getScanMode(id))&&(actualNumSteps)){ qDefs::WarningMessage("The mode could not be changed for an unknown reason.","ScanWidget"); comboScript->setCurrentIndex(myDet->getScanMode(id)); @@ -459,7 +496,7 @@ void qScanWidget::SetPrecision(int value){ //------------------------------------------------------------------------------------------------------------------------------------------------- -void qScanWidget::SetNSteps(){ +void qScanWidget::SetNSteps(int num){ #ifdef VERBOSE cout << "Setting number of steps" << endl; @@ -469,8 +506,24 @@ void qScanWidget::SetNSteps(){ comboCustom->setMaxCount(numSteps); //check if its ok - if(radioCustom->isChecked()){ + if(radioRange->isChecked()){ + //calculate the step size and display it + if(num==1){ + disconnect(spinTo, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + spinTo->setValue(spinFrom->value()); + connect(spinTo, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + }else if(num>1) + num--; + double stepSize = (spinTo->value()-spinFrom->value())/num; + disconnect(spinSize,SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + spinSize->setValue(stepSize); + connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + //set these positions + SetRangeSteps(); + }else if(radioCustom->isChecked()){ SetCustomSteps(); + }else if(radioFile->isChecked()){ + SetFileSteps(); } } @@ -479,6 +532,93 @@ void qScanWidget::SetNSteps(){ //------------------------------------------------------------------------------------------------------------------------------------------------- +void qScanWidget::SetRangeSteps(){ +#ifdef VERBOSE + cout << "Setting\tscan:" << id << "\trange\t"; +#endif + double fromVal = spinFrom->value(); + double sizeVal = spinSize->value(); + //if step size is 0, min and max should be same + if(!sizeVal){ + disconnect(spinTo, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + spinTo->setValue(fromVal); + connect(spinTo, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + QString tip = rangeTip + QString("

" + "Note: Increase the step size from zero to be able to change the range."); + lblSize->setToolTip(tip); + spinSize->setToolTip(tip); + lblSize->setText("step size:*"); + lblSize->setPalette(red); + }else{ + lblSize->setToolTip(rangeTip); + spinSize->setToolTip(rangeTip); + lblSize->setText("step size:"); + lblSize->setPalette(normal); + } + //if min and max is the same + if(fromVal==spinTo->value()) actualNumSteps = 0; + else actualNumSteps = (int)((spinTo->value()-fromVal)/sizeVal); + + //actualNumSteps will be negative if fromsetValue(-1*sizeVal); + connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(SetRangeSteps())); + sizeVal = spinSize->value(); + } + //increment is required like vice versa in setNSteps + actualNumSteps++; +#ifdef VERBOSE + cout << "num pos:" << actualNumSteps << endl; +#endif + + //set the vector positions + positions.resize(actualNumSteps); + for(int i=0;isetValue(actualNumSteps); + connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); + + + //sets the scan + if(SetScan(comboScript->currentIndex())==qDefs::OK){ + char cId[5];sprintf(cId,"%d",id); + QString script = dispScript->text(); + //positions wont be loaded if its custom script + if((comboScript->currentIndex()==CustomScript)&&((script=="")||(script=="none"))){ + qDefs::InfoMessage(string("Scan Level ")+string(cId)+ + string(": Constant Step Size

" + "Positions could not be loaded as the script file path is empty."),"ScanWidget"); + }else{ + //error loading positions + if(myDet->getScanSteps(id)!=actualNumSteps){ + qDefs::WarningMessage(string("Scan Level ")+string(cId)+ + string(": Values From File

" + "The positions list was not set for an unknown reason."),"ScanWidget"); + /*LoadPositions(); + comboScript->setCurrentIndex(myDet->getScanMode(id))*/ + }else{//SUCCESS + char cNum[200];sprintf(cNum,"%d",actualNumSteps); + qDefs::InfoMessage(string("Scan Level ")+string(cId)+ + string(": Constant Step Size

Number of positions added: ")+ + string(cNum)+string(""),"ScanWidget"); + } + } + } + +} + +//------------------------------------------------------------------------------------------------------------------------------------------------- + + int qScanWidget::SetCustomSteps(){ #ifdef VERBOSE @@ -519,18 +659,29 @@ int qScanWidget::SetCustomSteps(){ //copying the list for(int i=0;iitemText(i).toDouble(); +#ifdef VERBOSE cout<<"positions["<setScanSteps(id,actualNumSteps,positions)<currentIndex())==qDefs::OK){ - if(myDet->getScanSteps(id)!=actualNumSteps){ - qDefs::WarningMessage("The positions list was not set for an unknown reason.","ScanWidget"); - LoadPositions(); - comboScript->setCurrentIndex(myDet->getScanMode(id)); + char cId[5];sprintf(cId,"%d",id); + QString script = dispScript->text(); + //positions wont be loaded if its custom script + if((comboScript->currentIndex()==CustomScript)&&((script=="")||(script=="none"))){ + qDefs::InfoMessage(string("Scan Level ")+string(cId)+ + string(": Values From File

" + "Positions could not be loaded as the script file path is empty."),"ScanWidget"); return qDefs::FAIL; + }else{ + if(myDet->getScanSteps(id)!=actualNumSteps){ + qDefs::WarningMessage("The positions list was not set for an unknown reason.","ScanWidget"); + LoadPositions(); + comboScript->setCurrentIndex(myDet->getScanMode(id)); + return qDefs::FAIL; + } + //else success is checked in enabledsizewidgets , else it does this for every add, delete etc } } @@ -646,9 +797,9 @@ void qScanWidget::SetFileSteps(){ } } } - disconnect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps())); + disconnect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); spinSteps->setValue(actualNumSteps); - connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps())); + connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); inFile.close(); }else {//could not open file #ifdef VERBOSE @@ -664,16 +815,28 @@ void qScanWidget::SetFileSteps(){ if(set){//no error while reading file //sets the scan and positions if(SetScan(comboScript->currentIndex())==qDefs::OK){ + char cId[5];sprintf(cId,"%d",id); + QString script = dispScript->text(); radioFile->setPalette(normal); radioFile->setText("Values from File:"); radioFile->setToolTip(fileTip);dispFile->setToolTip(fileTip);btnFile->setToolTip(fileTip); - //error loading positions - if(myDet->getScanSteps(id)!=actualNumSteps){ - qDefs::WarningMessage("The positions list was not set for an unknown reason.","ScanWidget"); - }else{//SUCCESS - char cNum[200];sprintf(cNum,"%d",actualNumSteps); - char cId[5];sprintf(cId,"%d",id); - qDefs::InfoMessage(string("Scan Level ")+string(cId)+(" - ")+string(" Number of positions added from file : ")+string(cNum),"ScanWidget"); + //positions wont be loaded if its custom script + if((comboScript->currentIndex()==CustomScript)&&((script=="")||(script=="none"))){ + qDefs::InfoMessage(string("Scan Level ")+string(cId)+ + string(": Values From File

" + "Positions could not be loaded as the script file path is empty."),"ScanWidget"); + }else{ + //error loading positions + if(myDet->getScanSteps(id)!=actualNumSteps){ + qDefs::WarningMessage(string("Scan Level ")+string(cId)+ + string(": Values From File

" + "The positions list was not set for an unknown reason."),"ScanWidget"); + }else{//SUCCESS + char cNum[200];sprintf(cNum,"%d",actualNumSteps); + qDefs::InfoMessage(string("Scan Level ")+string(cId)+ + string(": Values From File

Number of positions added: ")+ + string(cNum)+string(""),"ScanWidget"); + } } } } @@ -711,7 +874,7 @@ void qScanWidget::LoadPositions(){ cout << "Loading positions" << endl; #endif disconnect(comboCustom, SIGNAL(currentIndexChanged(int)), this, SLOT(SetCustomSteps())); - disconnect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps())); + disconnect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); disconnect(btnGroup, SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(EnableSizeWidgets())); @@ -735,15 +898,14 @@ void qScanWidget::LoadPositions(){ for(int i=0;isetText("Specific Values"); radioCustom->setPalette(normal); radioCustom->setToolTip(customTip); comboCustom->setToolTip(customTip); - }else{ + }//no positions and has a mode + else if(mode){ radioCustom->setPalette(red); radioCustom->setText("Specific Values*"); QString tip = customTip + QString("

First, increase Number of Steps. " @@ -760,11 +922,13 @@ void qScanWidget::LoadPositions(){ comboCustom->setEnabled(numSteps&&mode); btnCustom->setEnabled(numSteps&&mode); - - connect(comboCustom, SIGNAL(currentIndexChanged(int)), this, SLOT(SetCustomSteps())); - connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps())); + connect(spinSteps, SIGNAL(valueChanged(int)), this, SLOT(SetNSteps(int))); connect(btnGroup, SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(EnableSizeWidgets())); + + + //do not set the range variables because if the stepsize is by any chance 0.. + //then the number of steps should change to 1. so only set custom steps } diff --git a/slsDetectorGui/src/qTabActions.cpp b/slsDetectorGui/src/qTabActions.cpp index 7379a3b8d..59c531a4d 100644 --- a/slsDetectorGui/src/qTabActions.cpp +++ b/slsDetectorGui/src/qTabActions.cpp @@ -76,6 +76,9 @@ void qTabActions::SetupWidgetWindow(){ lblName[i] = new QLabel(QString(names[i])); btnExpand[i] = new QPushButton("+"); btnExpand[i]->setFixedSize(20,20); + QString tip = "Click on the \"+\" to Expand or \"-\" to Collapse."; + lblName[i]->setToolTip(tip); + btnExpand[i]->setToolTip(tip); group->addButton(btnExpand[i],i); //Number of positions is only for mythen or gotthard