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

  1. /*****************************************************************************
  2.   FILE           : ui_funcdispl.c
  3.   SHORTNAME      : funcdispl
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : contains routines for output function display
  7.   NOTES          :
  8.   FUNCTIONS      : -- ui_functionPopup
  9.                       Purpose : Display the characteristic function of the units
  10.                       Calls   : ui_xCreateButtonItem()
  11.                                 ui_xCreateDialogItem()
  12.                                 ui_createMyScreen()
  13.                    -- ui_createMyScreen
  14.                       Purpose : Create screen for Graphic display
  15.                       Calls   : nothing
  16.                    -- ui_drawFunction
  17.                       Purpose : Draw the functions of the units
  18.                       Calls   : krf_funcSearch()
  19.                    -- local_kill
  20.                       Purpose : Kill the widget for unit function display
  21.                       Calls   : XtDestroyWidget()       
  22.                    -- ui_setXY
  23.                       Purpose : Set the x an y range for the function display
  24.                       Calls   : ui_xFloatFromAsciiWidget()
  25.  
  26.   AUTHOR         : Guenter Mamier 
  27.   DATE           : 14.01.92
  28.  
  29.   CHANGED BY     : Sven Doering
  30.   IDENTIFICATION : @(#)ui_funcdispl.c    1.12 3/2/94
  31.   SCCS VERSION   : 1.12
  32.   LAST CHANGE    : 3/2/94
  33.  
  34.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  35.  
  36. ******************************************************************************/
  37. #include <stdio.h>            /* For the Syntax message */
  38. #include <stdlib.h>
  39.  
  40. #include "ui.h"
  41.  
  42. #include <X11/Shell.h>
  43. #include <X11/cursorfont.h>
  44. #include <X11/Xaw/Text.h>
  45. #include <X11/Xaw/TextSrc.h>
  46. #include <X11/Xaw/MenuButton.h>
  47. #include <X11/Xaw/Form.h>
  48. #include <X11/Xaw/Box.h>
  49. #include <X11/Xaw/Cardinals.h>
  50. #include <X11/Xaw/Command.h>
  51. #include <X11/Xaw/Dialog.h>
  52. #include <X11/Xaw/List.h>
  53. #include <X11/Xaw/AsciiText.h>
  54.  
  55. #include "kr_typ.h"
  56. #include "kernel.h"
  57. #include "ext_typ.h"
  58. #include "kr_funcs.h"
  59. #include "kr_ui.h"
  60. #include "ui_info.h"
  61. #include "ui_setup.h"
  62. #include "ui_layer.h"
  63. #include "ui_file.h"
  64. #include "ui_fileP.h"
  65. #include "ui_netGraph.h"
  66. #include "ui_event.h"
  67. #include "ui_key.h"
  68. #include "ui_confirmer.h"
  69. #include "ui_xWidgets.h"
  70. #include "ui_lists.h"
  71. #include "ui_display.h"
  72. #include "ui_remoteP.h"
  73. #include "ui_edit.h"
  74. #include "ui_mainP.h"
  75. #include "ui_main.h"
  76. #include "ui_action.h"
  77.  
  78. #include "ui_funcdispl.ph"
  79.  
  80.  
  81. /*****************************************************************************
  82.   FUNCTION : ui_functionPopup
  83.  
  84.   PURPOSE  : Display the characteristic functions of the units
  85.   NOTES    : 
  86.   RETURNS  :
  87.   UPDATE   : 14.01.92
  88. ******************************************************************************/
  89.  
  90. void ui_functionPopup(Widget w, char *title, caddr_t call_data)
  91. {
  92.     Widget         fbutton,sbutton,framewidget[6],mainwidget[6];
  93.     Arg           args[25];   
  94.     Cardinal       n;
  95.     int            typus;
  96.     char           buf[40];
  97.  
  98.  
  99.  
  100.  
  101.     sprintf(buf,"\n");
  102.  
  103.  
  104.     /* Create window and all subwidgets for the display */
  105.  
  106.     if(!strcmp(title,"Target Out")){
  107.       FUNC_GRAPH_case = 1;
  108.       sprintf(buf,"Target Output");
  109.       typus = krui_getUnitTType(ui_targetUnit.no);
  110.       if(typus < 1){
  111.         ui_confirmOk("Unit not defined!!");
  112.         return;
  113.       }
  114.     }else if(!strcmp(title,"Target Act")){
  115.       FUNC_GRAPH_case = 2;
  116.       sprintf(buf,"Target Activation");
  117.       typus = krui_getUnitTType(ui_targetUnit.no);
  118.       if(typus < 2){
  119.         ui_confirmOk("Unit has no input!!");
  120.         return;
  121.       }
  122.     }else if(!strcmp(title,"Source Out")){
  123.       FUNC_GRAPH_case = 4;
  124.       sprintf(buf,"Source Output");
  125.       typus = krui_getUnitTType(ui_sourceUnit.no);
  126.       if(typus < 1){
  127.         ui_confirmOk("Unit not defined!!");
  128.         return;
  129.       }
  130.     }else if(!strcmp(title,"Source Act")){
  131.       FUNC_GRAPH_case = 5;
  132.       sprintf(buf,"Source Activation");
  133.       typus = krui_getUnitTType(ui_sourceUnit.no);
  134.       if(typus < 2){
  135.         ui_confirmOk("Unit has no input!!");
  136.         return;
  137.       }
  138.     }
  139.     if( FUNC_GRAPH_win_ex[ FUNC_GRAPH_case] ){
  140.        /* don't create second window */
  141.        ui_confirmOk("Please only one Window per Function !");
  142.        return;
  143.     }
  144.     
  145.     FUNC_GRAPH_created[FUNC_GRAPH_case] = 1; 
  146.     FUNC_GRAPH_win_ex[FUNC_GRAPH_case] = 1;
  147.     
  148.  
  149.     n = 0;
  150.     mainwidget[FUNC_GRAPH_case] = 
  151.           XtCreatePopupShell(buf,topLevelShellWidgetClass,ui_toplevel,args,n);
  152.     n =0;
  153.     framewidget[FUNC_GRAPH_case] = 
  154.           XtCreateManagedWidget("form",formWidgetClass,
  155.                 mainwidget[FUNC_GRAPH_case],args,n);
  156.     fbutton = ui_xCreateButtonItem("done",framewidget[FUNC_GRAPH_case],
  157.                    NULL,NULL);
  158.     sbutton = ui_xCreateButtonItem("set",framewidget[FUNC_GRAPH_case]
  159.                    ,NULL,fbutton);
  160.     FUNC_GRAPH_x_minW[FUNC_GRAPH_case] = 
  161.                      ui_xCreateDialogItem("xmin",framewidget[FUNC_GRAPH_case],
  162.                       "-2.0",40,fbutton,NULL);
  163.     if(FUNC_GRAPH_case == 2 || FUNC_GRAPH_case == 5)
  164.        FUNC_GRAPH_x_labW[FUNC_GRAPH_case] = ui_xCreateLabelItem("<= W_ij <=",
  165.                      framewidget[FUNC_GRAPH_case],80,
  166.                      FUNC_GRAPH_x_minW[FUNC_GRAPH_case],
  167.                      NULL);
  168.     else
  169.        FUNC_GRAPH_x_labW[FUNC_GRAPH_case] = ui_xCreateLabelItem("<= act <=",
  170.                      framewidget[FUNC_GRAPH_case],72,
  171.                      FUNC_GRAPH_x_minW[FUNC_GRAPH_case],
  172.                      NULL);
  173.     FUNC_GRAPH_x_maxW[FUNC_GRAPH_case] = 
  174.                      ui_xCreateDialogItem("xmax",framewidget[FUNC_GRAPH_case], 
  175.                       "2.0",40,
  176.                       FUNC_GRAPH_x_labW[FUNC_GRAPH_case],
  177.                       NULL);
  178.     FUNC_GRAPH_y_minW[FUNC_GRAPH_case] = 
  179.                      ui_xCreateDialogItem("ymin",framewidget[FUNC_GRAPH_case], 
  180.                       "-5.0",40,fbutton,
  181.                       FUNC_GRAPH_x_minW[FUNC_GRAPH_case]);
  182.     if(FUNC_GRAPH_case == 2 || FUNC_GRAPH_case == 5)
  183.        FUNC_GRAPH_y_labW[FUNC_GRAPH_case] = ui_xCreateLabelItem("<= act <=", 
  184.                      framewidget[FUNC_GRAPH_case],72,
  185.                      FUNC_GRAPH_y_minW[FUNC_GRAPH_case],
  186.                      FUNC_GRAPH_x_labW[FUNC_GRAPH_case]);
  187.     else
  188.        FUNC_GRAPH_y_labW[FUNC_GRAPH_case] = ui_xCreateLabelItem("<= out <=", 
  189.                      framewidget[FUNC_GRAPH_case],72,
  190.                      FUNC_GRAPH_y_minW[FUNC_GRAPH_case],
  191.                      FUNC_GRAPH_x_labW[FUNC_GRAPH_case]);
  192.  
  193.     FUNC_GRAPH_y_maxW[FUNC_GRAPH_case] = 
  194.                      ui_xCreateDialogItem("ymax",framewidget[FUNC_GRAPH_case],
  195.                       "5.0",40,
  196.                       FUNC_GRAPH_x_labW[FUNC_GRAPH_case],
  197.                       FUNC_GRAPH_x_maxW[FUNC_GRAPH_case]);
  198.     displaywidget[FUNC_GRAPH_case] = 
  199.                      ui_createMyScreen("screen",framewidget[FUNC_GRAPH_case],
  200.                        200,100,NULL,
  201.                        FUNC_GRAPH_y_maxW[FUNC_GRAPH_case]);
  202.  
  203.  
  204.     /* set defaults for display regions */
  205.     
  206.     FUNC_GRAPH_x_min[FUNC_GRAPH_case] = -2.0;
  207.     FUNC_GRAPH_x_max[FUNC_GRAPH_case] =  2.0;
  208.     FUNC_GRAPH_y_min[FUNC_GRAPH_case] = -5.0;
  209.     FUNC_GRAPH_y_max[FUNC_GRAPH_case] =  5.0;
  210.  
  211.     /* define the routines to be called for widget events */
  212.  
  213.  
  214.  
  215.     XtAddCallback(fbutton,XtNcallback,(XtCallbackProc)local_kill, mainwidget[FUNC_GRAPH_case]);
  216.     XtAddCallback(fbutton,XtNcallback,(XtCallbackProc)local_kill_prot,(caddr_t)FUNC_GRAPH_case);
  217.     XtAddCallback(sbutton, XtNcallback,(XtCallbackProc) ui_setXY,NULL);
  218.     XtAddCallback(sbutton, XtNcallback,(XtCallbackProc) ui_drawFunction,title);
  219.  
  220.     XtAddEventHandler(displaywidget[FUNC_GRAPH_case],
  221.               StructureNotifyMask | ExposureMask, 
  222.               GraphicsExpose,(XtEventHandler) ui_drawFunction,title);
  223.  
  224.  
  225.  
  226.  
  227.     /* Realize the window */
  228.  
  229.     ui_checkWindowPosition(mainwidget[FUNC_GRAPH_case]);
  230.     XtPopup(mainwidget[FUNC_GRAPH_case], XtGrabNone);
  231.  
  232.  
  233.  
  234.  
  235. }
  236.  
  237.  
  238. /*****************************************************************************
  239.   FUNCTION : ui_createMyScreen
  240.  
  241.   PURPOSE  : Create screen for Graphic display
  242.   NOTES    : 
  243.   RETURNS  : The Widgetnumber 
  244.   UPDATE   : 14.01.92
  245. ******************************************************************************/
  246.  
  247.  
  248. Widget ui_createMyScreen(char *name, Widget parent, Dimension width, Dimension height, Widget left, Widget top)
  249. {
  250.   Cardinal n;
  251.   Widget w;
  252.   Arg    args[15];
  253.  
  254.  
  255.     n = 0;
  256.     XtSetArg(args[n], XtNborderWidth,  1); n++;
  257.     XtSetArg(args[n], XtNwidth,  width); n++;
  258.     XtSetArg(args[n], XtNheight, height); n++;
  259.     XtSetArg(args[n], XtNfromHoriz, left); n++;
  260.     XtSetArg(args[n], XtNfromVert, top); n++;
  261.     XtSetArg(args[n], XtNleft  , XtChainLeft); n++;
  262.     XtSetArg(args[n], XtNright , XtChainRight); n++;
  263.     XtSetArg(args[n], XtNtop   , XtChainTop); n++;
  264.     XtSetArg(args[n], XtNbottom, XtChainBottom); n++;
  265.     XtSetArg(args[n], XtNx, 0);n++;
  266.     XtSetArg(args[n], XtNy, 0);n++;
  267.  
  268.     w = XtCreateManagedWidget(name, widgetClass,parent,args,n);
  269.     return(w);
  270.  
  271. }
  272.  
  273.  
  274.  
  275. /*****************************************************************************
  276.   FUNCTION : ui_drawFunction
  277.  
  278.   PURPOSE  : Draw the functions of the units
  279.   NOTES    : 
  280.   RETURNS  :
  281.   UPDATE   : 14.01.92
  282. ******************************************************************************/
  283.  
  284. void ui_drawFunction(Widget w, char *title, caddr_t call_data)
  285. {
  286.   FlintType strong;
  287.   OutFunctionPtr  thisfunc;
  288.   XPoint point[81];
  289.   int n;
  290.   char outString[40];
  291.   float temp;
  292.   int pointcount = 80;
  293.   XtWidgetGeometry geo_info, geo_data;
  294.   XtGeometryResult geo_result;
  295.   float dx,dy;
  296.   int pred_count=1;
  297.  
  298.   /* switch for the unit and function requested */
  299.  
  300.   if(!strcmp(title,"Target Out")){
  301.     FUNC_GRAPH_case = 1;
  302.  
  303.     /* do nothing if window does not exist */
  304.     if(!FUNC_GRAPH_win_ex[FUNC_GRAPH_case])return; 
  305.  
  306.     /* do nothing if function is not defined yet */
  307.     if(strlen(ui_targetUnit.outFuncName) <= 1)return;
  308.  
  309.     /* get widget geometry */
  310.     geo_data.request_mode = XtCWQueryOnly;
  311.     geo_result = XtQueryGeometry(displaywidget[FUNC_GRAPH_case],
  312.                  &geo_data,&geo_info);
  313.     if(geo_result != XtGeometryYes){
  314.       geo_info.height = 100;
  315.       geo_info.width  = 200;
  316.     }
  317.  
  318.     /* get a pointer to the current function */
  319.     if( !krf_funcSearch(ui_targetUnit.outFuncName,1,(FunctionPtr *) &thisfunc)){
  320.       printf("grep to the function failed\n");
  321.       return;
  322.     }
  323.  
  324.     /* compute function values */
  325.     dx = FUNC_GRAPH_x_max[FUNC_GRAPH_case] - FUNC_GRAPH_x_min[FUNC_GRAPH_case];
  326.     dy = FUNC_GRAPH_y_max[FUNC_GRAPH_case] - FUNC_GRAPH_y_min[FUNC_GRAPH_case];
  327.     if(thisfunc == NULL){
  328.       for(n=0; n<=pointcount; n++){
  329.     point[n].x = (short) n*geo_info.width/pointcount;
  330.     point[n].y = (short)(geo_info.height - 
  331.               geo_info.height*((FUNC_GRAPH_x_min[FUNC_GRAPH_case] + 
  332.                  (float)(dx*n)/(float)pointcount) - 
  333.                  FUNC_GRAPH_y_min[FUNC_GRAPH_case])/dy);
  334.       }
  335.     }else{
  336.       for(n=0; n<=pointcount; n++){
  337.     point[n].x = (short)(n*geo_info.width/pointcount);
  338.     temp       = ((OutFunctionPtr)thisfunc)( (FlintType)(FUNC_GRAPH_x_min[FUNC_GRAPH_case]+
  339.                        (float)(dx*n)/(float)pointcount));
  340.     point[n].y = (short)( geo_info.height - 
  341.                   geo_info.height*(temp - 
  342.                   FUNC_GRAPH_y_min[FUNC_GRAPH_case])/(float)dy );
  343.       }
  344.     }
  345.   }else if(!strcmp(title,"Target Act")){
  346.     FUNC_GRAPH_case = 2;
  347.  
  348.     /* do nothing if window does not exist */
  349.     if(!FUNC_GRAPH_win_ex[FUNC_GRAPH_case])return; 
  350.  
  351.     /* do nothing if function is not defined yet */
  352.     if(strlen(ui_targetUnit.actFuncName) <= 1)return;
  353.  
  354.     /* get widget geometry */
  355.     geo_data.request_mode = XtCWQueryOnly;
  356.     geo_result = XtQueryGeometry(displaywidget[FUNC_GRAPH_case],
  357.                  &geo_data,&geo_info);
  358.     if(geo_result != XtGeometryYes){
  359.       geo_info.height = 100;
  360.       geo_info.width  = 200;
  361.     }
  362.  
  363.     /* make target unit current unit */
  364.     krui_setCurrentUnit(ui_targetUnit.no);
  365.  
  366.     /* get a pointer to the current function */
  367.     if( !krf_funcSearch(ui_targetUnit.actFuncName,2,(FunctionPtr *) &thisfunc)){
  368.       ui_confirmOk("grep to the activation function failed");
  369.       return;
  370.     }
  371.  
  372.     /* This is a violation of the kernel-xgui interface, but necessary to 
  373.        initinalize some of the unit fields */
  374.     if( strcmp(ui_targetUnit.actFuncName,"Act_TD_Logistic") == 0){
  375.     kr_topoSort(11);
  376.     }
  377.  
  378.     /* save current strengths */
  379.     handle = (struct chain_el *)malloc(sizeof(struct chain_el));
  380.     weight_chain = handle;
  381.     krui_getFirstPredUnit(&strong);
  382.     weight_chain->weight = strong;
  383.     while(krui_getNextPredUnit(&strong)){
  384.       weight_chain->next = (struct chain_el *)malloc(sizeof(struct chain_el));
  385.       weight_chain = weight_chain->next;
  386.       weight_chain->weight = strong;
  387.     }
  388.     weight_chain->next = NULL;
  389.  
  390.  
  391.     /* clear strengths */
  392.     krui_getFirstPredUnit(&strong);
  393.     krui_setLinkWeight(0.0);
  394.     while(krui_getNextPredUnit(&strong)){
  395.       krui_setLinkWeight(0.0);
  396.     }
  397.  
  398.     /* compute function values */
  399.     dx = FUNC_GRAPH_x_max[FUNC_GRAPH_case] - FUNC_GRAPH_x_min[FUNC_GRAPH_case];
  400.     dy = FUNC_GRAPH_y_max[FUNC_GRAPH_case] - FUNC_GRAPH_y_min[FUNC_GRAPH_case];
  401.     if(thisfunc == NULL){
  402.       for(n=0; n<=pointcount; n++){
  403.     point[n].x = (short) n*geo_info.width/pointcount;
  404.     point[n].y = (short)(geo_info.height - 
  405.               geo_info.height*((FUNC_GRAPH_x_min[FUNC_GRAPH_case] + 
  406.                  (float)(dx*n)/(float)pointcount) - 
  407.                     FUNC_GRAPH_y_min[FUNC_GRAPH_case])/dy);
  408.       }
  409.       krui_getFirstPredUnit(&strong);
  410.       pred_count = 1;
  411.       while(krui_getNextPredUnit(&strong))pred_count++;
  412.     }else{
  413.       for(n=0; n<=pointcount; n++){
  414.     point[n].x = (short)(n*geo_info.width/pointcount);
  415.         krui_getFirstPredUnit(&strong);
  416.         pred_count = 1;
  417.         krui_setLinkWeight( (FlintType)(FUNC_GRAPH_x_min[FUNC_GRAPH_case]
  418.                     +(float)(dx*n)/(float)pointcount));
  419.         while(krui_getNextPredUnit(&strong)){
  420.            krui_setLinkWeight((FlintType)(FUNC_GRAPH_x_min[FUNC_GRAPH_case]+
  421.                       (float)(dx*n)/(float)pointcount));
  422.        pred_count++;
  423.         }
  424.     temp       = ((ActFunctionPtr) thisfunc) (kr_getUnitPtr(ui_targetUnit.no));
  425.     point[n].y = (short)( geo_info.height - 
  426.                   geo_info.height*
  427.                  (temp-FUNC_GRAPH_y_min[FUNC_GRAPH_case])/
  428.                   (float)dy);
  429.       }
  430.     }
  431.  
  432.     /* reset strengths */
  433.     weight_chain = handle;
  434.     krui_getFirstPredUnit(&strong);
  435.     strong = weight_chain->weight;
  436.     krui_setLinkWeight(strong);
  437.     while((weight_chain = weight_chain->next) != NULL){
  438.       krui_getNextPredUnit(&strong);
  439.       strong = weight_chain->weight;
  440.       krui_setLinkWeight(strong);
  441.     }
  442.  
  443.   }else if(!strcmp(title,"Source Out")){
  444.     FUNC_GRAPH_case = 4;
  445.  
  446.     /* do nothing if window does not exist */
  447.     if(!FUNC_GRAPH_win_ex[FUNC_GRAPH_case])return; 
  448.  
  449.     /* do nothing if function is not defined yet */
  450.     if(strlen(ui_sourceUnit.outFuncName) <= 1)return;
  451.  
  452.     /* get widget geometry */
  453.     geo_data.request_mode = XtCWQueryOnly;
  454.     geo_result = XtQueryGeometry(displaywidget[FUNC_GRAPH_case],&geo_data,
  455.                  &geo_info);
  456.     if(geo_result != XtGeometryYes){
  457.       geo_info.height = 100;
  458.       geo_info.width  = 200;
  459.     }
  460.  
  461.     /* get a pointer to the current function */
  462.     if( ! krf_funcSearch(ui_sourceUnit.outFuncName,1,(FunctionPtr *) &thisfunc)){
  463.       printf("grep to the function failed\n");
  464.       return;
  465.     }
  466.  
  467.     /* compute function values */
  468.     dx = FUNC_GRAPH_x_max[FUNC_GRAPH_case] - FUNC_GRAPH_x_min[FUNC_GRAPH_case];
  469.     dy = FUNC_GRAPH_y_max[FUNC_GRAPH_case] - FUNC_GRAPH_y_min[FUNC_GRAPH_case];
  470.     if(thisfunc == NULL){
  471.       for(n=0; n<=pointcount; n++){
  472.     point[n].x = (short) n*geo_info.width/pointcount;
  473.     point[n].y = (short)(geo_info.height - 
  474.              geo_info.height*((FUNC_GRAPH_x_min[FUNC_GRAPH_case]+
  475.                  (float)(dx*n)/(float)pointcount) - 
  476.                   FUNC_GRAPH_y_min[FUNC_GRAPH_case])/dy);
  477.       }
  478.     }else{
  479.       for(n=0; n<=pointcount; n++){
  480.     point[n].x = (short)(n*geo_info.width/pointcount);
  481.     temp       = thisfunc((FlintType)(FUNC_GRAPH_x_min[FUNC_GRAPH_case]+
  482.                        (float)(dx*n)/(float)pointcount));
  483.     point[n].y = (short)( geo_info.height - 
  484.                   geo_info.height*
  485.                (temp-FUNC_GRAPH_y_min[FUNC_GRAPH_case])/(float)dy);
  486.       }
  487.     }
  488.   
  489.   }else if(!strcmp(title,"Source Act")){
  490.     FUNC_GRAPH_case = 5;
  491.  
  492.     /* do nothing if window does not exist */
  493.     if(!FUNC_GRAPH_win_ex[FUNC_GRAPH_case])return; 
  494.  
  495.     /* do nothing if function is not defined yet */
  496.     if(strlen(ui_sourceUnit.actFuncName) <= 1)return;
  497.  
  498.     /* get widget geometry */
  499.     geo_data.request_mode = XtCWQueryOnly;
  500.     geo_result = XtQueryGeometry(displaywidget[FUNC_GRAPH_case],
  501.                  &geo_data,&geo_info);
  502.     if(geo_result != XtGeometryYes){
  503.       geo_info.height = 100;
  504.       geo_info.width  = 200;
  505.     }
  506.     
  507.     /* make source unit current unit */
  508.     krui_setCurrentUnit(ui_sourceUnit.no);
  509.  
  510.     /* get a pointer to the current function */
  511.     if( !krf_funcSearch(ui_sourceUnit.actFuncName,2,(FunctionPtr *) &thisfunc)){
  512.       ui_confirmOk("grep to the activation function failed");
  513.       return;
  514.     }
  515.  
  516.     /* This is a violation of the kernel-xgui interface, but necessary to 
  517.        initinalize some of the unit fields */
  518.     if( strcmp(ui_sourceUnit.actFuncName,"Act_TD_Logistic") == 0){
  519.     kr_topoSort(11);
  520.     }
  521.  
  522.     /* save current strengths */
  523.     handle = (struct chain_el *)malloc(sizeof(struct chain_el));
  524.     weight_chain = handle;
  525.     krui_getFirstPredUnit(&strong);
  526.     weight_chain->weight = strong;
  527.     while(krui_getNextPredUnit(&strong)){
  528.       weight_chain->next = (struct chain_el *)malloc(sizeof(struct chain_el));
  529.       weight_chain = weight_chain->next;
  530.       weight_chain->weight = strong;
  531.     }
  532.     weight_chain->next = NULL;
  533.  
  534.  
  535.     /* clear strengths */
  536.     krui_getFirstPredUnit(&strong);
  537.     krui_setLinkWeight(0.0);
  538.     while(krui_getNextPredUnit(&strong)){
  539.       krui_setLinkWeight(0.0);
  540.     }
  541.  
  542.     /* compute function values */
  543.     dx = FUNC_GRAPH_x_max[FUNC_GRAPH_case] - FUNC_GRAPH_x_min[FUNC_GRAPH_case];
  544.     dy = FUNC_GRAPH_y_max[FUNC_GRAPH_case] - FUNC_GRAPH_y_min[FUNC_GRAPH_case];
  545.     if(thisfunc == NULL){
  546.       for(n=0; n<=pointcount; n++){
  547.     point[n].x = (short) n*geo_info.width/pointcount;
  548.     point[n].y = (short)(geo_info.height - geo_info.height*
  549.                  ((FUNC_GRAPH_x_min[FUNC_GRAPH_case] + 
  550.                    (float)(dx*n)/(float)pointcount) - 
  551.                    FUNC_GRAPH_y_min[FUNC_GRAPH_case])/dy);
  552.       }
  553.       krui_getFirstPredUnit(&strong);
  554.       pred_count = 1;
  555.       while(krui_getNextPredUnit(&strong))pred_count++;
  556.     }else{
  557.       for(n=0; n<=pointcount; n++){
  558.     point[n].x = (short)(n*geo_info.width/pointcount);
  559.         krui_getFirstPredUnit(&strong);
  560.     pred_count = 1;
  561.         krui_setLinkWeight( (FlintType)(FUNC_GRAPH_x_min[FUNC_GRAPH_case]+
  562.                     (float)(dx*n)/(float)pointcount));
  563.         while(krui_getNextPredUnit(&strong)){
  564.            krui_setLinkWeight((FlintType)(FUNC_GRAPH_x_min[FUNC_GRAPH_case]+
  565.                       (float)(dx*n)/(float)pointcount));
  566.        pred_count++;
  567.         }
  568.     temp       = ((ActFunctionPtr) thisfunc) (kr_getUnitPtr(ui_sourceUnit.no));
  569.     point[n].y = (short)(geo_info.height - 
  570.                  geo_info.height*
  571.                  (temp-FUNC_GRAPH_y_min[FUNC_GRAPH_case])/
  572.                   (float)dy);
  573.       }
  574.     }
  575.  
  576.     /* reset strengths */
  577.     weight_chain = handle;
  578.     krui_getFirstPredUnit(&strong);
  579.     strong = weight_chain->weight;
  580.     krui_setLinkWeight(strong);
  581.     while((weight_chain = weight_chain->next) != NULL){
  582.       krui_getNextPredUnit(&strong);
  583.       strong = weight_chain->weight;
  584.       krui_setLinkWeight(strong);
  585.     }
  586.  
  587.   }else{
  588.     printf("Error in selection process\n");
  589.     return;
  590.   }
  591.  
  592.  
  593.    /* create a new xlib environment, but just once */
  594.  
  595.    if(FUNC_GRAPH_created[FUNC_GRAPH_case]){
  596.        FUNC_GRAPH_screen   = DefaultScreen(ui_display);
  597.        FUNC_GRAPH_window[FUNC_GRAPH_case] =  XtWindow(w);
  598.        FUNC_GRAPH_gc[FUNC_GRAPH_case] = 
  599.                 XCreateGC(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  600.                   0,0);
  601.        XSetForeground(ui_display,FUNC_GRAPH_gc[FUNC_GRAPH_case],
  602.               BlackPixel(ui_display,FUNC_GRAPH_screen));
  603.        XSetBackground(ui_display,FUNC_GRAPH_gc[FUNC_GRAPH_case],
  604.               WhitePixel(ui_display,FUNC_GRAPH_screen));
  605.        FUNC_GRAPH_created[FUNC_GRAPH_case] = 0;
  606.    }
  607.  
  608.    XClearWindow(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case]);
  609.  
  610.  
  611.    /* display function */
  612.  
  613.    XDrawLines(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  614.           FUNC_GRAPH_gc[FUNC_GRAPH_case],point,pointcount+1,
  615.           CoordModeOrigin);
  616.  
  617.  
  618.    /* display coordinate system */
  619.  
  620.    point[0].x = 0;
  621.    point[0].y = geo_info.height + 
  622.             (int)(geo_info.height*FUNC_GRAPH_y_min[FUNC_GRAPH_case]/(float)dy);
  623.    point[1].x = geo_info.width;
  624.    point[1].y = point[0].y; 
  625.    XDrawLines(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  626.           FUNC_GRAPH_gc[FUNC_GRAPH_case],point,2,CoordModeOrigin);
  627.    point[0].x = -(int)
  628.                 (geo_info.width*FUNC_GRAPH_x_min[FUNC_GRAPH_case]/(float)dx);
  629.    point[0].y = 0;
  630.    point[1].x = point[0].x;
  631.    point[1].y = geo_info.height;
  632.    XDrawLines(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  633.           FUNC_GRAPH_gc[FUNC_GRAPH_case],point,2,CoordModeOrigin);
  634.  
  635.  
  636.    /* label the coordinates */
  637.  
  638.    n = (int)FUNC_GRAPH_x_min[FUNC_GRAPH_case];
  639.    do{
  640.      point[0].x = (int)(geo_info.width*
  641.             (n-FUNC_GRAPH_x_min[FUNC_GRAPH_case])/(float)dx);
  642.      point[1].x = point[0].x;
  643.      point[0].y = geo_info.height +
  644.                  (int)
  645.          (geo_info.height*FUNC_GRAPH_y_min[FUNC_GRAPH_case]/(float)dy);
  646.      point[1].y = point[0].y + 5;
  647.      XDrawLines(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  648.         FUNC_GRAPH_gc[FUNC_GRAPH_case],point,2,CoordModeOrigin);
  649.      sprintf(outString,"%d",n*pred_count);
  650.      if(n == -1 || n == 1)
  651.         XDrawString(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  652.             FUNC_GRAPH_gc[FUNC_GRAPH_case],
  653.             point[0].x,point[0].y+15,outString,(int) strlen(outString));
  654.    }while(++n < FUNC_GRAPH_x_max[FUNC_GRAPH_case]);
  655.  
  656.    n = (int)FUNC_GRAPH_y_min[FUNC_GRAPH_case];
  657.    do{
  658.      point[0].x = -(int)
  659.                   (geo_info.width*FUNC_GRAPH_x_min[FUNC_GRAPH_case]/(float)dx);
  660.      point[1].x = point[0].x - 5;
  661.      point[0].y = (int)((float)geo_info.height*
  662.           (float)(dy-n+FUNC_GRAPH_y_min[FUNC_GRAPH_case])/(float)dy);
  663.      point[1].y = point[0].y;
  664.      XDrawLines(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  665.         FUNC_GRAPH_gc[FUNC_GRAPH_case],point,2,
  666.         CoordModeOrigin);
  667.      sprintf(outString,"%d",n);
  668.      if(n == -1 || n == 1){
  669.         XDrawString(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  670.             FUNC_GRAPH_gc[FUNC_GRAPH_case],
  671.             (int) point[0].x-9*strlen(outString),
  672.             point[0].y+4,outString,(int) strlen(outString));
  673.      }
  674.    }while(++n < FUNC_GRAPH_y_max[FUNC_GRAPH_case]);
  675.  
  676.    n = (int)FUNC_GRAPH_y_min[FUNC_GRAPH_case];
  677.    do{
  678.      point[0].x = 0;
  679.      point[1].x = point[0].x+(int)((float)geo_info.width*0.01);
  680.      point[2].x = geo_info.width;
  681.      point[0].y = (int)((float)geo_info.height*(float)(dy-
  682.             n+FUNC_GRAPH_y_min[FUNC_GRAPH_case])/(float)dy);
  683.      point[2].y = point[1].y = point[0].y;
  684.      XDrawLines(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  685.         FUNC_GRAPH_gc[FUNC_GRAPH_case],point,2,CoordModeOrigin);
  686.  
  687.      XDrawLine(ui_display,FUNC_GRAPH_window[FUNC_GRAPH_case],
  688.            FUNC_GRAPH_gc[FUNC_GRAPH_case],
  689.            point[2].x,point[0].y,
  690.            point[2].x-(int)((float)geo_info.width*0.01),point[1].y);
  691.    }while(++n < FUNC_GRAPH_y_max[FUNC_GRAPH_case]);
  692.  
  693.  
  694.    /* get everything on the screen */
  695.  
  696.    XFlush(ui_display);
  697.  
  698. }
  699.  
  700.  
  701. /****************************************************************************
  702.   FUNCTION : local_kill
  703.  
  704.   PURPOSE  : Kill the widget for unit function display
  705.   NOTES    : 
  706.   RETURNS  :
  707.  
  708.   UPDATE   : 14.01.92
  709. ******************************************************************************/
  710.  
  711. static void local_kill(Widget dummy, Widget w, caddr_t call_data)
  712. {
  713.   XtDestroyWidget(w);
  714. }
  715.  
  716.  
  717. /****************************************************************************
  718.   FUNCTION : local_kill_prot
  719.  
  720.   PURPOSE  : Kill the widget for unit function display
  721.   NOTES    : 
  722.   RETURNS  :
  723.  
  724.   UPDATE   : 14.01.92
  725. ******************************************************************************/
  726.  
  727. static void local_kill_prot(Widget dummy, int thiscase, caddr_t call_data)
  728. {
  729.   FUNC_GRAPH_win_ex[thiscase] = 0;
  730. }
  731.  
  732.  
  733. /*****************************************************************************
  734.   FUNCTION : ui_setXY
  735.  
  736.   PURPOSE  : Set the x an y range for the function display
  737.   NOTES    : 
  738.   RETURNS  :
  739.   UPDATE   : 22.01.92
  740. ******************************************************************************/
  741. static void ui_setXY(Widget w, caddr_t call_data)
  742. {
  743.     FUNC_GRAPH_x_min[FUNC_GRAPH_case] = 
  744.           (float)ui_xFloatFromAsciiWidget(FUNC_GRAPH_x_minW[FUNC_GRAPH_case]);
  745.     FUNC_GRAPH_x_max[FUNC_GRAPH_case] = 
  746.           (float)ui_xFloatFromAsciiWidget(FUNC_GRAPH_x_maxW[FUNC_GRAPH_case]);
  747.     FUNC_GRAPH_y_min[FUNC_GRAPH_case] = 
  748.           (float)ui_xFloatFromAsciiWidget(FUNC_GRAPH_y_minW[FUNC_GRAPH_case]);
  749.     FUNC_GRAPH_y_max[FUNC_GRAPH_case] = 
  750.           (float)ui_xFloatFromAsciiWidget(FUNC_GRAPH_y_maxW[FUNC_GRAPH_case]);
  751. }
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.