Commit fbab693e authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[gui] Layouts: black

parent 26069101
## Filename : layout
## Author(s) : Michel Le Borgne
## Created : 01/2012
## Revision :
## Source :
## Revision :
## Source :
##
## Copyright 2012 : IRISA/IRSET
##
......@@ -33,8 +33,8 @@
## IRISA/IRSET
## Symbiose team
## IRISA Campus de Beaulieu
## 35042 RENNES Cedex, FRANCE
##
## 35042 RENNES Cedex, FRANCE
##
##
## Contributor(s):
##
......@@ -76,36 +76,36 @@ class LayoutVisitor(object):
such as certain telecommunications networks.
"""
def __init__(self, view, layout_style):
self.view = view
self.drawing_style = view.drawing_style
self.layout = layout_style
def visit_chart_model(self, model):
"""
Not used
"""
model.get_root().accept(self)
def visit_cstart_node(self, node):
"""
Not used
"""
return
def visit_ctrap_node(self, node):
"""
Not used
"""
return
def visit_csimple_node(self, node):
"""
Not used
"""
return
def visit_cinput_node(self, node):
"""
Not used
......@@ -117,24 +117,24 @@ class LayoutVisitor(object):
Not used
"""
return
def visit_cmacro_node(self, node):
"""
Layouts are done on each macro place
Change the local coordinates of subnodes according to layout style
Change the local coordinates of subnodes according to layout style
"""
if node.sub_nodes == []:
return
agraph = pgv.AGraph(splines='ortho')
agraph = pgv.AGraph(splines="ortho")
node_dict = dict()
# build nodes
for snode in node.sub_nodes:
for snode in node.sub_nodes:
agraph.add_node(snode.name)
anode = agraph.get_node(snode.name)
node_dict[snode.name] = snode
if snode.is_macro() and snode.model.show_macro:
anode.attr['width'] = "%s" % snode.wloc
anode.attr['height'] = "%s" % snode.hloc
anode.attr["width"] = "%s" % snode.wloc
anode.attr["height"] = "%s" % snode.hloc
snode.accept(self)
# build edges
for tgr in node.transitions:
......@@ -142,51 +142,50 @@ class LayoutVisitor(object):
agraph.add_edge(trans.ori.name, trans.ext.name)
# layout
layout_style = self.layout
if layout_style == 'hierarchical_LR':
agraph.layout(prog='dot', args='-Grankdir=LR')
elif layout_style == 'hierarchical_TB':
agraph.layout(prog='dot', args='-Grankdir=BT')
elif layout_style == 'neato':
agraph.layout(prog='neato')
elif layout_style == 'fdp':
agraph.layout(prog='fdp')
elif layout_style == 'twopi':
agraph.layout(prog='twopi')
elif layout_style == 'circo':
agraph.layout(prog='circo')
if layout_style == "hierarchical_LR":
agraph.layout(prog="dot", args="-Grankdir=LR")
elif layout_style == "hierarchical_TB":
agraph.layout(prog="dot", args="-Grankdir=BT")
elif layout_style == "neato":
agraph.layout(prog="neato")
elif layout_style == "fdp":
agraph.layout(prog="fdp")
elif layout_style == "twopi":
agraph.layout(prog="twopi")
elif layout_style == "circo":
agraph.layout(prog="circo")
else:
LOGGER.error(
"LayoutVisitor::visit_cmacro_node: Unknow layout: %s",
layout_style
"LayoutVisitor::visit_cmacro_node: Unknow layout: %s", layout_style
)
exit(1)
# change coordinates
# bounding box for ratios
bbox = pgv.graphviz.agget(agraph.handle, 'bb')
bbox = bbox.split(',')
bbox = pgv.graphviz.agget(agraph.handle, "bb")
bbox = bbox.split(",")
xmin = float(bbox[0])
xmax = float(bbox[2])
ymin = float(bbox[1])
ymax = float(bbox[3])
#adjust graphic window
# adjust graphic window
view = self.view
cond = ((xmax - xmin) / 3.0 > view.draw_width)
cond = (xmax - xmin) / 3.0 > view.draw_width
cond = cond or ((xmax - xmin) / 3.0 < view.draw_width / 2.0)
if cond:
view.draw_width = min(int((xmax - xmin)/3.0), 10400) # 31200 max
view.draw_width = min(int((xmax - xmin) / 3.0), 10400) # 31200 max
view.draw_width = max(1300, view.draw_width)
view.min_width = view.draw_width
cond = ymax - ymin > view.draw_height
cond = cond or ymax - ymin < view.draw_height/2.0
if cond:
view.draw_height = min(int(ymax - ymin), 7200) # 21600 max
cond = cond or ymax - ymin < view.draw_height / 2.0
if cond:
view.draw_height = min(int(ymax - ymin), 7200) # 21600 max
view.draw_height = max(900, view.draw_height)
view.min_height = view.draw_height
# reset zoom counter
view.zoom_count = 0
gwidth = 1.0
gheight = 1.0 # virtual window for the macro node
gheight = 1.0 # virtual window for the macro node
if xmin == xmax or ymin == ymax:
LOGGER.error(
"LayoutVisitor::visit_cmacro_node: Coordinates consistency: "
......@@ -196,11 +195,11 @@ class LayoutVisitor(object):
)
exit(1)
x_ratio = gwidth/(xmax-xmin)
y_ratio = gheight/(ymax-ymin)
x_ratio = gwidth / (xmax - xmin)
y_ratio = gheight / (ymax - ymin)
# changing coordinates
for node in agraph.nodes():
pos = node.attr['pos'].split(',')
pos = node.attr["pos"].split(",")
cnn = node_dict[node]
xcoord = float(pos[0]) * x_ratio
ycoord = float(pos[1]) * y_ratio
......@@ -212,10 +211,9 @@ class LayoutVisitor(object):
"""
self.visit_cmacro_node(node)
return
def visit_ctransition(self, trans):
"""
Not used
"""
return
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment