mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[glass] Split DataSource into type-specific variants (#7588)
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
|
||||
using namespace glass;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <imgui_internal.h>
|
||||
#include <numbers>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
|
||||
using namespace glass;
|
||||
|
||||
@@ -80,12 +80,12 @@ void glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
|
||||
}
|
||||
|
||||
// Game Specific Message
|
||||
wpi::SmallString<64> gameSpecificMessageBuf;
|
||||
std::string gameSpecificMessage{
|
||||
model->GetGameSpecificMessage(gameSpecificMessageBuf)};
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
|
||||
if (ImGui::InputText("Game Specific", &gameSpecificMessage)) {
|
||||
model->SetGameSpecificMessage(gameSpecificMessage);
|
||||
if (auto data = model->GetGameSpecificMessageData()) {
|
||||
std::string gameSpecificMessage = data->GetValue();
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
|
||||
if (ImGui::InputText("Game Specific", &gameSpecificMessage)) {
|
||||
model->SetGameSpecificMessage(gameSpecificMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,11 +148,11 @@ void glass::DisplayFMSReadOnly(FMSModel* model) {
|
||||
ImGui::TextUnformatted("?");
|
||||
}
|
||||
}
|
||||
|
||||
wpi::SmallString<64> gameSpecificMessageBuf;
|
||||
std::string_view gameSpecificMessage =
|
||||
model->GetGameSpecificMessage(gameSpecificMessageBuf);
|
||||
ImGui::Text("Game Specific: %s", exists ? gameSpecificMessage.data() : "?");
|
||||
if (auto data = model->GetGameSpecificMessageData()) {
|
||||
wpi::SmallString<64> gsmBuf;
|
||||
ImGui::Text("Game Specific: %s",
|
||||
exists ? data->GetValue(gsmBuf).data() : "?");
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
@@ -4,11 +4,8 @@
|
||||
|
||||
#include "glass/other/PIDController.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
|
||||
using namespace glass;
|
||||
|
||||
@@ -82,12 +82,13 @@ class PlotSeries {
|
||||
private:
|
||||
bool IsDigital() const {
|
||||
return m_digital.GetValue() == kDigital ||
|
||||
(m_digital.GetValue() == kAuto && m_source && m_source->IsDigital());
|
||||
(m_digital.GetValue() == kAuto && m_source && m_digitalSource);
|
||||
}
|
||||
void AppendValue(double value, int64_t time);
|
||||
|
||||
// source linkage
|
||||
DataSource* m_source = nullptr;
|
||||
bool m_digitalSource = false;
|
||||
wpi::sig::ScopedConnection m_sourceCreatedConn;
|
||||
wpi::sig::ScopedConnection m_newValueConn;
|
||||
std::string& m_id;
|
||||
@@ -255,11 +256,39 @@ void PlotSeries::CheckSource() {
|
||||
void PlotSeries::SetSource(DataSource* source) {
|
||||
m_source = source;
|
||||
|
||||
// add initial value
|
||||
AppendValue(source->GetValue(), 0);
|
||||
if (auto s = dynamic_cast<BooleanSource*>(source)) {
|
||||
m_digitalSource = true;
|
||||
|
||||
m_newValueConn = source->valueChanged.connect_connection(
|
||||
[this](double value, int64_t time) { AppendValue(value, time); });
|
||||
// add initial value
|
||||
AppendValue(s->GetValue(), 0);
|
||||
|
||||
m_newValueConn = s->valueChanged.connect_connection(
|
||||
[this](bool value, int64_t time) { AppendValue(value, time); });
|
||||
} else if (auto s = dynamic_cast<DoubleSource*>(source)) {
|
||||
m_digitalSource = false;
|
||||
|
||||
// add initial value
|
||||
AppendValue(s->GetValue(), 0);
|
||||
|
||||
m_newValueConn = s->valueChanged.connect_connection(
|
||||
[this](double value, int64_t time) { AppendValue(value, time); });
|
||||
} else if (auto s = dynamic_cast<FloatSource*>(source)) {
|
||||
m_digitalSource = false;
|
||||
|
||||
// add initial value
|
||||
AppendValue(s->GetValue(), 0);
|
||||
|
||||
m_newValueConn = s->valueChanged.connect_connection(
|
||||
[this](double value, int64_t time) { AppendValue(value, time); });
|
||||
} else if (auto s = dynamic_cast<IntegerSource*>(source)) {
|
||||
m_digitalSource = false;
|
||||
|
||||
// add initial value
|
||||
AppendValue(s->GetValue(), 0);
|
||||
|
||||
m_newValueConn = s->valueChanged.connect_connection(
|
||||
[this](int64_t value, int64_t time) { AppendValue(value, time); });
|
||||
}
|
||||
}
|
||||
|
||||
void PlotSeries::AppendValue(double value, int64_t timeUs) {
|
||||
@@ -522,9 +551,18 @@ Plot::Plot(Storage& storage)
|
||||
}
|
||||
|
||||
void Plot::DragDropAccept(PlotView& view, size_t i, int yAxis) {
|
||||
if (const ImGuiPayload* payload =
|
||||
ImGui::AcceptDragDropPayload("DataSource")) {
|
||||
auto source = *static_cast<DataSource**>(payload->Data);
|
||||
// accept any of double/float/boolean/integer sources
|
||||
DataSource* source = AcceptDragDropPayload<DoubleSource>();
|
||||
if (!source) {
|
||||
source = AcceptDragDropPayload<FloatSource>();
|
||||
}
|
||||
if (!source) {
|
||||
source = AcceptDragDropPayload<BooleanSource>();
|
||||
}
|
||||
if (!source) {
|
||||
source = AcceptDragDropPayload<IntegerSource>();
|
||||
}
|
||||
if (source) {
|
||||
// don't add duplicates unless it's onto a different Y axis
|
||||
auto it =
|
||||
std::find_if(m_series.begin(), m_series.end(), [=](const auto& elem) {
|
||||
|
||||
@@ -4,11 +4,8 @@
|
||||
|
||||
#include "glass/other/ProfiledPIDController.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
|
||||
using namespace glass;
|
||||
|
||||
Reference in New Issue
Block a user