// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. #pragma once #include #include #include #include #include #include #include #include #include #include #include "frc/shuffleboard/BuiltInLayouts.h" #include "frc/shuffleboard/LayoutType.h" #include "frc/shuffleboard/ShuffleboardComponentBase.h" #include "frc/shuffleboard/ShuffleboardValue.h" #include "frc/shuffleboard/SuppliedValueWidget.h" namespace cs { class VideoSource; } // namespace cs namespace wpi { class Sendable; } // namespace wpi namespace frc { class ComplexWidget; class ShuffleboardLayout; class SimpleWidget; /** * Common interface for objects that can contain shuffleboard components. */ class ShuffleboardContainer : public virtual ShuffleboardValue { public: explicit ShuffleboardContainer(std::string_view title); ShuffleboardContainer(ShuffleboardContainer&& rhs) = default; ~ShuffleboardContainer() override = default; /** * Gets the components that are direct children of this container. */ const std::vector>& GetComponents() const; /** * Gets the layout with the given type and title, creating it if it does not * already exist at the time this method is called. * * @param title the title of the layout * @param type the type of the layout, eg "List" or "Grid" * @return the layout */ ShuffleboardLayout& GetLayout(std::string_view title, BuiltInLayouts type); /** * Gets the layout with the given type and title, creating it if it does not * already exist at the time this method is called. * * @param title the title of the layout * @param type the type of the layout, eg "List" or "Grid" * @return the layout */ ShuffleboardLayout& GetLayout(std::string_view title, const LayoutType& type); /** * Gets the layout with the given type and title, creating it if it does not * already exist at the time this method is called. Note: this method should * only be used to use a layout type that is not already built into * Shuffleboard. To use a layout built into Shuffleboard, use * GetLayout(std::string_view, const LayoutType&) and the layouts in * BuiltInLayouts. * * @param title the title of the layout * @param type the type of the layout, eg "List Layout" or "Grid Layout" * @return the layout * @see GetLayout(std::string_view, const LayoutType&) */ ShuffleboardLayout& GetLayout(std::string_view title, std::string_view type); /** * Gets the already-defined layout in this container with the given title. * *
{@code
   * Shuffleboard::GetTab("Example Tab")->getLayout("My Layout",
   * &BuiltInLayouts.kList);
   *
   * // Later...
   * Shuffleboard::GetTab("Example Tab")->GetLayout("My Layout");
   * }
* * @param title the title of the layout to get * @return the layout with the given title * @throws if no layout has yet been defined with the given title */ ShuffleboardLayout& GetLayout(std::string_view title); /** * Adds a widget to this container to display the given sendable. * * @param title the title of the widget * @param sendable the sendable to display * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title */ ComplexWidget& Add(std::string_view title, wpi::Sendable& sendable); /** * Adds a widget to this container to display the given video stream. * * @param title the title of the widget * @param video the video stream to display * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title */ ComplexWidget& Add(std::string_view title, const cs::VideoSource& video); /** * Adds a widget to this container to display the given sendable. * * @param sendable the sendable to display * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title, or if the sendable's name has not been * specified */ ComplexWidget& Add(wpi::Sendable& sendable); /** * Adds a widget to this container to display the given video stream. * * @param video the video to display * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the same title as the video source */ ComplexWidget& Add(const cs::VideoSource& video); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, std::shared_ptr) * Add(std::string_view title, std::shared_ptr defaultValue) */ SimpleWidget& Add(std::string_view title, std::shared_ptr defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, bool) * Add(std::string_view title, bool defaultValue) */ SimpleWidget& Add(std::string_view title, bool defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, double) * Add(std::string_view title, double defaultValue) */ SimpleWidget& Add(std::string_view title, double defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, int) * Add(std::string_view title, int defaultValue) */ SimpleWidget& Add(std::string_view title, int defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, std::string_view) * Add(std::string_view title, std::string_view defaultValue) */ SimpleWidget& Add(std::string_view title, std::string_view defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, const char*) * Add(std::string_view title, const char* defaultValue) */ SimpleWidget& Add(std::string_view title, const char* defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, wpi::span) * Add(std::string_view title, wpi::span defaultValue) */ SimpleWidget& Add(std::string_view title, wpi::span defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, wpi::span) * Add(std::string_view title, wpi::span defaultValue) */ SimpleWidget& Add(std::string_view title, wpi::span defaultValue); /** * Adds a widget to this container to display the given data. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @throws IllegalArgumentException if a widget already exists in this * container with the given title * @see AddPersistent(std::string_view, wpi::span) * Add(std::string_view title, wpi::span defaultValue) */ SimpleWidget& Add(std::string_view title, wpi::span defaultValue); /** * Adds a widget to this container. The widget will display the data provided * by the value supplier. Changes made on the dashboard will not propagate to * the widget object, and will be overridden by values from the value * supplier. * * @param title the title of the widget * @param supplier the supplier for values * @return a widget to display data */ SuppliedValueWidget& AddString( std::string_view title, std::function supplier); /** * Adds a widget to this container. The widget will display the data provided * by the value supplier. Changes made on the dashboard will not propagate to * the widget object, and will be overridden by values from the value * supplier. * * @param title the title of the widget * @param supplier the supplier for values * @return a widget to display data */ SuppliedValueWidget& AddNumber(std::string_view title, std::function supplier); /** * Adds a widget to this container. The widget will display the data provided * by the value supplier. Changes made on the dashboard will not propagate to * the widget object, and will be overridden by values from the value * supplier. * * @param title the title of the widget * @param supplier the supplier for values * @return a widget to display data */ SuppliedValueWidget& AddBoolean(std::string_view title, std::function supplier); /** * Adds a widget to this container. The widget will display the data provided * by the value supplier. Changes made on the dashboard will not propagate to * the widget object, and will be overridden by values from the value * supplier. * * @param title the title of the widget * @param supplier the supplier for values * @return a widget to display data */ SuppliedValueWidget>& AddStringArray( std::string_view title, std::function()> supplier); /** * Adds a widget to this container. The widget will display the data provided * by the value supplier. Changes made on the dashboard will not propagate to * the widget object, and will be overridden by values from the value * supplier. * * @param title the title of the widget * @param supplier the supplier for values * @return a widget to display data */ SuppliedValueWidget>& AddNumberArray( std::string_view title, std::function()> supplier); /** * Adds a widget to this container. The widget will display the data provided * by the value supplier. Changes made on the dashboard will not propagate to * the widget object, and will be overridden by values from the value * supplier. * * @param title the title of the widget * @param supplier the supplier for values * @return a widget to display data */ SuppliedValueWidget>& AddBooleanArray( std::string_view title, std::function()> supplier); /** * Adds a widget to this container. The widget will display the data provided * by the value supplier. Changes made on the dashboard will not propagate to * the widget object, and will be overridden by values from the value * supplier. * * @param title the title of the widget * @param supplier the supplier for values * @return a widget to display data */ SuppliedValueWidget& AddRaw( std::string_view title, std::function supplier); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, std::shared_ptr), the value in the * widget will be saved on the robot and will be used when the robot program * next starts rather than {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(stdd::string_view, std::shared_ptr) * Add(std::string_view title, std::shared_ptr defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, std::shared_ptr defaultValue); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, bool), the value in the widget will be saved * on the robot and will be used when the robot program next starts rather * than {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(std::string_view, bool) * Add(std::string_view title, bool defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, bool defaultValue); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, double), the value in the widget will be saved * on the robot and will be used when the robot program next starts rather * than {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(std::string_view, double) * Add(std::string_view title, double defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, double defaultValue); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, int), the value in the widget will be saved on * the robot and will be used when the robot program next starts rather than * {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(std:string_view, int) * Add(std::string_view title, int defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, int defaultValue); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, std::string_view), the value in the widget * will be saved on the robot and will be used when the robot program next * starts rather than {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(std::string_view, std::string_view) * Add(std::string_view title, std::string_view defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, std::string_view defaultValue); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, wpi::span), the value in the * widget will be saved on the robot and will be used when the robot program * next starts rather than {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(std::string_view, wpi::span) * Add(std::string_view title, wpi::span defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, wpi::span defaultValue); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, wpi::span), the value in the * widget will be saved on the robot and will be used when the robot program * next starts rather than {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(std::string_view, wpi::span) * Add(std::string_view title, wpi::span defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, wpi::span defaultValue); /** * Adds a widget to this container to display a simple piece of data. * * Unlike Add(std::string_view, wpi::span), the value in * the widget will be saved on the robot and will be used when the robot * program next starts rather than {@code defaultValue}. * * @param title the title of the widget * @param defaultValue the default value of the widget * @return a widget to display the sendable data * @see Add(std::string_view, wpi::span) * Add(std::string_view title, wpi::span defaultValue) */ SimpleWidget& AddPersistent(std::string_view title, wpi::span defaultValue); void EnableIfActuator() override; void DisableIfActuator() override; protected: bool m_isLayout = false; private: wpi::SmallSet m_usedTitles; std::vector> m_components; wpi::StringMap m_layouts; /** * Adds title to internal set if it hasn't already. * * @return True if title isn't in use; false otherwise. */ void CheckTitle(std::string_view title); friend class SimpleWidget; }; } // namespace frc // Make use of references returned by member functions usable #include "frc/shuffleboard/ComplexWidget.h" #include "frc/shuffleboard/ShuffleboardLayout.h" #include "frc/shuffleboard/SimpleWidget.h" #ifndef DYNAMIC_CAMERA_SERVER #include "frc/shuffleboard/SendableCameraWrapper.h" inline frc::ComplexWidget& frc::ShuffleboardContainer::Add( const cs::VideoSource& video) { return Add(frc::SendableCameraWrapper::Wrap(video)); } inline frc::ComplexWidget& frc::ShuffleboardContainer::Add( std::string_view title, const cs::VideoSource& video) { return Add(title, frc::SendableCameraWrapper::Wrap(video)); } #endif