forked from Ivasoft/DSView
fix: unable to click the last edge to measure distance
This commit is contained in:
@@ -338,6 +338,59 @@ bool LogicSignal::measure(const QPointF &p, uint64_t &index0, uint64_t &index1,
|
|||||||
return false;
|
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)
|
bool LogicSignal::edge(const QPointF &p, uint64_t &index, int radius)
|
||||||
{
|
{
|
||||||
uint64_t pre_index, nxt_index;
|
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 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 edge(const QPointF &p, uint64_t &index, int radius);
|
||||||
|
|
||||||
bool edges(const QPointF &p, uint64_t start, uint64_t &rising, uint64_t &falling);
|
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) {
|
for(auto s : sigs) {
|
||||||
if (s->signal_type() == SR_CHANNEL_LOGIC) {
|
if (s->signal_type() == SR_CHANNEL_LOGIC) {
|
||||||
view::LogicSignal *logicSig = (view::LogicSignal*)s;
|
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;
|
_action_type = LOGIC_JUMP;
|
||||||
_cur_preX = _view.index2pixel(_edge_start);
|
_cur_preX = _view.index2pixel(_edge_start);
|
||||||
_cur_preY = logicSig->get_y();
|
_cur_preY = logicSig->get_y();
|
||||||
@@ -1488,7 +1488,7 @@ void Viewport::measure()
|
|||||||
{
|
{
|
||||||
if (_view.session().is_data_lock())
|
if (_view.session().is_data_lock())
|
||||||
return;
|
return;
|
||||||
if (_view.session().is_loop_mode()&& _view.session().is_working())
|
if (_view.session().is_loop_mode() && _view.session().is_working())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_measure_type = NO_MEASURE;
|
_measure_type = NO_MEASURE;
|
||||||
|
|||||||
Reference in New Issue
Block a user