Skip to content

Commit

Permalink
app: fix data window sim/mod srcs access
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jun 20, 2024
1 parent 6ecad86 commit c861fb2
Show file tree
Hide file tree
Showing 10 changed files with 712 additions and 584 deletions.
37 changes: 22 additions & 15 deletions app/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,22 +794,29 @@ void application::start_init_source(const u64 id,

attempt_all(
[&]() noexcept -> status {
irt_check(
sim.srcs.dispatch(src, source::operation_type::initialize));

data_ed.plot.clear();
for (sz i = 0, e = src.buffer.size(); i != e; ++i)
data_ed.plot.push_back(ImVec2{
static_cast<float>(i), static_cast<float>(src.buffer[i]) });
data_ed.plot_available = true;

return mod.srcs.prepare();
if (mod.srcs.dispatch(src, source::operation_type::initialize)) {
data_ed.plot.clear();
for (sz i = 0, e = src.buffer.size(); i != e; ++i)
data_ed.plot.push_back(
ImVec2{ static_cast<float>(i),
static_cast<float>(src.buffer[i]) });
data_ed.plot_available = true;

if (!mod.srcs.prepare())
notifications.try_insert(
log_level::error, [](auto& title, auto& msg) noexcept {
title = "Data error";
msg = "Fail to prepare data from source.";
});
}
return success();
},

[&]() -> void {
auto& n = notifications.alloc(log_level::error);
n.title = "Fail to initialize data";
notifications.enable(n);
[&]() {
notifications.try_insert(
log_level::error, [](auto& title, auto& msg) noexcept {
title = "Data error";
msg = "Fail to prepare data from source.";
});
});
});
}
Expand Down
24 changes: 18 additions & 6 deletions app/gui/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace irt {

template<class T, class M>
constexpr std::ptrdiff_t offset_of(const M T::* member)
constexpr std::ptrdiff_t offset_of(const M T::*member)
{
return reinterpret_cast<std::ptrdiff_t>(
&(reinterpret_cast<T*>(0)->*member));
Expand All @@ -44,7 +44,7 @@ constexpr std::ptrdiff_t offset_of(const M T::* member)
//! }
//! @endcode
template<class T, class M>
constexpr T& container_of(M* ptr, const M T::* member)
constexpr T& container_of(M* ptr, const M T::*member)
{
return *reinterpret_cast<T*>(reinterpret_cast<intptr_t>(ptr) -
offset_of(member));
Expand Down Expand Up @@ -632,10 +632,22 @@ struct data_window {

ImPlotContext* context = nullptr;

irt::constant_source* constant_ptr = nullptr;
irt::binary_file_source* binary_file_ptr = nullptr;
irt::text_file_source* text_file_ptr = nullptr;
irt::random_source* random_source_ptr = nullptr;
struct selection {
void clear() noexcept;

void select(constant_source_id id) noexcept;
void select(text_file_source_id id) noexcept;
void select(binary_file_source_id id) noexcept;
void select(random_source_id id) noexcept;

bool is(constant_source_id id) const noexcept;
bool is(text_file_source_id id) const noexcept;
bool is(binary_file_source_id id) const noexcept;
bool is(random_source_id id) const noexcept;

std::optional<source::source_type> type_sel;
u64 id_sel = 0;
} sel;

bool show_file_dialog = false;
bool plot_available = false;
Expand Down
Loading

0 comments on commit c861fb2

Please sign in to comment.