Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework nested boundaries #55

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Changes from 2 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
28 changes: 17 additions & 11 deletions pytm/pytm.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class Element():

def __init__(self, name):
self.name = name
self._is_drawn = False
TM._BagOfElements.append(self)

def check(self):
Expand All @@ -297,6 +298,7 @@ def check(self):
raise ValueError("Element {} need a description and a name.".format(self.name))

def dfd(self):
self._is_drawn = True
print("%s [\n\tshape = square;" % _uniq_name(self.name))
print('\tlabel = <<table border="0" cellborder="0" cellpadding="2"><tr><td><b>{0}</b></td></tr></table>>;'.format(self.name))
print("]")
Expand All @@ -321,6 +323,7 @@ def __init__(self, name):
super().__init__(name)

def dfd(self):
self._is_drawn = True
color = _setColor(self)
pngpath = dirname(__file__) + "/images/lambda.png"
print('{0} [\n\tshape = none\n\tfixedsize=shape\n\timage="{2}"\n\timagescale=true\n\tcolor = {1}'.format(_uniq_name(self.name), color, pngpath))
Expand Down Expand Up @@ -355,6 +358,7 @@ def __init__(self, name):
super().__init__(name)

def dfd(self):
self._is_drawn = True
color = _setColor(self)
print("{0} [\n\tshape = circle\n\tcolor = {1}".format(_uniq_name(self.name), color))
print('\tlabel = <<table border="0" cellborder="0" cellpadding="2"><tr><td><b>{}</b></td></tr></table>>;'.format(self.name))
Expand Down Expand Up @@ -399,6 +403,7 @@ def __init__(self, name):
super().__init__(name)

def dfd(self):
self._is_drawn = True
color = _setColor(self)
print("{0} [\n\tshape = none;\n\tcolor = {1};".format(_uniq_name(self.name), color))
print('\tlabel = <<table sides="TB" cellborder="0" cellpadding="2"><tr><td><font color="{1}"><b>{0}</b></font></td></tr></table>>;'.format(self.name, color))
Expand All @@ -412,6 +417,7 @@ def __init__(self, name):
super().__init__(name)

def dfd(self):
self._is_drawn = True
print("%s [\n\tshape = square;" % _uniq_name(self.name))
print('\tlabel = <<table border="0" cellborder="0" cellpadding="2"><tr><td><b>{0}</b></td></tr></table>>;'.format(self.name))
print("]")
Expand Down Expand Up @@ -451,6 +457,7 @@ def __init__(self, name):
super().__init__(name)

def dfd(self):
self._is_drawn = True
color = _setColor(self)
print("{0} [\n\tshape = circle;\n\tcolor = {1};\n".format(_uniq_name(self.name), color))
print('\tlabel = <<table border="0" cellborder="0" cellpadding="2"><tr><td><font color="{1}"><b>{0}</b></font></td></tr></table>>;'.format(self.name, color))
Expand All @@ -462,6 +469,7 @@ def __init__(self, name):
super().__init__(name)

def dfd(self):
self._is_drawn = True
color = _setColor(self)
print("{0} [\n\tshape = doublecircle;\n\tcolor = {1};\n".format(_uniq_name(self.name), color))
print('\tlabel = <<table border="0" cellborder="0" cellpadding="2"><tr><td><font color="{1}"><b>{0}</b></font></td></tr></table>>;'.format(self.name, color))
Expand Down Expand Up @@ -502,6 +510,7 @@ def check(self):
pass

def dfd(self):
self._is_drawn = True
print("\t{0} -> {1} [".format(_uniq_name(self.source.name),
_uniq_name(self.sink.name)))
color = _setColor(self)
Expand All @@ -515,23 +524,21 @@ def dfd(self):
class Boundary(Element):
def __init__(self, name):
super().__init__(name)
self._is_drawn = False
if name not in TM._BagOfBoundaries:
TM._BagOfBoundaries.append(self)

def dfd(self):
self._is_drawn = True
print("subgraph cluster_{0} {{\n\tgraph [\n\t\tfontsize = 10;\n\t\tfontcolor = firebrick2;\n\t\tstyle = dashed;\n\t\tcolor = firebrick2;\n\t\tlabel = <<i>{1}</i>>;\n\t]\n".format(_uniq_name(self.name), self.name))
if self._is_drawn:
return

result = get_args()
self._is_drawn = True
_debug(result, "Now drawing boundary " + self.name)
print("subgraph cluster_{0} {{\n\tgraph [\n\t\tfontsize = 10;\n\t\tfontcolor = firebrick2;\n\t\tstyle = dashed;\n\t\tcolor = firebrick2;\n\t\tlabel = <<i>{1}</i>>;\n\t]\n".format(_uniq_name(self.name), self.name))
for e in TM._BagOfElements:
if type(e) == Boundary:
if not e._is_drawn:
_debug(result, "Now drawing boundary " + e.name)
e.dfd()
if e.inBoundary == self:
result = get_args()
_debug(result, "Now drawing content " + e.name)
if e.inBoundary == self and not e._is_drawn:
# The content to draw can include Boundary objects
_debug(result, "Now drawing content {}".format(e.name))
e.dfd()
print("\n}\n")

Expand All @@ -548,4 +555,3 @@ def get_args():

_args = _parser.parse_args()
return _args