INSTINCT Code Coverage Report


Directory: src/
File: internal/gui/windows/ColormapEditor.cpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 0 47 0.0%
Functions: 0 2 0.0%
Branches: 0 106 0.0%

Line Branch Exec Source
1 // This file is part of INSTINCT, the INS Toolkit for Integrated
2 // Navigation Concepts and Training by the Institute of Navigation of
3 // the University of Stuttgart, Germany.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9 /// @file ColormapEditor.cpp
10 /// @brief Colormap editor window
11 /// @author T. Topp (topp@ins.uni-stuttgart.de)
12 /// @date 2023-09-22
13
14 #include "ColormapEditor.hpp"
15
16 #include <imgui.h>
17 #include <imgui_stdlib.h>
18 #include <fmt/format.h>
19 #include <vector>
20
21 #include "util/Plot/Colormap.hpp"
22 #include "internal/FlowManager.hpp"
23
24 void NAV::gui::windows::ShowColormapEditor(bool* show)
25 {
26 if (!ImGui::Begin("Colormap Editor", show))
27 {
28 ImGui::End();
29 return;
30 }
31
32 auto showColormaps = [](std::vector<Colormap>& colormaps, bool flow) {
33 int colormapRemovalIdx = -1;
34
35 if (ImGui::BeginTable("##{} colormap table", 4, ImGuiTableFlags_SizingFixedFit, ImVec2(0.0F, 0.0F)))
36 {
37 ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 150.0F);
38 ImGui::TableSetupColumn("Discrete", ImGuiTableColumnFlags_WidthFixed, 25.0F);
39 ImGui::TableSetupColumn("Map", ImGuiTableColumnFlags_WidthStretch);
40 ImGui::TableSetupColumn("Delete", ImGuiTableColumnFlags_WidthFixed, 20.0F);
41
42 for (size_t i = 0; i < colormaps.size(); i++)
43 {
44 auto& cmap = colormaps.at(i);
45
46 ImGui::TableNextColumn();
47 ImGui::SetNextItemWidth(152.0F);
48 if (ImGui::InputText(fmt::format("##colormap name {}", i).c_str(), &cmap.name))
49 {
50 if (flow) { flow::ApplyChanges(); }
51 }
52
53 ImGui::TableNextColumn();
54 ImGui::SetNextItemWidth(145.0F);
55 if (ImGui::Checkbox(fmt::format("##colormap discrete {}", i).c_str(), &cmap.discrete))
56 {
57 cmap.version++;
58 if (flow) { flow::ApplyChanges(); }
59 }
60 if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Discrete?"); }
61
62 ImGui::TableNextColumn();
63 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
64 if (ColormapButton(fmt::format("##colormap button {}", i).c_str(), cmap, ImVec2(-1.0F, 0.0F)))
65 {
66 if (flow) { flow::ApplyChanges(); }
67 }
68
69 ImGui::TableNextColumn();
70 if (ImGui::Button(fmt::format("X##remove colormap {}", i).c_str())) { colormapRemovalIdx = static_cast<int>(i); }
71 if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Remove?"); }
72 }
73
74 ImGui::EndTable();
75 }
76
77 if (colormapRemovalIdx >= 0)
78 {
79 colormaps.erase(colormaps.begin() + static_cast<std::ptrdiff_t>(colormapRemovalIdx));
80 if (flow) { flow::ApplyChanges(); }
81 }
82
83 if (ImGui::Button("Add##colormap"))
84 {
85 colormaps.emplace_back();
86 if (flow) { flow::ApplyChanges(); }
87 }
88 };
89
90 if (ImGui::BeginTabBar("Colormap TabBar"))
91 {
92 if (ImGui::BeginTabItem("Global"))
93 {
94 showColormaps(ColormapsGlobal, false);
95 ImGui::EndTabItem();
96 }
97 if (ImGui::BeginTabItem("Flow"))
98 {
99 showColormaps(ColormapsFlow, true);
100 ImGui::EndTabItem();
101 }
102 ImGui::EndTabBar();
103 }
104
105 ImGui::End();
106 }
107