]> sigrok.org Git - pulseview.git/blobdiff - pv/view/view.cpp
Fix #685 by adding a special T marker when SR_DT_TRIGGER arrives
[pulseview.git] / pv / view / view.cpp
index 6d366e7311881b8736b80daf2709becd72d7c88b..7f9caa4cb50e69fb63f50e621d5dad01adbebc99 100644 (file)
@@ -65,6 +65,8 @@ using pv::data::Segment;
 using pv::util::TimeUnit;
 using pv::util::Timestamp;
 
+using std::back_inserter;
+using std::copy_if;
 using std::deque;
 using std::dynamic_pointer_cast;
 using std::inserter;
@@ -72,6 +74,7 @@ using std::list;
 using std::lock_guard;
 using std::max;
 using std::make_pair;
+using std::make_shared;
 using std::min;
 using std::pair;
 using std::set;
@@ -346,24 +349,12 @@ void View::zoom_one_to_one()
        if (visible_data.empty())
                return;
 
-       double samplerate = 0.0;
-       for (const shared_ptr<SignalData> d : visible_data) {
-               assert(d);
-               const vector< shared_ptr<Segment> > segments =
-                       d->segments();
-               for (const shared_ptr<Segment> &s : segments)
-                       samplerate = max(samplerate, s->samplerate());
-       }
-
-       if (samplerate == 0.0)
-               return;
-
        assert(viewport_);
        const int w = viewport_->width();
        if (w <= 0)
                return;
 
-       set_zoom(1.0 / samplerate, w / 2);
+       set_zoom(1.0 / session_.get_samplerate(), w / 2);
 }
 
 void View::set_scale_offset(double scale, const Timestamp& offset)
@@ -396,8 +387,7 @@ void View::set_scale_offset(double scale, const Timestamp& offset)
 
 set< shared_ptr<SignalData> > View::get_visible_data() const
 {
-       shared_lock<shared_mutex> lock(session().signals_mutex());
-       const unordered_set< shared_ptr<Signal> > &sigs(session().signals());
+       const unordered_set< shared_ptr<Signal> > sigs(session().signals());
 
        // Make a set of all the visible data objects
        set< shared_ptr<SignalData> > visible_data;
@@ -472,8 +462,14 @@ void View::add_flag(const Timestamp& time)
 {
        flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
                QString("%1").arg(next_flag_text_))));
+
        next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
                (next_flag_text_ + 1);
+
+       // Skip 'T' (for trigger) as it's treated special
+       if (next_flag_text_ == 'T')
+               next_flag_text_ += 1;
+
        time_item_appearance_changed(true, true);
 }
 
@@ -528,6 +524,16 @@ void View::restack_all_trace_tree_items()
                i->animate_to_layout_v_offset();
 }
 
+void View::trigger_event(util::Timestamp location)
+{
+       char next_flag_text = next_flag_text_;
+
+       next_flag_text_ = 'T';
+       add_flag(location);
+
+       next_flag_text_ = next_flag_text;
+}
+
 void View::get_scroll_layout(double &length, Timestamp &offset) const
 {
        const pair<Timestamp, Timestamp> extents = get_time_extents();
@@ -745,8 +751,7 @@ void View::determine_time_unit()
 {
        // Check whether we know the sample rate and hence can use time as the unit
        if (time_unit_ == util::TimeUnit::Samples) {
-               shared_lock<shared_mutex> lock(session().signals_mutex());
-               const unordered_set< shared_ptr<Signal> > &sigs(session().signals());
+               const unordered_set< shared_ptr<Signal> > sigs(session().signals());
 
                // Check all signals but...
                for (const shared_ptr<Signal> signal : sigs) {
@@ -870,6 +875,8 @@ void View::v_scroll_value_changed()
 
 void View::signals_changed()
 {
+       using sigrok::Channel;
+
        vector< shared_ptr<TraceTreeItem> > new_top_level_items;
 
        const auto device = session_.device();
@@ -879,14 +886,16 @@ void View::signals_changed()
        shared_ptr<sigrok::Device> sr_dev = device->device();
        assert(sr_dev);
 
+       const vector< shared_ptr<Channel> > channels(
+               sr_dev->channels());
+
        // Make a list of traces that are being added, and a list of traces
        // that are being removed
        const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>();
        const set<shared_ptr<Trace>> prev_traces(
                prev_trace_list.begin(), prev_trace_list.end());
 
-       shared_lock<shared_mutex> lock(session_.signals_mutex());
-       const unordered_set< shared_ptr<Signal> > &sigs(session_.signals());
+       const unordered_set< shared_ptr<Signal> > sigs(session_.signals());
 
        set< shared_ptr<Trace> > traces(sigs.begin(), sigs.end());
 
@@ -958,9 +967,23 @@ void View::signals_changed()
                        new_top_level_items.push_back(new_trace_group);
        }
 
+       // Enqueue the remaining logic channels in a group
+       vector< shared_ptr<Channel> > logic_channels;
+       copy_if(channels.begin(), channels.end(), back_inserter(logic_channels),
+               [](const shared_ptr<Channel>& c) {
+                       return c->type() == sigrok::ChannelType::LOGIC; });
+       const vector< shared_ptr<Trace> > non_grouped_logic_signals =
+               extract_new_traces_for_channels(logic_channels,
+                       signal_map, add_traces);
+       const shared_ptr<TraceGroup> non_grouped_trace_group(
+               make_shared<TraceGroup>());
+       for (shared_ptr<Trace> trace : non_grouped_logic_signals)
+               non_grouped_trace_group->add_child_item(trace);
+       new_top_level_items.push_back(non_grouped_trace_group);
+
        // Enqueue the remaining channels as free ungrouped traces
        const vector< shared_ptr<Trace> > new_top_level_signals =
-               extract_new_traces_for_channels(sr_dev->channels(),
+               extract_new_traces_for_channels(channels,
                        signal_map, add_traces);
        new_top_level_items.insert(new_top_level_items.end(),
                new_top_level_signals.begin(), new_top_level_signals.end());