Mercurial > hg > camir-aes2014
comparison toolboxes/graph_visualisation/lib/lefty/dotty_ui.lefty @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 # | |
2 # dotty_ui: user interface functions and data structures | |
3 # | |
4 dotty.protogt.doaction = function (data, s) { | |
5 local vt, gt; | |
6 | |
7 vt = dotty.views[data.widget]; | |
8 gt = dotty.graphs[vt.gtid]; | |
9 data.menuitem = s; | |
10 if (data.obj.nid >= 0) { | |
11 if (gt.actions.node[s]) { | |
12 gt.actions.node[s] (gt, vt, data.obj, data); | |
13 return; | |
14 } | |
15 } else if (data.obj.eid >= 0) { | |
16 if (gt.actions.edge[s]) { | |
17 gt.actions.edge[s] (gt, vt, data.obj, data); | |
18 return; | |
19 } | |
20 } | |
21 if (gt.actions.general[s]) | |
22 gt.actions.general[s] (gt, vt, data); | |
23 }; | |
24 dotty.protogt.actions.general = [ | |
25 "undo" = function (gt, vt, data) { | |
26 gt.undo (gt, 1); | |
27 }; | |
28 "paste" = function (gt, vt, data) { | |
29 gt.paste (gt, data.pos, 1); | |
30 }; | |
31 "do layout" = function (gt, vt, data) { | |
32 gt.layoutgraph (gt); | |
33 }; | |
34 "cancel layout" = function (gt, vt, data) { | |
35 gt.cancellayout (gt); | |
36 }; | |
37 "redraw" = function (gt, vt, data) { | |
38 gt.redrawgraph (gt, [vt.vtid = vt;]); | |
39 }; | |
40 "new graph" = function (gt, vt, data) { | |
41 gt.erasegraph (gt, null, null); | |
42 }; | |
43 "load graph" = function (gt, vt, data) { | |
44 gt.loadgraph (gt, null, 'file', dotty.protogt.graph, 1); | |
45 }; | |
46 "reload graph" = function (gt, vt, data) { | |
47 gt.loadgraph (gt, gt.name, gt.type, gt.graph, 1); | |
48 }; | |
49 "save graph" = function (gt, vt, data) { | |
50 gt.savegraph (gt, gt.name, gt.type); | |
51 }; | |
52 "save graph as" = function (gt, vt, data) { | |
53 gt.savegraph (gt, null, 'file'); | |
54 }; | |
55 "open view" = function (gt, vt, data) { | |
56 gt = dotty.protogt.creategraph (null); | |
57 gt.createview (gt, null); | |
58 }; | |
59 "copy view" = function (gt, vt, data) { | |
60 gt = gt.copygraph (gt); | |
61 gt.createview (gt, vt); | |
62 }; | |
63 "birdseye view" = function (gt, vt, data) { | |
64 gt.createview (gt, dotty.protovt.birdseye); | |
65 }; | |
66 "clone view" = function (gt, vt, data) { | |
67 gt.createview (gt, vt); | |
68 }; | |
69 "close view" = function (gt, vt, data) { | |
70 gt.destroyview (gt, vt); | |
71 if (tablesize (gt.views) == 0) | |
72 gt.destroygraph (gt); | |
73 }; | |
74 "set graph attr" = function (gt, vt, data) { | |
75 gt.setattr (gt, ['attr' = gt.graph.graphattr;]); | |
76 }; | |
77 "set node attr" = function (gt, vt, data) { | |
78 gt.setattr (gt, ['attr' = gt.graph.nodeattr;]); | |
79 }; | |
80 "set edge attr" = function (gt, vt, data) { | |
81 gt.setattr (gt, ['attr' = gt.graph.edgeattr;]); | |
82 }; | |
83 "zoom in" = function (gt, vt, data) { | |
84 gt.zoom (gt, vt, 0.5, data.pos); | |
85 }; | |
86 "zoom out" = function (gt, vt, data) { | |
87 gt.zoom (gt, vt, 2, data.pos); | |
88 }; | |
89 "zoom in slowly" = function (gt, vt, data) { | |
90 gt.zoom (gt, vt, 0.9, data.pos); | |
91 }; | |
92 "zoom out slowly" = function (gt, vt, data) { | |
93 gt.zoom (gt, vt, 1.1, data.pos); | |
94 }; | |
95 "scroll horizontally" = function (gt, vt, data) { | |
96 vt.scrollmode = 'h'; | |
97 }; | |
98 "scroll vertically" = function (gt, vt, data) { | |
99 vt.scrollmode = 'v'; | |
100 }; | |
101 "find node" = function (gt, vt, data) { | |
102 gt.findnode (gt, vt); | |
103 }; | |
104 "print graph" = function (gt, vt, data) { | |
105 gt.printorsave (gt, vt, null, null, null, null); | |
106 }; | |
107 "text view" = function (gt, vt, data) { | |
108 if (dotty.txtview == 'on') | |
109 dotty.txtview = 'off'; | |
110 else | |
111 dotty.txtview = 'on'; | |
112 txtview (dotty.txtview); | |
113 }; | |
114 "quit" = function (gt, vt, data) { | |
115 exit (); | |
116 }; | |
117 ]; | |
118 dotty.protogt.actions.node = [ | |
119 "cut" = function (gt, vt, obj, data) { | |
120 gt.cut (gt, obj, 'one', 'support', 'cut'); | |
121 dotty.clipgt.layoutgraph (dotty.clipgt); | |
122 }; | |
123 "Cut" = function (gt, vt, obj, data) { | |
124 gt.cut (gt, obj, 'reachable', 'support', 'cut'); | |
125 dotty.clipgt.layoutgraph (dotty.clipgt); | |
126 }; | |
127 "copy" = function (gt, vt, obj, data) { | |
128 gt.cut (gt, obj, 'one', 'support', 'copy'); | |
129 dotty.clipgt.layoutgraph (dotty.clipgt); | |
130 }; | |
131 "Copy" = function (gt, vt, obj, data) { | |
132 gt.cut (gt, obj, 'reachable', 'support', 'copy'); | |
133 dotty.clipgt.layoutgraph (dotty.clipgt); | |
134 }; | |
135 "group" = function (gt, vt, obj, data) { | |
136 local kv; | |
137 | |
138 if ((kv = gt.getattr (gt, obj))) | |
139 gt.groupnodesbyattr (gt, kv.key, kv.val, [ | |
140 'label' = kv.val; kv.key = kv.val; | |
141 ], 1, 1); | |
142 }; | |
143 "Group" = function (gt, vt, obj, data) { | |
144 local kv; | |
145 | |
146 if ((kv = gt.getattr (gt, obj))) | |
147 gt.groupnodesbyattr (gt, kv.key, kv.val, [ | |
148 'label' = kv.val; kv.key = kv.val; | |
149 ], 0, 1); | |
150 }; | |
151 "delete" = function (gt, vt, obj, data) { | |
152 if (obj.eid >= 0) | |
153 gt.removeedge (gt, obj); | |
154 else | |
155 gt.removenode (gt, obj); | |
156 }; | |
157 "Delete" = function (gt, vt, obj, data) { | |
158 gt.removesubtree (gt, obj); | |
159 }; | |
160 "remove" = function (gt, vt, obj, data) { | |
161 if (obj.nid >= 0) | |
162 if ((kv = gt.getattr (gt, obj))) | |
163 gt.removenodesbyattr (gt, kv.key, kv.val); | |
164 }; | |
165 "Remove" = function (gt, vt, obj, data) { | |
166 if (obj.nid >= 0) | |
167 if ((kv = gt.getattr (gt, obj))) | |
168 gt.removesubtreesbyattr (gt, kv.key, kv.val); | |
169 }; | |
170 "set attr" = function (gt, vt, obj, data) { | |
171 gt.setattr (gt, obj); | |
172 }; | |
173 "print attr" = function (gt, vt, obj, data) { | |
174 if (obj.nid >= 0) | |
175 echo ('node: ', obj.name); | |
176 dump (obj.attr); | |
177 }; | |
178 ]; | |
179 dotty.protogt.actions.edge = dotty.protogt.actions.node; | |
180 dotty.protovt.normal.menus = [ | |
181 'general' = [ | |
182 0 = "undo"; | |
183 1 = "paste"; | |
184 2 = "do layout"; | |
185 3 = "cancel layout"; | |
186 4 = "redraw"; | |
187 5 = "new graph"; | |
188 6 = "load graph"; | |
189 7 = "reload graph"; | |
190 8 = "save graph"; | |
191 9 = "save graph as"; | |
192 10 = "open view"; | |
193 11 = "copy view"; | |
194 12 = "clone view"; | |
195 13 = "birdseye view"; | |
196 14 = "close view"; | |
197 15 = "set graph attr"; | |
198 16 = "set node attr"; | |
199 17 = "set edge attr"; | |
200 18 = "zoom in"; | |
201 19 = "zoom out"; | |
202 20 = "find node"; | |
203 21 = "print graph"; | |
204 22 = "text view"; | |
205 23 = "quit"; | |
206 ]; | |
207 'node' = [ | |
208 0 = "cut"; | |
209 1 = "Cut"; | |
210 2 = "copy"; | |
211 3 = "Copy"; | |
212 4 = "group"; | |
213 5 = "Group"; | |
214 6 = "delete"; | |
215 7 = "Delete"; | |
216 8 = "remove"; | |
217 9 = "Remove"; | |
218 10 = "set attr"; | |
219 11 = "print attr"; | |
220 ]; | |
221 'edge' = [ | |
222 0 = "cut"; | |
223 1 = "Cut"; | |
224 2 = "copy"; | |
225 3 = "Copy"; | |
226 4 = "delete"; | |
227 5 = "Delete"; | |
228 6 = "set attr"; | |
229 7 = "print attr"; | |
230 ]; | |
231 ]; | |
232 dotty.protovt.normal.keys = [ | |
233 'general' = [ | |
234 'u' = "undo"; | |
235 'p' = "paste"; | |
236 'l' = "do layout"; | |
237 'k' = "cancel layout"; | |
238 ' ' = "redraw"; | |
239 'L' = "reload graph"; | |
240 's' = "save graph"; | |
241 'Z' = "zoom in slowly"; | |
242 'z' = "zoom out slowly"; | |
243 'h' = "scroll horizontally"; | |
244 'v' = "scroll vertically"; | |
245 ]; | |
246 'node' = [ | |
247 'c' = "copy"; | |
248 'C' = "Copy"; | |
249 'g' = "group"; | |
250 'G' = "Group"; | |
251 'd' = "delete"; | |
252 'D' = "Delete"; | |
253 'r' = "remove"; | |
254 'R' = "Remove"; | |
255 'a' = "set attr"; | |
256 ]; | |
257 'edge' = [ | |
258 'c' = "copy"; | |
259 'C' = "Copy"; | |
260 'd' = "delete"; | |
261 'D' = "Delete"; | |
262 'a' = "set attr"; | |
263 ]; | |
264 ]; | |
265 dotty.protovt.birdseye.menus = dotty.protovt.normal.menus; | |
266 dotty.protovt.birdseye.keys = dotty.protovt.normal.keys; | |
267 dotty.protovt.normal.uifuncs = [ | |
268 'leftdown' = function (data) { | |
269 local gt; | |
270 | |
271 gt = dotty.graphs[dotty.views[data.widget].gtid]; | |
272 if (data.obj.nid >= 0) { | |
273 dotty.node2move = data.obj; | |
274 dotty.movewidget = data.widget; | |
275 dotty.rp2 = data.pos; | |
276 } | |
277 }; | |
278 'leftmove' = function (data) { | |
279 local gt; | |
280 | |
281 gt = dotty.graphs[dotty.views[data.widget].gtid]; | |
282 if (dotty.node2move & ( | |
283 dotty.rp2.x ~= data.pos.x | dotty.rp2.y ~= data.pos.y | |
284 )) { | |
285 gt.movenode (gt, dotty.node2move, data.pos); | |
286 dotty.rp2 = data.pos; | |
287 } | |
288 }; | |
289 'leftup' = function (data) { | |
290 local gt; | |
291 | |
292 gt = dotty.graphs[dotty.views[data.widget].gtid]; | |
293 if (dotty.node2move) { | |
294 if (dotty.movewidget == data.widget) | |
295 gt.movenode (gt, dotty.node2move, data.pos); | |
296 dotty.node2move = 0; | |
297 } else if (~data.obj) | |
298 gt.insertnode (gt, data.pos, null, null, null, 1); | |
299 }; | |
300 'middledown' = function (data) { | |
301 if (~(data.obj.nid >= 0)) | |
302 return; | |
303 dotty.rubberband = 1; | |
304 dotty.movewidget = data.widget; | |
305 setgfxattr (data.widget, ['mode' = 'xor';]); | |
306 dotty.rp1 = data.pos; | |
307 dotty.rp2 = data.pos; | |
308 line (data.widget, null, dotty.rp1, dotty.rp2, ['color' = 1;]); | |
309 }; | |
310 'middlemove' = function (data) { | |
311 if (dotty.rubberband ~= 1 | ( | |
312 dotty.rp2.x == data.pos.x & dotty.rp2.y == data.pos.y | |
313 )) | |
314 return; | |
315 line (data.widget, null, dotty.rp1, dotty.rp2, ['color' = 1;]); | |
316 dotty.rp2 = data.pos; | |
317 line (data.widget, null, dotty.rp1, dotty.rp2, ['color' = 1;]); | |
318 }; | |
319 'middleup' = function (data) { | |
320 local gt; | |
321 | |
322 gt = dotty.graphs[dotty.views[data.widget].gtid]; | |
323 if (dotty.rubberband ~= 1) | |
324 return; | |
325 dotty.rubberband = 0; | |
326 line (dotty.movewidget, null, dotty.rp1, dotty.rp2, ['color' = 1;]); | |
327 setgfxattr (dotty.movewidget, ['mode' = 'src';]); | |
328 if (dotty.movewidget ~= data.widget | ~( | |
329 data.pobj.nid >= 0) | ~(data.obj.nid >= 0 | |
330 )) | |
331 return; | |
332 if (data.pobj.attr.support) | |
333 gt.groupnodes (gt, [ | |
334 data.obj.nid = data.obj; | |
335 data.pobj.nid = data.pobj; | |
336 ], data.obj, null, null, null, 1, 1); | |
337 else if (data.obj.attr.support) | |
338 gt.groupnodes (gt, [ | |
339 data.obj.nid = data.obj; | |
340 data.pobj.nid = data.pobj; | |
341 ], data.pobj, null, null, null, 1, 1); | |
342 else | |
343 gt.insertedge (gt, data.pobj, null, data.obj, null, null, 1); | |
344 }; | |
345 'rightdown' = function (data) { | |
346 local vt, gt, menu, i; | |
347 | |
348 vt = dotty.views[data.widget]; | |
349 gt = dotty.graphs[vt.gtid]; | |
350 if (~data.obj) | |
351 menu = vt.menus.general; | |
352 else if (data.obj.nid >= 0) | |
353 menu = vt.menus.node; | |
354 else if (data.obj.eid >= 0) | |
355 menu = vt.menus.edge; | |
356 if ((i = displaymenu (data.widget, menu)) >= 0) | |
357 gt.doaction (data, menu[i]); | |
358 }; | |
359 'button3up' = function (data) { | |
360 local vt, attr; | |
361 | |
362 vt = dotty.views[data.widget]; | |
363 attr = getwidgetattr (vt.scroll, [0 = 'childcenter';]); | |
364 if (vt.scrollmode == 'h') | |
365 attr.childcenter.x = attr.childcenter.x - 40; | |
366 else | |
367 attr.childcenter.y = attr.childcenter.y - 40; | |
368 setwidgetattr (vt.scroll, ['childcenter' = attr.childcenter;]); | |
369 }; | |
370 'button4up' = function (data) { | |
371 local vt, attr; | |
372 | |
373 vt = dotty.views[data.widget]; | |
374 attr = getwidgetattr (vt.scroll, [0 = 'childcenter';]); | |
375 if (vt.scrollmode == 'h') | |
376 attr.childcenter.x = attr.childcenter.x + 40; | |
377 else | |
378 attr.childcenter.y = attr.childcenter.y + 40; | |
379 setwidgetattr (vt.scroll, ['childcenter' = attr.childcenter;]); | |
380 }; | |
381 'keyup' = function (data) { | |
382 local vt, gt, action; | |
383 | |
384 vt = dotty.views[data.widget]; | |
385 gt = dotty.graphs[vt.gtid]; | |
386 if (data.obj.nid >= 0) { | |
387 if (vt.keys.node[data.key]) | |
388 action = vt.keys.node[data.key]; | |
389 } else if (data.obj.eid >= 0) { | |
390 if (vt.keys.edge[data.key]) | |
391 action = vt.keys.edge[data.key]; | |
392 } | |
393 if (~action) | |
394 if (vt.keys.general[data.key]) | |
395 action = vt.keys.general[data.key]; | |
396 if (action) | |
397 gt.doaction (data, action); | |
398 }; | |
399 'redraw' = function (data) { | |
400 local vt, gt; | |
401 | |
402 vt = dotty.views[data.widget]; | |
403 gt = dotty.graphs[vt.gtid]; | |
404 gt.drawgraph (gt, [vt.vtid = vt;]); | |
405 }; | |
406 'closeview' = function (data) { | |
407 local vt, gt; | |
408 | |
409 vt = dotty.views[data.widget]; | |
410 gt = dotty.graphs[vt.gtid]; | |
411 gt.destroyview (gt, vt); | |
412 if (tablesize (gt.views) == 0) | |
413 gt.destroygraph (gt); | |
414 }; | |
415 ]; | |
416 dotty.protovt.birdseye.uifuncs = [ | |
417 'leftdown' = function (data) { | |
418 local gt, vid; | |
419 | |
420 gt = dotty.graphs[dotty.views[data.widget].gtid]; | |
421 for (vid in gt.views) { | |
422 vt = gt.views[vid]; | |
423 if (vt.type ~= 'birdseye') | |
424 gt.setviewcenter ([vid = vt;], data.pos); | |
425 } | |
426 }; | |
427 'leftmove' = function (data) { | |
428 local gt, vid; | |
429 | |
430 gt = dotty.graphs[dotty.views[data.widget].gtid]; | |
431 for (vid in gt.views) { | |
432 vt = gt.views[vid]; | |
433 if (vt.type ~= 'birdseye') | |
434 gt.setviewcenter ([vid = vt;], data.pos); | |
435 } | |
436 }; | |
437 'leftup' = function (data) { | |
438 local gt, vid; | |
439 | |
440 gt = dotty.graphs[dotty.views[data.widget].gtid]; | |
441 for (vid in gt.views) { | |
442 vt = gt.views[vid]; | |
443 if (vt.type ~= 'birdseye') | |
444 gt.setviewcenter ([vid = vt;], data.pos); | |
445 } | |
446 }; | |
447 'middledown' = dotty.protovt.normal.uifuncs.middledown; | |
448 'middlemove' = dotty.protovt.normal.uifuncs.middlemove; | |
449 'middleup' = dotty.protovt.normal.uifuncs.middleup; | |
450 'rightdown' = dotty.protovt.normal.uifuncs.rightdown; | |
451 'keyup' = dotty.protovt.normal.uifuncs.keyup; | |
452 'redraw' = dotty.protovt.normal.uifuncs.redraw; | |
453 'closeview' = dotty.protovt.normal.uifuncs.closeview; | |
454 ]; | |
455 dotty.monitorfile = function (data) { | |
456 local gtid, gt, lpt; | |
457 | |
458 for (gtid in dotty.layoutpending) { | |
459 lpt = dotty.layoutpending[gtid]; | |
460 if (lpt.fd == data.fd) { | |
461 gt = dotty.graphs[lpt.gtid]; | |
462 gt.haveinput = 1; | |
463 gt.layoutgraph (gt); | |
464 return 1; | |
465 } | |
466 } | |
467 return 0; | |
468 }; |