mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-13 13:32:53 +08:00
fix: unable to click the last edge to measure distance
This commit is contained in:
parent
5f38c7b462
commit
35ccb21ae6
@ -338,6 +338,59 @@ bool LogicSignal::measure(const QPointF &p, uint64_t &index0, uint64_t &index1,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LogicSignal::is_by_edge(const QPointF &p, uint64_t &index, int radius)
|
||||
{
|
||||
uint64_t pre_index, nxt_index;
|
||||
const float gap = abs(p.y() - get_y());
|
||||
|
||||
if (gap < get_totalHeight() * 0.5) {
|
||||
if (_data->empty() || !_data->has_data(_probe->index))
|
||||
return false;
|
||||
|
||||
const uint64_t end = _data->get_sample_count() - 1;
|
||||
const double pos = _data->samplerate() * _view->scale() * (_view->offset() + p.x());
|
||||
index = floor(pos + 0.5);
|
||||
if (index > end)
|
||||
return false;
|
||||
|
||||
bool sample = _data->get_sample(index, get_index());
|
||||
if (index == 0)
|
||||
pre_index = index;
|
||||
else {
|
||||
index--;
|
||||
if (_data->get_pre_edge(index, sample, 1, get_index()))
|
||||
pre_index = index;
|
||||
else
|
||||
pre_index = 0;
|
||||
}
|
||||
|
||||
sample = _data->get_sample(index, get_index());
|
||||
index++;
|
||||
if (_data->get_nxt_edge(index, sample, end, 1, get_index()))
|
||||
nxt_index = index;
|
||||
else
|
||||
nxt_index = 0;
|
||||
|
||||
if (pre_index == 0 && nxt_index == 0)
|
||||
return false;
|
||||
|
||||
if (pre_index > 0 && nxt_index > 0)
|
||||
{
|
||||
if (pos - pre_index > nxt_index - pos)
|
||||
index = nxt_index;
|
||||
else
|
||||
index = pre_index;
|
||||
}
|
||||
else{
|
||||
index = pre_index > 0 ? pre_index : nxt_index;
|
||||
}
|
||||
|
||||
if (radius > abs((index-pos) / _view->scale() / _data->samplerate()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LogicSignal::edge(const QPointF &p, uint64_t &index, int radius)
|
||||
{
|
||||
uint64_t pre_index, nxt_index;
|
||||
|
@ -95,6 +95,8 @@ public:
|
||||
|
||||
bool measure(const QPointF &p, uint64_t &index0, uint64_t &index1, uint64_t &index2);
|
||||
|
||||
bool is_by_edge(const QPointF &p, uint64_t &index, int radius);
|
||||
|
||||
bool edge(const QPointF &p, uint64_t &index, int radius);
|
||||
|
||||
bool edges(const QPointF &p, uint64_t start, uint64_t &rising, uint64_t &falling);
|
||||
|
@ -971,7 +971,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
|
||||
for(auto s : sigs) {
|
||||
if (s->signal_type() == SR_CHANNEL_LOGIC) {
|
||||
view::LogicSignal *logicSig = (view::LogicSignal*)s;
|
||||
if (logicSig->edge(event->pos(), _edge_start, 10)) {
|
||||
if (logicSig->is_by_edge(event->pos(), _edge_start, 10)) {
|
||||
_action_type = LOGIC_JUMP;
|
||||
_cur_preX = _view.index2pixel(_edge_start);
|
||||
_cur_preY = logicSig->get_y();
|
||||
@ -1488,7 +1488,7 @@ void Viewport::measure()
|
||||
{
|
||||
if (_view.session().is_data_lock())
|
||||
return;
|
||||
if (_view.session().is_loop_mode()&& _view.session().is_working())
|
||||
if (_view.session().is_loop_mode() && _view.session().is_working())
|
||||
return;
|
||||
|
||||
_measure_type = NO_MEASURE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user