From b3ee11e4e6372ad80780117de7323764369b5c79 Mon Sep 17 00:00:00 2001 From: Lennart Ochel Date: Tue, 21 Sep 2021 10:47:46 +0200 Subject: [PATCH] Add SubModel to new python api (#1089) --- src/OMSimulatorPython/System.py | 43 +++++++++++++++++++++++++++++++ src/OMSimulatorPython/__init__.py | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/OMSimulatorPython/System.py b/src/OMSimulatorPython/System.py index 0508a55ca..1b720213c 100644 --- a/src/OMSimulatorPython/System.py +++ b/src/OMSimulatorPython/System.py @@ -28,6 +28,7 @@ def addSubModel(self, cref: str, path: str): status = Scope._capi.addSubModel(new_cref, path) if Types.Status(status) != Types.Status.OK: raise Exception('error {}'.format(Types.Status(status))) + return SubModel(new_cref) def addConnection(self, conA: str, conB: str): new_conA = self.cref + '.' + conA @@ -68,3 +69,45 @@ def setReal(self, cref: str, value: float) -> None: status = Scope._capi.setReal(self.cref + '.' + cref, value) if Types.Status(status) != Types.Status.OK: raise Exception('error {}'.format(Types.Status(status))) + + +class SubModel: + def __init__(self, cref: str): + self._cref = cref + + @property + def cref(self): + return self._cref + + def getBoolean(self, cref: str): + value, status = Scope._capi.getBoolean(self.cref + '.' + cref) + if Types.Status(status) != Types.Status.OK: + raise Exception('error {}'.format(Types.Status(status))) + return value + + def getInteger(self, cref: str): + value, status = Scope._capi.getInteger(self.cref + '.' + cref) + if Types.Status(status) != Types.Status.OK: + raise Exception('error {}'.format(Types.Status(status))) + return value + + def getReal(self, cref: str): + value, status = Scope._capi.getReal(self.cref + '.' + cref) + if Types.Status(status) != Types.Status.OK: + raise Exception('error {}'.format(Types.Status(status))) + return value + + def setBoolean(self, cref: str, value: bool) -> None: + status = Scope._capi.setBoolean(self.cref + '.' + cref, value) + if Types.Status(status) != Types.Status.OK: + raise Exception('error {}'.format(Types.Status(status))) + + def setInteger(self, cref: str, value: int) -> None: + status = Scope._capi.setInteger(self.cref + '.' + cref, value) + if Types.Status(status) != Types.Status.OK: + raise Exception('error {}'.format(Types.Status(status))) + + def setReal(self, cref: str, value: float) -> None: + status = Scope._capi.setReal(self.cref + '.' + cref, value) + if Types.Status(status) != Types.Status.OK: + raise Exception('error {}'.format(Types.Status(status))) diff --git a/src/OMSimulatorPython/__init__.py b/src/OMSimulatorPython/__init__.py index 2f778deb3..7a32a963c 100644 --- a/src/OMSimulatorPython/__init__.py +++ b/src/OMSimulatorPython/__init__.py @@ -6,7 +6,7 @@ from OMSimulator.Model import Model from OMSimulator.NewAPI import * from OMSimulator.OMSimulator import OMSimulator -from OMSimulator.System import System +from OMSimulator.System import SubModel, System __version__ = '@OMS_SHORT_VERSION_STRING@' __copyright__ = '''\