[sim] Add plotting to simulation GUI

This commit is contained in:
Peter Johnson
2020-08-14 20:02:35 -07:00
parent 70ba92f917
commit 1593eb4d47
29 changed files with 2550 additions and 301 deletions

View File

@@ -14,7 +14,33 @@
using namespace halsimgui;
void NameInfo::GetName(char* buf, size_t size, const char* defaultName) {
void NameInfo::GetName(char* buf, size_t size, const char* defaultName) const {
if (m_name[0] != '\0') {
std::snprintf(buf, size, "%s", m_name);
} else {
std::snprintf(buf, size, "%s", defaultName);
}
}
void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
int index) const {
if (m_name[0] != '\0') {
std::snprintf(buf, size, "%s [%d]", m_name, index);
} else {
std::snprintf(buf, size, "%s[%d]", defaultName, index);
}
}
void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
int index, int index2) const {
if (m_name[0] != '\0') {
std::snprintf(buf, size, "%s [%d,%d]", m_name, index, index2);
} else {
std::snprintf(buf, size, "%s[%d,%d]", defaultName, index, index2);
}
}
void NameInfo::GetLabel(char* buf, size_t size, const char* defaultName) const {
if (m_name[0] != '\0') {
std::snprintf(buf, size, "%s###Name%s", m_name, defaultName);
} else {
@@ -22,8 +48,8 @@ void NameInfo::GetName(char* buf, size_t size, const char* defaultName) {
}
}
void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
int index) {
void NameInfo::GetLabel(char* buf, size_t size, const char* defaultName,
int index) const {
if (m_name[0] != '\0') {
std::snprintf(buf, size, "%s [%d]###Name%d", m_name, index, index);
} else {
@@ -31,8 +57,8 @@ void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
}
}
void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
int index, int index2) {
void NameInfo::GetLabel(char* buf, size_t size, const char* defaultName,
int index, int index2) const {
if (m_name[0] != '\0') {
std::snprintf(buf, size, "%s [%d,%d]###Name%d", m_name, index, index2,
index);
@@ -66,30 +92,40 @@ void NameInfo::PushEditNameId(const char* name) {
ImGui::PushID(id);
}
void NameInfo::PopupEditName(int index) {
bool NameInfo::PopupEditName(int index) {
bool rv = false;
char id[64];
std::snprintf(id, sizeof(id), "Name%d", index);
if (ImGui::BeginPopupContextItem(id)) {
ImGui::Text("Edit name:");
if (ImGui::InputText("##edit", m_name, sizeof(m_name),
ImGuiInputTextFlags_EnterReturnsTrue))
if (InputTextName("##edit", ImGuiInputTextFlags_EnterReturnsTrue)) {
ImGui::CloseCurrentPopup();
rv = true;
}
if (ImGui::Button("Close")) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
return rv;
}
void NameInfo::PopupEditName(const char* name) {
bool NameInfo::PopupEditName(const char* name) {
bool rv = false;
char id[128];
std::snprintf(id, sizeof(id), "Name%s", name);
if (ImGui::BeginPopupContextItem(id)) {
ImGui::Text("Edit name:");
if (ImGui::InputText("##edit", m_name, sizeof(m_name),
ImGuiInputTextFlags_EnterReturnsTrue))
if (InputTextName("##edit", ImGuiInputTextFlags_EnterReturnsTrue)) {
ImGui::CloseCurrentPopup();
rv = true;
}
if (ImGui::Button("Close")) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
return rv;
}
bool NameInfo::InputTextName(const char* label_id, ImGuiInputTextFlags flags) {
return ImGui::InputText(label_id, m_name, sizeof(m_name), flags);
}
bool OpenInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {