added combined bit vectors
This commit is contained in:
1 parent
a4215fceb1
commit
42e0d83403
17 files changed
+1066
-14
No files matched your search
+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