X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=a8047f7da7f51ad9417f7861e447e465a2a77f94;hp=c2fd21498b248f36086580466ccf2356bd64bc87;hb=4640a84e926ac4b82e2a1b6ef9fc80ef44c2bd3c;hpb=96dbf014dad1309d4ade9c14a8b46733e2f531c8 diff --git a/pv/session.cpp b/pv/session.cpp index c2fd2149..a8047f7d 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -17,9 +17,6 @@ * along with this program; if not, see . */ -#include -#include - #include #include #include @@ -27,9 +24,14 @@ #include +#include +#include +#include + #include "devicemanager.hpp" #include "mainwindow.hpp" #include "session.hpp" +#include "util.hpp" #include "data/analog.hpp" #include "data/analogsegment.hpp" @@ -66,8 +68,8 @@ using std::bad_alloc; using std::dynamic_pointer_cast; using std::find_if; using std::function; -using std::lock_guard; using std::list; +using std::lock_guard; using std::make_pair; using std::make_shared; using std::map; @@ -83,7 +85,6 @@ using std::string; using std::unique_lock; #endif using std::unique_ptr; -using std::unordered_set; using std::vector; using sigrok::Analog; @@ -105,11 +106,18 @@ 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; +using pv::views::trace::LogicSignal; + namespace pv { shared_ptr Session::sr_context; Session::Session(DeviceManager &device_manager, QString name) : + shutting_down_(false), device_manager_(device_manager), default_name_(name), name_(name), @@ -121,8 +129,15 @@ Session::Session(DeviceManager &device_manager, QString name) : Session::~Session() { + shutting_down_ = true; + // Stop and join to the thread stop_capture(); + + for (SignalGroup* group : signal_groups_) { + group->clear(); + delete group; + } } DeviceManager& Session::device_manager() @@ -162,7 +177,17 @@ void Session::set_name(QString name) name_changed(); } -const list< shared_ptr > Session::views() const +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_; } @@ -189,13 +214,13 @@ bool Session::data_saved() const void Session::save_setup(QSettings &settings) const { - int decode_signals = 0, views = 0; + int i = 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(decode_signals++)); + settings.beginGroup("decode_signal" + QString::number(i++)); base->save_settings(settings); settings.endGroup(); } else @@ -207,23 +232,63 @@ void Session::save_setup(QSettings &settings) const } } - settings.setValue("decode_signals", decode_signals); + settings.setValue("decode_signals", i); // Save view states and their signal settings // Note: main_view must be saved as view0 - settings.beginGroup("view" + QString::number(views++)); + i = 0; + settings.beginGroup("view" + QString::number(i++)); main_view_->save_settings(settings); settings.endGroup(); for (const shared_ptr& view : views_) { if (view != main_view_) { - settings.beginGroup("view" + QString::number(views++)); + settings.beginGroup("view" + QString::number(i++)); + settings.setValue("type", view->get_type()); view->save_settings(settings); settings.endGroup(); } } - settings.setValue("views", views); + settings.setValue("views", i); + + int view_id = 0; + i = 0; + for (const shared_ptr& vb : views_) { + shared_ptr tv = dynamic_pointer_cast(vb); + if (tv) { + for (const shared_ptr& time_item : tv->time_items()) { + + const shared_ptr flag = + dynamic_pointer_cast(time_item); + if (flag) { + if (!flag->enabled()) + continue; + + settings.beginGroup("meta_obj" + QString::number(i++)); + settings.setValue("type", "time_marker"); + settings.setValue("assoc_view", view_id); + GlobalSettings::store_timestamp(settings, "time", flag->time()); + settings.setValue("text", flag->get_text()); + settings.endGroup(); + } + } + + if (tv->cursors_shown()) { + settings.beginGroup("meta_obj" + QString::number(i++)); + settings.setValue("type", "selection"); + settings.setValue("assoc_view", view_id); + const shared_ptr cp = tv->cursors(); + GlobalSettings::store_timestamp(settings, "start_time", cp->first()->time()); + GlobalSettings::store_timestamp(settings, "end_time", cp->second()->time()); + settings.endGroup(); + } + } + + view_id++; + } + + settings.setValue("meta_objs", i); } void Session::save_settings(QSettings &settings) const @@ -258,25 +323,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); @@ -312,20 +388,52 @@ void Session::restore_setup(QSettings &settings) if (i > 0) { views::ViewType type = (views::ViewType)settings.value("type").toInt(); - add_view(name_, type, this); + add_view(type, this); views_.back()->restore_settings(settings); } else main_view_->restore_settings(settings); settings.endGroup(); } + + // Restore meta objects like markers and cursors + int meta_objs = settings.value("meta_objs").toInt(); + + for (int i = 0; i < meta_objs; i++) { + settings.beginGroup("meta_obj" + QString::number(i)); + + shared_ptr vb; + shared_ptr tv; + if (settings.contains("assoc_view")) + vb = views_.at(settings.value("assoc_view").toInt()); + + if (vb) + tv = dynamic_pointer_cast(vb); + + const QString type = settings.value("type").toString(); + + if ((type == "time_marker") && tv) { + Timestamp ts = GlobalSettings::restore_timestamp(settings, "time"); + shared_ptr flag = tv->add_flag(ts); + flag->set_text(settings.value("text").toString()); + } + + if ((type == "selection") && tv) { + Timestamp start = GlobalSettings::restore_timestamp(settings, "start_time"); + Timestamp end = GlobalSettings::restore_timestamp(settings, "end_time"); + tv->set_cursors(start, end); + tv->show_cursors(); + } + + settings.endGroup(); + } } void Session::restore_settings(QSettings &settings) { shared_ptr device; - QString device_type = settings.value("device_type").toString(); + const QString device_type = settings.value("device_type").toString(); if (device_type == "hardware") { map dev_info; @@ -358,16 +466,17 @@ void Session::restore_settings(QSettings &settings) settings.endGroup(); } + + QString filename; if ((device_type == "sessionfile") || (device_type == "inputfile")) { if (device_type == "sessionfile") { settings.beginGroup("device"); - 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") { @@ -386,6 +495,14 @@ 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()); + } } } @@ -423,14 +540,22 @@ void Session::set_device(shared_ptr device) // Remove all stored data and reset all views for (shared_ptr view : views_) { - view->clear_signals(); + view->clear_signalbases(); #ifdef ENABLE_DECODE view->clear_decode_signals(); #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(); @@ -480,6 +605,17 @@ void Session::set_default_device() set_device((iter == devices.end()) ? devices.front() : *iter); } +bool Session::using_file_device() const +{ + shared_ptr sessionfile_device = + dynamic_pointer_cast(device_); + + shared_ptr inputfile_device = + dynamic_pointer_cast(device_); + + return (sessionfile_device || inputfile_device); +} + /** * Convert generic options to data types that are specific to InputFormat. * @@ -516,8 +652,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