X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=6b879cf91dcdd4e4b6127cb99a780366042d09a1;hp=ae29f6a9c4d5b135242dc4426fc6b1837ba6f89f;hb=7697cd83435e88689936b14c952b8a34d5258b69;hpb=97378470ded88af84edaa0f1063d10d834475665
diff --git a/pv/session.cpp b/pv/session.cpp
index ae29f6a9..6b879cf9 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,13 @@
#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 +67,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 +84,6 @@ using std::string;
using std::unique_lock;
#endif
using std::unique_ptr;
-using std::unordered_set;
using std::vector;
using sigrok::Analog;
@@ -105,6 +105,11 @@ using Gst::ElementFactory;
using Gst::Pipeline;
#endif
+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;
@@ -162,7 +167,7 @@ void Session::set_name(QString name)
name_changed();
}
-const list< shared_ptr > Session::views() const
+const vector< shared_ptr > Session::views() const
{
return views_;
}
@@ -189,13 +194,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 +212,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
@@ -312,20 +357,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;
@@ -361,7 +438,7 @@ void Session::restore_settings(QSettings &settings)
if ((device_type == "sessionfile") || (device_type == "inputfile")) {
if (device_type == "sessionfile") {
settings.beginGroup("device");
- QString filename = settings.value("filename").toString();
+ const QString filename = settings.value("filename").toString();
settings.endGroup();
if (QFileInfo(filename).isReadable()) {
@@ -480,6 +557,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.
*
@@ -525,7 +613,8 @@ Session::input_format_options(vector user_spec,
return result;
}
-void Session::load_init_file(const string &file_name, const string &format)
+void Session::load_init_file(const string &file_name,
+ const string &format, const string &setup_file_name)
{
shared_ptr input_format;
map input_opts;
@@ -549,12 +638,12 @@ void Session::load_init_file(const string &file_name, const string &format)
input_format->options());
}
- load_file(QString::fromStdString(file_name), input_format, input_opts);
+ load_file(QString::fromStdString(file_name), QString::fromStdString(setup_file_name),
+ input_format, input_opts);
}
-void Session::load_file(QString file_name,
- shared_ptr format,
- const map &options)
+void Session::load_file(QString file_name, QString setup_file_name,
+ shared_ptr format, const map &options)
{
const QString errorMessage(
QString("Failed to load file %1").arg(file_name));
@@ -576,16 +665,19 @@ void Session::load_file(QString file_name,
device_manager_.context(),
file_name.toStdString())));
} catch (Error& e) {
- MainWindow::show_session_error(tr("Failed to load ") + file_name, e.what());
+ MainWindow::show_session_error(tr("Failed to load %1").arg(file_name), e.what());
set_default_device();
main_bar_->update_device_list();
return;
}
- // Auto-load the setup if one exists
- QString setup_file_name = file_name;
- setup_file_name.truncate(setup_file_name.lastIndexOf('.'));
- setup_file_name.append(".pvs");
+ // Use the input file with .pvs extension if no setup file was given
+ if (setup_file_name.isEmpty()) {
+ setup_file_name = file_name;
+ setup_file_name.truncate(setup_file_name.lastIndexOf('.'));
+ setup_file_name.append(".pvs");
+ }
+
if (QFileInfo::exists(setup_file_name) && QFileInfo(setup_file_name).isReadable()) {
QSettings settings_storage(setup_file_name, QSettings::IniFormat);
restore_setup(settings_storage);
@@ -659,9 +751,8 @@ void Session::stop_capture()
void Session::register_view(shared_ptr view)
{
- if (views_.empty()) {
+ if (views_.empty())
main_view_ = view;
- }
views_.push_back(view);
@@ -669,35 +760,29 @@ void Session::register_view(shared_ptr view)
update_signals();
// Add all other signals
- unordered_set< shared_ptr > view_signalbases =
- view->signalbases();
-
- views::trace::View *trace_view =
- qobject_cast(view.get());
-
- if (trace_view) {
- for (const shared_ptr& signalbase : signalbases_) {
- const int sb_exists = count_if(
- view_signalbases.cbegin(), view_signalbases.cend(),
- [&](const shared_ptr &sb) {
- return sb == signalbase;
- });
- // Add the signal to the view as it doesn't have it yet
- if (!sb_exists)
- switch (signalbase->type()) {
- case data::SignalBase::AnalogChannel:
- case data::SignalBase::LogicChannel:
- case data::SignalBase::DecodeChannel:
+ vector< shared_ptr > view_signalbases = view->signalbases();
+
+ for (const shared_ptr& signalbase : signalbases_) {
+ const int sb_exists = count_if(
+ view_signalbases.cbegin(), view_signalbases.cend(),
+ [&](const shared_ptr &sb) {
+ return sb == signalbase;
+ });
+
+ // Add the signal to the view if it doesn't have it yet
+ if (!sb_exists)
+ switch (signalbase->type()) {
+ case data::SignalBase::AnalogChannel:
+ case data::SignalBase::LogicChannel:
+ case data::SignalBase::MathChannel:
+ view->add_signalbase(signalbase);
+ break;
+ case data::SignalBase::DecodeChannel:
#ifdef ENABLE_DECODE
- trace_view->add_decode_signal(
- dynamic_pointer_cast(signalbase));
+ view->add_decode_signal(dynamic_pointer_cast(signalbase));
#endif
- break;
- case data::SignalBase::MathChannel:
- // TBD
- break;
- }
- }
+ break;
+ }
}
signals_changed();
@@ -705,7 +790,9 @@ void Session::register_view(shared_ptr view)
void Session::deregister_view(shared_ptr view)
{
- views_.remove_if([&](shared_ptr v) { return v == view; });
+ views_.erase(std::remove_if(views_.begin(), views_.end(),
+ [&](shared_ptr v) { return v == view; }),
+ views_.end());
if (views_.empty()) {
main_view_.reset();
@@ -765,7 +852,7 @@ vector Session::get_triggers(uint32_t segment_id) const
return result;
}
-const unordered_set< shared_ptr > Session::signalbases() const
+const vector< shared_ptr > Session::signalbases() const
{
return signalbases_;
}
@@ -790,7 +877,7 @@ shared_ptr Session::add_decode_signal()
// Create the decode signal
signal = make_shared(*this);
- signalbases_.insert(signal);
+ signalbases_.push_back(signal);
// Add the decode signal to all views
for (shared_ptr& view : views_)
@@ -807,7 +894,9 @@ shared_ptr Session::add_decode_signal()
void Session::remove_decode_signal(shared_ptr signal)
{
- signalbases_.erase(signal);
+ signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(),
+ [&](shared_ptr s) { return s == signal; }),
+ signalbases_.end());
for (shared_ptr& view : views_)
view->remove_decode_signal(signal);
@@ -820,6 +909,11 @@ void Session::set_capture_state(capture_state state)
{
bool changed;
+ if (state == Running)
+ acq_time_.restart();
+ if (state == Stopped)
+ qDebug("Acquisition took %.2f s", acq_time_.elapsed() / 1000.);
+
{
lock_guard lock(sampling_mutex_);
changed = capture_state_ != state;
@@ -886,18 +980,17 @@ void Session::update_signals()
qobject_cast(viewbase.get());
if (trace_view) {
- unordered_set< shared_ptr >
- prev_sigs(trace_view->signals());
+ vector< shared_ptr > prev_sigs(trace_view->signals());
trace_view->clear_signals();
for (auto channel : sr_dev->channels()) {
shared_ptr signalbase;
- shared_ptr signal;
+ shared_ptr signal;
// Find the channel in the old signals
const auto iter = find_if(
prev_sigs.cbegin(), prev_sigs.cend(),
- [&](const shared_ptr &s) {
+ [&](const shared_ptr &s) {
return s->base()->channel() == channel;
});
if (iter != prev_sigs.end()) {
@@ -911,12 +1004,14 @@ void Session::update_signals()
if (b->channel() == channel)
signalbase = b;
+ shared_ptr signal;
+
switch(channel->type()->id()) {
case SR_CHANNEL_LOGIC:
if (!signalbase) {
signalbase = make_shared(channel,
data::SignalBase::LogicChannel);
- signalbases_.insert(signalbase);
+ signalbases_.push_back(signalbase);
all_signal_data_.insert(logic_data_);
signalbase->set_data(logic_data_);
@@ -925,10 +1020,7 @@ void Session::update_signals()
signalbase.get(), SLOT(on_capture_state_changed(int)));
}
- signal = shared_ptr(
- new views::trace::LogicSignal(*this,
- device_, signalbase));
- trace_view->add_signal(signal);
+ signal = shared_ptr(new LogicSignal(*this, device_, signalbase));
break;
case SR_CHANNEL_ANALOG:
@@ -936,7 +1028,7 @@ void Session::update_signals()
if (!signalbase) {
signalbase = make_shared(channel,
data::SignalBase::AnalogChannel);
- signalbases_.insert(signalbase);
+ signalbases_.push_back(signalbase);
shared_ptr data(new data::Analog());
all_signal_data_.insert(data);
@@ -946,10 +1038,7 @@ void Session::update_signals()
signalbase.get(), SLOT(on_capture_state_changed(int)));
}
- signal = shared_ptr(
- new views::trace::AnalogSignal(
- *this, signalbase));
- trace_view->add_signal(signal);
+ signal = shared_ptr(new AnalogSignal(*this, signalbase));
break;
}
@@ -957,6 +1046,17 @@ void Session::update_signals()
assert(false);
break;
}
+
+ // New views take their signal settings from the main view
+ if (!viewbase->is_main_view()) {
+ shared_ptr main_tv =
+ dynamic_pointer_cast(main_view_);
+ shared_ptr main_signal =
+ main_tv->get_signal_by_signalbase(signalbase);
+ signal->restore_settings(main_signal->save_settings());
+ }
+
+ trace_view->add_signal(signal);
}
}
}
@@ -1469,8 +1569,10 @@ void Session::on_new_decoders_selected(vector decoders)
shared_ptr signal = add_decode_signal();
if (signal)
- for (const srd_decoder* d : decoders)
- signal->stack_decoder(d);
+ for (unsigned int i = 0; i < decoders.size(); i++) {
+ const srd_decoder* d = decoders[i];
+ signal->stack_decoder(d, !(i < decoders.size() - 1));
+ }
}
#endif