diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/Math/tracemath.h b/Software/PC_Application/LibreVNA-GUI/Traces/Math/tracemath.h index ad6c894..ba5660d 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/Math/tracemath.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/Math/tracemath.h @@ -53,7 +53,7 @@ public: class Data { public: - Data() : x(0){} + Data() : x(0), y(0){} double x; std::complex y; }; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp index b9fb90e..07ce3df 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp @@ -6,6 +6,7 @@ #include "traceaxis.h" #include "tracemodel.h" #include "Math/parser/mpParser.h" +#include "preferences.h" #include #include @@ -684,10 +685,6 @@ nlohmann::json Trace::toJSON() if(!JSONskipHash) { j["hash"] = toHash(true); } - if(source == Source::Calibration) { - // calibration traces can't be saved - return j; - } j["name"] = _name.toStdString(); j["color"] = _color.name().toStdString(); j["visible"] = visible; @@ -717,7 +714,7 @@ nlohmann::json Trace::toJSON() } break; case Source::Calibration: - // Skip for now, TODO? + j["type"] = "Calibration"; break; case Source::Last: break; @@ -725,6 +722,19 @@ nlohmann::json Trace::toJSON() j["velocityFactor"] = vFactor; j["reflection"] = reflection; + auto &pref = Preferences::getInstance(); + if(pref.Debug.saveTraceData) { + nlohmann::json jdata; + for(const auto &d : data) { + nlohmann::json jpoint; + jpoint["x"] = d.x; + jpoint["real"] = d.y.real(); + jpoint["imag"] = d.y.imag(); + jdata.push_back(jpoint); + } + j["data"] = jdata; + } + nlohmann::json mathList; for(auto m : mathOps) { if(m.math->getType() == Type::Last) { @@ -757,6 +767,16 @@ void Trace::fromJSON(nlohmann::json j) _color = QColor(QString::fromStdString(j.value("color", "yellow"))); visible = j.value("visible", true); auto type = QString::fromStdString(j.value("type", "Live")); + if(j.contains("data")) { + // Trace data is contained in the json, load now + clear(); + for(auto jpoint : j["data"]) { + Data d; + d.x = jpoint.value("x", 0.0); + d.y = complex(jpoint.value("real", 0.0), jpoint.value("imag", 0.0)); + data.push_back(d); + } + } if(type == "Live") { if(j.contains("parameter")) { if(j["parameter"].type() == nlohmann::json::value_t::string) { @@ -776,6 +796,7 @@ void Trace::fromJSON(nlohmann::json j) _liveType = j.value("livetype", LivedataType::Overwrite); paused = j.value("paused", false); } else if(type == "Touchstone" || type == "File") { + source = Source::File; auto filename = QString::fromStdString(j.value("filename", "")); fileParameter = j.value("parameter", 0); try { @@ -788,10 +809,10 @@ void Trace::fromJSON(nlohmann::json j) fillFromTouchstone(t, fileParameter); } } catch (const exception &e) { - std::string what = e.what(); - throw runtime_error("Failed to create from file:" + what); + qWarning() << "Failed to create from file:" << QString::fromStdString(e.what()); } } else if(type == "Math") { + source = Source::Math; mathFormula = QString::fromStdString(j.value("expression", "")); if(j.contains("sources")) { for(auto js : j["sources"]) { @@ -804,6 +825,9 @@ void Trace::fromJSON(nlohmann::json j) } } fromMath(); + } else if(type == "Calibration") { + source = Source::Calibration; + // data has already been loaded if present in the file } vFactor = j.value("velocityFactor", 0.66); reflection = j.value("reflection", false); @@ -841,6 +865,8 @@ void Trace::fromJSON(nlohmann::json j) updateLastMath(mathOps.rbegin()); } enableMath(j.value("math_enabled", true)); + // indicate successful loading of trace data + success(); } unsigned int Trace::toHash(bool forceUpdate) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp index 0be6a09..52972b7 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp @@ -63,12 +63,13 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) : ui->GSource->setId(ui->bLive, 0); ui->GSource->setId(ui->bFile, 1); - ui->GSource->setId(ui->bFile, 2); + ui->GSource->setId(ui->bMath, 2); if(t.getSource() == Trace::Source::Calibration) { // prevent editing imported calibration traces (and csv files for now) ui->bLive->setEnabled(false); ui->bFile->setEnabled(false); + ui->bMath->setEnabled(false); ui->CLiveType->setEnabled(false); ui->CLiveParam->setEnabled(false); } diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui index 24bae6c..da30276 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui @@ -143,7 +143,7 @@ - 3 + 0 @@ -398,6 +398,11 @@ + + ColorPickerButton + QPushButton +
CustomWidgets/colorpickerbutton.h
+
SIUnitEdit QLineEdit @@ -409,11 +414,6 @@
CustomWidgets/touchstoneimport.h
1
- - ColorPickerButton - QPushButton -
CustomWidgets/colorpickerbutton.h
-
CSVImport QWidget diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp index 55c67a6..d31f703 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp @@ -117,7 +117,6 @@ void TracePolar::setAuto(bool horizontally, bool vertically) bool TracePolar::positionWithinGraphArea(const QPoint &p) { - // TODO auto coord = pixelToData(p); if(abs(coord) <= edgeReflection) { return true; diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index 906f44e..3ff33b0 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -89,13 +89,11 @@ VNA::VNA(AppWindow *window, QString name) calMenu->addSeparator(); connect(calLoad, &QAction::triggered, [=](){ - LoadCalibration(""); + LoadCalibration(); }); connect(saveCal, &QAction::triggered, [=](){ - if(cal.toFile()) { - UpdateStatusbar(); - } + SaveCalibration(); }); connect(&cal, &Calibration::startMeasurements, this, &VNA::StartCalibrationMeasurements); @@ -705,7 +703,7 @@ void VNA::shutdown() if(cal.hasUnsavedChanges() && cal.getCaltype().type != Calibration::Type::None) { auto save = InformationBox::AskQuestion("Save calibration?", "The calibration contains data that has not been saved yet. Do you want to save it before exiting?", false); if(save) { - cal.toFile(); + SaveCalibration(); } } } @@ -1740,3 +1738,8 @@ bool VNA::LoadCalibration(QString filename) { return cal.fromFile(filename); } + +bool VNA::SaveCalibration(QString filename) +{ + return cal.toFile(filename); +} diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h index e04a28c..6fbba29 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h @@ -76,7 +76,8 @@ public: }; public slots: - bool LoadCalibration(QString filename); + bool LoadCalibration(QString filename = ""); + bool SaveCalibration(QString filename = ""); private slots: void NewDatapoint(VirtualDevice::VNAMeasurement m); diff --git a/Software/PC_Application/LibreVNA-GUI/main.ui b/Software/PC_Application/LibreVNA-GUI/main.ui index d34044d..0660b53 100644 --- a/Software/PC_Application/LibreVNA-GUI/main.ui +++ b/Software/PC_Application/LibreVNA-GUI/main.ui @@ -82,6 +82,7 @@ Help +
@@ -234,6 +235,11 @@ View USB log + + + Create Debug Data + + diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.cpp b/Software/PC_Application/LibreVNA-GUI/preferences.cpp index d5e7d73..fbd8c71 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.cpp +++ b/Software/PC_Application/LibreVNA-GUI/preferences.cpp @@ -388,6 +388,7 @@ void PreferencesDialog::setInitialGUIState() ui->SCPIServerPort->setValue(p->SCPIServer.port); ui->DebugMaxUSBlogSize->setValue(p->Debug.USBlogSizeLimit); + ui->DebugSaveTraceData->setChecked(p->Debug.saveTraceData); for(auto cd : p->compoundDevices) { ui->compoundList->addItem(cd->getDesription()); @@ -491,6 +492,7 @@ void PreferencesDialog::updateFromGUI() p->SCPIServer.port = ui->SCPIServerPort->value(); p->Debug.USBlogSizeLimit = ui->DebugMaxUSBlogSize->value(); + p->Debug.saveTraceData = ui->DebugSaveTraceData->isChecked(); p->nonTrivialWriting(); } diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.h b/Software/PC_Application/LibreVNA-GUI/preferences.h index 76c1e14..3a04717 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.h +++ b/Software/PC_Application/LibreVNA-GUI/preferences.h @@ -162,6 +162,7 @@ public: } SCPIServer; struct { double USBlogSizeLimit; + bool saveTraceData; } Debug; bool TCPoverride; // in case of manual port specification via command line @@ -268,6 +269,7 @@ private: {&SCPIServer.enabled, "SCPIServer.enabled", true}, {&SCPIServer.port, "SCPIServer.port", 19542}, {&Debug.USBlogSizeLimit, "Debug.USBlogSizeLimit", 10000000.0}, + {&Debug.saveTraceData, "Debug.saveTraceData", false}, {&compoundDeviceJSON, "compoundDeviceJSON", "[]"}, }}; }; diff --git a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui index 01e236d..28f7393 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui +++ b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui @@ -712,8 +712,8 @@ 0 0 - 565 - 863 + 749 + 846 @@ -1033,8 +1033,8 @@ 0 0 - 553 - 969 + 749 + 952 @@ -1961,6 +1961,22 @@
+ + + + Trace saving + + + + + + Include datapoints + + + + + +