changes grouping of bits in bitvector to create copies
This commit is contained in:
1 parent
cc28c417c1
commit
9c249b9ba0
3 files changed
+120
No files matched your search
+24
@@ -134,6 +134,20 @@ public class TrackEntry {
|
|||||||
if (siblings == null) return null;
|
if (siblings == null) return null;
|
||||||
List<TrackEntry> members = siblings.stream()
|
List<TrackEntry> members = siblings.stream()
|
||||||
.filter(entry -> selected.stream().anyMatch(track -> track == entry)).toList();
|
.filter(entry -> selected.stream().anyMatch(track -> track == entry)).toList();
|
||||||
|
TrackEntry owner = parentOf(roots, siblings);
|
||||||
|
if (owner != null && owner.isBitVector()) {
|
||||||
|
List<TrackEntry> copies = new ArrayList<>();
|
||||||
|
for (TrackEntry member : members) {
|
||||||
|
TrackEntry copy = new TrackEntry(member.waveform, styles);
|
||||||
|
copy.valueDisplay = member.valueDisplay;
|
||||||
|
copy.waveDisplay = member.waveDisplay;
|
||||||
|
copies.add(copy);
|
||||||
|
}
|
||||||
|
TrackEntry group = group(name, copies, styles);
|
||||||
|
List<TrackEntry> destination = siblingsOf(roots, owner);
|
||||||
|
destination.add(destination.indexOf(owner) + 1, group);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
int index = siblings.indexOf(members.get(0));
|
int index = siblings.indexOf(members.get(0));
|
||||||
TrackEntry group = group(name, members, styles);
|
TrackEntry group = group(name, members, styles);
|
||||||
siblings.removeAll(members);
|
siblings.removeAll(members);
|
||||||
@@ -141,6 +155,16 @@ public class TrackEntry {
|
|||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Find the display parent owning a particular child list. */
|
||||||
|
private static TrackEntry parentOf(List<TrackEntry> roots, List<TrackEntry> children) {
|
||||||
|
for (TrackEntry entry : roots) {
|
||||||
|
if (entry.waveforms == children) return entry;
|
||||||
|
TrackEntry parent = parentOf(entry.waveforms, children);
|
||||||
|
if (parent != null) return parent;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean ungroupTracks(List<TrackEntry> roots, TrackEntry group) {
|
public static boolean ungroupTracks(List<TrackEntry> roots, TrackEntry group) {
|
||||||
List<TrackEntry> siblings = siblingsOf(roots, group);
|
List<TrackEntry> siblings = siblingsOf(roots, group);
|
||||||
if (!group.isGroup() || siblings == null) return false;
|
if (!group.isGroup() || siblings == null) return false;
|
||||||
|
|||||||
+70
@@ -18,6 +18,76 @@ import com.minres.scviewer.database.ui.TrackEntry;
|
|||||||
import com.minres.scviewer.database.ui.TrackEntry.HierState;
|
import com.minres.scviewer.database.ui.TrackEntry.HierState;
|
||||||
|
|
||||||
public class TrackGroupingTest {
|
public class TrackGroupingTest {
|
||||||
|
@Test
|
||||||
|
public void groupingRecordedAndCombinedVectorBitsCopiesThemAfterTheVector() {
|
||||||
|
var source = new BitVectorExpansionTest.Signal("bus", 3) {
|
||||||
|
@Override public com.minres.scviewer.database.IEventList getEvents() {
|
||||||
|
throw new AssertionError("Grouping must not read signal events");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var combined = new com.minres.scviewer.database.CombinedBitVectorWaveform("combined", List.of(
|
||||||
|
new com.minres.scviewer.database.CombinedBitVectorWaveform.SourceBit(source, 2),
|
||||||
|
new com.minres.scviewer.database.CombinedBitVectorWaveform.SourceBit(source, 1),
|
||||||
|
new com.minres.scviewer.database.CombinedBitVectorWaveform.SourceBit(source, 0)));
|
||||||
|
for (var waveform : List.of(source, combined)) {
|
||||||
|
TrackEntry bus = new TrackEntry(waveform, null);
|
||||||
|
bus.setExpanded(true);
|
||||||
|
var bits = List.copyOf(bus.waveforms);
|
||||||
|
bits.get(0).valueDisplay = TrackEntry.ValueDisplay.SIGNED;
|
||||||
|
bits.get(2).waveDisplay = TrackEntry.WaveDisplay.STEP_WISE;
|
||||||
|
TrackEntry tail = new TrackEntry(new EmptyWaveform("tail"), null);
|
||||||
|
var roots = new java.util.ArrayList<>(List.of(bus, tail));
|
||||||
|
|
||||||
|
TrackEntry group = TrackEntry.groupTracks(roots, List.of(bits.get(2), bits.get(0)), "bits", null);
|
||||||
|
assertEquals(List.of(bus, group, tail), roots);
|
||||||
|
assertEquals(bits, bus.waveforms);
|
||||||
|
assertEquals(2, group.waveforms.size());
|
||||||
|
for (int index = 0; index < 2; index++) {
|
||||||
|
TrackEntry original = bits.get(index == 0 ? 0 : 2);
|
||||||
|
TrackEntry copy = group.waveforms.get(index);
|
||||||
|
assertNotSame(original, copy);
|
||||||
|
assertSame(original.waveform, copy.waveform);
|
||||||
|
assertEquals(original.valueDisplay, copy.valueDisplay);
|
||||||
|
assertEquals(original.waveDisplay, copy.waveDisplay);
|
||||||
|
}
|
||||||
|
group.waveforms.get(0).valueDisplay = TrackEntry.ValueDisplay.BINARY;
|
||||||
|
assertEquals(TrackEntry.ValueDisplay.SIGNED, bits.get(0).valueDisplay);
|
||||||
|
assertTrue(TrackEntry.ungroupTracks(roots, group));
|
||||||
|
assertEquals(bits, bus.waveforms);
|
||||||
|
assertEquals(List.of(bus, group.waveforms.get(0), group.waveforms.get(1), tail), roots);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void groupingBitsOfNestedVectorPlacesCopiesInItsParentGroup() {
|
||||||
|
TrackEntry bus = new TrackEntry(new BitVectorExpansionTest.Signal("bus", 2), null);
|
||||||
|
bus.setExpanded(true);
|
||||||
|
var bits = List.copyOf(bus.waveforms);
|
||||||
|
TrackEntry tail = new TrackEntry(new EmptyWaveform("tail"), null);
|
||||||
|
TrackEntry outer = TrackEntry.group("outer", List.of(bus, tail), null);
|
||||||
|
var roots = new java.util.ArrayList<>(List.of(outer));
|
||||||
|
TrackEntry group = TrackEntry.groupTracks(roots, bits, "bits", null);
|
||||||
|
assertEquals(List.of(outer), roots);
|
||||||
|
assertEquals(List.of(bus, group, tail), outer.waveforms);
|
||||||
|
assertEquals(bits, bus.waveforms);
|
||||||
|
bus.setExpanded(false);
|
||||||
|
bus.setExpanded(true);
|
||||||
|
assertEquals(bits, bus.waveforms);
|
||||||
|
assertNotSame(bits.get(0), group.waveforms.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void groupingStandaloneBitTracksMovesTheirExistingEntries() {
|
||||||
|
var source = new BitVectorExpansionTest.Signal("bus", 2);
|
||||||
|
TrackEntry first = new TrackEntry(new com.minres.scviewer.database.ui.BitWaveform(source, 1), null);
|
||||||
|
TrackEntry second = new TrackEntry(new com.minres.scviewer.database.ui.BitWaveform(source, 0), null);
|
||||||
|
var roots = new java.util.ArrayList<>(List.of(first, second));
|
||||||
|
TrackEntry group = TrackEntry.groupTracks(roots, List.of(second, first), "bits", null);
|
||||||
|
assertEquals(List.of(group), roots);
|
||||||
|
assertSame(first, group.waveforms.get(0));
|
||||||
|
assertSame(second, group.waveforms.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deletingNestedSeparatorLeavesItsGroupAndOtherMembersIntact() {
|
public void deletingNestedSeparatorLeavesItsGroupAndOtherMembersIntact() {
|
||||||
TrackEntry separator = new TrackEntry(new EmptyWaveform(), null);
|
TrackEntry separator = new TrackEntry(new EmptyWaveform(), null);
|
||||||
|
|||||||
+26
@@ -465,6 +465,32 @@ public class WaveformScrollTest {
|
|||||||
assertEquals(List.of(bus), view.getStreamList());
|
assertEquals(List.of(bus), view.getStreamList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void groupingExpandedBitsKeepsTheVectorIntactAndSelectsTheNewGroup() {
|
||||||
|
var source = new BitVectorExpansionTest.Signal("bus", 3);
|
||||||
|
TrackEntry bus = new TrackEntry(source, null);
|
||||||
|
bus.setExpanded(true);
|
||||||
|
view.getStreamList().add(bus);
|
||||||
|
view.update();
|
||||||
|
var bits = List.copyOf(bus.waveforms);
|
||||||
|
view.setSelection(new StructuredSelection(List.of(bits.get(2), bits.get(0))));
|
||||||
|
TrackEntry group = view.groupSelectedTracks("bits");
|
||||||
|
assertNotNull(group);
|
||||||
|
assertEquals(List.of(bus, group), view.getStreamList());
|
||||||
|
assertEquals(bits, bus.waveforms);
|
||||||
|
assertSame(group, ((StructuredSelection) view.getSelection()).getFirstElement());
|
||||||
|
assertSame(bits.get(0).waveform, group.waveforms.get(0).waveform);
|
||||||
|
assertSame(bits.get(2).waveform, group.waveforms.get(1).waveform);
|
||||||
|
assertNotSame(bits.get(0), group.waveforms.get(0));
|
||||||
|
assertNotSame(bits.get(2), group.waveforms.get(1));
|
||||||
|
view.setGroupExpanded(bus, false);
|
||||||
|
view.setGroupExpanded(bus, true);
|
||||||
|
assertEquals(bits, bus.waveforms);
|
||||||
|
view.ungroupTracks(group);
|
||||||
|
assertEquals(bits, bus.waveforms);
|
||||||
|
assertEquals(List.of(bus, group.waveforms.get(0), group.waveforms.get(1)), view.getStreamList());
|
||||||
|
}
|
||||||
|
|
||||||
private Point origin() {
|
private Point origin() {
|
||||||
try { return (Point) canvas.getClass().getMethod("getOrigin").invoke(canvas); }
|
try { return (Point) canvas.getClass().getMethod("getOrigin").invoke(canvas); }
|
||||||
catch (ReflectiveOperationException e) { throw new AssertionError(e); }
|
catch (ReflectiveOperationException e) { throw new AssertionError(e); }
|
||||||
|
|||||||
Reference in new issue
Block a user