1 /*****************************************************************************
2 FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/xgui/sources/ui_kohonen.c,v $
3 SHORTNAME : ui_kohonen.c
4 SNNS VERSION : 4.2
5
6 PURPOSE : Creation/Callback routines for Kohonen Window
7 NOTES :
8
9 AUTHOR : Marcus Ritt
10 DATE : July 13 1993
11
12 CHANGED BY : Guenter Mamier
13 RCS VERSION : $Revision: 2.13 $
14 LAST CHANGE : $Date: 1998/03/03 14:10:32 $
15
16 Copyright (c) 1990-1995 SNNS Group, IPVR, Univ. Stuttgart, FRG
17 Copyright (c) 1996-1998 SNNS Group, WSI, Univ. Tuebingen, FRG
18
19 Copyright (c) 1990-1995 SNNS Group, IPVR, Univ. Stuttgart, FRG
20 Copyright (c) 1996-1998 SNNS Group, WSI, Univ. Tuebingen, FRG
21
22 ******************************************************************************/
23 #include <config.h>
24 #include <X11/Intrinsic.h>
25 #include <X11/Shell.h>
26 #include <X11/Xaw3d/Box.h>
27 #include <X11/Xaw3d/Form.h>
28
29 #include "ui.h"
30 #include "kr_ui.h"
31 #include "ui_xWidgets.h"
32 #include "ui_display.h"
33 #include "ui_mainP.h"
34 #include "ui_confirmer.h"
35 #include "ui_control.h"
36 #include "ui_controlP.h"
37 #include "ui_key.h"
38 #include "ui_netUpdate.h"
39
40 #include "ui_kohonen.ph"
41
42 /*****************************************************************************
43 FUNCTION : kohonen_rem_displayLayerNumber(void)
44
45 PURPOSE : Display the value of ui_NoOfCurrentLayer in the control panel
46 RETURNS : void
47 NOTES :
48
49 UPDATE :
50 ******************************************************************************/
kohonen_rem_displayLayerNumber(void)51 static void kohonen_rem_displayLayerNumber(void)
52 {
53 char buf[50];
54
55 if (NOT kohonen_open) return;
56
57 sprintf(buf,"%d", noOfCurrentLayer);
58 ui_xSetString(ui_LayerWidget, buf);
59 }
60
61 /*****************************************************************************
62 FUNCTION : kohonen_rem_moveLayerProc
63
64 PURPOSE : callback. Called when cursor buttons or GOTO of LAYER is clicked.
65 RETURNS : void
66 NOTES :
67
68 UPDATE :
69 ******************************************************************************/
kohonen_rem_moveLayerProc(Widget w,int moveType,caddr_t call_data)70 static void kohonen_rem_moveLayerProc(Widget w, int moveType, caddr_t call_data)
71 {
72 int temp;
73 Bool doMove = FALSE;
74
75 if (krui_getNoOfInputUnits() == 0) {
76 ui_confirmOk("No input units defined!");
77 return;
78 }
79 if (!ui_controlIsCreated) {
80 ui_confirmOk("Please create control panel first !");
81 return;
82 }
83
84 switch(moveType) {
85 case UI_JUMP:
86 temp = ui_xIntFromAsciiWidget(ui_LayerWidget);
87 if ((temp>0) AND (temp<= krui_getNoOfInputUnits())) {
88 noOfCurrentLayer = temp;
89 kohonen_rem_displayLayerNumber();
90 doMove = TRUE;
91 } else ui_confirmOk("Layer goto: invalid number!");
92 break;
93 case UI_FIRST:
94 if (noOfCurrentLayer!=1) {
95 noOfCurrentLayer = 1;
96 kohonen_rem_displayLayerNumber();
97 doMove = TRUE;
98 }
99 break;
100 case UI_LAST:
101 if (noOfCurrentLayer != krui_getNoOfInputUnits()) {
102 noOfCurrentLayer = krui_getNoOfInputUnits();
103 kohonen_rem_displayLayerNumber();
104 doMove = TRUE;
105 }
106 break;
107 case UI_NEXT:
108 if (++noOfCurrentLayer > krui_getNoOfInputUnits())
109 noOfCurrentLayer = 1;
110 kohonen_rem_displayLayerNumber();
111 doMove = TRUE;
112 break;
113 case UI_PREVIOUS:
114 if (--noOfCurrentLayer < 1)
115 noOfCurrentLayer = krui_getNoOfInputUnits();
116 kohonen_rem_displayLayerNumber();
117 doMove = TRUE;
118 break;
119 }
120 if (doMove) ui_rem_stepsProc(NULL, TRUE, NULL);
121 }
122
123
124 /*****************************************************************************
125 FUNCTION : kohonen_tree()
126
127 PURPOSE : callback. Called when WINNER button is clicked.
128 RETURNS : void
129 NOTES :
130
131 UPDATE :
132 ******************************************************************************/
kohonen_tree(void)133 static void kohonen_tree(void)
134 {
135 if (!ui_controlIsCreated) {
136 ui_confirmOk("Please create control panel first !");
137 return;
138 }
139 krui_spanning_tree();
140 ui_net_completeRefresh(ui_currentDisplay, UI_GLOBAL);
141 }
142
143
144 /*****************************************************************************
145 FUNCTION : kohonen_doneProc
146
147 PURPOSE : callback function of the done-buttom.
148
149 NOTES :
150
151 UPDATE :
152 ******************************************************************************/
kohonen_doneProc(void)153 static void kohonen_doneProc(void)
154 {
155 XtDestroyWidget(kohonen_mainWidget);
156 kohonen_open= 0;
157 }
158
159
160 /*****************************************************************************
161 FUNCTION : kohonen_createWindow
162
163 PURPOSE : create the Kohonen window
164 NOTES :
165
166 UPDATE :
167 ******************************************************************************/
kohonen_createWindow(void)168 void kohonen_createWindow (void)
169 {
170 Widget button,done,box,form,kohonenLabel;
171 Cardinal n;
172 Arg arg[25];
173 char buf[20];
174
175 int fontWidth = 8;
176 int titelWidth = 7 * fontWidth;
177 int numberWidth = 10 * fontWidth;
178
179 if (!ui_controlIsCreated) {
180 ui_confirmOk("Please create control panel first !");
181 return;
182 }
183
184 if (kohonen_open) {
185 XRaiseWindow (XtDisplay (kohonen_mainWidget),
186 XtWindow (kohonen_mainWidget));
187 return;
188 }
189
190 kohonen_open= 1;
191 sprintf(buf, "SNNS Kohonen Window");
192 n = 0;
193 kohonen_mainWidget= XtCreatePopupShell(buf,topLevelShellWidgetClass,
194 ui_toplevel,arg,n);
195 box = XtCreateManagedWidget("box",boxWidgetClass,kohonen_mainWidget,arg,n);
196 form= XtCreateManagedWidget("connt", formWidgetClass, box, arg, n);
197
198 /************* Kohonen LAYER *********************************************/
199
200 kohonenLabel = ui_xCreateLabelItem("LAYER", form, titelWidth, NULL, NULL);
201 sprintf(buf,"%d",1);
202 ui_LayerWidget = ui_xCreateDialogItem("Layers", form,
203 buf, numberWidth, kohonenLabel, NULL);
204
205 button = ui_xCreateButtonItem("goto", form, ui_LayerWidget, NULL);
206 XtAddCallback (button, XtNcallback, (XtCallbackProc)
207 kohonen_rem_moveLayerProc, (caddr_t) UI_JUMP);
208
209 button = ui_xCreateButtonItem("first", form, button, NULL);
210 XtAddCallback (button, XtNcallback, (XtCallbackProc)
211 kohonen_rem_moveLayerProc, (caddr_t) UI_FIRST);
212
213 button = ui_xCreateButtonItem("prev", form, button, NULL);
214 XtAddCallback (button, XtNcallback, (XtCallbackProc)
215 kohonen_rem_moveLayerProc, (caddr_t) UI_PREVIOUS);
216
217 button = ui_xCreateButtonItem("next", form, button, NULL);
218 XtAddCallback (button, XtNcallback, (XtCallbackProc)
219 kohonen_rem_moveLayerProc, (caddr_t) UI_NEXT);
220
221 button = ui_xCreateButtonItem("last", form, button, NULL);
222 XtAddCallback (button, XtNcallback, (XtCallbackProc)
223 kohonen_rem_moveLayerProc, (caddr_t) UI_LAST);
224
225 button = ui_xCreateButtonItem("STree", form, button, NULL);
226 XtAddCallback (button, XtNcallback, (XtCallbackProc)
227 kohonen_tree, kohonenLabel);
228
229 XtAddEventHandler(form,KeyPressMask,FALSE,
230 (XtEventHandler)ui_key_control,(Cardinal *) 0);
231 XawFormDoLayout(form, TRUE);
232
233 done= ui_xCreateButtonItem("done", box, NULL, NULL);
234 XtAddCallback(done,XtNcallback,(XtCallbackProc)kohonen_doneProc,NULL);
235
236 XtPopup (kohonen_mainWidget, XtGrabNone);
237
238 }
239