23 #include "baseexperimentgui.h" 
   24 #include <QVBoxLayout> 
   25 #include <QGridLayout> 
   31     QWidget(parent, flags),
 
   32     DataUploaderDownloader<__BaseExperiment_internal::OperationControl, __BaseExperiment_internal::OperationStatus>(1, BlockUploader, this),
 
   33     m_experiment(experiment),
 
   35     m_operationSelectionGroup(NULL),
 
   36     m_operationsListLabel(NULL),
 
   37     m_operationsList(NULL),
 
   38     m_selectedOperationInfo(NULL),
 
   39     m_startSelectedOperationButton(NULL),
 
   40     m_currentOperationControlGroup(NULL),
 
   41     m_currentOperationInfo(NULL),
 
   42     m_stopCurrentOperationButton(NULL),
 
   43     m_steppableOperationControlGroup(NULL),
 
   44     m_pauseOperationButton(NULL),
 
   45     m_stepOperationButton(NULL),
 
   46     m_delaySliderLabel(NULL),
 
   48     m_runningOperationID(-1)
 
   54     QVBoxLayout* mainLayout = 
new QVBoxLayout(
this);
 
   58         m_operationSelectionGroup = 
new QGroupBox(
"Operation Selection", 
this);
 
   59         mainLayout->addWidget(m_operationSelectionGroup);
 
   62         QGridLayout* layout = 
new QGridLayout(m_operationSelectionGroup);
 
   65         m_operationsListLabel = 
new QLabel(
"Operation: ", m_operationSelectionGroup);
 
   66         layout->addWidget(m_operationsListLabel, 0, 0);
 
   69         m_operationsList = 
new QComboBox(m_operationSelectionGroup);
 
   70         QSizePolicy operationsListSizePolicy = m_operationsList->sizePolicy();
 
   71         operationsListSizePolicy.setHorizontalStretch(1);
 
   72         m_operationsList->setSizePolicy(operationsListSizePolicy);
 
   73         connect(m_operationsList, SIGNAL(currentIndexChanged(
int)), 
this, SLOT(currentOperationChanged(
int)));
 
   74         layout->addWidget(m_operationsList, 0, 1);
 
   77         m_selectedOperationInfo = 
new QLabel(
"Invalid operation", m_operationSelectionGroup);
 
   78         layout->addWidget(m_selectedOperationInfo, 1, 0, 1, 2);
 
   81         m_startSelectedOperationButton = 
new QPushButton(
"Start Operation", m_operationSelectionGroup);
 
   82         connect(m_startSelectedOperationButton, SIGNAL(clicked()), 
this, SLOT(startOperation()));
 
   83         layout->addWidget(m_startSelectedOperationButton, 2, 0, 1, 2);
 
   88         m_currentOperationControlGroup = 
new QGroupBox(
"Current Operation Control", 
this);
 
   89         mainLayout->addWidget(m_currentOperationControlGroup);
 
   92         QVBoxLayout* layout = 
new QVBoxLayout(m_currentOperationControlGroup);
 
   95         m_currentOperationInfo = 
new QLabel(
"No running operation", m_currentOperationControlGroup);
 
   96         layout->addWidget(m_currentOperationInfo);
 
   99         m_stopCurrentOperationButton = 
new QPushButton(
"Stop Operation", m_currentOperationControlGroup);
 
  100         connect(m_stopCurrentOperationButton, SIGNAL(clicked()), 
this, SLOT(stopOperation()));
 
  101         layout->addWidget(m_stopCurrentOperationButton);
 
  106         m_steppableOperationControlGroup = 
new QGroupBox(
"Steppable Operation Control", 
this);
 
  107         mainLayout->addWidget(m_steppableOperationControlGroup);
 
  110         QGridLayout* layout = 
new QGridLayout(m_steppableOperationControlGroup);
 
  113         m_pauseOperationButton = 
new QPushButton(
"Pause", m_steppableOperationControlGroup);
 
  114         m_pauseOperationButton->setCheckable(
true);
 
  115         connect(m_pauseOperationButton, SIGNAL(clicked(
bool)), 
this, SLOT(pauseOperation(
bool)));
 
  116         layout->addWidget(m_pauseOperationButton, 0, 0, 1, 2);
 
  119         m_stepOperationButton = 
new QPushButton(
"Step", m_steppableOperationControlGroup);
 
  120         connect(m_stepOperationButton, SIGNAL(clicked()), 
this, SLOT(stepOperation()));
 
  121         layout->addWidget(m_stepOperationButton, 1, 0, 1, 2);
 
  124         m_delaySliderLabel = 
new QLabel(
"Interval between steps:", m_steppableOperationControlGroup);
 
  125         layout->addWidget(m_delaySliderLabel, 2, 0);
 
  128         m_delaySlider = 
new QSlider(Qt::Horizontal, m_steppableOperationControlGroup);
 
  129         QSizePolicy delaySliderSizePolicy = m_delaySlider->sizePolicy();
 
  130         delaySliderSizePolicy.setHorizontalStretch(1);
 
  131         m_delaySlider->setSizePolicy(delaySliderSizePolicy);
 
  132         m_delaySlider->setRange(0, 100);
 
  133         m_delaySlider->setValue(delayToSliderValue(m_experiment->
currentInterval()));
 
  134         connect(m_delaySlider, SIGNAL(valueChanged(
int)), 
this, SLOT(changeDelay(
int)));
 
  135         layout->addWidget(m_delaySlider, 2, 1);
 
  139     updateOperationsList();
 
  156                     updateOperationsList();
 
  160                     m_currentOperationInfo->setText(describeOperation(m_runningOperationID, 
"Running operation: "));
 
  162                     if (m_operations[m_runningOperationID]->getUseSeparateThread()) {
 
  163                         if (m_operations[m_runningOperationID]->getSteppable()) {
 
  164                             enableWidgets(
false, 
true, 
true, 
true);
 
  166                             enableWidgets(
false, 
true, 
false, 
false);
 
  169                         enableWidgets(
false, 
false, 
false, 
false);
 
  173                     m_runningOperationID = -1;
 
  174                     currentOperationChanged(m_operationsList->currentIndex());
 
  175                     m_currentOperationInfo->setText(
"No running operation");
 
  178                     m_stepOperationButton->setEnabled(
true);
 
  181                     m_stepOperationButton->setEnabled(
false);
 
  185                     m_delaySlider->blockSignals(
true);
 
  186                     m_delaySlider->setValue(delayToSliderValue(d->
delay));
 
  187                     m_delaySlider->blockSignals(
false);
 
  194         return QWidget::event(e);
 
  198 void BaseExperimentGUI::currentOperationChanged(
int index)
 
  200     m_selectedOperationInfo->setText(describeOperation(((index < 0) ? index : (index + 1)), 
"Selected operation: "));
 
  202     if (m_runningOperationID == -1) {
 
  204             enableWidgets(
false, 
false, 
false, 
false);
 
  206             if (m_operations[index + 1]->getUseSeparateThread()) {
 
  207                 if (m_operations[index + 1]->getSteppable()) {
 
  208                     enableWidgets(
true, 
false, 
true, 
true);
 
  210                     enableWidgets(
true, 
false, 
false, 
false);
 
  213                 enableWidgets(
true, 
false, 
false, 
false);
 
  219 void BaseExperimentGUI::startOperation()
 
  221     if (m_operationsList->currentIndex() == -1) {
 
  227     if (m_pauseOperationButton->isChecked()) {
 
  232     d->operationID = m_operationsList->currentIndex() + 1;
 
  234     m_startSelectedOperationButton->setEnabled(
false);
 
  237 void BaseExperimentGUI::stopOperation()
 
  244 void BaseExperimentGUI::pauseOperation(
bool pause)
 
  251         if (m_runningOperationID != -1) {
 
  252             m_stepOperationButton->setEnabled(
true);
 
  256         m_stepOperationButton->setEnabled(
false);
 
  260 void BaseExperimentGUI::stepOperation()
 
  267 void BaseExperimentGUI::changeDelay(
int delay)
 
  272     d->interval = sliderValueToDelay(delay);
 
  275 void BaseExperimentGUI::updateOperationsList()
 
  280     m_operationsList->clear();
 
  283     for (
int i = 1; i < m_operations.size(); i++) {
 
  284         m_operationsList->insertItem(i - 1, m_operations[i]->getName());
 
  288     m_operationsList->setCurrentIndex(0);
 
  291 void BaseExperimentGUI::enableWidgets(
bool enableStart, 
bool enableStop, 
bool enablePause, 
bool enableDelay)
 
  293     m_startSelectedOperationButton->setEnabled(enableStart);
 
  294     m_stopCurrentOperationButton->setEnabled(enableStop);
 
  295     m_pauseOperationButton->setEnabled(enablePause);
 
  296     if ((enablePause) && (m_runningOperationID != -1)) {
 
  297         m_stepOperationButton->setEnabled(m_pauseOperationButton->isChecked());
 
  299         m_stepOperationButton->setEnabled(
false);
 
  301     m_delaySlider->setEnabled(enableDelay);
 
  304 QString BaseExperimentGUI::describeOperation(
int id, QString prefix)
 const 
  309         str = 
"Invalid operation";
 
  311         str = prefix + m_operations[id]->getName();
 
  312         if (m_operations[
id]->getUseSeparateThread()) {
 
  313             if (m_operations[
id]->getSteppable()) {
 
  314                 str += 
"; it is a STEPPABLE THREAD operation";
 
  316                 str += 
"; it is a THREAD operation";
 
  319             str += 
"; it is an IMMEDIATE operation";
 
  326 unsigned long BaseExperimentGUI::sliderValueToDelay(
int value)
 const 
  331         return (
unsigned long) pow((
double) 1.1, (
double) value);
 
  335 int BaseExperimentGUI::delayToSliderValue(
unsigned long interval)
 const 
  340         return (
int) (log((
double) interval) / log((
double) 1.1));
 
unsigned int operationID
The id of the operation that was added/started/ended... 
unsigned long delay
The new delay for steps of the current operation. 
unsigned long currentInterval() const 
Returns the current delay for steppable operations. 
virtual ~BaseExperimentGUI()
Destructor. 
virtual bool event(QEvent *e)
Receives events. 
const QVector< AbstractOperationWrapper * > & getOperations() const 
Returns the list of operations. 
DataUploaderDownloader< __BaseExperiment_internal::OperationStatus, __BaseExperiment_internal::OperationControl > * getUploaderDownloader()
Returns the object to exchange data. 
Status status
The current status. 
const DataType * downloadDatum()
The base class for experiments. 
farsa::DatumToUpload< DataType > DatumToUpload
static void associate(DataUploader< DataType > *uploader, DataDownloader< DataType > *downloader)
BaseExperimentGUI(BaseExperiment *experiment, QWidget *parent=NULL, Qt::WindowFlags flags=0)
Constructor. 
The data sent by a BaseExperiment instance to the corresponding GUI.