Commit bdaa6734 authored by DreamSourceLab's avatar DreamSourceLab

Fix scale&offset issue when zoom in/out

parent 519f3b06
......@@ -276,7 +276,7 @@ void MainWindow::setup_ui()
connect(&_session, SIGNAL(update_capture()), _view,
SLOT(update_hori_res()), Qt::DirectConnection);
connect(&_session, SIGNAL(cur_samplerate_changed()), _measure_widget,
connect(&_session, SIGNAL(cur_snap_samplerate_changed()), _measure_widget,
SLOT(cursor_update()));
connect(_view, SIGNAL(cursor_update()), _measure_widget,
SLOT(cursor_update()));
......
......@@ -175,7 +175,7 @@ void SigSession::set_device(boost::shared_ptr<device::DevInst> dev_inst)
if (_dev_inst) {
try {
_dev_inst->use(this);
_cur_samplerate = _dev_inst->get_sample_rate();
_cur_snap_samplerate = _dev_inst->get_sample_rate();
_cur_samplelimits = _dev_inst->get_sample_limit();
if (_dev_inst->dev_inst()->mode == DSO)
......@@ -274,43 +274,63 @@ uint64_t SigSession::cur_samplelimits() const
uint64_t SigSession::cur_samplerate() const
{
return _cur_samplerate;
// samplerate for current viewport
if (_dev_inst->dev_inst()->mode == DSO)
return _dev_inst->get_sample_rate();
else
return cur_snap_samplerate();
}
uint64_t SigSession::cur_snap_samplerate() const
{
// samplerate for current snapshot
return _cur_snap_samplerate;
}
double SigSession::cur_sampletime() const
{
if (_cur_samplerate == 0)
return 0;
else
return cur_samplelimits() * 1.0 / cur_samplerate();
return cur_samplelimits() * 1.0 / cur_samplerate();
}
void SigSession::set_cur_samplerate(uint64_t samplerate)
double SigSession::cur_snap_sampletime() const
{
return cur_samplelimits() * 1.0 / cur_snap_samplerate();
}
double SigSession::cur_view_time() const
{
return _dev_inst->get_time_base() * DS_CONF_DSO_HDIVS * 1.0 / SR_SEC(1);
}
void SigSession::set_cur_snap_samplerate(uint64_t samplerate)
{
assert(samplerate != 0);
_cur_samplerate = samplerate;
_cur_snap_samplerate = samplerate;
// sample rate for all SignalData
// Logic/Analog/Dso
if (_logic_data)
_logic_data->set_samplerate(_cur_samplerate);
_logic_data->set_samplerate(_cur_snap_samplerate);
if (_analog_data)
_analog_data->set_samplerate(_cur_samplerate);
// if (_dso_data)
// _dso_data->set_samplerate(_cur_samplerate);
_analog_data->set_samplerate(_cur_snap_samplerate);
if (_dso_data)
_dso_data->set_samplerate(_cur_snap_samplerate);
// Group
if (_group_data)
_group_data->set_samplerate(_cur_samplerate);
_group_data->set_samplerate(_cur_snap_samplerate);
#ifdef ENABLE_DECODE
// DecoderStack
BOOST_FOREACH(const boost::shared_ptr<view::DecodeTrace> d, _decode_traces)
d->decoder()->set_samplerate(_cur_samplerate);
d->decoder()->set_samplerate(_cur_snap_samplerate);
#endif
// Math
if (_math_trace && _math_trace->enabled())
_math_trace->get_math_stack()->set_samplerate(_dev_inst->get_sample_rate());
// SpectrumStack
BOOST_FOREACH(const boost::shared_ptr<view::SpectrumTrace> m, _spectrum_traces)
m->get_spectrum_stack()->set_samplerate(_cur_samplerate);
m->get_spectrum_stack()->set_samplerate(_cur_snap_samplerate);
cur_samplerate_changed();
cur_snap_samplerate_changed();
}
void SigSession::set_cur_samplelimits(uint64_t samplelimits)
......@@ -328,7 +348,7 @@ void SigSession::capture_init()
_dev_inst->set_config(NULL, NULL, SR_CONF_INSTANT, g_variant_new_boolean(_instant));
update_capture();
set_cur_samplerate(_dev_inst->get_sample_rate());
set_cur_snap_samplerate(_dev_inst->get_sample_rate());
set_cur_samplelimits(_dev_inst->get_sample_limit());
_data_updated = false;
_trigger_flag = false;
......@@ -598,7 +618,7 @@ void SigSession::add_group()
// if (_group_data->get_snapshots().empty())
// _group_data->set_samplerate(_dev_inst->get_sample_rate());
_group_data->init();
_group_data->set_samplerate(_cur_samplerate);
_group_data->set_samplerate(_cur_snap_samplerate);
const boost::shared_ptr<view::GroupSignal> signal(
new view::GroupSignal("New Group",
_group_data, probe_index_list, _group_cnt));
......@@ -1017,13 +1037,7 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso)
if (dso.num_samples != 0) {
// update current sample rate
if (_dso_data)
_dso_data->set_samplerate(_dev_inst->get_sample_rate());
if (_math_trace && _math_trace->enabled())
_math_trace->get_math_stack()->set_samplerate(_dev_inst->get_sample_rate());
BOOST_FOREACH(const boost::shared_ptr<view::SpectrumTrace> m, _spectrum_traces)
m->get_spectrum_stack()->set_samplerate(_cur_samplerate);
set_cur_snap_samplerate(_dev_inst->get_sample_rate());
// // reset measure of dso signal
// BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals)
// {
......@@ -1540,6 +1554,7 @@ void SigSession::math_rebuild(bool enable,
new data::MathStack(*this, dsoSig1, dsoSig2, type));
_math_trace.reset(new view::MathTrace(enable, math_stack, dsoSig1, dsoSig2));
if (_math_trace && _math_trace->enabled()) {
_math_trace->get_math_stack()->set_samplerate(_dev_inst->get_sample_rate());
_math_trace->get_math_stack()->realloc(_dev_inst->get_sample_limit());
_math_trace->get_math_stack()->calc_math();
}
......
......@@ -150,9 +150,13 @@ public:
capture_state get_capture_state() const;
uint64_t cur_samplerate() const;
uint64_t cur_snap_samplerate() const;
uint64_t cur_samplelimits() const;
double cur_sampletime() const;
void set_cur_samplerate(uint64_t samplerate);
double cur_snap_sampletime() const;
double cur_view_time() const;
void set_cur_snap_samplerate(uint64_t samplerate);
void set_cur_samplelimits(uint64_t samplelimits);
void set_session_time(QDateTime time);
QDateTime get_session_time() const;
......@@ -301,7 +305,7 @@ private:
mutable boost::mutex _sampling_mutex;
capture_state _capture_state;
bool _instant;
uint64_t _cur_samplerate;
uint64_t _cur_snap_samplerate;
uint64_t _cur_samplelimits;
//mutable boost::mutex _signals_mutex;
......@@ -401,7 +405,7 @@ signals:
void repeat_hold(int percent);
void repeat_resume();
void cur_samplerate_changed();
void cur_snap_samplerate_changed();
void update_capture();
......
......@@ -365,7 +365,7 @@ QString StoreSession::meta_gen(boost::shared_ptr<data::Snapshot> snapshot)
fprintf(meta, "total blocks = %d\n", logic_snapshot->get_block_num());
}
s = sr_samplerate_string(_session.cur_samplerate());
s = sr_samplerate_string(_session.cur_snap_samplerate());
fprintf(meta, "samplerate = %s\n", s);
if (sdi->mode == DSO) {
......@@ -610,7 +610,7 @@ void StoreSession::export_proc(shared_ptr<data::Snapshot> snapshot)
struct sr_datafeed_meta meta;
struct sr_config *src;
src = sr_config_new(SR_CONF_SAMPLERATE,
g_variant_new_uint64(_session.cur_samplerate()));
g_variant_new_uint64(_session.cur_snap_samplerate()));
meta.config = g_slist_append(NULL, src);
src = sr_config_new(SR_CONF_LIMIT_SAMPLES,
g_variant_new_uint64(snapshot->get_sample_count()));
......
......@@ -761,8 +761,6 @@ double SamplingBar::commit_hori_res()
(uint64_t)(max_sample_rate /
(_session.get_ch_num(SR_CHANNEL_DSO) ? _session.get_ch_num(SR_CHANNEL_DSO) : 1)));
set_sample_rate(sample_rate);
if (_session.get_capture_state() != SigSession::Stopped)
_session.set_cur_samplerate(dev_inst->get_sample_rate());
dev_inst->set_config(NULL, NULL, SR_CONF_TIMEBASE,
g_variant_new_uint64(hori_res));
......
......@@ -59,7 +59,7 @@ Cursor::Cursor(View &view, QColor color, uint64_t index) :
QRect Cursor::get_label_rect(const QRect &rect, bool &visible) const
{
const double samples_per_pixel = _view.session().cur_samplerate() * _view.scale();
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
const double cur_offset = _index / samples_per_pixel;
if (cur_offset < _view.offset() ||
cur_offset > (_view.offset() + _view.width())) {
......@@ -124,7 +124,7 @@ void Cursor::paint_label(QPainter &p, const QRect &rect,
p.drawLine(close.left() + 2, close.bottom() - 2, close.right() - 2, close.top() + 2);
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
Ruler::format_real_time(_index, _view.session().cur_samplerate()));
Ruler::format_real_time(_index, _view.session().cur_snap_samplerate()));
const QRect arrowRect = QRect(r.bottomLeft().x(), r.bottomLeft().y(), r.width(), ArrowSize);
p.drawText(arrowRect, Qt::AlignCenter | Qt::AlignVCenter, QString::number(index));
......@@ -154,7 +154,7 @@ void Cursor::paint_fix_label(QPainter &p, const QRect &rect,
p.setPen(Qt::white);
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
Ruler::format_real_time(_index, _view.session().cur_samplerate()));
Ruler::format_real_time(_index, _view.session().cur_snap_samplerate()));
const QRect arrowRect = QRect(r.bottomLeft().x(), r.bottomLeft().y(), r.width(), ArrowSize);
p.drawText(arrowRect, Qt::AlignCenter | Qt::AlignVCenter, label);
......@@ -164,7 +164,7 @@ void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
{
(void)prefix;
_text_size = p.boundingRect(QRect(), 0,
Ruler::format_real_time(_index, _view.session().cur_samplerate())).size();
Ruler::format_real_time(_index, _view.session().cur_snap_samplerate())).size();
}
} // namespace view
......
......@@ -183,7 +183,7 @@ void DecodeTrace::paint_back(QPainter &p, int left, int right, QColor fore, QCol
p.drawLine(left, sigY, right, sigY);
// --draw decode region control
const double samples_per_pixel = _session.cur_samplerate() * _view->scale();
const double samples_per_pixel = _session.cur_snap_samplerate() * _view->scale();
const double startX = _decode_start/samples_per_pixel - _view->offset();
const double endX = _decode_end/samples_per_pixel - _view->offset();
const double regionY = get_y() - _totalHeight*0.5 - ControlRectWidth;
......
......@@ -719,7 +719,7 @@ void DsoSignal::paint_back(QPainter &p, int left, int right, QColor fore, QColor
fore.setAlpha(View::ForeAlpha);
p.setPen(fore);
const uint64_t sample_len = _view->session().cur_samplelimits();
const double samplerate = _view->session().cur_samplerate();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * _view->scale();
const double shown_rate = min(samples_per_pixel * width * 1.0 / sample_len, 1.0);
const double start = _view->offset() * samples_per_pixel;
......@@ -808,7 +808,7 @@ void DsoSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QColor
const double pixels_offset = offset;
const double samplerate = _data->samplerate();
//const double samplerate = _dev_inst->get_sample_rate();
//const double samplerate = _view->session().cur_samplerate();
//const double samplerate = _view->session().cur_snap_samplerate();
const int64_t last_sample = max((int64_t)(snapshot->get_sample_count() - 1), (int64_t)0);
const double samples_per_pixel = samplerate * scale;
const double start = offset * samples_per_pixel;
......@@ -1424,7 +1424,7 @@ bool DsoSignal::measure(const QPointF &p)
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_samplerate();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
_hover_index = floor((p.x() + pixels_offset) * samples_per_pixel+0.5);
......@@ -1467,7 +1467,7 @@ QPointF DsoSignal::get_point(uint64_t index, float &value)
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_samplerate();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
if (index >= snapshot->get_sample_count())
......
......@@ -218,7 +218,7 @@ void MathTrace::paint_mid(QPainter &p, int left, int right, QColor fore, QColor
const int64_t offset = _view->offset();
const double pixels_offset = offset;
//const double samplerate = _view->session().cur_samplerate();
//const double samplerate = _view->session().cur_snap_samplerate();
const double samplerate = _math_stack->samplerate();
const int64_t last_sample = max((int64_t)(_math_stack->get_sample_num() - 1), (int64_t)0);
const double samples_per_pixel = samplerate * scale;
......@@ -461,7 +461,7 @@ bool MathTrace::measure(const QPointF &p)
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_samplerate();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
_hover_index = floor((p.x() + pixels_offset) * samples_per_pixel+0.5);
......@@ -480,7 +480,7 @@ QPointF MathTrace::get_point(uint64_t index, float &value)
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_samplerate();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
const float top = get_view_rect().top();
......
......@@ -195,7 +195,7 @@ void Ruler::mouseMoveEvent(QMouseEvent *e)
if (_grabbed_marker) {
_grabbed_marker->set_index((_view.offset() + _view.hover_point().x()) *
_view.scale() * _view.session().cur_samplerate());
_view.scale() * _view.session().cur_snap_samplerate());
_view.cursor_moving();
_curs_moved = true;
}
......@@ -253,7 +253,7 @@ void Ruler::mouseReleaseEvent(QMouseEvent *event)
_cursor_sel_visible = true;
} else {
int overCursor;
uint64_t index = (_view.offset() + _cursor_sel_x + 0.5) * _view.scale() * _view.session().cur_samplerate();
uint64_t index = (_view.offset() + _cursor_sel_x + 0.5) * _view.scale() * _view.session().cur_snap_samplerate();
overCursor = in_cursor_sel_rect(event->pos());
if (overCursor == 0) {
_view.add_cursor(CursorColor[_view.get_cursorList().size() % 8], index);
......@@ -329,7 +329,7 @@ void Ruler::draw_logic_tick_mark(QPainter &p)
const double SpacingIncrement = 32.0;
const double MinValueSpacing = 16.0;
const int ValueMargin = 5;
const double abs_min_period = 10.0 / _view.session().cur_samplerate();
const double abs_min_period = 10.0 / _view.session().cur_snap_samplerate();
double min_width = SpacingIncrement;
double typical_width;
......
......@@ -364,8 +364,8 @@ void SpectrumTrace::paint_fore(QPainter &p, int left, int right, QColor fore, QC
double blank_right = width;
// horizontal ruler
const double NyFreq = _session.cur_samplerate() / (2.0 * _spectrum_stack->get_sample_interval());
const double deltaFreq = _session.cur_samplerate() * 1.0 /
const double NyFreq = _session.cur_snap_samplerate() / (2.0 * _spectrum_stack->get_sample_interval());
const double deltaFreq = _session.cur_snap_samplerate() * 1.0 /
(_spectrum_stack->get_sample_num() * _spectrum_stack->get_sample_interval());
const double FreqRange = NyFreq * _scale;
const double FreqOffset = NyFreq * _offset;
......
......@@ -80,7 +80,7 @@ void TimeMarker::set_index(uint64_t index)
void TimeMarker::paint(QPainter &p, const QRect &rect, const bool highlight, int order)
{
const uint64_t sample_rate = _view.session().cur_samplerate();
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double scale = _view.scale();
const double samples_per_pixel = sample_rate * scale;
const int64_t x = _index/samples_per_pixel - _view.offset();
......
......@@ -283,40 +283,38 @@ void View::update_hori_res()
void View::zoom(double steps, int offset)
{
//if (_session.get_capture_state() == SigSession::Stopped) {
_preScale = _scale;
_preOffset = _offset;
_preScale = _scale;
_preOffset = _offset;
if (_session.get_device()->dev_inst()->mode != DSO) {
_scale *= std::pow(3.0/2.0, -steps);
_scale = max(min(_scale, _maxscale), _minscale);
} else {
if (_session.get_capture_state() == SigSession::Running &&
_session.get_instant())
return;
double hori_res = -1;
if(steps > 0.5)
hori_res = _sampling_bar->hori_knob(-1);
else if (steps < -0.5)
hori_res = _sampling_bar->hori_knob(1);
if (hori_res > 0) {
const double scale = hori_res * DS_CONF_DSO_HDIVS / SR_SEC(1) / get_view_width();
_scale = max(min(scale, _maxscale), _minscale);
}
if (_session.get_device()->dev_inst()->mode != DSO) {
_scale *= std::pow(3.0/2.0, -steps);
_scale = max(min(_scale, _maxscale), _minscale);
} else {
if (_session.get_capture_state() == SigSession::Running &&
_session.get_instant())
return;
double hori_res = -1;
if(steps > 0.5)
hori_res = _sampling_bar->hori_knob(-1);
else if (steps < -0.5)
hori_res = _sampling_bar->hori_knob(1);
if (hori_res > 0) {
const double scale = _session.cur_view_time() / get_view_width();
_scale = max(min(scale, _maxscale), _minscale);
}
}
_offset = floor((_offset + offset) * (_preScale / _scale) - offset);
_offset = max(min(_offset, get_max_offset()), get_min_offset());
_offset = floor((_offset + offset) * (_preScale / _scale) - offset);
_offset = max(min(_offset, get_max_offset()), get_min_offset());
if (_scale != _preScale || _offset != _preOffset) {
_header->update();
_ruler->update();
viewport_update();
update_scroll();
}
//}
if (_scale != _preScale || _offset != _preOffset) {
_header->update();
_ruler->update();
viewport_update();
update_scroll();
}
}
void View::timebase_changed()
......@@ -327,7 +325,7 @@ void View::timebase_changed()
double scale = this->scale();
double hori_res = _sampling_bar->get_hori_res();
if (hori_res > 0)
scale = hori_res * DS_CONF_DSO_HDIVS / SR_SEC(1) / get_view_width();
scale = _session.cur_view_time() / get_view_width();
set_scale_offset(scale, this->offset());
}
......@@ -511,7 +509,7 @@ void View::receive_end()
void View::receive_trigger(quint64 trig_pos)
{
const double time = trig_pos * 1.0 / _session.cur_samplerate();
const double time = trig_pos * 1.0 / _session.cur_snap_samplerate();
_trig_cursor->set_index(trig_pos);
if (ds_trigger_get_en() ||
_session.get_device()->name() == "virtual-session" ||
......@@ -536,7 +534,7 @@ void View::set_search_pos(uint64_t search_pos, bool hit)
QColor fore(QWidget::palette().color(QWidget::foregroundRole()));
fore.setAlpha(View::BackAlpha);
const double time = search_pos * 1.0 / _session.cur_samplerate();
const double time = search_pos * 1.0 / _session.cur_snap_samplerate();
_search_pos = search_pos;
_search_hit = hit;
_search_cursor->set_index(search_pos);
......@@ -597,7 +595,7 @@ void View::get_scroll_layout(int64_t &length, int64_t &offset) const
if (data_set.empty())
return;
length = ceil(_session.cur_sampletime() / _scale);
length = ceil(_session.cur_snap_sampletime() / _scale);
offset = _offset;
}
......@@ -635,14 +633,11 @@ void View::update_scroll()
void View::update_scale_offset()
{
const uint64_t sample_rate = _session.cur_samplerate();
assert(sample_rate > 0);
if (_session.get_device()->dev_inst()->mode != DSO) {
_maxscale = _session.cur_sampletime() / (get_view_width() * MaxViewRate);
_minscale = (1.0 / sample_rate) / MaxPixelsPerSample;
_minscale = (1.0 / _session.cur_snap_samplerate()) / MaxPixelsPerSample;
} else {
_scale = _session.get_device()->get_time_base() * 10.0 / get_view_width() * std::pow(10.0, -9.0);
_scale = _session.cur_view_time() / get_view_width();
_maxscale = 1e9;
_minscale = 1e-15;
}
......@@ -662,11 +657,8 @@ void View::update_scale_offset()
void View::dev_changed(bool close)
{
if (!close) {
const uint64_t sample_rate = _session.cur_samplerate();
assert(sample_rate > 0);
if (_session.get_device()->name().contains("virtual"))
_scale = WellSamplesPerPixel * 1.0 / sample_rate;
_scale = WellSamplesPerPixel * 1.0 / _session.cur_snap_samplerate();
_scale = max(min(_scale, _maxscale), _minscale);
}
......@@ -843,7 +835,7 @@ void View::resizeEvent(QResizeEvent*)
update_scroll();
signals_changed();
if (_session.get_device()->dev_inst()->mode == DSO)
_scale = _session.get_device()->get_time_base() * std::pow(10.0, -9.0) * DS_CONF_DSO_HDIVS / get_view_width();
_scale = _session.cur_view_time() / get_view_width();
if (_session.get_device()->dev_inst()->mode != DSO)
_maxscale = _session.cur_sampletime() / (get_view_width() * MaxViewRate);
......@@ -899,11 +891,15 @@ void View::data_updated()
// Update the scroll bars
update_scroll();
// update scale & offset
update_scale_offset();
// Repaint the view
_time_viewport->unshow_wait_trigger();
set_update(_time_viewport, true);
set_update(_fft_viewport, true);
viewport_update();
_ruler->update();
}
void View::update_margins()
......@@ -987,7 +983,7 @@ void View::set_cursor_middle(int index)
list<Cursor*>::iterator i = _cursorList.begin();
while (index-- != 0)
i++;
set_scale_offset(_scale, (*i)->index() / (_session.cur_samplerate() * _scale) - (get_view_width() / 2));
set_scale_offset(_scale, (*i)->index() / (_session.cur_snap_samplerate() * _scale) - (get_view_width() / 2));
}
void View::on_measure_updated()
......@@ -1006,7 +1002,7 @@ QString View::get_measure(QString option)
QString View::get_cm_time(int index)
{
return _ruler->format_real_time(get_cursor_samples(index), _session.cur_samplerate());
return _ruler->format_real_time(get_cursor_samples(index), _session.cur_snap_samplerate());
}
QString View::get_cm_delta(int index1, int index2)
......@@ -1017,7 +1013,7 @@ QString View::get_cm_delta(int index1, int index2)
uint64_t samples1 = get_cursor_samples(index1);
uint64_t samples2 = get_cursor_samples(index2);
uint64_t delta_sample = (samples1 > samples2) ? samples1 - samples2 : samples2 - samples1;
return _ruler->format_real_time(delta_sample, _session.cur_samplerate());
return _ruler->format_real_time(delta_sample, _session.cur_snap_samplerate());
}
QString View::get_index_delta(uint64_t start, uint64_t end)
......@@ -1026,7 +1022,7 @@ QString View::get_index_delta(uint64_t start, uint64_t end)
return "0";
uint64_t delta_sample = (start > end) ? start - end : end - start;
return _ruler->format_real_time(delta_sample, _session.cur_samplerate());
return _ruler->format_real_time(delta_sample, _session.cur_snap_samplerate());
}
uint64_t View::get_cursor_samples(int index)
......@@ -1112,7 +1108,7 @@ int64_t View::get_min_offset()
int64_t View::get_max_offset()
{
return ceil((_session.cur_sampletime() / _scale) -
return ceil((_session.cur_snap_sampletime() / _scale) -
(get_view_width() * MaxViewRate));
}
......@@ -1153,13 +1149,13 @@ void View::show_region(uint64_t start, uint64_t end, bool keep)
set_all_update(true);
update();
} else if (_session.get_map_zoom() == 0) {
const double ideal_scale = (end-start) * 2.0 / _session.cur_samplerate() / get_view_width();
const double ideal_scale = (end-start) * 2.0 / _session.cur_snap_samplerate() / get_view_width();
const double new_scale = max(min(ideal_scale, _maxscale), _minscale);
const double new_off = (start + end) * 0.5 / (_session.cur_samplerate() * new_scale) - (get_view_width() / 2);
const double new_off = (start + end) * 0.5 / (_session.cur_snap_samplerate() * new_scale) - (get_view_width() / 2);
set_scale_offset(new_scale, new_off);
} else {
const double new_scale = scale();
const double new_off = (start + end) * 0.5 / (_session.cur_samplerate() * new_scale) - (get_view_width() / 2);
const double new_off = (start + end) * 0.5 / (_session.cur_snap_samplerate() * new_scale) - (get_view_width() / 2);
set_scale_offset(new_scale, new_off);
}
}
......
......@@ -229,7 +229,7 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back)
// plot cursors
//const QRect xrect = QRect(rect().left(), rect().top(), _view.get_view_width(), rect().height());
const QRect xrect = _view.get_view_rect();
const double samples_per_pixel = _view.session().cur_samplerate() * _view.scale();
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
if (_view.cursors_shown() && _type == TIME_VIEW) {
list<Cursor*>::iterator i = _view.get_cursorList().begin();
int index = 0;
......@@ -490,7 +490,7 @@ void Viewport::mousePressEvent(QMouseEvent *event)
_action_type = LOGIC_ZOOM;
} else if (_view.session().get_device()->dev_inst()->mode == DSO) {
if (_hover_hit) {
const int64_t index = (_view.offset() + event->pos().x()) * _view.scale() * _view.session().cur_samplerate();
const int64_t index = (_view.offset() + event->pos().x()) * _view.scale() * _view.session().cur_snap_samplerate();
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
_view.show_cursors(true);
}
......@@ -518,7 +518,7 @@ void Viewport::mousePressEvent(QMouseEvent *event)
if (_action_type == NO_ACTION &&
event->button() == Qt::LeftButton) {
uint64_t sample_rate = _view.session().cur_samplerate();
uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double samples_per_pixel = sample_rate * _view.scale();
if (_action_type == NO_ACTION && _view.search_cursor_shown()) {
const int64_t searchX = _view.get_search_cursor()->index()/samples_per_pixel - _view.offset();
......@@ -643,7 +643,7 @@ void Viewport::mouseMoveEvent(QMouseEvent *event)
}
}
if (_action_type == CURS_MOVE) {
uint64_t sample_rate = _view.session().cur_samplerate();
uint64_t sample_rate = _view.session().cur_snap_samplerate();
TimeMarker* grabbed_marker = _view.get_ruler()->get_grabbed_cursor();
if (grabbed_marker) {
int curX = _view.hover_point().x();
......@@ -740,7 +740,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
assert(event);
if (_type == TIME_VIEW) {
const double samples_per_pixel = _view.session().cur_samplerate() * _view.scale();
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
if ((_action_type == NO_ACTION) &&
(event->button() == Qt::LeftButton)) {
if (_view.session().get_device()->dev_inst()->mode == LOGIC &&
......@@ -771,7 +771,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s))) {
if (logicSig->edge(event->pos(), _edge_start, 10)) {
_action_type = LOGIC_JUMP;
const double samples_per_pixel = _view.session().cur_samplerate() * _view.scale();
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
_cur_preX = _edge_start / samples_per_pixel - _view.offset();
_cur_preY = logicSig->get_y();
_cur_preY_top = logicSig->get_y() - logicSig->get_totalHeight()/2 - 12;
......@@ -793,7 +793,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
assert(s);
if (abs(event->pos().y() - s->get_y()) < _view.get_signalHeight()) {
_action_type = LOGIC_EDGE;
_edge_start = (_view.offset() + event->pos().x()) * _view.scale() * _view.session().cur_samplerate();
_edge_start = (_view.offset() + event->pos().x()) * _view.scale() * _view.session().cur_snap_samplerate();
break;
}
}
......@@ -954,7 +954,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
}
}
}
const uint64_t sample_rate = _view.session().cur_samplerate();
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double curX = event->pos().x();
const double samples_per_pixel = sample_rate * _view.scale();
const double curP = index0 / samples_per_pixel - _view.offset();
......@@ -981,7 +981,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
BOOST_FOREACH(const boost::shared_ptr<Signal> s, _view.session().get_signals()) {
assert(s);
if (s->get_view_rect().contains(event->pos())) {
uint64_t sample_rate = _view.session().cur_samplerate();
uint64_t sample_rate = _view.session().cur_snap_samplerate();
double scale = _view.scale();
const double samples_per_pixel = sample_rate * scale;
_dso_xm_index[0] = (event->pos().x() + _view.offset()) * samples_per_pixel;
......@@ -999,7 +999,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
// }
// } else if (event->button() == Qt::LeftButton) {
// uint64_t index;
// const uint64_t sample_rate = _view.session().cur_samplerate();
// const uint64_t sample_rate = _view.session().cur_snap_samplerate();
// const double curX = event->pos().x();
// index = (_view.offset() + curX) * _view.scale() * sample_rate;;
// _view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
......@@ -1008,7 +1008,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
} else if (_view.session().get_device()->dev_inst()->mode == ANALOG) {
if (event->button() == Qt::LeftButton) {
uint64_t index;
const uint64_t sample_rate = _view.session().cur_samplerate();
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double curX = event->pos().x();
index = (_view.offset() + curX) * _view.scale() * sample_rate;;
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
......@@ -1122,7 +1122,7 @@ void Viewport::measure()
return;
_measure_type = NO_MEASURE;
if (_type == TIME_VIEW) {
const uint64_t sample_rate = _view.session().cur_samplerate();
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const vector< boost::shared_ptr<Signal> > sigs(_view.session().get_signals());
BOOST_FOREACH(const boost::shared_ptr<Signal> s, sigs) {
assert(s);
......@@ -1167,7 +1167,7 @@ void Viewport::measure()
break;
}
} else if (_action_type == LOGIC_JUMP) {
const double samples_per_pixel = _view.session().cur_samplerate() * _view.scale();
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
if (logicSig->edge(_view.hover_point(), _edge_end, 10)) {
_cur_aftX = _edge_end / samples_per_pixel - _view.offset();
_cur_aftY = logicSig->get_y();
......@@ -1298,7 +1298,7 @@ void Viewport::paintMeasure(QPainter &p, QColor fore, QColor back)
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().cur_samplerate();
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const int64_t x = (_dso_ym_index / (sample_rate * _view.scale())) -
_view.offset();
p.drawLine(x-10, _dso_ym_start,
......@@ -1344,7 +1344,7 @@ void Viewport::paintMeasure(QPainter &p, QColor fore, QColor back)
int measure_line_count = 6;
const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, "W").height();