- Fixed navigation and selection issue

- added some null checking
- corrected direction of releations
This commit is contained in:
ejentzsx 2015-02-11 09:32:46 +01:00
parent 54fb59db04
commit af1f21cac9
9 changed files with 134 additions and 78 deletions

View File

@ -85,6 +85,7 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
@Override
public boolean load(IWaveformDb db, File file) throws Exception {
this.db=db;
streams=null;
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[x.length];
int read = fis.read(buffer, 0, x.length);

View File

@ -10,7 +10,6 @@
*******************************************************************************/
package com.minres.scviewer.database.swt;
import java.awt.PageAttributes.OriginType;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
@ -60,11 +59,11 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
import swing2swt.layout.BorderLayout;
import com.google.common.collect.Lists;
import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxEvent;
@ -213,15 +212,17 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int y = ((ScrollBar) e.widget).getSelection();
valueListScrolled.setOrigin(valueListScrolled.getOrigin().x, y);
trackList.setOrigin(trackList.getOrigin().x, y);
Point v = valueListScrolled.getOrigin();
valueListScrolled.setOrigin(v.x, y);
Point t = trackList.getOrigin();
trackList.setOrigin(t.x, -y);
}
});
valueListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int y = ((ScrollBar) e.widget).getSelection();
nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y);
trackList.setOrigin(trackList.getOrigin().x, y);
trackList.setOrigin(trackList.getOrigin().x, -y);
}
});
trackList.addSelectionListener(new SelectionAdapter() {
@ -355,6 +356,11 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
public void setSelection(ISelection selection) {
boolean selectionChanged = false;
if (selection instanceof IStructuredSelection) {
if(((IStructuredSelection) selection).size()==0){
selectionChanged = currentSelection!=null||currentWaveformSelection!=null;
currentSelection = null;
currentWaveformSelection = null;
} else {
Object sel = ((IStructuredSelection) selection).getFirstElement();
if (sel instanceof ITx && currentSelection != sel) {
currentSelection = (ITx) sel;
@ -365,6 +371,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
currentWaveformSelection = (IWaveform<? extends IWaveformEvent>) sel;
selectionChanged = true;
}
}
} else {
if (currentSelection != null || currentWaveformSelection != null)
selectionChanged = true;
@ -392,9 +399,20 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
ITxStream<ITxEvent> stream = (ITxStream<ITxEvent>) currentWaveformSelection;
ITx transaction = null;
if (direction == GotoDirection.NEXT) {
List<ITxEvent> thisEntryList = stream.getEvents().get(currentSelection.getBeginTime());
boolean meFound=false;
for (ITxEvent evt : thisEntryList) {
if (evt.getType() == ITxEvent.Type.BEGIN) {
if(meFound){
transaction = evt.getTransaction();
break;
}
meFound|= evt.getTransaction().getId()==currentSelection.getId();
}
}
if (transaction == null){
Entry<Long, List<ITxEvent>> entry = stream.getEvents().higherEntry(currentSelection.getBeginTime());
if (entry != null)
do {
if (entry != null) do {
for (ITxEvent evt : entry.getValue()) {
if (evt.getType() == ITxEvent.Type.BEGIN) {
transaction = evt.getTransaction();
@ -404,13 +422,24 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
if (transaction == null)
entry = stream.getEvents().higherEntry(entry.getKey());
} while (entry != null && transaction == null);
}
} else if (direction == GotoDirection.PREV) {
List<ITxEvent> thisEntryList = stream.getEvents().get(currentSelection.getBeginTime());
boolean meFound=false;
for (ITxEvent evt : Lists.reverse(thisEntryList)) {
if (evt.getType() == ITxEvent.Type.BEGIN) {
if(meFound){
transaction = evt.getTransaction();
break;
}
meFound|= evt.getTransaction().getId()==currentSelection.getId();
}
}
if (transaction == null){
Entry<Long, List<ITxEvent>> entry = stream.getEvents().lowerEntry(currentSelection.getBeginTime());
if (entry != null)
do {
System.out.println(currentSelection.getBeginTime() + " -> " + entry.getKey());
for (ITxEvent evt : entry.getValue()) {
System.out.println("\t-> " + evt.toString());
for (ITxEvent evt : Lists.reverse(entry.getValue())) {
if (evt.getType() == ITxEvent.Type.BEGIN) {
transaction = evt.getTransaction();
break;
@ -420,6 +449,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
entry = stream.getEvents().lowerEntry(entry.getKey());
} while (entry != null && transaction == null);
}
}
if (transaction != null) {
setSelection(new StructuredSelection(transaction));
}

View File

@ -63,6 +63,9 @@ public class SignalPainter implements IWaveformPainter {
if(left.getValue() instanceof ISignalChangeSingle){
NavigableMap<Long, ? extends ISignalChange> entries=signal.getEvents().subMap(firstChange.getKey(), false, lastTx.getKey(), true);
for(Entry<Long, ? extends ISignalChange> right:entries.entrySet()){
int xEnd= (int)(right.getKey()/this.waveCanvas.getScaleFactor());
int xBegin= (int)(left.getKey()/this.waveCanvas.getScaleFactor());
if(xEnd>xBegin){
int yOffset = this.waveCanvas.getTrackHeight()/2;
Color color = this.waveCanvas.colors[WaveformCanvas.Colors.SIGNALX.ordinal()];
switch(((ISignalChangeSingle) left.getValue()).getValue()){
@ -81,8 +84,7 @@ public class SignalPainter implements IWaveformPainter {
}
yOffset+=area.y;
gc.setForeground(color);
int xEnd= (int)(right.getKey()/this.waveCanvas.getScaleFactor());
gc.drawLine((int)(left.getKey()/this.waveCanvas.getScaleFactor()), yOffset, xEnd, yOffset);
gc.drawLine(xBegin, yOffset, xEnd, yOffset);
int yNext = this.waveCanvas.getTrackHeight()/2;
switch(((ISignalChangeSingle) right.getValue()).getValue()){
case '1':
@ -94,6 +96,7 @@ public class SignalPainter implements IWaveformPainter {
default:
}
gc.drawLine(xEnd, yOffset, xEnd, yNext);
}
left=right;
}
} else if(left.getValue() instanceof ISignalChangeMulti){

View File

@ -56,7 +56,7 @@ public class StreamPainter implements IWaveformPainter{
else
gc.setBackground(this.waveCanvas.colors[even?WaveformCanvas.Colors.TRACK_BG_EVEN.ordinal():WaveformCanvas.Colors.TRACK_BG_ODD.ordinal()]);
gc.setFillRule(SWT.FILL_EVEN_ODD);
gc.fillRectangle(area);
gc.fillRectangle(0,0,area.width, area.height);
Entry<Long, ?> firstTx=stream.getEvents().floorEntry(area.x*waveCanvas.getScaleFactor());
Entry<Long, ?> lastTx=stream.getEvents().ceilingEntry((area.x+area.width)*waveCanvas.getScaleFactor());
if(firstTx==null) firstTx = stream.getEvents().firstEntry();
@ -125,7 +125,7 @@ public class StreamPainter implements IWaveformPainter{
Entry<Long, List<ITxEvent>> firstTx=stream.getEvents().floorEntry(point.x*waveCanvas.getScaleFactor());
if(firstTx!=null){
do {
ITx tx = getTxFromEntry(lane, firstTx);
ITx tx = getTxFromEntry(lane, point.x, firstTx);
if(tx!=null) return tx;
firstTx=stream.getEvents().lowerEntry(firstTx.getKey());
}while(firstTx!=null);
@ -141,9 +141,20 @@ public class StreamPainter implements IWaveformPainter{
this.stream = stream;
}
protected ITx getTxFromEntry(int lane, Entry<Long, List<ITxEvent>> firstTx) {
protected ITx getTxFromEntry(int lane, int offset, Entry<Long, List<ITxEvent>> firstTx) {
long timePoint=offset*waveCanvas.getScaleFactor();
for(ITxEvent evt:firstTx.getValue()){
if(evt.getType()==ITxEvent.Type.BEGIN && evt.getTransaction().getConcurrencyIndex()==lane){
ITx tx=evt.getTransaction();
if(evt.getType()==ITxEvent.Type.BEGIN && tx.getConcurrencyIndex()==lane && tx.getBeginTime()<=timePoint && tx.getEndTime()>=timePoint){
return evt.getTransaction();
}
}
// now with some fuzziness
timePoint=(offset-5)*waveCanvas.getScaleFactor();
long timePointHigh=(offset+5)*waveCanvas.getScaleFactor();
for(ITxEvent evt:firstTx.getValue()){
ITx tx=evt.getTransaction();
if(evt.getType()==ITxEvent.Type.BEGIN && tx.getConcurrencyIndex()==lane && tx.getBeginTime()<=timePointHigh && tx.getEndTime()>=timePoint){
return evt.getTransaction();
}
}

View File

@ -295,14 +295,7 @@ public class WaveformCanvas extends Canvas {
vertical.setThumb(ch);
ruler.setScaleFactor(scaleFactor);
redraw();
Event e = new Event();
e.widget = this;
SelectionEvent ev = new SelectionEvent(e);
ev.x = origin.x;
ev.y = origin.y;
for (SelectionAdapter a : selectionListeners) {
a.widgetSelected(ev);
}
fireSelectionEvent();
}
@ -386,4 +379,21 @@ public class WaveformCanvas extends Canvas {
public void removeSelectionListener(SelectionAdapter selectionAdapter) {
selectionListeners.remove(selectionAdapter);
}
/**
*
*/
protected void fireSelectionEvent() {
Event e = new Event();
e.widget = this;
e.detail=SWT.SELECTED;
e.type=SWT.Selection;
SelectionEvent ev = new SelectionEvent(e);
ev.x = origin.x;
ev.y = origin.y;
for (SelectionAdapter a : selectionListeners) {
a.widgetSelected(ev);
}
}
}

View File

@ -142,8 +142,8 @@ public class TextDbLoader implements IWaveformDbLoader{
}
break
case "tx_relation"://matcher = line =~ /^tx_relation\s+\"(\S+)\"\s+(\d+)\s+(\d+)$/
Tx tr1= transactionsById[Integer.parseInt(tokens[2])]
Tx tr2= transactionsById[Integer.parseInt(tokens[3])]
Tx tr2= transactionsById[Integer.parseInt(tokens[2])]
Tx tr1= transactionsById[Integer.parseInt(tokens[3])]
def relType=tokens[1][1..-2]
if(!relationTypes.containsKey(relType)) relationTypes[relType]=new RelationType(relType)
def rel = new TxRelation(relationTypes[relType], tr1, tr2)

View File

@ -37,6 +37,7 @@ class Tx implements ITx {
this.stream=stream
this.generator=generator
this.beginTime=begin
this.endTime=begin
}
@Override

View File

@ -142,9 +142,9 @@ public class WaveformDb extends HierNode implements IWaveformDb {
private void updateMaxTime(IWaveform<?> waveform) {
Long last=0L;
if(waveform instanceof ITxStream<?>)
if(waveform instanceof ITxStream<?> && ((ITxStream<?>)waveform).getEvents().lastEntry()!=null)
last=((ITxStream<?>)waveform).getEvents().lastEntry().getKey();
else if(waveform instanceof ISignal<?>)
else if(waveform instanceof ISignal<?> && ((ISignal<?>)waveform).getEvents().lastEntry()!=null)
last=((ISignal<?>)waveform).getEvents().lastEntry().getKey();
if(last>maxTime)
maxTime=last;

View File

@ -358,7 +358,7 @@ static void relationCb(const scv_tr_handle& tr_1, const scv_tr_handle& tr_2, voi
if (tr_1.get_scv_tr_stream().get_scv_tr_db()->get_recording() == false) return;
try {
queryBuilder.str("");
queryBuilder << "INSERT INTO " TX_RELATION_TABLE " (name,src,sink)"
queryBuilder << "INSERT INTO " TX_RELATION_TABLE " (name,sink,src)"
<< "values ('" << tr_1.get_scv_tr_stream().get_scv_tr_db()->get_relation_name(relation_handle) << "',"
<< tr_1.get_id() << ","<< tr_2.get_id() << ");";
db.exec(queryBuilder.str().c_str());