2
* Tcl extension for Dynamic Graphs by John Ellson (ellson@lucent.com)
4
* Builds on libincr + libgraph by Stephen North (north@research.att.com)
13
/* FIXME globally accessable structure. not thread safe */
14
/* should be malloc'ed in Init and reference through ClientData */
15
dglInterp_t dglInterp;
17
/* available engines from dynagraph */
18
extern ILengine_t OrthoGrid;
19
extern ILengine_t DynaDag;
20
extern ILengine_t GeoGraph;
21
extern ILengine_t FDPGraph;
24
dglayoutprops(dgLayout_t *v, int argc, char **argv)
27
processes any combination of the following configuration switches:
28
-engine (enum:dynadag,geograph,orthogrid) (default geograph)
29
-orientation (int) (default 2)
30
-resolution (float) (default 1)
31
-xseparation (float) (default 10)
32
-yseparation (float) (default 40)
33
-ticks (float) (default 1)
36
int res=TCL_OK, i=0, length;
41
interp = v->dglInterp->interp;
44
Tcl_AppendResult(interp,
45
"invalid number of args, must be even",
50
if (argv[i][0] != '-') {
51
Tcl_AppendResult(interp,
52
"invalid switch: \"", argv[i], (char *) NULL);
55
length = strlen(argv[i]);
56
if (strncmp(argv[i], "-engine", length) == 0) {
59
length = strlen(argv[i]);
61
if (c == 'd' && strncasecmp(argv[i], "dynadag", length) == 0)
63
else if (c == 'f' && strncasecmp(argv[i], "fdpgraph", length) == 0)
64
v->engine = &FDPGraph;
65
else if (c == 'g' && strncasecmp(argv[i], "geograph", length) == 0)
66
v->engine = &GeoGraph;
67
else if (c == 'o' && strncasecmp(argv[i], "orthogrid", length) == 0)
68
v->engine = &OrthoGrid;
72
else if (strncmp(argv[i], "-orientation", length) == 0)
73
res = Tcl_GetInt(interp, argv[++i], &v->orientation);
74
else if (strncmp(argv[i], "-resolution", length) == 0) {
75
res = Tcl_GetDouble(interp, argv[++i], &dtemp);
77
((ILview_t *)v)->resolution = (float)dtemp;
79
else if (strncmp(argv[i], "-xseparation", length) == 0)
80
res = Tcl_GetDouble(interp, argv[++i],
81
&((ILview_t *)v)->separation.x);
82
else if (strncmp(argv[i], "-yseparation", length) == 0)
83
res = Tcl_GetDouble(interp, argv[++i],
84
&((ILview_t *)v)->separation.y);
85
else if (strncmp(argv[i], "-ticks", length) == 0) {
86
res = Tcl_GetDouble(interp, argv[++i], &dtemp);
88
((ILview_t *)v)->ticks = (float)dtemp;
91
Tcl_AppendResult(interp,
92
"unknown switch: \"", argv[i], (char *) NULL);
96
Tcl_AppendResult(interp, "invalid switch value: \"",
97
argv[i-1], " ", argv[i], (char *) NULL);
106
dglayout(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
108
dglInterp_t *dg = (dglInterp_t *)clientData;
113
tv = (dgLayout_t **) tclhandleAlloc(dg->layoutTable, (char *)NULL, &id);
114
*tv = v = (dgLayout_t *) Tcl_Alloc(sizeof(dgLayout_t));
116
layout_to_handle(v, vbuf);
119
Tcl_InitHashTable(&(v->edgetable), TCL_STRING_KEYS);
120
Tcl_InitHashTable(&(v->nodetable), TCL_STRING_KEYS);
122
((ILview_t *)v)->base.tag = ILVIEW;
123
((ILview_t *)v)->ins = (ILevf_t)insert_obj;
124
((ILview_t *)v)->mod = (ILevf_t)modify_obj;
125
((ILview_t *)v)->del = (ILevf_t)delete_obj;
127
v->batch_cmd = (char *) NULL;
128
v->insert_node_cmd = (char *) NULL;
129
v->insert_edge_cmd = (char *) NULL;
130
v->modify_node_cmd = (char *) NULL;
131
v->modify_edge_cmd = (char *) NULL;
132
v->delete_node_cmd = (char *) NULL;
133
v->delete_edge_cmd = (char *) NULL;
135
/* callbacks are controlled by the "batch" command */
136
/* default is "batch 0" i.e. callbacks enabled */
137
((ILview_t *)v)->enable_immediate_callbacks = 1;
139
/* TODO the following should be configure options with cget support */
140
((ILview_t *)v)->resolution = 1;
141
((ILview_t *)v)->separation.x = 10;
142
((ILview_t *)v)->separation.y = 40;
143
((ILview_t *)v)->ticks = 1;
144
((ILview_t *)v)->max_bb.x = 50;
145
((ILview_t *)v)->max_bb.y = 50;
147
v->engine = &GeoGraph;
149
if (dglayoutprops(v, argc-1, &argv[1]) != TCL_OK) {
150
tclhandleFreeIndex(dg->layoutTable, id);
154
/* create node and edge defaults */
155
v->defaultedge = (ILedge_t *)Tcl_Alloc(sizeof(ILedge_t));
156
assert (v->defaultedge);
157
initedgespec(v->defaultedge);
158
setedgeshape(v->defaultedge, IL_SPLINE);
160
v->defaultnode = (ILnode_t *)Tcl_Alloc(sizeof(ILnode_t));
161
assert (v->defaultnode);
162
initnodespec(v->defaultnode);
163
setnodeshape(v->defaultnode, IL_ELLIPSE);
165
ilopen(v->engine, (ILview_t *)v);
167
Tcl_CreateCommand(interp, vbuf, layoutcmd, clientData,
168
(Tcl_CmdDeleteProc *) NULL);
169
Tcl_AppendResult(interp, vbuf, (char *) NULL);
175
Tcldgl_Init(Tcl_Interp * interp)
178
if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
182
if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) {
186
if (Tcl_PkgRequire(interp, "Tcldgr", VERSION, 0) == NULL) {
189
if (Tcl_PkgProvide(interp, "Tcldgl", VERSION) != TCL_OK) {
193
dglInterp.interp = interp;
194
dglInterp.layoutTable = tclhandleInit("dgL",sizeof(dgLayout_t), 10);
196
Tcl_CreateCommand(interp, "dglayout", dglayout, &dglInterp,
197
(Tcl_CmdDeleteProc *) NULL);
203
Tcldgl_SafeInit(Tcl_Interp * interp)
205
return Tcldgl_Init(interp);
208
void __eprintf(const char *a, const char *b, unsigned c, const char *d) {}