Commit 9d871219 authored by DreamSourceLab's avatar DreamSourceLab

add horizontal&vertical measure function @ DSO mode

parent 618f7c92
......@@ -32,6 +32,9 @@
#include "../view/logicsignal.h"
#include "../data/signaldata.h"
#include "../data/snapshot.h"
#include "../devicemanager.h"
#include "../device/device.h"
#include "../device/file.h"
#include <QObject>
#include <QPainter>
......@@ -64,21 +67,19 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession &session) :
_duty_label = new QLabel("#####", _widget);
_mouse_layout = new QGridLayout();
_mouse_layout->addWidget(_fen_checkBox, 0, 0, 1, 2);
_mouse_layout->addWidget(new QLabel(tr("Width: "), _widget), 1, 0);
_mouse_layout->addWidget(_fen_checkBox, 0, 0, 1, 4);
_mouse_layout->addWidget(new QLabel(tr("W: "), _widget), 1, 0);
_mouse_layout->addWidget(_width_label, 1, 1);
_mouse_layout->addWidget(new QLabel(tr("Period: "), _widget), 2, 0);
_mouse_layout->addWidget(_period_label, 2, 1);
_mouse_layout->addWidget(new QLabel(tr("Frequency: "), _widget), 3, 0);
_mouse_layout->addWidget(_freq_label, 3, 1);
_mouse_layout->addWidget(new QLabel(tr("Duty Cycle: "), _widget), 4, 0);
_mouse_layout->addWidget(_duty_label, 4, 1);
_mouse_layout->addWidget(new QLabel(_widget), 0, 2);
_mouse_layout->addWidget(new QLabel(_widget), 1, 2);
_mouse_layout->addWidget(new QLabel(_widget), 2, 2);
_mouse_layout->addWidget(new QLabel(_widget), 3, 2);
_mouse_layout->addWidget(new QLabel(_widget), 4, 2);
_mouse_layout->setColumnStretch(2, 1);
_mouse_layout->addWidget(new QLabel(tr("P: "), _widget), 1, 2);
_mouse_layout->addWidget(_period_label, 1, 3);
_mouse_layout->addWidget(new QLabel(tr("F: "), _widget), 2, 2);
_mouse_layout->addWidget(_freq_label, 2, 3);
_mouse_layout->addWidget(new QLabel(tr("D: "), _widget), 2, 0);
_mouse_layout->addWidget(_duty_label, 2, 1);
_mouse_layout->addWidget(new QLabel(_widget), 0, 4);
_mouse_layout->addWidget(new QLabel(_widget), 1, 4);
_mouse_layout->addWidget(new QLabel(_widget), 2, 4);
_mouse_layout->setColumnStretch(5, 1);
_mouse_groupBox->setLayout(_mouse_layout);
......@@ -86,12 +87,9 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession &session) :
_t1_comboBox = new QComboBox(_widget);
_t2_comboBox = new QComboBox(_widget);
_t3_comboBox = new QComboBox(_widget);
_delta_label_t1t2 = new QLabel("#####", _widget);
_cnt_label_t1t2 = new QLabel("#####", _widget);
_delta_label_t2t3 = new QLabel("#####", _widget);
_cnt_label_t2t3 = new QLabel("#####", _widget);
_delta_label_t1t3 = new QLabel("#####", _widget);
_cnt_label_t1t3 = new QLabel("#####", _widget);
_delta_label_t1t2 = new QLabel("##########/##########", _widget);
_delta_label_t2t3 = new QLabel("##########/##########", _widget);
_delta_label_t1t3 = new QLabel("##########/##########", _widget);
_t1_last_index = 0;
_t2_last_index = 0;
_t3_last_index = 0;
......@@ -104,31 +102,25 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession &session) :
_cursor_layout->addWidget(new QLabel(tr("T3: "), _widget), 2, 0);
_cursor_layout->addWidget(_t3_comboBox, 2, 1);
_cursor_layout->addWidget(new QLabel(tr("|T2 - T1|: "), _widget), 3, 0);
_cursor_layout->addWidget(_delta_label_t1t2, 3, 1);
_cursor_layout->addWidget(new QLabel(tr("Delta Samples: "), _widget), 3, 2);
_cursor_layout->addWidget(_cnt_label_t1t2, 3, 3);
_cursor_layout->addWidget(new QLabel(tr("Time/Samples"), _widget), 3, 1, 1, 2);
_cursor_layout->addWidget(new QLabel(tr("|T2 - T1|: "), _widget), 4, 0);
_cursor_layout->addWidget(_delta_label_t1t2, 4, 1, 1, 2);
_cursor_layout->addWidget(new QLabel(tr("|T3 - T2|: "), _widget), 4, 0);
_cursor_layout->addWidget(_delta_label_t2t3, 4, 1);
_cursor_layout->addWidget(new QLabel(tr("Delta Samples: "), _widget), 4, 2);
_cursor_layout->addWidget(_cnt_label_t2t3, 4, 3);
_cursor_layout->addWidget(new QLabel(tr("|T3 - T2|: "), _widget), 5, 0);
_cursor_layout->addWidget(_delta_label_t2t3, 5, 1, 1, 2);
_cursor_layout->addWidget(new QLabel(tr("|T3 - T1|: "), _widget), 5, 0);
_cursor_layout->addWidget(_delta_label_t1t3, 5, 1);
_cursor_layout->addWidget(new QLabel(tr("Delta Samples: "), _widget), 5, 2);
_cursor_layout->addWidget(_cnt_label_t1t3, 5, 3);
_cursor_layout->addWidget(new QLabel(tr("|T3 - T1|: "), _widget), 6, 0);
_cursor_layout->addWidget(_delta_label_t1t3, 6, 1, 1, 2);
_cursor_layout->addWidget(new QLabel(tr("Cursors"), _widget), 6, 0);
_cursor_layout->addWidget(new QLabel(tr("Time/Samples"), _widget), 6, 1, 1, 4);
_cursor_layout->addWidget(new QLabel(_widget), 7, 0);
_cursor_layout->addWidget(new QLabel(tr("Cursors"), _widget), 8, 0);
_cursor_layout->addWidget(new QLabel(tr("Time/Samples"), _widget), 8, 1, 1, 2);
_cursor_layout->addWidget(new QLabel(_widget), 0, 4);
_cursor_layout->addWidget(new QLabel(_widget), 1, 4);
_cursor_layout->addWidget(new QLabel(_widget), 2, 4);
_cursor_layout->addWidget(new QLabel(_widget), 3, 4);
_cursor_layout->addWidget(new QLabel(_widget), 4, 4);
_cursor_layout->addWidget(new QLabel(_widget), 0, 2);
_cursor_layout->addWidget(new QLabel(_widget), 1, 2);
_cursor_layout->addWidget(new QLabel(_widget), 2, 2);
_cursor_layout->setColumnStretch(2, 1);
_cursor_layout->setColumnStretch(4, 1);
_cursor_groupBox->setLayout(_cursor_layout);
QVBoxLayout *layout = new QVBoxLayout(_widget);
......@@ -205,9 +197,8 @@ void MeasureDock::cursor_update()
_curpos_label_list.push_back(_curpos_label);
_space_label_list.push_back(_space_label);
_cursor_layout->addWidget(_cursor_pushButton, 6 + index, 0);
_cursor_layout->addWidget(_curpos_label, 6 + index, 1, 1, 4);
_cursor_layout->addWidget(_space_label, 6 + index, 2);
_cursor_layout->addWidget(_cursor_pushButton, 8 + index, 0);
_cursor_layout->addWidget(_curpos_label, 8 + index, 1, 1, 2);
connect(_cursor_pushButton, SIGNAL(clicked()), this, SLOT(goto_cursor()));
......@@ -255,28 +246,32 @@ void MeasureDock::cursor_moved()
void MeasureDock::delta_update()
{
QString delta_text;
_t1_last_index = std::max(_t1_comboBox->currentIndex(), 0);
_t2_last_index = std::max(_t2_comboBox->currentIndex(), 0);
_t3_last_index = std::max(_t3_comboBox->currentIndex(), 0);
if (_t1_comboBox->count() != 0 && _t2_comboBox->count() != 0) {
uint64_t delta = abs(_view.get_cursor_samples(_t1_last_index) -
_view.get_cursor_samples(_t2_last_index));
_delta_label_t1t2->setText(_view.get_cm_delta(_t1_last_index, _t2_last_index));
_cnt_label_t1t2->setText(QString::number(delta));
delta_text = _view.get_cm_delta(_t1_last_index, _t2_last_index) +
"/" + QString::number(delta);
_delta_label_t1t2->setText(delta_text);
}
if (_t2_comboBox->count() != 0 && _t2_comboBox->count() != 0) {
uint64_t delta = abs(_view.get_cursor_samples(_t2_last_index) -
_view.get_cursor_samples(_t3_last_index));
_delta_label_t2t3->setText(_view.get_cm_delta(_t2_last_index, _t3_last_index));
_cnt_label_t2t3->setText(QString::number(delta));
delta_text = _view.get_cm_delta(_t2_last_index, _t3_last_index) +
"/" + QString::number(delta);
_delta_label_t2t3->setText(delta_text);
}
if (_t1_comboBox->count() != 0 && _t3_comboBox->count() != 0) {
uint64_t delta = abs(_view.get_cursor_samples(_t1_last_index) -
_view.get_cursor_samples(_t3_last_index));
_delta_label_t1t3->setText(_view.get_cm_delta(_t1_last_index, _t3_last_index));
_cnt_label_t1t3->setText(QString::number(delta));
delta_text = _view.get_cm_delta(_t1_last_index, _t3_last_index) +
"/" + QString::number(delta);
_delta_label_t1t3->setText(delta_text);
}
}
......
......@@ -65,7 +65,6 @@ public:
~MeasureDock();
void paintEvent(QPaintEvent *);
signals:
private slots:
......
......@@ -206,7 +206,7 @@ void MainWindow::setup_ui()
_measure_dock->setFeatures(QDockWidget::DockWidgetMovable);
_measure_dock->setAllowedAreas(Qt::RightDockWidgetArea);
_measure_dock->setVisible(false);
dock::MeasureDock *_measure_widget = new dock::MeasureDock(_measure_dock, *_view, _session);
_measure_widget = new dock::MeasureDock(_measure_dock, *_view, _session);
_measure_dock->setWidget(_measure_widget);
// search dock
_search_dock=new QDockWidget(tr("Search..."), this);
......
......@@ -165,6 +165,7 @@ private:
dock::TriggerDock *_trigger_widget;
dock::DsoTriggerDock *_dso_trigger_widget;
QDockWidget *_measure_dock;
dock::MeasureDock *_measure_widget;
QDockWidget *_search_dock;
dock::SearchDock * _search_widget;
......
......@@ -278,7 +278,7 @@ void DecodeTrace::paint_fore(QPainter &p, int left, int right)
const QRect r(left + ArrowSize * 2, y - row_height / 2,
right - left, row_height);
const QString h(_cur_row_headings[i]);
const int f = Qt::AlignLeft | Qt::AlignVCenter |
const int f = Qt::AlignLeft | Qt::AlignBottom |
Qt::TextDontClip;
// Draw the outline
......
......@@ -198,6 +198,11 @@ void DsoSignal::set_scale(float scale)
_scale = scale;
}
float DsoSignal::get_scale()
{
return _scale;
}
void DsoSignal::set_enable(bool enable)
{
if ((strcmp(_dev_inst->dev_inst()->driver->name, "DSLogic") == 0) &&
......@@ -845,7 +850,9 @@ void DsoSignal::paint_trace(QPainter &p,
const uint8_t *const samples = snapshot->get_samples(start, end, get_index());
assert(samples);
p.setPen(_colour);
QColor trace_colour = _colour;
trace_colour.setAlpha(100);
p.setPen(trace_colour);
//p.setPen(QPen(_colour, 3, Qt::SolidLine));
QPointF *points = new QPointF[sample_count];
......@@ -899,7 +906,9 @@ void DsoSignal::paint_envelope(QPainter &p,
p.setPen(QPen(NoPen));
//p.setPen(QPen(_colour, 2, Qt::SolidLine));
p.setBrush(_colour);
QColor envelope_colour = _colour;
envelope_colour.setAlpha(150);
p.setBrush(envelope_colour);
QRectF *const rects = new QRectF[e.length];
QRectF *rect = rects;
......@@ -1019,7 +1028,9 @@ void DsoSignal::paint_measure(QPainter &p)
abs(_period) > 1000 ? QString::number(_period/1000, 'f', 2) + "uS" : QString::number(_period, 'f', 2) + "nS";
QString freq_string = abs(_period) > 1000000 ? QString::number(1000000000/_period, 'f', 2) + "Hz" :
abs(_period) > 1000 ? QString::number(1000000/_period, 'f', 2) + "kHz" : QString::number(1000/_period, 'f', 2) + "MHz";
p.setPen(_colour);
QColor measure_colour = _colour;
measure_colour.setAlpha(180);
p.setPen(measure_colour);
p.drawText(QRectF(0, 100*index + UpMargin, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Max: ")+max_string+" ");
p.drawText(QRectF(0, 100*index + UpMargin + 20, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Min: ")+min_string+" ");
p.drawText(QRectF(0, 100*index + UpMargin + 40, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Period: ")+period_string+" ");
......
......@@ -73,6 +73,7 @@ public:
void set_view(pv::view::View *view);
void set_scale(float scale);
float get_scale();
/**
*
......
......@@ -43,7 +43,7 @@ const QColor Trace::dsRed = QColor(213, 15, 37, 255);
const QColor Trace::dsGreen = QColor(0, 153, 37, 200);
const QColor Trace::dsGray = QColor(0x88, 0x8A, 0x85, 60);
const QColor Trace::dsFore = QColor(0xff, 0xff, 0xff, 100);
const QColor Trace::dsBack = QColor(0x16, 0x18, 0x23, 255);
const QColor Trace::dsBack = QColor(0x16, 0x18, 0x23, 180);
const QColor Trace::dsDisable = QColor(0x88, 0x8A, 0x85, 200);
const QColor Trace::dsActive = QColor(17, 133, 209, 255);
const QColor Trace::dsLightBlue = QColor(17, 133, 209, 150);
......
......@@ -785,6 +785,21 @@ int View::get_view_width()
return view_width;
}
int View::get_view_height()
{
int view_height = 0;
if (_session.get_device()->dev_inst()->mode == DSO) {
const vector< boost::shared_ptr<Signal> > sigs(_session.get_signals());
BOOST_FOREACH(const boost::shared_ptr<Signal> s, sigs) {
view_height = max((double)view_height, s->get_view_rect().height());
}
} else {
view_height = _viewport->width();
}
return view_height;
}
double View::get_min_offset()
{
return -(_scale * (get_view_width() * (1 - MaxViewRate)));
......
......@@ -175,6 +175,7 @@ public:
void on_state_changed(bool stop);
int get_view_width();
int get_view_height();
void update_sample(bool instant);
......
......@@ -55,14 +55,18 @@ Viewport::Viewport(View &parent) :
_total_receive_len(0),
_zoom_rect_visible(false),
_measure_shown(false),
_measure_type(LOGIC),
_measure_type(NO_MEASURE),
_cur_sample(0),
_nxt_sample(1),
_cur_preX(0),
_cur_aftX(1),
_cur_midY(0),
_hover_index(0),
_hover_hit(false)
_hover_hit(false),
_dso_xm(false),
_dso_xm_stage(0),
_dso_ym(false),
_dso_ym_done(false)
{
setMouseTracking(true);
setAutoFillBackground(true);
......@@ -363,7 +367,8 @@ void Viewport::mousePressEvent(QMouseEvent *event)
_mouse_down_point = event->pos();
_mouse_down_offset = _view.offset();
_measure_shown = false;
_measure_shown = _dso_xm || _dso_ym;
//_dso_xm = false;
_drag_strength = 0;
_time.start();
......@@ -400,13 +405,56 @@ void Viewport::mousePressEvent(QMouseEvent *event)
update();
}
if (_hover_hit && (event->buttons() & Qt::RightButton)) {
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], _hover_index);
_view.show_cursors(true);
_hover_hit = false;
} else if (_hover_hit && (event->buttons() & Qt::LeftButton)) {
_dso_ym = true;
_dso_ym_done = false;
_dso_ym_sig_index = _hover_sig_index;
_dso_ym_sig_value = _hover_sig_value;
_dso_ym_index = _hover_index;
_dso_ym_start = event->pos().y();
} else if (_dso_ym && !_dso_ym_done && (event->buttons() & Qt::LeftButton)) {
_dso_ym_end = event->pos().y();
_dso_ym_done = true;
} else if (_dso_ym && !_dso_ym_done && (event->buttons() & Qt::RightButton)) {
_dso_ym = false;
_dso_ym_done = false;
} else if (_dso_xm && _dso_xm_stage < DsoMeasureStages && (event->buttons() & Qt::RightButton)) {
_dso_xm = false;
_measure_shown = _dso_ym;
_dso_xm_stage = 0;
_measure_type = NO_MEASURE;
_mm_width = "#####";
_mm_period = "#####";
_mm_freq = "#####";
_mm_duty = "#####";
mouse_measure();
} else if (event->buttons() & Qt::LeftButton) {
if (_dso_xm_stage > 0 && _dso_xm_stage < DsoMeasureStages) {
const uint64_t sample_rate = _view.session().get_device()->get_sample_rate();
const double scale = _view.scale();
const double samples_per_pixel = sample_rate * scale;
_dso_xm_index[_dso_xm_stage] = event->pos().x() * samples_per_pixel + _view.offset() * sample_rate;
for(int i = _dso_xm_stage; i > 0; i--) {
const uint64_t max_index = max(_dso_xm_index[i-1], _dso_xm_index[i]);
_dso_xm_index[i-1] = min(_dso_xm_index[i-1], _dso_xm_index[i]);
_dso_xm_index[i] = max_index;
}
_dso_xm_stage = (++_dso_xm_stage) % (DsoMeasureStages + 1);
}
}
}
void Viewport::mouseMoveEvent(QMouseEvent *event)
{
assert(event);
_hover_hit = false;
if (event->buttons() & Qt::RightButton) {
if (!_dso_xm && (_dso_ym_done || !_dso_ym) &&
event->buttons() & Qt::RightButton) {
_zoom_rect = QRectF(_mouse_down_point, event->pos());
_zoom_rect_visible = true;
}
......@@ -438,6 +486,8 @@ void Viewport::mouseMoveEvent(QMouseEvent *event)
else
grabbed_marker->set_index((uint64_t)ceil(pos));
}
if (_dso_ym && !_dso_ym_done)
_dso_ym_end = event->pos().y();
measure();
}
......@@ -461,13 +511,6 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
if(_drag_sig)
_drag_sig.reset();
if (_hover_hit){
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], _hover_index);
_view.show_cursors(true);
_hover_hit = false;
}
const double strength = _drag_strength*DragTimerInterval*1.0/_time.elapsed();
if (_drag_strength < MinorDragOffsetUp && abs(strength) > MinorDragRateUp) {
_drag_strength = _drag_strength;
......@@ -495,6 +538,29 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
_view.set_scale_offset(_view.get_maxscale(), 0);
update();
} else if (_view.session().get_device()->dev_inst()->mode == DSO &&
_view.session().get_capture_state() != SigSession::Init) {
if (_dso_xm_stage == 0) {
uint64_t sample_rate = _view.session().get_device()->get_sample_rate();
double scale = _view.scale();
const double samples_per_pixel = sample_rate * scale;
_dso_xm_index[0] = event->pos().x() * samples_per_pixel +
_view.offset() * sample_rate;;
_dso_xm_stage = 1;
_dso_xm_y = event->pos().y();
_dso_xm = true;
_measure_type = DSO_FREQ;
_measure_shown = true;
} else if (_dso_xm_stage == DsoMeasureStages) {
_dso_xm = false;
_measure_shown = _dso_ym;
_dso_xm_stage = 0;
_mm_width = "#####";
_mm_period = "#####";
_mm_freq = "#####";
_mm_duty = "#####";
mouse_measure();
}
}
}
......@@ -518,7 +584,7 @@ void Viewport::wheelEvent(QWheelEvent *event)
void Viewport::leaveEvent(QEvent *)
{
_measure_shown = false;
_measure_shown = _dso_xm || _dso_ym;
_mouse_point = QPoint(-1, -1);
//_view.show_cursors(false);
update();
......@@ -546,10 +612,11 @@ void Viewport::set_receive_len(quint64 length)
void Viewport::measure()
{
if (_view.session().get_capture_state() == SigSession::Running ||
if ((_view.session().get_device()->dev_inst()->mode == LOGIC &&
_view.session().get_capture_state() == SigSession::Running) ||
_drag_strength != 0)
return;
_measure_shown = false;
_measure_shown = _dso_xm || _dso_ym;
const uint64_t sample_rate = _view.session().get_device()->get_sample_rate();
const vector< boost::shared_ptr<Signal> > sigs(_view.session().get_signals());
BOOST_FOREACH(const boost::shared_ptr<Signal> s, sigs) {
......@@ -559,7 +626,7 @@ void Viewport::measure()
if (logicSig = dynamic_pointer_cast<view::LogicSignal>(s)) {
if (logicSig->measure(_view.hover_point(), _cur_sample, _nxt_sample, _thd_sample)) {
_measure_shown = true;
_measure_type = LOGIC;
_measure_type = LOGIC_FREQ;
_mm_width = _view.get_ruler()->format_real_time(_nxt_sample - _cur_sample, sample_rate);
_mm_period = _thd_sample != 0 ? _view.get_ruler()->format_real_time(_thd_sample - _cur_sample, sample_rate) : "#####";
......@@ -586,7 +653,7 @@ void Viewport::measure()
} else if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)) {
if (_measure_en && dsoSig->measure(_view.hover_point())) {
_measure_shown = true;
_measure_type = DSO;
_measure_type = DSO_FREQ;
}
}
}
......@@ -595,7 +662,7 @@ void Viewport::measure()
void Viewport::paintMeasure(QPainter &p)
{
_hover_hit = false;
if (_measure_type == LOGIC) {
if (_measure_type == LOGIC_FREQ) {
p.setPen(QColor(17, 133, 209, 255));
p.drawLine(QLineF(_cur_preX, _cur_midY, _cur_aftX, _cur_midY));
p.drawLine(QLineF(_cur_preX, _cur_midY, _cur_preX + 2, _cur_midY - 2));
......@@ -648,7 +715,7 @@ void Viewport::paintMeasure(QPainter &p)
p.drawText(measure4_rect, Qt::AlignRight | Qt::AlignVCenter,
tr("Duty Cycle: ") + _mm_duty);
}
} else if (_measure_type == DSO) {
} else if (_measure_type == DSO_FREQ) {
const vector< boost::shared_ptr<Signal> > sigs(_view.session().get_signals());
BOOST_FOREACH(const boost::shared_ptr<Signal> s, sigs) {
boost::shared_ptr<view::DsoSignal> dsoSig;
......@@ -685,6 +752,8 @@ void Viewport::paintMeasure(QPainter &p)
p.drawPolyline(dn_arrow, 3);
p.drawLine(cursor_md, cursor_up, cursor_md, cursor_dn);
_hover_hit = true;
_hover_sig_index = dsoSig->get_index();
_hover_sig_value = value;
_hover_index = index;
} else {
p.setBrush(Qt::NoBrush);
......@@ -704,6 +773,132 @@ void Viewport::paintMeasure(QPainter &p)
}
}
}
// -- vertical value
if (_dso_ym) {
BOOST_FOREACH(const boost::shared_ptr<Signal> s, sigs) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)) {
if (dsoSig->get_index() == _dso_ym_sig_index) {
p.setPen(QPen(dsoSig->get_colour(), 1, Qt::DotLine));
const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, "W").height();
const uint64_t sample_rate = _view.session().get_device()->get_sample_rate();
const double x = (_dso_ym_index / (sample_rate * _view.scale())) -
_view.offset() /_view.scale();
p.drawLine(x-10, _dso_ym_start,
x+10, _dso_ym_start);
p.drawLine(x, _dso_ym_start,
x, _dso_ym_end);
p.drawLine(0, _dso_ym_end,
_view.get_view_width(), _dso_ym_end);
// -- vertical delta value
double hrate = (_dso_ym_start - _dso_ym_end) * 1.0f / _view.get_view_height();
double value = hrate * dsoSig->get_vDialValue() * dsoSig->get_factor() * DS_CONF_DSO_VDIVS;
QString value_str = abs(value) > 1000 ? QString::number(value/1000.0, 'f', 2) + "V" : QString::number(value, 'f', 2) + "mV";
int value_rect_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignVCenter, value_str).width();
p.drawText(QRect(x+10, abs(_dso_ym_start+_dso_ym_end)/2, value_rect_width, text_height),
value_str);
// -- start value
value_str = abs(_dso_ym_sig_value) > 1000 ? QString::number(_dso_ym_sig_value/1000.0, 'f', 2) + "V" : QString::number(_dso_ym_sig_value, 'f', 2) + "mV";
value_rect_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignVCenter, value_str).width();
int str_y = value > 0 ? _dso_ym_start : _dso_ym_start - text_height;
p.drawText(QRect(x-0.5*value_rect_width, str_y, value_rect_width, text_height),
value_str);
// -- end value
double end_value = _dso_ym_sig_value + value;
value_str = abs(end_value) > 1000 ? QString::number(end_value/1000.0, 'f', 2) + "V" : QString::number(end_value, 'f', 2) + "mV";
value_rect_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignVCenter, value_str).width();
str_y = value > 0 ? _dso_ym_end-text_height : _dso_ym_end;
p.drawText(QRect(x-0.5*value_rect_width, str_y, value_rect_width, text_height),
value_str);
break;
}
}
}
}
// -- width/period/frequency/duty
if (_dso_xm) {
p.setPen(QPen(Qt::red, 1, Qt::DotLine));
int measure_line_count = 6;
const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, "W").height();
const uint64_t sample_rate = _view.session().get_device()->get_sample_rate();
QLineF *line;
QLineF *const measure_lines = new QLineF[measure_line_count];
line = measure_lines;
double x[DsoMeasureStages];
for (int i = 0; i < _dso_xm_stage; i++) {
x[i] = (_dso_xm_index[i] / (sample_rate * _view.scale())) -
_view.offset() /_view.scale();
}
measure_line_count = 0;
if (_dso_xm_stage > 0) {
*line++ = QLineF(x[0], _dso_xm_y - 10,
x[0], _dso_xm_y + 10);
measure_line_count += 1;
}
if (_dso_xm_stage > 1) {
*line++ = QLineF(x[1], _dso_xm_y - 10,
x[1], _dso_xm_y + 10);
*line++ = QLineF(x[0], _dso_xm_y,
x[1], _dso_xm_y);
_mm_width = _view.get_ruler()->format_real_time(_dso_xm_index[1] - _dso_xm_index[0], sample_rate);
// -- width show
const QString w_ctr = "W="+_mm_width;
int w_rect_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignVCenter, w_ctr).width();
p.drawText(QRect(x[0]+10, _dso_xm_y - text_height, w_rect_width, text_height), w_ctr);
measure_line_count += 2;
}
if (_dso_xm_stage > 2) {
*line++ = QLineF(x[0], _dso_xm_y + 20,
x[0], _dso_xm_y + 40);
*line++ = QLineF(x[0], _dso_xm_y + 30,
x[2], _dso_xm_y + 30);
*line++ = QLineF(x[2], _dso_xm_y + 20,
x[2], _dso_xm_y + 40);
_mm_period = _view.get_ruler()->format_real_time(_dso_xm_index[2] - _dso_xm_index[0], sample_rate);
_mm_freq = _view.get_ruler()->format_real_freq(_dso_xm_index[2] - _dso_xm_index[0], sample_rate);
_mm_duty = QString::number((_dso_xm_index[1] - _dso_xm_index[0]) * 100.0 / (_dso_xm_index[2] - _dso_xm_index[0]), 'f', 2)+"%";
// -- period show
const QString p_ctr = "P="+_mm_period;
int p_rect_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignVCenter, p_ctr).width();
p.drawText(QRect(x[0]+10, _dso_xm_y + 30 - text_height, p_rect_width, text_height), p_ctr);
// -- frequency show
const QString f_ctr = "F="+_mm_freq;
int f_rect_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignVCenter, f_ctr).width();
p.drawText(QRect(x[0]+20 + p_rect_width, _dso_xm_y + 30 - text_height, f_rect_width, text_height), f_ctr);
// -- duty show
const QString d_ctr = "D="+_mm_duty;
int d_rect_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignVCenter, d_ctr).width();
p.drawText(QRect(x[1]+10, _dso_xm_y - 0.5*text_height, d_rect_width, text_height), d_ctr);
measure_line_count += 3;
}
p.drawLines(measure_lines, measure_line_count);
if (_dso_xm_stage < DsoMeasureStages) {
p.drawLine(x[_dso_xm_stage-1], _dso_xm_y,
_mouse_point.x(), _dso_xm_y);
p.drawLine(_mouse_point.x(), 0,
_mouse_point.x(), _view.get_viewport()->height());
}
mouse_measure();
}
}
}
......
......@@ -51,8 +51,14 @@ public:
static const double HitCursorTimeMargin;
static const int DragTimerInterval = 100;
static const int MinorDragOffsetUp = 100;
static const int DsoMeasureStages = 3;
static const double MinorDragRateUp;
static const double DragDamping;
enum MeasureType {
NO_MEASURE,
LOGIC_FREQ,
DSO_FREQ
};
public:
explicit Viewport(View &parent);
......@@ -133,10 +139,25 @@ private:
uint64_t _hover_index;
bool _hover_hit;
uint16_t _hover_sig_index;
double _hover_sig_value;
QTime _time;
QTimer _drag_timer;
int _drag_strength;
bool _dso_xm;
int _dso_xm_stage;
int _dso_xm_y;
uint64_t _dso_xm_index[DsoMeasureStages];
bool _dso_ym;
bool _dso_ym_done;
uint16_t _dso_ym_sig_index;
double _dso_ym_sig_value;
uint64_t _dso_ym_index;
int _dso_ym_start;
int _dso_ym_end;
};
} // namespace view
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment