diff --git a/src/appvals/AppGlobalValues.h b/src/appvals/AppGlobalValues.h index b1b088a..fbd18e3 100644 --- a/src/appvals/AppGlobalValues.h +++ b/src/appvals/AppGlobalValues.h @@ -8,7 +8,8 @@ #define APP_VALUES()\ ADD_APP_VALUE(InProcessing)\ ADD_APP_VALUE(LastOperationTime)\ -ADD_APP_VALUE(LastOperation) +ADD_APP_VALUE(LastOperation)\ +ADD_APP_VALUE(EmptyScanFlag)\ #include #include diff --git a/src/device/DeviceManager.cpp b/src/device/DeviceManager.cpp index ae28cde..25cda10 100644 --- a/src/device/DeviceManager.cpp +++ b/src/device/DeviceManager.cpp @@ -10,6 +10,7 @@ #include #include #include "appvals/AppGlobalValues.h" +#include "json/ScanJson.h" #define TRIGGER_EVENT EventCenter::Default()->triggerEvent #define THROW_ERROR(errormsg)\ @@ -31,7 +32,6 @@ const char* getStatusString(int status) return ""; } - std::string getJsonFromPatInf(QObject* obj) { return ((QString*)obj)->toStdString(); @@ -229,6 +229,22 @@ void DeviceManager::timerEvent(QTimerEvent* event) { QString s("%1 %2"); s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss")).arg("Scan finished"); TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr, (QObject*)&s); + QString outputPath = GetDeviceInfo(DeviceInfo::DEV_OUTPATH); + outputPath = outputPath.replace("\\","/"); + if (outputPath.endsWith('/')) outputPath = outputPath.remove(outputPath.length()-1,1); + QStringList list = outputPath.split('/'); + if (list.length()){ + if (AppGlobalValues::EmptyScanFlag().toBool()){ + ScanJson::Current()->setEmptyScanID(list.last().toStdString().c_str()); + }else{ + ScanJson::Current()->setScanID(list.last().toStdString().c_str()); + } + ScanJson::Current()->save(); + } + else{ + QString msg("Scan Output Path error!"); + THROW_ERROR(msg); + } } //一般不会出现其他情况 else { @@ -267,6 +283,7 @@ void DeviceManager::processScan(const char* json, bool empty) { AppGlobalValues::setInProcessing(true); TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject*)&msg); qDebug() << "SetScanInfo>>>>>>>>>>>>>>>>>>>>"; + AppGlobalValues::setEmptyScanFlag(empty); int ret = SetScanInfo(json, empty ? 1 : 0); if (ret) { qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo failed"; @@ -293,6 +310,9 @@ void DeviceManager::processScan(const char* json, bool empty) { } void DeviceManager::close() { + #ifdef _WIN32 + StopDevice(); + #endif previewDataCaller->terminate(); delete previewDataCaller; } diff --git a/src/forms/scan/patientinformationform.cpp b/src/forms/scan/patientinformationform.cpp index b094f26..fbc2d1e 100644 --- a/src/forms/scan/patientinformationform.cpp +++ b/src/forms/scan/patientinformationform.cpp @@ -2,17 +2,13 @@ #include "ui_patientinformationform.h" #include "json/cJSON.h" #include "event/EventCenter.h" +#include "json/ScanJson.h" PatientInformationForm::PatientInformationForm(QWidget* parent) : QWidget(parent), ui(new Ui::PatientInformationForm) { ui->setupUi(this); - //ui->lbl_ID->setText(tr("")); - //ui->lbl_Date->setText(tr("")); - //ui->lbl_Name->setText(tr("")); - //ui->lbl_Sex->setText(tr("")); - //ui->lbl_Acc->setText(tr("")); connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() { ui->retranslateUi(this); @@ -63,6 +59,6 @@ const char* PatientInformationForm::getCurrentPatientJsonString(bool empty) { cJSON_AddItemToObject(root, "InstitutionAddress", cJSON_CreateString("HZ")); delete jsonstr; jsonstr = cJSON_Print(root); - cJSON_Delete(root); + ScanJson::Current()->store(root); return jsonstr; } diff --git a/src/json/ScanJson.cpp b/src/json/ScanJson.cpp new file mode 100644 index 0000000..e6145b0 --- /dev/null +++ b/src/json/ScanJson.cpp @@ -0,0 +1,20 @@ +// +// Created by Krad on 2022/5/11. +// + +#include "ScanJson.h" +#include +#include +#include +void ScanJson::save() { + if (!root) return; + QFile f(QString("%1/%2.json").arg(QCoreApplication::applicationDirPath(),scanID.c_str())); + f.open(QFileDevice::ReadWrite); + cJSON_AddItemToObject(root, "EmptyScanID", cJSON_CreateString(emptyScanID.c_str())); + cJSON_AddItemToObject(root, "ScanID", cJSON_CreateString(scanID.c_str())); + char* content = cJSON_Print(root); + f.write(content); + f.flush(); + f.close(); + free(content); +} diff --git a/src/json/ScanJson.h b/src/json/ScanJson.h new file mode 100644 index 0000000..296dda4 --- /dev/null +++ b/src/json/ScanJson.h @@ -0,0 +1,44 @@ +// +// Created by Krad on 2022/5/11. +// + +#ifndef GUI_SCANJSON_H +#define GUI_SCANJSON_H + +#include +#include "cJSON.h" + +class ScanJson { +public: + ~ScanJson(){ + if(root)cJSON_Delete(root); + } + void store(cJSON* json){ + if(root){ + cJSON_Delete(root); + root = nullptr; + } + root = json; + } + void setScanID(const char * id){ + scanID.clear(); + scanID.append(id); + } + void setEmptyScanID(const char * id){ + emptyScanID.clear(); + emptyScanID.append(id); + setScanID(id); + } + void save(); + static ScanJson* Current(){ + static ScanJson instance; + return &instance; + } +private: + std::string emptyScanID; + std::string scanID; + cJSON* root = nullptr; +}; + + +#endif //GUI_SCANJSON_H