home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDLOOP.C < prev    next >
C/C++ Source or Header  |  1992-12-15  |  10KB  |  295 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. /*          GWTOP - Topology         */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*          Loops dialog box         */
  14. /*                                   */
  15. /*           QuickC/WIN 1.0          */
  16. /*                                   */
  17. /*   (include here compilers that    */
  18. /*   compiled GWSIM successfully)    */
  19. /*                                   */
  20. /*************************************/
  21.  
  22.  
  23. #include <windows.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "defines.h"                    /* symbols also used in .DLG files        */
  27. #include "globals.h"                    /* gepasi's own symbols                    */
  28. #include "gwtop.h"                        /* macros, function prototypes, etc.    */
  29. #include "gep1.h"                        /* gepasi's variables                    */
  30. #include "topgvar.h"                    /* global variables                        */
  31.  
  32. void ModSel( HWND hCB, int r, unsigned char modn );
  33.  
  34. #pragma alloc_text( CODE4, ModSel, EdLoop)
  35.  
  36. void ModSel( HWND hCB, int r, unsigned char modn )
  37. {
  38.  char name[NAME_L];
  39.  int i, j;
  40.  
  41.  /* first get the text of the new metabolite                    */
  42.  SendMessage( hCB, WM_GETTEXT, (WORD) NAME_L, (DWORD) (LPSTR) name);
  43.  if( ! strcmp( "<not defined>", name ) )
  44.  {
  45.   for( j=0; j<totm; j++ )
  46.    if( (*lp)[r][j] == modn )
  47.    {
  48.     (*lp)[r][j] = 0;
  49.     nmd[r]--;
  50.    }
  51.  }
  52.  else
  53.  {
  54.   for( i=0; i<totm; i++)
  55.    if( ! lstrcmp( &metn[i][0], name ) ) break;
  56.   if( i==totm )                        /* metab. not yet defined            */
  57.   {
  58.    lstrcpy( &metn[i][0], name );
  59.    totm++;
  60.    for(j=0; j<nst; j++) sto[i*MAX_MET + j] = 0;
  61.    intm[i] = 0;
  62.   }
  63.   if( (*lp)[r][i]==0) nmd[r]++;     /* increase nmd if no modif. before    */
  64.   (*lp)[r][i] = modn;
  65.  }
  66. }
  67.  
  68. BOOL FAR PASCAL EdLoop( HWND hDlg, WORD message, WORD wParam, LONG lParam )
  69. {
  70.  static    HWND    hReactLst, hCombo, hMoreButt, hTitle, hCount;
  71.  static int    ridx[MAX_STEP];
  72.  static int react_sel;
  73.  static unsigned char modfnum;
  74.  int i, j, r;
  75.  char buff[128];
  76.  
  77.  switch( message )
  78.  {
  79.   case WM_INITDIALOG:
  80.    lbWidth = 0;                                            /* set the width of the list box to 0    */
  81.  
  82.    /* show the image on the mirror.                */
  83.    _fmemcpy( (void __far *) lp,
  84.                 (void __far *) loop,
  85.              (size_t) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  86.    _fmemcpy( (void __far *) kinet,
  87.                 (void __far *) kinetu,
  88.              (size_t) MAX_STEP * sizeof( int ) );
  89.    _fmemcpy( (void __far *) metn,
  90.                 (void __far *) metname,
  91.                 (size_t) MAX_MET * NAME_L * sizeof( char ) );
  92.    _fmemcpy( (void __far *) sto,
  93.                 (void __far *) stoiu,
  94.              (size_t) MAX_MET * MAX_STEP * sizeof( int ) );
  95.    _fmemcpy( (void __far *) intm,
  96.                 (void __far *) intmet,
  97.                 (size_t) MAX_MET * sizeof( int ) );
  98.    _fmemcpy( (void __far *) nmd,
  99.               (void __far *) nmod,
  100.              (size_t) MAX_STEP * sizeof( unsigned char ) );
  101.    nst = nsteps;
  102.    totm = totmet;
  103.  
  104.    /* get handles to controls                                    */
  105.    hReactLst = GetDlgItem( hDlg, IDC_REACTLST );
  106.    hCombo = GetDlgItem( hDlg, IDC_LOOPLST );
  107.    hMoreButt = GetDlgItem( hDlg, ID_MORE );
  108.    hTitle = GetDlgItem( hDlg, IDSTAT_3 );
  109.    hCount = GetDlgItem( hDlg, IDSTAT_1 );
  110.  
  111.    /* insert <not defined> in the first position of the combo box    */
  112.    SendMessage( hCombo, CB_INSERTSTRING, -1, (DWORD) (LPSTR) "<not defined>" );
  113.  
  114.    /* insert all metabolites to the combo box                        */
  115.    for( i=0; i<totmet; i++ )
  116.     SendMessage( hCombo, CB_INSERTSTRING, -1, (DWORD) metname[i] );
  117.  
  118.    /* initialize hReactLst: add all reactions with modifiers    */
  119.    for( i=0,j=0; i<nsteps; i++ )
  120.     if( ktype[kinet[i]].nmodf > 0 )
  121.     {
  122.      ridx[j] = i;
  123.      AddReactLst( hReactLst, i, 0, 0, &totmet, metname, stoiu, intmet, revers, rstr );
  124.      j++;
  125.     }
  126.  
  127.     /* select the first reaction of hReactLst                        */
  128.     SendMessage( hReactLst, LB_SETCURSEL, 0, 0 );
  129.     react_sel = 0;
  130.  
  131.     /* it is the first modf that we are dealing with now            */
  132.     modfnum = 1;
  133.     /* display its ordinal number                                    */
  134.     wsprintf( (LPSTR) buff, "%d%s modifier", modfnum,
  135.               (modfnum % 10) == 1 ? (LPSTR) "st"
  136.                                   : ( (modfnum % 10) == 2 ? (LPSTR) "nd"
  137.                                                           : ( (modfnum % 10) == 3 ? (LPSTR) "rd"
  138.                                                                                   : (LPSTR) "th"
  139.                                                              )
  140.                                     )
  141.             );
  142.     SendMessage( hTitle, WM_SETTEXT, 0, (DWORD) (LPSTR) buff );
  143.  
  144.     /* if this type has several modfs show the MORE button            */
  145.     if( ktype[kinet[ridx[react_sel]]].nmodf > 1 )
  146.     {
  147.      ShowWindow( hMoreButt, SW_SHOW );
  148.      wsprintf( buff, "This reaction has %d modifiers",
  149.                      ktype[kinet[ridx[react_sel]]].nmodf );
  150.     }
  151.     else
  152.     {
  153.      ShowWindow( hMoreButt, SW_HIDE );
  154.      wsprintf( buff, "This reaction has 1 modifier" );
  155.     }
  156.     SendMessage( hCount, WM_SETTEXT, 0, (DWORD) (LPSTR) buff );
  157.  
  158.    /* select the appropriate modifier                                */
  159.    for(i=0; i<totm; i++)
  160.     if( (*lp)[ridx[react_sel]][i] == modfnum )
  161.     {
  162.      SendMessage( hCombo, CB_SETCURSEL, i+1, 0 );
  163.      break;
  164.     }
  165.    if( i==totm ) SendMessage( hCombo, CB_SETCURSEL, 0, 0 );
  166.  
  167.    return( TRUE );
  168.  
  169.   case WM_COMMAND:
  170.    switch( wParam )
  171.    {
  172.     case IDC_REACTLST:
  173.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  174.      {
  175.       /* process previous selection                                        */
  176.       ModSel( hCombo, ridx[react_sel], modfnum );
  177.  
  178.       /* select the appropriate reaction of hReactLst                    */
  179.       if( ( react_sel = (int) SendMessage( hReactLst, LB_GETCURSEL, 0, 0 ) ) != LB_ERR )
  180.       {
  181.        /* signal that it is the first modf that we are dealing with now    */
  182.        modfnum = 1;
  183.        /* display its ordinal number                                    */
  184.        wsprintf( (LPSTR) buff, "%d%s modifier", modfnum,
  185.                  (modfnum % 10) == 1 ? (LPSTR) "st"
  186.                                      : ( (modfnum % 10) == 2 ? (LPSTR) "nd"
  187.                                                              : ( (modfnum % 10) == 3 ? (LPSTR) "rd"
  188.                                                                                      : (LPSTR) "th"
  189.                                                                )
  190.                                        )
  191.                );
  192.        SendMessage( hTitle, WM_SETTEXT, 0, (DWORD) (LPSTR) buff );
  193.  
  194.        /* if this type has several modfs show the MORE button            */
  195.        if( ktype[kinet[ridx[react_sel]]].nmodf > 1 )
  196.        {
  197.         ShowWindow( hMoreButt, SW_SHOW );
  198.         wsprintf( buff, "This reaction has %d modifiers",
  199.                         ktype[kinet[ridx[react_sel]]].nmodf );
  200.        }
  201.        else
  202.        {
  203.         ShowWindow( hMoreButt, SW_HIDE );
  204.         wsprintf( buff, "This reaction has 1 modifier" );
  205.        }
  206.        SendMessage( hCount, WM_SETTEXT, 0, (DWORD) (LPSTR) buff );
  207.  
  208.        /* select the appropriate modifier                                */
  209.        for(i=0; i<totm; i++)
  210.         if( (*lp)[ridx[react_sel]][i] == modfnum )
  211.         {
  212.          SendMessage( hCombo, CB_SETCURSEL, i+1, 0 );
  213.          break;
  214.         }
  215.        if( i==totm ) SendMessage( hCombo, CB_SETCURSEL, 0, 0 );
  216.        return TRUE;
  217.       }
  218.       else return FALSE;
  219.      }
  220.      else return FALSE;
  221.  
  222.     case ID_MORE:
  223.      ModSel( hCombo, ridx[react_sel], modfnum );
  224.      if( modfnum == ktype[kinet[ridx[react_sel]]].nmodf ) modfnum = 1;
  225.      else modfnum++;
  226.      wsprintf( (LPSTR) buff, "%d%s modifier", modfnum,
  227.                (modfnum % 10) == 1 ? (LPSTR) "st"
  228.                                    : ( (modfnum % 10) == 2 ? (LPSTR) "nd"
  229.                                                            : ( (modfnum % 10) == 3 ? (LPSTR) "rd"
  230.                                                                                    : (LPSTR) "th"
  231.                                                               )
  232.                                      )
  233.              );
  234.      SendMessage( hTitle, WM_SETTEXT, 0, (DWORD) (LPSTR) buff );
  235.  
  236.      /* select the appropriate modifier                                */
  237.      for(i=0; i<totm; i++)
  238.       if( (*lp)[ridx[react_sel]][i] == modfnum )
  239.       {
  240.        SendMessage( hCombo, CB_SETCURSEL, i+1, 0 );
  241.        break;
  242.       }
  243.      if( i==totm ) SendMessage( hCombo, CB_SETCURSEL, 0, 0 );
  244.      return TRUE;
  245.  
  246.     case IDC_HELP:                        /* Help for this Dialog Box             */
  247.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Loop editor" );
  248.      return( TRUE );
  249.  
  250.     case IDOK:
  251.      ModSel( hCombo, ridx[react_sel], modfnum );
  252.      /* copy the altered image to the original    */
  253.      _fmemcpy( (void __far *) loop,
  254.                   (void __far *) lp,
  255.                (size_t) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  256.      _fmemcpy( (void __far *) kinetu,
  257.                   (void __far *) kinet,
  258.                (size_t) MAX_STEP * sizeof( int ) );
  259.      _fmemcpy( (void __far *) metname,
  260.                   (void __far *) metn,
  261.                   (size_t) MAX_MET * NAME_L * sizeof( char ) );
  262.      _fmemcpy( (void __far *) stoiu,
  263.                   (void __far *) sto,
  264.                (size_t) MAX_MET * MAX_STEP * sizeof( int ) );
  265.      _fmemcpy( (void __far *) intmet,
  266.                   (void __far *) intm,
  267.                   (size_t) MAX_MET * sizeof( int ) );
  268.      _fmemcpy( (void __far *) nmod,
  269.                 (void __far *) nmd,
  270.                (size_t) MAX_STEP * sizeof( unsigned char ) );
  271.      nsteps = nst;
  272.      totmet = totm;
  273.  
  274.      for( i=0, loopass=0; i<nsteps ; i++)
  275.      {
  276.       /* copy nmd to nmod                        */
  277.       nmod[i] = nmd[i];
  278.       /* count the number of assigned loops        */
  279.       if( (ktype[kinet[i]].nmodf>0) &&
  280.           (ktype[kinet[i]].nmodf == nmod[i]) ) loopass++;
  281.      }
  282.      notsaved = 1;
  283.      /* close the dialog box and return            */
  284.      EndDialog( hDlg, IDOK );
  285.      return( TRUE );
  286.  
  287.     case IDCANCEL:
  288.      /* close the dialog box and return            */
  289.      EndDialog( hDlg, IDCANCEL );
  290.      return( TRUE );
  291.    }
  292.  
  293.   default: return( FALSE );
  294.  }
  295. }