From e0bcb2f39c367c863122cf80322c6560fcec34b9 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 6 Nov 2019 17:09:09 -0500 Subject: [PATCH 1/2] Fixing nested Boundaries (cherry picked from commit 87e1ecc35ccb5ca6b029fcc3541c3e5b3946b7ec) --- pytm/pytm.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pytm/pytm.py b/pytm/pytm.py index 2da707d..f9cf555 100644 --- a/pytm/pytm.py +++ b/pytm/pytm.py @@ -524,11 +524,11 @@ def dfd(self): 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 = <{1}>;\n\t]\n".format(_uniq_name(self.name), self.name)) result = get_args() _debug(result, "Now drawing boundary " + self.name) + if type(self) == Boundary: + if not self._is_drawn: + _debug(result, "Now drawing boundary " + self.name) + self.dfd() 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) @@ -548,4 +548,3 @@ def get_args(): _args = _parser.parse_args() return _args - From e65af2027395065b0c6524765293d1bd9149ec9e Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Thu, 7 Nov 2019 10:19:44 -0500 Subject: [PATCH 2/2] draw each element (including boundaries) once via _is_drawn attribute --- pytm/pytm.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pytm/pytm.py b/pytm/pytm.py index f9cf555..ad0df0c 100644 --- a/pytm/pytm.py +++ b/pytm/pytm.py @@ -287,6 +287,7 @@ class Element(): def __init__(self, name): self.name = name + self._is_drawn = False TM._BagOfElements.append(self) def check(self): @@ -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 = <
{0}
>;'.format(self.name)) print("]") @@ -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)) @@ -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 = <
{}
>;'.format(self.name)) @@ -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 = <
{0}
>;'.format(self.name, color)) @@ -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 = <
{0}
>;'.format(self.name)) print("]") @@ -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 = <
{0}
>;'.format(self.name, color)) @@ -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 = <
{0}
>;'.format(self.name, color)) @@ -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) @@ -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 = <{1}>;\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) - if type(self) == Boundary: - if not self._is_drawn: - _debug(result, "Now drawing boundary " + self.name) - self.dfd() + 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 = <{1}>;\n\t]\n".format(_uniq_name(self.name), self.name)) for e in TM._BagOfElements: - 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")