Refactored time representation
This commit is contained in:
parent
b34b836b5f
commit
9553fbff8c
|
@ -48,12 +48,12 @@ public class SQLiteDb extends HierNode implements IWaveformDb {
|
||||||
try {
|
try {
|
||||||
List<ScvTxEvent> event = handler.selectObjects();
|
List<ScvTxEvent> event = handler.selectObjects();
|
||||||
if(event.size()>0)
|
if(event.size()>0)
|
||||||
return new EventTime(event.get(0).getTime(), "fs");
|
return new EventTime(event.get(0).getTime());
|
||||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return new EventTime(0L, "s");
|
return EventTime.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class Tx implements ITx {
|
||||||
trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal());
|
trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal());
|
||||||
try {
|
try {
|
||||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
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
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||||
|
@ -73,7 +73,7 @@ public class Tx implements ITx {
|
||||||
trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal());
|
trStream.getDb().getDb(), "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal());
|
||||||
try {
|
try {
|
||||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
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
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||||
|
|
|
@ -11,61 +11,59 @@
|
||||||
package com.minres.scviewer.database;
|
package com.minres.scviewer.database;
|
||||||
|
|
||||||
public class EventTime implements Comparable<EventTime>{
|
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
|
private long value; // unit is femto seconds
|
||||||
|
|
||||||
|
public EventTime(Long value){
|
||||||
|
this(value, Unit.FS);
|
||||||
|
}
|
||||||
|
|
||||||
public EventTime(Long value, String unit){
|
public EventTime(Long value, Unit scale){
|
||||||
setValue(value, unit);
|
setValue(value, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getScalingFactor(Unit scale){
|
||||||
|
return scales[scale.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getValue(){
|
public long getValue(){
|
||||||
return(value);
|
return(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getScaledValue(double scale){
|
public double getScaledValue(Unit scale){
|
||||||
return value/scale;
|
return value/scales[scale.ordinal()];
|
||||||
}
|
|
||||||
|
|
||||||
public double getValueNS(){
|
|
||||||
return getScaledValue(NS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getValueMS(){
|
|
||||||
return getScaledValue(MS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(long value){
|
public void setValue(long value){
|
||||||
this.value=value;
|
this.value=value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(long value, String unit){
|
public void setValue(long value, Unit scale){
|
||||||
this.value=value;
|
this.value=(long) (value*scales[scale.ordinal()]);
|
||||||
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 String toString(){
|
public String toString(){
|
||||||
return value/1000000 +"ns";
|
return value/scales[Unit.NS.ordinal()] +"ns";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,7 +28,7 @@ import com.minres.scviewer.database.SignalChange;
|
||||||
public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder {
|
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. */
|
/** The module stack. */
|
||||||
private Stack<String> moduleStack;
|
private Stack<String> moduleStack;
|
||||||
|
|
|
@ -28,6 +28,7 @@ http://www.eclipse.org/legal/epl-v10.html
|
||||||
</url>
|
</url>
|
||||||
|
|
||||||
<requires>
|
<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.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.util" version="1.0.500" match="greaterOrEqual"/>
|
||||||
<import plugin="org.eclipse.equinox.ds" version="1.4.200" 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.ui.views.properties.tabbed"/>
|
||||||
<import plugin="org.eclipse.swt"/>
|
<import plugin="org.eclipse.swt"/>
|
||||||
<import plugin="org.eclipse.ui.views"/>
|
<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>
|
</requires>
|
||||||
|
|
||||||
<plugin
|
<plugin
|
||||||
|
@ -73,4 +75,10 @@ http://www.eclipse.org/legal/epl-v10.html
|
||||||
version="0.0.0"
|
version="0.0.0"
|
||||||
unpack="false"/>
|
unpack="false"/>
|
||||||
|
|
||||||
|
<plugin
|
||||||
|
id="org.codehaus.groovy"
|
||||||
|
download-size="0"
|
||||||
|
install-size="0"
|
||||||
|
version="0.0.0"/>
|
||||||
|
|
||||||
</feature>
|
</feature>
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class SignalWidget extends Canvas implements IWaveformWidget{
|
||||||
static final int trackInset = 1;
|
static final int trackInset = 1;
|
||||||
static final int txHeight = trackHeight - 2 * trackInset;
|
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 lineColor;
|
||||||
private Color trackBgColor;
|
private Color trackBgColor;
|
||||||
private Color color0;
|
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));
|
gc.fillRectangle(new Rectangle(e.x, e.y, e.width, e.height));
|
||||||
ISignalChange lastChange = null;
|
ISignalChange lastChange = null;
|
||||||
NavigableSet<ISignalChange> visibleChanges = signal.getSignalChangesByTimes(
|
NavigableSet<ISignalChange> visibleChanges = signal.getSignalChangesByTimes(
|
||||||
new EventTime((long) (e.x*zoomFactor), "fs"),
|
new EventTime((long) (e.x*zoomFactor)),
|
||||||
new EventTime((long) ((e.x+e.width)*zoomFactor), "fs"));
|
new EventTime((long) ((e.x+e.width)*zoomFactor)));
|
||||||
for(ISignalChange actChange:visibleChanges){
|
for(ISignalChange actChange:visibleChanges){
|
||||||
if(lastChange!=null){
|
if(lastChange!=null){
|
||||||
drawValues(e, gc, lastChange, actChange);
|
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 trackInset = 1;
|
||||||
static final int txHeight = trackHeight - 2 * trackInset;
|
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 lineColor;
|
||||||
private Color trackBgColor;
|
private Color trackBgColor;
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,10 @@ import com.minres.scviewer.database.IWaveform;
|
||||||
|
|
||||||
public class TxDisplay implements PropertyChangeListener, ISelectionProvider, MouseListener{
|
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 ITxStream currentStreamSelection;
|
||||||
private ITx currentSelection;
|
private ITx currentSelection;
|
||||||
private ScrolledComposite valueListScrolled;
|
private ScrolledComposite valueListScrolled;
|
||||||
|
@ -207,16 +210,16 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
||||||
LinkedList<IWaveform>toAdd = new LinkedList<IWaveform>();
|
LinkedList<IWaveform>toAdd = new LinkedList<IWaveform>();
|
||||||
toAdd.addAll(streams);
|
toAdd.addAll(streams);
|
||||||
for(Control child:trackList.getChildren()){
|
for(Control child:trackList.getChildren()){
|
||||||
IWaveform stream=(IWaveform) child.getData("WAVEFORM");
|
IWaveform stream=(IWaveform) child.getData(WAVEFORM);
|
||||||
if(!streams.contains(stream)){
|
if(!streams.contains(stream)){
|
||||||
child.setVisible(false);
|
child.setVisible(false);
|
||||||
((Control)(child.getData("NAMEWIDGET"))).setVisible(false);
|
((Control)(child.getData(NAMEWIDGET))).setVisible(false);
|
||||||
((Control)(child.getData("VALUEWIDGET"))).setVisible(false);
|
((Control)(child.getData(VALUEWIDGET))).setVisible(false);
|
||||||
}else{
|
}else{
|
||||||
toAdd.remove(stream);
|
toAdd.remove(stream);
|
||||||
child.setVisible(true);
|
child.setVisible(true);
|
||||||
((Control)(child.getData("NAMEWIDGET"))).setVisible(true);
|
((Control)(child.getData(NAMEWIDGET))).setVisible(true);
|
||||||
((Control)(child.getData("VALUEWIDGET"))).setVisible(true);
|
((Control)(child.getData(VALUEWIDGET))).setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(IWaveform wave: toAdd){
|
for(IWaveform wave: toAdd){
|
||||||
|
@ -224,7 +227,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
||||||
ITxStream stream = (ITxStream) wave;
|
ITxStream stream = (ITxStream) wave;
|
||||||
Track track = new Track(trackList,SWT.NONE);
|
Track track = new Track(trackList,SWT.NONE);
|
||||||
track.setTransactions(stream.getTransactions());
|
track.setTransactions(stream.getTransactions());
|
||||||
track.setData("WAVEFORM", stream);
|
track.setData(WAVEFORM, stream);
|
||||||
track.addMouseListener(this);
|
track.addMouseListener(this);
|
||||||
Point trackSize = track.computeSize(SWT.DEFAULT,SWT.DEFAULT);
|
Point trackSize = track.computeSize(SWT.DEFAULT,SWT.DEFAULT);
|
||||||
|
|
||||||
|
@ -232,20 +235,24 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
||||||
trackName.setText(stream.getFullName());
|
trackName.setText(stream.getFullName());
|
||||||
RowData trackNamelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
RowData trackNamelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
||||||
trackName.setLayoutData(trackNamelayoutData);
|
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);
|
Label trackValue = new Label(valueList, SWT.NONE);
|
||||||
trackValue.setText("-");
|
trackValue.setText("-");
|
||||||
RowData trackValuelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
RowData trackValuelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
||||||
trackValue.setLayoutData(trackValuelayoutData);
|
trackValue.setLayoutData(trackValuelayoutData);
|
||||||
track.setData("VALUEWIDGET", trackValue);
|
trackValue.setData(WAVEFORM, stream);
|
||||||
|
trackValue.addMouseListener(this);
|
||||||
|
track.setData(VALUEWIDGET, trackValue);
|
||||||
trackMap.put(stream, track);
|
trackMap.put(stream, track);
|
||||||
} else if(wave instanceof ISignal<?>){
|
} else if(wave instanceof ISignal<?>){
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ISignal<ISignalChange> isignal = (ISignal<ISignalChange>) wave;
|
ISignal<ISignalChange> isignal = (ISignal<ISignalChange>) wave;
|
||||||
SignalWidget signal = new SignalWidget(trackList, SWT.NONE);
|
SignalWidget signal = new SignalWidget(trackList, SWT.NONE);
|
||||||
signal.setTransactions(isignal);
|
signal.setTransactions(isignal);
|
||||||
signal.setData("WAVEFORM", isignal);
|
signal.setData(WAVEFORM, isignal);
|
||||||
signal.addMouseListener(this);
|
signal.addMouseListener(this);
|
||||||
Point trackSize = signal.computeSize(SWT.DEFAULT,SWT.DEFAULT);
|
Point trackSize = signal.computeSize(SWT.DEFAULT,SWT.DEFAULT);
|
||||||
|
|
||||||
|
@ -253,13 +260,17 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
||||||
trackName.setText(isignal.getFullName());
|
trackName.setText(isignal.getFullName());
|
||||||
RowData trackNamelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
RowData trackNamelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
||||||
trackName.setLayoutData(trackNamelayoutData);
|
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);
|
Label trackValue = new Label(valueList, SWT.NONE);
|
||||||
trackValue.setText("-");
|
trackValue.setText("-");
|
||||||
RowData trackValuelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
RowData trackValuelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
||||||
trackValue.setLayoutData(trackValuelayoutData);
|
trackValue.setLayoutData(trackValuelayoutData);
|
||||||
signal.setData("VALUEWIDGET", trackValue);
|
trackValue.setData(WAVEFORM, isignal);
|
||||||
|
trackValue.addMouseListener(this);
|
||||||
|
signal.setData(VALUEWIDGET, trackValue);
|
||||||
trackMap.put(isignal, signal);
|
trackMap.put(isignal, signal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,7 +364,10 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
|
||||||
StructuredSelection sel = new StructuredSelection(((Transaction)e.data).getData());
|
StructuredSelection sel = new StructuredSelection(((Transaction)e.data).getData());
|
||||||
setSelection(sel);
|
setSelection(sel);
|
||||||
}else if(e.widget instanceof Track){
|
}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);
|
setSelection(sel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue