11# -*- coding: utf-8 -*-
22"""
33OMPython is a Python interface to OpenModelica.
4- To get started, create an OMCSession/OMCSessionZMQ object:
5- from OMPython import OMCSession/OMCSessionZMQ
6- omc = OMCSession()/OMCSessionZMQ()
7- omc.sendExpression(command)
8-
9- Note: Conversion from OMPython 1.0 to OMPython 2.0 is very simple
10- 1.0:
11- import OMPython
12- OMPython.execute(command)
13- 2.0:
14- from OMPython import OMCSession
15- OMPython = OMCSession()
16- OMPython.execute(command)
17-
18- OMPython 3.0 includes a new class OMCSessionZMQ uses PyZMQ to communicate
19- with OpenModelica. A new argument `useCorba=False` is added to ModelicaSystem
20- class which means it will use OMCSessionZMQ by default. If you want to use
21- OMCSession then create ModelicaSystem object like this,
22- obj = ModelicaSystem(useCorba=True)
23-
24- The difference between execute and sendExpression is the type of the
25- returned expression. sendExpression maps Modelica types to Python types,
26- while execute tries to map also output that is not valid Modelica.
27- That format is harder to use.
4+ To get started, create an OMCSessionZMQ object:
5+ from OMPython import OMCSessionZMQ
6+ omc = OMCSessionZMQ()
7+ omc.sendExpression("command")
288"""
299
3010from __future__ import absolute_import
@@ -553,7 +533,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
553533 str (builtin ).lower (), str (showProtected ).lower ()))
554534 return value
555535
556- class OMCSession (OMCSessionHelper , OMCSessionBase ):
536+ class OMCSessionZMQ (OMCSessionHelper , OMCSessionBase ):
557537
558538 def __init__ (self , readonly = False , timeout = 10.00 ,
559539 docker = None , dockerContainer = None , dockerExtraArgs = None , dockerOpenModelicaPath = "omc" ,
@@ -662,16 +642,7 @@ def sendExpression(self, command, parsed=True):
662642 else :
663643 return result
664644 else :
665- raise Exception ("Process Exited, No connection with OMC. Create a new instance of OMCSession" )
666-
667- class OMCSessionZMQ (OMCSession ):
668- def __init__ (self , * args , ** kwargs ):
669- warnings .warn (
670- "OMCSessionZMQ is deprecated and will be remove in the next release. Please use OMCSession instead." ,
671- DeprecationWarning ,
672- stacklevel = 2
673- )
674- super (OMCSessionZMQ , self ).__init__ (* args , ** kwargs )
645+ raise Exception ("Process Exited, No connection with OMC. Create a new instance of OMCSessionZMQ" )
675646
676647class ModelicaSystemError (Exception ):
677648 pass
@@ -689,13 +660,8 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
689660 Note: If the model file is not in the current working directory, then the path where file is located must be included together with file name. Besides, if the Modelica model contains several different models within the same package, then in order to build the specific model, in second argument, user must put the package name with dot(.) followed by specific model name.
690661 ex: myModel = ModelicaSystem("ModelicaModel.mo", "modelName")
691662 """
692- if session is not None :
693- self .getconn = session
694- else :
695- self .getconn = OMCSession (omhome = omhome )
696-
697663 if fileName is None and modelName is None and not lmodel : # all None
698- self . getconn = OMCSession ( omhome = omhome )
664+ raise Exception ( "Cannot create ModelicaSystem object without any arguments" )
699665 return
700666
701667 self .tree = None
@@ -717,7 +683,10 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
717683
718684 self ._verbose = verbose
719685
720- self .getconn = OMCSession (omhome = omhome )
686+ if session is not None :
687+ self .getconn = session
688+ else :
689+ self .getconn = OMCSessionZMQ (omhome = omhome )
721690
722691 ## needed for properly deleting the session
723692 self ._omc_log_file = self .getconn ._omc_log_file
0 commit comments