Skip to content

Commit cca18f0

Browse files
authored
Add System to new python api (#963)
1 parent 3ca72f6 commit cca18f0

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/OMSimulatorPython/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/Model.py" DESTINATION ${CMAKE_INSTALL
1818
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/NewAPI.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/OMSimulator)
1919
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/OMSimulator.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/OMSimulator)
2020
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/Scope.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/OMSimulator)
21+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/System.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/OMSimulator)
2122
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/Types.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/OMSimulator)
2223

2324
IF (WIN32 AND MSVC)

src/OMSimulatorPython/Model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from OMSimulator import Scope, Types
1+
from OMSimulator import Scope, System, Types
22

33

44
class Model:
@@ -14,6 +14,13 @@ def delete(self):
1414
else:
1515
raise Exception('error {}'.format(Types.Status(status)))
1616

17+
def addSystem(self, cref: str, type_: Types.System):
18+
new_cref = self.cref + '.' + cref
19+
status = Scope._capi.addSystem(new_cref, type_.value)
20+
if Types.Status(status) != Types.Status.OK:
21+
raise Exception('error {}'.format(Types.Status(status)))
22+
return System.System(new_cref)
23+
1724
def instantiate(self):
1825
status = Scope._capi.instantiate(self.cref)
1926
if Types.Status(status) != Types.Status.OK:

src/OMSimulatorPython/System.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from OMSimulator import Scope, Types
2+
3+
4+
class System:
5+
def __init__(self, cref: str):
6+
self._cref = cref
7+
8+
@property
9+
def cref(self):
10+
return self._cref
11+
12+
@property
13+
def type(self):
14+
type_, status = Scope._capi.getSystemType(self.cref)
15+
if Types.Status(status) != Types.Status.OK:
16+
raise Exception('error {}'.format(Types.Status(status)))
17+
return Types.System(type_)
18+
19+
def addSystem(self, cref: str, type_: Types.System):
20+
new_cref = self.cref + '.' + cref
21+
status = Scope._capi.addSystem(new_cref, type_.value)
22+
if Types.Status(status) != Types.Status.OK:
23+
raise Exception('error {}'.format(Types.Status(status)))
24+
return System(new_cref)

src/OMSimulatorPython/Types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ class Status(Enum):
88
ERROR = 3
99
FATAL = 4
1010
PENDING = 5
11+
12+
class System(Enum):
13+
'oms_system_enu_t'
14+
NONE = 0
15+
TLM = 1 # TLM system
16+
WC = 2 # Weakly Coupled system
17+
SC = 3 # Strongly Coupled system

src/OMSimulatorPython/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from OMSimulator.Model import Model
77
from OMSimulator.NewAPI import *
88
from OMSimulator.OMSimulator import OMSimulator
9+
from OMSimulator.System import System
910

1011
__version__ = '@OMS_SHORT_VERSION_STRING@'
1112
__copyright__ = '''\

0 commit comments

Comments
 (0)