Version: 9.15.0
gui.graph.Graph Class Reference

Public Member Functions

def __init__ (self, item, parent)
 
def createGraph (self)
 
def addLink (self, link)
 
def addItem (self, item)
 
def selectItem (self, item)
 
def layout (self, rankdir)
 
def clearLinks (self)
 
def orthoLinks (self)
 

Public Attributes

 parent
 
 item
 
 node
 
 canvas
 
 editor
 
 citems
 

Detailed Description

Definition at line 40 of file graph.py.

Constructor & Destructor Documentation

◆ __init__()

def gui.graph.Graph.__init__ (   self,
  item,
  parent 
)

Definition at line 41 of file graph.py.

41  def __init__(self,item,parent):
42  self.parent=parent
43  self.item=item
44  self.node=item.node
45  #initial canvas size : 1000x1000
46  self.canvas=MyCanvas(1000,1000)
47  self.editor=GraphViewer(self.canvas,parent,"example",0)
48  self.createGraph()
49  root=self.node.getRootNode()
50  rootItem=Item.adapt(root)
51  CONNECTOR.Connect(rootItem,"selected",self.selectItem,())
52  CONNECTOR.Connect(self.item,"add",self.addItem,())
53  CONNECTOR.Connect(self.item.datalinks,"add",self.addLink,())
54 

Member Function Documentation

◆ addItem()

def gui.graph.Graph.addItem (   self,
  item 
)

Definition at line 112 of file graph.py.

112  def addItem(self,item):
113  #print "graph.addItem",item
114  node=CItems.Cell(item.node,self.canvas)
115  self.citems[item.node.ptr()]=node
116  node.show()
117  self.canvas.update()
118 

References gui.CItems.LinkItem.canvas, gui.graph.Graph.canvas, and gui.graph.Graph.citems.

◆ addLink()

def gui.graph.Graph.addLink (   self,
  link 
)

Definition at line 93 of file graph.py.

93  def addLink(self,link):
94  print("graph.addLink",link)
95  #CItem for outport
96  nodeS=self.citems[link.pout.getNode().ptr()]
97  nodeE=self.citems[link.pin.getNode().ptr()]
98  po=pi=None
99  for p in nodeS.outports:
100  if p.port == link.pout:
101  po=p
102  break
103  for p in nodeE.inports:
104  if p.port == link.pin:
105  pi=p
106  break
107 
108  if pi and po:
109  l=CItems.LinkItem(po,pi,self.canvas)
110  self.canvas.update()
111 

References gui.CItems.LinkItem.canvas, gui.graph.Graph.canvas, and gui.graph.Graph.citems.

◆ clearLinks()

def gui.graph.Graph.clearLinks (   self)

Definition at line 185 of file graph.py.

185  def clearLinks(self):
186  items=list(self.citems.values())
187  for node in items:
188  for port in node.outports:
189  if not hasattr(port,"links"):
190  continue
191  for link in port.links():
192  link.clearPoints()
193  self.canvas.update()
194 

References gui.CItems.LinkItem.canvas, gui.graph.Graph.canvas, and gui.graph.Graph.citems.

◆ createGraph()

def gui.graph.Graph.createGraph (   self)

Definition at line 55 of file graph.py.

55  def createGraph(self):
56  #citems dict helps finding items in canvas from swig proxy
57  #To find an item node make : citems[node.ptr()]
58  citems={}
59  self.citems=citems
60  #pitems dict helps finding items in canvas from swig proxy
61  #To find an item port make : pitems[port.ptr()]
62  pitems={}
63 
64  y=0
65  lnode=self.node.edGetDirectDescendants()
66  for n in lnode:
67  c=CItems.Cell(n,self.canvas)
68  citems[n.ptr()]=c
69  c.show()
70 
71  for k,n in list(citems.items()):
72  for p in n.inports:
73  pitems[p.port.ptr()]=p
74  for p in n.outports:
75  pitems[p.port.ptr()]=p
76 
77  for pout,pin in self.node.getSetOfInternalLinks():
78  if pout.getNode().getFather() != self.node and pin.getNode().getFather() != self.node:
79  continue
80  po=pitems.get(pout.ptr())
81  pi=pitems.get(pin.ptr())
82  if pi and po:
83  CItems.LinkItem(po,pi,self.canvas)
84 
85  for n in lnode:
86  itemup=citems[n.ptr()]
87  for ndown in n.getOutNodes():
88  itemdown=citems[ndown.ptr()]
89  CItems.ControlLinkItem(itemup.outgate,itemdown.ingate,self.canvas)
90 
91  self.layout("LR")
92 

◆ layout()

def gui.graph.Graph.layout (   self,
  rankdir 
)
Compute graph layout with graphviz package

Definition at line 123 of file graph.py.

123  def layout(self,rankdir):
124  """Compute graph layout with graphviz package"""
125  G=pygraphviz.AGraph(strict=False,directed=True)
126  G.graph_attr["rankdir"]=rankdir
127  G.graph_attr["dpi"]="72"
128  dpi=72.
129  aspect=dpi/72
130  for k,n in list(self.citems.items()):
131  #k is node address (YACS)
132  #n is item in canvas
133  G.add_node(k)
134 
135  for pout,pin in self.node.getSetOfInternalLinks():
136  if pout.getNode().ptr() not in self.citems :
137  continue
138  if pin.getNode().ptr() not in self.citems:
139  continue
140  G.add_edge(pout.getNode().ptr(),pin.getNode().ptr())
141 
142  for k,n in list(self.citems.items()):
143  for ndown in n.node.getOutNodes():
144  G.add_edge(n.node.ptr(),ndown.ptr())
145 
146  #By default graphviz uses 96.0 pixel per inch (dpi=96.0)
147  for n in G.nodes():
148  item=self.citems[int(n)]
149  h=item.height()/dpi #height in inch
150  w=item.width()/dpi #width in inch
151  n.attr['height']=str(h)
152  n.attr['width']=str(w)
153  n.attr['fixedsize']="true"
154  n.attr['shape']="box"
155  #n.attr['label']=item.node.getName()
156 
157  G.layout(prog='dot') # use dot
158  #G.write("layout.dot")
159  #G.draw("layout.png")
160 
161  graph_attr=dict(attrs(G))
162  bbox=graph_attr["bb"]
163  x1,y1,x2,y2=eval(bbox)
164  h=self.canvas.height()
165  w=self.canvas.width()
166  h2=max(h,y2-y1+100)
167  w2=max(w,x2-x1+100)
168  if h2 > h or w2 > w:
169  self.canvas.resize(w2,h2)
170 
171  for n in G:
172  pos=n.attr['pos'] #position is given in points (72 points par inch, so 1 point = dpi/72=1.34)
173  x,y=eval(pos)
174  x=aspect*x
175  y=aspect*y
176  item=self.citems[int(n)]
177  x0=item.x()
178  y0=item.y()
179  x=x-x0
180  y=y-y0
181  item.moveBy(x,y)
182 
183  self.canvas.update()
184 
def attrs(g, t=gv.AGRAPH)
Definition: graph.py:265

References gui.graph.attrs(), gui.CItems.LinkItem.canvas, gui.graph.Graph.canvas, gui.graph.Graph.citems, gui.cataitems.ItemNode.node, gui.cataitems.ItemComposedNode.node, gui.CItems.ControlItem.node, gui.CItems.PortItem.node, gui.CItems.Cell.node, gui.graph.Graph.node, gui.GraphViewer.PortItem.node, gui.Items.ItemComposedNode.node, gui.Items.ItemNode.node, YACS::servertypeParser< T >.node(), YACS::servicetypeParser< T >.node(), YACS::looptypeParser< ENGINE::WhileLoop * >.node(), YACS::looptypeParser< PseudoComposedNode * >.node(), YACS::looptypeParser< ENGINE::DynParaLoop * >.node(), YACS::looptypeParser< ENGINE::ForLoop * >.node(), YACS::looptypeParser< T >.node(), YACS::casetypeParser.node(), YACS::bloctypeParser< YACS::ENGINE::Proc * >.node(), and YACS::bloctypeParser< T >.node().

◆ orthoLinks()

def gui.graph.Graph.orthoLinks (   self)

Definition at line 195 of file graph.py.

195  def orthoLinks(self):
196  items=list(self.citems.values())
197  g=grid(items)
198  for node in items:
199  for port in node.outports:
200  if not hasattr(port,"links"):
201  continue
202  for link in port.links():
203  #clear all intermediate points of the link
204  link.clearPoints()
205  #if isinstance(link,CItems.ControlLinkItem):
206  # print port.port.getNode().getName() +"->"+link.toPort.port.getNode().getName()
207  #else:
208  # print port.port.getNode().getName() +":"+port.port.getName()+"->"+link.toPort.port.getNode().getName()+":"+link.toPort.port.getName()
209  #print (port.x(),port.y()),(link.toPort.x(),link.toPort.y())
210  x0,y0=port.x()+5,port.y()
211  while g.get((x0,y0)).blocked:
212  x0=x0+1
213  x1,y1=link.toPort.x()-5,link.toPort.y()
214  while g.get((x1,y1)).blocked:
215  x1=x1-1
216  path=g.findPath((x0,y0),(x1,y1))
217  #print path
218  if len(path)==1:
219  if port.y() == link.toPort.y():
220  #near ports face to face
221  continue
222  else:
223  x,y=path[0]
224  path=[(x,port.y()),(x,link.toPort.y())]
225  elif len(path)==2:
226  x1,y1=path[0]
227  x2,y2=path[1]
228  if x1 == x2:
229  #vertical line
230  path=[(x1,port.y()),(x1,link.toPort.y())]
231  else:
232  #horizontal line
233  if port.y() == link.toPort.y():
234  #near ports face to face
235  continue
236  else:
237  #transform it into a vertical line
238  x=(x1+x2)/2
239  path=[(x,port.y()),(x,link.toPort.y())]
240 
241  #adjust the first point to the same y as port
242  x0,y0=path[0]
243  x1,y1=path[1]
244  if y0==y1:
245  #remove first point and adjust second one
246  del path[0]
247  x0=x1
248  path[0]=x0,port.y()
249  #adjust the last point to the same y as link.toPort
250  x0,y0=path[-1]
251  x1,y1=path[-2]
252  if y0==y1:
253  #remove last point and adjust new last one
254  del path[-1]
255  x0=x1
256  path[-1]=x0,link.toPort.y()
257  #print path
258 
259  #add intermediate points
260  for x,y in path:
261  line=link.lines[-1]
262  link.splitLine(line,x,y)
263  self.canvas.update()
264 

References gui.CItems.LinkItem.canvas, gui.graph.Graph.canvas, and gui.graph.Graph.citems.

◆ selectItem()

def gui.graph.Graph.selectItem (   self,
  item 
)

Definition at line 119 of file graph.py.

119  def selectItem(self,item):
120  #print "graph.selectItem",item
121  self.editor.selectItem(item)
122 

References gui.graph.Graph.editor.

Referenced by gui.Tree.Tree.additem().

Member Data Documentation

◆ canvas

◆ citems

◆ editor

gui.graph.Graph.editor

Definition at line 47 of file graph.py.

Referenced by gui.graph.Graph.selectItem().

◆ item

◆ node

◆ parent

gui.graph.Graph.parent

Definition at line 42 of file graph.py.

Referenced by gui.Appli.Runner.run().


The documentation for this class was generated from the following file: