Skip to content

Commit

Permalink
Merge pull request #91 from aglowacki/master
Browse files Browse the repository at this point in the history
Changed default to fit with tails
  • Loading branch information
aglowacki authored Sep 26, 2024
2 parents 5a98316 + 8b389e9 commit 6ac77ea
Show file tree
Hide file tree
Showing 16 changed files with 391 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
uProbeX::log_textedit->insertHtml(h_msg);
break;
case QtFatalMsg:
abort();
//abort();
break;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/mvc/AnnimateSlideWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AnnimateSlideWidget::AnnimateSlideWidget(QWidget *parent) : QWidget(parent)
_anim_widget = nullptr;
_anim_enabled = true;
_first = true;
_running = false;
_cur_state = SlideState::SlideOut;
}

//---------------------------------------------------------------------------
Expand All @@ -24,11 +24,9 @@ void AnnimateSlideWidget::setAnimWidget(QWidget* w, QWidget* container_widget)
_anim_widget = w;
_anim_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_anim_hide = new QPropertyAnimation(_anim_widget, "minimumWidth");
connect(_anim_hide, &QPropertyAnimation::finished, this, &AnnimateSlideWidget::onFinished);
_anim_hide->setDuration(250);
_anim_hide->setDuration(100);

_anim_show = new QPropertyAnimation(_anim_widget, "minimumWidth");
connect(_anim_show, &QPropertyAnimation::finished, this, &AnnimateSlideWidget::onFinished);
_anim_show->setDuration(100);
}

Expand Down
54 changes: 31 additions & 23 deletions src/mvc/AnnimateSlideWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QWidget>
#include <QPropertyAnimation>
#include <QPushButton>
#include <QCoreApplication>

//---------------------------------------------------------------------------

Expand All @@ -20,6 +21,8 @@ class AnnimateSlideWidget : public QWidget

Q_OBJECT

enum class SlideState {SlideIn, SlideOut};

public:

AnnimateSlideWidget(QWidget *parent = nullptr);
Expand All @@ -34,18 +37,16 @@ class AnnimateSlideWidget : public QWidget

virtual void enterEvent(QEnterEvent *event) override
{
if(_anim_enabled && false == _running)
if(_anim_enabled)
{
_running = true;
animateSlideOut();
}
}
}

virtual void leaveEvent(QEvent *event) override
{
if(_anim_enabled && false == _running)
if(_anim_enabled)
{
_running = true;
animateSlideIn();
}
}
Expand All @@ -54,38 +55,45 @@ private slots:
void animateSlideIn()
{
// Animate the widget to slide in
if(_first)
if ( _anim_hide->state() == QAbstractAnimation::State::Stopped
&& _anim_show->state() == QAbstractAnimation::State::Stopped
&& _cur_state == SlideState::SlideOut)
{
_saved_width = _anim_widget->width();
_first = false;
if(_first)
{
_saved_width = _anim_widget->width();
_first = false;
_anim_hide->setStartValue(_saved_width);
_anim_hide->setEndValue(20);

_anim_show->setStartValue(20);
_anim_show->setEndValue(_saved_width);
}

_cur_state = SlideState::SlideIn;
_anim_hide->start();
}
_anim_hide->setStartValue(_saved_width);
_anim_hide->setEndValue(20);

_anim_show->setStartValue(20);
_anim_show->setEndValue(_saved_width);

_anim_hide->start();
}

void animateSlideOut()
{
_anim_show->start();
}

void onFinished()
{
_running = false;
if ( _anim_hide->state() == QAbstractAnimation::State::Stopped
&& _anim_show->state() == QAbstractAnimation::State::Stopped
&& _cur_state == SlideState::SlideIn)
{
_cur_state = SlideState::SlideOut;
_anim_show->start();
}
}

private:
QWidget* _anim_widget;
QPropertyAnimation *_anim_hide;
QPropertyAnimation *_anim_show;
bool _anim_enabled;
bool _first;
bool _running;
SlideState _cur_state;
int _saved_width;
bool _first;
};

//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/BatchRoiFitWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void BatchRoiFitWidget::createLayout()
_le_detectors = new QLineEdit("0,1,2,3,4,5,6");

_cb_opt_method = new QComboBox();
_cb_opt_method->addItem(STR_HYBRID_MP_FIT);
_cb_opt_method->addItem(STR_MP_FIT);
_cb_opt_method->addItem(STR_HYBRID_MP_FIT);
_cb_opt_method->addItem(STR_LM_FIT);
connect(_cb_opt_method, &QComboBox::currentTextChanged, this, &BatchRoiFitWidget::optimizer_changed);

Expand Down
65 changes: 65 additions & 0 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,71 @@ class BlueskyComm : public QThread
}
return ret;
}

//---------------------------------------------------------------------------

bool movePlan(QString &msg, int srcRow, int destRow)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;

QJsonObject params;
params["pos"] = srcRow;
params["pos_dest"] = destRow;
QByteArray msg_arr = gen_send_mesg2("queue_item_move", params);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());

_zmq_comm_socket->recv(&message);
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
if(reply.contains("success"))
{
if(reply["success"].toString() == "true")
{
ret = true;
}
}
if(reply.contains("msg"))
{
msg = reply["msg"].toString();
}
return ret;
}

//---------------------------------------------------------------------------

bool removePlan(QString &msg, int row)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;

QJsonObject params;
params["pos"] = row;
QByteArray msg_arr = gen_send_mesg2("queue_item_remove", params);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());

_zmq_comm_socket->recv(&message);
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
if(reply.contains("success"))
{
if(reply["success"].toString() == "true")
{
ret = true;
}
}
if(reply.contains("msg"))
{
msg = reply["msg"].toString();
}
return ret;
}

//---------------------------------------------------------------------------

Expand Down
21 changes: 5 additions & 16 deletions src/mvc/FitSpectraWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ void FitSpectraWidget::createLayout()


_cb_opttimizer = new QComboBox();
_cb_opttimizer->addItem(STR_HYBRID_MP_FIT);
_cb_opttimizer->addItem(STR_MP_FIT);
_cb_opttimizer->addItem(STR_HYBRID_MP_FIT);
_cb_opttimizer->addItem(STR_LM_FIT);
connect(_cb_opttimizer, &QComboBox::currentTextChanged, this, &FitSpectraWidget::optimizer_changed);

Expand Down Expand Up @@ -313,9 +313,9 @@ void FitSpectraWidget::createLayout()
// splitter->setStretchFactor(0, 1);
// splitter->addWidget(tab_and_buttons_widget);

_cb_fitting_preset->setCurrentIndex(2);
//optimizer_preset_changed(2); // batch with no tails
optimizer_changed(STR_HYBRID_MP_FIT);
_cb_fitting_preset->setCurrentIndex(3);
//optimizer_preset_changed(3); // batch with tails
optimizer_changed(STR_MP_FIT);

QLayout* layout = new QVBoxLayout();
// layout->addWidget(splitter);
Expand Down Expand Up @@ -1125,13 +1125,6 @@ void FitSpectraWidget::Fit_ROI_Spectra_Click()
{
_fit_spec += _spectra_background;
}
for (int i = 0; i < _fit_spec.size(); i++)
{
if (_fit_spec[i] <= 0.0)
{
_fit_spec[i] = 0.1;
}
}

fitting::optimizers::OPTIMIZER_OUTCOME outcome = _fitting_dialog->getOutcome();
std::string result = fitting::optimizers::optimizer_outcome_to_str(outcome);
Expand Down Expand Up @@ -1204,11 +1197,7 @@ void FitSpectraWidget::Model_Spectra_Click()
{
fit_spec += _spectra_background;
}
for(int i=0; i<fit_spec.size(); i++)
{
if(fit_spec[i] <= 0.0)
fit_spec[i] = 0.1;
}

_spectra_widget->append_spectra(DEF_STR_MODEL_SPECTRA, &fit_spec, (data_struct::Spectra<double>*)&_ev);
}
emit signal_finished_fit();
Expand Down
29 changes: 7 additions & 22 deletions src/mvc/FittingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,7 @@ void FittingDialog::setElementsToFit(data_struct::Fit_Element_Map_Dict<double>*
if (_elements_to_fit != nullptr)
{

data_struct::Spectra<double> fit_spec = _model.model_spectrum(&_out_fit_params, _elements_to_fit, &_labeled_spectras, _energy_range);
/*
if (fit_spec.size() == _spectra_background.size())
{
fit_spec += _spectra_background;
}
*/
for (int i = 0; i < fit_spec.size(); i++)
{
if (fit_spec[i] <= 0.0)
{
fit_spec[i] = 0.1;
}
}

data_struct::Spectra<double> fit_spec = _model.model_spectrum(&_out_fit_params, _elements_to_fit, &_labeled_spectras, _energy_range);
_spectra_widget->append_spectra(DEF_STR_FIT_INT_SPECTRA, &fit_spec, &_ev);
}
}
Expand Down Expand Up @@ -486,6 +472,12 @@ void FittingDialog::runProcessing()
if (_new_fit_spec.size() == _spectra_background.size())
{
_new_fit_spec += _spectra_background;
/*
for(auto &itr : _labeled_spectras)
{
itr.second += _spectra_background;
}
*/
}

data_struct::Range energy_range = data_struct::get_energy_range(_new_fit_spec.rows(), &(_out_fit_params));
Expand All @@ -500,13 +492,6 @@ void FittingDialog::runProcessing()
_spectra_background[i] = 0.0;
}

for (int i = 0; i < _new_fit_spec.size(); i++)
{
if (_new_fit_spec[i] <= 0.0)
{
_new_fit_spec[i] = 0.01;
}
}

_spectra_widget->append_spectra(DEF_STR_NEW_FIT_INT_SPECTRA, &_new_fit_spec, &_ev);
}
Expand Down
1 change: 0 additions & 1 deletion src/mvc/ImageStackControlWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ void ImageStackControlWidget::createLayout()
//QWidget *leftWidget = new QWidget();
//leftWidget->setLayout(hlayout2);
_files_anim_widget->setAnimWidget(_mapsFilsWidget, _files_dock);
//_files_anim_widget->setAnimWidget(_mapsFilsWidget, ">");

QWidget *rightWidget = new QWidget();
rightWidget->setLayout(vlayout);
Expand Down
Loading

0 comments on commit 6ac77ea

Please sign in to comment.