Skip to content

Commit

Permalink
core: updating generator behaviour with external transition
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jun 20, 2024
1 parent 7138f0d commit 0a4530a
Show file tree
Hide file tree
Showing 9 changed files with 508 additions and 184 deletions.
199 changes: 167 additions & 32 deletions app/gui/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,51 @@ void show_dynamics_inputs(external_source& srcs, priority_queue& dyn)

void show_dynamics_inputs(external_source& srcs, generator& dyn)
{
ImGui::InputReal("offset", &dyn.default_offset);
ImGui::Checkbox("Stop on error", &dyn.stop_on_error);
ImGui::SameLine();
HelpMarker("Unchecked, the generator stops to send data if the source are "
"empty or undefined. Checked, the simulation will stop.");
const char* menu[] = { "source", "external events" };

show_external_sources_combo(srcs, "source", dyn.default_source_value);
show_external_sources_combo(srcs, "time", dyn.default_source_ta);
auto combo_ta = dyn.flags[generator::option::ta_use_source] ? 0 : 1;
auto combo_value = dyn.flags[generator::option::value_use_source] ? 0 : 1;

{
auto ret = ImGui::Combo("ta", &combo_ta, menu, length(menu));
ImGui::SameLine();
HelpMarker(
"`Source` means you need to setup external source like random "
"number, input file etc. In `external events`, the value comes "
"from the input ports.");

if (ret)
dyn.flags.set(generator::option::ta_use_source, combo_ta == 0);
}

{
auto ret = ImGui::Combo("value", &combo_value, menu, length(menu));
ImGui::SameLine();
HelpMarker(
"`Source` means you need to setup external source like random "
"number, input file etc. In `external events`, the value comes "
"from the input port.");

if (ret)
dyn.flags.set(generator::option::value_use_source,
combo_value == 0);
}

if (dyn.flags[generator::option::ta_use_source]) {
auto stop_on_error = dyn.flags[generator::option::stop_on_error];

show_external_sources_combo(srcs, "time", dyn.default_source_ta);
ImGui::InputReal("offset", &dyn.default_offset);
if (ImGui::Checkbox("Stop on error", &stop_on_error))
dyn.flags.set(generator::option::stop_on_error);
ImGui::SameLine();
HelpMarker(
"Unchecked, the generator stops to send data if the source are "
"empty or undefined. Checked, the simulation will stop.");
}

if (dyn.flags[generator::option::value_use_source])
show_external_sources_combo(srcs, "source", dyn.default_source_value);
}

void show_dynamics_inputs(external_source& /*srcs*/, constant& dyn)
Expand Down Expand Up @@ -870,27 +907,76 @@ static bool show_parameter_editor(application& app,
}

static bool show_parameter_editor(application& app,
generator& /*dyn*/,
generator& /* dyn */,
parameter& p) noexcept
{
bool is_changed = false;
bool value = p.integers[0] != 0;
static const char* items[] = { "source", "external events" };

if (ImGui::Checkbox("Stop on error", &value)) {
p.integers[0] = value ? 1 : 0;
is_changed = true;
auto flags = bitflags<generator::option>(p.integers[0]);
auto is_changed = false;

auto combo_ta = flags[generator::option::ta_use_source] ? 0 : 1;
auto combo_value = flags[generator::option::value_use_source] ? 0 : 1;

{
auto ret = ImGui::Combo("ta", &combo_ta, items, length(items));
ImGui::SameLine();
HelpMarker(
"`Source` means you need to setup external source like random "
"number, input file etc. In `external events`, the value comes "
"from the input ports.");

if (ret) {
flags.set(generator::option::ta_use_source, combo_ta == 0);
is_changed = true;
}
}

if (show_external_sources_combo(
app.mod.srcs, "source", p.integers[1], p.integers[2])) {
is_changed = true;
{
auto ret = ImGui::Combo("value", &combo_value, items, length(items));
ImGui::SameLine();
HelpMarker(
"`Source` means you need to setup external source like random "
"number, input file etc. In `external events`, the value comes "
"from the input port.");

if (ret) {
flags.set(generator::option::value_use_source, combo_value == 0);
is_changed = true;
}
}

if (show_external_sources_combo(
app.mod.srcs, "time", p.integers[3], p.integers[4])) {
is_changed = true;
if (is_changed)
p.integers[0] = flags.to_unsigned();

if (flags[generator::option::ta_use_source]) {
auto stop_on_error = flags[generator::option::stop_on_error];

if (show_external_sources_combo(
app.mod.srcs, "time", p.integers[1], p.integers[2]))
is_changed = true;

if (ImGui::InputReal("offset", &p.reals[0])) {
p.reals[0] = p.reals[0] < 0.0 ? 0.0 : p.reals[0];
is_changed = true;
}

if (ImGui::Checkbox("Stop on error", &stop_on_error)) {
flags.set(generator::option::stop_on_error, stop_on_error);
is_changed = true;
}

ImGui::SameLine();
HelpMarker(
"Unchecked, the generator stops to send data if the source are "
"empty or undefined. Checked, the simulation will stop.");
}

if (flags[generator::option::value_use_source])
if (show_external_sources_combo(
app.mod.srcs, "source", p.integers[3], p.integers[4]))
is_changed = true;

return is_changed;
}

Expand Down Expand Up @@ -1502,24 +1588,73 @@ bool show_parameter(dynamics_generator_tag,
application& app,
parameter& p) noexcept
{
bool is_changed = false;
bool value = p.integers[0] != 0;
static const char* items[] = { "source", "external events" };

if (ImGui::Checkbox("Stop on error", &value)) {
p.integers[0] = value ? 1 : 0;
is_changed = true;
auto flags = bitflags<generator::option>(p.integers[0]);
auto is_changed = false;

auto combo_ta = flags[generator::option::ta_use_source] ? 0 : 1;
auto combo_value = flags[generator::option::value_use_source] ? 0 : 1;

{
auto ret = ImGui::Combo("ta", &combo_ta, items, length(items));
ImGui::SameLine();
HelpMarker(
"`Source` means you need to setup external source like random "
"number, input file etc. In `external events`, the value comes "
"from the input ports.");

if (ret) {
flags.set(generator::option::ta_use_source, combo_ta == 0);
is_changed = true;
}
}

if (show_external_sources_combo(
app.mod.srcs, "source", p.integers[1], p.integers[2])) {
is_changed = true;
{
auto ret = ImGui::Combo("value", &combo_value, items, length(items));
ImGui::SameLine();
HelpMarker(
"`Source` means you need to setup external source like random "
"number, input file etc. In `external events`, the value comes "
"from the input port.");

if (ret) {
flags.set(generator::option::value_use_source, combo_value == 0);
is_changed = true;
}
}

if (show_external_sources_combo(
app.mod.srcs, "time", p.integers[3], p.integers[4])) {
is_changed = true;
if (is_changed)
p.integers[0] = flags.to_unsigned();

if (flags[generator::option::ta_use_source]) {
auto stop_on_error = flags[generator::option::stop_on_error];

if (show_external_sources_combo(
app.mod.srcs, "time", p.integers[1], p.integers[2]))
is_changed = true;

if (ImGui::InputReal("offset", &p.reals[0])) {
p.reals[0] = p.reals[0] < 0.0 ? 0.0 : p.reals[0];
is_changed = true;
}

if (ImGui::Checkbox("Stop on error", &stop_on_error)) {
flags.set(generator::option::stop_on_error, stop_on_error);
is_changed = true;
}

ImGui::SameLine();
HelpMarker(
"Unchecked, the generator stops to send data if the source are "
"empty or undefined. Checked, the simulation will stop.");
}

if (flags[generator::option::value_use_source])
if (show_external_sources_combo(
app.mod.srcs, "source", p.integers[3], p.integers[4]))
is_changed = true;

return is_changed;
}

Expand Down Expand Up @@ -1814,8 +1949,8 @@ bool show_parameter(dynamics_logical_invert_tag,
return false;
}

static auto get_current_component_name(application& app,
parameter& p) noexcept -> const char*
static auto get_current_component_name(application& app, parameter& p) noexcept
-> const char*
{
static constexpr auto undefined_name = "-";

Expand Down
17 changes: 12 additions & 5 deletions lib/include/irritator/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,8 +1585,8 @@ class ring_buffer
using memory_resource_t = typename A::memory_resource_t;

static_assert((std::is_nothrow_constructible_v<T> ||
std::is_nothrow_move_constructible_v<T>) &&
std::is_nothrow_destructible_v<T>);
std::is_nothrow_move_constructible_v<
T>)&&std::is_nothrow_destructible_v<T>);

private:
T* buffer = nullptr;
Expand Down Expand Up @@ -1891,8 +1891,8 @@ class small_ring_buffer
public:
static_assert(length >= 1);
static_assert((std::is_nothrow_constructible_v<T> ||
std::is_nothrow_move_constructible_v<T>) &&
std::is_nothrow_destructible_v<T>);
std::is_nothrow_move_constructible_v<
T>)&&std::is_nothrow_destructible_v<T>);

using value_type = T;
using size_type = small_storage_size_t<length>;
Expand Down Expand Up @@ -2035,11 +2035,11 @@ class bitflags
static_assert(std::is_enum_v<EnumT>,
"irt::flags can only be used with enum types");

public:
using value_type = EnumT;
using underlying_type = typename std::make_unsigned_t<
typename std::underlying_type_t<value_type>>;

public:
constexpr bitflags() noexcept = default;
constexpr bitflags(unsigned long long val) noexcept;

Expand All @@ -2055,6 +2055,7 @@ class bitflags

constexpr std::size_t size() const noexcept;
constexpr std::size_t count() const noexcept;
std::size_t to_unsigned() const noexcept;

constexpr bool operator[](value_type e) const;

Expand Down Expand Up @@ -5597,6 +5598,12 @@ constexpr std::size_t bitflags<EnumT>::count() const noexcept
return m_bits.count();
}

template<typename EnumT>
std::size_t bitflags<EnumT>::to_unsigned() const noexcept
{
return m_bits.to_ullong();
}

template<typename EnumT>
constexpr bool bitflags<EnumT>::operator[](value_type e) const
{
Expand Down
Loading

0 comments on commit 0a4530a

Please sign in to comment.