home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDKCONST.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  10KB  |  312 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*         Kinetic constants         */
  14. /*            dialog box             */
  15. /*                                   */
  16. /*           QuickC/WIN 1.0          */
  17. /*                                   */
  18. /*   (include here compilers that    */
  19. /*   compiled GWSIM successfully)    */
  20. /*                                   */
  21. /*************************************/
  22.  
  23.  
  24. #include <windows.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <math.h>
  28. #include "defines.h"                    /* symbols also used in .DLG files        */
  29. #include "globals.h"                    /* gepasi's own symbols                    */
  30. #include "gwsim.h"                        /* macros, function prototypes, etc.    */
  31. #include "gep2.h"                        /* gepasi's variables                    */
  32. #include "simgvar.h"                    /* global variables                        */
  33. #include "strtbl.h"                        /* symbols for the string table            */
  34.  
  35. #pragma alloc_text( CODE2, AddReactLst, EdKConst)
  36.  
  37. void AddReactLst( HWND hControl, int j, int is_index, int scroll )
  38. {
  39.  WORD buffWidth;
  40.  HANDLE hDC;
  41.  
  42.  hDC = GetDC( hControl );
  43.  buffWidth = 5 + LOWORD( GetTextExtent( hDC, stepstr[j], _fstrlen(stepstr[j]) ) );
  44.  SetTextJustification( hDC, 0, 0 );
  45.  ReleaseDC( hControl, hDC );
  46.  if( buffWidth > lbWidth )
  47.  {
  48.   lbWidth = buffWidth;
  49.   SendMessage( hControl, LB_SETHORIZONTALEXTENT, lbWidth, (DWORD) 0 );
  50.  }
  51.  if( is_index )
  52.  {
  53.   SendMessage( hControl, LB_DELETESTRING, j, 0 );
  54.   SendMessage( hControl, LB_INSERTSTRING, j, (DWORD) (LPSTR) stepstr[j] );
  55.  }
  56.  else
  57.   SendMessage( hControl, LB_INSERTSTRING, -1, (DWORD) (LPSTR) stepstr[j] );
  58.  if( scroll ) SendMessage( hControl, WM_VSCROLL, SB_BOTTOM, 0 );
  59. }
  60.  
  61.  
  62. BOOL FAR PASCAL EdKConst(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  63. {
  64.  static int first, last, lots, i, j, k, r;
  65.  static BOOL circle;
  66.  int len;
  67.  static HWND hCtrl, hReactLst, hMore, hKineType, hStepName;
  68.  char buff[128];
  69.  LPSTR auxptr;
  70.  
  71.  switch(Message)
  72.  {
  73.   case WM_INITDIALOG:
  74.    /* set the width of the list box to 0        */
  75.    lbWidth = 0;
  76.  
  77.    /* allocate memory for the mirror            */
  78.    hPrm = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, sizeparam );
  79.    if( hPrm == NULL )
  80.    {
  81.     LoadString(hInst, IDS_ERR_NOEXEC, szString, sizeof(szString));
  82.     MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  83.     EndDialog(hDlg, FALSE);
  84.     return TRUE;
  85.    }
  86.    /* the parameters of the first step are the first        */
  87.    prm[0] = (double huge *) GlobalLock( hPrm );
  88.  
  89.    /* set the other pointers                                */
  90.    for( i=1; i<nsteps; i++ )
  91.     prm[i] = prm[i-1] + ktype[kinetu[i-1]].nconst;
  92.  
  93.    /* copy params to its mirror                                    */
  94.    _fmemcpy( (void __far *) prm[0],
  95.              (void __far *) params[0],
  96.              (size_t) sizeparam );
  97.  
  98.    /* get handles to controls                    */
  99.    hReactLst = GetDlgItem( hDlg, IDC_REACTLST );
  100.    hMore = GetDlgItem( hDlg, ID_MORE );
  101.    hKineType = GetDlgItem( hDlg, IDC_KINETYPE );
  102.    hStepName = GetDlgItem( hDlg, IDC_REACT );
  103.  
  104.    /* initialize hReactLst: add all reactions    */
  105.    for( i=0; i<nsteps; i++ )
  106.     AddReactLst( hReactLst, i, 1, 0 );
  107.  
  108.    /* select the first reaction of hReactLst  */
  109.    r = 0;
  110.    SendMessage( hReactLst, LB_SETCURSEL, (WORD) r, 0 );
  111.  
  112.   case WM_USER+1:
  113.    /* write the kinetic type description on the wide help button*/
  114.    SendMessage( hKineType, WM_SETTEXT, 0, (DWORD)(LPSTR) ktype[kinetu[r]].descr );
  115.  
  116.    /* write this step's name on the edit box above the list box    */
  117.    SendMessage( hStepName, WM_SETTEXT, 0, (DWORD)(LPSTR) stepname[r] );
  118.  
  119.    /* initialize working variables                                */
  120.    if (ktype[kinetu[r]].nconst >= 8 ) last = 8;
  121.    else last = ktype[kinetu[r]].nconst;
  122.    if ( ktype[kinetu[r]].nconst > 8 )  lots = TRUE;
  123.    else lots = FALSE;
  124.    first = 0;
  125.    circle = FALSE;
  126.  
  127.    /* initialize static controls with constant names            */
  128.    for( j=first, i=IDT_M0; j<last; j++, i++ )
  129.    {
  130.     for( k=0, auxptr=ktype[kinetu[r]].constnam; k<j; k++ )
  131.     {
  132.      do{ auxptr++; } while( (*auxptr) );
  133.      auxptr++;
  134.     }
  135.     SetDlgItemText( hDlg, i, (LPSTR) auxptr);
  136.    }
  137.  
  138.    /* update edit boxes with constant's values                    */
  139.    for( j=first, i=IDE_M0; j<last; j++, i++ )
  140.    {
  141.     gcvt( *(prm[r]+j), 16, buff );
  142.     SetDlgItemText( hDlg, i, (LPSTR) buff);
  143.    }
  144.  
  145.    /* show from first to last     (static and edit controls)        */
  146.    for( j=first, i=IDT_M0, k=IDE_M0; j<last; j++, i++, k++ )
  147.    {
  148.     hCtrl = GetDlgItem( hDlg, k );
  149.     ShowWindow( hCtrl, SW_SHOW );
  150.     hCtrl = GetDlgItem( hDlg, i );
  151.     ShowWindow( hCtrl, SW_SHOW );
  152.    }
  153.    /* hide from last to 9                                        */
  154.    for( ; k<=IDE_M7; i++, k++ )
  155.    {
  156.     hCtrl = GetDlgItem( hDlg, k );
  157.     ShowWindow( hCtrl, SW_HIDE );
  158.     hCtrl = GetDlgItem( hDlg, i );
  159.     ShowWindow( hCtrl, SW_HIDE );
  160.    }
  161.  
  162.    /* show MORE if more than 8 metabolites                        */
  163.    if (lots) ShowWindow( hMore, SW_SHOW );
  164.    else      ShowWindow( hMore, SW_HIDE );
  165.    break;
  166.  
  167.   case WM_COMMAND:
  168.    switch(wParam)
  169.    {
  170.     case IDC_REACTLST:
  171.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  172.      {
  173.       /* get the constants from the edit boxes                    */
  174.       for( i=IDE_M0, j=first; j<last; i++, j++)
  175.       {
  176.        hCtrl = GetDlgItem( hDlg, i);
  177.        len = (int) SendMessage( hCtrl, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  178.        if( len==0 ) *(prm[r]+j) = dft_const;
  179.        else *(prm[r]+j) = strtod( buff, NULL );
  180.        if( (*(prm[r]+j)==HUGE_VAL) || (*(prm[r]+j)==-HUGE_VAL) )
  181.        {
  182.         LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  183.         MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  184.         SetFocus( hCtrl );
  185.         return TRUE;
  186.        }
  187.       }
  188.       r = (int) SendMessage( hReactLst, LB_GETCURSEL, 0, 0 );
  189.       if( r != LB_ERR )
  190.        SendMessage( hDlg, WM_USER+1, 0, 0 );
  191.       break;
  192.      }
  193.      else return FALSE;
  194.  
  195.     case ID_MORE:
  196.      /* get the constants from the edit boxes                    */
  197.      for( i=IDE_M0, j=first; j<last; i++, j++)
  198.      {
  199.       hCtrl = GetDlgItem( hDlg, i);
  200.       len = (int) SendMessage( hCtrl, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  201.       if( len==0 ) *(prm[r]+j) = dft_const;
  202.       else *(prm[r]+j) = strtod( buff, NULL );
  203.       if( (*(prm[r]+j)==HUGE_VAL) || (*(prm[r]+j)==-HUGE_VAL) )
  204.       {
  205.        LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  206.        MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  207.        SetFocus( hCtrl );
  208.        return TRUE;
  209.       }
  210.      }
  211.      /* check need for going back to begginning                */
  212.      if ( circle )
  213.      {
  214.       circle = FALSE;
  215.       SendMessage( hDlg, WM_USER+1, 0, (DWORD) 0 );
  216.       break;
  217.      }
  218.      /* update working variables                            */
  219.      first = last;
  220.      last += 8;
  221.      if ( last >= (int) ktype[kinetu[r]].nconst )
  222.      {
  223.       last = ktype[kinetu[r]].nconst;
  224.       circle = TRUE;
  225.      }
  226.      /* update static controls with constant names                    */
  227.      for( j=first, i=IDT_M0; j<last; j++, i++ )
  228.      {
  229.       for( k=0, auxptr=ktype[kinetu[r]].constnam; k<j; k++ )
  230.       {
  231.        do{ auxptr++; } while( (*auxptr) );
  232.        auxptr++;
  233.       }
  234.       SetDlgItemText( hDlg, i, (LPSTR) auxptr);
  235.      }
  236.  
  237.      /* update edit boxes with constant's values                    */
  238.      for( j=first, i=IDE_M0; j<last; j++, i++ )
  239.      {
  240.       gcvt( *(prm[r]+j), 16, buff );
  241.       SetDlgItemText( hDlg, i, (LPSTR) buff);
  242.      }
  243.      /* show from first to last                                        */
  244.      for( j=first, i=IDT_M0, k=IDE_M0; j<last; j++, i++, k++ )
  245.      {
  246.       hCtrl = GetDlgItem( hDlg, k );
  247.       ShowWindow( hCtrl, SW_SHOW );
  248.       hCtrl = GetDlgItem( hDlg, i );
  249.       ShowWindow( hCtrl, SW_SHOW );
  250.      }
  251.      /* hide from last to 7                                            */
  252.      for( ; k<=IDE_M7; i++, k++ )
  253.      {
  254.       hCtrl = GetDlgItem( hDlg, k );
  255.       ShowWindow( hCtrl, SW_HIDE );
  256.       hCtrl = GetDlgItem( hDlg, i );
  257.       ShowWindow( hCtrl, SW_HIDE );
  258.      }
  259.      break;
  260.  
  261.     case IDC_KINETYPE:        /* Help on this kinetic model                */
  262.      if( kinetu[r] < MAX_TYP )
  263.          WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) ktype[kinetu[r]].descr );
  264.         else
  265.          WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "User-defined kinetics" );
  266.      break;
  267.  
  268.     case IDC_HELP:            /* Help on this Dialog Box                */
  269.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Kinetic constants" );
  270.      break;
  271.  
  272.     case IDOK:
  273.      /* get the constants from the edit boxes                    */
  274.      for( i=IDE_M0, j=first; j<last; i++, j++)
  275.      {
  276.       hCtrl = GetDlgItem( hDlg, i);
  277.       len = (int) SendMessage( hCtrl, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  278.       if( len==0 ) *(prm[r]+j) = dft_const;
  279.       else *(prm[r]+j) = strtod( buff, NULL );
  280.       if( (*(prm[r]+j)==HUGE_VAL) || (*(prm[r]+j)==-HUGE_VAL) )
  281.       {
  282.        LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  283.        MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  284.        SetFocus( hCtrl );
  285.        return TRUE;
  286.       }
  287.      }
  288.      /* copy params back from its mirror                                    */
  289.      _fmemcpy( (void __far *) params[0],
  290.                (void __far *) prm[0],
  291.                (size_t) sizeparam );
  292.      GlobalUnlock( hPrm );
  293.      GlobalFree( hPrm );
  294.      notsaved = 1;
  295.      EndDialog(hDlg, TRUE);
  296.      break;
  297.  
  298.     case IDCANCEL:
  299.      GlobalUnlock( hPrm );
  300.      GlobalFree( hPrm );
  301.      EndDialog(hDlg, FALSE);
  302.      break;
  303.    }
  304.    break;    /* End of WM_COMMAND                                 */
  305.  
  306.   default:
  307.    return FALSE;
  308.  }
  309.  return TRUE;
  310. } /* End of METABMsgProc                                      */
  311.  
  312.