1 /*****************************************************************************
2 FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/xgui/sources/ui_displmap.c,v $
3 SHORTNAME : ui_displmap
4 SNNS VERSION : 4.2
5
6 PURPOSE : realize al teh functions necessary to display the projection
7 of two units onto an other unit
8
9
10 NOTES : Functions:
11 -- ui_displMap
12 Purpose : Main program to display the MAPs of the network
13 -- ui_map_event:
14 Purpose : event handler for graphic window
15 -- ui_displMapBW
16 Purpose : Display the weights of the network in black and white
17 -- ui_displMapCOL
18 Purpose : Display the weights of the network in color
19 -- ui_displMapFromUpdate
20 Purpose : Interface program, used if net was updated and has
21 -- ui_map_close
22 Purpose : notify xgui about the destruction of the window
23 -- ui_map_setup
24 Purpose : Setup panel for the grid width and the color scale
25 -- ui_map_close_setup
26 Purpose : notify xgui about the destruction of the setup
27 panel and read out the widget values
28 -- ui_map_scale
29 Purpose : Program to display the scale of colors /scale of
30 square sizes
31 -- ui_map_zoom_in
32 Purpose : Zomms onto the weight squares
33 -- ui_map_zoom_out
34 Purpose : Zomms away from the weight squares
35 -- ui_map_geometry
36 Purpose : compute the geometry of the displays and the
37 size of the squares
38 -- ui_map_grid
39 Purpose : draws a grid over the weight squares and the axis
40
41
42 AUTHOR : Christian Wehrfritz
43 DATE : 20.05.1994
44
45 CHANGED BY : Guenter Mamier
46 RCS VERSION : $Revision: 1.15 $
47 LAST CHANGE : $Date: 1998/03/03 14:10:20 $
48
49 Copyright (c) 1990-1995 SNNS Group, IPVR, Univ. Stuttgart, FRG
50 Copyright (c) 1996-1998 SNNS Group, WSI, Univ. Tuebingen, FRG
51
52
53 ******************************************************************************/
54 #include <config.h>
55 #include <stdlib.h>
56 #include <stdio.h> /* For the Syntax message */
57
58 #include "ui.h"
59
60 #include <X11/Intrinsic.h>
61 #include <X11/IntrinsicP.h>
62 #include <X11/StringDefs.h>
63 #include <X11/Xaw3d/Text.h>
64 #include <X11/Xaw3d/TextSrc.h>
65 #include <X11/Shell.h>
66 #include <X11/cursorfont.h>
67 #include <X11/Xaw3d/MenuButton.h>
68 #include <X11/Xaw3d/Form.h>
69 #include <X11/Xaw3d/Box.h>
70 #include <X11/Xaw3d/Cardinals.h>
71 #include <X11/Xaw3d/Command.h>
72 #include <X11/Xaw3d/Dialog.h>
73 #include <X11/Xaw3d/List.h>
74 #include <X11/Xaw3d/Label.h>
75 #include <X11/Xaw3d/AsciiText.h>
76 #include <X11/Xaw3d/Scrollbar.h>
77 #include <X11/Xaw3d/Viewport.h>
78
79 #include "kr_ui.h"
80 #include "ui_xWidgets.h"
81 #include "ui_confirmer.h"
82 #include "ui_funcdispl.h"
83
84 #include "ui_displmap.ph"
85 #include "ui_main.h"
86 #include "ui_color.h"
87 #include "ui_mainP.h"
88 #include "ui_setup.h"
89 #include "ui_key.h"
90
91
92
93 /*****************************************************************************
94 FUNCTION : ui_displMap
95
96 PURPOSE : Main program to display the MAPs of the network
97 NOTES : Initializes widgets and switches for color or b&w terminal
98 RETURNS :
99 UPDATE : 22.09.94
100 ******************************************************************************/
ui_displMap(Widget w,caddr_t call_data)101 void ui_displMap(Widget w, caddr_t call_data)
102 {
103 Widget donebutton,setbutton,framewidget,zoomin,zoomout;
104 int maxstepX,maxstepY;
105 Arg args[25];
106 Cardinal n = 0;
107 char buf[40];
108
109 /* do nothing, if no network is defined */
110 if( (krui_getNoOfUnits()) == 0){
111 ui_confirmOk("No network loaded !");
112 return;
113 }
114
115
116 /* If a MAP window already exists, just put it on top */
117
118 if(MAP_WINDOW_created == 1){
119 XRaiseWindow (XtDisplay (MAP_GRAPH_mainwidget),
120 XtWindow (MAP_GRAPH_mainwidget));
121 return;
122 }
123
124
125 /* Create all necessary widgets */
126
127 n = 0;
128 sprintf(buf," SNNS Unit Projection\n");
129 MAP_GRAPH_mainwidget =
130 XtCreatePopupShell(buf,topLevelShellWidgetClass,ui_toplevel,args,n);
131 n = 0;
132 framewidget = XtCreateManagedWidget("form",formWidgetClass,
133 MAP_GRAPH_mainwidget,args,n);
134 donebutton = ui_xCreateButtonItem("done", framewidget, NULL, NULL);
135
136 zoomin = ui_xCreateButtonItem("zoomin",framewidget,NULL,donebutton);
137 setbutton = ui_xCreateButtonItem("setup",framewidget,zoomin,NULL);
138 zoomout = ui_xCreateButtonItem("zoomout",framewidget,zoomin,donebutton);
139 n = 0;
140 XtSetArg(args[n], XtNx, 0);n++;
141 XtSetArg(args[n], XtNy, 0);n++;
142 XtSetArg(args[n], XtNwidth, 210); n++;
143 XtSetArg(args[n], XtNheight, 25); n++;
144 XtSetArg(args[n], XtNinternalHeight, 1); n++;
145 XtSetArg(args[n], XtNinternalWidth , 1); n++;
146 XtSetArg(args[n], XtNborderWidth, 0); n++;
147 XtSetArg(args[n], XtNhorizDistance, 30); n++;
148 XtSetArg(args[n], XtNfromHoriz, setbutton); n++;
149 XtSetArg(args[n], XtNfromVert, NULL); n++;
150 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
151 XtSetArg(args[n], XtNright , XtChainLeft); n++;
152 XtSetArg(args[n], XtNtop , XtChainTop); n++;
153 XtSetArg(args[n], XtNbottom, XtChainTop);n++;
154 scale = XtCreateManagedWidget("Label",formWidgetClass,framewidget,args,n);
155
156 n = 0;
157 XtSetArg(args[n], XtNx, 0);n++;
158 XtSetArg(args[n], XtNy, 0);n++;
159 XtSetArg(args[n], XtNborderWidth, 1); n++;
160 XtSetArg(args[n], XtNwidth, MAP_windowsizeX+62); n++;
161 XtSetArg(args[n], XtNheight, MAP_windowsizeY+62); n++;
162 XtSetArg(args[n], XtNallowHoriz, TRUE);n++;
163 XtSetArg(args[n], XtNallowVert, TRUE);n++;
164 XtSetArg(args[n], XtNforceBars, TRUE);n++;
165 XtSetArg(args[n], XtNfromHoriz, NULL); n++;
166 XtSetArg(args[n], XtNfromVert, zoomin); n++;
167 XtSetArg(args[n], XtNvertDistance, 10); n++;
168 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
169 XtSetArg(args[n], XtNright , XtChainRight); n++;
170 XtSetArg(args[n], XtNtop , XtChainTop); n++;
171 XtSetArg(args[n], XtNbottom, XtChainBottom);n++;
172 view = XtCreateManagedWidget("view",viewportWidgetClass,framewidget,args,n);
173 MAP_GRAPH_displaywidget =
174 ui_createMyScreen("screen",view,MAP_windowsizeX,MAP_windowsizeY,
175 NULL,scale);
176 MAP_WINDOW_created = 1;
177
178
179 /* define the routines to be called for widget events */
180
181 XtAddCallback(donebutton, XtNcallback,
182 (XtCallbackProc)ui_map_close,MAP_GRAPH_mainwidget);
183 XtAddCallback(setbutton, XtNcallback,(XtCallbackProc)ui_map_setup,NULL);
184 XtAddCallback(zoomin, XtNcallback,(XtCallbackProc)ui_map_zoom_in,NULL);
185 XtAddCallback(zoomout, XtNcallback,(XtCallbackProc)ui_map_zoom_out,NULL);
186 XtAddEventHandler(MAP_GRAPH_displaywidget,
187 StructureNotifyMask | ExposureMask, GraphicsExpose,
188 (XtEventHandler) ui_map_event,ui_display);
189 XtAddEventHandler(framewidget,KeyPressMask,FALSE,
190 (XtEventHandler)ui_key_control,(Cardinal *) 0);
191
192
193 /* set the maximum size of each square and the size of the whole window */
194 maxstepX = (int)((float)(MAP_xMax - MAP_xMin)/ MAP_scaleX);
195 maxstepY = (int)((float)(MAP_yMax - MAP_yMin)/ MAP_scaleY);
196
197 if(ui_col_monochromeMode){
198 /* B&W terminal => variable square size needed */
199 MAP_squaresizeX = (maxstepX > MAP_viewsizeX/MAP_BW_squaresizeX)?
200 MAP_BW_squaresizeX:
201 (int)((float)MAP_viewsizeX/(float)maxstepX);
202 MAP_windowsizeX = MAP_squaresizeX*maxstepX+40;
203 MAP_squaresizeY = (maxstepY > MAP_viewsizeY/MAP_BW_squaresizeY)?
204 MAP_BW_squaresizeY:
205 (int)((float)MAP_viewsizeY/(float)maxstepY);
206 MAP_windowsizeX = MAP_squaresizeX*maxstepX+40;
207 }else{
208 /* color terminal => fixed square size */
209 MAP_squaresizeX =
210 ( maxstepX > MAP_viewsizeX/5)?5:(int)(MAP_viewsizeX/maxstepX);
211 MAP_squaresizeY =
212 ( maxstepY > MAP_viewsizeY/5)?5:(int)(MAP_viewsizeY/maxstepY);
213 MAP_windowsizeX = MAP_squaresizeX*maxstepX+40;
214 MAP_windowsizeY = MAP_squaresizeY*maxstepY+40;
215 }
216
217 /* Realize the window */
218 XtPopup(MAP_GRAPH_mainwidget, XtGrabNone);
219
220 MAP_GRAPH_screen = DefaultScreen(ui_display);
221 MAP_GRAPH_win = XtWindow(MAP_GRAPH_displaywidget);
222 }
223
224
225 /*****************************************************************************
226 FUNCTION : ui_map_event
227
228 PURPOSE : event handler for graphic window
229 NOTES :
230 RETURNS :
231 UPDATE : 22.09.94
232 *****************************************************************************/
ui_map_event(Widget w,Display * display,XEvent * event)233 static void ui_map_event(Widget w, Display *display, XEvent *event)
234 {
235 int zooming = 0;
236 int col_screen = 1;
237 int bw_screen = 0;
238
239 switch (event->type){
240 case Expose:
241 if((event->xexpose.count == 0) && (w = MAP_GRAPH_displaywidget))
242
243 if(ui_col_monochromeMode){
244 /* this is a B&W terminals, so use ui_displMAPBW */
245 ui_map_geometry(zooming);
246 ui_displMapBW();
247 ui_map_grid(bw_screen);
248 }else{
249 ui_map_geometry(zooming);
250 ui_displMapCOL();
251 ui_map_grid(col_screen);
252 }
253 break;
254 default:
255 break;
256 }
257 }
258
259
260
261 /*****************************************************************************
262 FUNCTION : ui_dispMapBW
263
264 PURPOSE : Program to display the MAPs of the network in black and white
265 NOTES :
266 RETURNS :
267 UPDATE : 22.09.94
268 ******************************************************************************/
ui_displMapBW(void)269 static void ui_displMapBW(void)
270 {
271 FlintType strength, this_x, this_y;
272 int xx,yy,xc=0,yc=0;
273 uint dx,dy;
274 FlintType save_act1,save_act2;
275
276 /* save unit activations */
277 save_act1 = krui_getUnitActivation(MAP_xUnit);
278 save_act2 = krui_getUnitActivation(MAP_yUnit);
279
280 /* clear the window */
281 XSetForeground(ui_display, MAP_GRAPH_gc[0],
282 BlackPixel(ui_display,MAP_GRAPH_screen));
283 XSetBackground(ui_display, MAP_GRAPH_gc[0],
284 WhitePixel(ui_display,MAP_GRAPH_screen));
285 XClearWindow(ui_display,MAP_GRAPH_win);
286
287
288 /* draw the MAP squares */
289 for (this_y=MAP_yMin; this_y<MAP_yMax; this_y+=MAP_scaleY) {
290 for (this_x=MAP_xMin; this_x<MAP_xMax; this_x+=MAP_scaleX) {
291 krui_setUnitActivation(MAP_xUnit, this_x);
292 krui_setUnitActivation(MAP_yUnit, this_y);
293 krui_updateNet(NULL,(int)NULL);
294 strength = krui_getUnitOutput(MAP_outputUnit);
295 dx = dy =
296 abs(18*(strength-MAP_minWght)/(MAP_maxWght-MAP_minWght)-9);
297 xx = (int)(xc*MAP_BW_squaresizeX)+20;
298 yy = (int)(yc*MAP_BW_squaresizeY)+20;
299 if(strength >(MAP_maxWght-MAP_minWght)/2 ){
300 XFillRectangle(ui_display,MAP_GRAPH_win,
301 MAP_GRAPH_gc[0],xx,yy,dx,dy);
302 }else{
303 XDrawRectangle(ui_display,MAP_GRAPH_win,
304 MAP_GRAPH_gc[0],xx,yy,dx,dy);
305 }
306 xc++;
307 }
308 yc++;xc=0;
309 }
310
311 /* restore unit activations */
312 krui_setUnitActivation(MAP_xUnit,save_act1);
313 krui_setUnitActivation(MAP_yUnit,save_act2);
314
315 /* draw the scale */
316 ui_map_scale(scale);
317 }
318
319
320 /*****************************************************************************
321 FUNCTION : ui_displMapCOL
322
323 PURPOSE : Program to display the MAP of the network in color
324 NOTES :
325 RETURNS :
326 UPDATE : 22.09.94
327 ******************************************************************************/
ui_displMapCOL(void)328 static void ui_displMapCOL(void)
329 {
330 FlintType strength, this_x, this_y;
331 int xx,yy,xc=0,yc=0;
332 uint dx,dy;
333 FlintType save_act1,save_act2;
334
335 /* save unit activations */
336 save_act1 = krui_getUnitActivation(MAP_xUnit);
337 save_act2 = krui_getUnitActivation(MAP_yUnit);
338
339 /* clear the window */
340 XSetForeground(ui_display, MAP_GRAPH_gc[20],
341 BlackPixel(ui_display,MAP_GRAPH_screen));
342 XSetBackground(ui_display, MAP_GRAPH_gc[20],
343 WhitePixel(ui_display,MAP_GRAPH_screen));
344 XClearWindow(ui_display,MAP_GRAPH_win);
345
346 /* draw the MAP squares */
347 dx = MAP_squaresizeX;
348 dy = MAP_squaresizeY;
349 for (this_y=MAP_yMin; this_y<MAP_yMax; this_y+=MAP_scaleY) {
350 for (this_x=MAP_xMin; this_x<MAP_xMax; this_x+=MAP_scaleX) {
351 krui_setUnitActivation(MAP_xUnit, this_x);
352 krui_setUnitActivation(MAP_yUnit, this_y);
353 krui_updateNet(NULL,(int)NULL);
354 strength = krui_getUnitOutput(MAP_outputUnit);
355 xx = (int)(xc*MAP_squaresizeX - 0.5*MAP_squaresizeX)+20;
356 yy = (int)(yc*MAP_squaresizeY - 0.5*MAP_squaresizeY)+20;
357
358 strength = 18*(strength-MAP_minWght)/(MAP_maxWght-MAP_minWght)-9;
359 strength = (strength > 9)? 9: strength;
360 strength = (strength <-9)? -9: strength;
361 XFillRectangle(ui_display,MAP_GRAPH_win,
362 MAP_GRAPH_gc[(int)(10.0 + (float)strength)],
363 xx,yy,dx,dy);
364 xc++;
365 }
366 yc++;xc=0;
367 }
368
369 /* restore unit activations */
370 krui_setUnitActivation(MAP_xUnit,save_act1);
371 krui_setUnitActivation(MAP_yUnit,save_act2);
372
373 /* draw the scale */
374 ui_map_scale(scale);
375 }
376
377 /*****************************************************************************
378 FUNCTION : ui_displMapFromUpdate
379
380 PURPOSE : Interface program, used if net was updated and has to be redrawn.
381 NOTES :
382 RETURNS :
383 UPDATE : 22.09.94
384 ******************************************************************************/
ui_displMapFromUpdate(void)385 void ui_displMapFromUpdate(void)
386 {
387
388 if( !MAP_WINDOW_created )return;
389
390 if(ui_col_monochromeMode){
391 ui_displMapBW();
392 }else{
393 ui_displMapCOL();
394 ui_map_grid(1);
395 }
396 }
397
398 /*****************************************************************************
399 FUNCTION : ui_map_zoom_in
400
401 PURPOSE : Zomms onto the weight squares
402 NOTES :
403 RETURNS :
404 UPDATE : 20.05.1994
405 ******************************************************************************/
ui_map_zoom_in(Widget w)406 static void ui_map_zoom_in(Widget w)
407 {
408 /* delete the old screen display */
409 XClearWindow(ui_display,MAP_GRAPH_win);
410
411 /* compute new display geometry */
412 ui_map_geometry(1);
413
414 /* display the new setting */
415 if(ui_col_monochromeMode){
416 ui_displMapBW();
417 ui_map_grid(0);
418 }else{
419 ui_displMapCOL();
420 ui_map_grid(1);
421 }
422 }
423
424 /*****************************************************************************
425 FUNCTION : ui_map_zoom_out
426
427 PURPOSE : Zomms away from the weight squares
428 NOTES :
429 RETURNS :
430 UPDATE : 20.05.1994
431 ******************************************************************************/
ui_map_zoom_out(Widget w)432 static void ui_map_zoom_out(Widget w)
433 {
434 /* delete the old screen display */
435 XClearWindow(ui_display,MAP_GRAPH_win);
436
437 /* compute new display geometry */
438 ui_map_geometry(-1);
439
440 /* display the new setting */
441 if(ui_col_monochromeMode){
442 ui_displMapBW();
443 ui_map_grid(0);
444 }else{
445 ui_displMapCOL();
446 ui_map_grid(1);
447 }
448 }
449
450
451 /*****************************************************************************
452 FUNCTION : ui_map_close
453
454 PURPOSE : notify xgui about the destruction of the window
455 NOTES :
456 RETURNS :
457 UPDATE : 20.05.94
458 ******************************************************************************/
ui_map_close(Widget dummy,Widget w,caddr_t call_data)459 static void ui_map_close(Widget dummy, Widget w, caddr_t call_data)
460 {
461 XtDestroyWidget(w);
462 MAP_WINDOW_created = 0;
463 MAP_gridWidth = 0;
464 }
465
466 /*****************************************************************************
467 FUNCTION : ui_map_setup
468
469 PURPOSE : Setup panel for the grid width and the color scale
470 NOTES :
471 RETURNS :
472 UPDATE : 22.09.94
473 ******************************************************************************/
ui_map_setup(Widget button,caddr_t call_data)474 static void ui_map_setup(Widget button, caddr_t call_data)
475 {
476 Widget grid_lab,MAP_GRAPH_setupwidget, x_lab,y_lab;
477 Widget ui_setupPanel,done,subframe,d1,d2,d3,range_lab;
478 Widget y_range_lab,x_range_lab,out_lab;
479 char buf[80];
480 Position x, y;
481 Dimension width, height;
482 Arg args[25];
483 Cardinal n = 0;
484 int titelWidth = 32;
485 int floatWidth = 48;
486
487
488 /* set Popup arguments */
489 n = 0;
490 XtSetArg(args[0], XtNwidth, &width);n++;
491 XtSetArg(args[1], XtNheight, &height);n++;
492 XtGetValues(button, args, n);
493 XtTranslateCoords(button, (Position)(width/2),
494 (Position)(height/2), &x, &y);
495 n = 0;
496 XtSetArg(args[n], XtNx, x);n++;
497 XtSetArg(args[n], XtNy, y+50);n++;
498
499 /* Now create Popup */
500 MAP_GRAPH_setupwidget =
501 XtCreatePopupShell("Setup", transientShellWidgetClass,
502 ui_toplevel, args, n);
503
504 ui_setupPanel =
505 XtCreateManagedWidget("form", formWidgetClass,
506 MAP_GRAPH_setupwidget, NULL, ZERO);
507 done = ui_xCreateButtonItem("done", ui_setupPanel, NULL, NULL);
508 XtAddCallback (done, XtNcallback, (XtCallbackProc)ui_map_close_setup,
509 MAP_GRAPH_setupwidget);
510 n = 0;
511 XtSetArg(args[n], XtNx, 0);n++;
512 XtSetArg(args[n], XtNy, 0);n++;
513 XtSetArg(args[n], XtNborderWidth, 1); n++;
514 XtSetArg(args[n], XtNfromHoriz, NULL); n++;
515 XtSetArg(args[n], XtNfromVert, done); n++;
516 XtSetArg(args[n], XtNleft , XtChainLeft); n++;
517 XtSetArg(args[n], XtNright , XtChainRight); n++;
518 XtSetArg(args[n], XtNtop , XtChainTop); n++;
519 XtSetArg(args[n], XtNbottom, XtChainBottom);n++;
520 subframe = XtCreateManagedWidget("sub",formWidgetClass,
521 ui_setupPanel,args,n);
522
523 /* X unit */
524
525 grid_lab = ui_xCreateLabelItem("X-axis :", subframe,104, NULL, NULL);
526 x_lab = ui_xCreateLabelItem("unit ",subframe,56,NULL,grid_lab);
527 sprintf(buf,"%d", MAP_xUnit);
528 x_dia = ui_xCreateDialogItem("xUnit",subframe,buf,
529 titelWidth,x_lab,grid_lab);
530 x_range_lab = ui_xCreateLabelItem(" value range :", subframe,
531 120, x_dia, grid_lab);
532 sprintf(buf,"%g",MAP_xMin);
533 x_min = ui_xCreateDialogItem("xMin", subframe, buf,
534 floatWidth,x_range_lab,grid_lab);
535 d1 = ui_xCreateLabelItem("to",subframe,24,x_min,grid_lab);
536
537 sprintf(buf,"%g",MAP_xMax);
538 x_max = ui_xCreateDialogItem("xMax", subframe, buf,
539 floatWidth, d1,grid_lab);
540
541 /* Y unit */
542
543 grid_lab = ui_xCreateLabelItem("Y-axis :", subframe,104, NULL, x_max);
544
545 y_lab = ui_xCreateLabelItem("unit ",subframe,56,NULL,grid_lab);
546 sprintf(buf,"%d", MAP_yUnit);
547 y_dia = ui_xCreateDialogItem("yUnit",subframe,buf,
548 titelWidth,y_lab,grid_lab);
549 y_range_lab = ui_xCreateLabelItem(" value range :", subframe,
550 120, y_dia, grid_lab);
551 sprintf(buf,"%g",MAP_yMin);
552 y_min = ui_xCreateDialogItem("yMin", subframe, buf,
553 floatWidth,y_range_lab,grid_lab);
554 d2 = ui_xCreateLabelItem("to",subframe,24,y_min,grid_lab);
555
556 sprintf(buf,"%g",MAP_yMax);
557 y_max = ui_xCreateDialogItem("yMax", subframe, buf,
558 floatWidth, d2, grid_lab);
559
560 /* output unit */
561
562 grid_lab = ui_xCreateLabelItem("activation pattern", subframe, 160,
563 NULL, y_lab);
564 out_lab = ui_xCreateLabelItem("unit ", subframe, 56, NULL, grid_lab);
565 sprintf(buf,"%d", MAP_outputUnit);
566 out_dia = ui_xCreateDialogItem("outUnit",subframe,buf,
567 titelWidth,out_lab,grid_lab);
568 range_lab = ui_xCreateLabelItem(" output range :", subframe,
569 120, out_dia, grid_lab);
570 sprintf(buf,"%g",MAP_minWght);
571 out_min = ui_xCreateDialogItem("outMin", subframe, buf,
572 floatWidth,range_lab,grid_lab);
573 d3 = ui_xCreateLabelItem("to",subframe,24,out_min,grid_lab);
574
575 sprintf(buf,"%g",MAP_maxWght);
576 out_max = ui_xCreateDialogItem("outMax", subframe, buf,
577 floatWidth, d3,grid_lab);
578
579 n = 0;
580 XtSetArg(args[n], XtNx, 0);n++;
581 XtSetArg(args[n], XtNy, 0);n++;
582 XtSetArg(args[n], XtNwidth, 210); n++;
583 XtSetArg(args[n], XtNheight, 25); n++;
584 XtSetArg(args[n], XtNinternalHeight, 1); n++;
585 XtSetArg(args[n], XtNinternalWidth , 1); n++;
586 XtSetArg(args[n], XtNborderWidth, 0); n++;
587 XtSetArg(args[n], XtNfromHoriz,range_lab); n++;
588 XtSetArg(args[n], XtNfromVert, range_lab); n++;
589 XtSetArg(args[n], XtNleft , XtChainRight); n++;
590 XtSetArg(args[n], XtNright , XtChainRight); n++;
591 XtSetArg(args[n], XtNtop , XtChainBottom); n++;
592 XtSetArg(args[n], XtNbottom, XtChainBottom);n++;
593 scale2 = XtCreateManagedWidget("Label2",formWidgetClass,subframe,args,n);
594
595 XtRealizeWidget(MAP_GRAPH_setupwidget);
596 XtAddEventHandler(scale2, ExposureMask, GraphicsExpose,
597 (XtEventHandler) ui_map_scale,NULL);
598
599
600 /* Realize the window */
601 XtPopup(MAP_GRAPH_setupwidget, XtGrabExclusive);
602 }
603
604
605 /*****************************************************************************
606 FUNCTION : ui_map_close_setup
607
608 PURPOSE : notify xgui about the destruction of the setup panel and read
609 out the widget values
610 NOTES :
611 RETURNS :
612 UPDATE : 22.09.94
613 ******************************************************************************/
ui_map_close_setup(Widget dummy,Widget w,caddr_t call_data)614 static void ui_map_close_setup(Widget dummy, Widget w, caddr_t call_data)
615 {
616
617 /* read the setup values */
618 MAP_xUnit = (int)ui_xIntFromAsciiWidget(x_dia);
619 MAP_yUnit = (int)ui_xIntFromAsciiWidget(y_dia);
620 MAP_outputUnit = (int)ui_xIntFromAsciiWidget(out_dia);
621 MAP_xMin = (float)ui_xFloatFromAsciiWidget(x_min);
622 MAP_xMax = (float)ui_xFloatFromAsciiWidget(x_max);
623 MAP_yMin = (float)ui_xFloatFromAsciiWidget(y_min);
624 MAP_yMax = (float)ui_xFloatFromAsciiWidget(y_max);
625 MAP_maxWght = (float)ui_xFloatFromAsciiWidget(out_max);
626 MAP_minWght = (float)ui_xFloatFromAsciiWidget(out_min);
627
628
629 /* update display according to the new values */
630 if(ui_col_colorDisplay){
631 MAP_scaleX = ((MAP_xMax-MAP_xMin) / MAP_viewsizeX) * MAP_squaresizeX;
632 MAP_scaleY = ((MAP_yMax-MAP_yMin) / MAP_viewsizeY) * MAP_squaresizeY;
633 ui_displMapCOL();
634 ui_map_scale(scale);
635 ui_map_grid(1);
636 }else{
637 MAP_scaleX = ((MAP_xMax-MAP_xMin) / MAP_viewsizeX) * MAP_BW_squaresizeX;
638 MAP_scaleY = ((MAP_yMax-MAP_yMin) / MAP_viewsizeY) * MAP_BW_squaresizeY;
639 ui_displMapBW();
640 ui_map_scale(scale);
641 ui_map_grid(0);
642 }
643
644 XtDestroyWidget(w);
645 }
646
647
648 /*****************************************************************************
649 FUNCTION : ui_map_scale
650
651 PURPOSE : Program to display the scale of colors /scale of square sizes
652 NOTES :
653 RETURNS :
654 UPDATE : 20.05.94
655 ******************************************************************************/
ui_map_scale(Widget w)656 static void ui_map_scale(Widget w)
657 {
658 Window scale_win;
659 int n;
660 uint size = 10;
661 char buf[80];
662
663 scale_win = XtWindow(w);
664 XClearWindow(ui_display,scale_win);
665
666 if(ui_col_monochromeMode){
667 /* on B/W screens display a row of different sized squares */
668 sprintf(buf,"%-g",MAP_minWght);
669 XDrawString(ui_display,scale_win,MAP_GRAPH_gc[0],0,10,buf,
670 strlen(buf));
671 for(n=1; n<=10; n++){
672 size = (uint)(10 - n);
673 XDrawRectangle(ui_display,scale_win,MAP_GRAPH_gc[0],
674 10*(n-1),14+(int)(n/2),size,size);
675 }
676 for(n=11; n<=19; n++){
677 size = (uint)(n - 10);
678 XFillRectangle(ui_display,scale_win,MAP_GRAPH_gc[0],
679 10*(n-1),14+(int)((20-n)/2),size,size);
680 }
681 sprintf(buf,"%g",MAP_maxWght);
682 XDrawString(ui_display,scale_win,MAP_GRAPH_gc[0],190-strlen(buf)*7,
683 10,buf,strlen(buf));
684 }else{ /* on color screens display the color range */
685 sprintf(buf,"%-g",MAP_minWght);
686 XDrawString(ui_display,scale_win,MAP_GRAPH_gc[20],0,10,buf,
687 strlen(buf));
688 for(n=1; n<=19; n++){
689 XFillRectangle(ui_display,scale_win,MAP_GRAPH_gc[n],
690 10*(n-1),12,size,size);
691 }
692 sprintf(buf,"%g",MAP_maxWght);
693 XDrawString(ui_display,scale_win,MAP_GRAPH_gc[20],190-strlen(buf)*7,
694 10,buf,strlen(buf));
695 }
696 }
697
698
699 /*****************************************************************************
700 FUNCTION : ui_map_geometry
701
702 PURPOSE : compute the geometry of the displays and the size of the squares
703 NOTES :
704 RETURNS :
705 UPDATE : 22.09.1994
706 ******************************************************************************/
ui_map_geometry(int zoom_fact)707 static void ui_map_geometry(int zoom_fact)
708 {
709 int maxstepsX,maxstepsY;
710 int n;
711 XtWidgetGeometry geo_info, geo_data;
712 XtWidgetGeometry disp_info, disp_data;
713 XtWidgetGeometry view_info, view_data;
714 XtGeometryResult geo_result;
715
716
717 /* do nothing, if no network defined */
718
719 if( krui_getNoOfUnits() == 0)
720 return;
721 maxstepsX = (int) (MAP_xMax-MAP_xMin)/MAP_scaleX;
722 maxstepsY = (int) (MAP_yMax-MAP_yMin)/MAP_scaleY;
723
724
725 /* set the necessary xlib environment variables */
726
727 if(ui_col_monochromeMode){
728 /* this is a B&W terminal */
729 MAP_GRAPH_gc[0] = XCreateGC(ui_display,MAP_GRAPH_win,0,0);
730 } else {
731 /* this is a color terminal */
732 for(n=0;n<=20;n++)
733 MAP_GRAPH_gc[n] = XCreateGC(ui_display,MAP_GRAPH_win,0,0);
734
735 /* set the foreground and background colors */
736 for(n=0; n<10;n++){
737 XSetForeground(ui_display,MAP_GRAPH_gc[n],
738 (uint) ui_col_rangePixels[(int)(n*1.7)]);
739 XSetBackground(ui_display,MAP_GRAPH_gc[n],
740 WhitePixel(ui_display,MAP_GRAPH_screen));
741 XSetForeground(ui_display,MAP_GRAPH_gc[10+n],
742 (uint) ui_col_rangePixels[(int)(15+n*1.7)]);
743 XSetBackground(ui_display,MAP_GRAPH_gc[10+n],
744 WhitePixel(ui_display,MAP_GRAPH_screen));
745 }
746 }
747
748
749 /* get widget geometry */
750
751 geo_result = XtQueryGeometry(MAP_GRAPH_mainwidget,&geo_data,&geo_info);
752
753 if(geo_result != XtGeometryYes){
754 geo_info.height = 400;
755 geo_info.width = 400;
756 }
757 if(zoom_fact != 0){
758 XtResizeWidget(MAP_GRAPH_mainwidget,geo_info.width,
759 geo_info.height,geo_info.border_width);
760 }
761
762
763 /* adjust squaresize */
764
765 if(ui_col_monochromeMode){ /* this is a B&W terminal */
766 MAP_BW_squaresizeX = MAP_BW_squaresizeX + zoom_fact;
767 MAP_BW_squaresizeY = MAP_BW_squaresizeY + zoom_fact;
768 if(MAP_BW_squaresizeX == 0)MAP_BW_squaresizeX = 1;
769 if(MAP_BW_squaresizeY == 0)MAP_BW_squaresizeY = 1;
770 MAP_windowsizeX = MAP_BW_squaresizeX*maxstepsX+40;
771 MAP_windowsizeY = MAP_BW_squaresizeY*maxstepsY+40;
772 }else{ /* this is a color terminal */
773 MAP_squaresizeX = MAP_squaresizeX + zoom_fact;
774 MAP_squaresizeY = MAP_squaresizeY + zoom_fact;
775 if(MAP_squaresizeX == 0)MAP_squaresizeX = 1;
776 if(MAP_squaresizeY == 0)MAP_squaresizeY = 1;
777 MAP_windowsizeX = MAP_squaresizeX*maxstepsX+62;
778 MAP_windowsizeY = MAP_squaresizeY*maxstepsY+62;
779 }
780
781
782 /* Resize all involved windows so that they fit the data and the screen */
783
784 XtResizeWidget(MAP_GRAPH_displaywidget,MAP_windowsizeX+62,
785 MAP_windowsizeY+62,0);
786 MAP_viewsizeX = MAP_squaresizeX * maxstepsX;
787 MAP_viewsizeY = MAP_squaresizeY * maxstepsY;
788 geo_result = XtQueryGeometry(MAP_GRAPH_displaywidget,
789 &disp_data,&disp_info);
790 geo_result = XtQueryGeometry(view,&view_data,&view_info);
791 if(view_info.width > disp_info.width)
792 XtResizeWidget(view,disp_info.width,
793 disp_info.height,view_info.border_width);
794 else
795 if(disp_info.width < geo_info.width)
796 XtResizeWidget(view,disp_info.width,
797 disp_info.height,view_info.border_width);
798 else
799 XtResizeWidget(view,geo_info.width,
800 geo_info.height,view_info.border_width);
801
802 }
803
804
805 /*****************************************************************************
806 FUNCTION : ui_map_grid
807
808 PURPOSE : draws a grid over the MAP squares and the axis
809 NOTES : type == 1 for color display; == 0 for B/W
810 RETURNS :
811 UPDATE : 20.05.1994
812 ******************************************************************************/
813 static void
ui_map_grid(int type)814 ui_map_grid(int type)
815 {
816 char x_String[40], y_String[40];
817 int x_steps,y_steps;
818 int n = 0;
819 float x_no,y_no,x_foo=0,y_foo=0;
820 int actual_sizeX,actual_sizeY;
821 XPoint p1,p2,p3,p4;
822 static char dash[]={6,6,6};
823
824 /* do nothing, if no network defined */
825 if(type == 0){
826 if( krui_getNoOfUnits() == 0 ||
827 (MAP_BW_squaresizeX == 0) || (MAP_BW_squaresizeY == 0) )return;
828 }else{
829 if( krui_getNoOfUnits() == 0 ||
830 (MAP_squaresizeX == 0) || (MAP_squaresizeY == 0) )return;
831 }
832
833 /* set the square size */
834 if(type == 0){
835 actual_sizeX = MAP_BW_squaresizeX;
836 actual_sizeY = MAP_BW_squaresizeY;
837 }else{
838 actual_sizeX = MAP_squaresizeX;
839 actual_sizeY = MAP_squaresizeY;
840 }
841
842 /* set output grid of units */
843 dash[0] = dash[1] = (int)(actual_sizeX*0.5 +0.5);
844 XSetDashes(ui_display,MAP_GRAPH_gc[20*type],
845 (int)(actual_sizeX*0.5 +0.5)+20*type,dash,2);
846 XSetLineAttributes(ui_display,MAP_GRAPH_gc[20*type],0,LineOnOffDash,
847 CapButt,JoinMiter);
848
849 x_steps = (int)((MAP_xMax - MAP_xMin)/MAP_scaleX);
850 y_steps = (int)((MAP_yMax - MAP_yMin)/MAP_scaleY);
851 x_no = MAP_xMin;
852 y_no = MAP_yMin;
853
854 while(n <= 10){
855 sprintf(x_String,"%1.1f",x_no);
856 sprintf(y_String,"%1.1f",y_no);
857 p1.x = (int)(x_foo)+20;
858 p1.y = 10;
859 p2.x = (x_steps)*actual_sizeX+30;
860 p2.y = (int)(y_foo)+20;
861 p3.x = 0;
862 p3.y = p2.y;
863 p4.x = p1.x;
864 p4.y = (y_steps)*actual_sizeY+20;
865
866 XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type],
867 p1.x,p1.y,x_String,(int)strlen(x_String));
868 XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type],
869 p2.x,p2.y,y_String,(int)strlen(y_String));
870 XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type],
871 p3.x,p3.y,y_String,(int)strlen(y_String));
872 XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type],
873 p4.x,p4.y+20,x_String,(int)strlen(x_String));
874 XDrawLine(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type],
875 p1.x,p1.y,p4.x,p4.y);
876 XDrawLine(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type],
877 p2.x,p2.y,p3.x+10,p3.y);
878 n ++;
879 x_foo = (type==0)?x_foo+(float)(x_steps*MAP_BW_squaresizeX)/10.0:
880 x_foo+(float)(x_steps*MAP_squaresizeX)/10.0;
881 y_foo = (type==0)?y_foo+(float)(y_steps*MAP_BW_squaresizeY)/10.0:
882 y_foo+(float)(y_steps*MAP_squaresizeY)/10.0;
883 x_no += (MAP_xMax-MAP_xMin)/10.0;
884 y_no += (MAP_yMax-MAP_yMin)/10.0;
885 }
886 XSetLineAttributes(ui_display,MAP_GRAPH_gc[20*type],0,
887 LineSolid,CapButt,JoinMiter);
888 }
889 /* end of file */
890
891