Refactored time representation
This commit is contained in:
parent
b34b836b5f
commit
9553fbff8c
|
@ -48,12 +48,12 @@ public class SQLiteDb extends HierNode implements IWaveformDb {
|
|||
try {
|
||||
List<ScvTxEvent> 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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -11,61 +11,59 @@
|
|||
package com.minres.scviewer.database;
|
||||
|
||||
public class EventTime implements Comparable<EventTime>{
|
||||
public enum Unit {
|
||||
FS("fs"), PS("ps"), NS("ns"), US("us"), MS("ms"), SEC("s");
|
||||
|
||||
public static final double NS = 1000000.0;
|
||||
private String alternative;
|
||||
private Unit(String alternative){
|
||||
this.alternative=alternative;
|
||||
}
|
||||
|
||||
public static final double MS = 1000000000.0;
|
||||
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 EventTime ZERO = new EventTime(0L, "fs");
|
||||
static final double[] scales = {1,1000.0,1000000.0,1000000000.0,1000000000000.0};
|
||||
|
||||
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 getValueNS(){
|
||||
return getScaledValue(NS);
|
||||
}
|
||||
|
||||
public double getValueMS(){
|
||||
return getScaledValue(MS);
|
||||
public double getScaledValue(Unit scale){
|
||||
return value/scales[scale.ordinal()];
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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<String> moduleStack;
|
||||
|
|
|
@ -28,6 +28,7 @@ http://www.eclipse.org/legal/epl-v10.html
|
|||
</url>
|
||||
|
||||
<requires>
|
||||
<import plugin="com.minres.scviewer.database" version="1.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.codehaus.groovy" version="1.8.6" match="greaterOrEqual"/>
|
||||
<import plugin="org.eclipse.equinox.util" version="1.0.500" match="greaterOrEqual"/>
|
||||
<import plugin="org.eclipse.equinox.ds" version="1.4.200" match="greaterOrEqual"/>
|
||||
|
@ -42,7 +43,8 @@ http://www.eclipse.org/legal/epl-v10.html
|
|||
<import plugin="org.eclipse.ui.views.properties.tabbed"/>
|
||||
<import plugin="org.eclipse.swt"/>
|
||||
<import plugin="org.eclipse.ui.views"/>
|
||||
<import plugin="com.minres.scviewer.database" version="1.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.ant"/>
|
||||
<import plugin="org.junit"/>
|
||||
</requires>
|
||||
|
||||
<plugin
|
||||
|
@ -73,4 +75,10 @@ http://www.eclipse.org/legal/epl-v10.html
|
|||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="org.codehaus.groovy"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"/>
|
||||
|
||||
</feature>
|
||||
|
|
|
@ -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<ISignalChange> 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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -59,6 +59,9 @@ import com.minres.scviewer.database.IWaveform;
|
|||
|
||||
public class TxDisplay implements PropertyChangeListener, ISelectionProvider, MouseListener{
|
||||
|
||||
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;
|
||||
|
@ -207,16 +210,16 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
|||
LinkedList<IWaveform>toAdd = new LinkedList<IWaveform>();
|
||||
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<ISignalChange> isignal = (ISignal<ISignalChange>) 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue