load_init_file(open_file_name, open_file_format);
}
+MainWindow::~MainWindow()
+{
+ for (auto entry : view_docks_) {
+ const std::shared_ptr<QDockWidget> dock = entry.first;
+ dock->setWidget(0);
+ const std::shared_ptr<pv::view::View> view = entry.second;
+ session_.deregister_view(view);
+ }
+}
+
QAction* MainWindow::action_open() const
{
return action_open_;
v->enable_coloured_bg(action_view_coloured_bg_->isChecked());
action_view_show_cursors_->setChecked(v->cursors_shown());
}
+
+ session.register_view(v);
}
return v;
std::string open_file_format = std::string(),
QWidget *parent = 0);
+ ~MainWindow();
+
QAction* action_open() const;
QAction* action_save_as() const;
QAction* action_save_selection_as() const;
map<shared_ptr<Channel>, shared_ptr<SignalBase> > signal_map;
unordered_set< shared_ptr<SignalBase> > sigs;
- for (const shared_ptr<view::Signal> s : session_.signals())
- sigs.insert(s->base());
+ for (const shared_ptr<data::SignalBase> b : session_.signalbases())
+ sigs.insert(b);
for (const shared_ptr<SignalBase> &sig : sigs)
signal_map[sig->channel()] = sig;
#include "view/analogsignal.hpp"
#include "view/decodetrace.hpp"
#include "view/logicsignal.hpp"
+#include "view/signal.hpp"
+#include "view/view.hpp"
#include <cassert>
#include <mutex>
device_.reset();
// Remove all stored data
- signals_.clear();
- {
- shared_lock<shared_mutex> lock(signals_mutex_);
- for (const shared_ptr<data::SignalData> d : all_signal_data_)
- d->clear();
- }
+ for (std::shared_ptr<pv::view::View> view : views_)
+ view->clear_signals();
+ for (const shared_ptr<data::SignalData> d : all_signal_data_)
+ d->clear();
all_signal_data_.clear();
+ signalbases_.clear();
cur_logic_segment_.reset();
for (auto entry : cur_analog_segments_) {
}
// Clear signal data
- {
- shared_lock<shared_mutex> lock(signals_mutex_);
- for (const shared_ptr<data::SignalData> d : all_signal_data_)
- d->clear();
- }
+ for (const shared_ptr<data::SignalData> d : all_signal_data_)
+ d->clear();
// Begin the session
sampling_thread_ = std::thread(
sampling_thread_.join();
}
+void Session::register_view(std::shared_ptr<pv::view::View> view)
+{
+ views_.insert(view);
+}
+
+void Session::deregister_view(std::shared_ptr<pv::view::View> view)
+{
+ views_.erase(view);
+}
+
double Session::get_samplerate() const
{
double samplerate = 0.0;
- {
- shared_lock<shared_mutex> lock(signals_mutex_);
- for (const shared_ptr<pv::data::SignalData> d : all_signal_data_) {
- assert(d);
- const vector< shared_ptr<pv::data::Segment> > segments =
- d->segments();
- for (const shared_ptr<pv::data::Segment> &s : segments)
- samplerate = std::max(samplerate, s->samplerate());
- }
+ for (const shared_ptr<pv::data::SignalData> d : all_signal_data_) {
+ assert(d);
+ const vector< shared_ptr<pv::data::Segment> > segments =
+ d->segments();
+ for (const shared_ptr<pv::data::Segment> &s : segments)
+ samplerate = std::max(samplerate, s->samplerate());
}
// If there is no sample rate given we use samples as unit
if (samplerate == 0.0)
return samplerate;
}
-const unordered_set< shared_ptr<view::Signal> > Session::signals() const
+const std::unordered_set< std::shared_ptr<data::SignalBase> >
+ Session::signalbases() const
{
- shared_lock<shared_mutex> lock(signals_mutex_);
- return signals_;
+ return signalbases_;
}
#ifdef ENABLE_DECODE
shared_ptr<data::DecoderStack> decoder_stack;
try {
- lock_guard<boost::shared_mutex> lock(signals_mutex_);
-
// Create the decoder
decoder_stack = shared_ptr<data::DecoderStack>(
new data::DecoderStack(*this, dec));
vector< shared_ptr<view::DecodeTrace> > Session::get_decode_signals() const
{
- shared_lock<shared_mutex> lock(signals_mutex_);
return decode_traces_;
}
void Session::update_signals()
{
if (!device_) {
- signals_.clear();
+ signalbases_.clear();
logic_data_.reset();
+ for (std::shared_ptr<pv::view::View> view : views_)
+ view->clear_signals();
return;
}
const shared_ptr<sigrok::Device> sr_dev = device_->device();
if (!sr_dev) {
- signals_.clear();
+ signalbases_.clear();
logic_data_.reset();
+ for (std::shared_ptr<pv::view::View> view : views_)
+ view->clear_signals();
return;
}
}
}
- // Make the Signals list
- {
- unique_lock<shared_mutex> lock(signals_mutex_);
-
- unordered_set< shared_ptr<view::Signal> > prev_sigs(signals_);
- signals_.clear();
+ // Make the signals list
+ for (std::shared_ptr<pv::view::View> view : views_) {
+ unordered_set< shared_ptr<view::Signal> > prev_sigs(view->signals());
+ view->clear_signals();
for (auto channel : sr_dev->channels()) {
shared_ptr<data::SignalBase> signalbase;
// Copy the signal from the old set to the new
signal = *iter;
} else {
- // Create a new signal
- signalbase = shared_ptr<data::SignalBase>(
- new data::SignalBase(channel));
+ // Find the signalbase for this channel if possible
+ signalbase.reset();
+ for (const shared_ptr<data::SignalBase> b : signalbases_)
+ if (b->channel() == channel)
+ signalbase = b;
switch(channel->type()->id()) {
case SR_CHANNEL_LOGIC:
- signalbase->set_data(logic_data_);
+ if (!signalbase) {
+ signalbase = shared_ptr<data::SignalBase>(
+ new data::SignalBase(channel));
+ signalbases_.insert(signalbase);
+
+ all_signal_data_.insert(logic_data_);
+ signalbase->set_data(logic_data_);
+ }
+
signal = shared_ptr<view::Signal>(
new view::LogicSignal(*this,
device_, signalbase));
- all_signal_data_.insert(logic_data_);
- signalbases_.insert(signalbase);
+ view->add_signal(signal);
break;
case SR_CHANNEL_ANALOG:
{
- shared_ptr<data::Analog> data(new data::Analog());
- signalbase->set_data(data);
+ if (!signalbase) {
+ signalbase = shared_ptr<data::SignalBase>(
+ new data::SignalBase(channel));
+ signalbases_.insert(signalbase);
+
+ shared_ptr<data::Analog> data(new data::Analog());
+ all_signal_data_.insert(data);
+ signalbase->set_data(data);
+ }
+
signal = shared_ptr<view::Signal>(
new view::AnalogSignal(
*this, signalbase));
- all_signal_data_.insert(data);
- signalbases_.insert(signalbase);
+ view->add_signal(signal);
break;
}
break;
}
}
-
- assert(signal);
- signals_.insert(signal);
}
}
uint64_t sample_count = 0;
{
- shared_lock<shared_mutex> lock(signals_mutex_);
for (const shared_ptr<pv::data::SignalData> d : all_signal_data_) {
assert(d);
uint64_t temp_count = 0;
const float *data = static_cast<const float *>(analog->data_pointer());
bool sweep_beginning = false;
- if (signals_.empty())
+ if (signalbases_.empty())
update_signals();
for (auto channel : channels) {
namespace view {
class DecodeTrace;
-class LogicSignal;
-class Signal;
+class View;
}
class Session : public QObject
double get_samplerate() const;
- const std::unordered_set< std::shared_ptr<view::Signal> >
- signals() const;
+ void register_view(std::shared_ptr<pv::view::View> view);
+
+ void deregister_view(std::shared_ptr<pv::view::View> view);
+
+ const std::unordered_set< std::shared_ptr<data::SignalBase> >
+ signalbases() const;
#ifdef ENABLE_DECODE
bool add_decoder(srd_decoder *const dec);
DeviceManager &device_manager_;
std::shared_ptr<devices::Device> device_;
+ std::unordered_set< std::shared_ptr<pv::view::View> > views_;
+
std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
capture_state capture_state_;
- mutable boost::shared_mutex signals_mutex_;
- std::unordered_set< std::shared_ptr<view::Signal> > signals_;
- std::set< std::shared_ptr<data::SignalBase> > signalbases_;
- std::set< std::shared_ptr<data::SignalData> > all_signal_data_;
+ std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
+ std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
mutable std::recursive_mutex data_mutex_;
std::shared_ptr<data::Logic> logic_data_;
#include <pv/data/logicsegment.hpp>
#include <pv/data/signalbase.hpp>
#include <pv/devices/device.hpp>
-#include <pv/view/signal.hpp>
#include <libsigrokcxx/libsigrokcxx.hpp>
using Glib::VariantBase;
+using sigrok::ChannelType;
using sigrok::ConfigKey;
using sigrok::Error;
using sigrok::OutputFormat;
bool StoreSession::start()
{
- const unordered_set< shared_ptr<view::Signal> > sigs(session_.signals());
+ const unordered_set< shared_ptr<data::SignalBase> > sigs(session_.signalbases());
shared_ptr<data::Segment> any_segment;
shared_ptr<data::LogicSegment> lsegment;
vector< shared_ptr<data::SignalBase> > achannel_list;
vector< shared_ptr<data::AnalogSegment> > asegment_list;
- for (shared_ptr<view::Signal> signal : sigs) {
+ for (shared_ptr<data::SignalBase> signal : sigs) {
if (!signal->enabled())
continue;
- shared_ptr<data::SignalData> data = signal->data();
-
- if (dynamic_pointer_cast<data::Logic>(data)) {
+ if (signal->type() == ChannelType::LOGIC) {
// All logic channels share the same data segments
- shared_ptr<data::Logic> ldata = dynamic_pointer_cast<data::Logic>(data);
+ shared_ptr<data::Logic> ldata = signal->logic_data();
const deque< shared_ptr<data::LogicSegment> > &lsegments =
ldata->logic_segments();
any_segment = lsegment;
}
- if (dynamic_pointer_cast<data::Analog>(data)) {
+ if (signal->type() == ChannelType::ANALOG) {
// Each analog channel has its own segments
- shared_ptr<data::Analog> adata =
- dynamic_pointer_cast<data::Analog>(data);
+ shared_ptr<data::Analog> adata = signal->analog_data();
const deque< shared_ptr<data::AnalogSegment> > &asegments =
adata->analog_segments();
asegment_list.push_back(asegments.front());
any_segment = asegments.front();
- achannel_list.push_back(signal->base());
+ achannel_list.push_back(signal);
}
}
#include <pv/data/logic.hpp>
#include <pv/data/logicsegment.hpp>
#include <pv/data/decode/annotation.hpp>
-#include <pv/view/signal.hpp>
#include <pv/view/view.hpp>
#include <pv/view/viewport.hpp>
#include <pv/widgets/decodergroupbox.hpp>
{
assert(dec);
- const auto sigs(session_.signals());
+ const auto sigs(session_.signalbases());
- vector< shared_ptr<Signal> > sig_list(sigs.begin(), sigs.end());
+ vector< shared_ptr<data::SignalBase> > sig_list(sigs.begin(), sigs.end());
std::sort(sig_list.begin(), sig_list.end(),
- [](const shared_ptr<Signal> &a, const shared_ptr<Signal> b) {
- return strnatcasecmp(a->base()->name().toStdString(),
- b->base()->name().toStdString()) < 0; });
+ [](const shared_ptr<data::SignalBase> &a,
+ const shared_ptr<data::SignalBase> &b) {
+ return strnatcasecmp(a->name().toStdString(),
+ b->name().toStdString()) < 0; });
- assert(decoder_stack_);
const auto channel_iter = dec->channels().find(pdch);
QComboBox *selector = new QComboBox(parent);
if (channel_iter == dec->channels().end())
selector->setCurrentIndex(0);
- for (const shared_ptr<view::Signal> &s : sig_list) {
- assert(s);
- if (s->base()->type() == sigrok::ChannelType::LOGIC && s->enabled()) {
- selector->addItem(s->base()->name(),
- qVariantFromValue((void*)s->base().get()));
+ for (const shared_ptr<data::SignalBase> &b : sig_list) {
+ assert(b);
+ if (b->type() == sigrok::ChannelType::LOGIC && b->enabled()) {
+ selector->addItem(b->name(),
+ qVariantFromValue((void*)b.get()));
if (channel_iter != dec->channels().end() &&
- (*channel_iter).second == s->base())
+ (*channel_iter).second == b)
selector->setCurrentIndex(
selector->count() - 1);
}
map<const srd_channel*, shared_ptr<data::SignalBase> > channel_map;
- const unordered_set< shared_ptr<Signal> > sigs(session_.signals());
+ const unordered_set< shared_ptr<data::SignalBase> >
+ sigs(session_.signalbases());
for (const ChannelSelector &s : channel_selectors_) {
if (s.decoder_ != dec)
(data::SignalBase*)s.combo_->itemData(
s.combo_->currentIndex()).value<void*>();
- for (shared_ptr<Signal> sig : sigs)
- if (sig->base().get() == selection) {
- channel_map[s.pdch_] = sig->base();
+ for (shared_ptr<data::SignalBase> sig : sigs)
+ if (sig.get() == selection) {
+ channel_map[s.pdch_] = sig;
break;
}
}
return session_;
}
+std::unordered_set< std::shared_ptr<view::Signal> > View::signals() const
+{
+ return signals_;
+}
+
+void View::clear_signals()
+{
+ signals_.clear();
+}
+
+void View::add_signal(const shared_ptr<view::Signal> signal)
+{
+ signals_.insert(signal);
+}
+
View* View::view()
{
return this;
set< shared_ptr<SignalData> > View::get_visible_data() const
{
- const unordered_set< shared_ptr<Signal> > sigs(session().signals());
-
// Make a set of all the visible data objects
set< shared_ptr<SignalData> > visible_data;
- for (const shared_ptr<Signal> sig : sigs)
+ for (const shared_ptr<Signal> sig : signals_)
if (sig->enabled())
visible_data.insert(sig->data());
{
// Check whether we know the sample rate and hence can use time as the unit
if (time_unit_ == util::TimeUnit::Samples) {
- const unordered_set< shared_ptr<Signal> > sigs(session().signals());
-
// Check all signals but...
- for (const shared_ptr<Signal> signal : sigs) {
+ for (const shared_ptr<Signal> signal : signals_) {
const shared_ptr<SignalData> data = signal->data();
// ...only check first segment of each
if (!session_.device()) {
reset_scroll();
+ signals_.clear();
} else {
sr_dev = session_.device()->device();
assert(sr_dev);
const set<shared_ptr<Trace>> prev_traces(
prev_trace_list.begin(), prev_trace_list.end());
- const unordered_set< shared_ptr<Signal> > sigs(session_.signals());
-
- set< shared_ptr<Trace> > traces(sigs.begin(), sigs.end());
+ set< shared_ptr<Trace> > traces(signals_.begin(), signals_.end());
#ifdef ENABLE_DECODE
const vector< shared_ptr<DecodeTrace> > decode_traces(
// Make a look-up table of sigrok Channels to pulseview Signals
unordered_map<shared_ptr<data::SignalBase>, shared_ptr<Signal> >
signal_map;
- for (const shared_ptr<Signal> &sig : sigs)
+ for (const shared_ptr<Signal> &sig : signals_)
signal_map[sig->base()] = sig;
// Populate channel groups
class CursorHeader;
class Header;
class Ruler;
+class Signal;
class Trace;
class Viewport;
class TriggerMarker;
Session& session();
const Session& session() const;
+ /**
+ * Returns the signals contained in this view.
+ */
+ std::unordered_set< std::shared_ptr<view::Signal> > signals() const;
+
+ void clear_signals();
+
+ void add_signal(const std::shared_ptr<view::Signal> signal);
+
/**
* Returns the view of the owner.
*/
Ruler *ruler_;
Header *header_;
+ std::unordered_set< std::shared_ptr<view::Signal> > signals_;
+
/// The view time scale in seconds per pixel.
double scale_;