From c822774f29498573efad388ff6b806e3f59c460c Mon Sep 17 00:00:00 2001 From: alexrayne Date: Mon, 3 Oct 2022 00:40:39 +0300 Subject: [PATCH] Timeline: fix low zoom limit for huge simultion tmes - prevent crashes and blank screen enhance max zoom levels to 1sec/pixel, for event activity on secnds scale * if suimulation time to huge on current zoom level, try adjust to higher zoom, keeping timeline still functional. --- .../org/contikios/cooja/plugins/TimeLine.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/java/org/contikios/cooja/plugins/TimeLine.java b/java/org/contikios/cooja/plugins/TimeLine.java index 747f42211b..b57caef7b5 100644 --- a/java/org/contikios/cooja/plugins/TimeLine.java +++ b/java/org/contikios/cooja/plugins/TimeLine.java @@ -124,7 +124,9 @@ public class TimeLine extends VisPlugin implements HasQuickHelp { private static final long[] ZOOM_LEVELS = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, - 2000, 5000, 10000, 20000, 50000, 100000 }; + 2000, 5000, 10000, 20000, 50000, 100000, + 100000*2, 100000*5, 100000*10 + }; private boolean needZoomOut = false; @@ -589,11 +591,21 @@ private static double zoomLevelToDivisor(int zoomLevel) { return ZOOM_LEVELS[zoomLevel]; } - private void zoomFinish (final double zoomDivisor, + private void zoomFinish (double zoomDivisor, final long focusTime, - final double focusCenter) { - currentPixelDivisor = zoomDivisor; + final double focusCenter) + { String note = ""; + + long now = simulation.getSimulationTime(); + if (now/zoomDivisor > Integer.MAX_VALUE) { + // limit zoom to fits sim-time in timeline + int min_level = zoomGetLevel( now/Integer.MAX_VALUE ); + zoomDivisor = zoomLevelToDivisor( min_level ); + note = " (LIM)"; + } + + currentPixelDivisor = zoomDivisor; if (ZOOM_LEVELS[0] >= zoomDivisor) { currentPixelDivisor = ZOOM_LEVELS[0]; note = " (MIN)"; @@ -604,6 +616,8 @@ private void zoomFinish (final double zoomDivisor, if (zoomDivisor != currentPixelDivisor) { logger.info("Zoom level: adjusted out-of-range " + zoomDivisor + " us/pixel"); } + + if (note != "") logger.info("Zoom level: " + currentPixelDivisor + " microseconds/pixel " + note); forceRepaintAndFocus(focusTime, focusCenter); @@ -2550,9 +2564,14 @@ public void actionPerformed(ActionEvent e) { /* Update timeline size */ int newWidth; if (now/currentPixelDivisor > Integer.MAX_VALUE) { - /* Need zoom out */ - newWidth = 1; - needZoomOut = true; + // if zoom not fits in timeline, try zoomout to apropriate level + int level = zoomGetLevel( now/Integer.MAX_VALUE ); + zoomFinishLevel(level, getCenterPointTime(), 0.5); + } + if (now/currentPixelDivisor > Integer.MAX_VALUE) { + /* Need zoom out */ + newWidth = 1; + needZoomOut = true; } else { newWidth = (int) (now/currentPixelDivisor); needZoomOut = false;