diff --git a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDb.java b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDb.java index acdaee2..fd5c6ab 100644 --- a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDb.java +++ b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDb.java @@ -48,12 +48,12 @@ public class SQLiteDb extends HierNode implements IWaveformDb { try { List event = handler.selectObjects(); if(event.size()>0) - return new EventTime(event.get(0).getTime(), "fs"); + return new EventTime(event.get(0).getTime()); } catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException | SQLException | IntrospectionException e) { e.printStackTrace(); } - return new EventTime(0L, "s"); + return EventTime.ZERO; } @Override diff --git a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java index f1c0dcd..33d6979 100644 --- a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java +++ b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/Tx.java @@ -57,7 +57,7 @@ public class Tx implements ITx { trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal()); try { for(ScvTxEvent scvEvent:handler.selectObjects()){ - begin= new EventTime(scvEvent.getTime()*trStream.getDb().timeResolution, "fs"); + begin= new EventTime(scvEvent.getTime()*trStream.getDb().timeResolution); } } catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException | SQLException | IntrospectionException e) { @@ -73,7 +73,7 @@ public class Tx implements ITx { trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal()); try { for(ScvTxEvent scvEvent:handler.selectObjects()){ - end = new EventTime(scvEvent.getTime()*trStream.getDb().timeResolution, "fs"); + end = new EventTime(scvEvent.getTime()*trStream.getDb().timeResolution); } } catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException | SQLException | IntrospectionException e) { diff --git a/com.minres.scviewer.database/src/com/minres/scviewer/database/EventTime.java b/com.minres.scviewer.database/src/com/minres/scviewer/database/EventTime.java index dd0ae72..334604f 100644 --- a/com.minres.scviewer.database/src/com/minres/scviewer/database/EventTime.java +++ b/com.minres.scviewer.database/src/com/minres/scviewer/database/EventTime.java @@ -11,61 +11,59 @@ package com.minres.scviewer.database; public class EventTime implements Comparable{ + public enum Unit { + FS("fs"), PS("ps"), NS("ns"), US("us"), MS("ms"), SEC("s"); + + private String alternative; + private Unit(String alternative){ + this.alternative=alternative; + } + + public static Unit fromString(String text) { + if (text != null) + for (Unit b : Unit.values()) { + if (text.equalsIgnoreCase(b.name()) || text.equalsIgnoreCase(b.alternative)) return b; + } + return null; + } + } - public static final double NS = 1000000.0; - - public static final double MS = 1000000000.0; + static final double[] scales = {1,1000.0,1000000.0,1000000000.0,1000000000000.0}; - public static final EventTime ZERO = new EventTime(0L, "fs"); + public static final EventTime ZERO = new EventTime(0L); private long value; // unit is femto seconds + public EventTime(Long value){ + this(value, Unit.FS); + } - public EventTime(Long value, String unit){ - setValue(value, unit); + public EventTime(Long value, Unit scale){ + setValue(value, scale); + } + + public static double getScalingFactor(Unit scale){ + return scales[scale.ordinal()]; } public long getValue(){ return(value); } - public double getScaledValue(double scale){ - return value/scale; + public double getScaledValue(Unit scale){ + return value/scales[scale.ordinal()]; } - public double getValueNS(){ - return getScaledValue(NS); - } - - public double getValueMS(){ - return getScaledValue(MS); - } - public void setValue(long value){ this.value=value; } - public void setValue(long value, String unit){ - this.value=value; - if("fs".compareToIgnoreCase(unit)==0) - this.value=value; - else if("ps".compareToIgnoreCase(unit)==0) - this.value=value*1000; - else if("ns".compareToIgnoreCase(unit)==0) - this.value=value*1000000; - else if("us".compareToIgnoreCase(unit)==0) - this.value=value*1000000000; - else if("ms".compareToIgnoreCase(unit)==0) - this.value=value*1000000000000L; - else if("s".compareToIgnoreCase(unit)==0) - this.value=value*1000000000000000L; - else { - System.err.print("Don't know what to do with "+unit+"\n"); - } + public void setValue(long value, Unit scale){ + this.value=(long) (value*scales[scale.ordinal()]); } public String toString(){ - return value/1000000 +"ns"; + return value/scales[Unit.NS.ordinal()] +"ns"; } @Override diff --git a/com.minres.scviewer.database/src/com/minres/scviewer/database/vcd/VCDDb.java b/com.minres.scviewer.database/src/com/minres/scviewer/database/vcd/VCDDb.java index ead19af..177280f 100644 --- a/com.minres.scviewer.database/src/com/minres/scviewer/database/vcd/VCDDb.java +++ b/com.minres.scviewer.database/src/com/minres/scviewer/database/vcd/VCDDb.java @@ -28,7 +28,7 @@ import com.minres.scviewer.database.SignalChange; public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder { - private static final String TIME_RES = "ps"; + private static final EventTime.Unit TIME_RES = EventTime.Unit.PS; /** The module stack. */ private Stack moduleStack; diff --git a/com.minres.scviewer.feature/feature.xml b/com.minres.scviewer.feature/feature.xml index 73a9b1e..65218da 100644 --- a/com.minres.scviewer.feature/feature.xml +++ b/com.minres.scviewer.feature/feature.xml @@ -28,6 +28,7 @@ http://www.eclipse.org/legal/epl-v10.html + @@ -42,7 +43,8 @@ http://www.eclipse.org/legal/epl-v10.html - + + + + diff --git a/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/SignalWidget.java b/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/SignalWidget.java index 1f31d90..ac66609 100644 --- a/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/SignalWidget.java +++ b/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/SignalWidget.java @@ -26,7 +26,7 @@ public class SignalWidget extends Canvas implements IWaveformWidget{ static final int trackInset = 1; static final int txHeight = trackHeight - 2 * trackInset; - static double zoomFactor = EventTime.NS; + static double zoomFactor = EventTime.getScalingFactor(EventTime.Unit.NS); private Color lineColor; private Color trackBgColor; private Color color0; @@ -76,8 +76,8 @@ public class SignalWidget extends Canvas implements IWaveformWidget{ gc.fillRectangle(new Rectangle(e.x, e.y, e.width, e.height)); ISignalChange lastChange = null; NavigableSet visibleChanges = signal.getSignalChangesByTimes( - new EventTime((long) (e.x*zoomFactor), "fs"), - new EventTime((long) ((e.x+e.width)*zoomFactor), "fs")); + new EventTime((long) (e.x*zoomFactor)), + new EventTime((long) ((e.x+e.width)*zoomFactor))); for(ISignalChange actChange:visibleChanges){ if(lastChange!=null){ drawValues(e, gc, lastChange, actChange); diff --git a/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/Track.java b/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/Track.java index 7eec62f..3f806d4 100644 --- a/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/Track.java +++ b/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/Track.java @@ -31,7 +31,7 @@ public class Track extends Composite implements IWaveformWidget, MouseListener { static final int trackInset = 1; static final int txHeight = trackHeight - 2 * trackInset; - static double zoomFactor = EventTime.NS; + static double zoomFactor = EventTime.getScalingFactor(EventTime.Unit.NS); private Color lineColor; private Color trackBgColor; diff --git a/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/TxDisplay.java b/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/TxDisplay.java index 8d3db1a..9aa017b 100644 --- a/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/TxDisplay.java +++ b/com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/TxDisplay.java @@ -59,7 +59,10 @@ import com.minres.scviewer.database.IWaveform; public class TxDisplay implements PropertyChangeListener, ISelectionProvider, MouseListener{ - private ListenerList listeners = new ListenerList(); + private static final String VALUEWIDGET = "VALUEWIDGET"; + private static final String NAMEWIDGET = "NAMEWIDGET"; + private static final String WAVEFORM = "WAVEFORM"; + private ListenerList listeners = new ListenerList(); private ITxStream currentStreamSelection; private ITx currentSelection; private ScrolledComposite valueListScrolled; @@ -207,16 +210,16 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo LinkedListtoAdd = new LinkedList(); toAdd.addAll(streams); for(Control child:trackList.getChildren()){ - IWaveform stream=(IWaveform) child.getData("WAVEFORM"); + IWaveform stream=(IWaveform) child.getData(WAVEFORM); if(!streams.contains(stream)){ child.setVisible(false); - ((Control)(child.getData("NAMEWIDGET"))).setVisible(false); - ((Control)(child.getData("VALUEWIDGET"))).setVisible(false); + ((Control)(child.getData(NAMEWIDGET))).setVisible(false); + ((Control)(child.getData(VALUEWIDGET))).setVisible(false); }else{ toAdd.remove(stream); child.setVisible(true); - ((Control)(child.getData("NAMEWIDGET"))).setVisible(true); - ((Control)(child.getData("VALUEWIDGET"))).setVisible(true); + ((Control)(child.getData(NAMEWIDGET))).setVisible(true); + ((Control)(child.getData(VALUEWIDGET))).setVisible(true); } } for(IWaveform wave: toAdd){ @@ -224,7 +227,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo ITxStream stream = (ITxStream) wave; Track track = new Track(trackList,SWT.NONE); track.setTransactions(stream.getTransactions()); - track.setData("WAVEFORM", stream); + track.setData(WAVEFORM, stream); track.addMouseListener(this); Point trackSize = track.computeSize(SWT.DEFAULT,SWT.DEFAULT); @@ -232,20 +235,24 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo trackName.setText(stream.getFullName()); RowData trackNamelayoutData = new RowData(SWT.DEFAULT, trackSize.y); trackName.setLayoutData(trackNamelayoutData); - track.setData("NAMEWIDGET", trackName); + trackName.setData(WAVEFORM, stream); + trackName.addMouseListener(this); + track.setData(NAMEWIDGET, trackName); Label trackValue = new Label(valueList, SWT.NONE); trackValue.setText("-"); RowData trackValuelayoutData = new RowData(SWT.DEFAULT, trackSize.y); trackValue.setLayoutData(trackValuelayoutData); - track.setData("VALUEWIDGET", trackValue); + trackValue.setData(WAVEFORM, stream); + trackValue.addMouseListener(this); + track.setData(VALUEWIDGET, trackValue); trackMap.put(stream, track); } else if(wave instanceof ISignal){ @SuppressWarnings("unchecked") ISignal isignal = (ISignal) wave; SignalWidget signal = new SignalWidget(trackList, SWT.NONE); signal.setTransactions(isignal); - signal.setData("WAVEFORM", isignal); + signal.setData(WAVEFORM, isignal); signal.addMouseListener(this); Point trackSize = signal.computeSize(SWT.DEFAULT,SWT.DEFAULT); @@ -253,13 +260,17 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo trackName.setText(isignal.getFullName()); RowData trackNamelayoutData = new RowData(SWT.DEFAULT, trackSize.y); trackName.setLayoutData(trackNamelayoutData); - signal.setData("NAMEWIDGET", trackName); + trackName.setData(WAVEFORM, isignal); + trackName.addMouseListener(this); + signal.setData(NAMEWIDGET, trackName); Label trackValue = new Label(valueList, SWT.NONE); trackValue.setText("-"); RowData trackValuelayoutData = new RowData(SWT.DEFAULT, trackSize.y); trackValue.setLayoutData(trackValuelayoutData); - signal.setData("VALUEWIDGET", trackValue); + trackValue.setData(WAVEFORM, isignal); + trackValue.addMouseListener(this); + signal.setData(VALUEWIDGET, trackValue); trackMap.put(isignal, signal); } } @@ -353,7 +364,10 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo StructuredSelection sel = new StructuredSelection(((Transaction)e.data).getData()); setSelection(sel); }else if(e.widget instanceof Track){ - StructuredSelection sel = new StructuredSelection(new Object[]{ ((Track)e.widget).getData()}); + StructuredSelection sel = new StructuredSelection(new Object[]{ e.widget.getData(WAVEFORM)}); + setSelection(sel); + }else if(e.widget instanceof Label){ + StructuredSelection sel = new StructuredSelection(new Object[]{ e.widget.getData(WAVEFORM)}); setSelection(sel); } }