Skip to content

Commit

Permalink
Merge pull request #96 from aglowacki/master
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
aglowacki authored Nov 19, 2024
2 parents 7347fcf + d954547 commit 51e8dc9
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 124 deletions.
7 changes: 7 additions & 0 deletions src/core/uProbeX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ uProbeX::~uProbeX()
}
}
m_subWindows.clear();
exitApplication();
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -855,6 +856,12 @@ void uProbeX::openMapsWorkspace(QString dirName)
QDir dir(dirName);
dir.mkdir("img.dat");
dir.mkdir("output");
QString ss1 = QString("output") + QDir::separator() + QString::fromStdString(STR_FIT_SPEC_DIR);
dir.mkdir(ss1);
ss1 = QString("output") + QDir::separator() + QString::fromStdString(STR_INT_SPEC_DIR);
dir.mkdir(ss1);
ss1 = QString("output") + QDir::separator() + QString::fromStdString(STR_FIT_PARAM_DIR);
dir.mkdir(ss1);

QStringList recentPaths = Preferences::inst()->getValue(STR_RECENT_MAPS_WORKSPACES).toStringList();
recentPaths.removeAll(dirName);
Expand Down
1 change: 1 addition & 0 deletions src/mvc/BatchRoiFitWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void BatchRoiFitWidget::runProcessing()

//run in thread
analysis_job.dataset_directory = _directory;
analysis_job.output_dir = _directory;
if (_optimizer_widget->isHybrid())
{
analysis_job.optimize_fit_routine = OPTIMIZE_FIT_ROUTINE::HYBRID;
Expand Down
119 changes: 27 additions & 92 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,20 @@
//---------------------------------------------------------------------------


class BlueskyComm : public QThread
class BlueskyComm
{

Q_OBJECT

public:

/**
* Constructor.
*/
BlueskyComm(QString str_ip, QObject* parent = nullptr) : QThread(parent)
BlueskyComm(zmq::context_t *context, QString str_ip)
{

std::string conn_str = "tcp://"+str_ip.toStdString()+":60615";
std::string lsn_str = "tcp://"+str_ip.toStdString()+":60625";
_context = new zmq::context_t(1);
_zmq_comm_socket = new zmq::socket_t(*_context, ZMQ_REQ);
_zmq_comm_socket = new zmq::socket_t(*context, ZMQ_REQ);
_zmq_comm_socket->connect(conn_str);
_zmq_lsn_socket = new zmq::socket_t(*_context, ZMQ_SUB);
_zmq_lsn_socket->connect(lsn_str);
_zmq_lsn_socket->set(zmq::sockopt::subscribe, "QS_Console");
_zmq_lsn_socket->set(zmq::sockopt::rcvtimeo, 1000); //set timeout to 1000ms

}

//---------------------------------------------------------------------------
Expand All @@ -57,19 +48,7 @@ class BlueskyComm : public QThread
_zmq_comm_socket->close();
delete _zmq_comm_socket;
}
if(_zmq_lsn_socket != nullptr)
{
_zmq_lsn_socket->close();
delete _zmq_lsn_socket;
}
if (_context != nullptr)
{
_context->close();
delete _context;
}
_zmq_comm_socket = nullptr;
_zmq_lsn_socket = nullptr;
_context = nullptr;
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -172,9 +151,9 @@ class BlueskyComm : public QThread
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("environment_open", nullptr);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -206,9 +185,9 @@ class BlueskyComm : public QThread
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("environment_close", nullptr);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -240,9 +219,9 @@ class BlueskyComm : public QThread
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("queue_start", nullptr);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -274,9 +253,9 @@ class BlueskyComm : public QThread
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("queue_stop", nullptr);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -312,9 +291,9 @@ class BlueskyComm : public QThread
params["user_group"] = "primary";
QByteArray msg_arr = gen_send_mesg2("queue_item_add", params);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -350,9 +329,9 @@ class BlueskyComm : public QThread
params["user_group"] = "primary";
QByteArray msg_arr = gen_send_mesg2("queue_item_update", params);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -388,9 +367,9 @@ class BlueskyComm : public QThread
params["pos_dest"] = destRow;
QByteArray msg_arr = gen_send_mesg2("queue_item_move", params);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -424,9 +403,9 @@ class BlueskyComm : public QThread
params["pos"] = row;
QByteArray msg_arr = gen_send_mesg2("queue_item_remove", params);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -462,9 +441,9 @@ class BlueskyComm : public QThread
params["user_group"] = "primary";
QByteArray msg_arr = gen_send_mesg("plans_allowed", &params);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);;
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);;

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -568,9 +547,9 @@ class BlueskyComm : public QThread
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("queue_get", nullptr);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
Expand Down Expand Up @@ -781,9 +760,9 @@ class BlueskyComm : public QThread
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("history_clear", nullptr);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
msg = QString::fromUtf8((char*)message.data(), message.size());
Expand All @@ -808,9 +787,9 @@ class BlueskyComm : public QThread
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("history_get", nullptr);
zmq::message_t zmsg(msg_arr.data(), msg_arr.length());
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg, zmq::send_flags::none);
zmq::send_result_t s_res = _zmq_comm_socket->send(zmsg);

zmq::recv_result_t r_res = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
zmq::recv_result_t r_res = _zmq_comm_socket->recv(message);
if(r_res.has_value())
{
if(raw_mesg)
Expand Down Expand Up @@ -963,54 +942,10 @@ class BlueskyComm : public QThread

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

public slots:
void run() override
{
_running = true;
zmq::message_t token, message;
while(_running)
{
zmq::recv_result_t r_res = _zmq_lsn_socket->recv(token, zmq::recv_flags::none);
if(r_res.has_value())
{
std::string s1 ((char*)token.data(), token.size());
if(s1 == "QS_Console")
{
zmq::recv_result_t r_res2 = _zmq_comm_socket->recv(message, zmq::recv_flags::none);
if(r_res2.has_value())
{
QJsonObject rootJson = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
if(rootJson.contains("msg"))
{
QString msg = rootJson["msg"].toString();
msg.chop(1);
emit newData(msg);
}
else
{
// logI<<data.toStdString()<<"\n"; // may cause issues coming from a thread
}
}
}
}
}
_zmq_lsn_socket->close();
}
void stop() {_running = false;}

signals:
void newData(const QString&);

protected:

bool _running;

zmq::context_t *_context;

zmq::socket_t *_zmq_comm_socket;

zmq::socket_t *_zmq_lsn_socket;

};


Expand Down
11 changes: 5 additions & 6 deletions src/mvc/FileTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ FileTabWidget::FileTabWidget(QWidget* parent) : QWidget(parent)
_file_list_view->setSelectionMode(QAbstractItemView::ExtendedSelection); //MultiSelection
_file_list_view->setSortingEnabled(true);

//_file_list_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
_file_list_view->horizontalHeader()->resizeSections(QHeaderView::Interactive);
_file_list_view->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);


// if preferences saves on select changes loaded dataset
connect(_file_list_view->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &FileTabWidget::onFileRowChange);

Expand Down Expand Up @@ -220,9 +225,6 @@ void FileTabWidget::set_file_list(const std::map<QString, QFileInfo>& fileinfo_l
{
_file_list_model->appendRow( RowData(QIcon(":/images/circle_gray.png"), itr.first, (double)itr.second.size()/divisor));
}

_file_list_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
_file_list_view->horizontalHeader()->resizeSections(QHeaderView::Interactive);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -280,9 +282,6 @@ void FileTabWidget::update_file_list(const std::map<QString, QFileInfo>& fileinf
_file_list_model->appendRow(RowData(QIcon(":/images/circle_gray.png"), itr.first, (double)itr.second.size()/divisor));
}
}

_file_list_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
_file_list_view->horizontalHeader()->resizeSections(QHeaderView::Interactive);
}

//---------------------------------------------------------------------------
Expand Down
16 changes: 12 additions & 4 deletions src/mvc/FitParamsTableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,30 @@ QVariant FitParamsTableModel::data(const QModelIndex &index, int role) const
data_struct::Fit_Param<double> fitp = _fit_parameters.at(_row_indicies[row]);
if (index.column() == VALUE || index.column() == MIN_VAL)
{
if (fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO || fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO_HI)
if (fitp.value < fitp.min_val)
{
if (fitp.value < fitp.min_val)
if (fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO || fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO_HI)
{
return QColor(Qt::red);
}
else
{
return QColor(Qt::darkYellow);
}
}
}
if (index.column() == VALUE || index.column() == MAX_VAL)
{
if (fitp.bound_type == data_struct::E_Bound_Type::LIMITED_HI || fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO_HI)
if (fitp.value > fitp.max_val)
{
if (fitp.value > fitp.max_val)
if (fitp.bound_type == data_struct::E_Bound_Type::LIMITED_HI || fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO_HI)
{
return QColor(Qt::red);
}
else
{
return QColor(Qt::darkYellow);
}
}
}
}
Expand Down
Loading

0 comments on commit 51e8dc9

Please sign in to comment.