Commit 0264d282 authored by Gauthier Quesnel's avatar Gauthier Quesnel Committed by Gauthier Quesnel
Browse files

gui: adding sources editor

parent d0a1bdca
...@@ -4,6 +4,7 @@ project(irritator-gui VERSION 0.1.0 LANGUAGES CXX) ...@@ -4,6 +4,7 @@ project(irritator-gui VERSION 0.1.0 LANGUAGES CXX)
set(gui_sources set(gui_sources
dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp implot.h implot.cpp dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp implot.h implot.cpp
window-logger.cpp node-editor.hpp node-editor.cpp simulation-editor.cpp window-logger.cpp node-editor.hpp node-editor.cpp simulation-editor.cpp
sources.cpp
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.cpp ${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.cpp
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.h ${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.h
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui_demo.cpp ${PROJECT_SOURCE_DIR}/../../external/imgui/imgui_demo.cpp
......
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
#include <pwd.h> #include <pwd.h>
#include <unistd.h> #include <unistd.h>
#elif defined(__APPLE__) #elif defined(__APPLE__)
#include <sys/param.h>
#include <sys/mount.h>
#include <errno.h> #include <errno.h>
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
#include <pwd.h> #include <pwd.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <unistd.h> #include <unistd.h>
#elif defined(_WIN32) #elif defined(_WIN32)
#include <KnownFolders.h> #include <KnownFolders.h>
......
...@@ -2993,6 +2993,7 @@ application_show() ...@@ -2993,6 +2993,7 @@ application_show()
ImGui::MenuItem("Simulation", nullptr, &app.show_simulation); ImGui::MenuItem("Simulation", nullptr, &app.show_simulation);
ImGui::MenuItem("Plot", nullptr, &app.show_plot); ImGui::MenuItem("Plot", nullptr, &app.show_plot);
ImGui::MenuItem("Sources", nullptr, &app.show_sources);
ImGui::MenuItem("Settings", nullptr, &app.show_settings); ImGui::MenuItem("Settings", nullptr, &app.show_settings);
ImGui::MenuItem("Log", nullptr, &app.show_log); ImGui::MenuItem("Log", nullptr, &app.show_log);
...@@ -3037,6 +3038,9 @@ application_show() ...@@ -3037,6 +3038,9 @@ application_show()
if (app.show_demo) if (app.show_demo)
ImGui::ShowDemoWindow(); ImGui::ShowDemoWindow();
if (app.show_sources)
app.srcs.show(&app.show_sources);
return ret; return ret;
} }
......
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
#define ORG_VLEPROJECT_IRRITATOR_APP_NODE_EDITOR_2020 #define ORG_VLEPROJECT_IRRITATOR_APP_NODE_EDITOR_2020
#include <irritator/core.hpp> #include <irritator/core.hpp>
#include <irritator/external_source.hpp>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <map>
#include <thread> #include <thread>
#include <variant> #include <variant>
#include <vector> #include <vector>
...@@ -295,6 +297,22 @@ using observation_output = std::variant<std::monostate, ...@@ -295,6 +297,22 @@ using observation_output = std::variant<std::monostate,
file_output_id, file_output_id,
file_discrete_output_id>; file_discrete_output_id>;
struct sources
{
std::map<int, irt::source::constant> csts;
std::map<int, irt::source::binary_file> bins;
std::map<int, irt::source::text_file> texts;
int csts_next_id = 1;
int bins_next_id = 1;
int texts_next_id = 1;
irt::source::constant* new_constant() noexcept;
irt::source::binary_file* new_binary_file() noexcept;
irt::source::text_file* new_text_file() noexcept;
void show(bool* is_show);
};
struct editor struct editor
{ {
small_string<16> name; small_string<16> name;
...@@ -358,9 +376,8 @@ struct editor ...@@ -358,9 +376,8 @@ struct editor
void observation_outputs_free(const u32 index) noexcept void observation_outputs_free(const u32 index) noexcept
{ {
observation_dispatch(index, [](auto& outs, auto out_id) { observation_dispatch(
outs.free(out_id); index, [](auto& outs, auto out_id) { outs.free(out_id); });
});
observation_outputs[index] = std::monostate{}; observation_outputs[index] = std::monostate{};
} }
...@@ -516,11 +533,14 @@ struct application ...@@ -516,11 +533,14 @@ struct application
void show(bool* is_open); void show(bool* is_open);
} settings; } settings;
sources srcs;
bool show_log = true; bool show_log = true;
bool show_simulation = true; bool show_simulation = true;
bool show_demo = false; bool show_demo = false;
bool show_plot = true; bool show_plot = true;
bool show_settings = false; bool show_settings = false;
bool show_sources = false;
editor* alloc_editor(); editor* alloc_editor();
void free_editor(editor& ed); void free_editor(editor& ed);
......
This diff is collapsed.
...@@ -4606,6 +4606,7 @@ struct external_source ...@@ -4606,6 +4606,7 @@ struct external_source
sz index = 0; // of data and size. sz index = 0; // of data and size.
sz size = 0; sz size = 0;
u64 id = 0; u64 id = 0;
u32 type = 0;
function_ref<bool(external_source& src)> expand; function_ref<bool(external_source& src)> expand;
......
...@@ -8,13 +8,26 @@ ...@@ -8,13 +8,26 @@
#include <irritator/core.hpp> #include <irritator/core.hpp>
#include <array> #include <array>
#include <filesystem>
#include <fstream> #include <fstream>
namespace irt::source { namespace irt::source {
struct constant
{
double value;
bool operator()(external_source& src)
{
src.index = 0;
return true;
}
};
struct binary_file struct binary_file
{ {
std::array<char, 1024 * 1024> buffer; std::array<char, 1024 * 1024> buffer;
std::filesystem::path file_path;
std::ifstream ifs; std::ifstream ifs;
sz buffer_size = 0; sz buffer_size = 0;
bool use_rewind = false; bool use_rewind = false;
...@@ -23,6 +36,13 @@ struct binary_file ...@@ -23,6 +36,13 @@ struct binary_file
bool init(external_source& src) bool init(external_source& src)
{ {
if (!ifs) {
ifs.open(file_path);
if (!ifs)
return false;
}
if (!read(src)) if (!read(src))
return false; return false;
} }
...@@ -61,6 +81,7 @@ private: ...@@ -61,6 +81,7 @@ private:
struct text_file struct text_file
{ {
std::array<double, 1024 * 1024 / 8> buffer; std::array<double, 1024 * 1024 / 8> buffer;
std::filesystem::path file_path;
std::ifstream ifs; std::ifstream ifs;
bool use_rewind = false; bool use_rewind = false;
...@@ -68,6 +89,13 @@ struct text_file ...@@ -68,6 +89,13 @@ struct text_file
bool init(external_source& src) bool init(external_source& src)
{ {
if (!ifs) {
ifs.open(file_path);
if (!ifs)
return false;
}
if (!read(src)) if (!read(src))
return false; return false;
} }
......
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