1 /*****************************************************************************
2 FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/xgui/sources/ui_mainP.c,v $
3 SHORTNAME : mainP.c
4 SNNS VERSION : 4.2
5
6 PURPOSE :
7 PURPOSE : contains callback routines of the gui window
8 NOTES :
9
10 AUTHOR : Tilman Sommer
11 DATE : 1.4.1990
12
13 CHANGED BY : Michael Vogt, Guenter Mamier
14 RCS VERSION : $Revision: 2.26 $
15 LAST CHANGE : $Date: 1998/05/20 15:00:40 $
16
17 Copyright (c) 1990-1995 SNNS Group, IPVR, Univ. Stuttgart, FRG
18 Copyright (c) 1996-1998 SNNS Group, WSI, Univ. Tuebingen, FRG
19
20 ******************************************************************************/
21 #include <config.h>
22
23
24 #include <ctype.h>
25 #include <stdio.h> /* For the Syntax message */
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29
30 #include "ui.h"
31
32 #include <X11/Shell.h>
33
34 #include <X11/cursorfont.h>
35 #include <X11/Xaw3d/MenuButton.h>
36 #include <X11/Xaw3d/Text.h>
37 #include <X11/Xaw3d/TextSrc.h>
38 #include <X11/Xaw3d/Form.h>
39 #include <X11/Xaw3d/Box.h>
40 #include <X11/Xaw3d/Cardinals.h>
41 #include <X11/Xaw3d/Command.h>
42 #include <X11/Xaw3d/Dialog.h>
43 #include <X11/Xaw3d/List.h>
44 #include <X11/Xaw3d/AsciiText.h>
45
46 #include "kr_ui.h"
47
48 #include "ui_info.h"
49 #include "ui_setup.h"
50 #include "ui_layer.h"
51 #include "ui_layerP.h"
52 #include "ui_file.h"
53 #include "ui_fileP.h"
54 #include "ui_netGraph.h"
55 #include "ui_netUpdate.h"
56 #include "ui_event.h"
57 #include "ui_key.h"
58 #include "ui_confirmer.h"
59 #include "ui_xWidgets.h"
60 #include "ui_lists.h"
61 #include "ui_display.h"
62 #include "ui_control.h"
63 #include "ui_controlP.h"
64 #include "ui_edit.h"
65 #include "ui_xGraphic.h"
66 #include "ui_textP.h"
67 #include "ui_funcdispl.h"
68 #include "ui_action.h"
69 #include "ui_result.h"
70 #include "ui_main.h"
71 #include "ui_print.h"
72 #include "ui_color.h"
73 #include "ui_infoP.h"
74
75 #include "ui_mainP.ph"
76
77 #ifdef PARAGON_KERNEL
78 #include "kr_ipmp.h"
79 #endif
80
81
82 /*****************************************************************************
83 FUNCTION : ui_createGC
84
85 PURPOSE : create the GC and load the graphic font
86 RETURNS : void
87 NOTES : window is any existing window of a widget on the screen used by
88 xgui.
89 UPDATE : 20.9.1990
90 ******************************************************************************/
91
ui_xCreateGC(Window window)92 void ui_xCreateGC (Window window)
93
94 {
95 int count;
96 char buf[255];
97 char **fontList;
98
99 ui_fontStruct = XLoadQueryFont(ui_display, ui_dfontName);
100
101 if (ui_fontStruct == 0) {
102 printf("Can't find display font specified in command line\n");
103 exit(1);
104 }else{
105 fontList = XListFonts(ui_display, ui_dfontName, 1, &count);
106 if (count != 0) {
107 sprintf (buf, "Display-Font %s loaded\n", *fontList);
108 ui_tw_printMessage(buf);
109 }
110 XFreeFontNames(fontList);
111 }
112
113 ui_gcValues.line_width = 0;
114 ui_gcValues.line_style = LineSolid;
115 /* Set (or get) the next two attributes, because ui_drawUnit()
116 in the file ui_netGraphics.c need this information */
117 ui_gc = XCreateGC(ui_display, window, GCLineWidth | GCLineStyle,
118 &ui_gcValues);
119 XSetFunction(ui_display,ui_gc, GXcopy);
120 XSetFont(ui_display, ui_gc, ui_fontStruct->fid);
121
122 }
123
124
125 /*****************************************************************************
126 FUNCTION : ui_printMessage
127
128 PURPOSE : display a message in the manager panel
129 RETURNS : void
130 NOTES :
131
132 UPDATE : 1.2.1990
133 ******************************************************************************/
134
ui_printMessage(char * msgString)135 void ui_printMessage (char *msgString)
136
137 {
138 ui_xSetLabel(ui_message, msgString);
139 XFlush(ui_display);
140 }
141
142
143 /*****************************************************************************
144 FUNCTION : ui_displayDone
145
146 PURPOSE : close a xgui display
147 RETURNS : void
148 NOTES :
149
150 UPDATE : 1.2.1990
151 ******************************************************************************/
152
ui_displayDone(Widget widget,struct Ui_DisplayType * displayPtr,caddr_t call_data)153 void ui_displayDone (Widget widget, struct Ui_DisplayType *displayPtr,
154 caddr_t call_data)
155
156 {
157 XtDestroyWidget(XtParent(displayPtr->frameWidget));
158 displayPtr->frameWidget = NULL;
159 displayPtr->widget = NULL;
160 displayPtr->drawable = 0;
161 ui_displ_freeItem(displayPtr);
162 }
163
164
165 /*****************************************************************************
166 FUNCTION : ui_helpDone
167
168 PURPOSE : close a xgui help window
169 RETURNS : void
170 NOTES :
171
172 UPDATE : 1.2.1990
173 ******************************************************************************/
174
175 /*ARGSUSED*/
ui_helpDone(Widget widget,struct HelpType * helpPtr,caddr_t call_data)176 static void ui_helpDone (Widget widget, struct HelpType *helpPtr, caddr_t call_data)
177
178 {
179 struct HelpType *listPtr;
180
181 if (ui_help_listPtr == helpPtr) {
182 ui_help_listPtr = helpPtr->nextPtr;
183 helpPtr->nextPtr = ui_help_freeListPtr;
184 ui_help_freeListPtr = helpPtr;
185 XtDestroyWidget(helpPtr->shellWidget);
186 } else {
187 listPtr = ui_help_listPtr;
188 while (listPtr->nextPtr != NULL AND listPtr->nextPtr != helpPtr)
189 listPtr = listPtr->nextPtr;
190
191 if (listPtr->nextPtr == helpPtr) {
192 listPtr->nextPtr = helpPtr->nextPtr;
193 helpPtr->nextPtr = ui_help_freeListPtr;
194 ui_help_freeListPtr = helpPtr;
195 XtDestroyWidget(helpPtr->shellWidget);
196 }
197 }
198 }
199
200
201 /*****************************************************************************
202 FUNCTION : ui_listPopupDone
203
204 PURPOSE : close a list panel
205 RETURNS : void
206 NOTES :
207
208 UPDATE : 1.2.1990
209 ******************************************************************************/
210
ui_listPopupDone(Widget widget,struct SimpleListType * listDescriptorPtr,caddr_t call_data)211 static void ui_listPopupDone (Widget widget,
212 struct SimpleListType *listDescriptorPtr, caddr_t call_data)
213
214 {
215 int i;
216
217 XtDestroyWidget(ui_popList);
218 ui_pop_exit = TRUE; /* signal to leave temporary event loop */
219 XFlush(ui_display);
220
221 /* keep the allocated space of the array, but free all the space
222 of valid strings */
223 for (i = 1; i<= listDescriptorPtr->noOfItems; i++)
224 free((listDescriptorPtr->listPtr)[i-1]);
225 listDescriptorPtr->noOfItems = 0;
226 }
227
228
229 /*****************************************************************************
230 FUNCTION : ui_editPopupDone
231
232 PURPOSE : close a edit panel
233 RETURNS : void
234 NOTES :
235
236 UPDATE : 1.2.1990
237 ******************************************************************************/
238
ui_editPopupDone(Widget widget,struct SimpleListType * listDescriptorPtr,caddr_t call_data)239 static void ui_editPopupDone (Widget widget,
240 struct SimpleListType *listDescriptorPtr, caddr_t call_data)
241
242 {
243 int i;
244
245 XtDestroyWidget(ui_popEdit);
246
247 /* keep the allocated space of the array, but free all the space
248 of valid strings */
249 for (i = 1; i<= listDescriptorPtr->noOfItems; i++)
250 free((listDescriptorPtr->listPtr)[i-1]);
251 listDescriptorPtr->noOfItems = 0;
252 }
253
254
255 /*****************************************************************************
256 FUNCTION : ui_popupDone
257
258 PURPOSE : close other panels and windows
259 RETURNS : void
260 NOTES :
261
262 UPDATE : 1.2.1990
263 ******************************************************************************/
264
265 /*ARGSUSED*/
ui_popupDone(Widget widget,int client_data,caddr_t call_data)266 void ui_popupDone (Widget widget, int client_data, caddr_t call_data)
267
268 {
269 char buf[80];
270 int gridSize, i;
271
272 switch (client_data) {
273 case UI_POPUP_DUMMY:
274 XtDestroyWidget(ui_popDummy);
275 break;
276 case UI_POPUP_SETUP:
277 ui_setupIsCreated = FALSE;
278 gridSize =
279 ui_xIntFromAsciiWidget(ui_set_gridWidthWidget);
280 if (gridSize >= 1)
281 ui_set_displayPtr->gridSize = gridSize;
282 ui_set_displayPtr->origin.x =
283 ui_xIntFromAsciiWidget(ui_set_originXWidget);
284 ui_set_displayPtr->origin.y =
285 ui_xIntFromAsciiWidget(ui_set_originYWidget);
286 ui_set_displayPtr->subNetNo =
287 ui_xIntFromAsciiWidget(ui_set_subnetWidget);
288 sprintf(buf,"snns-display %d - subnet: %d",
289 ui_set_displayPtr->displayNo,
290 ui_set_displayPtr->subNetNo);
291 ui_actualZvalue = ui_xIntFromAsciiWidget(ui_set_zWidget);
292 XStoreName(ui_display,
293 XtWindow(XtParent(ui_set_displayPtr->frameWidget)),
294 buf);
295 ui_net_completeRefresh(ui_set_displayPtr, UI_LOCAL);
296 XtDestroyWidget(ui_popSetup);
297 break;
298 case UI_POPUP_FILE:
299 ui_fileIsCreated = FALSE;
300 ui_filePannelPoppedUp = FALSE;
301 XtDestroyWidget(ui_popFile);
302 break;
303 case UI_POPUP_LAYER:
304 ui_layer_setLayerNames();
305 XtDestroyWidget(ui_popLayer);
306 ui_pop_exit = TRUE; /* signal to leave temporary loop */
307 XFlush(ui_display);
308 break;
309 case UI_POPUP_CONTROL:
310 for (i=0; i<UI_NO_LEARN_PARAMS; i++)
311 ui_learnParameters[i] = ui_xFloatFromAsciiWidget(ui_learnParameterWidgets[i]);
312 for (i=0; i<UI_NO_UPDATE_PARAMS; i++)
313 ui_updateParameters[i] = ui_xFloatFromAsciiWidget(ui_updateParameterWidgets[i]);
314 for (i=0; i<UI_NO_INIT_PARAMS; i++)
315 ui_initParameters[i] = ui_xFloatFromAsciiWidget(ui_initParameterWidgets[i]);
316 for (i=0; i<UI_NO_REMAP_PARAMS; i++)
317 ui_remapParameters[i] = ui_xFloatFromAsciiWidget(ui_remapParameterWidgets[i]);
318 ui_controlIsCreated = FALSE;
319 XtDestroyWidget(ui_popControl);
320 break;
321 case UI_POPUP_INFO:
322 ui_infoIsCreated = FALSE;
323 XtDestroyWidget(ui_popInfo);
324 break;
325 case UI_POPUP_WEIGHTS_DONE:
326 XtDestroyWidget(ui_popInit);
327 ui_pop_exit = TRUE; /* signal to leave temporary loop */
328 break;
329 case UI_POPUP_WEIGHTS_CANCEL:
330 jog_low = (FlintType) ui_xFloatFromAsciiWidget(ui_lowLimitWidget);
331 jog_high = (FlintType) ui_xFloatFromAsciiWidget(ui_highLimitWidget);
332 jog_correlation = (FlintType) ui_xFloatFromAsciiWidget(ui_correlationLimitWidget);
333 XtDestroyWidget(ui_popWeights);
334 ui_pop_exit = TRUE; /* signal to leave temporary loop */
335 XFlush(ui_display);
336 break;
337 case UI_POPUP_RESULT:
338 XtDestroyWidget(ui_popResult);
339 ui_ResultIsCreated = FALSE;
340 break;
341 case UI_POPUP_SUBPATTERN:
342 if(NO_OF_PATTERN_SETS != 0)ui_rem_getSubPatPanel();
343 XtDestroyWidget(ui_popPattern);
344 SubPatPanel = 0;
345 break;
346 }
347 ui_printMessage("");
348 }
349
350
351 /*****************************************************************************
352 FUNCTION : ui_popupWeights
353
354 PURPOSE : popup of random/jog weights
355 RETURNS : void
356 NOTES :
357
358 UPDATE : 27.5.1990
359 ******************************************************************************/
ui_popupWeights(Widget button,caddr_t call_data,caddr_t client_data)360 void ui_popupWeights (Widget button, caddr_t call_data, caddr_t client_data)
361 {
362 Widget doneButton, form, wrap, label;
363 Arg args[5];
364 Position x, y;
365 Dimension width, height;
366 Cardinal n;
367 char buf[20];
368
369 /* Upper left corner will be in the center of the calling button */
370
371 ui_xGetDimensions(button, &width, &height);
372 XtTranslateCoords(button, (Position) (width / 2),
373 (Position) (height / 2), &x, &y);
374
375 n = 0;
376 XtSetArg(args[n], XtNx, x); n++;
377 XtSetArg(args[n], XtNy, y); n++;
378
379 /* Now create Popup */
380
381 ui_popWeights = XtCreatePopupShell("jog weights", transientShellWidgetClass,
382 ui_toplevel, args, n);
383
384 wrap = XtCreateManagedWidget("form", formWidgetClass, ui_popWeights,NULL,0);
385 form = XtCreateManagedWidget("box", formWidgetClass, wrap,NULL,0);
386
387 label = ui_xCreateLabelItem("low limit:", form, 11*ui_labelFontWidth,
388 NULL, NULL);
389
390 sprintf(buf,"%g",jog_low);
391 ui_lowLimitWidget = ui_xCreateDialogItem("lowLimit", form, buf,
392 9*ui_labelFontWidth, label, NULL);
393
394 label = ui_xCreateLabelItem("high limit:", form, 11*ui_labelFontWidth,
395 ui_lowLimitWidget, NULL);
396
397 sprintf(buf,"%g",jog_high);
398 ui_highLimitWidget = ui_xCreateDialogItem("highLimit", form, buf,
399 9*ui_labelFontWidth, label,
400 NULL);
401
402 label = ui_xCreateLabelItem("Only jog correlated hidden units ?",form,
403 37*ui_labelFontWidth,NULL,ui_lowLimitWidget);
404 button = ui_xCreateToggleItem("yes", form, NULL, label, ui_lowLimitWidget);
405 ui_xSetToggleState(button, ui_jogCorrFlg);
406 XtAddCallback(button, XtNcallback,(XtCallbackProc)ui_jog_toggle_correlation,
407 NULL);
408
409 label = ui_xCreateLabelItem(" min. correlation:", form,
410 32*ui_labelFontWidth+2,
411 NULL, button);
412 sprintf(buf,"%g",jog_correlation);
413 ui_correlationLimitWidget = ui_xCreateDialogItem("correlation", form, buf,
414 9*ui_labelFontWidth, label,
415 button);
416
417 label = ui_xCreateLabelItem("Jog weights now ?",form,37*ui_labelFontWidth,
418 NULL,ui_correlationLimitWidget);
419 button = ui_xCreateButtonItem("yes", form, label,
420 ui_correlationLimitWidget);
421 XtAddCallback(button, XtNcallback, (XtCallbackProc)ui_rem_setRandomWeights,
422 (XtPointer) ((long)UI_JOG));
423
424 label = ui_xCreateLabelItem("Jog every epoch ?",form,
425 37*ui_labelFontWidth,NULL,button);
426 button = ui_xCreateToggleItem("yes", form, NULL, label,button);
427
428 ui_xSetToggleState(button, ui_jogFlg);
429 XtAddCallback(button, XtNcallback, (XtCallbackProc)ui_jog_on,NULL);
430
431 doneButton = ui_xCreateButtonItem("done", wrap, NULL, form);
432 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_popupDone,
433 (caddr_t) UI_POPUP_WEIGHTS_CANCEL);
434
435 ui_checkWindowPosition(ui_popWeights);
436 XtPopup(ui_popWeights, XtGrabExclusive);
437 ui_xDontResizeWidget(ui_popWeights);
438
439 }
440
441 /*****************************************************************************
442 FUNCTION : ui_jog_on
443
444 PURPOSE : set the continous weight jogging
445 RETURNS : void
446 NOTES :
447
448 UPDATE : 08.12.1997
449 ******************************************************************************/
ui_jog_on(Widget w,caddr_t client_data,caddr_t call_data)450 void ui_jog_on(Widget w, caddr_t client_data, caddr_t call_data)
451 {
452 Cardinal n = 0;
453 Arg args[10];
454 Pixel back, fore;
455
456 ui_jogFlg = !ui_jogFlg;
457
458 /* read the current values from a (any) existing widget */
459 XtSetArg(args[n], XtNforeground, &fore); n++;
460 XtSetArg(args[n], XtNbackground, &back); n++;
461 XtGetValues(ui_showModeLabel, args, n);
462
463 n = 0;
464 /* reverse button in the control panel */
465 if(ui_jogFlg){
466 XtSetArg(args[n], XtNbackground, fore);n++;
467 XtSetArg(args[n], XtNforeground, back);n++;
468 }else{
469 XtSetArg(args[n], XtNbackground, back);n++;
470 XtSetArg(args[n], XtNforeground, fore);n++;
471 }
472 XtSetValues(jogbutton, args, n);
473 }
474
475
476
477 /*****************************************************************************
478 FUNCTION : ui_jog_toggle_correlation
479
480 PURPOSE : set the correlation based weight jogging
481 RETURNS : void
482 NOTES :
483
484 UPDATE : 08.12.1997
485 ******************************************************************************/
ui_jog_toggle_correlation(Widget w,caddr_t client_data,caddr_t call_data)486 void ui_jog_toggle_correlation(Widget w, caddr_t client_data, caddr_t call_data)
487 {
488 ui_jogCorrFlg = !ui_jogCorrFlg;
489 }
490
491
492
493 /*****************************************************************************
494 FUNCTION : ui_editPopup
495
496 PURPOSE : edit popup of f-types
497 RETURNS : void
498 NOTES :
499
500 UPDATE : 27.8.1990
501 ******************************************************************************/
502
ui_editPopup(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call_data)503 void ui_editPopup (Widget w, struct SimpleListType *listDescriptorPtr,
504 caddr_t call_data)
505
506 {
507 Widget doneButton, abutton, form, actLabel, label, button;
508 Arg args[10];
509 Position x, y;
510 Dimension width, height;
511 Cardinal n;
512
513 /* Upper left corner will be in the center of the calling button */
514
515 n = 0;
516 XtSetArg(args[n], XtNwidth, &width); n++;
517 XtSetArg(args[n], XtNheight, &height); n++;
518 XtGetValues(listDescriptorPtr->widgetPtr, args, n);
519 XtTranslateCoords(listDescriptorPtr->widgetPtr,
520 (Position) (width / 2), (Position) (height / 2),
521 &x, &y);
522
523 n = 0;
524 XtSetArg(args[n], XtNx, x); n++;
525 XtSetArg(args[n], XtNy, y); n++;
526
527 /* Now create Popup */
528
529 ui_popEdit = XtCreatePopupShell("edit f-types", transientShellWidgetClass,
530 ui_toplevel, args, n);
531
532 form = XtCreateManagedWidget("form", formWidgetClass, ui_popEdit,NULL,ZERO);
533
534 label = ui_xCreateLabelItem("msg", form, 14*ui_labelFontWidth, NULL, NULL);
535 ui_xSetLabel(label, "Edit f-type");
536 ui_xSetResize(label, TRUE);
537
538 ui_edit_ftypeNameWidget = ui_xCreateDialogItem("name", form, "",
539 25*ui_labelFontWidth,
540 label, NULL);
541
542 button = ui_xCreateButtonItem("select", form, NULL, label);
543 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_selectFunction,
544 (caddr_t) UI_EDIT_ACT_FUNC);
545
546 actLabel = ui_xCreateLabelItem("actFunc", form, 11*ui_labelFontWidth,
547 button, label);
548 ui_xSetLabel(actLabel, "act. func.:");
549
550 ui_edit_actFuncNameWidget = ui_xCreateLabelItem("actFuncName", form,
551 25*ui_labelFontWidth,
552 actLabel, label);
553 ui_xSetResize(ui_edit_actFuncNameWidget, TRUE);
554 ui_xSetLabel(ui_edit_actFuncNameWidget,"");
555
556 button = ui_xCreateButtonItem("select", form, NULL, actLabel);
557 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_selectFunction,
558 (caddr_t) UI_EDIT_OUT_FUNC);
559
560 label = ui_xCreateLabelItem("outFunc", form, 11*ui_labelFontWidth,
561 button, actLabel);
562 ui_xSetLabel(label, "out. func.:");
563
564 ui_edit_outFuncNameWidget = ui_xCreateLabelItem("outFuncName", form,
565 25*ui_labelFontWidth,
566 label, actLabel);
567 ui_xSetResize(label, TRUE);
568 ui_xSetLabel(ui_edit_outFuncNameWidget,"");
569
570 abutton =
571 ui_xCreateButtonItem("add", form, NULL, label);
572 XtAddCallback(abutton, XtNcallback, (XtCallbackProc) ui_edit_ftypeAddSite,
573 (caddr_t) listDescriptorPtr);
574
575 button =
576 ui_xCreateButtonItem("delete", form, abutton, label);
577 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_ftypeDeleteSite,
578 (struct SimpleListType *) listDescriptorPtr);
579
580 n = 0;
581 XtSetArg(args[n], XtNfromHoriz, button ); n++;
582 XtSetArg(args[n], XtNfromVert , label ); n++;
583 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
584 XtSetArg(args[n], XtNright , XtChainLeft); n++;
585 XtSetArg(args[n], XtNtop , XtChainTop ); n++;
586 XtSetArg(args[n], XtNbottom, XtChainTop ); n++;
587
588 listDescriptorPtr->listWidget =
589 XtCreateManagedWidget("list", listWidgetClass, form, args, n);
590 ui_list_buildList(listDescriptorPtr);
591 ui_xSetResize(listDescriptorPtr->listWidget, TRUE);
592 /* XtAddCallback(listDescriptorPtr->listWidget, XtNcallback,
593 ui_edit_listSetSite, UI_EDIT_FTYPE);
594 */
595
596 doneButton =
597 ui_xCreateButtonItem("done", form, NULL,
598 listDescriptorPtr->listWidget);
599 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_editPopupDone,
600 (struct SimpleListType *) listDescriptorPtr);
601
602 button =
603 ui_xCreateButtonItem("choose", form, doneButton,
604 listDescriptorPtr->listWidget);
605 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_chooseFType,
606 (struct SimpleListType *) listDescriptorPtr);
607
608 button =
609 ui_xCreateButtonItem("set", form, button,
610 listDescriptorPtr->listWidget);
611 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_setFType,
612 (struct SimpleListType *) listDescriptorPtr);
613
614 button =
615 ui_xCreateButtonItem("new", form, button,
616 listDescriptorPtr->listWidget);
617 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_newFType,
618 (struct SimpleListType *) listDescriptorPtr);
619
620 button =
621 ui_xCreateButtonItem("delete", form, button,
622 listDescriptorPtr->listWidget);
623 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_deleteFType,
624 (struct SimpleListType *) listDescriptorPtr);
625
626
627 ui_edit_displayFirstFType(listDescriptorPtr);
628
629 XawFormDoLayout(form, True);
630 ui_checkWindowPosition(ui_popEdit);
631 XtPopup(ui_popEdit, XtGrabExclusive);
632 ui_xDontResizeWidget(ui_popEdit);
633 }
634
635
636 /*****************************************************************************
637 FUNCTION : ui_editSitePopup
638
639 PURPOSE : edit popup (sites)
640 RETURNS : void
641 NOTES :
642
643 UPDATE : 27.9.1990
644 ******************************************************************************/
645
ui_editSitePopup(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call_data)646 void ui_editSitePopup (Widget w, struct SimpleListType *listDescriptorPtr,
647 caddr_t call_data)
648
649 {
650 Widget doneButton, form, actLabel, label, button, sbutton;
651 Arg args[10];
652 Position x, y;
653 Dimension width, height;
654 Cardinal n;
655 char *name, *func;
656
657 /* Upper left corner will be in the center of the calling button */
658
659 n = 0;
660 XtSetArg(args[0], XtNwidth, &width); n++;
661 XtSetArg(args[1], XtNheight, &height); n++;
662 XtGetValues(listDescriptorPtr->widgetPtr, args, n);
663 XtTranslateCoords(listDescriptorPtr->widgetPtr,
664 (Position) (width / 2), (Position) (height / 2),
665 &x, &y);
666
667 n = 0;
668 XtSetArg(args[n], XtNx, x); n++;
669 XtSetArg(args[n], XtNy, y); n++;
670
671 /* Now create Popup */
672
673 ui_popEdit =
674 XtCreatePopupShell("edit sites", transientShellWidgetClass, ui_toplevel,
675 args, n);
676
677 form = XtCreateManagedWidget("form", formWidgetClass, ui_popEdit,NULL,ZERO);
678
679 label = ui_xCreateLabelItem("msg", form, 14*ui_labelFontWidth, NULL, NULL);
680 ui_xSetResize(label, TRUE);
681 ui_xSetLabel (label, "Edit site");
682
683 ui_edit_siteNameWidget = ui_xCreateDialogItem("name", form, "",
684 25*ui_labelFontWidth,
685 label, NULL);
686
687 button = ui_xCreateButtonItem("select", form, NULL, label);
688 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_selectFunction,
689 (caddr_t) UI_EDIT_SITE_FUNC);
690
691 actLabel = ui_xCreateLabelItem("SiteFunc", form, 11*ui_labelFontWidth,
692 button, label);
693 ui_xSetLabel(actLabel, "site func.:");
694
695 ui_edit_siteFuncNameWidget = ui_xCreateLabelItem("name", form,
696 25*ui_labelFontWidth,
697 actLabel, label);
698 ui_xSetResize(ui_edit_siteFuncNameWidget, TRUE);
699
700 doneButton = ui_xCreateButtonItem("done", form, NULL, button);
701 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_editPopupDone,
702 (struct SimpleListType *) listDescriptorPtr);
703
704 sbutton = ui_xCreateButtonItem("set", form, doneButton, button);
705 XtAddCallback(sbutton, XtNcallback, (XtCallbackProc) ui_edit_setSite,
706 (struct SimpleListType *) listDescriptorPtr);
707
708 n = 0;
709 XtSetArg(args[n], XtNfromHoriz, NULL); n++;
710 XtSetArg(args[n], XtNfromVert , sbutton); n++;
711 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
712 XtSetArg(args[n], XtNright , XtChainLeft); n++;
713 XtSetArg(args[n], XtNtop , XtChainTop); n++;
714 XtSetArg(args[n], XtNbottom, XtChainTop); n++;
715
716 listDescriptorPtr->listWidget =
717 XtCreateManagedWidget("list", listWidgetClass, form, args, n);
718 ui_list_buildList(listDescriptorPtr);
719 XtAddCallback(listDescriptorPtr->listWidget, XtNcallback,
720 (XtCallbackProc) ui_edit_listSetSite, (caddr_t) UI_EDIT_SITE);
721 ui_xSetResize(listDescriptorPtr->listWidget, TRUE);
722
723 if (krui_getFirstSiteTableEntry(&name, &func))
724 XawListHighlight(listDescriptorPtr->listWidget, 1);
725 /* name is NULL, if there is no first site ! */
726 ui_edit_setCurrentSite(name);
727
728 button =
729 ui_xCreateButtonItem("new", form, listDescriptorPtr->listWidget, sbutton);
730 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_newSite,
731 (struct SimpleListType *) listDescriptorPtr);
732
733 button =
734 ui_xCreateButtonItem("delete", form, button, sbutton);
735 XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_edit_deleteSite,
736 (struct SimpleListType *) listDescriptorPtr);
737
738 if (krui_getFirstSiteTableEntry(&name, &func)) {
739 sprintf(ui_edit_siteName,"%s",name);
740 sprintf(ui_edit_siteFuncName,"%s",func);
741 ui_xSetLabel(ui_edit_siteFuncNameWidget, ui_edit_siteFuncName);
742 ui_xSetString(ui_edit_siteNameWidget, ui_edit_siteName);
743 }
744
745 ui_checkWindowPosition(ui_popEdit);
746 XtPopup(ui_popEdit, XtGrabExclusive);
747 ui_xDontResizeWidget(ui_popEdit);
748 }
749
750
751 /*****************************************************************************
752 FUNCTION : ui_listPopup
753
754 PURPOSE : popup a list panel
755 RETURNS : void
756 NOTES :
757
758 UPDATE : 27.8.1990
759 ******************************************************************************/
760
ui_listPopup(struct SimpleListType * listDescriptorPtr,Position x,Position y)761 void ui_listPopup (struct SimpleListType *listDescriptorPtr, Position x,
762 Position y)
763
764 {
765 Widget doneButton, form, label;
766 char buf[80], title[80];
767 Arg args[6];
768 Cardinal n;
769 XEvent event;
770
771 /* Upper left corner will be in the center of the calling button */
772
773 n = 0;
774 XtSetArg(args[n], XtNx, x); n++;
775 XtSetArg(args[n], XtNy, y); n++;
776
777 /* Now create Popup */
778
779 sprintf (title, listDescriptorPtr->msg);
780 title[0] = tolower(title[0]);
781 ui_popList =
782 XtCreatePopupShell(title, transientShellWidgetClass, ui_toplevel,
783 args, n);
784
785 form =
786 XtCreateManagedWidget("form", formWidgetClass, ui_popList,
787 NULL, ZERO);
788
789 label = ui_xCreateLabelItem("msg", form, 80*ui_labelFontWidth, NULL, NULL);
790 ui_xSetResize(label, TRUE);
791 ui_xSetLabel(label, listDescriptorPtr->msg);
792
793 if ((listDescriptorPtr->unitPtr != NULL) AND
794 (listDescriptorPtr->unitPtr->no != ZERO)) {
795 label =
796 ui_xCreateLabelItem("msg", form, 80*ui_labelFontWidth, NULL, label);
797 ui_xSetResize(label, TRUE);
798 sprintf(buf,"unit #%d - %s",
799 listDescriptorPtr->unitPtr->no,
800 listDescriptorPtr->unitPtr->name);
801 ui_xSetLabel(label, buf);
802 }
803
804 n = 0;
805 XtSetArg(args[n], XtNfromHoriz, NULL); n++;
806 XtSetArg(args[n], XtNfromVert , label); n++;
807 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
808 XtSetArg(args[n], XtNright , XtChainLeft); n++;
809 XtSetArg(args[n], XtNtop , XtChainTop); n++;
810 XtSetArg(args[n], XtNbottom, XtChainTop); n++;
811
812 listDescriptorPtr->listWidget =
813 XtCreateManagedWidget("list", listWidgetClass, form, args, n);
814 ui_list_buildList(listDescriptorPtr);
815 XtAddCallback(listDescriptorPtr->listWidget, XtNcallback,
816 (XtCallbackProc) ui_list_setUnitValue,
817 (struct SimpleListType *) listDescriptorPtr);
818 ui_list_returnIndex = XAW_LIST_NONE;
819
820 if ((listDescriptorPtr->unitPtr != NULL) AND
821 (listDescriptorPtr->unitPtr->no != ZERO)) {
822 if( listDescriptorPtr->unitPtr->no == ui_sourceUnit.no){
823 if(listDescriptorPtr->listType == UI_LIST_ACT_FUNC){
824 XtAddCallback(listDescriptorPtr->listWidget, XtNcallback,
825 (XtCallbackProc) ui_drawFunction,"Source Act");
826 }else if(listDescriptorPtr->listType == UI_LIST_OUT_FUNC){
827 XtAddCallback(listDescriptorPtr->listWidget, XtNcallback,
828 (XtCallbackProc) ui_drawFunction,"Source Out");
829 }
830 }else {
831 if(listDescriptorPtr->listType == UI_LIST_ACT_FUNC){
832 XtAddCallback(listDescriptorPtr->listWidget, XtNcallback,
833 (XtCallbackProc) ui_drawFunction,"Target Act");
834 }else if(listDescriptorPtr->listType == UI_LIST_OUT_FUNC){
835 XtAddCallback(listDescriptorPtr->listWidget, XtNcallback,
836 (XtCallbackProc) ui_drawFunction,"Target Out");
837 }
838 }
839 }
840
841 doneButton =
842 ui_xCreateButtonItem("done", form, NULL, listDescriptorPtr->listWidget);
843 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_listPopupDone,
844 (struct SimpleListType *) listDescriptorPtr);
845
846 ui_checkWindowPosition(ui_popList);
847 XtPopup(ui_popList, XtGrabExclusive);
848 ui_xDontResizeWidget(ui_popList);
849
850 ui_pop_exit = FALSE;
851 while (NOT ui_pop_exit) { /* exit after pressing the DONE button */
852 XtAppNextEvent(ui_appContext, &event);
853 (void) XtDispatchEvent(&event);
854 }
855 }
856
857
858 /*****************************************************************************
859 FUNCTION : ui_popupSetup
860
861 PURPOSE : popup a setup panel
862 RETURNS : void
863 NOTES :
864
865 UPDATE : 27.5.1990
866 ******************************************************************************/
867
ui_popupSetup(Widget button,struct Ui_DisplayType * displayPtr,caddr_t call_data)868 static void ui_popupSetup (Widget button, struct Ui_DisplayType *displayPtr,
869 caddr_t call_data)
870
871 {
872 Widget doneButton;
873 Arg args[5];
874 Position x, y;
875 Dimension width, height;
876 Cardinal n;
877
878 /* Upper left corner will be in the center of the calling button */
879
880 if (NOT ui_setupIsCreated) {
881
882 n = 0;
883 XtSetArg(args[0], XtNwidth, &width); n++;
884 XtSetArg(args[1], XtNheight, &height); n++;
885 XtGetValues(button, args, n);
886 XtTranslateCoords(button, (Position) (width / 2),
887 (Position) (height / 2),
888 &x, &y);
889
890 n = 0;
891 XtSetArg(args[n], XtNx, x); n++;
892 XtSetArg(args[n], XtNy, y); n++;
893
894 /* Now create Popup */
895
896 ui_popSetup =
897 XtCreatePopupShell("setup", transientShellWidgetClass,
898 ui_toplevel, args, n);
899
900 ui_setupBox =
901 XtCreateManagedWidget("form", formWidgetClass, ui_popSetup,
902 NULL, ZERO);
903
904 ui_xCreateSetupPanel(ui_setupBox, displayPtr);
905
906 doneButton =
907 ui_xCreateButtonItem("done", ui_setupBox, NULL, ui_setupPanel);
908 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_popupDone,
909 (caddr_t) UI_POPUP_SETUP);
910
911 ui_setupSliderMessage =
912 ui_xCreateLabelItem("", ui_setupBox, 30*ui_labelFontWidth,
913 doneButton, ui_setupPanel);
914 ui_checkWindowPosition(ui_popSetup);
915 XtPopup(ui_popSetup, XtGrabExclusive);
916 ui_xDontResizeWidget(ui_popSetup);
917 }
918 }
919
920
921
922 /*****************************************************************************
923 FUNCTION : ui_displayFilePanel
924
925 PURPOSE : popup the file panel
926 RETURNS : void
927 NOTES :
928
929 UPDATE : 22.5.1990
930 ******************************************************************************/
931
ui_displayFilePanel(Widget w,Widget button,caddr_t call_data)932 void ui_displayFilePanel (Widget w, Widget button, caddr_t call_data)
933
934 {
935 Widget doneButton;
936 Arg args[5];
937 Position x, y;
938 Dimension width, height;
939 Cardinal n;
940
941 if (ui_filePannelPoppedUp){
942 XRaiseWindow (XtDisplay (ui_popFile), XtWindow (ui_popFile));
943 return;
944 }
945 ui_filePannelPoppedUp = TRUE;
946
947 /* Upper left corner will be in the center of the calling button */
948 n = 0;
949 XtSetArg(args[0], XtNwidth, &width); n++;
950 XtSetArg(args[1], XtNheight, &height); n++;
951 XtGetValues(button, args, n);
952
953 XtTranslateCoords(button, (Position) 0, (Position) (height),
954 &x, &y);
955
956 n = 0;
957 XtSetArg(args[n], XtNx, x); n++;
958 XtSetArg(args[n], XtNy, y); n++;
959
960 /* Now create Popup */
961 ui_popFile = XtCreatePopupShell("SNNS file browser",
962 transientShellWidgetClass, button, args, n);
963 ui_fileBox = XtCreateManagedWidget("box", boxWidgetClass, ui_popFile,
964 NULL, ZERO);
965 ui_xCreateFilePanel(ui_fileBox);
966
967 doneButton = ui_xCreateButtonItem("done", ui_fileBox, NULL, ui_filePanel);
968 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_popupDone,
969 (caddr_t) UI_POPUP_FILE);
970
971 ui_fileIsCreated = TRUE;
972 ui_checkWindowPosition(ui_popFile);
973 XtPopup(ui_popFile, XtGrabNone);
974 XtAddEventHandler(ui_fileBox,KeyPressMask,FALSE,
975 (XtEventHandler)ui_key_control,(Cardinal *) 0);
976 }
977
978
979 /*****************************************************************************
980 FUNCTION : ui_displayLayerPanel
981
982 PURPOSE : popup the layer panel
983 RETURNS : void
984 NOTES :
985
986 UPDATE : 22.5.1990
987 ******************************************************************************/
988
ui_displayLayerPanel(Position x,Position y)989 void ui_displayLayerPanel (Position x, Position y)
990
991 {
992 Widget doneButton, layerBox;
993 Arg args[5];
994 Cardinal n;
995 XEvent event;
996
997 /* Upper left corner will be in the center of the calling button */
998
999 n = 0;
1000 XtSetArg(args[n], XtNx, x); n++;
1001 XtSetArg(args[n], XtNy, y); n++;
1002 ui_popLayer = XtCreatePopupShell("layers", transientShellWidgetClass,
1003 ui_toplevel, args, n);
1004 layerBox = XtCreateManagedWidget("box", boxWidgetClass, ui_popLayer,
1005 NULL, ZERO);
1006 ui_xCreateLayerPanel(layerBox);
1007
1008 doneButton = ui_xCreateButtonItem("done", layerBox, NULL, NULL);
1009 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_popupDone,
1010 (caddr_t) UI_POPUP_LAYER);
1011
1012 ui_checkWindowPosition(ui_popLayer);
1013 XtAddEventHandler(ui_popLayer,KeyPressMask,FALSE,
1014 (XtEventHandler)ui_key_control,(Cardinal *) 0);
1015 XtPopup(ui_popLayer, XtGrabExclusive);
1016 ui_xDontResizeWidget(ui_popLayer);
1017
1018 ui_pop_exit = FALSE;
1019 while (NOT ui_pop_exit) { /* exit after pressing the DONE button */
1020 XtAppNextEvent(ui_appContext, &event);
1021 (void) XtDispatchEvent(&event);
1022 }
1023 }
1024
1025
1026 /*****************************************************************************
1027 FUNCTION : ui_refresh
1028
1029 PURPOSE : Refresh of a network graphic window case of an expose event
1030 RETURNS : void
1031 NOTES :
1032
1033 UPDATE : 15.5.1990
1034 ******************************************************************************/
ui_refresh(Widget w,struct Ui_DisplayType * displayPtr,XEvent * event)1035 static void ui_refresh (Widget w, struct Ui_DisplayType *displayPtr,
1036 XEvent *event)
1037
1038 {
1039 switch ((*event).type) {
1040 case Expose:
1041 if (event->xexpose.count == 0) {
1042
1043 ui_xGetDimensions(displayPtr->widget,
1044 &(displayPtr->width),
1045 &(displayPtr->height));
1046
1047 displayPtr->unitsInX =
1048 displayPtr->width / displayPtr->gridSize;
1049 displayPtr->unitsInY =
1050 displayPtr->height / displayPtr->gridSize;
1051 ui_net_completeRefresh(displayPtr, UI_LOCAL);
1052 }
1053 break;
1054 case ConfigureNotify:
1055 ui_xGetDimensions(displayPtr->widget,
1056 &(displayPtr->width),
1057 &(displayPtr->height));
1058 displayPtr->unitsInX =
1059 displayPtr->width / displayPtr->gridSize;
1060 displayPtr->unitsInY =
1061 displayPtr->height / displayPtr->gridSize;
1062 break;
1063 }
1064 }
1065
1066
1067 /*****************************************************************************
1068 FUNCTION : ui_displayGraphic
1069
1070 PURPOSE : display a graphic window
1071 RETURNS : void
1072 NOTES :
1073
1074 UPDATE : 1.4.1990
1075 ******************************************************************************/
ui_displayGraphic(Widget button,struct Ui_DisplayType * displPtr,caddr_t call_data)1076 void ui_displayGraphic (Widget button, struct Ui_DisplayType *displPtr,
1077 caddr_t call_data)
1078
1079 {
1080 Widget fbutton;
1081 Arg args[10];
1082 Cardinal n;
1083 char buf[40];
1084 XtTranslations trans;
1085
1086 struct Ui_DisplayType *displayPtr;
1087
1088 if (displPtr == NULL) {
1089 /* call from the GUI menue */
1090 if ((displayPtr = ui_displ_getFreeItem()) == NULL) {
1091 ui_confirmOk("No more memory for displays available!");
1092 return;
1093 }
1094 } else
1095 /* call from ui_cfg_load() */
1096 displayPtr = displPtr;
1097
1098 sprintf(buf,"SNNS display %d - subnet: %d",
1099 displayPtr->displayNo, displayPtr->subNetNo);
1100
1101 n = 0;
1102 ui_popCanvas = XtCreatePopupShell(buf, topLevelShellWidgetClass,
1103 ui_toplevel, args, n);
1104
1105 /* now create the display structure to held data */
1106 displayPtr->frameWidget = XtCreateManagedWidget("form", formWidgetClass,
1107 ui_popCanvas, NULL, ZERO);
1108
1109 fbutton = ui_xCreateButtonItem("done", displayPtr->frameWidget, NULL, NULL);
1110 XtAddCallback(fbutton, XtNcallback, (XtCallbackProc) ui_displayDone,
1111 (struct Ui_DisplayType *) displayPtr);
1112
1113 fbutton = ui_xCreateButtonItem("setup", displayPtr->frameWidget, fbutton,
1114 NULL);
1115 XtAddCallback(fbutton, XtNcallback, (XtCallbackProc) ui_popupSetup,
1116 (struct Ui_DisplayType *) displayPtr);
1117
1118 fbutton = ui_xCreateToggleItem("freeze", displayPtr->frameWidget, NULL,
1119 fbutton, NULL);
1120 ui_xSetToggleState(fbutton, displayPtr->frozen);
1121 XtAddCallback(fbutton, XtNcallback, (XtCallbackProc) ui_displ_freezeDisplay,
1122 (struct Ui_DisplayType *) displayPtr);
1123
1124 n = 0;
1125 XtSetArg(args[n], XtNwidth, displayPtr->width); n++;
1126 XtSetArg(args[n], XtNheight, displayPtr->height); n++;
1127 XtSetArg(args[n], XtNfromVert, fbutton); n++;
1128 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
1129 XtSetArg(args[n], XtNright , XtChainRight); n++;
1130 XtSetArg(args[n], XtNtop , XtChainTop); n++;
1131 XtSetArg(args[n], XtNbottom, XtChainBottom); n++;
1132 displayPtr->widget = XtCreateManagedWidget("display", boxWidgetClass,
1133 displayPtr->frameWidget, args,n);
1134 trans = XtParseTranslationTable("Ctrl<Btn1Down>: XawPositionSimpleMenu(popmenu) MenuPopup(popmenu)");
1135
1136 XtAugmentTranslations(displayPtr->widget, trans);
1137
1138
1139 XtAddEventHandler(displayPtr->widget, ExposureMask, GraphicsExpose,
1140 (XtEventHandler) ui_refresh,
1141 (struct Ui_DisplayType *) displayPtr);
1142 XtAddEventHandler(ui_popCanvas,
1143 StructureNotifyMask | SubstructureNotifyMask, FALSE,
1144 (XtEventHandler) ui_refresh,
1145 (struct Ui_DisplayType *) displayPtr);
1146 XtAddEventHandler(displayPtr->widget,
1147 ButtonPressMask | ButtonMotionMask | ButtonReleaseMask
1148 | EnterWindowMask | LeaveWindowMask,
1149 FALSE, (XtEventHandler) ui_mw_eventProc,
1150 (struct Ui_DisplayType *) displayPtr);
1151 XtAddEventHandler(displayPtr->widget,
1152 KeyPressMask, FALSE, (XtEventHandler) ui_can_KEventProc,
1153 (struct Ui_DisplayType *) displayPtr);
1154 XtAddEventHandler(ui_popCanvas, StructureNotifyMask,
1155 FALSE, (XtEventHandler) ui_can_MapEventProc,
1156 (struct Ui_DisplayType *) displayPtr);
1157
1158 ui_checkWindowPosition(ui_popCanvas);
1159 XtPopup(ui_popCanvas, XtGrabNone);
1160
1161 displayPtr->drawable = XtWindow(displayPtr->widget);
1162
1163 ui_xToggleBackingStore(TRUE, ui_display, displayPtr->drawable);
1164
1165 XSelectInput(ui_display, displayPtr->drawable,
1166 ExposureMask | PointerMotionMask |
1167 ButtonPressMask | ButtonMotionMask | ButtonReleaseMask |
1168 KeyPressMask | EnterWindowMask | LeaveWindowMask);
1169
1170 XGrabButton(ui_display, AnyButton, AnyModifier, displayPtr->drawable, TRUE,
1171 ButtonPressMask | ButtonMotionMask | ButtonReleaseMask,
1172 GrabModeAsync, GrabModeAsync, None,
1173 XCreateFontCursor(ui_display, XC_crosshair));
1174 }
1175
1176
1177 /*****************************************************************************
1178 FUNCTION : ui_textLook
1179
1180 PURPOSE : callback. Called when clicked on the LOOK button
1181 RETURNS : void
1182 NOTES :
1183
1184 UPDATE : 1.5.1990
1185 ******************************************************************************/
ui_textLook(Widget widget,XtPointer client_data,XtPointer call_data)1186 static void ui_textLook (Widget widget, XtPointer client_data,
1187 XtPointer call_data)
1188
1189 {
1190 Widget w, src;
1191 XawTextBlock textBlock;
1192 XawTextPosition start, end, found; /* int ! */
1193 char sWord[SEARCH_WORD_MAXLEN+1];
1194 Cardinal n;
1195 Arg args[5];
1196
1197 w = (Widget) client_data;
1198
1199 XawTextGetSelectionPos(w, &start, &end);
1200
1201 if (start != end) {
1202 if ((end-start+1) > SEARCH_WORD_MAXLEN)
1203 end = start + SEARCH_WORD_MAXLEN;
1204
1205 n = 0;
1206 XtSetArg(args[n], XtNtextSource, &src); n++;
1207 XtGetValues(w, args, n);
1208
1209 found = XawTextSourceRead(src, (int)start, &textBlock,(int)(end-start));
1210
1211 textBlock.firstPos = 0;
1212 textBlock.length = end - start;
1213 textBlock.format = FMT8BIT;
1214
1215
1216 XawTextSetInsertionPoint(w, 0);
1217 found = XawTextSearch(w, XawsdRight, &textBlock);
1218 if (found > 0) {
1219 strncpy(sWord, textBlock.ptr, (unsigned int) (end - start));
1220 sWord[end-start] = '\0';
1221 #ifdef DEBUG
1222 sprintf(buf, "Found: <%s>", sWord);
1223 ui_printMessage(buf);
1224 #endif
1225 XawTextSetInsertionPoint(w, (int) (ui_lengthOfHelp));
1226 XawTextSetInsertionPoint(w, (int) (found + textBlock.length));
1227 XawTextSetSelection(w, (int) found,
1228 (int) (found + textBlock.length));
1229 XawTextInvalidate(w, (int) found,
1230 (int) (found + textBlock.length));
1231 }
1232 }
1233 }
1234
1235
1236 /*****************************************************************************
1237 FUNCTION : ui_textMore
1238
1239 PURPOSE : callback. Called when clicked on the MORE button
1240 RETURNS : void
1241 NOTES :
1242
1243 UPDATE : 1.5.1990
1244 ******************************************************************************/
ui_textMore(Widget widget,XtPointer client_data,XtPointer call_data)1245 static void ui_textMore (Widget widget, XtPointer client_data,
1246 XtPointer call_data)
1247
1248 {
1249 Widget w, src;
1250 XawTextBlock textBlock;
1251 XawTextPosition start, end, found; /* int ! */
1252 char sWord[SEARCH_WORD_MAXLEN+1];
1253 Cardinal n;
1254 Arg args[5];
1255
1256 w = (Widget) client_data;
1257
1258 XawTextGetSelectionPos(w, &start, &end);
1259
1260 if (start != end) {
1261 if ((end-start+1) > SEARCH_WORD_MAXLEN)
1262 end = start + SEARCH_WORD_MAXLEN;
1263
1264 n = 0;
1265 XtSetArg(args[n], XtNtextSource, &src); n++;
1266 XtGetValues(w, args, n);
1267
1268 found = XawTextSourceRead(src, (int) start, &textBlock,
1269 (int) (end-start));
1270
1271 textBlock.firstPos = 0;
1272 textBlock.length = end - start;
1273 textBlock.format = FMT8BIT;
1274
1275 /* XawTextSetInsertionPoint(w, 0); */
1276 found = XawTextSearch(w, XawsdRight, &textBlock);
1277 if (found > 0) {
1278 strncpy(sWord, textBlock.ptr, (unsigned int) (end - start));
1279 sWord[end-start] = '\0';
1280 #ifdef DEBUG
1281 sprintf(buf, "Found: <%s>", sWord);
1282 ui_printMessage(buf);
1283 #endif
1284 XawTextSetInsertionPoint(w, (int) (ui_lengthOfHelp));
1285 XawTextSetInsertionPoint(w, (int) (found + textBlock.length));
1286 XawTextSetSelection(w, (int) found,
1287 (int) (found + textBlock.length));
1288
1289 XawTextInvalidate(w, (int) found,
1290 (int) (found + textBlock.length));
1291 }
1292 }
1293 }
1294
1295
1296 /*****************************************************************************
1297 FUNCTION : ui_textKey
1298
1299 PURPOSE : searches in the specified ascii widget for a key string
1300 RETURNS : void
1301 NOTES :
1302
1303 UPDATE : 1.5.1990
1304 ******************************************************************************/
ui_textKey(Widget w,char * key)1305 static void ui_textKey (Widget w, char *key)
1306
1307 {
1308 XawTextBlock textBlock;
1309 XawTextPosition found; /* int ! */
1310
1311 if (strlen(key) < 1) return;
1312
1313 textBlock.ptr = key;
1314 textBlock.firstPos = 0;
1315 textBlock.length = strlen(key);
1316 textBlock.format = FMT8BIT;
1317
1318 XawTextSetInsertionPoint(w, 0);
1319 found = XawTextSearch(w, XawsdRight, &textBlock);
1320 if (found > 0) {
1321 #ifdef DEBUG
1322 sprintf(buf, "Found: <%s>", key);
1323 ui_printMessage(buf);
1324 #endif
1325 XawTextSetInsertionPoint(w, (int) (ui_lengthOfHelp));
1326 XawTextSetInsertionPoint(w, (int) (found + textBlock.length));
1327 XawTextSetSelection(w, (int) found,
1328 (int) (found + textBlock.length));
1329 XawTextInvalidate(w, (int) found,
1330 (int) (found + textBlock.length));
1331 }
1332 }
1333
1334
1335 /*****************************************************************************
1336 FUNCTION : ui_textTopics
1337
1338 PURPOSE : callback. Called when clicked on the TOPICS button
1339 RETURNS : void
1340 NOTES :
1341
1342 UPDATE : 1.5.1990
1343 ******************************************************************************/
ui_textTopics(Widget widget,Widget client_data,caddr_t call_data)1344 static void ui_textTopics (Widget widget, Widget client_data, caddr_t call_data)
1345
1346 {
1347 ui_textKey(client_data, "* TOPICS");
1348 }
1349
1350
1351 /*****************************************************************************
1352 FUNCTION : ui_displayControl
1353
1354 PURPOSE : display control-panel
1355 RETURNS : void
1356 NOTES :
1357
1358 UPDATE : 26.9.1990
1359 ******************************************************************************/
ui_displayControl(Widget w,caddr_t client_data,caddr_t call_data)1360 void ui_displayControl (Widget w, caddr_t client_data, caddr_t call_data)
1361
1362 {
1363 Widget doneButton, form;
1364
1365 if (ui_controlIsCreated) {
1366 XRaiseWindow (XtDisplay (ui_popControl), XtWindow (ui_popControl));
1367 return;
1368 }
1369
1370 ui_popControl = XtCreatePopupShell("SNNS control", topLevelShellWidgetClass,
1371 ui_toplevel, NULL, ZERO);
1372
1373 form = XtCreateManagedWidget("form", formWidgetClass, ui_popControl,
1374 NULL, ZERO);
1375
1376 ui_xCreateControlPanel(form);
1377
1378 doneButton = ui_xCreateButtonItem("done", form, NULL, ui_controlPanel);
1379 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_popupDone,
1380 (caddr_t) UI_POPUP_CONTROL);
1381
1382 ui_controlMessageWidget = ui_xCreateLabelItem("message",form,
1383 10*ui_labelFontWidth,
1384 doneButton, ui_controlPanel);
1385 ui_xSetResize(ui_controlMessageWidget, TRUE);
1386 ui_xSetLabel(ui_controlMessageWidget, "");
1387
1388 XtAddEventHandler(form,KeyPressMask,FALSE,
1389 (XtEventHandler)ui_key_control,(Cardinal *) 0);
1390 XawFormDoLayout(form, True);
1391 ui_checkWindowPosition(ui_popControl);
1392 XtPopup(ui_popControl, XtGrabNone);
1393 ui_xDontResizeWidget(ui_popControl);
1394 ui_file_updateShellLabels();
1395 }
1396
1397
1398 /*****************************************************************************
1399 FUNCTION : ui_displayInfo
1400
1401 PURPOSE : display control-panel
1402 RETURNS : void
1403 NOTES :
1404
1405 UPDATE : 26.9.1990
1406 ******************************************************************************/
ui_displayInfo(Widget w,caddr_t client_data,caddr_t call_data)1407 void ui_displayInfo (Widget w, caddr_t client_data, caddr_t call_data)
1408
1409 {
1410 Widget doneButton, form;
1411
1412 if (ui_infoIsCreated) {
1413 XRaiseWindow (XtDisplay (ui_popInfo), XtWindow (ui_popInfo));
1414 return;
1415 }
1416
1417 ui_popInfo = XtCreatePopupShell("SNNS info", topLevelShellWidgetClass,
1418 ui_toplevel, NULL, ZERO);
1419
1420 form = XtCreateManagedWidget("form", formWidgetClass, ui_popInfo,
1421 NULL, ZERO);
1422
1423 ui_xCreateInfoPanel(form);
1424
1425 doneButton = ui_xCreateButtonItem("done", form, NULL, ui_infoPanel);
1426 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_popupDone,
1427 (caddr_t) UI_POPUP_INFO);
1428
1429
1430 XtAddEventHandler(form,KeyPressMask,FALSE,
1431 (XtEventHandler)ui_key_control,(Cardinal *) 0);
1432 XawFormDoLayout(form, True);
1433 ui_checkWindowPosition(ui_popInfo);
1434 XtPopup(ui_popInfo, XtGrabNone);
1435 ui_xDontResizeWidget(ui_popInfo);
1436 ui_file_updateShellLabels();
1437 }
1438
1439
1440 /*****************************************************************************
1441 FUNCTION : ui_displayText
1442
1443 PURPOSE : display a help window
1444 RETURNS : void
1445 NOTES : returns false if no help.hdoc found
1446
1447 UPDATE : 1.5.1990
1448 ******************************************************************************/
ui_displayText(Widget button,caddr_t client_data,caddr_t call_data)1449 void ui_displayText (Widget button, caddr_t client_data, caddr_t call_data)
1450
1451 {
1452 Widget doneButton, lookButton, moreButton, topicsButton, form;
1453 Arg args[12];
1454 Cardinal n;
1455 char buf[20];
1456 char hdoc[MAX_NAME_LENGTH];
1457 struct stat *help_size_buf;
1458
1459 struct HelpType *listPtr;
1460
1461 sprintf(hdoc, "help.hdoc");
1462 if (NOT ui_fileExist(hdoc,0)) {
1463 if (getenv("XGUILOADPATH") != NULL)
1464 sprintf(hdoc, "%s/help.hdoc", getenv("XGUILOADPATH"));
1465 if (NOT ui_fileExist(hdoc,0)) {
1466 ui_confirmOk("Can't display help. <help.hdoc> not found.");
1467 ui_helpOk = FALSE;
1468 return;
1469 }
1470 }
1471
1472 /* getting the length of the helpfile */
1473 help_size_buf = (struct stat *) malloc(sizeof(struct stat));
1474 if (help_size_buf == NULL) {
1475 ui_confirmOk("No memory available to display a new help window!");
1476 ui_helpOk = FALSE;
1477 return;
1478 }
1479 stat (hdoc, help_size_buf);
1480 ui_lengthOfHelp = help_size_buf->st_size;
1481 free (help_size_buf);
1482
1483 /* first get a free help item */
1484 if (ui_help_freeListPtr == NULL) { /* no free item */
1485 listPtr = (struct HelpType *) (malloc(sizeof(struct HelpType)));
1486 if (listPtr == NULL) {
1487 ui_confirmOk("No memory available to display a new help window!");
1488 ui_helpOk = FALSE;
1489 return;
1490 }
1491 listPtr->no = ++ui_noOfHelpsUp;
1492 } else {
1493 listPtr = ui_help_freeListPtr;
1494 ui_help_freeListPtr = listPtr->nextPtr;
1495 }
1496 /* link it in normal list */
1497 listPtr->nextPtr = ui_help_listPtr;
1498 ui_help_listPtr = listPtr;
1499
1500 sprintf(buf,"SNNS help %d",listPtr->no);
1501 listPtr->shellWidget = XtCreatePopupShell(buf, topLevelShellWidgetClass,
1502 ui_toplevel,
1503 NULL, ZERO);
1504
1505 form = XtCreateManagedWidget("form", formWidgetClass, listPtr->shellWidget,
1506 NULL, ZERO);
1507
1508 doneButton = ui_xCreateButtonItem("done", form, NULL, NULL);
1509 XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_helpDone,
1510 (struct HelpType *) listPtr);
1511
1512 lookButton = ui_xCreateButtonItem("look", form, doneButton, NULL);
1513
1514 moreButton = ui_xCreateButtonItem("more", form, lookButton, NULL);
1515
1516 topicsButton = ui_xCreateButtonItem("topics", form, moreButton, NULL);
1517
1518 n = 0;
1519 XtSetArg(args[n], XtNwidth, 575); n++;
1520 XtSetArg(args[n], XtNheight, 400); n++;
1521 XtSetArg(args[n], XtNtype, XawAsciiFile); n++;
1522 XtSetArg(args[n], XtNstring, hdoc); n++;
1523 XtSetArg(args[n], XtNscrollVertical, XawtextScrollAlways); n++;
1524 XtSetArg(args[n], XtNfromVert , doneButton); n++;
1525 XtSetArg(args[n], XtNfromHoriz, NULL); n++;
1526 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
1527 XtSetArg(args[n], XtNright , XtChainLeft); n++;
1528 XtSetArg(args[n], XtNtop , XtChainTop); n++;
1529 XtSetArg(args[n], XtNbottom, XtChainTop); n++;
1530 listPtr->textWidget = XtCreateManagedWidget("textWin", asciiTextWidgetClass,
1531 form, args, n);
1532
1533 XtAddCallback(lookButton, XtNcallback, ui_textLook,
1534 (XtPointer) listPtr->textWidget);
1535 XtAddCallback(moreButton, XtNcallback, ui_textMore,
1536 (XtPointer) listPtr->textWidget);
1537 XtAddCallback(topicsButton, XtNcallback, (XtCallbackProc) ui_textTopics,
1538 (XtPointer) listPtr->textWidget);
1539
1540 XtAddEventHandler(form,KeyPressMask,FALSE,
1541 (XtEventHandler)ui_key_control,(Cardinal *) 0);
1542 XawFormDoLayout(form, True);
1543 ui_checkWindowPosition(listPtr->shellWidget);
1544 XtPopup(listPtr->shellWidget, XtGrabNone);
1545 ui_xDontResizeWidget(listPtr->shellWidget);
1546 ui_helpOk = TRUE;
1547 }
1548
1549
1550 /*****************************************************************************
1551 FUNCTION : ui_displayHelp
1552
1553 PURPOSE : show a help window and the first position where the key string
1554 was found
1555 RETURNS : void
1556 NOTES :
1557
1558 UPDATE : 1.2.1990
1559 ******************************************************************************/
ui_displayHelp(char * key)1560 void ui_displayHelp (char *key)
1561
1562 {
1563 if (ui_help_listPtr != NULL) {
1564 /* there are help windows opened */
1565 /* get one, which is not iconified */
1566 /* struct HelpType *listPtr;
1567 listOtr = ui_help_listPtr;
1568 while ((listPtr != NULL) AND listPtr->unmapped)
1569 listPtr = listPtr->nextPtr;
1570 if (listPtr == NULL) {
1571 } else
1572 */
1573 XMapRaised(ui_display, XtWindow(ui_help_listPtr->shellWidget));
1574 ui_textKey(ui_help_listPtr->textWidget, key);
1575 } else {
1576 ui_displayText(NULL, NULL, NULL); /* popup a window */
1577 if (ui_helpOk)
1578 ui_textKey(ui_help_listPtr->textWidget, key);
1579 }
1580 }
1581
1582
1583 /*****************************************************************************
1584 FUNCTION : ui_guiQuit()
1585
1586 PURPOSE : leave XGUI
1587 RETRURNS : void
1588 NOTES : erases all temp files
1589
1590 UPDATE : 15.5.1992
1591 ******************************************************************************/
ui_guiQuit(Widget widget,XtPointer client_data,XtPointer call_data)1592 void ui_guiQuit (Widget widget, XtPointer client_data, XtPointer call_data)
1593
1594 {
1595 char cmdLine[200];
1596
1597 if (ui_confirmYes("Do you really want to quit?")) {
1598 krui_deleteNet();
1599 sprintf(cmdLine,"/bin/rm -f %s/%s* > /dev/null", ui_tmpDir, ui_praefix);
1600 system (cmdLine);
1601
1602 /* free all memory used by the kernel */
1603 XtDestroyApplicationContext(XtWidgetToApplicationContext(widget));
1604
1605 #ifdef PARAGON_KERNEL
1606 krip_TermApp();
1607 #endif
1608 exit(0);
1609 }
1610 }
1611
1612
1613 /*****************************************************************************
1614 FUNCTION : ui_guiDoQuit()
1615
1616 PURPOSE : leave XGUI
1617 RETRURNS : void
1618 NOTES : erases all temp files
1619
1620 UPDATE : 09.01.1995
1621 ******************************************************************************/
ui_guiDoQuit(Widget widget,XtPointer client_data,XtPointer call_data)1622 void ui_guiDoQuit (Widget widget, XtPointer client_data, XtPointer call_data)
1623
1624 {
1625 char cmdLine[200];
1626
1627 krui_deleteNet();
1628 sprintf(cmdLine,"/bin/rm -f %s/%s* > /dev/null", ui_tmpDir, ui_praefix);
1629 system (cmdLine);
1630
1631 /* free all memory used by the kernel */
1632 XtDestroyApplicationContext(XtWidgetToApplicationContext(widget));
1633
1634 #ifdef PARAGON_KERNEL
1635 krip_TermApp();
1636 #endif
1637 exit(0);
1638 }
1639
1640
1641
1642 /*****************************************************************************
1643 FUNCTION : ui_loadFileFromCommandLine
1644
1645 PURPOSE : load files from command line
1646 RETURNS : void
1647 NOTES : load default if no cfg specified
1648
1649 UPDATE : 15.6.1992
1650 ******************************************************************************/
ui_loadFileFromCommandLine(void)1651 void ui_loadFileFromCommandLine (void)
1652 {
1653 int cfg_loaded;
1654
1655 if (ui_loadNetbyInit)
1656 cfg_loaded = ui_file_loadNet((Widget) ZERO, (XtPointer) NULL,
1657 (caddr_t) NULL);
1658 if (ui_loadPatbyInit)
1659 ui_file_loadPatterns((Widget) ZERO, (XtPointer) NULL, (caddr_t) NULL);
1660
1661 if(cfg_loaded)
1662 return;
1663
1664 if (ui_loadCfgbyInit)
1665 ui_file_loadConfiguration((Widget) ZERO, (XtPointer)NULL, (caddr_t)NULL);
1666 else
1667 ui_file_loadDefaultConfiguration(ui_pathname);
1668 }
1669
1670
1671 /*****************************************************************************
1672 FUNCTION : ui_chkFileName
1673
1674 PURPOSE : check extention for a given filename
1675 RETURNS : int
1676 NOTES :
1677
1678 UPDATE : 15.6.1992
1679 ******************************************************************************/
ui_chkFileName(char * s1,char * s2)1680 static int ui_chkFileName (char *s1, char *s2)
1681
1682 {
1683 return (!strcmp(s1+strlen(s1)-4, s2));
1684 }
1685
1686
1687 /*****************************************************************************
1688 FUNCTION : ui_showHelpMsg
1689
1690 PURPOSE : displays a help message
1691 RETURNS : void
1692 NOTES :
1693
1694 UPDATE : 15.6.1992
1695 ******************************************************************************/
ui_showHelpMsg(char * call)1696 static void ui_showHelpMsg (char *call)
1697
1698 {
1699 fprintf(stderr, "\n\n Stuttgart Neural Network Simulator V4.2\n\n");
1700 fprintf(stderr,
1701 " usage %s [netfile] [patternfile] [configuration] [options]\n\n",
1702 call);
1703 fprintf(stderr,
1704 " where options are -font <name> font for the simulator\n");
1705 fprintf(stderr,
1706 " -dfont <name> font for the displays\n");
1707 fprintf(stderr,
1708 " -mono black & white on color screens \n");
1709 fprintf(stderr, " -help this help\n");
1710 fprintf(stderr, "\n\n");
1711 }
1712
1713
1714 /*****************************************************************************
1715 FUNCTION : ui_parseCmdLine
1716
1717 PURPOSE : parse command line
1718 RETURNS : void
1719 NOTES : sets options and filenames
1720
1721 UPDATE : 15.6.1992
1722 ******************************************************************************/
ui_parseCmdLine(int noParams,char * params[])1723 void ui_parseCmdLine (int noParams, char *params[])
1724
1725 {
1726 int i;
1727 char *call;
1728
1729 call = *params;
1730
1731 strcpy (ui_dfontName, "6x12");
1732 ui_labelFontWidth = 7;
1733 hasCmdlineFont = TRUE;
1734
1735 i = 0;
1736 while(++i != noParams) {
1737 if (*params[i] == '-') {
1738 if ((strcmp(params[i], "-dfont")) == 0) {
1739 if(params[++i] == NULL){
1740 fprintf(stderr,"%s: No display font specified\n",call);
1741 exit(1);
1742 }else{
1743 strcpy (ui_dfontName, params[i]);
1744 }
1745 } else if ((strcmp(params[i], "-mono")) == 0) {
1746 ui_monoOnColorScreen = TRUE;
1747 } else if ((strcmp(params[i], "-help") == 0)
1748 OR (strcmp(params[i], "-h") == 0)) {
1749 ui_showHelpMsg(call);
1750 exit(1);
1751 } else if ((strcmp(params[i], "-font")) == 0) {
1752 if(params[++i] == NULL){
1753 fprintf(stderr,"%s: No label font specified\n",call);
1754 exit(1);
1755 }
1756 }
1757 else{
1758 fprintf(stderr,"%s: unrecognized command line option %s\n",
1759 call,params[i]);
1760 exit(1);
1761 }
1762 } else if (ui_chkFileName(params[i], ".net")) {
1763 strncpy(ui_filenameNET, params[i], strlen(params[i])-4);
1764 ui_loadNetbyInit = TRUE;
1765 } else if (ui_chkFileName(params[i], ".pat")) {
1766 strncpy(ui_filenamePAT, params[i], strlen(params[i])-4);
1767 ui_loadPatbyInit = TRUE;
1768 } else if (ui_chkFileName(params[i], ".cfg")) {
1769 strncpy(ui_filenameCFG, params[i], strlen(params[i])-4);
1770 ui_loadCfgbyInit = TRUE;
1771 ui_loadCorrespondingCfg = FALSE;
1772 }
1773 else{
1774 printf("unrecognized file type in command line\n");
1775 exit(1);
1776 }
1777 }
1778 }
1779 /* end of file */
1780