Commit 193fe47e authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

WIP

parent fe528308
Pipeline #40469 failed with stage
in 1 minute
......@@ -16,7 +16,15 @@ enum class parameter_id = u64;
enum class vertice_type : i8
{
model, component;
model,
component
};
enum class connection_type : i8
{
internal,
input,
output
};
struct parameter;
......@@ -37,12 +45,13 @@ struct parameter
struct connection
{
u64 src; // model_id or component_id
u64 dst; // model_id or component_id
node_type type_src; // model or component
node_type type_dst; // model or component
i8 port_src; // output port index
i8 port_dst; // input port index
u64 src; // model_id or component_id
u64 dst; // model_id or component_id
node_type type_src; // model or component
node_type type_dst; // model or component
i8 port_src; // output port index
i8 port_dst; // input port index
connection_type type;
};
struct component_ref
......
......@@ -7,14 +7,20 @@
namespace irt {
static status
build_models(const modeling& mod, const component_ref& comp, simulation& sim)
build_models_recursively(const modeling& mod,
const component_ref& comp_ref,
simulation& sim)
{
comp.mappers.clear();
comp_ref.mappers.clear();
auto* comp = mod.components.try_to_get(comp_ref.id);
if (!comp)
return status::success; /* @TODO certainly an error in API */
for (i64 i = 0, e = comp.children.size(); i != e; ++i) {
u64 id = comp.children[i].id;
for (i64 i = 0, e = comp->children.size(); i != e; ++i) {
u64 id = comp->children[i].id;
if (comp.children[i].type == child_type::model) {
if (comp->children[i].type == child_type::model) {
auto src_id = enum_cast<model_id>(id);
auto* src = mod.models.try_to_get(src_id);
if (!src)
......@@ -26,18 +32,54 @@ build_models(const modeling& mod, const component_ref& comp, simulation& sim)
auto& dst = sim.models.clone(*src);
auto dst_id = sim.models.get_id(dst);
comp.mappers.data.emplace_back(src_id, dst_id);
irt_return_if_bad(
comp_ref.mappers.data.try_emplace_back(src_id, dst_id));
} else {
auto src_id = enum_cast<component_ref_id>(id);
auto* src = mod.component_refs.try_to_get(src_id);
if (!src)
continue;
irt_return_if_bad(build_models(mod, *src, sim));
irt_return_if_bad(build_models_recursively(mod, *src, sim));
}
}
com.mappers.sort();
return status::success;
}
static status
build_connection(const modeling& mod,
const component_ref& comp,
simulation& sim,
int index)
{
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);
irt_return_if_fail(src_map_id && dst_map_id,
status::model_connect_unknown_dynamics);
auto* src_sim = sim.models.try_to_get(*src_map_id);
auto* dst_sim = sim.models.try_to_get(*dst_map_id);
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);
}
static status
build_connections_recursively(const modeling& mod,
const component_ref& comp,
simulation& sim)
{
auto compo_id = m.component_refs.get_id(comp);
for (i64 i = 0, e = comp.connections.size(); i != e; ++i) {
auto src = comp.connections[i].src;
......@@ -45,7 +87,7 @@ build_models(const modeling& mod, const component_ref& comp, simulation& sim)
if (comp.connections[i].type_src == child_type::model) {
if (comp.connections[i].type_dst == child_type::model) {
// model to model connection
irt_return_if_fail(build_connection(mod, com, sim, i));
} else {
// model to component connection
}
......@@ -61,6 +103,13 @@ build_models(const modeling& mod, const component_ref& comp, simulation& sim)
return status::success;
}
static status
build_models(const modeling& mod, const component_ref& comp, simulation& sim)
{
irt_return_if_bad(build_models_recursively(mod, component_ref, sim));
irt_return_if_bad(build_connections_recursively(mod, component_ref, sim));
}
status
build_simulation(const modeling& mod, simulation& sim)
{
......@@ -68,7 +117,7 @@ build_simulation(const modeling& mod, simulation& sim)
if (!component_refs)
return status::success;
return build_models(mod, *component_ref, sim);
return build_models_from_component(mod, *component_ref, sim);
}
} // namespace irt
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