From b614a67f2dcd8d766614c24404a44640d92b4ab3 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Mon, 20 Sep 2021 11:15:04 +0200 Subject: [PATCH] Improve selection-area of transactions. The selection-area is no longer incorrectly double the vertical size of the transaction and it is now possible to select very narrow transactions even when zoomed out of the plot. --- .../businessObjects/phases/phase.cpp | 17 +++++++---------- .../businessObjects/phases/phase.h | 3 +-- .../traceAnalyzer/businessObjects/timespan.cpp | 5 +++++ .../traceAnalyzer/businessObjects/timespan.h | 1 + .../businessObjects/transaction.cpp | 13 +++++-------- .../traceAnalyzer/businessObjects/transaction.h | 3 +-- .../traceAnalyzer/presentation/traceplot.cpp | 13 ++++++++----- .../presentation/traceplotitem.cpp | 8 ++++---- .../traceAnalyzer/presentation/traceplotitem.h | 4 +--- 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp index c99e1788..4f89bf0f 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp @@ -137,22 +137,18 @@ Qt::BrushStyle Phase::getBrushStyle() const return Qt::SolidPattern; } -bool Phase::isSelected(traceTime time, double yVal, - const TraceDrawingProperties &drawingProperties) const +bool Phase::isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingProperties) const { - // Increase selectable area of phases with zero span - traceTime offset = (span.Begin() == span.End()) ? static_cast(0.05 * clk) : 0; - - if (span.Begin() <= time && time <= (span.End() + offset)) + if (span.overlaps(timespan)) { for (auto line : getTracePlotLines(drawingProperties)) { - if (!line->isCollapsed() && fabs(yVal - line->getYVal()) <= hexagonHeight) + if (!line->isCollapsed() && fabs(yVal - line->getYVal()) <= hexagonHeight / 2) return true; } } - if (spanOnDataBus && spanOnDataBus->contains(time)) + if (spanOnDataBus && spanOnDataBus->overlaps(timespan)) { for (auto dataBusLine : drawingProperties.getDataBusLines()) { @@ -161,8 +157,9 @@ bool Phase::isSelected(traceTime time, double yVal, } } - for (Timespan span : spansOnCommandBus) { - if (span.contains(time)) + for (const Timespan &span : spansOnCommandBus) + { + if (span.overlaps(timespan)) { for (auto commandBusLine : drawingProperties.getCommandBusLines()) { diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.h b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.h index 822fec5d..df6185aa 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.h +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.h @@ -64,8 +64,7 @@ public: void draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, bool highlight, const TraceDrawingProperties &drawingProperties) const; - bool isSelected(traceTime time, double yVal, - const TraceDrawingProperties &drawingproperties) const; + bool isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingproperties) const; const Timespan &Span() const { return span; diff --git a/DRAMSys/traceAnalyzer/businessObjects/timespan.cpp b/DRAMSys/traceAnalyzer/businessObjects/timespan.cpp index 0b964a78..7a0e4b8d 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/timespan.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/timespan.cpp @@ -42,6 +42,11 @@ bool Timespan::contains(traceTime time) const return (begin <= time && time <= end); } +bool Timespan::overlaps(const Timespan &other) const +{ + return other.Begin() < this->end && this->begin < other.End(); +} + void Timespan::shift(traceTime offset) { begin += offset; diff --git a/DRAMSys/traceAnalyzer/businessObjects/timespan.h b/DRAMSys/traceAnalyzer/businessObjects/timespan.h index 0b4dd72f..4dfb4974 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/timespan.h +++ b/DRAMSys/traceAnalyzer/businessObjects/timespan.h @@ -73,6 +73,7 @@ public: end = time; } bool contains(traceTime time) const; + bool overlaps(const Timespan &other) const; void shift(traceTime offset); }; diff --git a/DRAMSys/traceAnalyzer/businessObjects/transaction.cpp b/DRAMSys/traceAnalyzer/businessObjects/transaction.cpp index 2a87e94b..87a46f99 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/transaction.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/transaction.cpp @@ -60,16 +60,13 @@ void Transaction::draw(QPainter *painter, const QwtScaleMap &xMap, phase->draw(painter, xMap, yMap, canvasRect, highlight, drawingProperties); } -bool Transaction::isSelected(traceTime time, double yVal, - const TraceDrawingProperties &drawingproperties) const +bool Transaction::isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingproperties) const { - // Increase selectable area of transactions for phases with zero span - traceTime offset = static_cast(0.05 * clk); - - if (span.Begin() <= time && time <= (span.End() + offset)) + if (span.overlaps(timespan)) { - for (shared_ptr phase : phases) { - if (phase->isSelected(time, yVal, drawingproperties)) + for (shared_ptr phase : phases) + { + if (phase->isSelected(timespan, yVal, drawingproperties)) return true; } } diff --git a/DRAMSys/traceAnalyzer/businessObjects/transaction.h b/DRAMSys/traceAnalyzer/businessObjects/transaction.h index 84f5f89a..ef489083 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/transaction.h +++ b/DRAMSys/traceAnalyzer/businessObjects/transaction.h @@ -68,8 +68,7 @@ public: const TraceDrawingProperties &drawingProperties) const; void addPhase(std::shared_ptr phase); - bool isSelected(traceTime time, double yVal, - const TraceDrawingProperties &drawingproperties) const; + bool isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingproperties) const; const std::vector> &Phases() const { diff --git a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp index c7bde09a..ac3c18cc 100644 --- a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp +++ b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp @@ -723,12 +723,15 @@ bool TracePlot::eventFilter(QObject *object, QEvent *event) void TracePlot::SelectTransaction(int x, int y) const { double yVal = invTransform(yLeft, y); - traceTime time = invTransform(xBottom, x); - vector> selectedTransactions = - tracePlotItem->getSelectedTransactions(time, yVal); - if (selectedTransactions.size() > 0) { + Timespan timespan = hoveredTimespan(x); + + auto selectedTransactions = tracePlotItem->getSelectedTransactions(timespan, yVal); + + if (selectedTransactions.size() > 0) + { if (!keyPressData.ctrlPressed) navigator->clearSelectedTransactions(); + navigator->addSelectedTransactions(selectedTransactions); } } @@ -750,7 +753,7 @@ void TracePlot::SelectComment(int x) const Timespan TracePlot::hoveredTimespan(int x) const { traceTime time = invTransform(xBottom, x); - traceTime offset = 0.01 * zoomLevel; + traceTime offset = 0.005 * zoomLevel; return Timespan(time - offset, time + offset); } diff --git a/DRAMSys/traceAnalyzer/presentation/traceplotitem.cpp b/DRAMSys/traceAnalyzer/presentation/traceplotitem.cpp index 0782ff99..32200f0f 100644 --- a/DRAMSys/traceAnalyzer/presentation/traceplotitem.cpp +++ b/DRAMSys/traceAnalyzer/presentation/traceplotitem.cpp @@ -60,13 +60,13 @@ void TracePlotItem::draw(QPainter *painter, const QwtScaleMap &xMap, } } -vector> TracePlotItem::getSelectedTransactions( - traceTime time, double yVal) +vector> TracePlotItem::getSelectedTransactions(Timespan timespan, double yVal) { vector> result; - for (const auto &transaction : transactions) { - if (transaction->isSelected(time, yVal, drawingProperties)) + for (const auto &transaction : transactions) + { + if (transaction->isSelected(timespan, yVal, drawingProperties)) result.push_back(transaction); } diff --git a/DRAMSys/traceAnalyzer/presentation/traceplotitem.h b/DRAMSys/traceAnalyzer/presentation/traceplotitem.h index 675cec50..122d518f 100644 --- a/DRAMSys/traceAnalyzer/presentation/traceplotitem.h +++ b/DRAMSys/traceAnalyzer/presentation/traceplotitem.h @@ -65,9 +65,7 @@ public: virtual int rtti() const; virtual void draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const; - std::vector> getSelectedTransactions( - traceTime time, double yVal); - + std::vector> getSelectedTransactions(Timespan timespan, double yVal); }; #endif // TRACEPLOTITEM_H