Commit e92a6512 authored by Markus Mirz's avatar Markus Mirz
Browse files

python: add simulation interface import


Signed-off-by: Markus Mirz's avatarMarkus Mirz <mmirz@eonerc.rwth-aachen.de>
parent a58cade6
......@@ -263,6 +263,7 @@ namespace DPsim {
Complex getComplexIdObjAttr(const String &comp, const String &attr, UInt row = 0, UInt col = 0);
void exportIdObjAttr(const String &comp, const String &attr, UInt idx, CPS::AttributeBase::Modifier mod = CPS::AttributeBase::Modifier::real, UInt row = 0, UInt col = 0);
void importIdObjAttr(const String &comp, const String &attr, UInt idx);
void logIdObjAttr(const String &comp, const String &attr);
};
}
......@@ -616,6 +616,32 @@ void Simulation::exportIdObjAttr(const String &comp, const String &attr, UInt id
}
}
void Simulation::importIdObjAttr(const String &comp, const String &attr, UInt idx) {
Bool found = false;
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
if (!compObj) compObj = mSystem.node<TopologicalNode>(comp);
if (compObj) {
try {
auto v = compObj->attribute<Real>(attr);
compObj->setAttributeRef(attr, mInterfaces[0].interface->importReal(idx));
found = true;
} catch (InvalidAttributeException &e) { }
try {
auto v = compObj->attributeComplex(attr);
compObj->setAttributeRef(attr, mInterfaces[0].interface->importComplex(idx));
found = true;
} catch (InvalidAttributeException &e) { }
if (!found) mLog->error("Attribute not found");
}
else {
mLog->error("Component not found");
}
}
void Simulation::logIdObjAttr(const String &comp, const String &attr) {
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
IdentifiedObject::Ptr nodeObj = mSystem.node<TopologicalNode>(comp);
......
......@@ -56,6 +56,7 @@ PYBIND11_MODULE(dpsimpy, m) {
.def("get_comp_idobj_attr", &DPsim::Simulation::getComplexIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("row") = 0, py::arg("col") = 0)
.def("add_interface", &DPsim::Simulation::addInterface, py::arg("interface"), py::arg("syncStart") = false)
.def("export_attr", &DPsim::Simulation::exportIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("idx"), py::arg("modifier"), py::arg("row") = 0, py::arg("col") = 0)
.def("import_attr", &DPsim::Simulation::importIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("idx"))
.def("log_attr", &DPsim::Simulation::logIdObjAttr);
py::class_<DPsim::RealTimeSimulation, DPsim::Simulation>(m, "RealTimeSimulation")
......
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