added combined bit vectors
This commit is contained in:
1 parent
a4215fceb1
commit
42e0d83403
17 files changed
+1066
-14
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2026 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ui;
|
||||
|
||||
import java.util.List;
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
import com.minres.scviewer.database.CombinedBitVectorWaveform.SourceBit;
|
||||
import com.minres.scviewer.database.EventEntry;
|
||||
import com.minres.scviewer.database.WaveformType;
|
||||
|
||||
/** Selection and source normalization shared by the combine action and viewer. */
|
||||
public final class BitVectorComposition {
|
||||
private BitVectorComposition() { }
|
||||
|
||||
public static boolean isSingleBit(TrackEntry track) {
|
||||
if (track.waveform == null || track.waveform.getType() != WaveformType.SIGNAL
|
||||
|| track.waveform.getWidth() != 1) return false;
|
||||
EventEntry first = track.waveform.getEvents().firstEntry();
|
||||
return first == null || (first.events != null && first.events.length > 0
|
||||
&& first.events[first.events.length - 1] instanceof BitVector);
|
||||
}
|
||||
|
||||
public static List<TrackEntry> selectedBits(List<TrackEntry> roots, List<TrackEntry> selection) {
|
||||
List<TrackEntry> ordered = TrackEntry.visibleTracks(roots).stream()
|
||||
.filter(track -> selection.stream().anyMatch(selected -> selected == track)).toList();
|
||||
return ordered.size() >= 2 && ordered.size() == selection.size() && ordered.stream().allMatch(BitVectorComposition::isSingleBit)
|
||||
? ordered : List.of();
|
||||
}
|
||||
|
||||
public static List<SourceBit> sources(List<TrackEntry> tracks) {
|
||||
if (tracks.size() < 2 || !tracks.stream().allMatch(BitVectorComposition::isSingleBit))
|
||||
throw new IllegalArgumentException("Select at least two single-bit signals");
|
||||
return tracks.stream().map(track -> track.waveform instanceof BitWaveform bit
|
||||
? new SourceBit(bit.getSource(), bit.getBitIndex()) : new SourceBit(track.waveform, 0)).toList();
|
||||
}
|
||||
}
|
||||
+3
@@ -38,6 +38,9 @@ public final class BitWaveform extends HierNode implements IWaveform {
|
||||
}
|
||||
|
||||
@Override public String getFullName() { return source.getFullName() + getName(); }
|
||||
@Override public String getDisplayName() { return source.getDisplayName() + getName(); }
|
||||
public IWaveform getSource() { return source; }
|
||||
public int getBitIndex() { return bit; }
|
||||
@Override public DirectionType getDirection() { return source.getDirection(); }
|
||||
@Override public long getId() { return source.getId(); }
|
||||
@Override public WaveformType getType() { return WaveformType.SIGNAL; }
|
||||
|
||||
+2
-2
@@ -648,7 +648,7 @@ public class WaveformView implements IWaveformView {
|
||||
for (TrackEntry entry : TrackEntry.visibleTracks(streams)) {
|
||||
addPainter(even, entry);
|
||||
trackVerticalOffset.put(tracksVerticalHeight, entry);
|
||||
tl.setText(entry.waveform.getFullName());
|
||||
tl.setText(entry.waveform.getDisplayName());
|
||||
nameMaxWidth = Math.max(nameMaxWidth, tl.getBounds().width + nameIndent(entry)
|
||||
+ (entry.hierState == HierState.NONE && nameIndent(entry) == 0 ? 5 : 18));
|
||||
tracksVerticalHeight += entry.height;
|
||||
@@ -1261,7 +1261,7 @@ public class WaveformView implements IWaveformView {
|
||||
protected void drawName(GC gc, Rectangle subArea, Integer firstKey, TrackEntry entry) {
|
||||
IWaveform w = entry.waveform;
|
||||
subArea.height = w.getRowCount() * styleProvider.getTrackHeight();
|
||||
drawTextFormat(gc, subArea, firstKey, w.getFullName(), entry.selected, entry.hierState, nameIndent(entry));
|
||||
drawTextFormat(gc, subArea, firstKey, w.getDisplayName(), entry.selected, entry.hierState, nameIndent(entry));
|
||||
}
|
||||
|
||||
protected void drawValue(GC gc, Rectangle subArea, Integer yOffset, String value, boolean highlite) {
|
||||
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2026 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.UUID;
|
||||
|
||||
/** An immutable composition of recorded bits, listed from MSB to LSB.
|
||||
* Recording event lists must be immutable after loading. Range views merge lazily;
|
||||
* only a bounded set of sampled values is cached, never the entire merged timeline.
|
||||
*/
|
||||
public final class CombinedBitVectorWaveform extends HierNode implements IWaveform {
|
||||
public record SourceBit(IWaveform waveform, int bit) {
|
||||
public SourceBit {
|
||||
if (waveform == null || waveform.getType() != WaveformType.SIGNAL
|
||||
|| bit < 0 || bit >= waveform.getWidth())
|
||||
throw new IllegalArgumentException("Invalid source bit");
|
||||
}
|
||||
}
|
||||
|
||||
private final String identifier;
|
||||
private final List<SourceBit> sources;
|
||||
private final LazyValue<List<IEventList>> events = new LazyValue<>();
|
||||
private final Map<Long, BitValue[]> samples = new LinkedHashMap<>(32, .75f, true) {
|
||||
@Override protected boolean removeEldestEntry(Map.Entry<Long, BitValue[]> entry) { return size() > 256; }
|
||||
};
|
||||
private final IEventList timeline = new Timeline(0L, true, -1L, false);
|
||||
private record Seek(long time, boolean forward, boolean inclusive, long limit) { }
|
||||
private final Map<Seek, Long> positions = new LinkedHashMap<>(32, .75f, true) {
|
||||
@Override protected boolean removeEldestEntry(Map.Entry<Seek, Long> entry) { return size() > 256; }
|
||||
};
|
||||
|
||||
public CombinedBitVectorWaveform(String name, List<SourceBit> sources) {
|
||||
this("@combined:" + UUID.randomUUID(), name, sources);
|
||||
}
|
||||
|
||||
public CombinedBitVectorWaveform(String identifier, String name, List<SourceBit> sources) {
|
||||
super(name);
|
||||
if (identifier == null || !identifier.startsWith("@combined:") || identifier.length() <= 10
|
||||
|| name == null || name.isBlank() || sources == null || sources.size() < 2)
|
||||
throw new IllegalArgumentException("A combined vector needs an identity, a name and at least two bits");
|
||||
this.identifier = identifier;
|
||||
List<SourceBit> normalized = new ArrayList<>();
|
||||
for (SourceBit input : sources) {
|
||||
while (input.waveform() instanceof CombinedBitVectorWaveform combined)
|
||||
input = combined.sources.get(combined.getWidth() - 1 - input.bit());
|
||||
normalized.add(input);
|
||||
}
|
||||
this.sources = List.copyOf(normalized);
|
||||
}
|
||||
|
||||
public List<SourceBit> getSources() { return sources; }
|
||||
@Override public String getFullName() { return identifier; }
|
||||
@Override public String getDisplayName() { return getName(); }
|
||||
@Override public DirectionType getDirection() { return DirectionType.IMPLICIT; }
|
||||
@Override public long getId() { return identifier.hashCode(); }
|
||||
@Override public boolean isSame(IWaveform other) {
|
||||
return other instanceof CombinedBitVectorWaveform combined && identifier.equals(combined.identifier);
|
||||
}
|
||||
@Override public WaveformType getType() { return WaveformType.SIGNAL; }
|
||||
@Override public String getKind() { return "combined bitvector"; }
|
||||
@Override public int getWidth() { return sources.size(); }
|
||||
@Override public int getRowCount() { return 1; }
|
||||
@Override public IEventList getEvents() { return timeline; }
|
||||
@Override public IEvent[] getEventsAtTime(long time) { return timeline.get(time); }
|
||||
@Override public IEvent[] getEventsBeforeTime(long time) {
|
||||
EventEntry entry = timeline.floorEntry(time);
|
||||
return entry == null ? new IEvent[0] : entry.events;
|
||||
}
|
||||
|
||||
private List<IEventList> inputs() {
|
||||
return events.get(() -> sources.stream().map(bit -> bit.waveform().getEvents()).toList());
|
||||
}
|
||||
|
||||
private BitValue[] sample(long time) {
|
||||
synchronized (samples) {
|
||||
BitValue[] cached = samples.get(time);
|
||||
if (cached != null) return cached;
|
||||
}
|
||||
BitValue[] value = new BitValue[getWidth()];
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
EventEntry entry = inputs().get(i).floorEntry(time);
|
||||
value[i] = BitValue.X;
|
||||
if (entry != null && entry.events != null && entry.events.length > 0) {
|
||||
IEvent event = entry.events[entry.events.length - 1];
|
||||
if (!(event instanceof BitVector vector))
|
||||
throw new IllegalArgumentException("Source is not a bit signal: " + sources.get(i).waveform().getFullName());
|
||||
value[i] = vector.getValue(sources.get(i).bit());
|
||||
}
|
||||
}
|
||||
synchronized (samples) { samples.put(time, value); }
|
||||
return value;
|
||||
}
|
||||
|
||||
/** Find the next/previous timestamp in the union, before suppressing unchanged samples. */
|
||||
private Long candidate(long time, boolean forward, boolean inclusive) {
|
||||
Long result = null;
|
||||
for (IEventList input : inputs()) {
|
||||
EventEntry entry = forward ? (inclusive ? input.ceilingEntry(time) : input.higherEntry(time))
|
||||
: (inclusive ? input.floorEntry(time) : input.lowerEntry(time));
|
||||
if (entry != null && (result == null || (forward
|
||||
? Long.compareUnsigned(entry.timestamp, result) < 0
|
||||
: Long.compareUnsigned(entry.timestamp, result) > 0))) result = entry.timestamp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean changed(long time) {
|
||||
Long previous = candidate(time, false, false);
|
||||
return previous == null || !Arrays.equals(sample(time), sample(previous));
|
||||
}
|
||||
|
||||
private Long seek(long time, boolean forward, boolean inclusive, long limit) {
|
||||
Seek query = new Seek(time, forward, inclusive, limit);
|
||||
synchronized (positions) {
|
||||
if (positions.containsKey(query)) return positions.get(query);
|
||||
}
|
||||
Long next = candidate(time, forward, inclusive);
|
||||
while (next != null) {
|
||||
if (forward ? Long.compareUnsigned(next, limit) > 0 : Long.compareUnsigned(next, limit) < 0) {
|
||||
next = null;
|
||||
break;
|
||||
}
|
||||
if (changed(next)) break;
|
||||
if (Thread.currentThread().isInterrupted()) throw new java.util.concurrent.CancellationException();
|
||||
next = candidate(next, forward, false);
|
||||
}
|
||||
synchronized (positions) { positions.put(query, next); }
|
||||
return next;
|
||||
}
|
||||
|
||||
private EventEntry event(long time) {
|
||||
BitVector vector = new BitVector(getWidth());
|
||||
BitValue[] value = sample(time);
|
||||
for (int i = 0; i < value.length; i++) vector.setValue(value.length - i - 1, value[i]);
|
||||
return new EventEntry(time, new IEvent[]{vector});
|
||||
}
|
||||
|
||||
private final class Timeline implements IEventList {
|
||||
private final long low, high;
|
||||
private final boolean includeLow, empty;
|
||||
Timeline(long low, boolean includeLow, long high, boolean empty) {
|
||||
this.low = low; this.high = high; this.includeLow = includeLow; this.empty = empty;
|
||||
}
|
||||
private EventEntry find(long time, boolean forward, boolean inclusive) {
|
||||
if (empty) return null;
|
||||
if (forward && Long.compareUnsigned(time, low) < 0) { time = low; inclusive = includeLow; }
|
||||
else if (forward && time == low) inclusive &= includeLow;
|
||||
if (!forward && Long.compareUnsigned(time, high) > 0) { time = high; inclusive = true; }
|
||||
Long next = seek(time, forward, inclusive, forward ? high : low);
|
||||
return next == null || Long.compareUnsigned(next, low) < 0 || (!includeLow && next == low)
|
||||
|| Long.compareUnsigned(next, high) > 0 ? null : event(next);
|
||||
}
|
||||
@Override public EventEntry firstEntry() { return find(low, true, includeLow); }
|
||||
@Override public EventEntry lastEntry() { return find(high, false, true); }
|
||||
@Override public EventEntry floorEntry(long key) { return find(key, false, true); }
|
||||
@Override public EventEntry ceilingEntry(long key) { return find(key, true, true); }
|
||||
@Override public EventEntry lowerEntry(long key) { return find(key, false, false); }
|
||||
@Override public EventEntry higherEntry(long key) { return find(key, true, false); }
|
||||
@Override public boolean isEmpty() { return firstEntry() == null; }
|
||||
@Override public int size() { int size = 0; for (EventEntry ignored : this) size++; return size; }
|
||||
@Override public long firstKey() {
|
||||
EventEntry entry = firstEntry(); if (entry == null) throw new NoSuchElementException(); return entry.timestamp;
|
||||
}
|
||||
@Override public long lastKey() {
|
||||
EventEntry entry = lastEntry(); if (entry == null) throw new NoSuchElementException(); return entry.timestamp;
|
||||
}
|
||||
@Override public IEvent[] get(long key) {
|
||||
EventEntry entry = ceilingEntry(key); return entry != null && entry.timestamp == key ? entry.events : null;
|
||||
}
|
||||
@Override public boolean containsKey(long key) { return get(key) != null; }
|
||||
@Override public void put(long key, IEvent value) { throw new UnsupportedOperationException("Read-only combined vector"); }
|
||||
@Override public IEventList subMap(long from, boolean inclusive, long to) {
|
||||
if (Long.compareUnsigned(from, to) > 0) throw new IllegalArgumentException("Reversed time range");
|
||||
long lower = Long.compareUnsigned(from, low) > 0 ? from : low;
|
||||
boolean include = (lower != from || inclusive) && (lower != low || includeLow);
|
||||
long upper = Long.compareUnsigned(to, high) < 0 ? to : high;
|
||||
return new Timeline(lower, include, upper, empty || Long.compareUnsigned(lower, upper) > 0);
|
||||
}
|
||||
@Override public Iterator<EventEntry> iterator() {
|
||||
return new Iterator<>() {
|
||||
EventEntry next = firstEntry();
|
||||
@Override public boolean hasNext() { return next != null; }
|
||||
@Override public EventEntry next() {
|
||||
if (next == null) throw new NoSuchElementException();
|
||||
EventEntry result = next; next = higherEntry(result.timestamp); return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override public Collection<EventEntry> entrySet() {
|
||||
return new AbstractCollection<>() {
|
||||
@Override public int size() { return Timeline.this.size(); }
|
||||
@Override public Iterator<EventEntry> iterator() { return Timeline.this.iterator(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,9 @@ package com.minres.scviewer.database;
|
||||
*/
|
||||
public interface IWaveform extends IHierNode {
|
||||
|
||||
/** User-facing label; derived waveforms may have a separate persistent identity. */
|
||||
default String getDisplayName() { return getFullName(); }
|
||||
|
||||
public DirectionType getDirection();
|
||||
/**
|
||||
* Gets the id.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
</topic>
|
||||
<topic label="Reference" href="ch02.html">
|
||||
<topic label="Bitvector expansion" href="ch02.html#_bitvector_expansion"/>
|
||||
<topic label="Key Shortcuts" href="ch02s02.html"/>
|
||||
<topic label="Combining single bits" href="ch02s02.html"/>
|
||||
<topic label="Key Shortcuts" href="ch02s03.html"/>
|
||||
</topic>
|
||||
</toc>
|
||||
@@ -32,6 +32,7 @@
|
||||
</children>
|
||||
</children>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_menu_edit_groupTracks" elementId="com.minres.scviewer.e4.application.menu.edit.groupTracks" label="Group tracks…" command="_command_groupTracks"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_menu_edit_combineBits" elementId="com.minres.scviewer.e4.application.menu.edit.combineBits" label="Combine bits…" command="_command_combineBits"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_menu_edit_ungroupTracks" elementId="com.minres.scviewer.e4.application.menu.edit.ungroupTracks" label="Ungroup tracks" command="_command_ungroupTracks"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_FiwZcEhdEeyp3vLifEzGbQ" elementId="com.minres.scviewer.e4.application.handledmenuitem.delete" label="Delete" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/cross.png" command="_WUZ2wHXHEeWwZ-9vrAR2UQ"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_cPlx4HgvEeWwZ-9vrAR2UQ" elementId="com.minres.scviewer.e4.application.handledmenuitem.delete" label="Select All" iconURI="" command="_bV-TMHXHEeWwZ-9vrAR2UQ"/>
|
||||
@@ -179,6 +180,7 @@
|
||||
<descriptors xmi:id="_KicY0HRMEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.partdescriptor.waveformviewer" label="SCViewer" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/scviewer.png" bindingContexts="_context_waveform" allowMultiple="true" category="General" closeable="true" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.WaveformViewer">
|
||||
<tags>categoryTag:General</tags>
|
||||
<handlers xmi:id="_handler_groupTracks" elementId="com.minres.scviewer.e4.application.handler.groupTracks" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.GroupTracksHandler" command="_command_groupTracks"/>
|
||||
<handlers xmi:id="_handler_combineBits" elementId="com.minres.scviewer.e4.application.handler.combineBits" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.CombineBitsHandler" command="_command_combineBits"/>
|
||||
<handlers xmi:id="_handler_ungroupTracks" elementId="com.minres.scviewer.e4.application.handler.ungroupTracks" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.UngroupTracksHandler" command="_command_ungroupTracks"/>
|
||||
<handlers xmi:id="_BSIuEHacEeWwZ-9vrAR2UQ" elementId="com.minres.scviewer.e4.application.handler.navigateEvent" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.NavigateEvent" command="_79rx4HabEeWwZ-9vrAR2UQ"/>
|
||||
<handlers xmi:id="_JpdGwHXKEeWwZ-9vrAR2UQ" elementId="com.minres.scviewer.e4.application.handler.navigateTrans" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.NavigateTrans" command="_Gn3lEHXKEeWwZ-9vrAR2UQ"/>
|
||||
@@ -229,6 +231,7 @@
|
||||
</children>
|
||||
<children xsi:type="menu:MenuSeparator" xmi:id="_cxgs4Lc0Ee294PIiYLxpfA" elementId="com.minres.scviewer.e4.application.menuseparator.1"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_menu_popup_groupTracks" elementId="com.minres.scviewer.e4.application.menu.popup.groupTracks" label="Group tracks…" mnemonics="M1+G" command="_command_groupTracks"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_menu_popup_combineBits" elementId="com.minres.scviewer.e4.application.menu.popup.combineBits" label="Combine bits…" command="_command_combineBits"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_menu_popup_ungroupTracks" elementId="com.minres.scviewer.e4.application.menu.popup.ungroupTracks" label="Ungroup tracks" command="_command_ungroupTracks"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_NFfK0LcyEe294PIiYLxpfA" elementId="com.minres.scviewer.e4.application.handledmenuitem.add_separator" label="Add separator before" command="_vYAOQLcxEe294PIiYLxpfA">
|
||||
<parameters xmi:id="_or7iYLcyEe294PIiYLxpfA" elementId="com.minres.scviewer.e4.application.parameter.15" name="com.minres.scviewer.e4.application.commandparameter.add_separator" value="before"/>
|
||||
@@ -297,6 +300,7 @@
|
||||
</snippets>
|
||||
<commands xmi:id="_command_ungroupTracks" elementId="com.minres.scviewer.e4.application.command.ungroupTracks" commandName="Resolve group"/>
|
||||
<commands xmi:id="_command_groupTracks" elementId="com.minres.scviewer.e4.application.command.groupTracks" commandName="Group tracks…"/>
|
||||
<commands xmi:id="_command_combineBits" elementId="com.minres.scviewer.e4.application.command.combineBits" commandName="Combine bits…"/>
|
||||
<commands xmi:id="_95PfvHNmEeWBq8z1Dv39LA" elementId="org.eclipse.ui.file.exit" commandName="Quit Command"/>
|
||||
<commands xmi:id="_95PfwHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.open" commandName="Open Command"/>
|
||||
<commands xmi:id="_95Pfw3NmEeWBq8z1Dv39LA" elementId="org.eclipse.ui.file.save" commandName="Save Command"/>
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2026 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.jface.dialogs.TitleAreaDialog;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import com.minres.scviewer.database.ui.TrackEntry;
|
||||
|
||||
public class CombineBitsHandler {
|
||||
public record Request(String name, List<TrackEntry> bits) {
|
||||
public Request { bits = List.copyOf(bits); }
|
||||
}
|
||||
|
||||
@CanExecute public boolean canExecute(EPartService parts) {
|
||||
var viewer = GroupTracksHandler.activeViewer(parts);
|
||||
return viewer != null && viewer.canCombineSelectedBits();
|
||||
}
|
||||
|
||||
@Execute public void execute(EPartService parts, Shell shell) {
|
||||
var viewer = GroupTracksHandler.activeViewer(parts);
|
||||
if (viewer == null || !viewer.canCombineSelectedBits()) return;
|
||||
Request request = requestVector(shell, viewer.selectedBits());
|
||||
if (request != null) viewer.combineBits(request.name(), request.bits());
|
||||
}
|
||||
|
||||
protected Request requestVector(Shell shell, List<TrackEntry> bits) {
|
||||
CombineDialog dialog = new CombineDialog(shell, bits);
|
||||
return dialog.open() == Window.OK ? dialog.getRequest() : null;
|
||||
}
|
||||
|
||||
public static class CombineDialog extends TitleAreaDialog {
|
||||
private final List<TrackEntry> bits;
|
||||
private Text name;
|
||||
private Table table;
|
||||
private Request request;
|
||||
public Request getRequest() { return request; }
|
||||
public CombineDialog(Shell shell, List<TrackEntry> bits) {
|
||||
super(shell);
|
||||
this.bits = new ArrayList<>(bits);
|
||||
setShellStyle(getShellStyle() | SWT.RESIZE);
|
||||
}
|
||||
@Override protected Control createDialogArea(Composite parent) {
|
||||
Composite area = (Composite) super.createDialogArea(parent);
|
||||
setTitle("Combine bits");
|
||||
setMessage("Name the vector and order its bits. The top entry is the most significant bit.");
|
||||
Composite form = new Composite(area, SWT.NONE);
|
||||
form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
form.setLayout(new GridLayout(2, false));
|
||||
new Label(form, SWT.NONE).setText("Vector name");
|
||||
name = new Text(form, SWT.BORDER);
|
||||
name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
||||
name.setText("Combined vector");
|
||||
table = new Table(form, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL);
|
||||
table.setHeaderVisible(true);
|
||||
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
data.widthHint = 450; data.heightHint = 220;
|
||||
table.setLayoutData(data);
|
||||
TableColumn index = new TableColumn(table, SWT.NONE); index.setText("Bit"); index.setWidth(55);
|
||||
TableColumn source = new TableColumn(table, SWT.NONE); source.setText("Source"); source.setWidth(380);
|
||||
Composite buttons = new Composite(form, SWT.NONE);
|
||||
buttons.setLayout(new GridLayout());
|
||||
Button up = new Button(buttons, SWT.PUSH); up.setText("Move up");
|
||||
Button down = new Button(buttons, SWT.PUSH); down.setText("Move down");
|
||||
up.addListener(SWT.Selection, event -> move(-1));
|
||||
down.addListener(SWT.Selection, event -> move(1));
|
||||
refresh(0);
|
||||
return area;
|
||||
}
|
||||
private void move(int offset) {
|
||||
int selected = table.getSelectionIndex(), target = selected + offset;
|
||||
if (selected < 0 || target < 0 || target >= bits.size()) return;
|
||||
java.util.Collections.swap(bits, selected, target);
|
||||
refresh(target);
|
||||
}
|
||||
private void refresh(int selected) {
|
||||
table.removeAll();
|
||||
for (int i = 0; i < bits.size(); i++) {
|
||||
TableItem item = new TableItem(table, SWT.NONE);
|
||||
item.setText(new String[]{Integer.toString(bits.size() - i - 1), bits.get(i).waveform.getDisplayName()});
|
||||
}
|
||||
table.setSelection(selected);
|
||||
}
|
||||
@Override protected void okPressed() {
|
||||
if (name.getText().isBlank()) { setErrorMessage("Enter a vector name"); return; }
|
||||
request = new Request(name.getText().trim(), bits);
|
||||
super.okPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
+95
-5
@@ -22,6 +22,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.CombinedBitVectorWaveform;
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.WaveformType;
|
||||
import com.minres.scviewer.database.EventEntry;
|
||||
@@ -34,7 +36,7 @@ import com.minres.scviewer.database.ui.BitWaveform;
|
||||
|
||||
/** Validates the existing properties format before any viewer state is changed. */
|
||||
public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale, Long baseline,
|
||||
Long transactionId, String transactionTrack, Boolean detailsShown, List<File> files) {
|
||||
Long transactionId, String transactionTrack, Boolean detailsShown, List<File> files, List<CombinedVector> combinedVectors) {
|
||||
public static final String DATABASE_FILE = "DATABASE_FILE";
|
||||
public static final String SHOWN_WAVEFORM = "SHOWN_WAVEFORM";
|
||||
public static final String WAVEFORM_TYPE = ".WAVEFORM_TYPE";
|
||||
@@ -59,10 +61,32 @@ public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale,
|
||||
}
|
||||
}
|
||||
|
||||
public record BitSource(String waveform, int bit) {
|
||||
public BitSource {
|
||||
if (waveform == null || waveform.isBlank() || waveform.startsWith("@combined:") || bit < 0)
|
||||
throw new IllegalArgumentException("Invalid recorded bit reference");
|
||||
}
|
||||
}
|
||||
public record CombinedVector(String id, String name, List<BitSource> bits) {
|
||||
public CombinedVector {
|
||||
if (id == null || !id.startsWith("@combined:") || id.length() <= 10 || name == null || name.isBlank()
|
||||
|| bits == null || bits.size() < 2) throw new IllegalArgumentException("Invalid combined vector definition");
|
||||
bits = List.copyOf(bits);
|
||||
}
|
||||
}
|
||||
|
||||
public ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale, Long baseline,
|
||||
Long transactionId, String transactionTrack, Boolean detailsShown, List<File> files) {
|
||||
this(tracks, cursors, scale, baseline, transactionId, transactionTrack, detailsShown, files, List.of());
|
||||
}
|
||||
|
||||
public ViewerSettings {
|
||||
tracks = List.copyOf(tracks);
|
||||
cursors = List.copyOf(cursors);
|
||||
files = List.copyOf(files);
|
||||
combinedVectors = List.copyOf(combinedVectors);
|
||||
if (combinedVectors.stream().map(CombinedVector::id).distinct().count() != combinedVectors.size())
|
||||
throw new IllegalArgumentException("Duplicate combined vector identity");
|
||||
}
|
||||
|
||||
public static ViewerSettings read(Path path) throws IOException {
|
||||
@@ -81,6 +105,18 @@ public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale,
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
Map<String, String> state = new HashMap<>();
|
||||
state.put("COMBINED_VECTORS", Integer.toString(combinedVectors.size()));
|
||||
for (int i = 0; i < combinedVectors.size(); i++) {
|
||||
CombinedVector vector = combinedVectors.get(i);
|
||||
String key = "COMBINED_VECTOR" + i;
|
||||
state.put(key + ".ID", vector.id());
|
||||
state.put(key + ".NAME", vector.name());
|
||||
state.put(key + ".BITS", Integer.toString(vector.bits().size()));
|
||||
for (int bit = 0; bit < vector.bits().size(); bit++) {
|
||||
state.put(key + ".BIT" + bit + ".SOURCE", vector.bits().get(bit).waveform());
|
||||
state.put(key + ".BIT" + bit + ".INDEX", Integer.toString(vector.bits().get(bit).bit()));
|
||||
}
|
||||
}
|
||||
state.put(DATABASE_FILE + "S", Integer.toString(files.size()));
|
||||
for (int i = 0; i < files.size(); i++) state.put(DATABASE_FILE + i, files.get(i).getAbsolutePath());
|
||||
state.put(SHOWN_WAVEFORM + "S", Integer.toString(tracks.size()));
|
||||
@@ -113,13 +149,26 @@ public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale,
|
||||
}
|
||||
|
||||
public void replaceState(Map<String, String> state) {
|
||||
state.keySet().removeIf(key -> key.startsWith(DATABASE_FILE) || key.startsWith(SHOWN_WAVEFORM)
|
||||
state.keySet().removeIf(key -> key.startsWith("COMBINED_VECTOR") || key.startsWith(DATABASE_FILE) || key.startsWith(SHOWN_WAVEFORM)
|
||||
|| key.startsWith(SHOWN_CURSOR) || key.equals(SCALING_FACTOR) || key.equals(BASE_LINE_TIME)
|
||||
|| key.equals(SELECTED_TX_ID) || key.equals(SELECTED_TRACKENTRY_NAME) || key.equals(TX_DETAILS_SHOWN));
|
||||
state.putAll(toMap());
|
||||
}
|
||||
|
||||
public static ViewerSettings parse(Map<String, String> state) {
|
||||
List<CombinedVector> vectors = new ArrayList<>();
|
||||
for (int i = 0, n = count(state, "COMBINED_VECTORS"); i < n; i++) {
|
||||
String key = "COMBINED_VECTOR" + i;
|
||||
List<BitSource> bits = new ArrayList<>();
|
||||
for (int j = 0, m = count(state, key + ".BITS"); j < m; j++) {
|
||||
String source = key + ".BIT" + j;
|
||||
required(state, source + ".INDEX");
|
||||
Long bit = number(state, source + ".INDEX");
|
||||
if (bit < 0 || bit > Integer.MAX_VALUE) throw invalid(source + ".INDEX", "invalid bit index");
|
||||
bits.add(new BitSource(required(state, source + ".SOURCE"), bit.intValue()));
|
||||
}
|
||||
vectors.add(new CombinedVector(required(state, key + ".ID"), required(state, key + ".NAME"), bits));
|
||||
}
|
||||
List<Track> tracks = new ArrayList<>();
|
||||
int count = count(state, SHOWN_WAVEFORM + "S");
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -156,7 +205,7 @@ public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale,
|
||||
String track = state.get(SELECTED_TRACKENTRY_NAME);
|
||||
if (tx != null) required(state, SELECTED_TRACKENTRY_NAME);
|
||||
return new ViewerSettings(List.copyOf(tracks), List.copyOf(cursors), scale, baseline,
|
||||
tx, track, bool(state, TX_DETAILS_SHOWN), List.copyOf(databaseFiles(state)));
|
||||
tx, track, bool(state, TX_DETAILS_SHOWN), List.copyOf(databaseFiles(state)), vectors);
|
||||
}
|
||||
|
||||
public static List<File> databaseFiles(Map<String, String> state) {
|
||||
@@ -166,12 +215,52 @@ public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale,
|
||||
return files;
|
||||
}
|
||||
|
||||
/** Definitions only reference recorded waveforms, so reconstruction cannot create cycles. */
|
||||
public Map<String, IWaveform> resolveCombinedVectors(IWaveformDb database, List<String> missing) {
|
||||
Map<String, IWaveform> resolved = new HashMap<>();
|
||||
for (CombinedVector vector : combinedVectors) {
|
||||
List<CombinedBitVectorWaveform.SourceBit> bits = new ArrayList<>();
|
||||
for (BitSource bit : vector.bits()) {
|
||||
IWaveform waveform = resolveWaveform(database, bit.waveform());
|
||||
if (waveform == null || waveform.getType() != WaveformType.SIGNAL || bit.bit() >= waveform.getWidth()) {
|
||||
missing.add(vector.name() + ": " + bit.waveform() + "[" + bit.bit() + "]");
|
||||
break;
|
||||
}
|
||||
EventEntry first = waveform.getEvents().firstEntry();
|
||||
if (first != null && (first.events == null || first.events.length == 0
|
||||
|| !(first.events[first.events.length - 1] instanceof BitVector))) {
|
||||
missing.add(vector.name() + ": " + bit.waveform() + " is not a bit signal");
|
||||
break;
|
||||
}
|
||||
bits.add(new CombinedBitVectorWaveform.SourceBit(waveform, bit.bit()));
|
||||
}
|
||||
if (bits.size() == vector.bits().size())
|
||||
resolved.put(vector.id(), new CombinedBitVectorWaveform(vector.id(), vector.name(), bits));
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
public String displayName(String identity) {
|
||||
for (CombinedVector vector : combinedVectors) {
|
||||
if (identity.equals(vector.id())) return vector.name();
|
||||
if (identity.startsWith(vector.id() + "[")) return vector.name() + identity.substring(vector.id().length());
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
public static IWaveform resolveWaveform(IWaveformDb database, String name) {
|
||||
IWaveform waveform = database.getStreamByName(name);
|
||||
return resolveWaveform(database, name, Map.of());
|
||||
}
|
||||
|
||||
public static IWaveform resolveWaveform(IWaveformDb database, String name, Map<String, IWaveform> derived) {
|
||||
IWaveform waveform = derived.get(name);
|
||||
if (waveform == null && database != null) waveform = database.getStreamByName(name);
|
||||
if (waveform != null) return waveform;
|
||||
int bitStart = name.lastIndexOf('[');
|
||||
if (bitStart > 0 && name.endsWith("]")) {
|
||||
IWaveform source = database.getStreamByName(name.substring(0, bitStart));
|
||||
String sourceName = name.substring(0, bitStart);
|
||||
IWaveform source = derived.get(sourceName);
|
||||
if (source == null && database != null) source = database.getStreamByName(sourceName);
|
||||
if (source != null && source.getType() == WaveformType.SIGNAL) {
|
||||
try {
|
||||
int bit = Integer.parseInt(name.substring(bitStart + 1, name.length() - 1));
|
||||
@@ -179,6 +268,7 @@ public record ViewerSettings(List<Track> tracks, List<Long> cursors, Long scale,
|
||||
} catch (NumberFormatException e) { /* A declared signal range is not a projected bit. */ }
|
||||
}
|
||||
}
|
||||
if (database == null) return null;
|
||||
int separator = name.lastIndexOf('.');
|
||||
if (separator <= 0 || separator == name.length() - 1) return null;
|
||||
IWaveform parent = database.getStreamByName(name.substring(0, separator));
|
||||
|
||||
+82
-5
@@ -70,6 +70,10 @@ import org.eclipse.swt.widgets.Widget;
|
||||
import org.eclipse.wb.swt.SWTResourceManager;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
import com.minres.scviewer.database.CombinedBitVectorWaveform;
|
||||
import com.minres.scviewer.database.ui.BitVectorComposition;
|
||||
import com.minres.scviewer.database.ui.BitWaveform;
|
||||
import com.minres.scviewer.e4.application.internal.util.LatestJob;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.EmptyWaveform;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
@@ -177,6 +181,9 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
|
||||
String partConfig = "";
|
||||
private Path settingsFile;
|
||||
private LatestJob<PreparedVector> vectorJob;
|
||||
private record PreparedVector(CombinedBitVectorWaveform vector, List<TrackEntry> tracks,
|
||||
IWaveformDb database, String error) { }
|
||||
|
||||
/** The persisted state. */
|
||||
Map<String, String> persistedState;
|
||||
@@ -440,7 +447,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
TrackEntry te = (TrackEntry)res.get(0);
|
||||
final Font font = SWTResourceManager.getFont("Terminal", 10, SWT.NORMAL);
|
||||
final Label label = new Label(parent, SWT.NONE);
|
||||
label.setText(te.waveform.getFullName());
|
||||
label.setText(te.waveform.getDisplayName());
|
||||
label.setFont(font);
|
||||
GridData labelGridData = new GridData();
|
||||
labelGridData.horizontalAlignment = GridData.FILL;
|
||||
@@ -460,6 +467,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
public void closeDatabase() {
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
if (vectorJob != null) vectorJob.close();
|
||||
if (sessions != null) sessions.close();
|
||||
if (observedPreferences != null) {
|
||||
observedPreferences.removePreferenceChangeListener(this);
|
||||
@@ -528,6 +536,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
|
||||
protected void loadDatabase(final Map<String, String> state, long delay) {
|
||||
if (disposed) return;
|
||||
if (vectorJob != null) vectorJob.cancel();
|
||||
setSelection(null);
|
||||
waveformPane.getStreamList().clear();
|
||||
waveformPane.update();
|
||||
@@ -649,16 +658,30 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
}
|
||||
}
|
||||
|
||||
private static void captureCombined(List<TrackEntry> entries, Map<String, ViewerSettings.CombinedVector> definitions) {
|
||||
for (TrackEntry entry : entries) {
|
||||
IWaveform source = entry.waveform instanceof BitWaveform bit ? bit.getSource() : entry.waveform;
|
||||
if (source instanceof CombinedBitVectorWaveform vector) {
|
||||
definitions.putIfAbsent(vector.getFullName(), new ViewerSettings.CombinedVector(vector.getFullName(),
|
||||
vector.getName(), vector.getSources().stream()
|
||||
.map(bit -> new ViewerSettings.BitSource(bit.waveform().getFullName(), bit.bit())).toList()));
|
||||
}
|
||||
if (entry.isExpandable()) captureCombined(entry.waveforms, definitions);
|
||||
}
|
||||
}
|
||||
|
||||
private ViewerSettings captureSettings() {
|
||||
List<ViewerSettings.Track> tracks = new ArrayList<>();
|
||||
captureTracks(waveformPane.getStreamList(), null, tracks);
|
||||
Map<String, ViewerSettings.CombinedVector> definitions = new java.util.LinkedHashMap<>();
|
||||
captureCombined(waveformPane.getStreamList(), definitions);
|
||||
WaveformSelection selection = WaveformSelection.from(waveformPane.getSelection());
|
||||
boolean selectedTransaction = selection.transaction() != null && selection.track() != null;
|
||||
return new ViewerSettings(tracks, waveformPane.getCursorList().stream().map(ICursor::getTime).toList(),
|
||||
waveformPane.getWaveformZoom().getScale(), waveformPane.getWaveformZoom().getMinVisibleTime(),
|
||||
selectedTransaction ? selection.transaction().getId() : null,
|
||||
selectedTransaction ? selection.track().waveform.getFullName() : null,
|
||||
store.getBoolean(PreferenceConstants.SHOW_TX_DETAILS, false), List.copyOf(filesToLoad));
|
||||
store.getBoolean(PreferenceConstants.SHOW_TX_DETAILS, false), List.copyOf(filesToLoad), List.copyOf(definitions.values()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,16 +700,18 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
private record ResolvedTrack(IWaveform waveform, ViewerSettings.Track settings) {}
|
||||
|
||||
private void applySettings(ViewerSettings settings) {
|
||||
if (vectorJob != null) vectorJob.cancel();
|
||||
// Resolve all references before replacing the current layout.
|
||||
List<ResolvedTrack> resolved = new ArrayList<>();
|
||||
List<String> missing = new ArrayList<>();
|
||||
Map<String, IWaveform> derived = settings.resolveCombinedVectors(getDatabase(), missing);
|
||||
ITx selectedTransaction = null;
|
||||
IWaveform selectedWaveform = null;
|
||||
for (ViewerSettings.Track track : settings.tracks()) {
|
||||
IWaveform waveform = track.type() == WaveformType.EMPTY ? new EmptyWaveform(track.name())
|
||||
: ViewerSettings.resolveWaveform(getDatabase(), track.name());
|
||||
: ViewerSettings.resolveWaveform(getDatabase(), track.name(), derived);
|
||||
if (waveform == null) {
|
||||
missing.add(track.name());
|
||||
missing.add(settings.displayName(track.name()));
|
||||
continue;
|
||||
}
|
||||
resolved.add(new ResolvedTrack(waveform, track));
|
||||
@@ -735,7 +760,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
waveformPane.setSelection(WaveformSelection.of(selectedTransaction, transactionTrack));
|
||||
else waveformPane.setSelection(new StructuredSelection(selectedTracks));
|
||||
updateAll();
|
||||
if (!missing.isEmpty() && !disposed && !myParent.isDisposed())
|
||||
if (!missing.isEmpty() && !disposed && myParent != null && !myParent.isDisposed())
|
||||
MessageDialog.openWarning(myParent.getShell(), "Missing waveforms",
|
||||
"These waveforms are absent from the current database and were skipped:\n" + String.join("\n", missing));
|
||||
}
|
||||
@@ -938,6 +963,58 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene
|
||||
updateAll();
|
||||
}
|
||||
|
||||
public List<TrackEntry> selectedBits() {
|
||||
return disposed || waveformPane == null ? List.of() : BitVectorComposition.selectedBits(
|
||||
waveformPane.getStreamList(), WaveformSelection.from(getSelection()).tracks());
|
||||
}
|
||||
|
||||
public boolean canCombineSelectedBits() { return !selectedBits().isEmpty(); }
|
||||
|
||||
public void combineBits(String name, List<TrackEntry> ordered) {
|
||||
if (disposed || name == null || name.isBlank() || waveformPane == null
|
||||
|| BitVectorComposition.selectedBits(waveformPane.getStreamList(), ordered).isEmpty()) return;
|
||||
List<TrackEntry> snapshot = List.copyOf(ordered);
|
||||
IWaveformDb database = getDatabase();
|
||||
long visibleStart = waveformPane.getWaveformZoom().getMinVisibleTime();
|
||||
long visibleEnd = waveformPane.getWaveformZoom().getMaxVisibleTime();
|
||||
long cursor = waveformPane.getCursorTime();
|
||||
if (vectorJob == null) vectorJob = new LatestJob<>(task -> sync.asyncExec(task), result -> {
|
||||
if (disposed || getDatabase() != result.database()) return;
|
||||
if (result.error() != null) { reportSettingsError("Cannot combine bits", result.error()); return; }
|
||||
insertCombinedVector(result.vector(), result.tracks());
|
||||
});
|
||||
vectorJob.schedule("Combine bits", monitor -> {
|
||||
try {
|
||||
var vector = new CombinedBitVectorWaveform(name.trim(), BitVectorComposition.sources(snapshot));
|
||||
vector.getEvents().firstEntry(); // Load any lazy inputs on this worker, before painting on the UI thread.
|
||||
vector.getEvents().floorEntry(visibleStart);
|
||||
vector.getEvents().floorEntry(cursor);
|
||||
for (var ignored : vector.getEvents().subMap(visibleStart, true, visibleEnd)) {
|
||||
if (monitor.isCanceled()) return null;
|
||||
}
|
||||
return new PreparedVector(vector, snapshot, database, null);
|
||||
} catch (RuntimeException exception) {
|
||||
return new PreparedVector(null, snapshot, database, exception.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void insertCombinedVector(CombinedBitVectorWaveform vector, List<TrackEntry> tracks) {
|
||||
List<TrackEntry> roots = waveformPane.getStreamList();
|
||||
List<TrackEntry> visible = TrackEntry.visibleTracks(roots);
|
||||
if (tracks.stream().anyMatch(track -> !visible.contains(track))) return;
|
||||
TrackEntry anchor = visible.stream().filter(tracks::contains).reduce((previous, current) -> current).orElse(null);
|
||||
if (anchor == null) return;
|
||||
// Nested bits stay in their group/bus; insert after their containing root.
|
||||
int position = 0;
|
||||
while (position < roots.size() && roots.get(position) != anchor
|
||||
&& TrackEntry.siblingsOf(List.of(roots.get(position)), anchor) == null) position++;
|
||||
if (position == roots.size()) return;
|
||||
TrackEntry combined = waveformPane.addWaveform(vector, position + 1);
|
||||
waveformPane.update();
|
||||
waveformPane.setSelection(new StructuredSelection(combined));
|
||||
}
|
||||
|
||||
public boolean canGroupSelectedTracks() {
|
||||
return waveformPane != null && TrackEntry.groupingSiblings(waveformPane.getStreamList(),
|
||||
WaveformSelection.from(getSelection()).tracks()) != null;
|
||||
|
||||
Reference in new issue
Block a user