Commit 328adfcc authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: add select output directory

parent a9803dd9
Pipeline #23419 passed with stage
in 1 minute and 18 seconds
......@@ -575,7 +575,118 @@ save_file_dialog(std::filesystem::path& out)
const auto item_spacing = ImGui::GetStyle().ItemSpacing.x;
const auto region_width = ImGui::GetContentRegionAvail().x;
const auto button_size = ImVec2{ (region_width - item_spacing) / 2.f, 0};
const auto button_size =
ImVec2{ (region_width - item_spacing) / 2.f, 0 };
if (ImGui::Button("Ok", button_size)) {
auto sel = fd.current;
sel /= fd.buffer;
out = sel;
res = true;
}
ImGui::SetItemDefaultFocus();
ImGui::SameLine();
if (ImGui::Button("Cancel", button_size)) {
res = true;
}
if (res) {
ImGui::CloseCurrentPopup();
fd.clear();
}
ImGui::EndPopup();
}
return res;
}
bool
select_directory_dialog(std::filesystem::path& out)
{
if (fd.current.empty()) {
fd.fill_drives();
fd.selected.clear();
std::error_code error;
fd.current = std::filesystem::current_path(error);
}
std::filesystem::path next;
bool res = false;
if (ImGui::BeginPopupModal("Select directory")) {
bool path_click = false;
fd.show_drives(&path_click, &next);
if (!path_click)
fd.show_path(&path_click, &next);
if (!path_click) {
ImGui::BeginChild("##select_files",
ImVec2{ 0.f, 350.f },
true,
ImGuiWindowFlags_HorizontalScrollbar);
if (ImGui::Selectable("..##select_file", (fd.selected == ".."))) {
if (next.empty()) {
next = fd.current.parent_path();
fd.selected.clear();
path_click = true;
}
}
for (auto it = fd.paths.begin(), et = fd.paths.end(); it != et;
++it) {
fd.temp.clear();
if (std::filesystem::is_directory(*it)) {
#if defined(__APPLE__)
// @TODO Remove this part when XCode allows u8string
// concatenation.
fd.temp = "[Dir] ";
fd.temp += reinterpret_cast<const char*>(
it->filename().u8string().c_str());
#else
fd.temp = u8"[Dir] ";
fd.temp += it->filename().u8string();
#endif
if (ImGui::Selectable((const char*)fd.temp.c_str(),
(it->filename() == fd.selected))) {
fd.selected = it->filename();
if (next.empty()) {
fd.selected.clear();
next = fd.current;
next /= it->filename();
path_click = true;
}
break;
}
}
}
ImGui::EndChild();
}
if (path_click) {
fd.paths.clear();
fd.extension_filters = nullptr;
fd.file_filters = nullptr;
fd.copy_files_and_directories(next);
fd.sort();
fd.current = next;
}
ImGui::Text("Directory name: %s",
(const char*)fd.current.u8string().c_str());
const auto item_spacing = ImGui::GetStyle().ItemSpacing.x;
const auto region_width = ImGui::GetContentRegionAvail().x;
const auto button_size =
ImVec2{ (region_width - item_spacing) / 2.f, 0 };
if (ImGui::Button("Ok", button_size)) {
auto sel = fd.current;
......
......@@ -6,6 +6,7 @@
#define ORG_VLEPROJECT_IRRITATOR_APP_GUI_2020
#include <filesystem>
#include <optional>
namespace irt {
......@@ -34,6 +35,9 @@ load_file_dialog(std::filesystem::path& out);
bool
save_file_dialog(std::filesystem::path& out);
bool
select_directory_dialog(std::filesystem::path& out);
} // namespace irt
#endif
......@@ -970,6 +970,9 @@ editor::initialize(u32 id) noexcept
ImVec2{ 0.f, 0.f });
displacements.resize(sim.models.capacity() + clusters.capacity(),
ImVec2{ 0.f, 0.f });
observation_directory = std::filesystem::current_path();
} catch (const std::bad_alloc& /*e*/) {
return status::gui_not_enough_memory;
}
......@@ -2231,8 +2234,6 @@ bool
editor::show_editor() noexcept
{
imnodes::EditorContextSet(context);
static bool show_load_file_dialog = false;
static bool show_save_file_dialog = false;
ImGuiWindowFlags windows_flags = 0;
windows_flags |= ImGuiWindowFlags_MenuBar;
......@@ -2275,6 +2276,7 @@ editor::show_editor() noexcept
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edition")) {
ImGui::MenuItem("Show parameter in models",
nullptr,
......@@ -2416,6 +2418,16 @@ editor::show_editor() noexcept
ImGui::EndMenuBar();
}
if (show_select_directory_dialog) {
ImGui::OpenPopup("Select directory");
if (select_directory_dialog(observation_directory)) {
show_select_directory_dialog = false;
log_w.log(
5, "Output directory: %s", (const char*)path.u8string().c_str());
}
}
if (show_load_file_dialog) {
ImGui::OpenPopup("Select file path to load");
if (load_file_dialog(path)) {
......@@ -2952,19 +2964,19 @@ node_editor_show()
editor* next = ed;
editors.next(next);
editors_free(*ed);
} else {
if (show_log)
log_w.show(&show_log);
if (show_simulation)
show_simulation_box(*ed, log_w, &show_simulation);
if (show_plot)
show_plot_box(&show_plot);
}
}
}
if (show_log)
log_w.show(&show_log);
if (show_simulation)
show_simulation_box(log_w, &show_simulation);
if (show_plot)
show_plot_box(&show_plot);
if (show_demo)
ImGui::ShowDemoWindow();
......
......@@ -360,6 +360,10 @@ struct editor
std::string tooltip;
bool show_load_file_dialog = false;
bool show_save_file_dialog = false;
bool show_select_directory_dialog = false;
status initialize(u32 id) noexcept;
void clear() noexcept;
......@@ -444,7 +448,7 @@ editor*
make_combo_editor_name(editor_id& current) noexcept;
void
show_simulation_box(window_logger& log_w, bool* show_simulation);
show_simulation_box(editor& ed, window_logger& log_w, bool* show_simulation);
} // namespace irt
......
......@@ -427,7 +427,7 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
}
void
show_simulation_box(window_logger& log_w, bool* show_simulation)
show_simulation_box(editor& ed, window_logger& log_w, bool* show_simulation)
{
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(250, 350), ImGuiCond_Once);
......@@ -436,27 +436,35 @@ show_simulation_box(window_logger& log_w, bool* show_simulation)
return;
}
static editor_id current = undefined<editor_id>();
if (auto* ed = make_combo_editor_name(current); ed) {
ImGui::InputDouble("Begin", &ed->simulation_begin);
ImGui::InputDouble("End", &ed->simulation_end);
ImGui::Checkbox("Show values", &ed->simulation_show_value);
ImGui::InputDouble("Begin", &ed.simulation_begin);
ImGui::InputDouble("End", &ed.simulation_end);
ImGui::Checkbox("Show values", &ed.simulation_show_value);
if (ImGui::CollapsingHeader("Simulation run one"))
show_simulation_run_once(log_w, *ed);
if (ImGui::Button("Output files"))
ed.show_select_directory_dialog = true;
if (ImGui::CollapsingHeader("Debug simulation"))
show_simulation_run_debug(log_w, *ed);
ImGui::Text("output directory: ");
#if _WIN32
ImGui::Text("%s", ed.observation_directory.u8string().c_str());
#else
ImGui::Text("%s",
reinterpret_cast<const char*>(
ed.observation_directory.u8string().c_str()));
#endif
if (ed->st != editor_status::editing) {
ImGui::Text("Current: %g", ed->simulation_current);
if (ImGui::CollapsingHeader("Simulation run one"))
show_simulation_run_once(log_w, ed);
const double duration = ed->simulation_end - ed->simulation_begin;
const double elapsed =
ed->simulation_current - ed->simulation_begin;
const double fraction = elapsed / duration;
ImGui::ProgressBar(static_cast<float>(fraction));
}
if (ImGui::CollapsingHeader("Debug simulation"))
show_simulation_run_debug(log_w, ed);
if (ed.st != editor_status::editing) {
ImGui::Text("Current: %g", ed.simulation_current);
const double duration = ed.simulation_end - ed.simulation_begin;
const double elapsed = ed.simulation_current - ed.simulation_begin;
const double fraction = elapsed / duration;
ImGui::ProgressBar(static_cast<float>(fraction));
}
ImGui::End();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment