Skip to content

Commit

Permalink
Update plots when editing local YAML GRC in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
frankosterfeld committed Mar 15, 2024
1 parent 26e84d5 commit e518561
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/ui/dashboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,13 @@ void Dashboard::deletePlot(Plot *plot) {
m_plots.erase(it);
}

void Dashboard::removeSinkFromPlots(std::string_view sinkName) {
for (auto &plot : m_plots) {
std::erase(plot.sourceNames, std::string(sinkName));
}
std::erase_if(m_plots, [](const Plot &p) { return p.sourceNames.empty(); });
}

void Dashboard::loadPlotSources() {
for (auto &plot : m_plots) {
plot.sources.clear();
Expand Down
1 change: 1 addition & 0 deletions src/ui/dashboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Dashboard : public std::enable_shared_from_this<Dashboard> {

void newPlot(int x, int y, int w, int h);
void deletePlot(Plot *plot);
void removeSinkFromPlots(std::string_view sinkName);

inline const auto &sources() const { return m_sources; }
inline auto &sources() { return m_sources; }
Expand Down
2 changes: 1 addition & 1 deletion src/ui/imguiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
});

app.dashboardPage.newPlot(app.dashboard.get());
app.dashboard->plots().back().sources.push_back(&*source);
app.dashboard->plots().back().sourceNames.push_back(source->name);
}
ctx.block = block.get();

Expand Down
22 changes: 22 additions & 0 deletions src/ui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#else
#include <SDL_opengl.h>
#endif

#include <algorithm>
#include <array>
#include <cstdio>

Expand Down Expand Up @@ -416,7 +418,27 @@ static void main_loop(void *arg) {
}
ImGui::SameLine();
if (ImGui::Button("Apply")) {
auto sinkNames = [](const auto &sinks) {
std::vector<std::string> names;
std::ranges::transform(sinks, std::back_inserter(names), [](const auto &s) { return s->name; });
std::ranges::sort(names);
names.erase(std::unique(names.begin(), names.end()), names.end());
return names;
};
const auto oldNames = sinkNames(app->dashboard->localFlowGraph.sinkBlocks());
app->dashboard->localFlowGraph.parse(localFlowgraphGrc);
const auto newNames = sinkNames(app->dashboard->localFlowGraph.sinkBlocks());
std::vector<std::string> toRemove;
std::ranges::set_difference(oldNames, newNames, std::back_inserter(toRemove));
std::vector<std::string> toAdd;
std::ranges::set_difference(newNames, oldNames, std::back_inserter(toAdd));
for (const auto &name : toRemove) {
app->dashboard->removeSinkFromPlots(name);
}
for (const auto &newName : toAdd) {
app->dashboardPage.newPlot(app->dashboard.get());
app->dashboard->plots().back().sourceNames.push_back(newName);
}
}

ImGui::InputTextMultiline("##grc", &localFlowgraphGrc, ImGui::GetContentRegionAvail());
Expand Down

0 comments on commit e518561

Please sign in to comment.