Skip to content

Commit

Permalink
Use meta data for bluesky plans as scan name
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Aug 12, 2024
1 parent 3aa420a commit 7100d76
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/gstar/Annotation/ScanRegionGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ void ScanRegionGraphicsItem::onScanUpdated(const BlueskyPlan& plan)
{

setPropertyValue(DEF_STR_DISPLAY_NAME, _scan_dialog.getScanName());
emit scanUpdated(plan);
BlueskyPlan nplan = plan;
nplan.name = _scan_dialog.getScanName();
BlueskyParam meta_data;
meta_data.name = "md";
meta_data.default_val = nplan.name;
meta_data.description = "Link to scan name";
nplan.parameters["md"] = meta_data;
emit scanUpdated(nplan);

}
/*
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/BatchRoiFitWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ void BatchRoiFitWidget::createLayout()

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

_file_list_model = new QStandardItemModel();
Expand Down
38 changes: 35 additions & 3 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BlueskyComm : public QThread

QJsonObject item;

item["name"] = plan.name;
item["name"] = plan.type;
item["item_type"] = "plan";

QJsonObject kwargs;
Expand All @@ -137,6 +137,11 @@ class BlueskyComm : public QThread
{
//
bool ret = false;

if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("environment_open", nullptr);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());
Expand All @@ -163,6 +168,10 @@ class BlueskyComm : public QThread
{
//
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("environment_close", nullptr);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());
Expand All @@ -189,6 +198,10 @@ class BlueskyComm : public QThread
{
//
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("queue_start", nullptr);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());
Expand All @@ -215,6 +228,10 @@ class BlueskyComm : public QThread
{
//
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("queue_stop", nullptr);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());
Expand All @@ -240,6 +257,10 @@ class BlueskyComm : public QThread
bool queue_plan(QString &msg, const BlueskyPlan& plan)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;

QJsonObject params;
Expand Down Expand Up @@ -274,7 +295,10 @@ class BlueskyComm : public QThread

//params["user_group"] = "primary";
//obj["params"] = params;

if(_zmq_comm_socket == nullptr)
{
return ret;
}
std::map<QString, QString> params;
params["user_group"] = "primary";
QByteArray msg_arr = gen_send_mesg("plans_allowed", &params);
Expand Down Expand Up @@ -350,6 +374,10 @@ class BlueskyComm : public QThread
bool get_queued_scans(QString &msg, std::vector<BlueskyPlan> &queued_plans, BlueskyPlan &running_plan)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
running_plan.name = "";
running_plan.uuid = "";
zmq::message_t message;
Expand Down Expand Up @@ -393,7 +421,7 @@ class BlueskyComm : public QThread
QJsonObject param = itr2.toObject();
if(param.contains("name"))
{
plan.name = param["name"].toString();
plan.type = param["name"].toString();
}
if(param.contains("args"))
{
Expand All @@ -409,6 +437,10 @@ class BlueskyComm : public QThread
bsp.name = pitr;
bsp.default_val = kwargs[pitr].toString();
plan.parameters[pitr] = bsp;
if(pitr == "md") // use meta data to link to scan name
{
plan.name = bsp.default_val;
}
}
}
if(param.contains("user"))
Expand Down
1 change: 1 addition & 0 deletions src/mvc/BlueskyPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct BlueskyPlan
user="";
}
QString name;
QString type;
QString description;
QString module;
std::unordered_map<QString, BlueskyParam> parameters;
Expand Down
28 changes: 28 additions & 0 deletions src/mvc/LiveMapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ void LiveMapsElementsWidget::image_changed(int start, int end)
void LiveMapsElementsWidget::updateScansAvailable()
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->get_avail_scans(_avail_scans, msg))
{
_scan_queue_widget->newDataArrived( msg );
Expand All @@ -300,6 +304,10 @@ void LiveMapsElementsWidget::updateScansAvailable()
void LiveMapsElementsWidget::getQueuedScans()
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->get_queued_scans(msg, _queued_scans, _running_scan))
{
_scan_queue_widget->newDataArrived( msg );
Expand All @@ -315,6 +323,10 @@ void LiveMapsElementsWidget::getQueuedScans()
void LiveMapsElementsWidget::callOpenEnv()
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->open_env(msg))
{
//_scan_queue_widget->newDataArrived( msg );
Expand All @@ -332,6 +344,10 @@ void LiveMapsElementsWidget::callOpenEnv()
void LiveMapsElementsWidget::callCloseEnv()
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->close_env(msg))
{
//_scan_queue_widget->newDataArrived( msg );
Expand All @@ -349,6 +365,10 @@ void LiveMapsElementsWidget::callCloseEnv()
void LiveMapsElementsWidget::callStartQueue()
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->start_queue(msg))
{
//_scan_queue_widget->newDataArrived( msg );
Expand All @@ -366,6 +386,10 @@ void LiveMapsElementsWidget::callStartQueue()
void LiveMapsElementsWidget::callStopQueue()
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->stop_queue(msg))
{
//_scan_queue_widget->newDataArrived( msg );
Expand All @@ -383,6 +407,10 @@ void LiveMapsElementsWidget::callStopQueue()
void LiveMapsElementsWidget::queueScan(const BlueskyPlan& plan)
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->queue_plan(msg, plan))
{

Expand Down
17 changes: 10 additions & 7 deletions src/mvc/ScanQueueTableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class ScanQueueTableModel : public QAbstractTableModel
ScanQueueTableModel(QObject* parent = nullptr) : QAbstractTableModel(parent)
{
_headers[0] = "name";
_headers[1] = "user";
_headers[2] = "uuid";
_headers[1] = "type";
_headers[2] = "user";
_headers[3] = "uuid";
}
//---------------------------------------------------------------------------
int rowCount(const QModelIndex& parent = QModelIndex()) const override
Expand All @@ -31,7 +32,7 @@ class ScanQueueTableModel : public QAbstractTableModel

int columnCount(const QModelIndex& parent = QModelIndex()) const override
{
return 3;
return 4;
}
//---------------------------------------------------------------------------
void appendRow(const BlueskyPlan& row)
Expand Down Expand Up @@ -86,8 +87,10 @@ class ScanQueueTableModel : public QAbstractTableModel
case 0:
return rowData.name;
case 1:
return rowData.user;
return rowData.type;
case 2:
return rowData.user;
case 3:
return rowData.uuid;
};
}
Expand All @@ -102,7 +105,7 @@ class ScanQueueTableModel : public QAbstractTableModel
// Horizontal headers
if (orientation == Qt::Horizontal)
{
if(section > 3)
if(section > 4)
{
return QVariant();
}
Expand Down Expand Up @@ -147,7 +150,7 @@ class ScanQueueTableModel : public QAbstractTableModel
{
if (role == Qt::EditRole && index.isValid())
{
if( index.row() < _data.size() && index.column() == 1)
if( index.row() < _data.size() && index.column() == 2)
{
_data[index.row()].user = value.toString();
return true;
Expand All @@ -162,7 +165,7 @@ class ScanQueueTableModel : public QAbstractTableModel
private:
QList<BlueskyPlan> _data;

QString _headers[3];
QString _headers[4];
};


Expand Down
8 changes: 8 additions & 0 deletions src/mvc/ScanQueueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QHeaderView>
#include <QDockWidget>
#include "core/defines.h"

Expand Down Expand Up @@ -38,10 +39,15 @@ void ScanQueueWidget::_createLayout()
_scan_running_table_view = new QTableView();
_scan_running_table_view->setFixedHeight(100);
_scan_running_table_view->setModel(_scan_running_table_model);
_scan_running_table_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
// _scan_running_table_view->horizontalHeader()->resizeSections(QHeaderView::Interactive);

_scan_queue_table_model = new ScanQueueTableModel();
_scan_queue_table_view = new QTableView();
_scan_queue_table_view->setModel(_scan_queue_table_model);
_scan_queue_table_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
// _scan_queue_table_view->horizontalHeader()->resizeSections(QHeaderView::Interactive);


QSize btn_size(33,33);

Expand Down Expand Up @@ -105,12 +111,14 @@ void ScanQueueWidget::_createLayout()
void ScanQueueWidget::updateQueuedItems( std::vector<BlueskyPlan> &queued_plans, BlueskyPlan &running_plan)
{
_scan_queue_table_model->setAllData(queued_plans);
_scan_queue_table_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
std::vector<BlueskyPlan> runlist;
if(running_plan.uuid.length() > 0)
{
runlist.push_back(running_plan);
}
_scan_running_table_model->setAllData(runlist);
_scan_running_table_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
}

//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/ScanRegionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void ScanRegionDialog::onUpdate()
void ScanRegionDialog::onUpdateAndQueue()
{
BlueskyPlan plan;
plan.name = _scan_type->currentText();
plan.type = _scan_type->currentText();
_scan_table_model->getCurrentParams(plan);
emit ScanUpdated(plan);
close();
Expand Down

0 comments on commit 7100d76

Please sign in to comment.