Added UI support for real value signals
This commit is contained in:
@ -25,6 +25,7 @@ import org.eclipse.swt.graphics.Rectangle;
|
||||
import com.minres.scviewer.database.ISignal;
|
||||
import com.minres.scviewer.database.ISignalChange;
|
||||
import com.minres.scviewer.database.ISignalChangeMulti;
|
||||
import com.minres.scviewer.database.ISignalChangeReal;
|
||||
import com.minres.scviewer.database.ISignalChangeSingle;
|
||||
import com.minres.scviewer.database.ui.TrackEntry;
|
||||
import com.minres.scviewer.database.ui.WaveformColors;
|
||||
@ -107,8 +108,13 @@ public class SignalPainter extends TrackPainter {
|
||||
NavigableMap<Long, ? extends ISignalChange> 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);
|
||||
SignalStencil stencil = left.value instanceof ISignalChangeSingle ? new SingleBitStencil() : new MultiBitStencil(gc);
|
||||
|
||||
SignalStencil stencil = null;
|
||||
if(left.value instanceof ISignalChangeSingle)
|
||||
stencil= new SingleBitStencil();
|
||||
else if(left.value instanceof ISignalChangeMulti)
|
||||
stencil= new MultiBitStencil(gc);
|
||||
else
|
||||
stencil= new RealStencil(left.value, entries);
|
||||
maxX = area.x + area.width;
|
||||
yOffsetT = this.waveCanvas.getTrackHeight() / 5 + area.y;
|
||||
yOffsetM = this.waveCanvas.getTrackHeight() / 2 + area.y;
|
||||
@ -122,7 +128,6 @@ public class SignalPainter extends TrackPainter {
|
||||
// b) left to close to right
|
||||
if (left.time == right.time) {
|
||||
right.time = endTime;
|
||||
|
||||
} else {
|
||||
multiple = true;
|
||||
long eTime = (xBegin + 1) * this.waveCanvas.getScaleFactor();
|
||||
@ -144,7 +149,9 @@ public class SignalPainter extends TrackPainter {
|
||||
if (xEnd == xBegin) {
|
||||
multiple = true;
|
||||
long eTime = (xBegin + 1) * this.waveCanvas.getScaleFactor();
|
||||
right.set(entries.floorEntry(eTime), endTime);
|
||||
Entry<Long, ? extends ISignalChange> entry = entries.floorEntry(eTime);
|
||||
if(entry!=null && entry.getKey()> right.time)
|
||||
right.set(entry, endTime);
|
||||
xEnd = getXEnd(eTime);
|
||||
}
|
||||
} while (left.time < endTime);
|
||||
@ -254,7 +261,84 @@ public class SignalPainter extends TrackPainter {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class RealStencil implements SignalStencil {
|
||||
double min;
|
||||
double max;
|
||||
double diff;
|
||||
|
||||
public RealStencil(ISignalChange value, NavigableMap<Long, ? extends ISignalChange> entries) {
|
||||
min=((ISignalChangeReal) value).getValue();
|
||||
max=min;
|
||||
for (ISignalChange e : entries.values()) {
|
||||
double v = ((ISignalChangeReal)e).getValue();
|
||||
max= Double.isNaN(max)? v : Math.max(max, v);
|
||||
min= Double.isNaN(min)? v : Math.min(min, v);
|
||||
}
|
||||
int nans = (Double.isNaN(max)?2:0) + (Double.isNaN(max)?1:0);
|
||||
switch(nans) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
max=min;
|
||||
break;
|
||||
case 2:
|
||||
min=max;
|
||||
case 3:
|
||||
max=min=0;
|
||||
}
|
||||
diff=max-min;
|
||||
if(diff==0.0) {
|
||||
if(max>0)
|
||||
min=0.0;
|
||||
else if(min<0.0)
|
||||
max=0.0;
|
||||
else {
|
||||
max=1.0;
|
||||
min=0.0;
|
||||
}
|
||||
diff=max-min;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(GC gc, Rectangle area, ISignalChange left, ISignalChange right, int xBegin, int xEnd, boolean multiple) {
|
||||
double value = ((ISignalChangeReal)left).getValue();
|
||||
if(Double.isNaN(value)) {
|
||||
Color color = waveCanvas.colors[WaveformColors.SIGNAL_NAN.ordinal()];
|
||||
int width = xEnd - xBegin;
|
||||
if (width > 1) {
|
||||
int[] points = {
|
||||
xBegin, yOffsetT,
|
||||
xEnd, yOffsetT,
|
||||
xEnd, yOffsetB,
|
||||
xBegin, yOffsetB
|
||||
};
|
||||
gc.setForeground(color);
|
||||
gc.drawPolygon(points);
|
||||
gc.setBackground(color);
|
||||
gc.fillPolygon(points);
|
||||
} else {
|
||||
gc.setForeground(color);
|
||||
gc.drawLine(xEnd, yOffsetT, xEnd, yOffsetB);
|
||||
}
|
||||
} else {
|
||||
Color color = waveCanvas.colors[WaveformColors.SIGNAL_ANALOG.ordinal()];
|
||||
int height=yOffsetT-yOffsetB;
|
||||
double offset=value-min;
|
||||
int yOffset=diff>0?(int)(height*(offset/diff)) + yOffsetB:yOffsetM;
|
||||
gc.setForeground(color);
|
||||
if (xEnd > maxX) {
|
||||
gc.drawLine(xBegin, yOffset, maxX, yOffset);
|
||||
} else {
|
||||
gc.drawLine(xBegin, yOffset, xEnd, yOffset);
|
||||
double nextOffset = ((ISignalChangeReal)right).getValue()-min;
|
||||
int yNext = diff>0?(int)(height*(nextOffset/diff)) + yOffsetB:height/2;
|
||||
if (yOffset != yNext)
|
||||
gc.drawLine(xEnd, yOffset, xEnd, yNext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ISignal<? extends ISignalChange> getSignal() {
|
||||
|
@ -156,6 +156,8 @@ public class WaveformCanvas extends Canvas {
|
||||
colors[WaveformColors.SIGNALZ.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_YELLOW);
|
||||
colors[WaveformColors.SIGNALX.ordinal()] = SWTResourceManager.getColor(255, 51, 51);
|
||||
colors[WaveformColors.SIGNALU.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
|
||||
colors[WaveformColors.SIGNAL_ANALOG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN);
|
||||
colors[WaveformColors.SIGNAL_NAN.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
|
||||
colors[WaveformColors.SIGNAL_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE);
|
||||
colors[WaveformColors.CURSOR.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
|
||||
colors[WaveformColors.CURSOR_DRAG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY);
|
||||
|
@ -72,6 +72,7 @@ import com.google.common.collect.Lists;
|
||||
import com.minres.scviewer.database.ISignal;
|
||||
import com.minres.scviewer.database.ISignalChange;
|
||||
import com.minres.scviewer.database.ISignalChangeMulti;
|
||||
import com.minres.scviewer.database.ISignalChangeReal;
|
||||
import com.minres.scviewer.database.ISignalChangeSingle;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
@ -458,6 +459,8 @@ public class WaveformViewer implements IWaveformViewer {
|
||||
entry.setValue("b'"+((ISignalChangeSingle)event).getValue());
|
||||
} else if(event instanceof ISignalChangeMulti){
|
||||
entry.setValue("h'"+((ISignalChangeMulti)event).getValue().toHexString());
|
||||
} else if(event instanceof ISignalChangeReal){
|
||||
entry.setValue(Double.toString(((ISignalChangeReal)event).getValue()));
|
||||
}
|
||||
} else if(entry.getKey() instanceof ITxStream<?>){
|
||||
ITxStream<?> stream = (ITxStream<?>) entry.getKey();
|
||||
|
Reference in New Issue
Block a user