Skip to content

Commit

Permalink
core: enabling multi-graph in grid
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Oct 14, 2024
1 parent e987cc1 commit 1745328
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 26 deletions.
40 changes: 40 additions & 0 deletions lib/include/irritator/modeling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,26 @@ struct component {
return ret;
}

vector<port_id> get_x_starts_with(std::string_view str) const noexcept
{
vector<port_id> ret;

x.for_each<port_str>([&](const auto id, const auto& name) noexcept {
if (name.sv() == str) {
ret.emplace_back(id);
} else {
const auto str = name.sv();
const auto pos = str.find_last_of('_');

if (pos != std::string_view::npos and
str.substr(0, pos) == name)
ret.emplace_back(id);
}
});

return ret;
}

port_id get_y(std::string_view str) const noexcept
{
auto ret = undefined<port_id>();
Expand All @@ -777,6 +797,26 @@ struct component {
return ret;
}

vector<port_id> get_y_starts_with(std::string_view str) const noexcept
{
vector<port_id> ret;

y.for_each<port_str>([&](const auto id, const auto& name) noexcept {
if (name.sv() == str) {
ret.emplace_back(id);
} else {
const auto str = name.sv();
const auto pos = str.find_last_of('_');

if (pos != std::string_view::npos and
str.substr(0, pos) == name)
ret.emplace_back(id);
}
});

return ret;
}

port_id get_or_add_x(std::string_view str) noexcept
{
const auto id = get_x(str);
Expand Down
99 changes: 73 additions & 26 deletions lib/src/modeling-grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,86 @@ static auto build_grid_children(modeling& mod, grid_component& grid) noexcept
return ret;
}

struct split_name {
split_name(std::string_view str) noexcept
{
const auto pos = str.find_last_of('_');
if (pos != std::string_view::npos and
std::cmp_less(pos + 1, str.size())) {
left = str.substr(0, pos);
right = str.substr(pos + 1, std::string::npos);
} else {
left = str;
}
}

std::string_view left;
std::string_view right;
};

static void connection_add(modeling& mod,
grid_component& grid,
child_id src,
std::string_view port_src,
child_id dst,
std::string_view port_dst) noexcept
{
auto port_src_real = undefined<port_id>();
if_data_exists_do(grid.cache, src, [&](auto& child) noexcept {
debug::ensure(child.type == child_type::component);

if (child.type == child_type::component) {
if_data_exists_do(
mod.components, child.id.compo_id, [&](auto& compo) noexcept {
port_src_real = compo.get_y(port_src);
});
}
});

auto port_dst_real = undefined<port_id>();
if_data_exists_do(grid.cache, dst, [&](auto& child) noexcept {
debug::ensure(child.type == child_type::component);

if (child.type == child_type::component) {
if_data_exists_do(
mod.components, child.id.compo_id, [&](auto& compo) noexcept {
port_dst_real = compo.get_x(port_dst);
});
}
});

if (is_defined(port_src_real) && is_defined(port_dst_real))
grid.cache_connections.alloc(src, port_src_real, dst, port_dst_real);
auto* child_src = grid.cache.try_to_get(src);
auto* child_dst = grid.cache.try_to_get(dst);

debug::ensure(child_src == nullptr or
child_src->type != child_type::component);
debug::ensure(child_dst == nullptr or
child_dst->type != child_type::component);

auto* compo_src = mod.components.try_to_get(child_src->id.compo_id);
auto* compo_dst = mod.components.try_to_get(child_dst->id.compo_id);
debug::ensure(compo_src and compo_dst);

compo_src->y.for_each<port_str>(
[&](const auto sid, const auto& sname) noexcept {
split_name p_src(sname.sv());
if (port_src == p_src.left) {

compo_dst->x.for_each<port_str>(
[&](const auto did, const auto dname) noexcept {
split_name p_dst(dname.sv());

if (port_dst == p_dst.left) {

if (p_src.right == p_dst.right)
grid.cache_connections.alloc(src, sid, dst, did);
}
});
}
});

// auto port_src_real = undefined<port_id>();
// if_data_exists_do(grid.cache, src, [&](auto& child) noexcept {
// debug::ensure(child.type == child_type::component);

// if (child.type == child_type::component) {
// if_data_exists_do(
// mod.components, child.id.compo_id, [&](auto& compo) noexcept {
// ports_src = compo.get_x_starts_with(port_src);
// });
// }
// });

// auto port_dst_real = undefined<port_id>();
// if_data_exists_do(grid.cache, dst, [&](auto& child) noexcept {
// debug::ensure(child.type == child_type::component);

// if (child.type == child_type::component) {
// if_data_exists_do(
// mod.components, child.id.compo_id, [&](auto& compo) noexcept {
// port_dst_real = compo.get_x(port_dst);
// });
// }
// });

// if (is_defined(port_src_real) && is_defined(port_dst_real))
// grid.cache_connections.alloc(src, port_src_real, dst, port_dst_real);
}

void build_grid_connections(modeling& mod,
Expand Down

0 comments on commit 1745328

Please sign in to comment.