diff --git a/Software/PC_Application/Application.pro b/Software/PC_Application/Application.pro index 4afcd2e..87b4b22 100644 --- a/Software/PC_Application/Application.pro +++ b/Software/PC_Application/Application.pro @@ -108,6 +108,7 @@ FORMS += \ Generator/signalgenwidget.ui \ Tools/impedancematchdialog.ui \ Traces/markerwidget.ui \ + Traces/smithchartdialog.ui \ Traces/traceeditdialog.ui \ Traces/traceexportdialog.ui \ Traces/traceimportdialog.ui \ diff --git a/Software/PC_Application/CustomWidgets/siunitedit.cpp b/Software/PC_Application/CustomWidgets/siunitedit.cpp index 62153b6..544c0c4 100644 --- a/Software/PC_Application/CustomWidgets/siunitedit.cpp +++ b/Software/PC_Application/CustomWidgets/siunitedit.cpp @@ -40,6 +40,7 @@ bool SIUnitEdit::eventFilter(QObject *, QEvent *event) if(key == Qt::Key_Escape) { // abort editing process and set old value setValueQuiet(_value); + emit editingAborted(); clearFocus(); return true; } @@ -62,6 +63,7 @@ bool SIUnitEdit::eventFilter(QObject *, QEvent *event) parseNewValue(1.0); } else { setValueQuiet(_value); + emit editingAborted(); } } return false; diff --git a/Software/PC_Application/CustomWidgets/siunitedit.h b/Software/PC_Application/CustomWidgets/siunitedit.h index 3d48506..5e868a9 100644 --- a/Software/PC_Application/CustomWidgets/siunitedit.h +++ b/Software/PC_Application/CustomWidgets/siunitedit.h @@ -20,6 +20,7 @@ public slots: signals: void valueChanged(double newvalue); void valueUpdated(QWidget *w); + void editingAborted(); protected: bool eventFilter(QObject *obj, QEvent *event) override; private: diff --git a/Software/PC_Application/Device/devicelog.cpp b/Software/PC_Application/Device/devicelog.cpp index 660f494..ccdccae 100644 --- a/Software/PC_Application/Device/devicelog.cpp +++ b/Software/PC_Application/Device/devicelog.cpp @@ -22,7 +22,7 @@ DeviceLog::DeviceLog(QWidget *parent) : } }); connect(ui->numLines, qOverload(&QSpinBox::valueChanged), [=](int lines) { - ui->text->setMaximumBlockCount(lines); + ui->text->setMaximumBlockCount(lines ); }); } diff --git a/Software/PC_Application/Traces/smithchartdialog.ui b/Software/PC_Application/Traces/smithchartdialog.ui new file mode 100644 index 0000000..eaf61bf --- /dev/null +++ b/Software/PC_Application/Traces/smithchartdialog.ui @@ -0,0 +1,89 @@ + + + SmithChartDialog + + + + 0 + 0 + 224 + 69 + + + + Smithchart Setup + + + + + + + + Display mode: + + + + + + + + Show complete traces + + + + + Limit to current span + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SmithChartDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SmithChartDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/Software/PC_Application/Traces/tracemarkermodel.cpp b/Software/PC_Application/Traces/tracemarkermodel.cpp index 491052f..a69a169 100644 --- a/Software/PC_Application/Traces/tracemarkermodel.cpp +++ b/Software/PC_Application/Traces/tracemarkermodel.cpp @@ -316,6 +316,9 @@ QWidget *MarkerSettingsDelegate::createEditor(QWidget *parent, const QStyleOptio e->setMaximumHeight(rowHeight); e->setParent(parent); connect(e, &SIUnitEdit::valueUpdated, this, &MarkerSettingsDelegate::commitData); + connect(e, &SIUnitEdit::editingAborted, [=](){ + marker->editingFrequeny = false; + }); } return e; } diff --git a/Software/PC_Application/Traces/traceplot.cpp b/Software/PC_Application/Traces/traceplot.cpp index a55d8cd..07116b9 100644 --- a/Software/PC_Application/Traces/traceplot.cpp +++ b/Software/PC_Application/Traces/traceplot.cpp @@ -1,18 +1,20 @@ #include "traceplot.h" - -//const QColor TracePlot::Background = QColor(0,0,0); -//const QColor TracePlot::Border = QColor(255,255,255); -//const QColor TracePlot::Divisions = QColor(255,255,255); #include "tracemarker.h" std::set TracePlot::plots; -TracePlot::TracePlot(QWidget *parent) : QWidget(parent) +TracePlot::TracePlot(TraceModel &model, QWidget *parent) + : QWidget(parent), + model(model) { contextmenu = new QMenu(); markedForDeletion = false; setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); lastUpdate = QTime::currentTime(); + sweep_fmin = std::numeric_limits::lowest(); + sweep_fmax = std::numeric_limits::max(); + // get notified when the span changes + connect(&model, &TraceModel::SpanChanged, this, qOverload(&TracePlot::updateSpan)); plots.insert(this); } @@ -48,7 +50,14 @@ void TracePlot::mouseDoubleClickEvent(QMouseEvent *) { emit doubleClicked(this); } -void TracePlot::initializeTraceInfo(TraceModel &model) +void TracePlot::updateSpan(double min, double max) +{ + sweep_fmin = min; + sweep_fmax = max; + triggerReplot(); +} + +void TracePlot::initializeTraceInfo() { // Populate already present traces auto tvect = model.getTraces(); @@ -69,30 +78,6 @@ void TracePlot::contextMenuEvent(QContextMenuEvent *event) } } -void TracePlot::updateContextMenu() -{ - contextmenu->clear(); - contextmenu->addSection("Traces"); - // Populate context menu - for(auto t : traces) { - auto action = new QAction(t.first->name(), contextmenu); - action->setCheckable(true); - if(t.second) { - action->setChecked(true); - } - connect(action, &QAction::toggled, [=](bool active) { - enableTrace(t.first, active); - }); - contextmenu->addAction(action); - } - contextmenu->addSeparator(); - auto close = new QAction("Close", contextmenu); - contextmenu->addAction(close); - connect(close, &QAction::triggered, [=]() { - markedForDeletion = true; - }); -} - std::set TracePlot::getPlots() { return plots; diff --git a/Software/PC_Application/Traces/traceplot.h b/Software/PC_Application/Traces/traceplot.h index e4fd274..2887b6b 100644 --- a/Software/PC_Application/Traces/traceplot.h +++ b/Software/PC_Application/Traces/traceplot.h @@ -11,12 +11,12 @@ class TracePlot : public QWidget { Q_OBJECT public: - TracePlot( QWidget *parent = nullptr); + TracePlot(TraceModel &model, QWidget *parent = nullptr); ~TracePlot(); virtual void enableTrace(Trace *t, bool enabled); void mouseDoubleClickEvent(QMouseEvent *event) override; - virtual void updateSpan(double min, double max){Q_UNUSED(min);Q_UNUSED(max)}; + virtual void updateSpan(double min, double max); static std::set getPlots(); @@ -25,14 +25,11 @@ signals: void deleted(TracePlot*); protected: -// static const QColor Background;// = QColor(0,0,0); -// static const QColor Border;// = QColor(255,255,255); -// static const QColor Divisions;// = QColor(255,255,255); static constexpr int MinUpdateInterval = 100; // need to be called in derived class constructor - void initializeTraceInfo(TraceModel &model); + void initializeTraceInfo(); void contextMenuEvent(QContextMenuEvent *event) override; - virtual void updateContextMenu(); + virtual void updateContextMenu(){}; virtual bool supported(Trace *t) = 0; virtual void replot(){}; std::map traces; @@ -48,6 +45,9 @@ protected slots: void triggerReplot(); virtual void markerAdded(TraceMarker *m); virtual void markerRemoved(TraceMarker *m); +protected: + double sweep_fmin, sweep_fmax; + TraceModel &model; }; diff --git a/Software/PC_Application/Traces/tracesmithchart.cpp b/Software/PC_Application/Traces/tracesmithchart.cpp index d05d680..0f8204c 100644 --- a/Software/PC_Application/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/Traces/tracesmithchart.cpp @@ -5,18 +5,37 @@ #include "tracemarker.h" #include #include "preferences.h" +#include "ui_smithchartdialog.h" using namespace std; TraceSmithChart::TraceSmithChart(TraceModel &model, QWidget *parent) - : TracePlot(parent) + : TracePlot(model, parent) { chartLinesPen = QPen(palette().windowText(), 0.75); thinPen = QPen(palette().windowText(), 0.25); textPen = QPen(palette().windowText(), 0.25); pointDataPen = QPen(QColor("red"), 4.0, Qt::SolidLine, Qt::RoundCap); lineDataPen = QPen(QColor("blue"), 1.0); - initializeTraceInfo(model); + limitToSpan = true; + initializeTraceInfo(); +} + +void TraceSmithChart::axisSetupDialog() +{ + auto dialog = new QDialog(); + auto ui = new Ui::SmithChartDialog(); + ui->setupUi(dialog); + if(limitToSpan) { + ui->displayMode->setCurrentIndex(1); + } else { + ui->displayMode->setCurrentIndex(0); + } + connect(ui->buttonBox, &QDialogButtonBox::accepted, [=](){ + limitToSpan = ui->displayMode->currentIndex() == 1; + triggerReplot(); + }); + dialog->show(); } QPoint TraceSmithChart::plotToPixel(std::complex S) @@ -43,6 +62,10 @@ void TraceSmithChart::mousePressEvent(QMouseEvent *event) if(!m->isMovable()) { continue; } + if (limitToSpan && (m->getFrequency() < sweep_fmin || m->getFrequency() > sweep_fmax)) { + // marker outside of currently displayed range + continue; + } auto S = m->getData(); auto markerPoint = plotToPixel(S); auto yDiff = abs(markerPoint.y() - clickPoint.y()); @@ -74,6 +97,10 @@ void TraceSmithChart::mouseMoveEvent(QMouseEvent *event) unsigned int closestIndex = 0; for(unsigned int i=0;isample(i); + if (limitToSpan && (data.frequency < sweep_fmin || data.frequency > sweep_fmax)) { + // destination point outside of currently displayed range + continue; + } auto distance = norm(data.S - mouseS); if(distance < closestDistance) { closestDistance = distance; @@ -136,21 +163,27 @@ void TraceSmithChart::draw(QPainter * painter, double width_factor) { painter->setPen(QPen(trace->color(), 1.5 * width_factor)); int nPoints = trace->size(); for(int i=1;isample(i-1).S; - auto now = trace->sample(i).S; - if(isnan(now.real())) { + auto last = trace->sample(i-1); + auto now = trace->sample(i); + if (limitToSpan && (last.frequency < sweep_fmin || now.frequency > sweep_fmax)) { + continue; + } + if(isnan(now.S.real())) { break; } // scale to size of smith diagram - last *= smithCoordMax; - now *= smithCoordMax; + last.S *= smithCoordMax; + now.S *= smithCoordMax; // draw line - painter->drawLine(std::real(last), -std::imag(last), std::real(now), -std::imag(now)); + painter->drawLine(std::real(last.S), -std::imag(last.S), std::real(now.S), -std::imag(now.S)); } if(trace->size() > 0) { // only draw markers if the trace has at least one point auto markers = t.first->getMarkers(); for(auto m : markers) { + if (limitToSpan && (m->getFrequency() < sweep_fmin || m->getFrequency() > sweep_fmax)) { + continue; + } auto coords = m->getData(); coords *= smithCoordMax; auto symbol = m->getSymbol(); @@ -187,6 +220,34 @@ void TraceSmithChart::paintEvent(QPaintEvent * /* the event */) draw(&painter, 2*smithCoordMax/side); } +void TraceSmithChart::updateContextMenu() +{ + contextmenu->clear(); + contextmenu->clear(); + auto setup = new QAction("Setup...", contextmenu); + connect(setup, &QAction::triggered, this, &TraceSmithChart::axisSetupDialog); + contextmenu->addAction(setup); + contextmenu->addSection("Traces"); + // Populate context menu + for(auto t : traces) { + auto action = new QAction(t.first->name(), contextmenu); + action->setCheckable(true); + if(t.second) { + action->setChecked(true); + } + connect(action, &QAction::toggled, [=](bool active) { + enableTrace(t.first, active); + }); + contextmenu->addAction(action); + } + contextmenu->addSeparator(); + auto close = new QAction("Close", contextmenu); + contextmenu->addAction(close); + connect(close, &QAction::triggered, [=]() { + markedForDeletion = true; + }); +} + bool TraceSmithChart::supported(Trace *t) { if(t->isReflection()) { diff --git a/Software/PC_Application/Traces/tracesmithchart.h b/Software/PC_Application/Traces/tracesmithchart.h index cb5931f..125cd9a 100644 --- a/Software/PC_Application/Traces/tracesmithchart.h +++ b/Software/PC_Application/Traces/tracesmithchart.h @@ -9,7 +9,8 @@ class TraceSmithChart : public TracePlot Q_OBJECT public: TraceSmithChart(TraceModel &model, QWidget *parent = 0); - +public slots: + void axisSetupDialog(); protected: static constexpr double ReferenceImpedance = 50.0; static constexpr double screenUsage = 0.9; @@ -21,7 +22,7 @@ protected: void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void paintEvent(QPaintEvent *event) override; - + virtual void updateContextMenu() override; bool supported(Trace *t) override; void draw(QPainter * painter, double width_factor); void replot() override; @@ -30,6 +31,7 @@ protected: QPen thinPen; QPen pointDataPen; QPen lineDataPen; + bool limitToSpan; /// Path for the thin arcs QPainterPath thinArcsPath; diff --git a/Software/PC_Application/Traces/tracexyplot.cpp b/Software/PC_Application/Traces/tracexyplot.cpp index fb8582e..b6edfb5 100644 --- a/Software/PC_Application/Traces/tracexyplot.cpp +++ b/Software/PC_Application/Traces/tracexyplot.cpp @@ -115,7 +115,7 @@ private: }; TraceXYPlot::TraceXYPlot(TraceModel &model, QWidget *parent) - : TracePlot(parent), + : TracePlot(model, parent), selectedMarker(nullptr) { YAxis[0].log = false; @@ -164,7 +164,7 @@ TraceXYPlot::TraceXYPlot(TraceModel &model, QWidget *parent) layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); plot->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - initializeTraceInfo(model); + initializeTraceInfo(); setAutoFillBackground(true); // Setup default axis @@ -173,8 +173,6 @@ TraceXYPlot::TraceXYPlot(TraceModel &model, QWidget *parent) // enable autoscaling and set for full span (no information about actual span available yet) updateSpan(0, 6000000000); setXAxis(XAxisType::Frequency, XAxisMode::UseSpan, 0, 6000000000, 600000000); - // get notified when the span changes - connect(&model, &TraceModel::SpanChanged, this, qOverload(&TraceXYPlot::updateSpan)); allPlots.insert(this); } @@ -190,12 +188,6 @@ TraceXYPlot::~TraceXYPlot() allPlots.erase(this); } -void TraceXYPlot::updateSpan(double min, double max) -{ - sweep_fmin = min; - sweep_fmax = max; -} - void TraceXYPlot::setYAxis(int axis, TraceXYPlot::YAxisType type, bool log, bool autorange, double min, double max, double div) { if(YAxis[axis].type != type) { diff --git a/Software/PC_Application/Traces/tracexyplot.h b/Software/PC_Application/Traces/tracexyplot.h index 709254c..14fd142 100644 --- a/Software/PC_Application/Traces/tracexyplot.h +++ b/Software/PC_Application/Traces/tracexyplot.h @@ -57,7 +57,6 @@ public: Manual, }; - virtual void updateSpan(double min, double max) override; void setYAxis(int axis, YAxisType type, bool log, bool autorange, double min, double max, double div); void setXAxis(XAxisType type, XAxisMode mode, double min, double max, double div); void enableTrace(Trace *t, bool enabled) override; @@ -114,7 +113,6 @@ private: YAxis YAxis[2]; XAxis XAxis; - double sweep_fmin, sweep_fmax; using CurveData = struct { QwtPlotCurve *curve;