home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDCONC.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  6KB  |  200 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. /*     Metabolite concentrations     */
  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( CODE4, EdConc )
  36.  
  37. BOOL FAR PASCAL EdConc(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  38. {
  39.  static int first, last, lots, i, j, k;
  40.  static BOOL circle;
  41.  int len;
  42.  HWND hCtrl;
  43.  char buff[128];
  44.  
  45.  switch(Message)
  46.  {
  47.   case WM_INITDIALOG:
  48.   /* copy metname to its mirror                                    */
  49.   _fmemcpy( (void __far *) x,
  50.             (void __far *) xu,
  51.             (size_t) MAX_MET * sizeof( double ) );
  52.  
  53.   case WM_USER+1:
  54.    /* initialize working variables                            */
  55.    if (totmet >= 10 ) last = 10;
  56.    else               last = totmet;
  57.    if (totmet > 10 )  lots = TRUE;
  58.    else               lots = FALSE;
  59.    first = 0;
  60.    circle = FALSE;
  61.  
  62.    /* initialize static controls with metabolite names            */
  63.    for( j=first, i=IDT_M0; j<last; j++, i++ )
  64.     SetDlgItemText( hDlg, i, (LPSTR) metname[j]);
  65.  
  66.    /* update edit boxes                                            */
  67.    for( j=first, i=IDE_M0; j<last; j++, i++ )
  68.    {
  69.     gcvt( x[j], 16, buff );
  70.     SetDlgItemText( hDlg, i, (LPSTR) buff);
  71.    }
  72.  
  73.    /* show from first to last     (static and edit controls)            */
  74.    for( j=first, i=IDT_M0, k=IDE_M0; j<last; j++, i++, k++ )
  75.    {
  76.     hCtrl = GetDlgItem( hDlg, k );
  77.     ShowWindow( hCtrl, SW_SHOW );
  78.     hCtrl = GetDlgItem( hDlg, i );
  79.     ShowWindow( hCtrl, SW_SHOW );
  80.    }
  81.    /* hide from last to 9                                            */
  82.    for( j=last; j<10; j++, i++, k++ )
  83.    {
  84.     hCtrl = GetDlgItem( hDlg, k );
  85.     ShowWindow( hCtrl, SW_HIDE );
  86.     hCtrl = GetDlgItem( hDlg, i );
  87.     ShowWindow( hCtrl, SW_HIDE );
  88.    }
  89.  
  90.    /* show MORE if more than 10 metabolites                        */
  91.    hCtrl = GetDlgItem( hDlg, ID_MORE );
  92.    if (lots) ShowWindow( hCtrl, SW_SHOW );
  93.    else      ShowWindow( hCtrl, SW_HIDE );
  94.    break;
  95.  
  96.   case WM_COMMAND:
  97.    switch(wParam)
  98.    {
  99.     case ID_MORE:
  100.      /* get the concentrations from the edit boxes            */
  101.      for( i=IDE_M0, j=first; j<last; i++, j++)
  102.      {
  103.       hCtrl = GetDlgItem( hDlg, i );
  104.       len = (int) SendMessage( hCtrl, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  105.       if( len==0 ) x[j] = dft_conc;
  106.       else x[j] = strtod( buff, NULL );
  107.       if( (x[j]==HUGE_VAL) || (x[j]==-HUGE_VAL) )
  108.       {
  109.        LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  110.        MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  111.        SetFocus( hCtrl );
  112.        return TRUE;
  113.       }
  114.      }
  115.      /* check need for going back to begginning                */
  116.      if ( circle )
  117.      {
  118.       circle = FALSE;
  119.       SendMessage( hDlg, WM_USER+1, 0, (DWORD) 0 );
  120.       break;
  121.      }
  122.      /* update working variables                            */
  123.      first = last;
  124.      last += 10;
  125.      if ( last >= totmet )
  126.      {
  127.       last = totmet;
  128.       circle = TRUE;
  129.      }
  130.      /* update metabolite names                                */
  131.      for( j=first, i=IDT_M0; j<last; j++, i++ )
  132.       SetDlgItemText( hDlg, i, (LPSTR) metname[j]);
  133.  
  134.      /* update edit boxes                                    */
  135.      for( j=first, i=IDE_M0; j<last; j++, i++ )
  136.      {
  137.       gcvt( x[j], 16, buff );
  138.       SetDlgItemText( hDlg, i, (LPSTR) buff);
  139.      }
  140.      /* show from first to last                                */
  141.      for( j=first, i=IDT_M0, k=IDE_M0; j<last; j++, i++, k++ )
  142.      {
  143.       hCtrl = GetDlgItem( hDlg, k );
  144.       ShowWindow( hCtrl, SW_SHOW );
  145.       hCtrl = GetDlgItem( hDlg, i );
  146.       ShowWindow( hCtrl, SW_SHOW );
  147.      }
  148.      /* hide from last to 9                                            */
  149.      for( ; k<=IDE_M9; i++, k++ )
  150.      {
  151.       hCtrl = GetDlgItem( hDlg, k );
  152.       ShowWindow( hCtrl, SW_HIDE );
  153.       hCtrl = GetDlgItem( hDlg, i );
  154.       ShowWindow( hCtrl, SW_HIDE );
  155.      }
  156.      break;
  157.  
  158.     case IDC_HELP:            /* Help on this Dialog Box                */
  159.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Metabolite initial concentrations" );
  160.      break;
  161.  
  162.     case IDOK:
  163.      /* get the concentrations from the edit boxes            */
  164.      for( i=IDE_M0, j=first; j<last; i++, j++)
  165.      {
  166.       hCtrl = GetDlgItem( hDlg, i);
  167.       len = (int) SendMessage( hCtrl, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  168.       if( len==0 ) x[j] = dft_conc;
  169.       else x[j] = strtod( buff, NULL );
  170.       if( (x[j]==HUGE_VAL) || (x[j]==-HUGE_VAL) )
  171.       {
  172.        LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  173.        MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  174.        SetFocus( hCtrl );
  175.        return TRUE;
  176.       }
  177.      }
  178.      /* copy metname back from its mirror                                    */
  179.      _fmemcpy( (void __far *) xu,
  180.                (void __far *) x,
  181.                (size_t) MAX_MET * sizeof( double ) );
  182.      notsaved = 1;
  183.      EndDialog(hDlg, TRUE);
  184.      break;
  185.  
  186.     case IDCANCEL:
  187.      /* Ignore data values entered into the controls        */
  188.      /* and dismiss the dialog window returning FALSE       */
  189.      EndDialog(hDlg, FALSE);
  190.      break;
  191.    }
  192.    break;    /* End of WM_COMMAND                                 */
  193.  
  194.   default:
  195.    return FALSE;
  196.  }
  197.  return TRUE;
  198. } /* End of EdConc                                      */
  199.  
  200.