Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Ref: #4622 Making the icon generator compatible with ZMQ
Browse files Browse the repository at this point in the history
It should also still run with CORBA

Belonging to [master]:
  - #2507
  • Loading branch information
dietmarw authored and OpenModelica-Hudson committed Jun 15, 2018
1 parent 7ad3a17 commit 383f820
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Examples/generate_icons.py
Expand Up @@ -39,8 +39,14 @@
from optparse import OptionParser

import svgwrite
from OMPython import OMCSession
OMPython = OMCSession()
try:
from OMPython import OMCSession
omc = OMCSession()
print("Using CORBA")
except ImportError:
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
print("No CORBA interface found, using ZMQ instead")

# OpenModelica setup commands
OMC_SETUP_COMMANDS = ['setCommandLineOptions("-d=nogen,noevalfunc")']
Expand Down Expand Up @@ -106,9 +112,9 @@ def ask_omc(question, opt=None, parsed=True):

try:
if parsed:
res = OMPython.execute(expression)
res = omc.execute(expression)
else:
res = OMPython._omc.sendExpression(expression)
res = omc.sendExpression(expression, parsed=False)
except Exception as e:
logger.error("OMC failed: {0}, {1}, parsed={2}".format(question, opt, parsed))
raise
Expand Down Expand Up @@ -1173,22 +1179,22 @@ def main():
success = True

for command in OMC_SETUP_COMMANDS:
OMPython._omc.sendExpression(command)
omc.sendExpression(command, parsed=False)
for package in PACKAGES_TO_LOAD:
logger.info('Loading package: {0}'.format(package))
package_load = OMPython.sendExpression('loadModel(' + package + ')')
package_load = omc.sendExpression('loadModel(' + package + ')')
if not package_load:
success = False
break
for package in PACKAGES_TO_LOAD_FROM_FILE:
logger.info('Loading package from file: {0}'.format(package))
package_load = OMPython.sendExpression('loadFile("' + package + '")')
package_load = omc.sendExpression('loadFile("' + package + '")')
logger.info('Load success: {0}'.format(package_load))
if not package_load:
success = False
break
if not success:
logger.critical('Failed to load packages in %.1f seconds: %s' % (time.time()-t,OMPython.sendExpression('getErrorString()')))
logger.critical('Failed to load packages in %.1f seconds: %s' % (time.time()-t,omc.sendExpression('getErrorString()')))
return 1
dwgs = []

Expand All @@ -1200,7 +1206,7 @@ def main():
fh.setFormatter(formatter)
logger.addHandler(fh)

modelica_classes = OMPython.sendExpression('getClassNames(' + package + ', recursive=true, qualified=true, sort=true)')
modelica_classes = omc.sendExpression('getClassNames(' + package + ', recursive=true, qualified=true, sort=true)')
for modelica_class in modelica_classes:
logger.info('Exporting: ' + modelica_class)

Expand Down

0 comments on commit 383f820

Please sign in to comment.