📄 gwsim.c
字号:
#include "copyleft.h"
/*
GEPASI - a simulator of metabolic pathways and other dynamical systems
Copyright (C) 1989, 1992, 1993 Pedro Mendes
*/
/*************************************/
/* */
/* GWSIM - Simulation */
/* MS-WINDOWS front end */
/* */
/* Simulation window */
/* */
/* QuickC/WIN 1.0 */
/* */
/* (include here compilers that */
/* compiled GWSIM successfully) */
/* */
/*************************************/
/*
be sure that IOTOP.C is recompiled and that
iotop.obj from a GWTOP compilation is not
being used now. To be sure, delete iotop.obj
*/
#include <windows.h>
#include <string.h>
#include <direct.h>
#include "commdlg.h"
#include "toolhelp.h"
#include "basic.h" /* basic windows function prototypes */
#include "defines.h" /* symbols also used in .DLG files */
#include "globals.h" /* gepasi's own symbols */
#include "gwsim.h" /* macros, function prototypes, etc. */
#include "gep2.h" /* gepasi's variables */
#include "strtbl.h" /* symbols for the string table */
#include "iosim.h"
#include "iotop.h"
#define HELP_PARTIALKEY 0x0105
/* Struct pointed to by WM_GETMINMAXINFO lParam
typedef struct tagMINMAXINFO
{
POINT ptReserved;
POINT ptMaxSize;
POINT ptMaxPosition;
POINT ptMinTrackSize;
POINT ptMaxTrackSize;
} MINMAXINFO; */
/* global variables */
char szString[256]; /* variable to load resource strings */
char szHelpFile[] =
"GEPASI.HLP"; /* help file name */
char szAppName[20]; /* class name for the window */
HCURSOR hHourGlass; /* handle for the wait cursor */
WORD lbWidth; /* width of largest string in list box */
HANDLE hInst; /* handle to this instance of the appl. */
HWND hWndMain; /* handle to the main window */
HWND hButton1; /* handle to push button */
HWND hButton2; /* handle to push button */
HMENU hMenu; /* handle to the menu */
GLOBALHANDLE hPrm; /* handle to memory block with prm */
GLOBALHANDLE hOel; /* handle to memory block w/ oel */
GLOBALHANDLE hScp; /* handle to memory block w/ scp */
double huge *prm[MAX_STEP]; /* mirror of params */
struct ou huge *oel; /* mirror of outpel */
struct sp huge *scp; /* mirror of spar */
double x[MAX_MET]; /* initial concentrations */
int notsaved; /* 1 if file has not been saved */
int eqefl; /* for compatibility with IOTOP.C */
int lno; /* number of link to edit */
int nlks; /* mirror of nlinks */
char GepasiIni[256]; /* GEPASI's INI file with full path */
char GnuplotExe[256]; /* name of gnuplot.exe with full path */
char CommandLine[1024];
char FileName[256]; /* filename of sim file with full path */
char FileTitle[13]; /* filename of sim file w/o full path */
char TopFile[256]; /* filename of top file with full path */
char TopTitle[13]; /* filename of top file w/o full path */
char DatName[256]; /* filename of dat file with full path */
char DatTitle[13]; /* filename of dat file w/o full path */
char LogFile[256]; /* filename of log file with full path */
FARPROC fpCheckSimEng; /* MakeProcInstance of callback */
char TempFile[256]; /* filename of temporary file */
int TimerId; /* identifies the timer */
int running; /* set when simulation engine is active */
#pragma alloc_text( CODE0, WinMain, clear_all, WndProc, RegisterClasses, DeleteTmp, CleanUp )
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
/***********************************************************************/
/* HANDLE hInstance; handle for this instance */
/* HANDLE hPrevInstance; handle for possible previous instances */
/* LPSTR lpszCmdLine; long pointer to exec command line */
/* int nCmdShow; Show code for main window display */
/***********************************************************************/
MSG msg; /* MSG structure to store your messages */
int nRc; /* return value from Register Classes */
char *ptr;
LPSTR lp;
OFSTRUCT OfStruct;
HANDLE hAcc;
strcpy(szAppName, "GWSIM");
hInst = hInstance;
if(!hPrevInstance)
{
/* register window classes if first instance of application */
if ((nRc = RegisterClasses()) == -1)
{
/* registering one of the windows failed */
LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString));
MessageBeep( MB_ICONHAND );
MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
return nRc;
}
}
/* setup the device independent screen units */
InitScrScale();
/* load the wait cursor */
hHourGlass = LoadCursor(NULL, IDC_WAIT);
/* load the accelerators table */
hAcc = LoadAccelerators( hInst, (LPSTR) "ACCTABLE" );
if( InitGepasiVar() != 0 ) /* initialize GEPASI's vars */
{
LoadString(hInst, IDS_ERR_OUT_OF_MEM, szString, sizeof(szString));
MessageBeep( MB_ICONHAND );
MessageBox(NULL, szString, NULL, MB_ICONSTOP);
if(!hPrevInstance) UnregisterClass(szAppName, hInst);
return IDS_ERR_OUT_OF_MEM;
}
/* get the path of GEPASI's binary files directory */
GetModuleFileName( hInst, (LPSTR) GepasiIni, sizeof( GepasiIni ) );
ptr = strrchr( GepasiIni, '\\' );
*(ptr+1) = '\0';
/* append the filename of the INI file */
lstrcat( (LPSTR) GepasiIni, (LPSTR) "GEPASI.INI" );
/* create application's Main window */
hWndMain = CreateWindow(
szAppName, /* Window class name */
"GEPASI - Simulation", /* Window's title */
WS_CAPTION | /* Title and Min/Max */
WS_SYSMENU | /* Add system menu box */
WS_MINIMIZEBOX | /* Add minimize box */
WS_CLIPCHILDREN | /* don't draw in child windows areas */
WS_OVERLAPPED,
CW_USEDEFAULT, 0, /* Use default X, Y */
ScrX(180), ScrY(90),
NULL, /* Parent window's handle */
NULL, /* Default to Class Menu */
hInst, /* Instance of window */
NULL); /* Create struct for WM_CREATE */
if(hWndMain == NULL)
{
LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
MessageBeep( MB_ICONEXCLAMATION );
MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
TidyGepasiVar();
return IDS_ERR_CREATE_WINDOW;
}
InitTxtMetrics( hWndMain );
/* create the button controls */
hButton1 = CreateWindow( "Button", "&Top",
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
ScrX(114), ScrY(40),
ScrX(30), ScrY(24),
hWndMain, IDC_BUTTON1, hInst, NULL );
if(hButton1 == NULL)
{
LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
MessageBeep( MB_ICONHAND );
MessageBox(NULL, szString, NULL, MB_ICONSTOP);
CleanUp( hWndMain, hPrevInstance );
return IDS_ERR_CREATE_WINDOW;
}
hButton2 = CreateWindow( "Button", "&Run!",
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
ScrX(145), ScrY(40),
ScrX(30), ScrY(24),
hWndMain, IDC_BUTTON2, hInst, NULL );
if(hButton2 == NULL)
{
LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
MessageBeep( MB_ICONHAND );
MessageBox(NULL, szString, NULL, MB_ICONSTOP);
CleanUp( hWndMain, hPrevInstance );
return IDS_ERR_CREATE_WINDOW;
}
/* store the pointer to the timer callback function */
fpCheckSimEng = MakeProcInstance(CheckSimEng, hInst);
/* get options from GEPASI.INI file */
/* get the complete filename path of wgnuplot.exe */
GetPrivateProfileString( (LPSTR) "Gnuplot",
(LPSTR) "Path",
(LPSTR) "\0",
(LPSTR) GnuplotExe,
sizeof( GnuplotExe ),
(LPSTR) GepasiIni
);
/* test if the file really exists */
nRc = OpenFile( (LPSTR) GnuplotExe, &OfStruct, OF_READ );
if( nRc==-1 ) *GnuplotExe = '\0';
else _lclose( nRc );
ShowWindow(hWndMain, nCmdShow); /* display main window */
/* if called with a .sim filename argument, store it in FileName */
FileName[0] = '\0';
if( *lpszCmdLine)
{
lp = _fstrchr( lpszCmdLine, ' ' );
if( lp != NULL ) *lp = '\0';
lstrcat( (LPSTR) FileName, lpszCmdLine );
SendMessage( hWndMain, WM_USER+1, 0, (DWORD) 0 );
}
while(GetMessage(&msg, NULL, 0, 0)) /* Until WM_QUIT message */
{
if( !TranslateAccelerator( hWndMain, hAcc, &msg ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/* clean up before exiting from the application */
CleanUp(hWndMain, hPrevInstance);
return msg.wParam;
} /* End of WinMain */
void clear_all( HWND hWnd )
{
int i;
totmet = nsteps = nscanpar = totsel =
totscan = nloops = noutpel = nlinks =
nudf = 0;
nrateq = MAX_TYP;
notsaved = 0;
FileName[0] = FileTitle[0] = '\0';
for( i=0; i<MAX_MET; i++ ) xu[i] = 0;
get_dfts();
SendMessage( hWnd, WM_CREATE, 0, 0 );
}
LONG FAR PASCAL WndProc(HWND hWnd, WORD Message, WORD wParam, LONG lParam)
{
HDC hDC; /* handle for the display device */
MINMAXINFO FAR* lpmmi; /* pointer to minmaxinfo structure */
PAINTSTRUCT ps; /* holds PAINT information */
FARPROC lpfnProc; /* pointer to dialog procedures */
int nRc=0; /* return code */
char szASTR[128];
char tmpFile[256];
int i, j, dim;
unsigned long perm;
char *ptr;
switch (Message)
{
case WM_CREATE:
hMenu = GetMenu( hWnd );
EnableMenuItem( hMenu, IDM_F_SAVE, MF_GRAYED );
EnableMenuItem( hMenu, IDM_F_SAVEAS, MF_GRAYED );
EnableMenuItem( hMenu, IDM_E_METABOLITES, MF_GRAYED );
EnableMenuItem( hMenu, IDM_E_KINETICS, MF_GRAYED );
EnableMenuItem( hMenu, IDM_O_TASKS, MF_GRAYED );
EnableMenuItem( hMenu, IDM_O_UNITS, MF_GRAYED );
EnableMenuItem( hMenu, IDM_O_OUTPUT, MF_GRAYED );
EnableMenuItem( hMenu, IDM_O_REPORT, MF_GRAYED );
EnableMenuItem( hMenu, IDM_GO, MF_GRAYED );
EnableMenuItem( hMenu, IDM_PLOT, MF_GRAYED );
EnableWindow( hButton2, FALSE );
SendMessage( hWnd, WM_COMMAND, IDM_S_NONE, 0 );
DrawMenuBar( hWnd );
break; /* End of WM_CREATE */
case WM_CLOSE: /* close the window */
if( notsaved )
AskAboutSave( hWnd, hInst, FileName, MB_ICONQUESTION | MB_YESNO );
/* tell WinHelp we're closing */
WinHelp( hWnd, (LPSTR) szHelpFile, HELP_QUIT, 0 );
/* kill the timer (it will fail if one is not active) */
KillTimer( hWnd, TimerId );
DestroyWindow(hWnd);
if (hWnd == hWndMain)
PostQuitMessage(0); /* Quit the application */
break;
case WM_QUERYENDSESSION:
/* windows is about to shut-down... */
if( notsaved )
{
nRc = AskAboutSave( hWnd, hInst, FileName, MB_ICONQUESTION | MB_YESNOCANCEL );
if ( nRc != IDCANCEL ) return 1;
else return 0;
}
return 1;
case WM_COMPACTING:
/* windows is taking a lot of time compacting memory: FULL! */
LoadString(hInst, IDS_ERR_OUT_OF_MEM, szString, sizeof(szString));
MessageBeep( MB_ICONEXCLAMATION );
MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
return 1;
case WM_PAINT:
/* Obtain a handle to the device context */
memset( &ps, 0x00, sizeof( PAINTSTRUCT ) );
/* BeginPaint will sends WM_ERASEBKGND if appropriate */
hDC = BeginPaint(hWnd, &ps);
/* Included in case the background is not a pure color */
SetBkMode( hDC, TRANSPARENT );
i=0;
if( FileName[0] != '\0' )
wsprintf( szASTR, "%s", (LPSTR) FileName );
else
wsprintf( szASTR, "<untitled>");
TextOut( hDC, TxtX(0), TxtY(i++), szASTR, strlen( szASTR ) );
wsprintf( szASTR, "%i metabolites", totmet );
TextOut( hDC, TxtX(0), TxtY(i++), szASTR, strlen( szASTR ) );
wsprintf( szASTR, "%i steps", nsteps );
TextOut( hDC, TxtX(0), TxtY(i++), szASTR, strlen( szASTR ) );
if( options.scan )
{
/* count the number of dimensions and permutations */
for( j=dim=0, perm=1; j<nscanpar; j++ )
if( spar[j].idx!=0 )
{
dim++;
perm *= spar[j].dens+1;
}
if( options.scan == 1 )
wsprintf( szASTR, "%dD regular grid", dim );
else
{
wsprintf( szASTR, "%dD random fill", dim );
perm = options.scandens;
}
TextOut( hDC, TxtX(0), TxtY(i++), szASTR, strlen( szASTR ) );
wsprintf( szASTR, "%lu iterations", perm );
TextOut( hDC, TxtX(0), TxtY(i++), szASTR, strlen( szASTR ) );
wsprintf( szASTR, "%i links", nlinks );
TextOut( hDC, TxtX(0), TxtY(i++), szASTR, strlen( szASTR ) );
}
EndPaint( hWnd, &ps );
break; /* End of WM_PAINT */
case WM_USER+1:
if( !(nRc = ReadSim( FileName ) ) )
{
/* kill the timer (it will fail if one is not active) */
KillTimer( hWnd, TimerId );
GetFileTitle( (LPSTR) FileName, (LPSTR) FileTitle, sizeof(FileTitle) );
GetFileTitle( (LPSTR) DatName, (LPSTR) DatTitle, sizeof(DatTitle) );
EnableMenuItem( hMenu, IDM_F_SAVE , MF_ENABLED );
EnableMenuItem( hMenu, IDM_F_SAVEAS , MF_ENABLED );
EnableMenuItem( hMenu, IDM_E_METABOLITES , MF_ENABLED );
EnableMenuItem( hMenu, IDM_E_KINETICS , MF_ENABLED );
EnableMenuItem( hMenu, IDM_E_OPTIONS , MF_ENABLED );
EnableMenuItem( hMenu, IDM_O_TASKS, MF_ENABLED );
EnableMenuItem( hMenu, IDM_O_UNITS, MF_ENABLED );
EnableMenuItem( hMenu, IDM_GO, MF_ENABLED );
EnableMenuItem( hMenu, IDM_PLOT, MF_ENABLED );
EnableWindow( hButton2, TRUE );
if( options.dat ) EnableMenuItem( hMenu, IDM_O_OUTPUT, MF_ENABLED );
if( options.txt ) EnableMenuItem( hMenu, IDM_O_REPORT, MF_ENABLED );
if( !(options.dyn || options.ss) )
{
EnableMenuItem( hMenu, IDM_O_OUTPUT, MF_GRAYED );
EnableMenuItem( hMenu, IDM_O_REPORT, MF_GRAYED );
EnableMenuItem( hMenu, IDM_GO, MF_GRAYED );
EnableWindow( hButton2, FALSE );
}
switch( options.scan )
{
case 0: SendMessage( hWnd, WM_COMMAND, IDM_S_NONE, 0 ); break;
case 1: SendMessage( hWnd, WM_COMMAND, IDM_S_GRID, 0 ); break;
case 2: SendMessage( hWnd, WM_COMMAND, IDM_S_FILL, 0 ); break;
}
wsprintf( (LPSTR) szASTR, "GEPASI - %s", (LPSTR) FileTitle );
SendMessage( hWnd, WM_SETTEXT, 0, (DWORD) (LPSTR) szASTR );
InvalidateRect( hWnd, NULL, TRUE );
DrawMenuBar( hWnd );
notsaved = 0;
}
else
{
LoadString(hInst, nRc, szString, sizeof(szString));
wsprintf( (LPSTR) szASTR, "GEPASI - Simulation" );
SendMessage( hWnd, WM_SETTEXT, 0, (DWORD) (LPSTR) szASTR );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -