Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ local.properties
# External tool builders
.externalToolBuilders/

# DEVSimPy-noGui simu report
*.report

# Locally stored "Eclipse launch configurations"
*.launch

Expand All @@ -34,7 +37,6 @@ local.properties
# PDT-specific
.buildpath


#################
## Visual Studio
#################
Expand Down
98 changes: 67 additions & 31 deletions Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@

if builtins.__dict__.get('GUI_FLAG',True):
import wx

from pubsub import pub as Publisher

import Editor

import ZipManager

from Utilities import replaceAll, GetActiveWindow, path_to_module, install_and_import, printOnStatusBar
from Utilities import replaceAll, GetActiveWindow, printOnStatusBar
from NetManager import Net
from SimpleFrameEditor import FrameEditor
from which import which
Expand Down Expand Up @@ -80,20 +78,31 @@ def GetClass(elem):
clsmembers = getClassMember(elem)

if isinstance(clsmembers, dict):
moduleName = path_to_module(elem)

if 'DomainBehavior' in clsmembers:
DomainClass = clsmembers['DomainBehavior']
elif 'DomainStructure' in clsmembers:
DomainClass = clsmembers['DomainStructure']
elif 'Port' in clsmembers:
DomainClass = clsmembers['Port']
else:
sys.stderr.write(_("Class unknown..."))
return None

from DomainInterface.DomainBehavior import DomainBehavior
from DomainInterface.DomainStructure import DomainStructure
from Container import Port

# moduleName = path_to_module(elem)

# if 'DomainBehavior' in clsmembers:
# DomainClass = clsmembers['DomainBehavior']
# elif 'DomainStructure' in clsmembers:
# DomainClass = clsmembers['DomainStructure']
# elif 'Port' in clsmembers:
# DomainClass = clsmembers['Port']
# else:
# DomainClass = clsmembers[os.path.basename(elem).split('.')[0]]
# sys.stderr.write(_("Class unknown..."))
# print(DomainClass)
# return None

### return only the class that inherite of DomainBehavoir or DomainStructure which are present in the clsmembers dict
return next(filter(lambda c: c != DomainClass and issubclass(c, DomainClass), clsmembers.values()), None)
# return next(filter(lambda c: c != DomainClass and issubclass(c, DomainClass), clsmembers.values()), None)

DomainClass = (DomainBehavior,DomainStructure,Port)

return next(filter(lambda c: c not in DomainClass and issubclass(c, DomainClass), clsmembers.values()), None)

#for cls in [c for c in clsmembers.values() if c != DomainClass]:
# if issubclass(cls, DomainClass):
Expand All @@ -119,13 +128,12 @@ def GetArgs(cls = None):
###
###########################################################


class DSPComponent:
"""
"""
@staticmethod
def Load(filename, label, canvas):
""" Load component from filename
""" Load component from filename.
"""
from Container import Diagram
#assert(filename.endswith('.dsp'))
Expand Down Expand Up @@ -865,21 +873,49 @@ def GetModule(filename):
current_dirname = os.path.dirname(current_dirname)

module_name = os.path.basename(filename).split('.py')[0]
name, ext = os.path.splitext(module_name)

# find and load module
try:
name, ext = os.path.splitext(module_name)
pkg = '.'.join(module_name.split('.')[0:-1])
module = importlib.import_module(name, package=pkg)

#f, fn, description = imp.find_module(module_name, [dir_name])
#module = imp.load_module(module_name, f, fn, description)
#f.close()
return module

except Exception as info:
sys.stderr.write(_("Module %s not imported from %s!\n"%(module_name,dir_name)))
return sys.exc_info()
### try to find the specification of module
spec = importlib.util.find_spec(name, dir_name)

if spec:

### try to import module
try:
module = spec.loader.load_module()
except (ValueError, ImportError) as msg:
sys.stderr.write(_("Module %s not imported from %s: %s!\n"%(module_name,dir_name,str(msg))))
module = sys.exc_info()
else:
### if module are finded, we add on sys.modules all of the paths allowing to reach the module
### For example, PowerSystem.Sources.SinGen, Sources.SinGen and SinGen is the same module SinGen. So, You can use:
### from PowerSystem.Sources.SinGen import SinGen
### from Sources.SinGen import SinGen
### or SinGen import SinGen

### replace os.sep by . from DOMAIN_PATH into the path of the python module file
if DOMAIN_PATH in dir_name:
L = dir_name.replace(DOMAIN_PATH+os.sep,'').split(os.sep)
names = ['.'.join(L[i:]+[name]) for i in range(len(L))]
else:
### external lib
### we add the directory of the lib (So, for example, you can import module by using form Dir.module import ... or from module import ...)
names = ['.'.join([name,module_name])]

### add all combination of path to reach the module
for n in names:
sys.modules[n]=module

### TODO: other dependencies are not imported (python files which are not DomainBehavior or DomainStructure but which are imported from this files...)
# import pkgutil
# search_path = [dir_name] # set to None to see all modules importable from sys.path
# all_modules = [x[1] for x in pkgutil.iter_modules(path=search_path)]
# print(all_modules)
else:
print("Import error 0: " + " module not found")
module = None

return module

@staticmethod
def GetBlock(filename, label):
Expand Down
47 changes: 31 additions & 16 deletions Container.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def makeDEVSInstance(diagram = None):

### shape list of diagram
shape_list = diagram.GetShapeList()
block_list = [c for c in shape_list if isinstance(c, Block)]
block_list = (c for c in shape_list if isinstance(c, Block))

### for all codeBlock shape, we make the devs instance
for m in block_list:
Expand Down Expand Up @@ -465,18 +465,18 @@ def makeDEVSInstance(diagram = None):
dia_0 = diagram.layers[0]
shapeL0 = dia_0.GetShapeList()

for m in [s for s in shapeL0 if isinstance(s, iPort)]:
for m in (s for s in shapeL0 if isinstance(s, iPort)):
devs_dam.addInPort()
diagram.addInPort()

for m in [s for s in shapeL0 if isinstance(s, oPort)]:
for m in (s for s in shapeL0 if isinstance(s, oPort)):
devs_uam.addOutPort()
diagram.addOutPort()

for m in [s for s in shape_list if isinstance(s, iPort)]:
for m in (s for s in shape_list if isinstance(s, iPort)):
devs_dam.addOutPort()

for m in [s for s in shape_list if isinstance(s, oPort)]:
for m in (s for s in shape_list if isinstance(s, oPort)):
devs_uam.addInPort()

###==================================================================================
Expand All @@ -486,13 +486,13 @@ def makeDEVSInstance(diagram = None):
###==============================================================================
if hasattr(diagram, 'current_level') and diagram.current_level>0:
# for all iPort shape, we make the devs instance
for i,m in enumerate([s for s in shapeL0 if isinstance(s, iPort)]):
for i,m in enumerate((s for s in shapeL0 if isinstance(s, iPort))):
p1 = diagram.getDEVSModel().IPorts[i]
p2 = devs_dam.IPorts[i]
Structurable.ConnectDEVSPorts(diagram, p1, p2)
###==============================================================================
else:
for m in [s for s in shape_list if isinstance(s, iPort)]:
for m in (s for s in shape_list if isinstance(s, iPort)):
### add port to coupled model
diagram.addInPort()
assert(len(diagram.getIPorts()) <= diagram.input)
Expand All @@ -501,24 +501,36 @@ def makeDEVSInstance(diagram = None):
### Add abstraction level manager
if hasattr(diagram, 'current_level') and diagram.current_level>0:
# for all oPort shape, we make the devs instance
for i,m in enumerate([s for s in shapeL0 if isinstance(s, oPort)]):
for i,m in enumerate((s for s in shapeL0 if isinstance(s, oPort))):
p1 = devs_uam.OPorts[i]
p2 = diagram.getDEVSModel().OPorts[i]
Structurable.ConnectDEVSPorts(diagram, p1, p2)
###===============================================================================
else:
for m in [s for s in shape_list if isinstance(s, oPort)]:
for m in (s for s in shape_list if isinstance(s, oPort)):
### add port to coupled model
diagram.addOutPort()
assert(len(diagram.getOPorts()) <= diagram.output)

### Connection
for m in [s for s in shape_list if isinstance(s, ConnectionShape)]:
### Connections
for m in (s for s in shape_list if isinstance(s, ConnectionShape)):
m1,n1 = m.input
m2,n2 = m.output

if isinstance(m1, Block) and isinstance(m2, Block):
p1 = m1.getDEVSModel().OPorts[n1]
p2 = m2.getDEVSModel().IPorts[n2]
try:
p1 = m1.getDEVSModel().OPorts[n1]
except:
msg = _("It seems that the number of internal output ports (%d) of the coupled model %s is not enough!\nPlease check this.")%(len(m1.getDEVSModel().OPorts),m1.label)
sys.stdout.write(msg)
return msg
try:
p2 = m2.getDEVSModel().IPorts[n2]
except:
msg = _("It seems that the number of internal input ports (%d) of the coupled model %s is not enough!\nPlease check this.")%(len(m2.getDEVSModel().IPorts),m2.label)
sys.stdout.write(msg)
return msg

Structurable.ConnectDEVSPorts(diagram, p1, p2)

elif isinstance(m1, Block) and isinstance(m2, oPort):
Expand Down Expand Up @@ -833,8 +845,11 @@ def OnSimulation(self, event):
## make DEVS instance from diagram
master = Diagram.makeDEVSInstance(diagram)

if not master or isinstance(master,str):
wx.MessageBox(master, _("Simulation Manager"))
return False
## test of filename model attribute
if all(model.bad_filename_path_flag for model in [m for m in diagram.GetShapeList() if isinstance(m, Block)] if hasattr(model, 'bad_filename_path_flag')):
elif all(model.bad_filename_path_flag for model in [m for m in diagram.GetShapeList() if isinstance(m, Block)] if hasattr(model, 'bad_filename_path_flag')):
dial = wx.MessageDialog(win, \
_("You don't make the simulation of the Master model.\nSome models have bad fileName path !"),\
_('Simulation Manager'), \
Expand Down Expand Up @@ -2687,7 +2702,7 @@ def getCurrentShape(self, event):
""" Return the selected current shape.
"""
# get coordinate of click in our coordinate system
if isinstance(event,wx.MouseEvent):
if isinstance(event, wx.MouseEvent):
point = self.getEventCoordinates(event)
self.currentPoint = point

Expand Down Expand Up @@ -3940,7 +3955,7 @@ def __setstate__(self, state):
index = args_from_stored_constructor_py.index(arg)
state['args'].update({arg:arg_values[index]})
else:
sys.stderr.write(_("args is None in setstate for ContainerBlock: %s\n"%str(cls)))
#sys.stderr.write(_("args is None in setstate for ContainerBlock: %s\n"%str(cls)))
state['args'] = {}
else:
sys.stderr.write(_("Error in setstate for ContainerBlock: %s\n"%str(cls)))
Expand Down
3 changes: 0 additions & 3 deletions Domain/PowerSystem/Continuous/.directory

This file was deleted.

Binary file removed Domain/PowerSystem/Continuous/Delay.pyc
Binary file not shown.
Binary file removed Domain/PowerSystem/Continuous/Gain.pyc
Binary file not shown.
Binary file removed Domain/PowerSystem/Continuous/Integrator.pyc
Binary file not shown.
Binary file removed Domain/PowerSystem/Continuous/Integrator2.pyc
Binary file not shown.
Binary file removed Domain/PowerSystem/Continuous/Integrator3.pyc
Binary file not shown.
Binary file removed Domain/PowerSystem/Continuous/NLFunction.pyc
Binary file not shown.
Binary file removed Domain/PowerSystem/Continuous/WSum.pyc
Binary file not shown.
9 changes: 0 additions & 9 deletions Domain/PowerSystem/Continuous/__init__.py

This file was deleted.

Loading