[Xcircuit-dev] restore insertparam to python/Xw branch
ldoolitt at recycle.lbl.gov
ldoolitt at recycle.lbl.gov
Tue Jun 6 11:59:57 PDT 2006
Nominally restores insertparam() functionality to python/Xw builds.
I'm not really happy with the order of parameters listed by Wprintf().
A typical status/prompt line for a Resistor is
Choose: 1 = v3 = <?>, 2 = v2 = <k>, 3 = v1 = <1.0>
..and you have to press either 1, 2, or 3. If I knew that all of
these string parameters consisted of "v" and a digit, I would do
something different.
getkeynum() is stolen directly from xcircuit-3.1.24.
Its comments and code look rife with off-by-one errors.
It returns 0 if you press XK_1.
- Larry
diff -ur xcircuit-3.6-ref/events.c xcircuit-3.6-work/events.c
--- xcircuit-3.6-ref/events.c 2006-06-02 20:36:05.000000000 -0700
+++ xcircuit-3.6-work/events.c 2006-06-06 11:24:58.000000000 -0700
@@ -1199,6 +1199,32 @@
checkwarp(&curang);
}
+/*------------------------------------------------------*/
+/* Get a numerical response from the keyboard (0-9) */
+/*------------------------------------------------------*/
+
+#ifndef TCL_WRAPPER
+
+short getkeynum()
+{
+ XEvent event;
+ XKeyEvent *keyevent = (XKeyEvent *)(&event);
+ KeySym keypressed;
+
+ for (;;) {
+ XNextEvent(dpy, &event);
+ if (event.type == KeyPress) break;
+ else xcDispatchEvent(&event);
+ }
+ XLookupString(keyevent, _STR, 150, &keypressed, NULL);
+ if (keypressed > XK_0 && keypressed <= XK_9)
+ return (short)(keypressed - XK_1);
+ else
+ return -1;
+}
+
+#endif
+
/*--------------------------*/
/* Register a "press" event */
/*--------------------------*/
diff -ur xcircuit-3.6-ref/parameter.c xcircuit-3.6-work/parameter.c
--- xcircuit-3.6-ref/parameter.c 2006-06-02 20:36:05.000000000 -0700
+++ xcircuit-3.6-work/parameter.c 2006-06-06 11:24:58.000000000 -0700
@@ -1625,40 +1625,47 @@
#else
- /* First pass is to check how many string parameters there are: */
- /* If only one, then automatically use it. Otherwise, prompt */
- /* for which parameter to use. */
-
- for (ops = topobject->params; ops != NULL; ops = ops->next)
- if (ops->type == XC_STRING)
- nparms++;
-
- if (nparms > 1) {
+ {
char *newstr, *sptr;
char *sstart = (char *)malloc(1024);
+ oparamptr chosen_ops=NULL;
nparms = 0;
strcpy(sstart, "Choose: ");
sptr = sstart + 8;
for (ops = topobject->params; ops != NULL; ops = ops->next) {
if (ops->type == XC_STRING) {
+ chosen_ops = ops;
nparms++;
if (nparms != 1) {
strcat(sptr, ", ");
sptr += 2;
}
- sprintf(sptr, "%s = <", ops->key);
newstr = stringprint(ops->parameter.string, NULL);
- strcat(sptr, newstr);
+ sprintf(sptr, "%d = %s = <%s", nparms, ops->key, newstr);
free(newstr);
newstr = NULL;
sptr += strlen(sptr);
}
}
- Wprintf("%s", sstart);
- free(sstart);
- /* XXX Need a new non-Tcl version method . . . */
- ops = NULL; /* placeholder */
+ /* If only one parameter, then automatically use it. Otherwise, */
+ /* prompt for which parameter to use. */
+
+ if (nparms > 1) {
+ int i=0, select_int;
+ chosen_ops = NULL;
+ Wprintf("%s", sstart);
+ select_int = getkeynum();
+ for (ops = topobject->params; ops != NULL; ops = ops->next) {
+ if (ops->type == XC_STRING) {
+ if (i==select_int) chosen_ops = ops;
+ i++;
+ }
+ }
+ }
+ free(sstart);
+ ops = chosen_ops;
+ if (ops != NULL) selparm = ops->key;
}
#endif
diff -ur xcircuit-3.6-ref/prototypes.h xcircuit-3.6-work/prototypes.h
--- xcircuit-3.6-ref/prototypes.h 2006-06-02 20:36:05.000000000 -0700
+++ xcircuit-3.6-work/prototypes.h 2006-06-06 11:24:58.000000000 -0700
@@ -177,6 +177,7 @@
extern void elvflip(genericptr *, short);
extern void elementflip(XPoint *);
extern void elementvflip(XPoint *);
+extern short getkeynum(void);
#ifdef TCL_WRAPPER
extern void makepress(ClientData);
#else
More information about the Xcircuit-dev
mailing list