Skip to content

Commit 1fcbcac

Browse files
authored
load the dependent libraries using ModelicaSystem (#201)
1 parent 52ec65c commit 1fcbcac

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

OMPython/__init__.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def sendExpression(self, command, parsed=True):
788788

789789

790790
class ModelicaSystem(object):
791-
def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, commandLineOptions=None, variableFilter=None): # 1
791+
def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, commandLineOptions=None, variableFilter=None, verbose=True): # 1
792792
"""
793793
"constructor"
794794
It initializes to load file and build a model, generating object, exe, xml, mat, and json files. etc. It can be called :
@@ -860,12 +860,13 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
860860

861861
if fileName is not None:
862862
self.loadFile()
863+
self.loadLibrary(verbose)
863864

864865
## allow directly loading models from MSL without fileName
865866
if fileName is None and modelName is not None:
866-
self.loadLibrary()
867+
self.loadLibrary(verbose)
867868

868-
self.buildModel()
869+
self.buildModel(variableFilter, verbose)
869870

870871
def __del__(self):
871872
OMCSessionBase.__del__(self)
@@ -886,20 +887,25 @@ def loadFile(self):
886887
return print(self.getconn.sendExpression("getErrorString()"))
887888

888889
# for loading file/package, loading model and building model
889-
def loadLibrary(self):
890+
def loadLibrary(self, verbose):
890891
# load Modelica standard libraries or Modelica files if needed
891892
for element in self.lmodel:
892893
if element is not None:
893-
loadmodelError = ''
894894
if isinstance(element, str):
895895
if element.endswith(".mo"):
896896
loadModelResult = self.requestApi("loadFile", element)
897897
if not loadModelResult:
898898
loadmodelError = self.requestApi('getErrorString')
899+
## always print the notification warning to user, to suppress the warnings add verbose=False
900+
if verbose:
901+
print(self.requestApi('getErrorString'))
899902
else:
900903
loadModelResult = self.requestApi("loadModel", element)
901904
if not loadModelResult:
902905
loadmodelError = self.requestApi('getErrorString')
906+
if verbose:
907+
print(self.requestApi('getErrorString'))
908+
903909
elif isinstance(element, tuple):
904910
if not element[1]:
905911
libname = "".join(["loadModel(", element[0], ")"])
@@ -908,10 +914,10 @@ def loadLibrary(self):
908914
loadModelResult = self.sendExpression(libname)
909915
if not loadModelResult:
910916
loadmodelError = self.sendExpression("getErrorString()")
917+
if verbose:
918+
print(self.requestApi('getErrorString'))
911919
else:
912920
print("| info | loadLibrary() failed, Unknown type detected: ", element , " is of type ", type(element), ", The following patterns are supported\n1)[\"Modelica\"]\n2)[(\"Modelica\",\"3.2.3\"), \"PowerSystems\"]\n")
913-
if loadmodelError:
914-
print(loadmodelError)
915921

916922
def setTempDirectory(self):
917923
# create a unique temp directory for each session and build the model in that directory
@@ -925,7 +931,7 @@ def setTempDirectory(self):
925931
def getWorkDirectory(self):
926932
return self.tempdir
927933

928-
def buildModel(self, variableFilter=None):
934+
def buildModel(self, variableFilter=None, verbose=True):
929935
if variableFilter is not None:
930936
self.variableFilter = variableFilter
931937

@@ -937,11 +943,14 @@ def buildModel(self, variableFilter=None):
937943
# buildModelResult=self.getconn.sendExpression("buildModel("+ mName +")")
938944
buildModelResult = self.requestApi("buildModel", self.modelName, properties=varFilter)
939945
buildModelError = self.requestApi("getErrorString")
946+
947+
if ('' in buildModelResult):
948+
print(buildModelError)
949+
940950
# Issue #145. Always print the getErrorString since it might contains build warnings.
941-
if buildModelError:
951+
if verbose:
942952
print(buildModelError)
943-
if ('' in buildModelResult):
944-
return
953+
945954
self.xmlFile=os.path.join(os.path.dirname(buildModelResult[0]),buildModelResult[1]).replace("\\","/")
946955
self.xmlparse()
947956

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def generateIDL():
5454
OMPython_packages.extend(['OMPythonIDL', 'OMPythonIDL._OMCIDL', 'OMPythonIDL._OMCIDL__POA'])
5555

5656
setup(name='OMPython',
57-
version='3.5.0',
57+
version='3.5.1',
5858
description='OpenModelica-Python API Interface',
5959
author='Anand Kalaiarasi Ganeson',
6060
author_email='ganan642@student.liu.se',

0 commit comments

Comments
 (0)