From: Soeren Apel Date: Sun, 2 Aug 2020 15:48:58 +0000 (+0200) Subject: Introduce math signals X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b0773a8aa01735d7220284ab7a3e8b5d02b48e9e;p=pulseview.git Introduce math signals --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bd5de9ec..aead6ee7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,7 @@ set(pulseview_SOURCES pv/data/analogsegment.cpp pv/data/logic.cpp pv/data/logicsegment.cpp + pv/data/mathsignal.cpp pv/data/signalbase.cpp pv/data/signaldata.cpp pv/data/segment.cpp @@ -331,6 +332,7 @@ set(pulseview_HEADERS pv/data/analogsegment.hpp pv/data/logic.hpp pv/data/logicsegment.hpp + pv/data/mathsignal.hpp pv/data/signalbase.hpp pv/dialogs/connect.hpp pv/dialogs/inputoutputoptions.hpp diff --git a/README b/README index a35cb8d5..96f17ab6 100644 --- a/README +++ b/README @@ -71,6 +71,11 @@ icons/information.svg: Bobarino GFDL 1.2 or later / CC-BY-SA 3.0 https://en.wikipedia.org/wiki/File:Information.svg#Licensing +icons/add-math-channel.svg: Inductiveload + https://en.wikipedia.org/wiki/File:Icon_Mathematical_Plot.svg + License: + Public Domain + QDarkStyleSheet: Colin Duquesnoy https://github.com/ColinDuquesnoy/QDarkStyleSheet License: diff --git a/icons/add-math-signal.svg b/icons/add-math-signal.svg new file mode 100644 index 00000000..4fa71243 --- /dev/null +++ b/icons/add-math-signal.svg @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + Accessibility + + + accessibility + assist + + + + + + + + + + + + + + + + + + + + diff --git a/pulseview.qrc b/pulseview.qrc index 4427a759..ceda06df 100644 --- a/pulseview.qrc +++ b/pulseview.qrc @@ -1,6 +1,7 @@ icons/add-decoder.svg + icons/add-math-signal.svg icons/application-exit.png icons/channels.svg icons/decoder-delete.svg diff --git a/pv/data/mathsignal.cpp b/pv/data/mathsignal.cpp new file mode 100644 index 00000000..18761682 --- /dev/null +++ b/pv/data/mathsignal.cpp @@ -0,0 +1,67 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2020 Soeren Apel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +#include + +#include "mathsignal.hpp" + +#include +#include +#include +#include + +using std::make_shared; + +namespace pv { +namespace data { + +const int64_t MathSignal::ChunkLength = 256 * 1024; + + +MathSignal::MathSignal(pv::Session &session) : + SignalBase(nullptr, SignalBase::MathChannel), + session_(session) +{ + shared_ptr data(new data::Analog()); + set_data(data); + + shared_ptr segment = make_shared( + *data, data->get_segment_count(), session.get_samplerate()); + + data->push_segment(segment); +} + +MathSignal::~MathSignal() +{ +} + +void MathSignal::save_settings(QSettings &settings) const +{ + (void)settings; +} + +void MathSignal::restore_settings(QSettings &settings) +{ + (void)settings; +} + +} // namespace data +} // namespace pv diff --git a/pv/data/mathsignal.hpp b/pv/data/mathsignal.hpp new file mode 100644 index 00000000..04380cdc --- /dev/null +++ b/pv/data/mathsignal.hpp @@ -0,0 +1,80 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2020 Soeren Apel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef PULSEVIEW_PV_DATA_MATHSIGNAL_HPP +#define PULSEVIEW_PV_DATA_MATHSIGNAL_HPP + +#include +#include + +#include +#include +#include + +using std::shared_ptr; + +namespace pv { +class Session; + +namespace data { + +class SignalBase; +class SignalData; + +class MathSignal : public SignalBase +{ + Q_OBJECT + +private: + static const int64_t ChunkLength; + +public: + MathSignal(pv::Session &session); + virtual ~MathSignal(); + + virtual void save_settings(QSettings &settings) const; + virtual void restore_settings(QSettings &settings); + +Q_SIGNALS: + void samples_cleared(); + + void samples_added(uint64_t segment_id, uint64_t start_sample, + uint64_t end_sample); + + void min_max_changed(float min, float max); + +//private Q_SLOTS: +// void on_data_cleared(); +// void on_data_received(); + +// void on_samples_added(SharedPtrToSegment segment, uint64_t start_sample, +// uint64_t end_sample); + +// void on_min_max_changed(float min, float max); + +private: + pv::Session &session_; + + QString error_message_; +}; + +} // namespace data +} // namespace pv + +#endif // PULSEVIEW_PV_DATA_MATHSIGNAL_HPP diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 28ea0042..b35e1466 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -35,6 +35,7 @@ #include +#include #include #include #include @@ -59,6 +60,7 @@ using std::back_inserter; using std::copy; using std::list; using std::make_pair; +using std::make_shared; using std::map; using std::max; using std::min; @@ -108,10 +110,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view sample_rate_("Hz", this), updating_sample_rate_(false), updating_sample_count_(false), - sample_count_supported_(false) + sample_count_supported_(false), #ifdef ENABLE_DECODE - , add_decoder_button_(new QToolButton()) + add_decoder_button_(new QToolButton()), #endif + add_math_signal_button_(new QToolButton()) { setObjectName(QString::fromUtf8("MainBar")); @@ -240,6 +243,16 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view this, SLOT(on_add_decoder_clicked())); #endif + // Setup the math signal button + add_math_signal_button_->setIcon(QIcon(":/icons/add-math-signal.svg")); + add_math_signal_button_->setPopupMode(QToolButton::InstantPopup); + add_math_signal_button_->setToolTip(tr("Add math signal")); + add_math_signal_button_->setShortcut(QKeySequence(Qt::Key_M)); + + connect(add_math_signal_button_, SIGNAL(clicked()), + this, SLOT(on_add_math_signal_clicked())); + + connect(&sample_count_, SIGNAL(value_changed()), this, SLOT(on_sample_count_changed())); connect(&sample_rate_, SIGNAL(value_changed()), @@ -893,6 +906,12 @@ void MainBar::on_add_decoder_clicked() show_decoder_selector(&session_); } +void MainBar::on_add_math_signal_clicked() +{ + shared_ptr signal = make_shared(session_); + session_.add_generated_signal(signal); +} + void MainBar::add_toolbar_widgets() { addWidget(new_view_button_); @@ -912,6 +931,7 @@ void MainBar::add_toolbar_widgets() addSeparator(); addWidget(add_decoder_button_); #endif + addWidget(add_math_signal_button_); } bool MainBar::eventFilter(QObject *watched, QEvent *event) diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index eae43fa5..e4aa39b6 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -145,6 +145,7 @@ private Q_SLOTS: void on_actionConnect_triggered(); void on_add_decoder_clicked(); + void on_add_math_signal_clicked(); protected: void add_toolbar_widgets(); @@ -185,6 +186,8 @@ private: #ifdef ENABLE_DECODE QToolButton *add_decoder_button_; #endif + + QToolButton *add_math_signal_button_; }; } // namespace toolbars diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index e2d9365e..a1a163b0 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -365,6 +365,10 @@ void View::add_signalbase(const shared_ptr signalbase) signal = shared_ptr(new AnalogSignal(session_, signalbase)); break; + case SignalBase::MathChannel: + signal = shared_ptr(new AnalogSignal(session_, signalbase)); + break; + default: qDebug() << "Unknown signalbase type:" << signalbase->type(); assert(false); @@ -929,7 +933,7 @@ pair View::get_time_extents() const return make_pair(0, 0); for (shared_ptr s : signals_) - if (s->data()->segments().size() > 0) + if (s->data() && (s->data()->segments().size() > 0)) data.push_back(s->data()); for (const shared_ptr& d : data) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2b6cb87e..79647a31 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,6 +35,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/data/analogsegment.cpp ${PROJECT_SOURCE_DIR}/pv/data/logic.cpp ${PROJECT_SOURCE_DIR}/pv/data/logicsegment.cpp + ${PROJECT_SOURCE_DIR}/pv/data/mathsignal.cpp ${PROJECT_SOURCE_DIR}/pv/data/segment.cpp ${PROJECT_SOURCE_DIR}/pv/data/signalbase.cpp ${PROJECT_SOURCE_DIR}/pv/data/signaldata.cpp @@ -116,6 +117,7 @@ set(pulseview_TEST_HEADERS ${PROJECT_SOURCE_DIR}/pv/data/analogsegment.hpp ${PROJECT_SOURCE_DIR}/pv/data/logic.hpp ${PROJECT_SOURCE_DIR}/pv/data/logicsegment.hpp + ${PROJECT_SOURCE_DIR}/pv/data/mathsignal.hpp ${PROJECT_SOURCE_DIR}/pv/data/signalbase.hpp ${PROJECT_SOURCE_DIR}/pv/devices/device.hpp ${PROJECT_SOURCE_DIR}/pv/dialogs/connect.hpp