sophiar_monitor.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "module/sophiar_monitor.h"
  2. #include "core/imgui_utility.hpp"
  3. struct sophiar_monitor::impl {
  4. create_config conf;
  5. explicit impl(const create_config &_conf) {
  6. conf = _conf;
  7. }
  8. void show_item(const std::string &var_name,
  9. const std::string &show_name,
  10. bool last = false) {
  11. auto var = conf.sophiar_conn->query_transform_variable(var_name);
  12. bool var_ok = var.has_value();
  13. if (var_ok) {
  14. ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4) ImColor(0, 255, 0));
  15. } else {
  16. ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4) ImColor(255, 0, 0));
  17. }
  18. ImGui::Checkbox(show_name.c_str(), &var_ok);
  19. ImGui::PopStyleColor();
  20. if (!last) {
  21. ImGui::SameLine();
  22. }
  23. }
  24. void show() {
  25. for (auto k = 0; k < conf.item_list.size(); ++k) {
  26. auto &item = conf.item_list[k];
  27. show_item(item.var_name, item.disp_name,
  28. (k + 1) == conf.item_list.size());
  29. }
  30. }
  31. };
  32. sophiar_monitor::sophiar_monitor(const create_config &conf)
  33. : pimpl(std::make_unique<impl>(conf)) {
  34. }
  35. sophiar_monitor::~sophiar_monitor() = default;
  36. sophiar_monitor::item_list_type
  37. sophiar_monitor::item_list_from_yaml(const YAML::Node &_conf) {
  38. auto item_num = _conf.size();
  39. auto ret = item_list_type(item_num);
  40. for (auto k = 0; k < item_num; ++k) {
  41. auto conf = _conf[k];
  42. ret[k].disp_name = LOAD_STR("name");
  43. ret[k].var_name = LOAD_STR("var");
  44. }
  45. return ret;
  46. }
  47. void sophiar_monitor::show() {
  48. pimpl->show();
  49. }