Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array widgets #812

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Array widgets #812

wants to merge 7 commits into from

Conversation

Martysh12
Copy link

Overview

Add widgets for array types: BooleanArrayWidget, NumberArrayWidget and StringArrayWidget

Screenshots

image

Fixes #305

Copy link
Member

@SamCarlberg SamCarlberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! This looks pretty good, but there are a few things (mostly small) that will need to be addressed

Comment on lines +41 to +42
final var array = new Boolean[newBooleans.length];
IntStream.range(0, newBooleans.length).forEach(i -> array[i] = newBooleans[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newBooleans.clone() would do this better

Comment on lines +25 to +26
final var array = new Double[newDoubles.length];
IntStream.range(0, newDoubles.length).forEach(i -> array[i] = newDoubles[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use newDoubles.clone() instead


@Description(
name = "Number Array",
dataTypes = double[].class,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float[] and long[] will need to be supported, too

Copy link
Author

@Martysh12 Martysh12 Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try to change the type from double[] to Number[],

diff --git a/plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/NumberArrayWidget.java b/plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/NumberArrayWidget.java
@@ -10,21 +10,19 @@
 
 @Description(
     name = "Number Array",
-    dataTypes = double[].class,
+    dataTypes = Number[].class,
     summary = "Displays an array of numbers"
 )
-public final class NumberArrayWidget extends SimpleAnnotatedWidget<double[]> {
+public final class NumberArrayWidget extends SimpleAnnotatedWidget<Number[]> {
   private final StackPane pane = new StackPane();
-  private final ArrayTableView<Double> table = new ArrayTableView<>();
+  private final ArrayTableView<Number> table = new ArrayTableView<>();
 
   @SuppressWarnings("JavadocMethod")
   public NumberArrayWidget() {
     pane.getChildren().add(table);
 
-    dataOrDefault.addListener((observableValue, oldDoubles, newDoubles) -> {
-      final var array = new Double[newDoubles.length];
-      IntStream.range(0, newDoubles.length).forEach(i -> array[i] = newDoubles[i]);
-      table.setItems(array);
+    dataOrDefault.addListener((observableValue, oldNumbers, newNumbers) -> {
+      table.setItems(newNumbers);
     });
   }

I get a strange exception:

edu.wpi.first.shuffleboard.api.data.IncompatibleSourceException: Expected one of (LW Subsystem), but found type NumberArray instead
	at edu.wpi.first.shuffleboard.api.widget.SingleSourceWidget.addSource(SingleSourceWidget.java:55)
	at edu.wpi.first.shuffleboard.app.components.ProcedurallyDefinedTab.populateLayout(ProcedurallyDefinedTab.java:112)
	at edu.wpi.first.shuffleboard.app.components.ProcedurallyDefinedTab.populate(ProcedurallyDefinedTab.java:98)
	at edu.wpi.first.shuffleboard.api.util.FxUtils.lambda$runOnFxThread$0(FxUtils.java:64)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
	at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:290)
	at java.base/java.lang.Thread.run(Thread.java:840)

Shuffleboard seems to think that NumberArrayWidget now accepts a SubsystemType, but I never specified that type anywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on what commit your bench is based on, this may be a different bug that's fixed in #815, where data types aren't correctly loaded. LW Subsystem is interesting though, what does your robot code Shuffleboard setup look like?

Copy link
Author

@Martysh12 Martysh12 Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does your robot code Shuffleboard setup look like?

I have the following in robotInit:

final var tab = Shuffleboard.getTab("Test");

tab.addBooleanArray("BooleanArray", () -> new boolean[]{false, true, false, true, true, false, true, false})
        .withSize(3, 3);
tab.addDoubleArray("DoubleArray", () -> new double[]{0.0, 1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN, 0.00001, -0.00001})
        .withSize(3, 3);
tab.addFloatArray("FloatArray", () -> new float[]{0.0f, 1.0f, -1.0f, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NaN, 0.00001f, -0.00001f})
        .withSize(3, 3);
tab.addIntegerArray("IntegerArray", () -> new long[]{0L, 1L, -1L, Long.MAX_VALUE, Long.MIN_VALUE})
        .withSize(3, 3);
tab.addStringArray("StringArray", () -> new String[]{"Hello", "The quick brown fox jumps over the lazy dog.", "Extra long extra long Extra long extra long Extra long extra long Extra long extra long Extra long extra long", "", "newlines!\nnewlines!\nnewlines!"})
        .withSize(3, 3);

tab.addBoolean("Boolean", () -> true);
tab.addDouble("Double", () -> 0.123456f);
tab.addFloat("Float", () -> 0.123f);
tab.addInteger("Integer", () -> 123);
tab.addString("String", () -> "String");

Depending on what commit your branch is based on, this may be a different bug that's fixed in #815.

My branch (Martysh12/shuffleboard:array-widgets) is based on wpilibsuite/shuffleboard:main (commit cdd5e7a, specifically).

I actually did try merging SamCarlberg/shuffleboard:nt-fixes into my branch and seeing if doing so fixes anything; it looks like it didn't:
image
All entries in my robot-created Test tab can only display as a Network Table Tree (when I right click on them), and only the primitives types are auto-populated.

Entries under FMSInfo seem to display fine, however, and all widgets are available for them:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No support for arrays
2 participants