Commit 4737c13f authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

WIP

parent 193fe47e
Pipeline #40514 failed with stage
in 1 minute and 7 seconds
......@@ -48,16 +48,16 @@ build_models_recursively(const modeling& mod,
}
static status
build_connection(const modeling& mod,
const component_ref& comp,
simulation& sim,
int index)
build_simulation_connection(const component& src,
model_id mdl_src,
i8 port_src,
const component& dst,
model_id mdl_dst,
i8 port_dst,
simulation& sim)
{
auto src_id = enum_cast<model_id>(comp.connections[i].src);
auto dst_id = enum_cast<model_id>(comp.connections[i].dst);
auto* src_map_id = comp.mappers.get(src_id);
auto* dst_map_id = comp.mappers.get(dst_id);
auto* src_map_id = src.mappers.get(mdl_src);
auto* dst_map_id = dst.mappers.get(mdl_dst);
irt_return_if_fail(src_map_id && dst_map_id,
status::model_connect_unknown_dynamics);
......@@ -68,34 +68,94 @@ build_connection(const modeling& mod,
irt_return_if_fail(src_sim && dst_sim,
status::model_connect_unknown_dynamics);
return sim.connect(*src_sim,
comp.connections[i].port_src,
*dst_sim,
comp.connections[i].port_dst);
return sim.connect(*src_sim, port_src, *dst_sim, port_dst);
}
static status
build_model_to_model_connection(const modeling& mod,
const component_ref& comp_ref,
simulation& sim,
int i)
{
irt_assert(comp_ref.connections[i].type_src == child_type::model);
irt_assert(comp_ref.connections[i].type_dst == child_type::model);
irt_assert(i >= 0 && i < comp_ref.connections.size());
auto src_id = enum_cast<model_id>(comp_ref.connections[i].src);
auto dst_id = enum_cast<model_id>(comp_ref.connections[i].dst);
return build_simulation_connection(comp_ref,
src_id,
comp.connections[i].port_src,
comp_ref,
dst_id,
comp.connections[i].port_dst,
sim);
}
static status
build_model_to_component_connection(const modeling& mod,
const component_ref& compo_ref,
simulation& sim,
int index)
{
irt_assert(comp_ref.connections[i].type_src == child_type::model);
irt_assert(comp_ref.connections[i].type_dst == child_type::component);
irt_assert(i >= 0 && i < comp_ref.connections.size());
auto* compo = m.components.try_to_get(compo_ref.id);
if (!compo)
return status::success; // @todo certainly an error
if (comp.connections[index].port_dst >= length(compo->x))
return status::success; // @todo certainly an error
if (comp.connections[index].type == child_type::model) {
// classic connection between compo_ref
} else {
}
}
static status
build_connections_recursively(const modeling& mod,
const component_ref& comp,
const component_ref& compo_ref,
simulation& sim)
{
auto compo_id = m.component_refs.get_id(comp);
auto* compo = m.components.try_to_get(compo_ref.id);
if (!compo)
return status::success; // @todo certainly an error
for (i64 i = 0, e = compo->children.size(); i != e; ++i) {
if (compo->children[i].type == child_type::component) {
u64 id = compo->children[i].id;
auto child_c_ref_id = enum_cast<component_ref_id>(id);
auto* child_c_ref = mod.component_refs.try_to_get(child_c_ref_id);
if (!child_c_ref)
continue;
build_connections_recursively(mod, *child_c_ref, sim);
}
}
for (i64 i = 0, e = comp.connections.size(); i != e; ++i) {
auto src = comp.connections[i].src;
auto dst = comp.connections[i].dst;
for (i64 i = 0, e = compo->connections.size(); i != e; ++i) {
auto src = compo->connections[i].src;
auto dst = compo->connections[i].dst;
if (comp.connections[i].type_src == child_type::model) {
if (comp.connections[i].type_dst == child_type::model) {
irt_return_if_fail(build_connection(mod, com, sim, i));
if (compo->connections[i].type_src == child_type::model) {
if (compo->connections[i].type_dst == child_type::model) {
irt_return_if_bad(
build_model_to_model_connection(mod, comp, sim, i));
} else {
// model to component connection
irt_return_if_bad(
build_model_to_component_connection(mod, comp, sim, i));
}
} else {
if (comp.connections[i].type_dst == child_type::model) {
// component to model connection
if (compo->connections[i].type_dst == child_type::model) {
irt_return_if_bad(
buid_component_to_model_connection(mod, comp, sim, i));
} else {
// component to component connection
irt_return_if_bad(
buid_component_to_component_connection(mod, comp, sim, i));
}
}
}
......
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