Skip to content

Commit

Permalink
Added export history
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Oct 30, 2024
1 parent e0b4a81 commit bdec347
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/gstar/Annotation/ScanRegionGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ScanRegionGraphicsItem::ScanRegionGraphicsItem(QMap<QString, QString>& marker,
const QString ScanRegionGraphicsItem::displayName() const
{

return QString("Scan");
return QString("ScanRegion");

}

Expand Down
32 changes: 31 additions & 1 deletion src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,34 @@ class BlueskyComm : public QThread
*/
return ret;
}

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

bool clear_history(QString &msg)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("history_clear", nullptr);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());

_zmq_comm_socket->recv(&message);

msg = QString::fromUtf8((char*)message.data(), message.size());
QJsonObject reply = QJsonDocument::fromJson(msg.toUtf8()).object();
if(reply.contains("success"))
{
return true;
}
return false;
}

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

bool get_scan_history(QString &msg, std::vector<BlueskyPlan> &finished_plans)
bool get_scan_history(QString &msg, std::vector<BlueskyPlan> &finished_plans, bool raw_mesg=false)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
Expand All @@ -745,6 +769,12 @@ class BlueskyComm : public QThread

_zmq_comm_socket->recv(&message);

if(raw_mesg)
{
msg = QString::fromUtf8((char*)message.data(), message.size());
return true;
}

QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
if(reply.contains("success"))
{
Expand Down
47 changes: 47 additions & 0 deletions src/mvc/LiveMapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QFileDialog>
#include "core/defines.h"

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -142,6 +143,7 @@ void LiveMapsElementsWidget::createLayout()
connect(_scan_queue_widget, &ScanQueueWidget::onRemoveScan, this, &LiveMapsElementsWidget::callRemoveScan);
connect(_scan_queue_widget, &ScanQueueWidget::onPlanChanged, this, &LiveMapsElementsWidget::callUpdatePlan);
connect(_scan_queue_widget, &ScanQueueWidget::onAddScan, this, &LiveMapsElementsWidget::callQueueScan);
connect(_scan_queue_widget, &ScanQueueWidget::onExportHistory, this, &LiveMapsElementsWidget::exportHistory);

_tab_widget = new QTabWidget();
_tab_widget->addTab(_mapsElementsWidget, "Counts");
Expand Down Expand Up @@ -333,6 +335,51 @@ void LiveMapsElementsWidget::getQueuedScans()

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

void LiveMapsElementsWidget::exportHistory()
{

QDateTime date = QDateTime::currentDateTime();
QString formattedTime = date.toString("yyyy.MM.dd_hh.mm.ss");
QByteArray formattedTimeMsg = formattedTime.toLocal8Bit();
QString apath = "Scan_History_" + formattedTime + ".json";

QString fileName = QFileDialog::getSaveFileName(this,
"Scan History", apath,
tr("JSON (*.json)"));

if (!fileName.endsWith(".json"))
{
fileName += ".json";
}
QFile file(fileName);

if (!file.open(QIODevice::WriteOnly))
{
QMessageBox::warning(nullptr, "Export History", "The file is in read only mode");
}
QString msg;
if (false == _qserverComm->get_scan_history(msg, _finished_scans, true))
{
QMessageBox::warning(nullptr, "Export History", "Failed to get scan history from QServer");
_scan_queue_widget->newDataArrived( msg );
}

file.write(msg.toUtf8());
file.close();

QMessageBox::information(this, "Export History", "Saved!");

if (false == _qserverComm->clear_history(msg))
{
QMessageBox::warning(nullptr, "Export History", "Failed to clear scan history from QServer");
_scan_queue_widget->newDataArrived( msg );
}

getQueuedScans();
}

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

void LiveMapsElementsWidget::callOpenEnv()
{
QString msg;
Expand Down
2 changes: 2 additions & 0 deletions src/mvc/LiveMapsElementsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public slots:

void getQueuedScans();

void exportHistory();

void callOpenEnv();

void callCloseEnv();
Expand Down
10 changes: 9 additions & 1 deletion src/mvc/ScanQueueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ void ScanQueueWidget::_createLayout()
_btn_add_scan = new QPushButton("Add Scan");
connect(_btn_add_scan, &QPushButton::pressed, &_scan_dialog, &ScanRegionDialog::show);

_btn_add_batch_scan = new QPushButton("Add Batch Scan");
_btn_add_batch_scan->setEnabled(false);
connect(_btn_add_batch_scan, &QPushButton::pressed, &_scan_dialog, &ScanRegionDialog::show);

_btn_export_history = new QPushButton("Export History");
connect(_btn_export_history, &QPushButton::pressed, this, &ScanQueueWidget::onExportHistory);

_scan_dialog.setRegionNameVisible(false);
connect(&_scan_dialog, &ScanRegionDialog::ScanUpdated, this, &ScanQueueWidget::onAddScan);

Expand Down Expand Up @@ -123,7 +130,8 @@ void ScanQueueWidget::_createLayout()
grid->addWidget(_btn_open_env,0,3);
grid->addWidget(_btn_close_env,0,4);
grid->addWidget(_btn_add_scan,0,6);
//grid->addWidget(_btn_export_history,0,8);
grid->addWidget(_btn_add_batch_scan,0,7);
grid->addWidget(_btn_export_history,0,8);
grid->addItem(new QSpacerItem(999,10), 0,9);

layout->addItem(grid);
Expand Down
6 changes: 6 additions & 0 deletions src/mvc/ScanQueueWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class ScanQueueWidget : public QWidget

void onAddScan(const BlueskyPlan&);

void onExportHistory();

public slots:
void newDataArrived(const QString &);

Expand Down Expand Up @@ -101,6 +103,10 @@ public slots:

QPushButton* _btn_add_scan;

QPushButton* _btn_add_batch_scan;

QPushButton* _btn_export_history;

QAction* _move_scan_up;

QAction* _move_scan_down;
Expand Down

0 comments on commit bdec347

Please sign in to comment.