diff --git a/com.minres.scviewer.database.sqlite/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.database.sqlite/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/com.minres.scviewer.database.sqlite/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/com.minres.scviewer.database.test/.classpath b/com.minres.scviewer.database.test/.classpath index 43b9862..cc5ee2d 100644 --- a/com.minres.scviewer.database.test/.classpath +++ b/com.minres.scviewer.database.test/.classpath @@ -2,6 +2,10 @@ - + + + + + diff --git a/com.minres.scviewer.database.test/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.database.test/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index e84a201..0000000 --- a/com.minres.scviewer.database.test/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/com/minres/scviewer/database/test/DatabaseServicesTest.java=UTF-8 -encoding/=UTF-8 diff --git a/com.minres.scviewer.database.text/.classpath b/com.minres.scviewer.database.text/.classpath index fbe692e..289f0a4 100644 --- a/com.minres.scviewer.database.text/.classpath +++ b/com.minres.scviewer.database.text/.classpath @@ -1,19 +1,22 @@ - - - - - - + + + + + + - - - - + + + + + + + diff --git a/com.minres.scviewer.database.text/.settings/org.eclipse.jdt.core.prefs b/com.minres.scviewer.database.text/.settings/org.eclipse.jdt.core.prefs index 6e80039..4e4a3ad 100644 --- a/com.minres.scviewer.database.text/.settings/org.eclipse.jdt.core.prefs +++ b/com.minres.scviewer.database.text/.settings/org.eclipse.jdt.core.prefs @@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy b/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy index 9d9c1cd..c915e0e 100644 --- a/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy +++ b/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.groovy @@ -84,7 +84,11 @@ public class TextDbLoader implements IWaveformDbLoader{ calculateConcurrencyIndicees() return true } - } catch(Exception e) { } + } catch(EOFException e) { + return true; + } catch(Exception e) { + e.printStackTrace() + } return false; } diff --git a/com.minres.scviewer.database.ui.swt/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.database.ui.swt/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/com.minres.scviewer.database.ui.swt/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF b/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF index 26854e4..7ee26fb 100644 --- a/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SWT widget Bundle-SymbolicName: com.minres.scviewer.database.ui.swt -Bundle-Version: 2.0.0.qualifier +Bundle-Version: 2.0.2.qualifier Bundle-Vendor: MINRES Technologies GmbH Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.swt;bundle-version="3.103.1", diff --git a/com.minres.scviewer.database.ui.swt/pom.xml b/com.minres.scviewer.database.ui.swt/pom.xml index 8079c8c..3c274f8 100644 --- a/com.minres.scviewer.database.ui.swt/pom.xml +++ b/com.minres.scviewer.database.ui.swt/pom.xml @@ -8,4 +8,5 @@ 2.0.0-SNAPSHOT ../com.minres.scviewer.parent + 2.0.2-SNAPSHOT \ No newline at end of file diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java index 4834914..04dcbca 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ArrowPainter.java @@ -46,6 +46,8 @@ public class ArrowPainter implements IPainter { private RelationType highlightType; + private long selectionOffset; + long scaleFactor; boolean deferredUpdate; @@ -87,8 +89,9 @@ public class ArrowPainter implements IPainter { deferredUpdate = true; return; } + selectionOffset = waveCanvas.getXOffset(); int laneHeight = painter.getHeight() / stream.getMaxConcurrency(); - txRectangle = new Rectangle((int) (tx.getBeginTime() / scaleFactor), + txRectangle = new Rectangle((int) (tx.getBeginTime() / scaleFactor-waveCanvas.getXOffset()), waveCanvas.rulerHeight + painter.getVerticalOffset() + laneHeight * tx.getConcurrencyIndex(), (int) ((tx.getEndTime() - tx.getBeginTime()) / scaleFactor), laneHeight); deriveGeom(tx.getIncomingRelations(), iRect, false); @@ -102,7 +105,7 @@ public class ArrowPainter implements IPainter { ITxStream stream = otherTx.getStream(); IWaveformPainter painter = waveCanvas.wave2painterMap.get(stream); int laneHeight = painter.getHeight() / stream.getMaxConcurrency(); - Rectangle bb = new Rectangle((int) (otherTx.getBeginTime() / scaleFactor), + Rectangle bb = new Rectangle((int) (otherTx.getBeginTime() / scaleFactor-waveCanvas.getXOffset()), waveCanvas.rulerHeight + painter.getVerticalOffset() + laneHeight * otherTx.getConcurrencyIndex(), (int) ((otherTx.getEndTime() - otherTx.getBeginTime()) / scaleFactor), laneHeight); @@ -120,14 +123,19 @@ public class ArrowPainter implements IPainter { scaleFactor = waveCanvas.getScaleFactor(); calculateGeometries(); } + if(txRectangle == null) return; + int correctionValue = (int)(selectionOffset - waveCanvas.getXOffset()); + Rectangle correctedTargetRectangle = new Rectangle(txRectangle.x+correctionValue, txRectangle.y, txRectangle.width, txRectangle.height); for (LinkEntry entry : iRect) { + Rectangle correctedRectangle = new Rectangle(entry.rectangle.x+correctionValue, entry.rectangle.y, entry.rectangle.width, entry.rectangle.height); Point target = drawPath(gc, highlightType.equals(entry.relationType) ? highliteColor : fgColor, - entry.rectangle, txRectangle); + correctedRectangle, correctedTargetRectangle); drawArrow(gc, target); } for (LinkEntry entry : oRect) { - Point target = drawPath(gc, highlightType.equals(entry.relationType) ? highliteColor : fgColor, txRectangle, - entry.rectangle); + Rectangle correctedRectangle = new Rectangle(entry.rectangle.x+correctionValue, entry.rectangle.y, entry.rectangle.width, entry.rectangle.height); + Point target = drawPath(gc, highlightType.equals(entry.relationType) ? highliteColor : fgColor, correctedTargetRectangle, + correctedRectangle); drawArrow(gc, target); } } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java index ac0e528..a23e8c2 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/CursorPainter.java @@ -30,6 +30,11 @@ public class CursorPainter implements IPainter, ICursor { public final int id; + /// maximum visible canvas position in canvas coordinates + int maxPosX; + /// maximum visible position in waveform coordinates + int maxValX; + /** * @param i * @param txDisplay @@ -56,23 +61,32 @@ public class CursorPainter implements IPainter, ICursor { this.isDragging = isDragging; } + public void paintArea(GC gc, Rectangle area) { if(this.waveCanvas.painterList.size()>0){ + long scaleFactor=waveCanvas.getScaleFactor(); + long beginPos = area.x; + + maxPosX = area.x + area.width; + maxValX = maxPosX + (int)waveCanvas.getXOffset(); + + // x position of marker in pixels on canvas int x = (int) (time/scaleFactor); + // distance of marker from the top of Canvas' painting area int top = id<0?area.y:area.y+15; + Color drawColor=waveCanvas.colors[id<0?WaveformColors.CURSOR.ordinal():WaveformColors.MARKER.ordinal()]; Color dragColor = waveCanvas.colors[WaveformColors.CURSOR_DRAG.ordinal()]; Color textColor=waveCanvas.colors[id<0?WaveformColors.CURSOR_TEXT.ordinal():WaveformColors.MARKER_TEXT.ordinal()]; - if(x>=area.x && x<=(area.x+area.width)){ + if(x>=beginPos && x<=maxValX){ gc.setForeground(isDragging?dragColor:drawColor); - gc.drawLine(x, top, x, area.y+area.height); + gc.drawLine(x-(int)waveCanvas.getXOffset(), top, x-(int)waveCanvas.getXOffset(), area.y+area.height); gc.setBackground(drawColor); gc.setForeground(textColor); Double dTime=new Double(time); - gc.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top); + gc.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1-(int)waveCanvas.getXOffset(), top); } } - } - + } } \ No newline at end of file diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java index b629632..96cee3b 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java @@ -32,6 +32,7 @@ public class RulerPainter implements IPainter { @Override public void paintArea(GC gc, Rectangle area) { + Color headerFgColor=waveCanvas.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND); if(headerFgColor.isDisposed()) headerFgColor=SWTResourceManager.getColor(0,0,0); @@ -41,9 +42,11 @@ public class RulerPainter implements IPainter { String unit=waveCanvas.getUnitStr(); int unitMultiplier=waveCanvas.getUnitMultiplier(); long scaleFactor=waveCanvas.getScaleFactor(); -// long zoomLevel = waveCanvas.getZoomLevel(); - long start=area.x*scaleFactor; - long end=start+area.width*scaleFactor; + + long startPos=area.x*scaleFactor; + long startVal=startPos + waveCanvas.getXOffset()*scaleFactor; + long endPos=startPos+area.width*scaleFactor; + long endVal=startVal+area.width*scaleFactor; long rulerTickMinor = rulerTickMinorC*scaleFactor; long rulerTickMajor = rulerTickMajorC*scaleFactor; @@ -54,9 +57,9 @@ public class RulerPainter implements IPainter { int baselineY=waveCanvas.rulerHeight - 1; int bottom=waveCanvas.rulerHeight - 2; - long startMinorIncr = start; - long modulo = start % rulerTickMinor; - startMinorIncr+=rulerTickMinor-modulo; + long modulo = startVal % rulerTickMinor; + long startMinorIncrPos = startPos+rulerTickMinor-modulo; + long startMinorIncrVal = startVal+rulerTickMinor-modulo; gc.setBackground(waveCanvas.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); gc.fillRectangle(new Rectangle(area.x, area.y, area.width, waveCanvas.rulerHeight)); @@ -65,15 +68,18 @@ public class RulerPainter implements IPainter { gc.setForeground(headerFgColor); gc.drawLine(area.x, area.y+bottom, area.x+area.width, area.y+bottom); - for (long tick = startMinorIncr; tick < end; tick += rulerTickMinor) { - int x0 = (int) (tick/scaleFactor); + int x0_max = 0; + + for (long pos = startMinorIncrPos, tick = startMinorIncrVal; pos < endPos; pos+= rulerTickMinor, tick += rulerTickMinor) { + int x0_pos = (int) (pos/scaleFactor); + long x0_val = tick/scaleFactor; + x0_max = x0_pos; if ((tick % rulerTickMajor) == 0) { - gc.drawText(df.format(tick/scaleFactor*unitMultiplier)+unit, x0, area.y+textY); - gc.drawLine(x0, area.y+majorTickY, x0,area.y+ bottom); + gc.drawText(df.format(x0_val*unitMultiplier)+unit, x0_pos, area.y+textY); + gc.drawLine(x0_pos, area.y+majorTickY, x0_pos,area.y+ bottom); } else { - gc.drawLine(x0, area.y+minorTickY, x0, area.y+bottom); + gc.drawLine(x0_pos, area.y+minorTickY, x0_pos, area.y+bottom); } } - } } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java index d39ed81..a011541 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/SignalPainter.java @@ -68,18 +68,26 @@ public class SignalPainter extends TrackPainter { int yOffsetT; int yOffsetM; int yOffsetB; - int maxX; + /// maximum visible canvas position in canvas coordinates + int maxPosX; + /// maximum visible position in waveform coordinates + int maxValX; public SignalPainter(WaveformCanvas txDisplay, boolean even, TrackEntry trackEntry) { super(trackEntry, even); this.waveCanvas = txDisplay; } - private int getXEnd(long time) { + private int getXValEnd(long time) { long ltmp = time / this.waveCanvas.getScaleFactor(); - return ltmp > maxX ? maxX : (int) ltmp; + return ltmp > maxValX ? maxValX : (int) ltmp; } + private int getXPosEnd(long time) { + long ltmp = time / this.waveCanvas.getScaleFactor() - waveCanvas.getXOffset(); + return ltmp > maxPosX ? maxPosX : (int) ltmp; + } + public void paintArea(GC gc, Rectangle area) { ISignal signal = trackEntry.getSignal(); if (trackEntry.selected) @@ -88,8 +96,13 @@ public class SignalPainter extends TrackPainter { gc.setBackground(this.waveCanvas.colors[even ? WaveformColors.TRACK_BG_EVEN.ordinal() : WaveformColors.TRACK_BG_ODD.ordinal()]); gc.setFillRule(SWT.FILL_EVEN_ODD); gc.fillRectangle(area); - long beginTime = area.x * this.waveCanvas.getScaleFactor(); - long endTime = (area.x + area.width) * this.waveCanvas.getScaleFactor(); + + long scaleFactor = this.waveCanvas.getScaleFactor(); + long beginPos = area.x; + long beginTime = (beginPos + waveCanvas.getXOffset())*scaleFactor; + long endPos = beginPos + area.width; + long endTime = beginTime + area.width*scaleFactor; + Entry first = signal.getEvents().floorEntry(beginTime); Entry last = signal.getEvents().floorEntry(endTime); if (first == null) { @@ -105,14 +118,18 @@ public class SignalPainter extends TrackPainter { NavigableMap entries = signal.getEvents().subMap(first.getKey(), false, last.getKey(), true); SignalChange left = new SignalChange(first); SignalChange right = new SignalChange(entries.size() > 0 ? entries.firstEntry() : first); - maxX = area.x + area.width; + maxPosX = area.x + area.width; + maxValX = maxPosX + (int)waveCanvas.getXOffset(); yOffsetT = this.waveCanvas.getTrackHeight() / 5 + area.y; yOffsetM = this.waveCanvas.getTrackHeight() / 2 + area.y; yOffsetB = 4 * this.waveCanvas.getTrackHeight() / 5 + area.y; - int xBegin = Math.max(area.x, (int) (left.time / this.waveCanvas.getScaleFactor())); - int xEnd = Math.max(area.x, getXEnd(right.time)); + int xSigChangeBeginVal = Math.max(area.x + (int)waveCanvas.getXOffset(), (int) (left.time / this.waveCanvas.getScaleFactor())); + int xSigChangeBeginPos = area.x; + int xSigChangeEndVal = Math.max(area.x + (int)waveCanvas.getXOffset(), getXValEnd(right.time)); + int xSigChangeEndPos = Math.max(area.x, getXPosEnd(right.time)); + boolean multiple = false; - if (xEnd == xBegin) { + if (xSigChangeEndPos == xSigChangeBeginPos) { // this can trigger if // a) left == right // b) left to close to right @@ -120,30 +137,31 @@ public class SignalPainter extends TrackPainter { right.time = endTime; } else { multiple = true; - long eTime = (xBegin + 1) * this.waveCanvas.getScaleFactor(); + long eTime = (xSigChangeBeginVal + 1) * this.waveCanvas.getScaleFactor(); right.set(entries.floorEntry(eTime), endTime); right.time = eTime; } - xEnd = getXEnd(right.time); + xSigChangeEndPos = getXPosEnd(right.time); } + SignalStencil stencil = getStencil(gc, left, entries); do { - stencil.draw(gc, area, left.value, right.value, xBegin, xEnd, multiple); + stencil.draw(gc, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple); if (right.time >= endTime) break; left.assign(right); - xBegin = xEnd; + xSigChangeBeginPos = xSigChangeEndPos; right.set(entries.higherEntry(left.time), endTime); - xEnd = getXEnd(right.time); + xSigChangeEndPos = getXPosEnd(right.time); multiple = false; - if (xEnd == xBegin) { + if (xSigChangeEndPos == xSigChangeBeginPos) { multiple = true; - long eTime = (xBegin + 1) * this.waveCanvas.getScaleFactor(); + long eTime = (xSigChangeBeginPos + 1) * this.waveCanvas.getScaleFactor(); Entry entry = entries.floorEntry(eTime); if(entry!=null && entry.getKey()> right.time) right.set(entry, endTime); - xEnd = getXEnd(eTime); + xSigChangeEndPos = getXPosEnd(eTime); } } while (left.time < endTime); } @@ -273,14 +291,14 @@ public class SignalPainter extends TrackPainter { int yOffsetLeft = (int) ((leftVal-minVal) / range * (yOffsetB-yOffsetT)); int yOffsetRight = (int) ((rightVal-minVal) / range * (yOffsetB-yOffsetT)); if(continous) { - if (xEnd > maxX) { - gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxX, yOffsetB-yOffsetRight); + if (xEnd > maxPosX) { + gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetRight); } else { gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight); } } else { - if (xEnd > maxX) { - gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxX, yOffsetB-yOffsetLeft); + if (xEnd > maxPosX) { + gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetLeft); } else { gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetLeft); if(yOffsetRight!=yOffsetLeft) { @@ -316,8 +334,8 @@ public class SignalPainter extends TrackPainter { default: } gc.setForeground(color); - if (xEnd > maxX) { - gc.drawLine(xBegin, yOffset, maxX, yOffset); + if (xEnd > maxPosX) { + gc.drawLine(xBegin, yOffset, maxPosX, yOffset); } else { gc.drawLine(xBegin, yOffset, xEnd, yOffset); int yNext = yOffsetM; @@ -398,14 +416,14 @@ public class SignalPainter extends TrackPainter { int yOffsetLeft = (int) ((leftVal-minVal) / range * (yOffsetB-yOffsetT)); int yOffsetRight = Double.isNaN(rightVal)?yOffsetLeft:(int) ((rightVal-minVal) / range * (yOffsetB-yOffsetT)); if(continous) { - if (xEnd > maxX) { - gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxX, yOffsetB-yOffsetRight); + if (xEnd > maxPosX) { + gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetRight); } else { gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight); } } else { - if (xEnd > maxX) { - gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxX, yOffsetB-yOffsetLeft); + if (xEnd > maxPosX) { + gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetLeft); } else { gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetLeft); if(yOffsetRight!=yOffsetLeft) { diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/StreamPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/StreamPainter.java index 81f8faf..cad44fd 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/StreamPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/StreamPainter.java @@ -44,6 +44,20 @@ public class StreamPainter extends TrackPainter{ this.stream=trackEntry.getStream(); this.seenTx=new TreeSet(); } + + /* + * convert java.awt.Color to org.eclipse.swt.graphics.Color + */ + static org.eclipse.swt.graphics.Color toSwtColor( GC gc, java.awt.Color awtColor ){ + return new org.eclipse.swt.graphics.Color( gc.getDevice(), awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue() ); + } + + static org.eclipse.swt.graphics.Color[] toSwtColors( GC gc, java.awt.Color[] awtColors ){ + org.eclipse.swt.graphics.Color[] swtColors = new org.eclipse.swt.graphics.Color[awtColors.length]; + for( int i=0; i firstTx=stream.getEvents().floorEntry(area.x*waveCanvas.getScaleFactor()); - Entry lastTx=stream.getEvents().ceilingEntry((area.x+area.width)*waveCanvas.getScaleFactor()); + + long scaleFactor = this.waveCanvas.getScaleFactor(); + long beginPos = area.x; + long beginTime = (beginPos + waveCanvas.getXOffset())*scaleFactor; + //long endPos = beginPos + area.width; + long endTime = beginTime + area.width*scaleFactor; + + Entry firstTx=stream.getEvents().floorEntry(beginTime); + Entry lastTx=stream.getEvents().ceilingEntry(endTime); if(firstTx==null) firstTx = stream.getEvents().firstEntry(); if(lastTx==null) lastTx=stream.getEvents().lastEntry(); gc.setFillRule(SWT.FILL_EVEN_ODD); gc.setLineStyle(SWT.LINE_SOLID); gc.setLineWidth(1); gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); - for(int y1=area.y+trackHeight/2; y1)firstTx.getValue()) - drawTx(gc, area, txEvent.getTransaction()); - else{ + drawTx(gc, area, txEvent.getTransaction(), false); + }else{ seenTx.clear(); NavigableMap entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true); boolean highlighed=false; gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); - gc.setBackground(this.waveCanvas.colors[WaveformColors.TX_BG.ordinal()]); - for(Entry entry: entries.entrySet()) + + for(Entry entry: entries.entrySet()) for(ITxEvent txEvent:(Collection)entry.getValue()){ if(txEvent.getType()==ITxEvent.Type.BEGIN) seenTx.add(txEvent.getTransaction()); if(txEvent.getType()==ITxEvent.Type.END){ ITx tx = txEvent.getTransaction(); highlighed|=waveCanvas.currentSelection!=null && waveCanvas.currentSelection.equals(tx); - drawTx(gc, area, tx); + drawTx(gc, area, tx, false); seenTx.remove(tx); } } for(ITx tx:seenTx){ - drawTx(gc, area, tx); + drawTx(gc, area, tx, false); } if(highlighed){ gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE_HIGHLITE.ordinal()]); - gc.setBackground(this.waveCanvas.colors[WaveformColors.TX_BG_HIGHLITE.ordinal()]); - drawTx(gc, area, waveCanvas.currentSelection); + drawTx(gc, area, waveCanvas.currentSelection, true); } } } - - protected void drawTx(GC gc, Rectangle area, ITx tx) { + + protected void drawTx(GC gc, Rectangle area, ITx tx, boolean highlighted ) { + // compute colors + java.awt.Color[] fallbackColors = trackEntry.getColors(); + java.awt.Color[] transColor = TrackEntry.computeColor( tx.getGenerator().getName(), fallbackColors[0], fallbackColors[1] ); + + gc.setBackground( toSwtColor( gc, transColor[highlighted?1:0] ) ); + int offset = tx.getConcurrencyIndex()*this.waveCanvas.getTrackHeight(); Rectangle bb = new Rectangle( - (int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+txBase, + (int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()-waveCanvas.getXOffset()), area.y+offset+txBase, (int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight); + if(bb.x+bb.widtharea.x+area.width) return; if(bb.width==0){ gc.drawLine(bb.x, bb.y, bb.x, bb.y+bb.height); @@ -110,7 +139,6 @@ public class StreamPainter extends TrackPainter{ gc.fillRectangle(bb); gc.drawRectangle(bb); } else { - // adjusting drawing width to circumvent issues in canvas algos if(bb.x < area.x) { bb.width = bb.width-(area.x-bb.x)+5; bb.x=area.x-5; @@ -121,7 +149,7 @@ public class StreamPainter extends TrackPainter{ bb_x2=area_x2+5; bb.width= bb_x2-bb.x; } - gc.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5); + gc.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5); gc.drawRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5); } } diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java index 0ee05df..0da478c 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java @@ -45,7 +45,7 @@ import com.minres.scviewer.database.ui.IWaveformViewer; import com.minres.scviewer.database.ui.TrackEntry; import com.minres.scviewer.database.ui.WaveformColors; -public class WaveformCanvas extends Canvas { +public class WaveformCanvas extends Canvas{ Color[] colors = new Color[WaveformColors.values().length]; @@ -84,13 +84,13 @@ public class WaveformCanvas extends Canvas { * Constructor for ScrollableCanvas. * * @param parent - * the parent of this control. + * the parent of this control.super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); * @param style * the style of this control. */ public WaveformCanvas(final Composite parent, int style) { super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); - addControlListener(new ControlAdapter() { /* resize listener. */ + addControlListener(new ControlAdapter() { /* resize listener. */ public void controlResized(ControlEvent event) { syncScrollBars(); } @@ -149,7 +149,11 @@ public class WaveformCanvas extends Canvas { colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()] = SWTResourceManager.getColor(255, 128, 255); } - + + public long getXOffset() { + return -origin.x; + } + public void addCursoPainter(CursorPainter cursorPainter){ painterList.add(cursorPainter); cursorPainters.add(cursorPainter); @@ -243,10 +247,11 @@ public class WaveformCanvas extends Canvas { long xoffs=xc+origin.x; // cursor offset relative to left border long xcn=tc/scaleFactor; // new total x-offset long originX=xcn-xoffs; - if(originX>0) + if(originX>0) { origin.x=(int) -originX; // new cursor time offset relative to left border - else + }else { origin.x=0; + } syncScrollBars(); arrowPainter.setTx(tx); redraw(); @@ -354,7 +359,7 @@ public class WaveformCanvas extends Canvas { return; } int height = trackAreaPainter.getHeight(); // incl. Ruler - int width = (int) (maxTime / scaleFactor); + long width = maxTime / scaleFactor; Rectangle clientArea=getClientArea(); ScrollBar horizontal = getHorizontalBar(); horizontal.setIncrement((int) (getClientArea().width / 100)); @@ -362,10 +367,11 @@ public class WaveformCanvas extends Canvas { int clientWidthw = clientArea.width; if (width > clientWidthw) { /* image is wider than client area */ horizontal.setMinimum(0); - horizontal.setMaximum(width); + horizontal.setMaximum((int)width); horizontal.setEnabled(true); - if (((int) -origin.x) > horizontal.getMaximum() - clientWidthw) + if (((int) -origin.x) > horizontal.getMaximum() - clientWidthw) { origin.x = -horizontal.getMaximum() + clientWidthw; + } } else { /* image is narrower than client area */ horizontal.setEnabled(false); } @@ -380,8 +386,9 @@ public class WaveformCanvas extends Canvas { vertical.setMinimum(0); vertical.setMaximum(height); vertical.setEnabled(true); - if (((int) -origin.y) > vertical.getMaximum() - clientHeighth) + if (((int) -origin.y) > vertical.getMaximum() - clientHeighth) { origin.y = -vertical.getMaximum() + clientHeighth; + } } else { /* image is less higher than client area */ vertical.setMaximum((int) (clientHeighth)); vertical.setEnabled(false); @@ -396,12 +403,13 @@ public class WaveformCanvas extends Canvas { /* Paint function */ private void paint(GC gc) { Rectangle clientRect = getClientArea(); /* Canvas' painting area */ - clientRect.x = -origin.x; +// clientRect.x = -origin.x; clientRect.y = -origin.y; // reset the transform transform.identity(); // shift the content - transform.translate(origin.x, origin.y); + // DO NOT SHIFT HORIZONTALLY, the range is WAY TOO BIG for float!!! + transform.translate(0, origin.y); gc.setTransform(transform); gc.setClipping(clientRect); if (painterList.size() > 0 ) { diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java index 5872254..04d9232 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java @@ -10,6 +10,7 @@ *******************************************************************************/ package com.minres.scviewer.database.swt.internal; +import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -225,7 +226,7 @@ public class WaveformViewer implements IWaveformViewer { SashForm topSash = new SashForm(top, SWT.SMOOTH); topSash.setBackground(topSash.getDisplay().getSystemColor(SWT.COLOR_GRAY)); - + Composite composite = new Composite(topSash, SWT.NONE); composite.setLayout(new FillLayout(SWT.HORIZONTAL)); @@ -304,7 +305,7 @@ public class WaveformViewer implements IWaveformViewer { valueList.addMouseListener(nameValueMouseListener); valueListScrolled.setContent(valueList); - waveformCanvas.setMaxTime(1); + waveformCanvas.setMaxTime(1); waveformCanvas.addMouseListener(waveformMouseListener); nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { @@ -485,13 +486,15 @@ public class WaveformViewer implements IWaveformViewer { resultsList[tx.getConcurrencyIndex()]= evt.getTransaction(); } } - firstTx=stream.getEvents().lowerEntry(firstTx.getKey()); + firstTx=stream.getEvents().lowerEntry(firstTx.getKey()); }while(firstTx!=null && !isArrayFull(resultsList)); entry.currentValue=""; boolean separator=false; + for(ITx o:resultsList){ if(separator) entry.currentValue+="|"; if(o!=null) entry.currentValue+=((ITx)o).getGenerator().getName(); + separator=true; } } @@ -502,7 +505,8 @@ public class WaveformViewer implements IWaveformViewer { valueListScrolled.setMinSize(width, trackVerticalHeight); valueListScrolled.redraw(); } - + + private boolean isArrayFull(Object[] array){ for(Object o:array){ if(o==null) return false; @@ -600,6 +604,9 @@ public class WaveformViewer implements IWaveformViewer { TrackEntry trackEntry = getEntryForStream(txSel.getStream()); if(trackEntry==null && addIfNeeded){ trackEntry=new TrackEntry(txSel.getStream()); + // compute fallback colors + Color fallbackColors[] = TrackEntry.computeColor(txSel.getStream().getName(), TrackEntry.fallbackColor, TrackEntry.highlightedFallbackColor); + trackEntry.setColor(fallbackColors[0], fallbackColors[1]); streams.add(trackEntry); } currentTxSelection = txSel; diff --git a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/TrackEntry.java b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/TrackEntry.java index b751aa1..534d4a9 100644 --- a/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/TrackEntry.java +++ b/com.minres.scviewer.database.ui/src/com/minres/scviewer/database/ui/TrackEntry.java @@ -10,13 +10,87 @@ *******************************************************************************/ package com.minres.scviewer.database.ui; + +import java.awt.Color; + import com.minres.scviewer.database.ISignal; import com.minres.scviewer.database.ITxEvent; import com.minres.scviewer.database.ITxStream; import com.minres.scviewer.database.IWaveform; - public class TrackEntry { + + // color info + public static Color fallbackColor = new Color(200,0,0); + public static Color highlightedFallbackColor = new Color(255,0,0); + private Color[]signalColors; + + // list of random colors + private static Color[][] randomColors = { + { new Color( 170, 66, 37 ), new Color ( 190, 66, 37 ) }, + { new Color( 96, 74, 110 ), new Color ( 96, 74, 130 ) }, + { new Color( 133, 105, 128 ), new Color ( 153, 105, 128 ) }, + { new Color( 0, 126, 135 ), new Color ( 0, 126, 155 ) }, + { new Color( 243, 146, 75 ), new Color ( 255, 146, 75 ) }, + { new Color( 206, 135, 163 ), new Color ( 226, 135, 163 ) }, + { new Color( 124, 103, 74 ), new Color ( 144, 103, 74 ) }, + { new Color( 194, 187, 169 ), new Color ( 214, 187, 169 ) }, + { new Color( 104, 73, 71 ), new Color ( 124, 73, 71 ) }, + { new Color( 75, 196, 213 ), new Color ( 75, 196, 233 ) }, + { new Color( 206, 232, 229 ), new Color ( 206, 252, 229 ) }, + { new Color( 169, 221, 199 ), new Color ( 169, 241, 199 ) }, + { new Color( 100, 165, 197 ), new Color ( 100, 165, 217 ) }, + { new Color( 150, 147, 178 ), new Color ( 150, 147, 198 ) }, + { new Color( 200, 222, 182 ), new Color ( 200, 242, 182 ) }, + { new Color( 147, 208, 197 ), new Color ( 147, 228, 197 ) } + }; + + public static Color[] computeColor (String streamValue, Color fallback, Color highlightedFallback) { + + Color[]result = new Color[2]; + + result[0] = fallback; + result[1] = highlightedFallback; + + // assign colors to standard values + if (streamValue.contains("read")){ + result[0] = new Color(86,174,53); + result[1] = new Color (86,194,53); + }else if (streamValue.contains("rdata")){ + result[0] = new Color(138,151,71); + result[1] = new Color (138,171,71); + }else if (streamValue.contains("addr")){ + result[0] = new Color(233,187,68); + result[1] = new Color (233,207,68); + }else if (streamValue.contains("write")){ + result[0] = new Color(1,128,191); + result[1] = new Color (1,128,211); + }else if (streamValue.contains("wdata")){ + result[0] = new Color(2,181,160); + result[1] = new Color (2,201,160); + + }else { + // assign "random" color here, one name always results in the same color! + if( randomColors.length > 0 ) { + int index = Math.abs(streamValue.hashCode()) % randomColors.length; + result[0] = randomColors[index][0]; + result[1] = randomColors[index][1]; + } + } + + return result; + + } + + public void setColor(Color changedColor, Color highlightColor) { + signalColors[0] = changedColor; + signalColors[1] = highlightColor; + } + + public Color[] getColors() { + return signalColors; + } + public enum ValueDisplay { DEFAULT, SIGNED, UNSIGNED @@ -45,6 +119,9 @@ public class TrackEntry { vOffset=0; height=0; selected=false; + signalColors = new Color[2]; + signalColors[0] = fallbackColor; + signalColors[1] = highlightedFallbackColor; } public boolean isStream(){ diff --git a/com.minres.scviewer.database.vcd/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.database.vcd/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/com.minres.scviewer.database.vcd/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/com.minres.scviewer.database.vcd/META-INF/MANIFEST.MF b/com.minres.scviewer.database.vcd/META-INF/MANIFEST.MF index 968707f..3f0cc56 100644 --- a/com.minres.scviewer.database.vcd/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.database.vcd/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: VCD signal database Bundle-SymbolicName: com.minres.scviewer.database.vcd -Bundle-Version: 2.0.0.qualifier +Bundle-Version: 2.0.2.qualifier Bundle-Vendor: MINRES Technologies GmbH Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: com.minres.scviewer.database;bundle-version="1.0.0", diff --git a/com.minres.scviewer.database.vcd/pom.xml b/com.minres.scviewer.database.vcd/pom.xml index 20be6aa..606e69a 100644 --- a/com.minres.scviewer.database.vcd/pom.xml +++ b/com.minres.scviewer.database.vcd/pom.xml @@ -1,6 +1,7 @@ 4.0.0 com.minres.scviewer.database.vcd + 2.0.2-SNAPSHOT com.minres.scviewer com.minres.scviewer.parent diff --git a/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java b/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java index fbbd8f4..d0a93bd 100644 --- a/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java +++ b/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDDbLoader.java @@ -13,6 +13,8 @@ package com.minres.scviewer.database.vcd; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -20,6 +22,7 @@ import java.util.NavigableMap; import java.util.Stack; import java.util.TreeMap; import java.util.Vector; +import java.util.zip.GZIPInputStream; import com.minres.scviewer.database.BitVector; import com.minres.scviewer.database.ISignal; @@ -56,8 +59,20 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder { public VCDDbLoader() { } - /** The date bytes. */ - private byte[] dateBytes = "$date".getBytes(); + private static boolean isGzipped(File f) { + InputStream is = null; + try { + is = new FileInputStream(f); + byte [] signature = new byte[2]; + int nread = is.read( signature ); //read the gzip signature + return nread == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b; + } catch (IOException e) { + return false; + } finally { + try { is.close();} catch (IOException e) { } + } + } + /* (non-Javadoc) * @see com.minres.scviewer.database.ITrDb#load(java.io.File) @@ -67,22 +82,16 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder { public boolean load(IWaveformDb db, File file) throws Exception { this.db=db; this.maxTime=0; - try { - FileInputStream fis = new FileInputStream(file); - byte[] buffer = new byte[dateBytes.length]; - int read = fis.read(buffer, 0, dateBytes.length); - fis.close(); - if (read == dateBytes.length) - for (int i = 0; i < dateBytes.length; i++) - if (buffer[i] != dateBytes[i]) - return false; - } catch(FileNotFoundException e) { + String name = file.getCanonicalFile().getName(); + if(!(name.endsWith(".vcd") || + name.endsWith(".vcdz") || + name.endsWith(".vcdgz") || + name.endsWith(".vcd.gz")) ) return false; - } - signals = new Vector(); - moduleStack= new Stack(); - boolean res = new VCDFileParser(false).load(new FileInputStream(file), this); + moduleStack= new Stack(); + FileInputStream fis = new FileInputStream(file); + boolean res = new VCDFileParser(false).load(isGzipped(file)?new GZIPInputStream(fis):fis, this); moduleStack=null; if(!res) throw new InputFormatException(); // calculate max time of database diff --git a/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDFileParser.java b/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDFileParser.java index d1cf505..cd41817 100644 --- a/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDFileParser.java +++ b/com.minres.scviewer.database.vcd/src/com/minres/scviewer/database/vcd/VCDFileParser.java @@ -22,10 +22,12 @@ class VCDFileParser { private HashMap nameToNetMap = new HashMap(); private long picoSecondsPerIncrement; private boolean stripNetWidth; + private boolean replaceColon; long currentTime; public VCDFileParser(boolean stripNetWidth) { this.stripNetWidth=stripNetWidth; + this.replaceColon=false; } public boolean load(InputStream is, IVCDDatabaseBuilder builder) { @@ -76,11 +78,17 @@ class VCDFileParser { } Integer net = nameToNetMap.get(id); - if (net == null) { - // We've never seen this net before + if (net == null) { // We've never seen this net before + int openBracket = netName.indexOf('['); if(stripNetWidth){ - int openBracket = netName.indexOf('['); if (openBracket != -1) netName = netName.substring(0, openBracket); + openBracket = -1; + } + if(replaceColon) { + if (openBracket != -1) { + netName = netName.substring(0, openBracket).replaceAll(":", ".")+netName.substring(openBracket); + } else + netName=netName.replaceAll(":", "."); } nameToNetMap.put(id, traceBuilder.newNet(netName, -1, width)); } else { @@ -89,6 +97,17 @@ class VCDFileParser { } } + private void parseComment() throws Exception { + nextToken(); + String s = tokenizer.sval; + nextToken(); + while(!tokenizer.sval.equals("$end")){ + s+=" "+tokenizer.sval; + nextToken(); + } + replaceColon|=s.contains("ARTERIS Architecture"); + } + private void parseTimescale() throws Exception { nextToken(); String s = tokenizer.sval; @@ -132,6 +151,8 @@ class VCDFileParser { parseUpscope(); else if (tokenizer.sval.equals("$timescale")) parseTimescale(); + else if (tokenizer.sval.equals("$comment")) + parseComment(); else if (tokenizer.sval.equals("$enddefinitions")) { match("$end"); return false; diff --git a/com.minres.scviewer.database/.classpath b/com.minres.scviewer.database/.classpath index 5f81a27..cf36b56 100644 --- a/com.minres.scviewer.database/.classpath +++ b/com.minres.scviewer.database/.classpath @@ -1,7 +1,7 @@ - - + + diff --git a/com.minres.scviewer.database/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.database/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/com.minres.scviewer.database/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java b/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java index f6d74cd..212a7dd 100644 --- a/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java +++ b/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java @@ -76,6 +76,7 @@ public class BitVector { for(int i=resWidth-1; i>=0; i--){ int digit=0; for(int j=3; j>=0; j--){ + if((4*i+j)>=value.length) continue; BitValue val = BitValue.fromChar(value[4*i+j]); switch(val) { case X: diff --git a/com.minres.scviewer.e4.application/.classpath b/com.minres.scviewer.e4.application/.classpath index eca7bdb..43b9862 100644 --- a/com.minres.scviewer.e4.application/.classpath +++ b/com.minres.scviewer.e4.application/.classpath @@ -3,5 +3,5 @@ - + diff --git a/com.minres.scviewer.e4.application/Application.e4xmi b/com.minres.scviewer.e4.application/Application.e4xmi index 8b7c1e3..f02d07f 100644 --- a/com.minres.scviewer.e4.application/Application.e4xmi +++ b/com.minres.scviewer.e4.application/Application.e4xmi @@ -26,19 +26,22 @@ - + + NoAutoCollapse + + - + - + @@ -142,9 +145,6 @@ - - - diff --git a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index 96a8505..7c8389f 100644 --- a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true -Bundle-Version: 2.0.0.qualifier +Bundle-Version: 2.1.1.qualifier Bundle-Vendor: %Bundle-Vendor Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.core.runtime;bundle-version="3.11.1", diff --git a/com.minres.scviewer.e4.application/pom.xml b/com.minres.scviewer.e4.application/pom.xml index 91d86b7..88d42e4 100644 --- a/com.minres.scviewer.e4.application/pom.xml +++ b/com.minres.scviewer.e4.application/pom.xml @@ -1,6 +1,7 @@ 4.0.0 com.minres.scviewer.e4.application + 2.1.1-SNAPSHOT com.minres.scviewer com.minres.scviewer.parent diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java index 6d5db35..b53ec5c 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AboutHandler.java @@ -12,6 +12,7 @@ package com.minres.scviewer.e4.application.handlers; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.swt.widgets.Shell; @@ -22,9 +23,9 @@ public class AboutHandler { @Execute public void execute(Shell shell, MApplication app, MWindow window, EModelService ms /*@Named("mdialog01.dialog.0") MDialog dialog*/) { - MWindow dialog = (MWindow) ms.find(DIALOG_ID, app); //$NON-NLS-1$ - dialog.setToBeRendered(true); - dialog.setToBeRendered(false); + MPart mel = (MPart) ms.find(DIALOG_ID, app); //$NON-NLS-1$ + mel.setToBeRendered(true); + mel.setToBeRendered(false); } } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java index 54c476e..4965478 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/AddWaveformHandler.java @@ -40,13 +40,16 @@ public class AddWaveformHandler { @Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection) { if(designBrowser==null) designBrowser = getListPart( partService); if(designBrowser==null || designBrowser.getActiveWaveformViewerPart()==null) return false; - Boolean before = "before".equalsIgnoreCase(where); //$NON-NLS-1$ + boolean before = "before".equalsIgnoreCase(where); //$NON-NLS-1$ + IStructuredSelection waveformSelection = null; + if(designBrowser.getActiveWaveformViewerPart()!=null) + waveformSelection = (IStructuredSelection)designBrowser.getActiveWaveformViewerPart().getSelection(); if("true".equalsIgnoreCase(all)) //$NON-NLS-1$ return designBrowser.getFilteredChildren().length>0 && - (!before || ((IStructuredSelection)designBrowser.getActiveWaveformViewerPart().getSelection()).size()>0); + (!before || (waveformSelection!=null && waveformSelection.size()>0)); else - return selection.size()>0 && - (!before || ((IStructuredSelection)designBrowser.getActiveWaveformViewerPart().getSelection()).size()>0); + return selection!=null && selection.size()>0 && + (!before || (waveformSelection!=null && waveformSelection.size()>0)); } @Execute diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java index e53617c..fc575c9 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java @@ -10,6 +10,8 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.handlers; +import java.io.File; + import javax.inject.Named; import org.eclipse.e4.core.di.annotations.CanExecute; @@ -20,6 +22,7 @@ import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import com.minres.scviewer.e4.application.Messages; @@ -38,21 +41,60 @@ public class LoadStoreSettingsHandler { @Execute public void execute(@Named(PARAMETER_ID) String param, Shell shell, MApplication app, EModelService modelService, EPartService partService){ + boolean load = "load".equals(param); //$NON-NLS-1$ FileDialog dialog = new FileDialog(shell, load?SWT.OPEN:SWT.SAVE); dialog.setFilterExtensions (new String []{Messages.LoadStoreSettingsHandler_2}); if(!load) dialog.setFileName(Messages.LoadStoreSettingsHandler_3); - String res = dialog.open(); + + String fileName = null; MPart part = partService.getActivePart(); - if(res!=null && part!=null){ - Object obj = part.getObject(); - if(obj instanceof WaveformViewer){ - if(load) - ((WaveformViewer)obj).loadState(res); - else - ((WaveformViewer)obj).saveState(res); + Object obj = part.getObject(); + + // Save active tab settings + if(!load) { + // 3 possible cases when when saving active tab settings: + // - user dismisses the dialog by pressing Cancel + // - selected file name does not exist + // - user agrees to overwrite existing file + boolean done = false; + while (!done) { + // open the File Dialog + fileName = dialog.open(); + if (fileName == null) { + // user has cancelled -> quit and return + done = true; + } else { + // user has selected a file -> see if it already exists + File file = new File(fileName); + if (file.exists()) { + // file already exists -> asks for confirmation + MessageBox mb = new MessageBox(dialog.getParent(), SWT.ICON_WARNING + | SWT.YES | SWT.NO); + mb.setText("Confirm overwrite"); + mb.setMessage(fileName + " already exists. Do you want to overwrite it?"); + // user clicks Yes -> all done, drop out + if(mb.open() == SWT.YES) { + ((WaveformViewer)obj).saveState(fileName); + done = true; + } else { // user clicks No -> redisplay the File Dialog + done = false; + } + } else { + // file does not exist -> save and drop out + ((WaveformViewer)obj).saveState(fileName); + done = true; + } + } } - } + return; + } // end if(!load) + + else { // load active tab settings + String res = dialog.open(); + if(res != null && part!=null && (obj instanceof WaveformViewer)) { + ((WaveformViewer)obj).loadState(res); + } + } } - -} +} \ No newline at end of file diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/WaveStatusBarControl.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/WaveStatusBarControl.java index 8483068..a1c2006 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/WaveStatusBarControl.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/internal/status/WaveStatusBarControl.java @@ -59,7 +59,7 @@ public class WaveStatusBarControl extends StatusBarControl { final String labelString; /** The width. */ - final int width; + //final int width; /** The text. */ CLabel label, text; @@ -73,10 +73,10 @@ public class WaveStatusBarControl extends StatusBarControl { * @param labelString the label string * @param width the width */ - public TextContributionItem(String labelString, int width) { + public TextContributionItem(String labelString /*, int width */) { super(); this.labelString = labelString; - this.width=width; + //this.width=width; content=""; //$NON-NLS-1$ } @@ -85,14 +85,16 @@ public class WaveStatusBarControl extends StatusBarControl { */ @Override public void fill(Composite parent) { - Composite box=new Composite(parent, SWT.NONE); + Composite box=new Composite(parent, SWT.NONE); //NONE box.setLayout(new GridLayout(2, false)); label=new CLabel(box, SWT.SHADOW_NONE); label.setText(labelString); text=new CLabel(box, SWT.SHADOW_IN); text.setAlignment(SWT.RIGHT); + //GridData layoutData=new GridData(SWT.DEFAULT, SWT.DEFAULT, true, false); GridData layoutData=new GridData(SWT.DEFAULT, SWT.DEFAULT, true, false); - layoutData.minimumWidth=width; + layoutData.minimumWidth=70; + //layoutData.minimumWidth=width; text.setLayoutData(layoutData); } @@ -127,10 +129,11 @@ public class WaveStatusBarControl extends StatusBarControl { @Inject public WaveStatusBarControl(UISynchronize sync) { super(sync); - cursorContribution = new TextContributionItem(Messages.WaveStatusBarControl_5, 150); - markerContribution = new TextContributionItem(Messages.WaveStatusBarControl_6, 150); - markerDiffContribution = new TextContributionItem(Messages.WaveStatusBarControl_7, 150); - zoomContribution = new TextContributionItem(Messages.WaveStatusBarControl_8, 60); + + cursorContribution = new TextContributionItem(Messages.WaveStatusBarControl_5 /*, 150 */); //150 + markerContribution = new TextContributionItem(Messages.WaveStatusBarControl_6 /*, 150 */); //150 + markerDiffContribution = new TextContributionItem(Messages.WaveStatusBarControl_7 /*, 150 */); //150 + zoomContribution = new TextContributionItem(Messages.WaveStatusBarControl_8 /*, 60 */); //60 manager.appendToGroup(StatusLineManager.BEGIN_GROUP,cursorContribution); manager.appendToGroup(StatusLineManager.BEGIN_GROUP,markerContribution); manager.appendToGroup(StatusLineManager.BEGIN_GROUP,markerDiffContribution); diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties index ae08425..b73f82f 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties @@ -1,5 +1,5 @@ -AboutDialog_0=\nSCViewer - a SystemC waveform viewer\n\nVersion: 2.0\n -AboutDialog_1=\nCopyright (c) 2015, 2018 MINRES Technologies GmbH and others.\n\nAll rights reserved. MINRES and the MINRES logo are trademarks of MINRES Technologies GmbH, http://www.minres.com/. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html\n\nParts of the software are governed by the Apache License Version 2.0 available at http://www.apache.org/licenses/. These are namely org.mapdb and org.sqlite JDBC driver\n\nSources code is hosted at https://git.minres.com/VP/SCViewer and the master branch is mirrored to GitHub: https://git.com/minres/SCViewer\n +AboutDialog_0=\nSCViewer - a SystemC waveform viewer\n\nVersion: {0}\n +AboutDialog_1=\nCopyright (c) 2015, 2019 MINRES Technologies GmbH and others.\n\nAll rights reserved. MINRES and the MINRES logo are trademarks of MINRES Technologies GmbH, http://www.minres.com/. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html\n\nParts of the software are governed by the Apache License Version 2.0 available at http://www.apache.org/licenses/. These are namely org.mapdb and org.sqlite JDBC driver\n\nSource code is hosted at https://git.minres.com/VP-Tools/SCViewer and the master branch is mirrored to GitHub: https://github.com/minres/SCViewer\n DesignBrowser_12=Append all after DesignBrowser_16=Insert all before DesignBrowser_2=Enter text to filter waveforms diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java index 8b0745c..6180e95 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java @@ -19,8 +19,10 @@ import java.util.regex.Pattern; import javax.annotation.PostConstruct; import javax.inject.Inject; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; @@ -39,6 +41,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.wb.swt.ResourceManager; import org.eclipse.wb.swt.SWTResourceManager; +import org.osgi.framework.Version; import com.minres.scviewer.e4.application.Messages; @@ -75,7 +78,7 @@ public class AboutDialog extends Dialog { Composite composite = new Composite(parent, SWT.NONE); GridData gd_composite = new GridData(SWT.LEFT, SWT.FILL, true, true); gd_composite.widthHint = 600; - gd_composite.heightHint =250; + gd_composite.heightHint =300; composite.setLayoutData(gd_composite); composite.setLayout(new GridLayout(2, false)); @@ -86,7 +89,7 @@ public class AboutDialog extends Dialog { Canvas canvas = new Canvas(composite,SWT.NO_REDRAW_RESIZE); GridData gd_canvas = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); gd_canvas.widthHint = 200; - gd_canvas.heightHint =250; + gd_canvas.heightHint =300; canvas.setLayoutData(gd_canvas); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { @@ -97,11 +100,14 @@ public class AboutDialog extends Dialog { } }); - StyledText styledText = new StyledText(composite, SWT.BORDER); + StyledText styledText = new StyledText(composite, SWT.V_SCROLL | SWT.BORDER); styledText.setEditable(false); GridData gd_styledText = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); styledText.setLayoutData(gd_styledText); - styledText.setText(productTitle+copyrightText); + Version version = Platform.getProduct().getDefiningBundle().getVersion(); + String versionString = String.format("%d.%d.%d", version.getMajor(), version.getMinor(), version.getMicro()); + String pt = NLS.bind(Messages.AboutDialog_0, versionString); + styledText.setText(pt+copyrightText); styledText.setBackground(white); styledText.setWordWrap(true); styledText.setLeftMargin(5); @@ -133,7 +139,7 @@ public class AboutDialog extends Dialog { // links are activated on mouse down when the control key is held down // if ((event.stateMask & SWT.MOD1) != 0) { try { - int offset = ((StyledText)event.widget).getOffsetAtPoint(new Point (event.x, event.y)); + int offset = ((StyledText)event.widget).getOffsetAtLocation(new Point (event.x, event.y)); StyleRange style = ((StyledText)event.widget).getStyleRangeAtOffset(offset); if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) { Desktop.getDesktop().browse(new java.net.URI(style.data.toString())); diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java index 99b997e..db0aa1e 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java @@ -10,6 +10,7 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.parts; +import java.util.ArrayList; import java.util.Vector; import javax.annotation.PostConstruct; @@ -29,14 +30,16 @@ import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ITreeViewerListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; @@ -51,11 +54,12 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import com.minres.scviewer.database.DataType; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITxAttribute; import com.minres.scviewer.database.ITxRelation; -import com.minres.scviewer.database.DataType; import com.minres.scviewer.e4.application.Messages; import com.minres.scviewer.e4.application.provider.TxPropertiesLabelProvider; @@ -129,6 +133,19 @@ public class TransactionDetails { treeViewer.addFilter(attributeFilter); treeViewer.setComparator(viewSorter); treeViewer.setAutoExpandLevel(2); + treeViewer.addTreeListener(new ITreeViewerListener() { + + @Override + public void treeCollapsed(TreeExpansionEvent event) { + treeViewer.getSelection(); + } + + @Override + public void treeExpanded(TreeExpansionEvent event) { + treeViewer.getSelection(); + } + + }); // Set up the table Tree tree = treeViewer.getTree(); @@ -187,7 +204,7 @@ public class TransactionDetails { Object[] selectedArray = (Object[]) selected; if(selectedArray.length==3 && selectedArray[2] instanceof ITx){ waveformViewerPart.setSelection(new StructuredSelection(selectedArray[2])); - treeViewer.setInput(selectedArray[2]); + setInput(selectedArray[2]); } } } @@ -247,6 +264,77 @@ public class TransactionDetails { this.waveformViewerPart=part; } + public void setInput(Object object) { + if(object instanceof ITx){ + ArrayList names = new ArrayList<>(); + int indexInParent=getTopItemHier(names); + ArrayList states = getExpandedState(treeViewer.getTree().getItems()); + treeViewer.setInput(object); + setExpandedState(treeViewer.getTree().getItems(), states); + setTopItemFromHier(names, indexInParent); + } else { + treeViewer.setInput(null); + } + + } + + private void setExpandedState(TreeItem[] treeItems, ArrayList states) { + for (int i = 0; i < treeItems.length; i++) { + treeItems[i].setExpanded(states.size()>i?states.get(i):true); + } + } + + private ArrayList getExpandedState(TreeItem[] items){ + ArrayList ret = new ArrayList<>(); + for (TreeItem treeItem : items) + ret.add(treeItem.getItemCount()>0?treeItem.getExpanded():true); + return ret; + } + + private int getTopItemHier(ArrayList names){ + int indexInParent=-1; + TreeItem obj = treeViewer.getTree().getTopItem(); + if(obj!=null) { + names.add(0, obj.getText(0)); + if(obj.getParentItem()!=null) { + TreeItem pobj=obj.getParentItem(); + names.add(0, pobj.getText(0)); + TreeItem[] items = pobj.getItems(); + for (int i = 0; i < items.length; i++) { + if(items[i]==obj) { + indexInParent=i; + break; + } + } + } + } + return indexInParent; + } + + private void setTopItemFromHier(ArrayList names, int indexInParent) { + if(indexInParent<0 || names.size()==0 ) return; + TreeItem selItem=null; + for (TreeItem item : treeViewer.getTree().getItems()) { // find item from category + if(item.getText(0).equals(names.get(0))) { + if(names.size()>1) { // if we had an attribute as top item + TreeItem[] subItems=item.getItems(); + for(TreeItem it : subItems) { // try to align by name + if(it.getText(0).equals(names.get(1))) { + selItem=it; + break; + } + } + if(selItem==null && indexInParent>=0 && subItems.length>0) // name based match failed so try to use position + selItem=subItems[subItems.length>indexInParent?indexInParent:subItems.length-1]; + } + if(selItem==null) // no match in attributes so set the category as top item + selItem=item; + break; + } + } + if(selItem!=null) + treeViewer.getTree().setTopItem(selItem); + } /** * Sets the selection. * @@ -256,12 +344,7 @@ public class TransactionDetails { public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection){ if(treeViewer!=null && selection!=null && !treeViewer.getTree().isDisposed()){ if( selection instanceof IStructuredSelection) { - Object object= ((IStructuredSelection)selection).getFirstElement(); - if(object instanceof ITx){ - treeViewer.setInput(object); - } else { - treeViewer.setInput(null); - } + setInput(((IStructuredSelection)selection).getFirstElement()); } } } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index 56f947b..251a9d8 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -74,6 +74,7 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import com.minres.scviewer.database.ITx; +import com.minres.scviewer.database.ITxEvent; import com.minres.scviewer.database.ITxRelation; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformDb; @@ -126,7 +127,16 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis /** The Constant BASE_LINE_TIME. */ protected static final String BASE_LINE_TIME = "BASE_LINE_TIME"; //$NON-NLS-1$ + + /** The Constant SELECTED_TX_ID. */ + protected static final String SELECTED_TX_ID = "SELECTED_TX_ID"; //$NON-NLS-1$ + /** The Constant SELECTED_TRACKENTRY_NAME. */ + protected static final String SELECTED_TRACKENTRY_NAME = "SELECTED_TRACKENTRY_NAME"; //$NON-NLS-1$ + + /** The Constant WAVEFORM_SELECTED. */ + protected static final String WAVEFORM_SELECTED = ".WAVEFORM_SELECTED"; //$NON-NLS-1$ + /** The Constant FILE_CHECK_INTERVAL. */ protected static final long FILE_CHECK_INTERVAL = 60000; @@ -578,6 +588,8 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis } public void saveState(String fileName){ + + Map persistedState = new HashMap<>(); persistedState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); //$NON-NLS-1$ Integer index = 0; @@ -588,10 +600,14 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis saveWaveformViewerState(persistedState); Properties props = new Properties(); props.putAll(persistedState); + try { - FileOutputStream out = new FileOutputStream(fileName); - props.store(out, "Written by SCViewer"); //$NON-NLS-1$ - out.close(); + + FileOutputStream out = new FileOutputStream(fileName); + props.store(out, "Written by SCViewer"); //$NON-NLS-1$ + out.close(); + + } catch (IOException e) { e.printStackTrace(); } @@ -600,6 +616,13 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis public void loadState(String fileName){ Properties props = new Properties(); try { + //clear old streams before loading tab settings + if(!waveformPane.getStreamList().isEmpty()) { + waveformPane.getStreamList().clear(); + for (TrackEntry trackEntry : waveformPane.getStreamList()) { + trackEntry.selected = false; + } + } FileInputStream in = new FileInputStream(fileName); props.load(in); in.close(); @@ -619,12 +642,15 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis */ protected void saveWaveformViewerState(Map persistedState) { Integer index; + boolean isStream = false; persistedState.put(SHOWN_WAVEFORM + "S", Integer.toString(waveformPane.getStreamList().size())); //$NON-NLS-1$ index = 0; for (TrackEntry trackEntry : waveformPane.getStreamList()) { + if(trackEntry.isStream()) { isStream=true; } persistedState.put(SHOWN_WAVEFORM + index, trackEntry.waveform.getFullName()); persistedState.put(SHOWN_WAVEFORM + index + VALUE_DISPLAY, trackEntry.valueDisplay.toString()); persistedState.put(SHOWN_WAVEFORM + index + WAVE_DISPLAY, trackEntry.waveDisplay.toString()); + persistedState.put(SHOWN_WAVEFORM + index + WAVEFORM_SELECTED, String.valueOf(trackEntry.selected).toUpperCase()); index++; } List cursors = waveformPane.getCursorList(); @@ -636,8 +662,38 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis } persistedState.put(ZOOM_LEVEL, Integer.toString(waveformPane.getZoomLevel())); persistedState.put(BASE_LINE_TIME, Long.toString(waveformPane.getBaselineTime())); + + // get selected transaction of a stream + ISelection selection = waveformPane.getSelection(); + if (!selection.isEmpty() && isStream) { + List t = getISelection(selection); + ITx tx = (ITx) t.get(0); + TrackEntry te = (TrackEntry) t.get(1); + // get transaction id + persistedState.put(SELECTED_TX_ID, Long.toString(tx.getId())); + //get TrackEntry name + String name = te.getStream().getFullName(); + persistedState.put(SELECTED_TRACKENTRY_NAME, name); + } } + protected List getISelection(ISelection selection){ + List result = new LinkedList (); + + if ( selection instanceof IStructuredSelection ) + { + Iterator i = ((IStructuredSelection)selection).iterator(); + while (i.hasNext()){ + Object o = i.next (); + if (o == null) { + continue; + } + result.add(o); + } + } + return result; + } + /** * Restore waveform viewer state. * @@ -650,6 +706,13 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i)); if (waveform != null) { TrackEntry t = new TrackEntry(waveform); + //check if t is selected + boolean isSelected = Boolean.valueOf(state.get(SHOWN_WAVEFORM + i + WAVEFORM_SELECTED)); + if(isSelected) { + t.selected = true; + } else { + t.selected = false; + } res.add(t); String v = state.get(SHOWN_WAVEFORM + i + VALUE_DISPLAY); if(v!=null) @@ -683,6 +746,38 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis } catch (NumberFormatException e) { } } + if (state.containsKey(SELECTED_TX_ID) && state.containsKey(SELECTED_TRACKENTRY_NAME)) { + try { + Long txId = Long.parseLong(state.get(SELECTED_TX_ID)); + String trackentryName = state.get(SELECTED_TRACKENTRY_NAME); + + //get TrackEntry Object based on name and TX Object by id and put into selectionList + for(TrackEntry te : res) { + if(te.waveform.getFullName().compareTo(trackentryName)==0) { + boolean found = false; + // TODO: find transaction by time? To avoid 3x for-loop + for( List lev : te.getStream().getEvents().values() ) { + if(lev == null) continue; + for(ITxEvent itxe : lev) { + if(itxe == null) continue; + ITx itx = itxe.getTransaction(); + if(itx.getId() == txId) { + found = true; + ArrayList selectionList = new ArrayList(); + selectionList.add(te); + selectionList.add(itx); + waveformPane.setSelection(new StructuredSelection (selectionList)); + break; + } + } + if(found) break; + } + break; + } + } + } catch (NumberFormatException e) { + } + } updateAll(); } @@ -826,14 +921,26 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis List streams = waveformPane.getStreamList(); ISelection sel = waveformPane.getSelection(); TrackEntry newSelection=null; + if(sel instanceof IStructuredSelection && ((IStructuredSelection) sel).size()==2) { Iterator it = ((IStructuredSelection)sel).iterator(); it.next(); int idx = streams.indexOf(it.next()); - if(idx==streams.size()-1) - newSelection=streams.get(idx-1); - else + + if(idx==streams.size()-1) { + //last stream gets deleted, no more selection + if(idx==0) { + newSelection=null; + } + //more than 1 stream left, last gets deleted, selection jumps to new last stream + else { + newSelection=streams.get(idx-1); + } + } + //more than 1 stream left, any stream but the last gets deleted, selection jumps to the next stream + else { newSelection=streams.get(idx+1); + } } waveformPane.setSelection(new StructuredSelection()); streams.remove(trackEntry); diff --git a/com.minres.scviewer.e4.product/pom.xml b/com.minres.scviewer.e4.product/pom.xml index ff56ab9..129b5ce 100644 --- a/com.minres.scviewer.e4.product/pom.xml +++ b/com.minres.scviewer.e4.product/pom.xml @@ -10,6 +10,7 @@ ../com.minres.scviewer.parent com.minres.scviewer.e4.product + 2.1.2-SNAPSHOT eclipse-repository com.minres.scviewer diff --git a/com.minres.scviewer.e4.product/scviewer.product b/com.minres.scviewer.e4.product/scviewer.product index df81227..7235902 100644 --- a/com.minres.scviewer.e4.product/scviewer.product +++ b/com.minres.scviewer.e4.product/scviewer.product @@ -1,7 +1,7 @@ - + diff --git a/com.minres.scviewer.feature/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.feature/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/com.minres.scviewer.feature/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/com.minres.scviewer.ui/.classpath b/com.minres.scviewer.ui/.classpath index 879524a..cf36b56 100644 --- a/com.minres.scviewer.ui/.classpath +++ b/com.minres.scviewer.ui/.classpath @@ -2,7 +2,6 @@ - - + diff --git a/com.minres.scviewer.ui/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.ui/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/com.minres.scviewer.ui/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/com.minres.scviewer.updateSite/.settings/org.eclipse.core.resources.prefs b/com.minres.scviewer.updateSite/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/com.minres.scviewer.updateSite/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8