home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_displwght.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  31.7 KB  |  1,101 lines

  1. /*****************************************************************************
  2.   FILE           : ui_displwght.c
  3.   SHORTNAME      : ui_displwght
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : contains all routines to display the weights as Hinton or
  7.                    WV- diagrams
  8.  
  9.  
  10.   NOTES          :  Functions: 
  11.              -- ui_displWeights
  12.                 Purpose : Main program to display the weights of the network
  13.                 Calls   : krui_getNoOfUnits()
  14.                           ui_confirmOk()
  15.                           DisplayPlanes()
  16.                           ui_xCreateButtonItem()
  17.                           ui_createMyScreen()
  18.          -- ui_wght_event:
  19.             Purpose : event handler for graphic window
  20.         Calls   :ui_wght_geometry();
  21.                      ui_displWeightsBW();
  22.              ui_displWeightsCOL();
  23.                  ui_wght_grid();
  24.              -- ui_displWeightsBW
  25.                 Purpose : Display the weights of the network in black and white
  26.                 Calls   : krui_getNoOfUnits()
  27.                           krui_getFirstUnit()
  28.                           krui_setCurrentUnit()
  29.                           krui_getFirstPredUnit()
  30.                           krui_getNextPredUnit()
  31.                           krui_getNextUnit()
  32.              -- ui_displWeightsCOL
  33.                 Purpose : Display the weights of the network in color
  34.                 Calls   : krui_getNoOfUnits()
  35.                           krui_getFirstUnit()
  36.                           krui_setCurrentUnit()
  37.                           krui_getFirstPredUnit()
  38.                           krui_getNextPredUnit()
  39.                           krui_getNextUnit()
  40.              -- ui_displWeightsFromUpdate
  41.                 Purpose : Interface program, used if net was updated and has 
  42.                           to be redrawn.
  43.                 Calls   : krui_getNoOfUnits()
  44.                           ui_displWeights()
  45.                           ui_displWeightsBW()
  46.                           ui_displWeightsCOL()
  47.              -- ui_wght_close
  48.                 Purpose : notify xgui about the destruction of the window
  49.                 Calls   : XtDestroyWidget()
  50.          -- ui_wght_info
  51.             Purpose : Program to display information about the weights
  52.          -- ui_wght_setup
  53.             Purpose : Setup panel for the grid width and the color scale 
  54.          -- ui_wght_close_setup
  55.             Purpose : notify xgui about the destruction of the setup 
  56.                   panel and read out the widget values
  57.          -- ui_wght_scale
  58.             Purpose : Program to display the scale of colors /scale of 
  59.                   square sizes
  60.          -- ui_wght_zoom_in
  61.             Purpose : Zomms onto the weight squares
  62.          -- ui_wght_zoom_out
  63.             Purpose : Zomms away from the weight squares
  64.          -- ui_wght_geometry
  65.             Purpose : compute the geometry of the displays and the 
  66.                   size of the squares
  67.          -- ui_wght_grid
  68.             Purpose : draws a grid over the weight squares and the axis
  69.  
  70.  
  71.   AUTHOR         : Guenter Mamier 
  72.   DATE           : 05.08.1993 
  73.  
  74.   CHANGED BY     : Sven Doering
  75.   IDENTIFICATION : @(#)ui_displwght.c    1.14 3/2/94
  76.   SCCS VERSION   : 1.14
  77.   LAST CHANGE    : 3/2/94
  78.  
  79.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  80.  
  81.  
  82. ******************************************************************************/
  83. #include <stdio.h>            /* For the Syntax message */
  84.  
  85. #include "ui.h"
  86.  
  87. #include <X11/Intrinsic.h>
  88. #include <X11/IntrinsicP.h>
  89. #include <X11/StringDefs.h>
  90. #include <X11/Xaw/Text.h>
  91. #include <X11/Xaw/TextSrc.h>
  92. #include <X11/Shell.h>
  93. #include <X11/cursorfont.h>
  94. #include <X11/Xaw/MenuButton.h>
  95. #include <X11/Xaw/Form.h>
  96. #include <X11/Xaw/Box.h>
  97. #include <X11/Xaw/Cardinals.h>
  98. #include <X11/Xaw/Command.h>
  99. #include <X11/Xaw/Dialog.h>
  100. #include <X11/Xaw/List.h>
  101. #include <X11/Xaw/Label.h>
  102. #include <X11/Xaw/AsciiText.h>
  103. #include <X11/Xaw/Scrollbar.h>
  104. #include <X11/Xaw/Viewport.h>
  105.  
  106. #include "kr_ui.h"
  107. #include "ui_xWidgets.h"
  108. #include "ui_confirmer.h"
  109. #include "ui_funcdispl.h"
  110.  
  111. #include "ui_displwght.ph"
  112. #include "ui_main.h"
  113. #include "ui_color.h"
  114. #include "ui_mainP.h"
  115. #include "ui_setup.h"
  116.  
  117.  
  118.  
  119. /*****************************************************************************
  120.   FUNCTION : ui_displWeights
  121.  
  122.   PURPOSE  : Main program to display the weights of the network
  123.   NOTES    : Initializes widgets and switches for color or b&w terminal
  124.   RETURNS  : 
  125.   UPDATE   : 29.01.92
  126. ******************************************************************************/
  127.  
  128. void ui_displWeights(Widget w, caddr_t call_data)
  129. {
  130.     Widget donebutton,setbutton,framewidget,zoomin,zoomout;
  131.     int maxunits;
  132.     Arg           args[25];   
  133.     Cardinal       n = 0;
  134.     char           buf[40];
  135.  
  136.  
  137.     /* do nothing, if no network is defined */
  138.  
  139.     if( (maxunits = krui_getNoOfUnits()) == 0){
  140.       ui_confirmOk("No network loaded !");
  141.       return;
  142.     }
  143.  
  144.  
  145.     /* If a weight window already exists, just put it on top */
  146.  
  147.     if(WEIGHT_WINDOW_created == 1){
  148.        Window root;
  149.        int    x, y;
  150.        unsigned int borderWidth, depth, width, height;
  151.        XWindowChanges xChange;
  152.  
  153.        (void) XGetGeometry(ui_display, XtWindow(WEIGHT_GRAPH_mainwidget),
  154.                &root,&x,&y,&width,&height,&borderWidth,&depth);
  155.        xChange.stack_mode = (int) Above;
  156.        XConfigureWindow(ui_display, XtWindow(WEIGHT_GRAPH_mainwidget), 
  157.             CWStackMode, &xChange);
  158.        return;
  159.     }
  160.  
  161.  
  162.     /* Create all necessary widgets */
  163.  
  164.     n = 0;
  165.     sprintf(buf,"Weight Visualization\n");
  166.     WEIGHT_GRAPH_mainwidget = 
  167.            XtCreatePopupShell(buf,topLevelShellWidgetClass,ui_toplevel,args,n);
  168.     n = 0;
  169.     framewidget = XtCreateManagedWidget("form",formWidgetClass,
  170.                     WEIGHT_GRAPH_mainwidget,args,n);
  171.     donebutton  = ui_xCreateButtonItem("done", framewidget, NULL, NULL);
  172.  
  173.     if(WEIGHT_gridWidth == 0)
  174.     WEIGHT_gridWidth = ((int)(0.1*maxunits)<1)? 1: 0.1*maxunits;
  175.     minWght = (float)-ui_maxWeight;
  176.     maxWght = (float)ui_maxWeight;
  177.     zoomin = ui_xCreateButtonItem("zoomin",framewidget,NULL,donebutton);
  178.     setbutton = ui_xCreateButtonItem("setup",framewidget,zoomin,NULL);
  179.     zoomout = ui_xCreateButtonItem("zoomout",framewidget,zoomin,donebutton);
  180.  
  181.     n = 0;
  182.     XtSetArg(args[n], XtNx, 0);n++;
  183.     XtSetArg(args[n], XtNy, 0);n++;
  184.     XtSetArg(args[n], XtNwidth, 210); n++;
  185.     XtSetArg(args[n], XtNheight, 25); n++;
  186.     XtSetArg(args[n], XtNinternalHeight, 1); n++;
  187.     XtSetArg(args[n], XtNinternalWidth , 1); n++;
  188.     XtSetArg(args[n], XtNborderWidth,  0); n++;
  189.     XtSetArg(args[n], XtNhorizDistance, 30);      n++;
  190.     XtSetArg(args[n], XtNfromHoriz, setbutton);      n++;
  191.     XtSetArg(args[n], XtNfromVert, NULL); n++;
  192.     XtSetArg(args[n], XtNleft  , XtChainLeft);  n++;
  193.     XtSetArg(args[n], XtNright , XtChainLeft); n++;
  194.     XtSetArg(args[n], XtNtop   , XtChainTop);   n++;
  195.     XtSetArg(args[n], XtNbottom, XtChainTop);n++;
  196.     scale = XtCreateManagedWidget("Label",formWidgetClass,framewidget,args,n);
  197.  
  198.     n = 0;
  199.     XtSetArg(args[n], XtNx, 0);n++;
  200.     XtSetArg(args[n], XtNy, 0);n++;
  201.     XtSetArg(args[n], XtNborderWidth,  1); n++;
  202.     XtSetArg(args[n], XtNwidth,  WEIGHT_windowsize+62); n++;
  203.     XtSetArg(args[n], XtNheight, WEIGHT_windowsize+62); n++;
  204.     XtSetArg(args[n], XtNallowHoriz, TRUE);n++;
  205.     XtSetArg(args[n], XtNallowVert, TRUE);n++;
  206.     XtSetArg(args[n], XtNforceBars, TRUE);n++;
  207.     XtSetArg(args[n], XtNfromHoriz, NULL);      n++;
  208.     XtSetArg(args[n], XtNfromVert, zoomin); n++;
  209.     XtSetArg(args[n], XtNvertDistance, 10); n++;
  210.     XtSetArg(args[n], XtNleft  , XtChainLeft);  n++;
  211.     XtSetArg(args[n], XtNright , XtChainRight); n++;
  212.     XtSetArg(args[n], XtNtop   , XtChainTop);   n++;
  213.     XtSetArg(args[n], XtNbottom, XtChainBottom);n++;
  214.     view = XtCreateManagedWidget("view",viewportWidgetClass,framewidget,args,n);
  215.     WEIGHT_GRAPH_displaywidget =
  216.            ui_createMyScreen("screen",view,WEIGHT_windowsize,WEIGHT_windowsize,
  217.                  NULL,scale);
  218.     WEIGHT_WINDOW_created = 1;
  219.  
  220.  
  221.     /* define the routines to be called for widget events */
  222.  
  223.     XtAddCallback(donebutton, XtNcallback,
  224.           (XtCallbackProc)ui_wght_close,WEIGHT_GRAPH_mainwidget);
  225.     XtAddCallback(setbutton, XtNcallback,(XtCallbackProc)ui_wght_setup,NULL);
  226.     XtAddCallback(zoomin, XtNcallback,(XtCallbackProc)ui_wght_zoom_in,NULL);
  227.     XtAddCallback(zoomout, XtNcallback,(XtCallbackProc)ui_wght_zoom_out,NULL);
  228.     XtAddEventHandler(WEIGHT_GRAPH_displaywidget,
  229.               ButtonPressMask|ButtonReleaseMask,FALSE,
  230.               (XtEventHandler) ui_wght_info,NULL);
  231.     XtAddEventHandler(WEIGHT_GRAPH_displaywidget, 
  232.               StructureNotifyMask | ExposureMask, GraphicsExpose,
  233.               (XtEventHandler) ui_wght_event,ui_display);
  234.  
  235.  
  236.     /* set the maximum size of each square and the size of the whole window */
  237.  
  238.     if(ui_col_monochromeMode){
  239.        /* B&W terminal => variable square size needed */
  240.        WEIGHT_squaresize = (maxunits > WEIGHT_viewsize/HINTON_squaresize)? 
  241.                        HINTON_squaresize: 
  242.                        (int)((float)WEIGHT_viewsize/(float)maxunits);
  243.        WEIGHT_windowsize = WEIGHT_squaresize*maxunits+40;
  244.     }else{
  245.        /* color terminal => fixed square size */
  246.        WEIGHT_squaresize = 
  247.               (maxunits > WEIGHT_viewsize/5)?5:(int)(WEIGHT_viewsize/maxunits);
  248.        WEIGHT_windowsize = WEIGHT_squaresize*maxunits+40;
  249.     }
  250.  
  251.  
  252.     /* Realize the window */
  253.  
  254.     XtPopup(WEIGHT_GRAPH_mainwidget, XtGrabNone);
  255.  
  256.     WEIGHT_GRAPH_screen = DefaultScreen(ui_display);
  257.     WEIGHT_GRAPH_win    = XtWindow(WEIGHT_GRAPH_displaywidget);
  258.  
  259.       
  260. }
  261.  
  262.  
  263.  
  264.  
  265. /*****************************************************************************
  266.   FUNCTION : ui_wght_event
  267.  
  268.   PURPOSE  : event handler for graphic window
  269.   NOTES    : 
  270.   RETURNS  :
  271.   UPDATE   : 20.02.92
  272. *****************************************************************************/
  273. static void ui_wght_event(Widget w, Display *display, XEvent *event)
  274. {
  275.  
  276.     int zooming    = 0;
  277.     int col_screen = 1;
  278.     int bw_screen  = 0;
  279.  
  280.     switch (event->type){
  281.         case Expose:
  282.                if (event->xexpose.count == 0)
  283.  
  284.            if(ui_col_monochromeMode){
  285.                /* this is a  B&W terminals, so use ui_displWeightsBW */
  286.                ui_wght_geometry(zooming);
  287.                    ui_displWeightsBW();
  288.                ui_wght_grid(bw_screen);
  289.            }else{
  290.                ui_wght_geometry(zooming);
  291.                ui_displWeightsCOL();
  292.                ui_wght_grid(col_screen);
  293.            }
  294.            break;
  295.     default:
  296.            break;
  297.     }
  298. }
  299.  
  300.  
  301.  
  302.  
  303. /*****************************************************************************
  304.   FUNCTION : ui_displWeightsBW
  305.  
  306.   PURPOSE  : Program to display the weights of the network in black and white
  307.   NOTES    :
  308.   RETURNS  : 
  309.   UPDATE   : 04.08.93
  310. ******************************************************************************/
  311.  
  312. static void ui_displWeightsBW(void)
  313. {
  314.    int  maxunits,step;
  315.    int  n,next,pred;
  316.    FlintType strength;
  317.    float reference;
  318.    int xx,yy;
  319.    uint dx,dy;
  320.  
  321.  
  322.    /* clear the window */
  323.  
  324.    XSetForeground(ui_display, WEIGHT_GRAPH_gc[0], 
  325.           BlackPixel(ui_display,WEIGHT_GRAPH_screen));
  326.    XSetBackground(ui_display, WEIGHT_GRAPH_gc[0], 
  327.           WhitePixel(ui_display,WEIGHT_GRAPH_screen));
  328.    XClearWindow(ui_display,WEIGHT_GRAPH_win);
  329.  
  330.  
  331.    /* draw the weight squares */
  332.  
  333.    n = 1;
  334.    next = krui_getFirstUnit();
  335.    krui_setCurrentUnit(next);
  336.    reference = (float)HINTON_squaresize / (float)((maxWght-minWght)/2); 
  337.    do{
  338.       if((pred=krui_getFirstPredUnit(&strength)) !=0){
  339.          do{
  340.         strength = (strength > maxWght)? maxWght: strength;
  341.         strength = (strength < minWght)? minWght: strength;
  342.         dx = dy = abs( (int)(reference * (float)strength));
  343.         xx = (int)(pred*HINTON_squaresize-HINTON_squaresize*0.5-dx*0.5)+20;
  344.         yy = (int)(next*HINTON_squaresize-HINTON_squaresize*0.5-dy*0.5)+20;
  345.  
  346.         if(strength > 0.0){
  347.            XFillRectangle(ui_display,WEIGHT_GRAPH_win,
  348.                   WEIGHT_GRAPH_gc[0],xx,yy,dx,dy);
  349.         }else{
  350.            XDrawRectangle(ui_display,WEIGHT_GRAPH_win,
  351.                   WEIGHT_GRAPH_gc[0],xx,yy,dx,dy);
  352.         }
  353.      }while( (pred=krui_getNextPredUnit(&strength)) != 0);
  354.       }
  355.     }while((next=krui_getNextUnit()) != 0);
  356.  
  357.   
  358.    /* draw the scale */
  359.  
  360.    ui_wght_scale(scale); 
  361.  
  362.  
  363.    /* get everything on the screen */
  364.  
  365.    XFlush(ui_display);
  366.  
  367.  
  368.  
  369.  
  370. /*****************************************************************************
  371.   FUNCTION : ui_displWeightsCOL
  372.  
  373.   PURPOSE  : Program to display the weights of the network in color
  374.   NOTES    :
  375.   RETURNS  : 
  376.   UPDATE   : 04.08.93
  377. ******************************************************************************/
  378.  
  379. static void ui_displWeightsCOL(void)
  380. {
  381.    int  next,pred;
  382.    FlintType strength;
  383.    float maxStrength;
  384.    int xx,yy;
  385.    uint dx,dy;
  386.  
  387.  
  388.    /* clear the window */
  389.    
  390.    XSetForeground(ui_display, WEIGHT_GRAPH_gc[20], 
  391.           BlackPixel(ui_display,WEIGHT_GRAPH_screen));
  392.    XSetBackground(ui_display, WEIGHT_GRAPH_gc[20], 
  393.           WhitePixel(ui_display,WEIGHT_GRAPH_screen));
  394.    XClearWindow(ui_display,WEIGHT_GRAPH_win);
  395.  
  396.  
  397.    /* draw the weight squares */
  398.  
  399.    dx = dy = WEIGHT_squaresize;
  400.    next = krui_getFirstUnit();
  401.    krui_setCurrentUnit(next);
  402.    do{
  403.       if((pred=krui_getFirstPredUnit(&strength)) !=0){
  404.          do{
  405.         xx = (int)(pred-1)*WEIGHT_squaresize+20;
  406.         yy = (int)(next-1)*WEIGHT_squaresize+20;
  407.         strength = 20*strength/(maxWght-minWght);
  408.         strength = (strength > 9)?  9: strength;
  409.         strength = (strength <-9)? -9: strength;
  410.         XFillRectangle(ui_display,WEIGHT_GRAPH_win,
  411.                WEIGHT_GRAPH_gc[(int)(10.0 + (float)strength)],
  412.                xx,yy,dx,dy);
  413.      }while( (pred=krui_getNextPredUnit(&strength)) != 0);
  414.       }
  415.     }while((next=krui_getNextUnit()) != 0);
  416.  
  417.  
  418.    /* draw the scale */
  419.  
  420.    ui_wght_scale(scale);
  421.  
  422.    /* get everything on the screen */
  423.  
  424.    XFlush(ui_display);
  425. }
  426.  
  427.  
  428.  
  429.  
  430. /*****************************************************************************
  431.   FUNCTION : ui_displWeightsFromUpdate
  432.  
  433.   PURPOSE  : Interface program, used if net was updated and has to be redrawn.
  434.   NOTES    :
  435.   RETURNS  : 
  436.   UPDATE   : 29.01.92
  437. ******************************************************************************/
  438. void ui_displWeightsFromUpdate(void)
  439. {
  440.    int maxunits;
  441.  
  442.    if( !WEIGHT_WINDOW_created )return;
  443.  
  444.  
  445.    if(((maxunits=krui_getNoOfUnits()) != old_maxunits)  && old_maxunits){
  446.       /* New network was loaded with different # of units *
  447.        * ==> new viewport has to be created               */
  448.       XtDestroyWidget(WEIGHT_GRAPH_mainwidget);
  449.       old_maxunits = maxunits;
  450.       WEIGHT_WINDOW_created = 0;
  451.       WEIGHT_viewsize   = 400;
  452.       HINTON_squaresize =  16;
  453.       WEIGHT_squaresize =   0;
  454.       ui_displWeights(WEIGHT_GRAPH_displaywidget,NULL);
  455.    }else{
  456.  
  457.       /* old network was only updated, so redraw is sufficient */
  458.       if(ui_col_monochromeMode){
  459.          ui_displWeightsBW();
  460.       }else{
  461.          ui_displWeightsCOL();
  462.      }
  463.  
  464.    }
  465. }
  466.  
  467.  
  468.  
  469. /*****************************************************************************
  470.   FUNCTION : ui_wght_close
  471.  
  472.   PURPOSE  : notify xgui about the destruction of the window
  473.   NOTES    :
  474.   RETURNS  : 
  475.   UPDATE   : 29.01.92
  476. ******************************************************************************/
  477. static void ui_wght_close(Widget dummy, Widget w, caddr_t call_data)
  478. {
  479.    XtDestroyWidget(w);
  480.    WEIGHT_WINDOW_created = 0;
  481.    WEIGHT_gridWidth = 0;
  482.    old_maxunits = 0;
  483. }
  484.  
  485.  
  486.  
  487. /*****************************************************************************
  488.   FUNCTION : ui_wght_info
  489.  
  490.   PURPOSE  : Program to display information about the weights
  491.   NOTES    :
  492.   RETURNS  : 
  493.   UPDATE   : 03.08.93
  494. ******************************************************************************/
  495.  
  496. static void ui_wght_info(Widget w, Display *display, XEvent *event)
  497. {
  498.     Widget ui_wei_popup;
  499.     static Bool ui_wei_exit = TRUE;
  500.     int xval,yval;
  501.     int actual_size;
  502.     FlintType con_weight;
  503.     char buf[40];
  504.     Widget label,form;
  505.     uint n;
  506.  
  507.     Arg args[5];
  508.     
  509.  
  510.    /* set the square size */
  511.  
  512.    if(ui_col_monochromeMode)
  513.        actual_size = HINTON_squaresize;
  514.    else 
  515.        actual_size = WEIGHT_squaresize;
  516.  
  517.  
  518.     switch(event->type){
  519.         case ButtonPress: 
  520.  
  521.              /* get unit numbers of clicked at connection */
  522.          xval = (int)((float)(event->xbutton.x-20) /
  523.               (float)(actual_size))+1;
  524.          yval = (int)((float)(event->xbutton.y-20) /
  525.               (float)actual_size)+1;
  526.  
  527.          /* do nothing for invalid numbers */
  528.          if(xval<0 || yval<0)return;
  529.          if(xval>krui_getNoOfUnits() || yval>krui_getNoOfUnits())return;
  530.  
  531.          /* create  label and popup */
  532.          if(krui_areConnected(xval,yval,&con_weight))
  533.             sprintf(buf,"Link %d -> %d \nhas weight %f"
  534.             ,xval,yval,con_weight);
  535.          else
  536.             sprintf(buf,"No connection from unit %d to unit %d\n",
  537.                xval,yval);
  538.          ui_wei_popup = XtCreatePopupShell("info",overrideShellWidgetClass,
  539.                            ui_toplevel,NULL, 0);
  540.          form = XtCreateManagedWidget("form",formWidgetClass,ui_wei_popup, 
  541.                        NULL,0);
  542.          n = 0;
  543.          XtSetArg(args[n], XtNfromHoriz, NULL); n++;
  544.          XtSetArg(args[n], XtNborderWidth, 0); n++;
  545.          XtSetArg(args[n], XtNlabel, buf); n++;
  546.          label = XtCreateManagedWidget("weiMsg",labelWidgetClass,form,
  547.                        args,n);
  548.          XawFormDoLayout(form, True);
  549.          XtRealizeWidget(ui_wei_popup);
  550.     
  551.          /* now move the popup to the mouse position */
  552.          {
  553.            Window root;
  554.            int    x, y;
  555.            unsigned int borderWidth, depth, width, height;
  556.            XWindowChanges xChange;
  557.  
  558.            (void) XGetGeometry(ui_display, XtWindow(ui_wei_popup),
  559.                    &root, &x, &y, &width, &height, 
  560.                    &borderWidth, &depth);
  561.  
  562.            xChange.x = event->xbutton.x_root;
  563.            xChange.y = event->xbutton.y_root;
  564.            xChange.stack_mode = (int) Above;
  565.            XConfigureWindow(ui_display, XtWindow(ui_wei_popup), 
  566.                 CWX BIT_OR CWY BIT_OR CWStackMode, &xChange);
  567.          }
  568.  
  569.          XtPopup(ui_wei_popup, XtGrabExclusive);
  570.          ui_wei_exit = FALSE;
  571.          while (NOT ui_wei_exit) {
  572.             XtAppNextEvent(ui_appContext, event);
  573.         if(event->type == ButtonRelease){
  574.            XtDestroyWidget(ui_wei_popup);
  575.            ui_wei_exit = TRUE;
  576.         }
  577.             (void) XtDispatchEvent(event);
  578.          }
  579.              break;
  580.  
  581.         default: /* ignore all other events */
  582.              break;
  583.     }
  584. }
  585.  
  586.  
  587.  
  588.  
  589. /*****************************************************************************
  590.   FUNCTION : ui_wght_setup
  591.  
  592.   PURPOSE  : Setup panel for the grid width and the color scale 
  593.   NOTES    :
  594.   RETURNS  : 
  595.   UPDATE   : 04.08.93
  596. ******************************************************************************/
  597.  
  598. static void ui_wght_setup(Widget button, caddr_t call_data)
  599. {
  600.  
  601.  
  602.     Widget      grid_lab,grid_win,WEIGHT_GRAPH_setupwidget;
  603.     Widget      ui_setupPanel,done,subframe,dummy,range_lab;
  604.     char        buf[80];
  605.     Position    x, y;
  606.     Dimension   width, height;
  607.     Arg        args[25];   
  608.     Cardinal    n = 0;
  609.  
  610.     int         titelWidth  = 32;
  611.     int         floatWidth  = 48;
  612.     int         maxunits;
  613.  
  614.  
  615.     maxunits = krui_getNoOfUnits();
  616.  
  617.     /* set Popup arguments */
  618.  
  619.     n = 0;
  620.     XtSetArg(args[0], XtNwidth, &width);n++;
  621.     XtSetArg(args[1], XtNheight, &height);n++;
  622.     XtGetValues(button, args, n);
  623.     XtTranslateCoords(button, (Position)(width/2), 
  624.               (Position)(height/2), &x, &y);
  625.     n = 0;
  626.     XtSetArg(args[n], XtNx, x);n++;
  627.     XtSetArg(args[n], XtNy, y+50);n++;
  628.  
  629.  
  630.     /* Now create Popup */
  631.  
  632.     WEIGHT_GRAPH_setupwidget = 
  633.     XtCreatePopupShell("Setup", transientShellWidgetClass, 
  634.                ui_toplevel, args, n);
  635.     ui_setupPanel =
  636.     XtCreateManagedWidget("form", formWidgetClass, 
  637.                   WEIGHT_GRAPH_setupwidget, NULL, ZERO);
  638.  
  639.     done = ui_xCreateButtonItem("done", ui_setupPanel, NULL, NULL);
  640.     XtAddCallback (done, XtNcallback, (XtCallbackProc)ui_wght_close_setup,
  641.            WEIGHT_GRAPH_setupwidget);
  642.  
  643.     n = 0;
  644.     XtSetArg(args[n], XtNx, 0);n++;
  645.     XtSetArg(args[n], XtNy, 0);n++;
  646.     XtSetArg(args[n], XtNborderWidth,  1); n++;
  647.     XtSetArg(args[n], XtNfromHoriz, NULL);      n++;
  648.     XtSetArg(args[n], XtNfromVert, done); n++;
  649.     XtSetArg(args[n], XtNleft  , XtChainLeft);  n++;
  650.     XtSetArg(args[n], XtNright , XtChainRight); n++;
  651.     XtSetArg(args[n], XtNtop   , XtChainTop);   n++;
  652.     XtSetArg(args[n], XtNbottom, XtChainBottom);n++;
  653.     subframe = XtCreateManagedWidget("sub",formWidgetClass,
  654.                            ui_setupPanel,args,n);
  655.     grid_lab = ui_xCreateLabelItem("grid width   :", subframe,104, NULL, NULL);
  656.  
  657.     sprintf(buf,"%d", WEIGHT_gridWidth);
  658.     grid_dia = ui_xCreateDialogItem("gridWidth", subframe, buf, 
  659.                     titelWidth, grid_lab,NULL);
  660.  
  661.     range_lab = ui_xCreateLabelItem("weight range :", subframe, 
  662.                     104, NULL, grid_lab);
  663.  
  664.     sprintf(buf,"%g",minWght);
  665.     bottomLabel = ui_xCreateDialogItem("bottLab", subframe, buf, 
  666.                        floatWidth,range_lab,grid_lab);
  667.     dummy = ui_xCreateLabelItem("to",subframe,24,bottomLabel,grid_lab);
  668.     
  669.     sprintf(buf,"%g",maxWght);
  670.     topLabel = ui_xCreateDialogItem("topLab", subframe, buf, 
  671.                     floatWidth, dummy,grid_lab);
  672.  
  673.     n = 0;
  674.     XtSetArg(args[n], XtNx, 0);n++;
  675.     XtSetArg(args[n], XtNy, 0);n++;
  676.     XtSetArg(args[n], XtNwidth, 210); n++;
  677.     XtSetArg(args[n], XtNheight, 25); n++;
  678.     XtSetArg(args[n], XtNinternalHeight, 1); n++;
  679.     XtSetArg(args[n], XtNinternalWidth , 1); n++;
  680.     XtSetArg(args[n], XtNborderWidth,  0); n++;
  681.     XtSetArg(args[n], XtNfromHoriz,range_lab);      n++;
  682.     XtSetArg(args[n], XtNfromVert, range_lab); n++;
  683.     XtSetArg(args[n], XtNleft  , XtChainRight);  n++;
  684.     XtSetArg(args[n], XtNright , XtChainRight); n++;
  685.     XtSetArg(args[n], XtNtop   , XtChainBottom);   n++;
  686.     XtSetArg(args[n], XtNbottom, XtChainBottom);n++;
  687.     scale2 = XtCreateManagedWidget("Label2",formWidgetClass,subframe,args,n);
  688.  
  689.     XtRealizeWidget(WEIGHT_GRAPH_setupwidget);
  690.     XtAddEventHandler(scale2, ExposureMask, GraphicsExpose,
  691.               (XtEventHandler) ui_wght_scale,NULL);
  692.  
  693.  
  694.     /* Realize the window */
  695.  
  696.     XtPopup(WEIGHT_GRAPH_setupwidget, XtGrabExclusive);
  697.  
  698.  
  699.     /* get everything on the screen */
  700.  
  701.     XFlush(ui_display);
  702. }              
  703.  
  704.  
  705. /*****************************************************************************
  706.   FUNCTION : ui_wght_close_setup
  707.  
  708.   PURPOSE  : notify xgui about the destruction of the setup panel and read 
  709.              out the widget values
  710.   NOTES    :
  711.   RETURNS  : 
  712.   UPDATE   : 29.01.92
  713. ******************************************************************************/
  714. static void ui_wght_close_setup(Widget dummy, Widget w, caddr_t call_data)
  715. {
  716.    int depth;
  717.    int test;
  718.  
  719.  
  720.    XtDestroyWidget(w);
  721.  
  722.    /* read/set the setup values */
  723.  
  724.    test = (int)ui_xIntFromAsciiWidget(grid_dia);
  725.    if(test > krui_getNoOfUnits()+10)
  726.        ui_confirmOk("Ignoring unplausible large grid size");
  727.    else if(test > 0)
  728.       WEIGHT_gridWidth = test;
  729.    else
  730.       ui_confirmOk("Negative grid size not allowed!!");
  731.  
  732.    maxWght = (float)ui_xFloatFromAsciiWidget(topLabel);
  733.    minWght = (float)ui_xFloatFromAsciiWidget(bottomLabel);
  734.  
  735.  
  736.    /* update display according to the new values */
  737.  
  738.    if(ui_col_colorDisplay){
  739.        ui_displWeightsCOL();
  740.        ui_wght_scale(scale);
  741.        ui_wght_grid(1);
  742.    }else{
  743.        ui_displWeightsBW();
  744.        ui_wght_scale(scale);
  745.        ui_wght_grid(0);
  746.    }
  747.  
  748.  
  749.    /* get everything on the screen */
  750.  
  751.    XFlush(ui_display);
  752.  
  753. }
  754.  
  755.  
  756.  
  757.  
  758.  
  759. /*****************************************************************************
  760.   FUNCTION : ui_wght_scale
  761.  
  762.   PURPOSE  : Program to display the scale of colors /scale of square sizes
  763.   NOTES    :
  764.   RETURNS  : 
  765.   UPDATE   : 04.08.93
  766. ******************************************************************************/
  767.  
  768. static void ui_wght_scale(Widget w)
  769. {
  770.     Window scale_win;
  771.     int n;
  772.     uint size = 10;
  773.     char buf[80];
  774.  
  775.     scale_win = XtWindow(w);
  776.     XClearWindow(ui_display,scale_win);
  777.     
  778.  
  779.     if(ui_col_monochromeMode){
  780.  
  781.        /* on B/W screens display a row of different sized squares */
  782.  
  783.        sprintf(buf,"%-g",minWght);
  784.        XDrawString(ui_display,scale_win,WEIGHT_GRAPH_gc[0],0,10,buf,
  785.            strlen(buf));
  786.        for(n=1; n<=10; n++){
  787.        size = (uint)(10 - n);
  788.        XDrawRectangle(ui_display,scale_win,WEIGHT_GRAPH_gc[0],
  789.               10*(n-1),14+(int)(n/2),size,size);
  790.        }
  791.        for(n=11; n<=19; n++){
  792.        size = (uint)(n - 10);
  793.        XFillRectangle(ui_display,scale_win,WEIGHT_GRAPH_gc[0],
  794.               10*(n-1),14+(int)((20-n)/2),size,size);       
  795.        }
  796.        sprintf(buf,"%g",maxWght);
  797.        XDrawString(ui_display,scale_win,WEIGHT_GRAPH_gc[0],190-strlen(buf)*7,
  798.            10,buf,strlen(buf));
  799.  
  800.     }else{ /* on color screens display the color range */
  801.  
  802.        sprintf(buf,"%-g",minWght);
  803.        XDrawString(ui_display,scale_win,WEIGHT_GRAPH_gc[20],0,10,buf,
  804.            strlen(buf));
  805.        for(n=1; n<=19; n++){
  806.        XFillRectangle(ui_display,scale_win,WEIGHT_GRAPH_gc[n],
  807.               10*(n-1),12,size,size);
  808.        }
  809.        sprintf(buf,"%g",maxWght);
  810.        XDrawString(ui_display,scale_win,WEIGHT_GRAPH_gc[20],190-strlen(buf)*7,
  811.            10,buf,strlen(buf));
  812.    }
  813. }
  814.  
  815.  
  816.  
  817. /*****************************************************************************
  818.   FUNCTION : ui_wght_zoom_in
  819.  
  820.   PURPOSE  : Zomms onto the weight squares
  821.   NOTES    :
  822.   RETURNS  : 
  823.   UPDATE   : 20.07.1993
  824. ******************************************************************************/
  825.  
  826. static void ui_wght_zoom_in(Widget w)
  827. {
  828.  
  829.  
  830.     /* delete the old screen display */
  831.  
  832.     XClearWindow(ui_display,WEIGHT_GRAPH_win);
  833.  
  834.  
  835.     /* compute new display geometry */
  836.  
  837.     ui_wght_geometry(1);
  838.  
  839.  
  840.     /* display the new setting */
  841.  
  842.     if(ui_col_monochromeMode){
  843.     ui_displWeightsBW();
  844.     ui_wght_grid(0);
  845.     }else{
  846.     ui_displWeightsCOL();
  847.     ui_wght_grid(1);
  848.     }
  849. }
  850.  
  851.  
  852.  
  853.  
  854. /*****************************************************************************
  855.   FUNCTION : ui_wght_zoom_out
  856.  
  857.   PURPOSE  : Zomms away from the weight squares
  858.   NOTES    :
  859.   RETURNS  : 
  860.   UPDATE   : 20.07.1993
  861. ******************************************************************************/
  862.  
  863. static void ui_wght_zoom_out(Widget w)
  864. {
  865.  
  866.  
  867.     /* delete the old screen display */
  868.  
  869.     XClearWindow(ui_display,WEIGHT_GRAPH_win);
  870.  
  871.  
  872.     /* compute new display geometry */
  873.  
  874.     ui_wght_geometry(-1);
  875.  
  876.  
  877.     /* display the new setting */
  878.  
  879.     if(ui_col_monochromeMode){
  880.     ui_displWeightsBW();
  881.     ui_wght_grid(0);
  882.     }else{
  883.     ui_displWeightsCOL();
  884.     ui_wght_grid(1);
  885.     }
  886. }
  887.  
  888.  
  889.  
  890. /*****************************************************************************
  891.   FUNCTION : ui_wght_geometry
  892.  
  893.   PURPOSE  : compute the geometry of the displays and the size of the squares
  894.   NOTES    :
  895.   RETURNS  : 
  896.   UPDATE   : 04.08.1993
  897. ******************************************************************************/
  898.  
  899. static void ui_wght_geometry(int zoom_fact)
  900. {
  901.     int  maxunits,step;
  902.     int  n,next,pred;
  903.     FlintType strength;
  904.     float maxStrength;
  905.     int xx,yy;
  906.     uint dx,dy;
  907.     XtWidgetGeometry geo_info, geo_data;
  908.     XtWidgetGeometry disp_info, disp_data;
  909.     XtWidgetGeometry view_info, view_data;
  910.     XtGeometryResult geo_result;
  911.     Dimension got_w,got_h;
  912.     XEvent *event;
  913.  
  914.  
  915.     /* do nothing, if no network defined */
  916.     
  917.     if( (maxunits = krui_getNoOfUnits()) == 0)return;
  918.  
  919.  
  920.     /* set the necessary xlib environment variables */
  921.  
  922.     if(ui_col_monochromeMode){ /* this is a  B&W terminal */
  923.  
  924.     WEIGHT_GRAPH_gc[0]  = XCreateGC(ui_display,WEIGHT_GRAPH_win,0,0); 
  925.  
  926.     /* set the labeling font */
  927.     XSetFont(ui_display, WEIGHT_GRAPH_gc[0], ui_fontStruct->fid);
  928.     
  929.     }else{ /* this is a color terminal */
  930.    
  931.     for(n=0;n<=20;n++)
  932.         WEIGHT_GRAPH_gc[n] = XCreateGC(ui_display,WEIGHT_GRAPH_win,0,0); 
  933.  
  934.     /* set the labeling font */
  935.     XSetFont(ui_display, WEIGHT_GRAPH_gc[20], ui_fontStruct->fid);
  936.  
  937.  
  938.     /* Allocate color table */
  939.  
  940.     WEIGHT_GRAPH_col = DefaultColormap(ui_display,WEIGHT_GRAPH_screen);
  941.     for(n=0; n<10;n++){
  942.         WEIGHT_GRAPH_color_def[n].red   = 65535;
  943.         WEIGHT_GRAPH_color_def[n].green = n*6553;
  944.         WEIGHT_GRAPH_color_def[n].blue  = n*6553;
  945.         XAllocColor(ui_display,WEIGHT_GRAPH_col,&WEIGHT_GRAPH_color_def[n]);
  946.         WEIGHT_GRAPH_color1[n] = WEIGHT_GRAPH_color_def[n].pixel;
  947.         XSetForeground(ui_display,WEIGHT_GRAPH_gc[n],
  948.                (uint) WEIGHT_GRAPH_color1[n]);
  949.         XSetBackground(ui_display,WEIGHT_GRAPH_gc[n], 
  950.                WhitePixel(ui_display,WEIGHT_GRAPH_screen));
  951.         WEIGHT_GRAPH_color_def[10+n].red   = 65535-n*6553;
  952.         WEIGHT_GRAPH_color_def[10+n].green = 65535;
  953.         WEIGHT_GRAPH_color_def[10+n].blue  = 65535-n*6553;
  954.         XAllocColor(ui_display,WEIGHT_GRAPH_col,
  955.             &WEIGHT_GRAPH_color_def[10+n]);
  956.         WEIGHT_GRAPH_color2[n] = WEIGHT_GRAPH_color_def[10+n].pixel;
  957.         XSetForeground(ui_display,WEIGHT_GRAPH_gc[10+n],
  958.                (uint) WEIGHT_GRAPH_color2[n]);
  959.         XSetBackground(ui_display,WEIGHT_GRAPH_gc[10+n],
  960.                WhitePixel(ui_display,WEIGHT_GRAPH_screen));
  961.     }
  962.     }
  963.     
  964.  
  965.     /* get widget geometry */
  966.  
  967.     geo_result = XtQueryGeometry(WEIGHT_GRAPH_mainwidget,&geo_data,&geo_info);
  968.  
  969.     if(geo_result != XtGeometryYes){
  970.     geo_info.height = 400;
  971.     geo_info.width  = 400;
  972.     }
  973.  
  974.     if(zoom_fact != 0){
  975.     XtResizeWidget(WEIGHT_GRAPH_mainwidget,geo_info.width,
  976.                geo_info.height,geo_info.border_width);
  977.     }
  978.  
  979.  
  980.     /* adjust squaresize */
  981.  
  982.     if(ui_col_monochromeMode){ /* this is a  B&W terminal */
  983.     HINTON_squaresize = HINTON_squaresize + zoom_fact;
  984.     if(HINTON_squaresize == 0)HINTON_squaresize = 1;
  985.     WEIGHT_windowsize = HINTON_squaresize*maxunits+40;
  986.     }else{ /* this is a color terminal */
  987.     WEIGHT_squaresize = WEIGHT_squaresize + zoom_fact;
  988.     if(WEIGHT_squaresize == 0)WEIGHT_squaresize = 1;
  989.     WEIGHT_windowsize = WEIGHT_squaresize*maxunits+62;
  990.     }
  991.  
  992.  
  993.     /* Resize all involved windows so that they fit the data and the screen */
  994.  
  995.     XtResizeWidget(WEIGHT_GRAPH_displaywidget,WEIGHT_windowsize+62,
  996.            WEIGHT_windowsize+62,0);
  997.     WEIGHT_viewsize = WEIGHT_squaresize * maxunits;
  998.  
  999.     geo_result = XtQueryGeometry(WEIGHT_GRAPH_displaywidget,
  1000.                  &disp_data,&disp_info);
  1001.     geo_result = XtQueryGeometry(view,&view_data,&view_info);
  1002.     if(view_info.width > disp_info.width)
  1003.     XtResizeWidget(view,disp_info.width,
  1004.                disp_info.height,view_info.border_width);
  1005.     else
  1006.     if(disp_info.width < geo_info.width)
  1007.         XtResizeWidget(view,disp_info.width,
  1008.                disp_info.height,view_info.border_width);
  1009.     else
  1010.         XtResizeWidget(view,geo_info.width,
  1011.                geo_info.height,view_info.border_width);
  1012.  
  1013.     
  1014.     /* get everything on the screen */
  1015.  
  1016.     XFlush(ui_display);
  1017. }
  1018.  
  1019.  
  1020.  
  1021. /*****************************************************************************
  1022.   FUNCTION : ui_wght_grid
  1023.  
  1024.   PURPOSE  : draws a grid over the weight squares and the axis
  1025.   NOTES    : type == 1 for color display; == 0 for B/W
  1026.   RETURNS  : 
  1027.   UPDATE   : 20.07.1993
  1028. ******************************************************************************/
  1029. static void ui_wght_grid(int type)
  1030. {
  1031.  
  1032.    char outString[40];
  1033.    int  maxunits,step;
  1034.    int  n,next,pred;
  1035.    FlintType strength;  
  1036.    float maxStrength;
  1037.    int xx,yy;
  1038.    int actual_size;
  1039.    uint dx,dy;
  1040.    XPoint p1,p2,p3,p4;
  1041.    static char dash[]={6,6,6};
  1042.  
  1043.  
  1044.  
  1045.     /* do nothing, if no network defined */
  1046.     
  1047.     if( (maxunits = krui_getNoOfUnits()) == 0 || 
  1048.         (WEIGHT_squaresize == 0) )return;
  1049.  
  1050.  
  1051.    /* set the square size */
  1052.  
  1053.    if(ui_col_monochromeMode)
  1054.        actual_size = HINTON_squaresize;
  1055.    else 
  1056.        actual_size = WEIGHT_squaresize;
  1057.  
  1058.  
  1059.  
  1060.    /* set output grid of units */
  1061.  
  1062.    dash[0] = dash[1] = (int)(actual_size*0.5 +0.5);
  1063.    XSetDashes(ui_display,WEIGHT_GRAPH_gc[20*type],
  1064.           (int)(actual_size*0.5 +0.5)+20*type,dash,2);
  1065.    XSetLineAttributes(ui_display,WEIGHT_GRAPH_gc[20*type],0,LineOnOffDash,
  1066.               CapButt,JoinMiter);
  1067.    step = WEIGHT_gridWidth;
  1068.    n = step;
  1069.    while(n <= maxunits){
  1070.       sprintf(outString,"%d",n);
  1071.       p1.x = (int)(actual_size*n-actual_size*0.5)+20;
  1072.       p1.y = 10;
  1073.       p2.x = (maxunits)*actual_size+30;
  1074.       p2.y = (int)(actual_size*n-actual_size*0.5)+20;
  1075.       p3.x = 0; 
  1076.       p3.y = p2.y;
  1077.       p4.x = p1.x;
  1078.       p4.y = (maxunits)*actual_size+20;
  1079.       XDrawString(ui_display,WEIGHT_GRAPH_win,WEIGHT_GRAPH_gc[20*type],
  1080.           p1.x,p1.y,outString,(int)strlen(outString));
  1081.       XDrawString(ui_display,WEIGHT_GRAPH_win,WEIGHT_GRAPH_gc[20*type],
  1082.           p2.x,p2.y,outString,(int)strlen(outString));
  1083.       XDrawString(ui_display,WEIGHT_GRAPH_win,WEIGHT_GRAPH_gc[20*type],
  1084.           p3.x,p3.y,outString,(int)strlen(outString));
  1085.       XDrawString(ui_display,WEIGHT_GRAPH_win,WEIGHT_GRAPH_gc[20*type],
  1086.           p4.x,p4.y+20,outString,(int)strlen(outString));
  1087.       XDrawLine(ui_display,WEIGHT_GRAPH_win,WEIGHT_GRAPH_gc[20*type],
  1088.         p1.x,p1.y,p4.x,p4.y);
  1089.       XDrawLine(ui_display,WEIGHT_GRAPH_win,WEIGHT_GRAPH_gc[20*type],
  1090.         p2.x,p2.y,p3.x+10,p3.y);
  1091.       n += step;
  1092.    }
  1093.    XSetLineAttributes(ui_display,WEIGHT_GRAPH_gc[20*type],0,
  1094.               LineSolid,CapButt,JoinMiter);
  1095.  
  1096. }
  1097.  
  1098. /* end of file */
  1099. /* lines: 1094 */
  1100.