X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=9ec8bd07264036e85c052c05695749f4bccf797b;hp=85b6c0b4968795666cb422e2919afb892eb58fe8;hb=HEAD;hpb=f9a0fd83226d97af7458d8c9dac0b88c83a54d29 diff --git a/pv/session.cpp b/pv/session.cpp index 85b6c0b4..b4ecc6a8 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include "devicemanager.hpp" @@ -37,6 +38,7 @@ #include "data/decode/decoder.hpp" #include "data/logic.hpp" #include "data/logicsegment.hpp" +#include "data/mathsignal.hpp" #include "data/signalbase.hpp" #include "devices/hardwaredevice.hpp" @@ -105,6 +107,7 @@ using Gst::ElementFactory; using Gst::Pipeline; #endif +using pv::data::SignalGroup; using pv::util::Timestamp; using pv::views::trace::Signal; using pv::views::trace::AnalogSignal; @@ -123,6 +126,8 @@ Session::Session(DeviceManager &device_manager, QString name) : cur_samplerate_(0), data_saved_(true) { + // Use this name also for the QObject instance + setObjectName(name_); } Session::~Session() @@ -131,6 +136,11 @@ Session::~Session() // Stop and join to the thread stop_capture(); + + for (SignalGroup* group : signal_groups_) { + group->clear(); + delete group; + } } DeviceManager& Session::device_manager() @@ -167,9 +177,22 @@ void Session::set_name(QString name) name_ = name; + // Use this name also for the QObject instance + setObjectName(name_); + name_changed(); } +QString Session::save_path() const +{ + return save_path_; +} + +void Session::set_save_path(QString path) +{ + save_path_ = path; +} + const vector< shared_ptr > Session::views() const { return views_; @@ -197,25 +220,33 @@ bool Session::data_saved() const void Session::save_setup(QSettings &settings) const { - int i = 0; + int i; + int decode_signal_count = 0; + int gen_signal_count = 0; // Save channels and decoders for (const shared_ptr& base : signalbases_) { #ifdef ENABLE_DECODE if (base->is_decode_signal()) { - settings.beginGroup("decode_signal" + QString::number(i++)); + settings.beginGroup("decode_signal" + QString::number(decode_signal_count++)); base->save_settings(settings); settings.endGroup(); } else #endif - { + if (base->is_generated()) { + settings.beginGroup("generated_signal" + QString::number(gen_signal_count++)); + settings.setValue("type", base->type()); + base->save_settings(settings); + settings.endGroup(); + } else { settings.beginGroup(base->internal_name()); base->save_settings(settings); settings.endGroup(); } } - settings.setValue("decode_signals", i); + settings.setValue("decode_signals", decode_signal_count); + settings.setValue("generated_signals", gen_signal_count); // Save view states and their signal settings // Note: main_view must be saved as view0 @@ -306,25 +337,36 @@ void Session::save_settings(QSettings &settings) const settings.endGroup(); } - shared_ptr sessionfile_device = - dynamic_pointer_cast(device_); - - if (sessionfile_device) { + // Having saved the data to srzip overrides the current device. This is + // a crappy hack around the fact that saving e.g. an imported file to + // srzip would require changing the underlying libsigrok device + if (!save_path_.isEmpty()) { + QFileInfo fi = QFileInfo(QDir(save_path_), name_); settings.setValue("device_type", "sessionfile"); settings.beginGroup("device"); - settings.setValue("filename", QString::fromStdString( - sessionfile_device->full_name())); + settings.setValue("filename", fi.absoluteFilePath()); settings.endGroup(); - } + } else { + shared_ptr sessionfile_device = + dynamic_pointer_cast(device_); + + if (sessionfile_device) { + settings.setValue("device_type", "sessionfile"); + settings.beginGroup("device"); + settings.setValue("filename", QString::fromStdString( + sessionfile_device->full_name())); + settings.endGroup(); + } - shared_ptr inputfile_device = - dynamic_pointer_cast(device_); + shared_ptr inputfile_device = + dynamic_pointer_cast(device_); - if (inputfile_device) { - settings.setValue("device_type", "inputfile"); - settings.beginGroup("device"); - inputfile_device->save_meta_to_settings(settings); - settings.endGroup(); + if (inputfile_device) { + settings.setValue("device_type", "inputfile"); + settings.beginGroup("device"); + inputfile_device->save_meta_to_settings(settings); + settings.endGroup(); + } } save_setup(settings); @@ -340,11 +382,34 @@ void Session::restore_setup(QSettings &settings) settings.endGroup(); } + // Restore generated signals + int gen_signal_count = settings.value("generated_signals").toInt(); + + for (int i = 0; i < gen_signal_count; i++) { + settings.beginGroup("generated_signal" + QString::number(i)); + SignalBase::ChannelType type = (SignalBase::ChannelType)settings.value("type").toInt(); + shared_ptr signal; + + if (type == SignalBase::MathChannel) + signal = make_shared(*this); + else + qWarning() << tr("Can't restore generated signal of unknown type %1 (%2)") \ + .arg((int)type) \ + .arg(settings.value("name").toString()); + + if (signal) { + add_generated_signal(signal); + signal->restore_settings(settings); + } + + settings.endGroup(); + } + // Restore decoders #ifdef ENABLE_DECODE - int decode_signals = settings.value("decode_signals").toInt(); + int decode_signal_count = settings.value("decode_signals").toInt(); - for (int i = 0; i < decode_signals; i++) { + for (int i = 0; i < decode_signal_count; i++) { settings.beginGroup("decode_signal" + QString::number(i)); shared_ptr signal = add_decode_signal(); signal->restore_settings(settings); @@ -436,18 +501,21 @@ void Session::restore_settings(QSettings &settings) set_device(device); settings.endGroup(); + + if (device) + restore_setup(settings); } + QString filename; if ((device_type == "sessionfile") || (device_type == "inputfile")) { if (device_type == "sessionfile") { settings.beginGroup("device"); - const QString filename = settings.value("filename").toString(); + filename = settings.value("filename").toString(); settings.endGroup(); - if (QFileInfo(filename).isReadable()) { + if (QFileInfo(filename).isReadable()) device = make_shared(device_manager_.context(), filename.toStdString()); - } } if (device_type == "inputfile") { @@ -457,8 +525,10 @@ void Session::restore_settings(QSettings &settings) settings.endGroup(); } + if (device) { set_device(device); + restore_setup(settings); start_capture([](QString infoMessage) { // TODO Emulate noquote() @@ -466,11 +536,16 @@ void Session::restore_settings(QSettings &settings) set_name(QString::fromStdString( dynamic_pointer_cast(device)->display_name(device_manager_))); + + if (!filename.isEmpty()) { + // Only set the save path if we load an srzip file + if (device_type == "sessionfile") + set_save_path(QFileInfo(filename).absolutePath()); + + set_name(QFileInfo(filename).fileName()); + } } } - - if (device) - restore_setup(settings); } void Session::select_device(shared_ptr device) @@ -509,8 +584,16 @@ void Session::set_device(shared_ptr device) #endif view->reset_view_state(); } + + for (SignalGroup* group : signal_groups_) { + group->clear(); + delete group; + } + signal_groups_.clear(); + for (const shared_ptr& d : all_signal_data_) d->clear(); + all_signal_data_.clear(); signalbases_.clear(); cur_logic_segment_.reset(); @@ -531,6 +614,9 @@ void Session::set_device(shared_ptr device) } catch (const QString &e) { device_.reset(); MainWindow::show_session_error(tr("Failed to open device"), e); + } catch (const sigrok::Error &e) { + device_.reset(); + MainWindow::show_session_error(tr("Failed to open device"), QString(e.what())); } if (device_) { @@ -607,8 +693,12 @@ Session::input_format_options(vector user_spec, * data type. */ auto found = fmt_opts.find(key); - if (found == fmt_opts.end()) + if (found == fmt_opts.end()) { + qCritical() << "Supplied input option" << QString::fromStdString(key) << + "is not a valid option for this input module, it will be ignored!"; continue; + } + shared_ptr