Skip to content
Snippets Groups Projects
Commit b10f0551 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Signal/slot renaming between FitSuiteWidget and GUIFitObserver to better...

Signal/slot renaming between FitSuiteWidget and GUIFitObserver to better describe what is flying around.
parent 28fda9f5
No related branches found
No related tags found
No related merge requests found
......@@ -43,8 +43,8 @@ FitActivityPanel::FitActivityPanel(JobModel *jobModel, QWidget *parent)
setLayout(mainLayout);
connect(m_controlWidget, SIGNAL(startFitting()), this, SLOT(onStartFittingRequest()));
connect(m_controlWidget, SIGNAL(stopFitting()), this, SLOT(onStopFittingRequest()));
connect(m_controlWidget, SIGNAL(startFittingPushed()), this, SLOT(onStartFittingRequest()));
connect(m_controlWidget, SIGNAL(stopFittingPushed()), this, SLOT(onStopFittingRequest()));
m_stackedWidget->setModel(jobModel);
}
......
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file GUI/coregui/Views/FitWidgets/FitProgressInfo.cpp
//! @brief Implements class FitProgressInfo
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2016
//! @authors Scientific Computing Group at MLZ Garching
//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov
//! @authors Walter Van Herck, Joachim Wuttke
//
// ************************************************************************** //
#include "FitProgressInfo.h"
FitProgressInfo::FitProgressInfo()
: m_chi2(0.0)
, m_iteration_count(0)
{
}
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file GUI/coregui/Views/FitWidgets/FitProgressInfo.h
//! @brief Declares class FitProgressInfo
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2016
//! @authors Scientific Computing Group at MLZ Garching
//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov
//! @authors Walter Van Herck, Joachim Wuttke
//
// ************************************************************************** //
#ifndef FITPROGRESSINFO_H
#define FITPROGRESSINFO_H
#include "WinDllMacros.h"
#include <QVector>
//! The FitProgressInfo class contains all essential information about fit progress.
//! It is send from GUIFitObserver to FitSuiteWidget on every nth iteration.
class BA_CORE_API_ FitProgressInfo {
public:
FitProgressInfo();
double chi2() const { return m_chi2; }
int iterationCount() const { return m_iteration_count; }
QVector<double> parValues() const { return m_values; }
friend class GUIFitObserver;
private:
double m_chi2;
int m_iteration_count;
QVector<double> m_values;
};
#endif
......@@ -30,6 +30,7 @@
#include "MinimizerSettingsWidget.h"
#include "FitResultsWidget.h"
#include "mainwindow_constants.h"
#include "FitProgressInfo.h"
#include "GUIHelpers.h"
#include <QVBoxLayout>
#include <QTabWidget>
......@@ -98,10 +99,10 @@ void FitSuiteWidget::onError(const QString &text)
qDebug() << "FitSuiteWidget::onError" << text;
}
void FitSuiteWidget::onUpdatePlots()
void FitSuiteWidget::onPlotsUpdate()
{
qDebug() << "FitSuiteWidget::onUpdatePlots";
m_currentItem->getIntensityDataItem()->setRawDataVector(m_observer->getSimulationData());
m_currentItem->getIntensityDataItem()->setRawDataVector(m_observer->simulationData());
m_observer->finishedPlotting();
}
......@@ -133,7 +134,7 @@ void FitSuiteWidget::onUpdateParameters(const QStringList &parameters, QVector<d
}
}
void FitSuiteWidget::onUpdateStatus(const QString &text)
void FitSuiteWidget::onStatusUpdate(const QString &text)
{
Q_ASSERT(m_currentItem);
qDebug() << "FitSuiteWidget::onUpdateStatus(const QString &text)" << text;
......@@ -144,6 +145,11 @@ void FitSuiteWidget::onUpdateStatus(const QString &text)
fitSuiteItem->setItemValue(FitSuiteItem::P_ITERATION_COUNT, niter);
}
void FitSuiteWidget::onProgressInfoUpdate(const FitProgressInfo &info)
{
}
void FitSuiteWidget::startFitting()
{
if(!m_currentItem)
......@@ -222,13 +228,19 @@ void FitSuiteWidget::connectSignals()
connect(m_runFitManager, SIGNAL(finishedFitting()), this, SLOT(onFittingFinished()));
connect(m_runFitManager, SIGNAL(fittingError(QString)), this, SIGNAL(fittingError(QString)));
connect(m_observer.get(), SIGNAL(updatePlots()),
this, SLOT(onUpdatePlots()));
connect(m_observer.get(), SIGNAL(updateParameters(QStringList,QVector<double>)),
connect(m_observer.get(), SIGNAL(plotsUpdate()), this, SLOT(onPlotsUpdate()));
connect(m_observer.get(), SIGNAL(parameterUpdate(QStringList,QVector<double>)),
this, SLOT(onUpdateParameters(QStringList,QVector<double>)));
connect(m_observer.get(), SIGNAL(updateStatus(QString)),
this, SLOT(onUpdateStatus(QString)));
connect(m_observer.get(), SIGNAL(updateLog(QString)),
connect(m_observer.get(), SIGNAL(statusUpdate(QString)), this, SLOT(onStatusUpdate(QString)));
connect(m_observer.get(), SIGNAL(logInfoUpdate(QString)),
this, SIGNAL(fittingLog(QString)));
connect(m_observer.get(), SIGNAL(progressInfoUpdate(FitProgressInfo)),
this, SLOT(onProgressInfoUpdate(QString)));
}
......@@ -32,6 +32,7 @@ class ParameterTuningWidget;
class RunFitManager;
class GUIFitObserver;
template <class T> class OutputData;
class FitProgressInfo;
//! The FitSuiteWidget contains all fit settings for given JobItem (fit parameters,
......@@ -60,9 +61,10 @@ signals:
public slots:
void onError(const QString &text);
void onUpdatePlots();
void onPlotsUpdate();
void onUpdateParameters(const QStringList &parameters, QVector<double> values);
void onUpdateStatus(const QString &text);
void onStatusUpdate(const QString &text);
void onProgressInfoUpdate(const FitProgressInfo &info);
void startFitting();
void stopFitting();
......@@ -70,7 +72,6 @@ public slots:
private slots:
void onFittingStarted();
void onFittingFinished();
void onFitSuitePropertyChange(const QString &name);
private:
......
......@@ -19,6 +19,9 @@
#include "IntensityDataItem.h"
#include "FitParameter.h"
#include "FitSuiteParameters.h"
#include "FitProgressInfo.h"
#include "GUIHelpers.h"
#include <QVector>
#include <QDebug>
......@@ -54,9 +57,9 @@ void GUIFitObserver::update(FitSuite *subject)
qDebug() << (*it)->getValue();
}
}
emit updateParameters(parameters, values);
emit parameterUpdate(parameters, values);
emit updateLog(QString("NCalls: %1 Chi: %2\n%3").
emit logInfoUpdate(QString("NCalls: %1 Chi: %2\n%3").
arg(QString::number(subject->getNumberOfIterations()),
QString::number(subject->getChi2()),
QString::fromStdString(text)));
......@@ -66,28 +69,31 @@ void GUIFitObserver::update(FitSuite *subject)
std::streambuf *old = std::cout.rdbuf(buffer.rdbuf());
subject->printResults();
std::string text = buffer.str();
emit updateLog(QString::fromStdString(text));
emit logInfoUpdate(QString::fromStdString(text));
std::cout.rdbuf(old);
}
int curIteration = subject->getNumberOfIterations();
if (curIteration == 0) {
emit startFitting(subject->getRealOutputData()->clone());
}
if(canUpdateStatus(subject)) {
emit statusUpdate(QString::number(subject->getNumberOfIterations()));
FitProgressInfo info;
info.m_chi2 = subject->getChi2();
info.m_iteration_count = subject->getNumberOfIterations();
info.m_values = GUIHelpers::fromStdVector(subject->getFitParameters()->getValues());
emit progressInfoUpdate(info);
if(canUpdateStatus(subject)) {
emit updateStatus(QString::number(subject->getNumberOfIterations()));
}
if(canUpdatePlots(subject)) {
m_block_update_plots = true;
m_simData.reset(subject->getSimulationOutputData()->clone());
m_chiData.reset(subject->getChiSquaredOutputData()->clone());
emit updatePlots();
emit plotsUpdate();
}
}
void GUIFitObserver::setInterval(int val)
......@@ -120,12 +126,12 @@ void GUIFitObserver::finishedPlotting()
m_block_update_plots = false;
}
const OutputData<double> *GUIFitObserver::getSimulationData() const
const OutputData<double> *GUIFitObserver::simulationData() const
{
return m_simData.get();
}
const OutputData<double> *GUIFitObserver::getChiSquaredData() const
const OutputData<double> *GUIFitObserver::chiSquaredData() const
{
return m_chiData.get();
}
......
......@@ -24,6 +24,7 @@
template <class T> class OutputData;
class FitSuite;
class IntensityDataItem;
class FitProgressInfo;
//! The GUIFitObserver class is a intermediate between FitSuite and the GUI.
//! It is called at the end of each iterations and sends (messages, data) to the rest of the GUI.
......@@ -40,24 +41,18 @@ public:
void finishedPlotting();
const OutputData<double> *getSimulationData() const;
const OutputData<double> *getChiSquaredData() const;
const OutputData<double> *simulationData() const;
const OutputData<double> *chiSquaredData() const;
public slots:
void setInterval(int val);
signals:
void updateStatus(const QString &);
void updatePlots();
void updateLog(const QString &);
void startFitting(OutputData<double>*);
void updateParameters(const QStringList &, QVector<double>);
void statusUpdate(const QString &);
void plotsUpdate();
void logInfoUpdate(const QString &);
void parameterUpdate(const QStringList &, QVector<double>);
void progressInfoUpdate(const FitProgressInfo &info);
private:
bool canUpdatePlots(FitSuite *fitSuite);
......
......@@ -89,8 +89,8 @@ RunFitControlWidget::RunFitControlWidget(QWidget *parent)
layout->addWidget(m_iterationsCountLabel);
setLayout(layout);
connect(m_startButton, SIGNAL(clicked(bool)), this, SIGNAL(startFitting()));
connect(m_stopButton, SIGNAL(clicked(bool)), this, SIGNAL(stopFitting()));
connect(m_startButton, SIGNAL(clicked(bool)), this, SIGNAL(startFittingPushed()));
connect(m_stopButton, SIGNAL(clicked(bool)), this, SIGNAL(stopFittingPushed()));
connect(m_intervalSlider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
setEnabled(false);
......
......@@ -40,8 +40,8 @@ public:
void setJobMessagePanel(JobMessagePanel *jobMessagePanel);
signals:
void startFitting();
void stopFitting();
void startFittingPushed();
void stopFittingPushed();
public slots:
void onFittingStarted(JobItem *jobItem);
......
......@@ -228,5 +228,12 @@ QStringList fromStdList(const std::list<std::string> &string_list)
return result;
}
QVector<double> fromStdVector(const std::vector<double> &data)
{
QVector<double> result;
result.reserve(int(data.size())); std::copy(data.begin(), data.end(), std::back_inserter(result));
return result;
}
} // namespace GUIHelpers
......@@ -71,6 +71,7 @@ BA_CORE_API_ bool isVersionMatchMinimal(const QString &version, const QString &m
BA_CORE_API_ QString currentDateTime();
BA_CORE_API_ QStringList fromStdList(const std::list<std::string> &string_list);
BA_CORE_API_ QVector<double> fromStdVector(const std::vector<double> &data);
template<class T, class... Ts> std::unique_ptr<T> make_unique(Ts&&... params)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment