From eecfba3f18abb9b09b506316e7f63d684418aca7 Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Sat, 5 Jul 2025 11:04:32 -0500 Subject: [PATCH] Finished Matrix Visializer. --- src/SeerMatrixVisualizerWidget.cpp | 91 +++++++++++++++++++++++++- src/SeerMatrixVisualizerWidget.h | 1 + src/SeerMatrixWidget.cpp | 18 +++++ src/SeerMatrixWidget.h | 1 + src/resource.qrc | 1 + src/resources/help/MatrixVisualizer.md | 47 +++++++++++++ 6 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/resources/help/MatrixVisualizer.md diff --git a/src/SeerMatrixVisualizerWidget.cpp b/src/SeerMatrixVisualizerWidget.cpp index 1e43184..d4d5b67 100644 --- a/src/SeerMatrixVisualizerWidget.cpp +++ b/src/SeerMatrixVisualizerWidget.cpp @@ -1,4 +1,5 @@ #include "SeerMatrixVisualizerWidget.h" +#include "SeerHelpPageDialog.h" #include "SeerUtl.h" #include #include @@ -11,6 +12,8 @@ #include #include #include +#include +#include SeerMatrixVisualizerWidget::SeerMatrixVisualizerWidget (QWidget* parent) : QWidget(parent) { @@ -38,6 +41,7 @@ SeerMatrixVisualizerWidget::SeerMatrixVisualizerWidget (QWidget* parent) : QWidg // Connect things. QObject::connect(refreshToolButton, &QToolButton::clicked, this, &SeerMatrixVisualizerWidget::handleRefreshButton); + QObject::connect(helpToolButton, &QToolButton::clicked, this, &SeerMatrixVisualizerWidget::handleHelpButton); QObject::connect(variableNameLineEdit, &SeerHistoryLineEdit::returnPressed, this, &SeerMatrixVisualizerWidget::handleVariableNameLineEdit); QObject::connect(variableNameLineEdit, &SeerHistoryLineEdit::editingFinished, this, &SeerMatrixVisualizerWidget::handleVariableNameLineEdit); QObject::connect(matrixRowsLineEdit, &SeerHistoryLineEdit::returnPressed, this, &SeerMatrixVisualizerWidget::handleRefreshButton); @@ -424,6 +428,14 @@ void SeerMatrixVisualizerWidget::handleRefreshButton () { emit evaluateMemoryExpression(_memoryId, variableAddressLineEdit->text(), bytes); } +void SeerMatrixVisualizerWidget::handleHelpButton () { + + SeerHelpPageDialog* help = new SeerHelpPageDialog; + help->loadFile(":/seer/resources/help/MatrixVisualizer.md"); + help->show(); + help->raise(); +} + void SeerMatrixVisualizerWidget::handleVariableNameLineEdit () { setVariableName (variableNameLineEdit->text()); @@ -540,7 +552,84 @@ void SeerMatrixVisualizerWidget::handleMatrixDisplayFormatComboBox (int index) { } void SeerMatrixVisualizerWidget::handleDataChanged () { - return; // Do nothing for now. + + // Update the meta information. + + // Clear everything. + countLineEdit->setText(""); + rowsLineEdit->setText(""); + columnsLineEdit->setText(""); + minimumLineEdit->setText(""); + maximumLineEdit->setText(""); + sumLineEdit->setText(""); + averageLineEdit->setText(""); + medianLineEdit->setText(""); + rmsLineEdit->setText(""); + + + // If there's nothing to show, just return. + if (matrixTableWidget->dataCount() <= 0) { + return; + } + + if (matrixTableWidget->dataValues().count() <= 0) { + return; + } + + // Make a copy of the values for us to play with. + QVector values = matrixTableWidget->dataValues(); + + // Fill in counts. + countLineEdit->setText(QString::number(matrixTableWidget->dataCount())); + rowsLineEdit->setText(QString::number(matrixTableWidget->dataRows())); + columnsLineEdit->setText(QString::number(matrixTableWidget->dataColumns())); + + // Calculate statistics. + double val = 0.0; + double min = 0.0; + double max = 0.0; + double sum = 0.0; + double sum2 = 0.0; + double avg = 0.0; + double med = 0.0; + double rms = 0.0; + + for (int i=0; isetText(QString::number(min)); + maximumLineEdit->setText(QString::number(max)); + sumLineEdit->setText(QString::number(sum)); + averageLineEdit->setText(QString::number(avg)); + rmsLineEdit->setText(QString::number(rms)); + + // For median, we need to sort the values. So do this last. + std::sort(values.begin(), values.end()); + + // If the number of elements is odd, the median is the middle element + if (values.size() % 2 != 0) { + med = values[values.size() / 2]; + }else{ + double mid1 = values[values.size() / 2 - 1]; + double mid2 = values[values.size() / 2]; + + med = (mid1 + mid2) / 2.0; + } + + medianLineEdit->setText(QString::number(med)); + + return; } void SeerMatrixVisualizerWidget::writeSettings() { diff --git a/src/SeerMatrixVisualizerWidget.h b/src/SeerMatrixVisualizerWidget.h index 420e15f..14d52e0 100644 --- a/src/SeerMatrixVisualizerWidget.h +++ b/src/SeerMatrixVisualizerWidget.h @@ -34,6 +34,7 @@ class SeerMatrixVisualizerWidget : public QWidget, protected Ui::SeerMatrixVisua protected slots: void handleRefreshButton (); + void handleHelpButton (); void handleVariableNameLineEdit (); void handleElementRowsLineEdit (); void handleElementColumnsLineEdit (); diff --git a/src/SeerMatrixWidget.cpp b/src/SeerMatrixWidget.cpp index 7b3527a..1a07a3f 100644 --- a/src/SeerMatrixWidget.cpp +++ b/src/SeerMatrixWidget.cpp @@ -83,6 +83,19 @@ unsigned long SeerMatrixWidget::dataSize () const { return 0; } +int SeerMatrixWidget::dataCount () const { + + if (_data == 0) { + return 0; + } + + if (elementSize() < 1) { + return 0; + } + + return _data->size() / elementSize(); +} + unsigned long SeerMatrixWidget::elementSize () const { if (dataType() == SeerMatrixWidget::Int16MatrixType) { @@ -141,6 +154,11 @@ QString SeerMatrixWidget::dataTypeString () const { return "???"; } +const QVector& SeerMatrixWidget::dataValues () const { + + return _dataValues; +} + void SeerMatrixWidget::setData(SeerMatrixWidget::DataStorage* pData) { if (_data) { diff --git a/src/SeerMatrixWidget.h b/src/SeerMatrixWidget.h index 71c7ed0..9ba5c97 100644 --- a/src/SeerMatrixWidget.h +++ b/src/SeerMatrixWidget.h @@ -54,6 +54,7 @@ class SeerMatrixWidget: public QTableWidget { int dataRows () const; int dataColumns () const; unsigned long dataSize () const; + int dataCount () const; signals: void dataChanged (); diff --git a/src/resource.qrc b/src/resource.qrc index f4173c6..88b0762 100644 --- a/src/resource.qrc +++ b/src/resource.qrc @@ -65,6 +65,7 @@ resources/help/BasicStructVisualizer.md resources/help/MemoryVisualizer.md resources/help/ArrayVisualizer.md + resources/help/MatrixVisualizer.md resources/help/ImageVisualizer.md resources/help/StackInfoBrowser.md resources/help/VariableRegisterInfoBrowser.md diff --git a/src/resources/help/MatrixVisualizer.md b/src/resources/help/MatrixVisualizer.md new file mode 100644 index 0000000..0cefad9 --- /dev/null +++ b/src/resources/help/MatrixVisualizer.md @@ -0,0 +1,47 @@ +## Matrix Visualizer + +### Introduction + +The Matrix Visualizer shows the contents of an array as a matrix, a number of rows and an number of columns. + +The Matrix Visualizer is made up of 3 main parts: + +* Input parameters +* Values table +* Statistic information + +### Input parameters + +This part of the Visualizer specifies the array to view. Here are the details for an array. + +* Variable name of the array. The name name should resolve to an address. +* Number of rows and columns. The total length of the array is determined from this. +* Array offset. How many elements to initially skip. Default 0 (start at the begining of the array). +* Array stride. How the elements are accessed in the array. Default 1 (use every element). 2 would access every second element. +* Array data type. +* Refresh. + +By having array offset and array stride, it's possible to handle oddly constructed arrays. + +### Values table + +This part of the Visualizer shows the array's values as a matrix. The number of rows and number of columns reflect the values +entered in the input parameters. + +Note, the array offset and array stride is taken into account. + +### Statistic information + +These statistical values are calculated from the array values. + +* Count of values +* Count of number of rows +* Count of number of columns +* Minimum value of values +* Maximum value of values +* Sum of values +* Average value +* Median value +* RMS value + +