Skip to content

Commit

Permalink
Added ability to edit plans that are queued in table
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Oct 15, 2024
1 parent a43e983 commit 8eeb775
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 6 deletions.
44 changes: 44 additions & 0 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <zmq.hpp>
#include "mvc/BlueskyPlan.h"
#include <string>

#include "core/defines.h"
//---------------------------------------------------------------------------


Expand Down Expand Up @@ -118,6 +120,10 @@ class BlueskyComm : public QThread

QJsonObject item;

if(plan.uuid.length() > 0)
{
item["item_uid"] = plan.uuid;
}
item["name"] = plan.type;
item["item_type"] = "plan";
QJsonObject meta;
Expand All @@ -127,6 +133,7 @@ class BlueskyComm : public QThread
QJsonObject kwargs;
for(auto itr: plan.parameters)
{
logI<<itr.first.toStdString()<<" : "<<itr.second.default_val.toStdString()<<" :: "<<(int)(itr.second.kind)<< "\n";
if(itr.second.name == "detectors")
{
QJsonArray inner_args; // need this for bluesky or it doesn't work
Expand Down Expand Up @@ -306,6 +313,41 @@ class BlueskyComm : public QThread
return ret;
}

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

bool update_plan(QString &msg, const BlueskyPlan& plan)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;

QJsonObject params;
params["item"] = plan_to_json_item(plan);
params["user"] = "uProbeX";
params["user_group"] = "primary";
QByteArray msg_arr = gen_send_mesg2("queue_item_update", 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 movePlan(QString &msg, int srcRow, int destRow)
Expand Down Expand Up @@ -561,10 +603,12 @@ class BlueskyComm : public QThread
{
double p = kwargs.value(pitr).toDouble();
bsp.default_val = QString::number(p);
bsp.kind = BlueskyParamType::Numeral;
}
else if( kwargs.value(pitr).isString() )
{
bsp.default_val = kwargs.value(pitr).toString();
bsp.kind = BlueskyParamType::String;
}
plan.parameters[pitr] = bsp;
}
Expand Down
23 changes: 23 additions & 0 deletions src/mvc/LiveMapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void LiveMapsElementsWidget::createLayout()
connect(_scan_queue_widget, &ScanQueueWidget::onMoveScanUp, this, &LiveMapsElementsWidget::callMoveScanUp);
connect(_scan_queue_widget, &ScanQueueWidget::onMoveScanDown, this, &LiveMapsElementsWidget::callMoveScanDown);
connect(_scan_queue_widget, &ScanQueueWidget::onRemoveScan, this, &LiveMapsElementsWidget::callRemoveScan);
connect(_scan_queue_widget, &ScanQueueWidget::onPlanChanged, this, &LiveMapsElementsWidget::callUpdatePlan);

_tab_widget = new QTabWidget();
_tab_widget->addTab(_mapsElementsWidget, "Counts");
Expand Down Expand Up @@ -493,3 +494,25 @@ void LiveMapsElementsWidget::callRemoveScan(int row)
}

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

void LiveMapsElementsWidget::callUpdatePlan(const BlueskyPlan& plan)
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->update_plan(msg, plan))
{

}
else
{

}

_scan_queue_widget->newDataArrived( msg );
getQueuedScans();
}

//---------------------------------------------------------------------------
2 changes: 2 additions & 0 deletions src/mvc/LiveMapsElementsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public slots:

void callRemoveScan(int);

void callUpdatePlan(const BlueskyPlan& plan);

void queueScan(const BlueskyPlan& plan);

protected:
Expand Down
25 changes: 19 additions & 6 deletions src/mvc/ScanQueueTableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ class ScanQueueTableModel : public QAbstractTableModel
return Qt::NoItemFlags;
}

return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
if(index.column() == 0)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
}
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}

//---------------------------------------------------------------------------
Expand All @@ -228,12 +232,21 @@ class ScanQueueTableModel : public QAbstractTableModel
{
if (role == Qt::EditRole && index.isValid())
{
if( index.row() < _data.size() && index.column() == 2)
if( index.row() < _data.size() && index.column() != 0)
{
_data[index.row()].user = value.toString();
return true;
int idx = 1;
for (auto &itr : _data[index.row()].parameters)
{
if(idx == index.column())
{
// this will be refreshed from qserver
itr.second.default_val = value.toString();
emit planChanged(_data.at(index.row()));
return true;
}
idx ++;
}
}
return false;
}
return false;

Expand All @@ -242,7 +255,7 @@ class ScanQueueTableModel : public QAbstractTableModel

signals:
void moveScanRow(int, int);

void planChanged(const BlueskyPlan&);

private:
QList<BlueskyPlan> _data;
Expand Down
1 change: 1 addition & 0 deletions src/mvc/ScanQueueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void ScanQueueWidget::_createLayout()

_scan_queue_table_model = new ScanQueueTableModel();
connect(_scan_queue_table_model, &ScanQueueTableModel::moveScanRow, this, &ScanQueueWidget::onMoveScanRow);
connect(_scan_queue_table_model, &ScanQueueTableModel::planChanged, this, &ScanQueueWidget::onPlanChanged);
_scan_queue_table_view = new QTableView();
_scan_queue_table_view->setModel(_scan_queue_table_model);
_scan_queue_table_view->setSelectionBehavior(QAbstractItemView::SelectRows);
Expand Down
2 changes: 2 additions & 0 deletions src/mvc/ScanQueueWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ScanQueueWidget : public QWidget

void onRemoveScan(int);

void onPlanChanged(const BlueskyPlan&);

public slots:
void newDataArrived(const QString &);

Expand Down

0 comments on commit 8eeb775

Please sign in to comment.