-const QColor AnalogSignal::SignalColors[4] = {
- QColor(0xC4, 0xA0, 0x00), // Yellow
- QColor(0x87, 0x20, 0x7A), // Magenta
- QColor(0x20, 0x4A, 0x87), // Blue
- QColor(0x4E, 0x9A, 0x06) // Green
-};
-
const QPen AnalogSignal::AxisPen(QColor(0, 0, 0, 30 * 256 / 100), 2);
const QColor AnalogSignal::GridMajorColor = QColor(0, 0, 0, 40 * 256 / 100);
const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20 * 256 / 100);
const QPen AnalogSignal::AxisPen(QColor(0, 0, 0, 30 * 256 / 100), 2);
const QColor AnalogSignal::GridMajorColor = QColor(0, 0, 0, 40 * 256 / 100);
const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20 * 256 / 100);
connect(analog_data, SIGNAL(min_max_changed(float, float)),
this, SLOT(on_min_max_changed(float, float)));
connect(analog_data, SIGNAL(min_max_changed(float, float)),
this, SLOT(on_min_max_changed(float, float)));
+ GlobalSettings settings;
+ show_sampling_points_ =
+ settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
+ fill_high_areas_ =
+ settings.value(GlobalSettings::Key_View_FillSignalHighAreas).toBool();
+ high_fill_color_ = QColor::fromRgba(settings.value(
+ GlobalSettings::Key_View_FillSignalHighAreaColor).value<uint32_t>());
+ show_analog_minor_grid_ =
+ settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
- settings.setValue("pos_vdivs", pos_vdivs_);
- settings.setValue("neg_vdivs", neg_vdivs_);
- settings.setValue("scale_index", scale_index_);
- settings.setValue("display_type", display_type_);
- settings.setValue("autoranging", autoranging_);
- settings.setValue("div_height", div_height_);
+ std::map<QString, QVariant> result;
+
+ result["pos_vdivs"] = pos_vdivs_;
+ result["neg_vdivs"] = neg_vdivs_;
+ result["scale_index"] = scale_index_;
+ result["display_type"] = display_type_;
+ result["autoranging"] = pos_vdivs_;
+ result["div_height"] = div_height_;
+
+ return result;
-int AnalogSignal::scale_handle_offset() const
-{
- const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
-
- return ((scale_index_drag_offset_ - scale_index_) * h / 4) - h / 2;
-}
-
-void AnalogSignal::scale_handle_dragged(int offset)
-{
- const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
-
- scale_index_ = scale_index_drag_offset_ - (offset + h / 2) / (h / 4);
-
- update_scale();
-}
-
-void AnalogSignal::scale_handle_drag_release()
-{
- scale_index_drag_offset_ = scale_index_;
- update_scale();
-}
-
-void AnalogSignal::on_setting_changed(const QString &key, const QVariant &value)
-{
- Signal::on_setting_changed(key, value);
-
- if (key == GlobalSettings::Key_View_ConversionThresholdDispMode)
- on_settingViewConversionThresholdDispMode_changed(value);
-}
-
- if (!segment || (segment->get_sample_count() == 0))
- return;
-
- const double pixels_offset = pp.pixels_offset();
- const double samplerate = max(1.0, segment->samplerate());
- const pv::util::Timestamp& start_time = segment->start_time();
- const int64_t last_sample = (int64_t)segment->get_sample_count() - 1;
- const double samples_per_pixel = samplerate * pp.scale();
- const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
- const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
-
- const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
- (int64_t)0), last_sample);
- const int64_t end_sample = min(max((ceil(end) + 1).convert_to<int64_t>(),
- (int64_t)0), last_sample);
-
- if (samples_per_pixel < EnvelopeThreshold)
- paint_trace(p, segment, y, pp.left(), start_sample, end_sample,
- pixels_offset, samples_per_pixel);
- else
- paint_envelope(p, segment, y, pp.left(), start_sample, end_sample,
- pixels_offset, samples_per_pixel);
+
+ if (segment && (segment->get_sample_count() > 0)) {
+ const double pixels_offset = pp.pixels_offset();
+ const double samplerate = max(1.0, segment->samplerate());
+ const pv::util::Timestamp& start_time = segment->start_time();
+ const int64_t last_sample = (int64_t)segment->get_sample_count() - 1;
+ const double samples_per_pixel = samplerate * pp.scale();
+ const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
+ const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
+
+ const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
+ (int64_t)0), last_sample);
+ const int64_t end_sample = min(max((ceil(end) + 1).convert_to<int64_t>(),
+ (int64_t)0), last_sample);
+
+ if (samples_per_pixel < EnvelopeThreshold)
+ paint_trace(p, segment, y, pp.left(), start_sample, end_sample,
+ pixels_offset, samples_per_pixel);
+ else
+ paint_envelope(p, segment, y, pp.left(), start_sample, end_sample,
+ pixels_offset, samples_per_pixel);
+ }
// Show the info section on the right side of the trace, including
// the value at the hover point when the hover marker is enabled
// and we have corresponding data available
// Show the info section on the right side of the trace, including
// the value at the hover point when the hover marker is enabled
// and we have corresponding data available
p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
for (int i = 0; i < pos_vdivs_; i++) {
const float dy = i * div_height_;
p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
for (int i = 0; i < pos_vdivs_; i++) {
const float dy = i * div_height_;
p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
for (int i = 0; i < neg_vdivs_; i++) {
const float dy = i * div_height_;
p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
for (int i = 0; i < neg_vdivs_; i++) {
const float dy = i * div_height_;
const int nh = min(neg_vdivs_, 1) * div_height_;
const float high_offset = y - ph + signal_margin + 0.5f;
const float low_offset = y + nh - signal_margin - 0.5f;
const int nh = min(neg_vdivs_, 1) * div_height_;
const float high_offset = y - ph + signal_margin + 0.5f;
const float low_offset = y + nh - signal_margin - 0.5f;
- // Check whether we need to paint the sampling points
- GlobalSettings settings;
- const bool show_sampling_points =
- settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool() &&
- (samples_per_pixel < 0.25);
+ const float first_sample_x =
+ pp.left() + (edges.front().first / samples_per_pixel - pixels_offset);
+ const float last_sample_x =
+ pp.left() + (edges.back().first / samples_per_pixel - pixels_offset);
- const float x = ((*i).first / samples_per_pixel -
- pixels_offset) + pp.left();
+ // Note: multiple edges occupying a single pixel are represented by an edge
+ // with undefined logic level. This means that only the first falling edge
+ // after a rising edge corresponds to said rising edge - and vice versa. If
+ // more edges with the same logic level follow, they denote multiple edges.
+
+ const float x = pp.left() + ((*i).first / samples_per_pixel - pixels_offset);
+ if (fill_high_areas_) {
+ // Any edge terminates a high area
+ if (rising_edge_seen) {
+ const int width = x - rising_edge_x;
+ if (width > 0)
+ high_rects.emplace_back(rising_edge_x, high_offset,
+ width, signal_height);
+ rising_edge_seen = false;
+ }
+
+ // Only rising edges start high areas
+ if ((*i).second) {
+ rising_edge_x = x;
+ rising_edge_seen = true;
+ }
+ }
+
+ if (fill_high_areas_) {
+ // Add last high rectangle if the signal is still high at the end of the trace
+ if (rising_edge_seen && (edges.cend() - 1)->second)
+ high_rects.emplace_back(rising_edge_x, high_offset,
+ last_sample_x - rising_edge_x, signal_height);
+
+ p.setPen(high_fill_color_);
+ p.setBrush(high_fill_color_);
+ p.drawRects((const QRectF*)(high_rects.data()), high_rects.size());
+ }
+
+vector<data::LogicSegment::EdgePair> AnalogSignal::get_nearest_level_changes(uint64_t sample_pos)
+{
+ assert(base_);
+ assert(owner_);
+
+ // Return if there's no logic data or we're showing only the analog trace
+ if (!base_->logic_data() || (display_type_ == DisplayAnalog))
+ return vector<data::LogicSegment::EdgePair>();
+
+ if (sample_pos == 0)
+ return vector<LogicSegment::EdgePair>();
+
+ shared_ptr<LogicSegment> segment = get_logic_segment_to_paint();
+ if (!segment || (segment->get_sample_count() == 0))
+ return vector<LogicSegment::EdgePair>();
+
+ const View *view = owner_->view();
+ assert(view);
+ const double samples_per_pixel = base_->get_samplerate() * view->scale();
+
+ vector<LogicSegment::EdgePair> edges;
+
+ segment->get_surrounding_edges(edges, sample_pos,
+ samples_per_pixel / LogicSignal::Oversampling, 0);
+
+ if (edges.empty())
+ return vector<LogicSegment::EdgePair>();
+
+ return edges;
+}
+
pair<double, double> mm = segment->get_min_max();
min = std::min(min, mm.first);
max = std::max(max, mm.second);
}
pair<double, double> mm = segment->get_min_max();
min = std::min(min, mm.first);
max = std::max(max, mm.second);
}
// Add div-related settings
pvdiv_sb_ = new QSpinBox(parent);
pvdiv_sb_->setRange(0, MaximumVDivs);
pvdiv_sb_->setValue(pos_vdivs_);
connect(pvdiv_sb_, SIGNAL(valueChanged(int)),
this, SLOT(on_pos_vdivs_changed(int)));
// Add div-related settings
pvdiv_sb_ = new QSpinBox(parent);
pvdiv_sb_->setRange(0, MaximumVDivs);
pvdiv_sb_->setValue(pos_vdivs_);
connect(pvdiv_sb_, SIGNAL(valueChanged(int)),
this, SLOT(on_pos_vdivs_changed(int)));
nvdiv_sb_ = new QSpinBox(parent);
nvdiv_sb_->setRange(0, MaximumVDivs);
nvdiv_sb_->setValue(neg_vdivs_);
connect(nvdiv_sb_, SIGNAL(valueChanged(int)),
this, SLOT(on_neg_vdivs_changed(int)));
nvdiv_sb_ = new QSpinBox(parent);
nvdiv_sb_->setRange(0, MaximumVDivs);
nvdiv_sb_->setValue(neg_vdivs_);
connect(nvdiv_sb_, SIGNAL(valueChanged(int)),
this, SLOT(on_neg_vdivs_changed(int)));
div_height_sb_->setValue(div_height_);
connect(div_height_sb_, SIGNAL(valueChanged(int)),
this, SLOT(on_div_height_changed(int)));
div_height_sb_->setValue(div_height_);
connect(div_height_sb_, SIGNAL(valueChanged(int)),
this, SLOT(on_div_height_changed(int)));
vdiv_layout->addWidget(resolution_cb_, 0, 0);
vdiv_layout->addWidget(vdiv_unit, 0, 1);
vdiv_layout->addWidget(resolution_cb_, 0, 0);
vdiv_layout->addWidget(vdiv_unit, 0, 1);
connect(display_type_cb_, SIGNAL(currentIndexChanged(int)),
this, SLOT(on_display_type_changed(int)));
// Update the conversion widget contents and states
update_conversion_widgets();
connect(display_type_cb_, SIGNAL(currentIndexChanged(int)),
this, SLOT(on_display_type_changed(int)));
// Update the conversion widget contents and states
update_conversion_widgets();
+ if (key == GlobalSettings::Key_View_FillSignalHighAreaColor)
+ high_fill_color_ = QColor::fromRgba(value.value<uint32_t>());
+
+ if (key == GlobalSettings::Key_View_ShowAnalogMinorGrid)
+ show_analog_minor_grid_ = value.toBool();
+
+ if (key == GlobalSettings::Key_View_ConversionThresholdDispMode) {
+ conversion_threshold_disp_mode_ = value.toInt();
+
+ if (owner_)
+ owner_->row_item_appearance_changed(false, true);
+ }
+}
+
+void AnalogSignal::on_min_max_changed(float min, float max)
+{