Skip to content

Commit

Permalink
Add SubModel to new python api (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored Sep 21, 2021
1 parent b224df1 commit b3ee11e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/OMSimulatorPython/System.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
2 changes: 1 addition & 1 deletion src/OMSimulatorPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = '''\
Expand Down

0 comments on commit b3ee11e

Please sign in to comment.