+void View::set_current_segment(uint32_t segment_id)
+{
+ current_segment_ = segment_id;
+
+ for (shared_ptr<Signal> signal : signals_)
+ signal->set_current_segment(current_segment_);
+#ifdef ENABLE_DECODE
+ for (shared_ptr<DecodeTrace> dt : decode_traces_)
+ dt->set_current_segment(current_segment_);
+#endif
+
+ vector<util::Timestamp> triggers = session_.get_triggers(current_segment_);
+
+ trigger_markers_.clear();
+ for (util::Timestamp timestamp : triggers)
+ trigger_markers_.push_back(make_shared<TriggerMarker>(*this, timestamp));
+
+ // When enabled, the first trigger for this segment is used as the zero position
+ GlobalSettings settings;
+ bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool();
+
+ if (trigger_is_zero_time && (triggers.size() > 0))
+ set_zero_position(triggers.front());
+
+ viewport_->update();
+
+ segment_changed(segment_id);
+}
+
+bool View::segment_is_selectable() const
+{
+ return segment_selectable_;
+}
+
+Trace::SegmentDisplayMode View::segment_display_mode() const
+{
+ return segment_display_mode_;
+}
+
+void View::set_segment_display_mode(Trace::SegmentDisplayMode mode)
+{
+ trigger_markers_.clear();
+
+ segment_display_mode_ = mode;
+
+ for (shared_ptr<Signal> signal : signals_)
+ signal->set_segment_display_mode(mode);
+
+ uint32_t last_segment = session_.get_segment_count() - 1;
+
+ switch (mode) {
+ case Trace::ShowLastSegmentOnly:
+ if (current_segment_ != last_segment)
+ set_current_segment(last_segment);
+ break;
+
+ case Trace::ShowLastCompleteSegmentOnly:
+ // Do nothing if we only have one segment so far
+ if (last_segment > 0) {
+ // If the last segment isn't complete, the previous one must be
+ uint32_t segment_id =
+ (session_.all_segments_complete(last_segment)) ?
+ last_segment : last_segment - 1;
+
+ if (current_segment_ != segment_id)
+ set_current_segment(segment_id);
+ }
+ break;
+
+ case Trace::ShowSingleSegmentOnly:
+ case Trace::ShowAllSegments:
+ case Trace::ShowAccumulatedIntensity:
+ default:
+ // Current segment remains as-is
+ break;
+ }
+
+ segment_selectable_ = true;
+
+ if ((mode == Trace::ShowAllSegments) || (mode == Trace::ShowAccumulatedIntensity))
+ segment_selectable_ = false;
+
+ viewport_->update();
+
+ segment_display_mode_changed((int)mode, segment_selectable_);
+}
+