Skip to content

Commit 6b1c340

Browse files
committed
first prototypes in generating pumla layouted SVG diagrams.
1 parent b4b1b04 commit 6b1c340

File tree

7 files changed

+118
-6
lines changed

7 files changed

+118
-6
lines changed

src/pumla/control/cmd_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ def gendiagram(mainpath, inputpuml, outputname, picformat):
4545
print("creating diagram for: " + inputpuml)
4646
print("done.")
4747

48-
def genpumladiag(mainpath, inputpuml, outputname, layoutoverride):
49-
print("feature not yet implemented. sorry.")
50-
51-
5248
def installPlantUMLJAR(mainpath):
5349
'''downloads the PlantUML JAR file and places it into a pumla command line tool installation directory.'''
5450
print("downloading...")

src/pumla/control/diag_handling.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""functions to handle pumla diagrams and pumla-specific .svg diagram generation."""
2+
from pumla.model.PUMLADiagram import PUMLADiagram
3+
from pumla.model.PUMLAElement import PUMLAElement
4+
from pumla.view.PUMLASVGDiagram import PUMLASVGDiagram
5+
6+
def genpumladiag(mainpath, inputpuml, outputname, layoutoverride):
7+
print("feature not yet implemented. sorry.")
8+
9+
d = PUMLADiagram("diag1", "My first pumla SVG Diagram")
10+
e1 = PUMLAElement()
11+
e1.setAlias("huhu")
12+
e1.setName("Huhu")
13+
e1.addStereotype("system")
14+
e1.addStereotype("block")
15+
16+
e2 = PUMLAElement()
17+
e2.setAlias("trara")
18+
e2.setName("Trara Trara")
19+
20+
d.addElement(e1)
21+
d.addElement(e2)
22+
23+
svg_d = PUMLASVGDiagram(d)
24+
svg_d.generateHTMLfile()
25+
26+
27+
28+
29+
def parsePUMLADRFile(file):
30+
pass

src/pumla/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from pumla.control.cmd_utils import checkElsRelsConsForAliasExistence
2424
from pumla.control.cmd_utils import installPlantUMLJAR
2525
from pumla.control.cmd_utils import gendiagram
26-
from pumla.control.cmd_utils import genpumladiag
26+
from pumla.control.diag_handling import genpumladiag
2727
from pumla.control.reqparse import updatePUMLAReqRepo
2828

2929
parser = None

src/pumla/model/PUMLADiagram.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class PUMLAConnection:
1+
class PUMLADiagram:
22
''' store PUMLA diagram information '''
33
def __init__(self, alias, title=""):
44
self.alias = alias
@@ -7,3 +7,7 @@ def __init__(self, alias, title=""):
77
self.filename = "-"
88
self.elements = []
99
self.mainlayout = {"direction": "l-to-r"}
10+
11+
def addElement(self, element):
12+
self.elements.append(element)
13+

src/pumla/view/PUMLASVGDiagram.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from pumla.model.PUMLAElement import PUMLAElement
2+
from pumla.model.PUMLADiagram import PUMLADiagram
3+
from pumla.view.PUMLASVGElement import PUMLASVGElement
4+
5+
"""Class defining the SVG view of a pumla diagram."""
6+
class PUMLASVGDiagram:
7+
''' Class defining the SVG view of a pumla diagram. '''
8+
def __init__(self, diagram):
9+
self.diagram = diagram
10+
self.svg_elements = []
11+
self.filename = "defaultHTMLwithSVGfilename.html"
12+
for e in self.diagram.elements:
13+
self.svg_elements.append(PUMLASVGElement(e))
14+
15+
def generateSVG(self):
16+
svg_code = '<svg width="1600" height="1200"> <svg id="' + self.diagram.alias + '" width="600" height="400" xmlns="http://www.w3.org/2000/svg">\n'
17+
svg_code = svg_code + '<text id="' + self.diagram.alias + '_titletxt" x="50%" y="10" dominant-baseline="middle" text-anchor="middle" font-size="20" font-family="Arial, sans-serif" fill="black">' + self.diagram.title + '</text>\n'
18+
19+
cnt = 0
20+
for e in self.svg_elements:
21+
el_code = e.generateSVG(cnt, 30)
22+
svg_code = svg_code + el_code
23+
cnt += 1
24+
25+
svg_code = svg_code + '</svg>\n'
26+
27+
return svg_code
28+
29+
30+
def generateHTMLembeddedSVG(self):
31+
html_code = '<html>\n<body>\n<h1>' + self.diagram.title
32+
html_code = html_code + '</h1>\n\n'
33+
html_code = html_code + self.generateSVG()
34+
html_code = html_code + '\n</body>\n</html>\n'
35+
36+
return html_code
37+
38+
def generateHTMLfile(self, filename=""):
39+
with open(self.filename, "w") as f:
40+
f.write(self.generateHTMLembeddedSVG())
41+
42+

src/pumla/view/PUMLASVGElement.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Class defining the SVG view of a model element."""
2+
class PUMLASVGElement:
3+
""" class defining the SVG view of an atomic PUMLA model element """
4+
5+
def __init__(self, element):
6+
self.element = element
7+
8+
def generateSVG(self, count, y_offset):
9+
stps = ""
10+
for s in self.element.stereotypes:
11+
stps = stps + s + ", "
12+
13+
stereotypes = "<< " + stps[:len(stps)-2] + " >>"
14+
svg_code = '<svg id="' + self.element.alias + '" width="600" height="400" xmlns="http://www.w3.org/2000/svg">\n'
15+
svg_code = svg_code + '<rect id="' + self.element.alias + '_rect" width="150" height="220" x="5" y="5" rx="20" ry="20" style="fill:yellow;stroke:black;stroke-width:3;opacity:0.5" />\n'
16+
svg_code = svg_code + '<text id="' + self.element.alias + '_txt" x="80" y="25" dominant-baseline="middle" text-anchor="middle" font-size="14" font-family="Arial, sans-serif" style="opacity:0.5" fill="black">' + self.element.name + '</text>\n'
17+
if self.element.stereotypes != []:
18+
svg_code = svg_code + '<text id="' + self.element.alias + '_txt" x="80" y="45" dominant-baseline="middle" text-anchor="middle" font-size="12" font-style="italic" font-family="Arial, sans-serif" style="opacity:0.5" fill="black">' + stereotypes + '</text>\n'
19+
svg_code = svg_code + '<set attributeName="x" to="' + str(count * (150 + 30) ) + '" /><set attributeName="y" to="' + str(y_offset) + '" /></svg>\n'
20+
21+
return svg_code
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<body>
3+
<h1>My first pumla SVG Diagram</h1>
4+
5+
<svg width="1600" height="1200"> <svg id="diag1" width="600" height="400" xmlns="http://www.w3.org/2000/svg">
6+
<text id="diag1_titletxt" x="50%" y="10" dominant-baseline="middle" text-anchor="middle" font-size="20" font-family="Arial, sans-serif" fill="black">My first pumla SVG Diagram</text>
7+
<svg id="huhu" width="600" height="400" xmlns="http://www.w3.org/2000/svg">
8+
<rect id="huhu_rect" width="150" height="220" x="5" y="5" rx="20" ry="20" style="fill:yellow;stroke:black;stroke-width:3;opacity:0.5" />
9+
<text id="huhu_txt" x="80" y="25" dominant-baseline="middle" text-anchor="middle" font-size="14" font-family="Arial, sans-serif" style="opacity:0.5" fill="black">Huhu</text>
10+
<text id="huhu_txt" x="80" y="45" dominant-baseline="middle" text-anchor="middle" font-size="12" font-style="italic" font-family="Arial, sans-serif" style="opacity:0.5" fill="black"><< system, block >></text>
11+
<set attributeName="x" to="0" /><set attributeName="y" to="30" /></svg>
12+
<svg id="trara" width="600" height="400" xmlns="http://www.w3.org/2000/svg">
13+
<rect id="trara_rect" width="150" height="220" x="5" y="5" rx="20" ry="20" style="fill:yellow;stroke:black;stroke-width:3;opacity:0.5" />
14+
<text id="trara_txt" x="80" y="25" dominant-baseline="middle" text-anchor="middle" font-size="14" font-family="Arial, sans-serif" style="opacity:0.5" fill="black">Trara Trara</text>
15+
<set attributeName="x" to="180" /><set attributeName="y" to="30" /></svg>
16+
</svg>
17+
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)