WPILibC++  2020.3.2
ShuffleboardContainer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <functional>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include <networktables/NetworkTableEntry.h>
16 #include <networktables/NetworkTableValue.h>
17 #include <wpi/ArrayRef.h>
18 #include <wpi/SmallSet.h>
19 #include <wpi/StringMap.h>
20 #include <wpi/Twine.h>
21 
22 #include "frc/ErrorBase.h"
23 #include "frc/WPIErrors.h"
24 #include "frc/shuffleboard/BuiltInLayouts.h"
25 #include "frc/shuffleboard/LayoutType.h"
26 #include "frc/shuffleboard/ShuffleboardComponentBase.h"
27 #include "frc/shuffleboard/ShuffleboardValue.h"
28 #include "frc/shuffleboard/SuppliedValueWidget.h"
29 
30 namespace cs {
31 class VideoSource;
32 } // namespace cs
33 
34 namespace frc {
35 
36 class ComplexWidget;
37 class Sendable;
38 class ShuffleboardLayout;
39 class SimpleWidget;
40 
45  public ErrorBase {
46  public:
47  explicit ShuffleboardContainer(const wpi::Twine& title);
48 
50 
51  virtual ~ShuffleboardContainer() = default;
52 
56  const std::vector<std::unique_ptr<ShuffleboardComponentBase>>& GetComponents()
57  const;
58 
68 
78  const LayoutType& type);
79 
94  const wpi::Twine& type);
95 
111  ShuffleboardLayout& GetLayout(const wpi::Twine& title);
112 
122  ComplexWidget& Add(const wpi::Twine& title, Sendable& sendable);
123 
133  ComplexWidget& Add(const wpi::Twine& title, const cs::VideoSource& video);
134 
144  ComplexWidget& Add(Sendable& sendable);
145 
154  ComplexWidget& Add(const cs::VideoSource& video);
155 
166  SimpleWidget& Add(const wpi::Twine& title,
167  std::shared_ptr<nt::Value> defaultValue);
168 
179  SimpleWidget& Add(const wpi::Twine& title, bool defaultValue);
180 
191  SimpleWidget& Add(const wpi::Twine& title, double defaultValue);
192 
203  SimpleWidget& Add(const wpi::Twine& title, int defaultValue);
204 
215  SimpleWidget& Add(const wpi::Twine& title, const wpi::Twine& defaultValue);
216 
227  SimpleWidget& Add(const wpi::Twine& title, const char* defaultValue);
228 
239  SimpleWidget& Add(const wpi::Twine& title, wpi::ArrayRef<bool> defaultValue);
240 
251  SimpleWidget& Add(const wpi::Twine& title,
252  wpi::ArrayRef<double> defaultValue);
253 
264  SimpleWidget& Add(const wpi::Twine& title,
265  wpi::ArrayRef<std::string> defaultValue);
266 
278  const wpi::Twine& title, std::function<std::string()> supplier);
279 
291  std::function<double()> supplier);
292 
304  std::function<bool()> supplier);
305 
317  const wpi::Twine& title,
318  std::function<std::vector<std::string>()> supplier);
319 
331  const wpi::Twine& title, std::function<std::vector<double>()> supplier);
332 
344  const wpi::Twine& title, std::function<std::vector<int>()> supplier);
345 
357  const wpi::Twine& title, std::function<wpi::StringRef()> supplier);
358 
371  SimpleWidget& AddPersistent(const wpi::Twine& title,
372  std::shared_ptr<nt::Value> defaultValue);
373 
386  SimpleWidget& AddPersistent(const wpi::Twine& title, bool defaultValue);
387 
400  SimpleWidget& AddPersistent(const wpi::Twine& title, double defaultValue);
401 
414  SimpleWidget& AddPersistent(const wpi::Twine& title, int defaultValue);
415 
428  SimpleWidget& AddPersistent(const wpi::Twine& title,
429  const wpi::Twine& defaultValue);
430 
443  SimpleWidget& AddPersistent(const wpi::Twine& title,
444  wpi::ArrayRef<bool> defaultValue);
445 
458  SimpleWidget& AddPersistent(const wpi::Twine& title,
459  wpi::ArrayRef<double> defaultValue);
460 
473  SimpleWidget& AddPersistent(const wpi::Twine& title,
474  wpi::ArrayRef<std::string> defaultValue);
475 
476  void EnableIfActuator() override;
477 
478  void DisableIfActuator() override;
479 
480  protected:
481  bool m_isLayout = false;
482 
483  private:
484  wpi::SmallSet<std::string, 32> m_usedTitles;
485  std::vector<std::unique_ptr<ShuffleboardComponentBase>> m_components;
487 
493  void CheckTitle(const wpi::Twine& title);
494 
495  friend class SimpleWidget;
496 };
497 
498 } // namespace frc
499 
500 // Make use of references returned by member functions usable
501 #include "frc/shuffleboard/ComplexWidget.h"
502 #include "frc/shuffleboard/ShuffleboardLayout.h"
503 #include "frc/shuffleboard/SimpleWidget.h"
504 
505 #ifndef DYNAMIC_CAMERA_SERVER
506 #include "frc/shuffleboard/SendableCameraWrapper.h"
507 
509  const cs::VideoSource& video) {
510  return Add(frc::SendableCameraWrapper::Wrap(video));
511 }
512 
514  const wpi::Twine& title, const cs::VideoSource& video) {
515  return Add(title, frc::SendableCameraWrapper::Wrap(video));
516 }
517 #endif
frc::SuppliedValueWidget
Definition: SuppliedValueWidget.h:25
frc::LayoutType
Represents the type of a layout in Shuffleboard.
Definition: LayoutType.h:21
frc::ComplexWidget
A Shuffleboard widget that handles a Sendable object such as a speed controller or sensor.
Definition: ComplexWidget.h:28
frc::ShuffleboardLayout
A layout in a Shuffleboard tab.
Definition: ShuffleboardLayout.h:29
wpi::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
frc::ShuffleboardContainer::AddBooleanArray
SuppliedValueWidget< std::vector< int > > & AddBooleanArray(const wpi::Twine &title, std::function< std::vector< int >()> supplier)
Adds a widget to this container.
frc::ShuffleboardValue
Definition: ShuffleboardValue.h:19
frc::SimpleWidget
A Shuffleboard widget that handles a single data point such as a number or string.
Definition: SimpleWidget.h:26
frc::ShuffleboardContainer::GetLayout
ShuffleboardLayout & GetLayout(const wpi::Twine &title, BuiltInLayouts type)
Gets the layout with the given type and title, creating it if it does not already exist at the time t...
frc::ShuffleboardContainer::AddPersistent
SimpleWidget & AddPersistent(const wpi::Twine &title, std::shared_ptr< nt::Value > defaultValue)
Adds a widget to this container to display a simple piece of data.
frc::ShuffleboardContainer::Add
ComplexWidget & Add(const wpi::Twine &title, Sendable &sendable)
Adds a widget to this container to display the given sendable.
frc::ShuffleboardContainer
Common interface for objects that can contain shuffleboard components.
Definition: ShuffleboardContainer.h:44
frc::ShuffleboardContainer::EnableIfActuator
void EnableIfActuator() override
Enables user control of this widget in the Shuffleboard application.
cs
CameraServer (cscore) namespace.
Definition: cscore_cpp.h:35
wpi::SmallSet< std::string, 32 >
frc::ShuffleboardContainer::AddNumber
SuppliedValueWidget< double > & AddNumber(const wpi::Twine &title, std::function< double()> supplier)
Adds a widget to this container.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::BuiltInLayouts
BuiltInLayouts
The types of layouts bundled with Shuffleboard.
Definition: BuiltInLayouts.h:22
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
frc::ShuffleboardContainer::AddString
SuppliedValueWidget< std::string > & AddString(const wpi::Twine &title, std::function< std::string()> supplier)
Adds a widget to this container.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
wpi::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:206
frc::ShuffleboardContainer::AddStringArray
SuppliedValueWidget< std::vector< std::string > > & AddStringArray(const wpi::Twine &title, std::function< std::vector< std::string >()> supplier)
Adds a widget to this container.
frc::ShuffleboardContainer::AddBoolean
SuppliedValueWidget< bool > & AddBoolean(const wpi::Twine &title, std::function< bool()> supplier)
Adds a widget to this container.
frc::ShuffleboardContainer::GetComponents
const std::vector< std::unique_ptr< ShuffleboardComponentBase > > & GetComponents() const
Gets the components that are direct children of this container.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::ShuffleboardContainer::AddRaw
SuppliedValueWidget< wpi::StringRef > & AddRaw(const wpi::Twine &title, std::function< wpi::StringRef()> supplier)
Adds a widget to this container.
cs::VideoSource
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:97
frc::ShuffleboardContainer::AddNumberArray
SuppliedValueWidget< std::vector< double > > & AddNumberArray(const wpi::Twine &title, std::function< std::vector< double >()> supplier)
Adds a widget to this container.
frc::ShuffleboardContainer::DisableIfActuator
void DisableIfActuator() override
Disables user control of this widget in the Shuffleboard application.
frc::SendableCameraWrapper::Wrap
static SendableCameraWrapper & Wrap(const cs::VideoSource &source)
Gets a sendable wrapper object for the given video source, creating the wrapper if one does not alrea...
Definition: SendableCameraWrapper.h:82
wpi::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85