📄 pcrgraph.cpp
字号:
LPSTR lpszCmdLine, int nCmdShow) { DWORD dwStyle = WS_OVERLAPPEDWINDOW; if (!hPrevInstance) { /* Register Class for First Overlapped Window */ rClass.lpszClassName = "FreeFem++" ; rClass.hInstance = hInstance; rClass.lpfnWndProc = OpenWindowProc1; rClass.hCursor = LoadCursor(NULL, IDC_ARROW); rClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); rClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); rClass.style = 0x4000; rClass.cbClsExtra = 0; rClass.cbWndExtra = 0; if (!RegisterClass( &rClass)) return FALSE; } int dd=600; int ddx0=200; int ddy0=30;// long dwFlags;/* DEVMODE dev_mode = {0}; if(!EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dev_mode)) { cout << " screen size ?? " << dev_mode.dmPelsWidth << " x " << dev_mode.dmPelsHeight << endl; dd = Min(dev_mode.dmPelsWidth*0.7,dev_mode.dmPelsHeight*0.9); ddx0 = dev_mode.dmPelsWidth*0.28; ddy0=dev_mode.dmPelsHeight*0.05; } else cout << " Error EnumDisplaySettings => no screen size " << endl; */ int sx = GetSystemMetrics(SM_CXSCREEN); int sy = GetSystemMetrics(SM_CYSCREEN); dd = static_cast<int>(Min(sx*0.7,sy*0.9)); ddx0 = static_cast<int>(sx*0.28); ddy0 = static_cast<int>(sy*0.05); //cout << " Screen Size " << sx << " x " << sy << endl; // Rectangle ss=Get_VirtualScreen(); // dd=(Abs(ss.get_Top-ss.get_Bottom())*90)/100; GetOption(lpszCmdLine); hWnd = CreateWindow("FreeFEM++", PACKAGE_STRING " for Windows", dwStyle,ddx0,ddy0,dd,dd,/* CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,*/ NULL, NULL, hInstance, NULL); if (*fullName == '\0' && (winf_flg != winf_Usage)) { // in command line, there is no filename if (ShowOpenDialogBox(shortName)==FALSE) { exit(0); } strcpy(fullName,shortName); } if (inittext()==FALSE) myexit(1); else if (winf_flg & winf_VFFEM ) { // create only cache, option "-f" is given if (!getcwd(FreeFemCache,MAX_PATH)) { FatalErr("Fail to get current path",-1); } strcat(FreeFemCache,"\\cache\\"); if (chdir(FreeFemCache)) { // check the cache directory#ifndef __CYGWIN__ if (mkdir(FreeFemCache)) {#else if (mkdir(FreeFemCache,0777)) {#endif sprintf(errbuf,"Fail to create the directory %s",FreeFemCache); FatalErr(errbuf,-1); } } else (chdir("..\\")); // already created return TRUE; }; return TRUE;}/* OpenWindowProc1 - Handles messages for the main window. * Parameters: * hWnd - Handle to Window which message is delivered to. * msgID - ID number of message * wParam - 16-bit parameter * lParam - 32-bit parameter * */LONG WINAPI OpenWindowProc1( HWND hWnd, UINT wMsgID, WPARAM wParam, LPARAM lParam){ switch (wMsgID) { case WM_DESTROY: PostQuitMessage(0); DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, wMsgID, wParam, lParam); } return 0;}//*OT 29/12/98// Routines and functions for WinfFEMint chkCacheDir();BOOL TestProjetPresence(char *shortName);BOOL CreateProjetFile(char *shortName);BOOL SaveLogFile(char *fileName);void GetOption(int argc, char *argv[]);FILE *projet=NULL;// end int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, // int argc, char *argv[] int nCmdShow){ MSG msg; LPTSTR cmd = GetCommandLine(); if (Init(hInstance, hPrevInstance,lpszCmdLine,nCmdShow)) { // main after checking options if (mainFreeFEM() == FALSE) myexit(99); // exit with error else myexit(0); while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } myexit(msg.wParam); // exit(msg.wParam); } return -1;}// the real main extern int mymain(int argc,char **argv);// main() in FreeFEM+ for PCsBOOL mainFreeFEM(){ char prjName[256]; if (winf_flg & winf_VFFEM) { // given by "-f filename" strcpy(prjName,ChangePdeToExt(shortName,"prj")); if (strcmp(FreeFemCache,"")!=0) if (CreateProjetFile(prjName)==FALSE) FatalErr(prjName,-1); } cout << "Welcome to freefem++ v " << StrVersionNumber() <<endl; cout << "Program file [" << fullName <<']'<< endl; time_t ltime; // write the time stump in console struct tm *now; time(<ime); now = localtime(<ime); cout << "Start Time: " << asctime(now) << endl; ShowWindow(hWnd,SW_SHOW); initgraphique(); int argc; char * argv [3]; argc = 2; argv[0]= "FreeFem++"; argv[1]= fullName;// int main (int argc, char **argv) int ret=1; try { //compile(fullName); ret=mymain(argc,argv); cout << fullName << endl; rattente(1); rattente(1); } catch(Error &e){ ret=e.errcode(); cout<<" error "<<e.what(); myexit(1); }; if (projet!=NULL) fclose(projet); SetWindowText(hWnd,"End of FreeFEM++"); if (winf_flg & winf_NOWAIT) { // option "-s" myexit(ret); }; return ret==0;}// error without consoleBOOL FatalErr(char *s, int err){ int ret; UINT Style = MB_SYSTEMMODAL|MB_ICONEXCLAMATION; if (err==0) Style |= MB_YESNO; else Style |= MB_OK; ret = MessageBox(NULL,s,"Information from FreeFEM++",Style); if (!err & (ret ==IDYES)) return TRUE; else if (!err & (ret == IDNO)) return FALSE; else if (err != 99) exit(err); return TRUE;}//*OT// Modules for debug console and logvoid SetConsole(HANDLE hConsole){ SMALL_RECT srctWindowRect; COORD coordScreen; srctWindowRect.Left = 10; srctWindowRect.Top = 10; srctWindowRect.Bottom = 500; srctWindowRect.Right = 320; SetConsoleWindowInfo(hConsole, TRUE, &srctWindowRect); coordScreen.X = 80; // buffer size 80x1000 coordScreen.Y = 1000; SetConsoleScreenBufferSize(hConsole,coordScreen);}// the console handle to stdout FILE *GetConsoleHandle(DWORD Device){ int Crt; FILE *Console = NULL; if ((hConOut = GetStdHandle(Device)) != INVALID_HANDLE_VALUE) { // _open_osfhandle() is not in cygwin#if !defined(__CYGWIN__) Crt = _open_osfhandle((long)hConOut, _O_TEXT); if (Device == STD_INPUT_HANDLE) Console = fdopen(Crt, "r"); else Console = fdopen(Crt, "w");#else if (Device == STD_INPUT_HANDLE) Console = fdopen(0,"r"); else Console = fdopen(1,"w");#endif setvbuf(Console, NULL, _IONBF, 0); SetConsole(hConOut); } return Console;}int GetFileName( char *fullname, char *shortname) // filename{ int i, j, k; int tail=0; ifstream test(fullname,ios::in); if (!test.is_open()) { cout << "File " << fullname << "do not exist !" << endl; return FALSE; } strcpy( shortname , "\0" ) ; tail = strlen( fullname ) ; if ( tail == 0 ) return -1 ; // return by nothing for ( i = tail - 1 ; i >= 0 ; i-- ) { // loop 1 if ( fullname[i] == '\\' ) { for ( j = i+1, k=0 ; j < tail ; j++, k++ ) *(shortname + k) = *(fullname + j ) ; *(shortname + k) = '\0'; break; } } if (i == -1) strcpy(shortname,fullname); return 0 ; // OK!}void ShowHelp(const char * s,int k){ if(k) { MettreDansPostScript(0); couleur(1); float xmin,xmax,ymin,ymax; getcadre(xmin,xmax,ymin,ymax); rmoveto(xmin+(xmax-xmin)/100,ymax-(k)*(ymax-ymin)/30); plotstring(s); MettreDansPostScript(1); // couleur(1); }}char *ChangePdeToExt(char *fileName,char *ext){ int len; len=strlen(fileName); char *file = new char[len+1]; for(int i=0; i<len; i++) *(file+i) = *(fileName+i); file[len-4]='.'; file[len-3]=ext[0]; file[len-2]=ext[1]; file[len-1]=ext[2]; file[len]='\0'; return file;} BOOL CreateProjetFile(char *fileName){ char chemin[256]; strcpy(chemin,FreeFemCache); strcat(chemin,ChangePdeToExt(shortName,"prj")); if (projet=fopen(chemin,"w"),!projet) return FALSE; fprintf(projet,"FFF@WinfFEM@FFF\n"); return TRUE;}//* the module for graph.cppint NbMeshTotal=1, NbPlotTotal=1;float GetHeigthFont(){ return (float)fontH/echy;}//* store all data created in graph.cpp// Chack the mesh which will be stored in the cache// return TRUE (if it is same)// else return FALSE /*BOOL CheckSameTrig(Grid& t){ static struct { // store the information of the mesh float x; float y; int w; } p[3] = { {0,0,0}, {0,0,0}, {0,0,0}}; // three virteces static int nv = 0, nt = 0; // numbers of the virteces and the triangles if ((nv != t.nv) || (nt != t.nt)) goto SET; if ((t.v[0].x != p[0].x) || (t.v[0].y != p[0].y) || (t.v[0].where != p[0].w)) goto SET; if ((t.v[nv/2].x != p[1].x) || (t.v[nv/2].y != p[1].y) || (t.v[nv/2].where != p[1].w)) goto SET; if ((t.v[nv-1].x != p[2].x) || (t.v[nv-1].y != p[2].y) || (t.v[nv-1].where != p[2].w)) goto SET; else return TRUE;SET: nv = t.nv; nt = t.nt; p[0].x = t.v[0].x; p[0].y = t.v[0].y; p[0].w = t.v[0].where; p[1].x = t.v[nv/2].x; p[1].y = t.v[nv/2].y; p[1].w = t.v[nv/2].where; p[2].x = t.v[nv-1].x; p[2].y = t.v[nv-1].y; p[2].w = t.v[nv-1].where; return FALSE;}// ohtsuka 8/23/98 void SaveMesh(Grid& t){ char chemin[256],meshName[256]; int i,j=0; if (!(winf_flg&winf_VFFEM)) return; if (CheckSameTrig(t)==TRUE) return; strcpy(chemin,FreeFemCache); sprintf(meshName,"%d-%s",NbMeshTotal++,ChangePdeToExt(shortName,"msh")); strcat(chemin,meshName); ofstream mesh(chemin,ios::out); if (mesh.is_open()) { mesh << "FFF@WinfFEM_MESH@FFF" << endl; fprintf(projet,"%s\n",meshName); mesh << t.nv << " " << t.nt << endl; for( i=0; i<t.nv; i++ ) { mesh << t.v[i].x <<" "<< t.v[i].y <<" " << t.v[i].where << endl; } for( i=0; i<t.nt; i++ ) { mesh << t.no(t.t[i].v[0]) <<" "<< t.no(t.t[i].v[1]) <<" "<< t.no(t.t[i].v[2]) <<" "<< j<<endl; } } else { cout << "Unable to SAVE MESH for WinfFEM !" << endl; return; } NbPlotTotal=1; mesh.close();} void SavePlot(int D,Grid& t, Real *f){ char chemin[256],plotName[256]; int i; if (!(winf_flg&winf_VFFEM)) return; if (f == NULL) return; strcpy(chemin,FreeFemCache); sprintf(plotName,"%d-%d%s",NbMeshTotal-1,NbPlotTotal,ChangePdeToExt(shortName,"fnc")); strcat(chemin,plotName); ofstream plot(chemin,ios::out); if (plot.is_open()) { fprintf(projet,"%s\n",plotName); plot << "FFF@WinfFEM_PLOT@FFF" << endl; plot << NbMeshTotal-1 << "-" << ChangePdeToExt(shortName,"msh") << endl; plot << D << endl; plot << t.nv << endl; for (i=0; i<t.nv; i++) plot << t.v[i].where << " " << f[i] << endl; } else { cerr << "Unable to SAVE PLOT for WinfFEM !" << endl; return; } NbPlotTotal++;} */void viderbuff(){;}//*OT July 7 2000//This module is used in analyse.cpp "system"//#include <shellapi.h>#define MAXPATH 256char * getOp(const char *what){ int tail=0, len=0; char *p; p = strrchr(what, '\\'); if (p == NULL) p = (char *)what; while (*p && (*p != ' ')) p++; if (*p) *p++ = '\0'; else return NULL; while (*p && (*p == ' ')) p++; if (*p) return p; else return NULL;}#ifdef WWWWWWWWWWWWWWWWWWWWint execute(const char* what){ char szBuffer[MAXPATH + 1]; char *option; int r=0; char *vide=""; option = getOp(what); if(!option) option = vide; cout << "excute :: " <<what << " ## " << option << endl; if (*what) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(STARTUPINFO) ); ZeroMemory( &pi, sizeof(PROCESS_INFORMATION) ); si.cb=sizeof( STARTUPINFO ); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOWNORMAL; CreateProcess(what,option,NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi ); if( pi.hProcess ) { WaitForInputIdle( GetCurrentProcess(), INFINITE ); DWORD dwExitCode = STILL_ACTIVE; while(dwExitCode == STILL_ACTIVE) { WaitForSingleObject( pi.hProcess, 1000 ); GetExitCodeProcess( pi.hProcess, &dwExitCode ); } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } else { sprintf(szBuffer,"%s: cannot execute",what); if (option != NULL) sprintf(szBuffer,"%s with option %s!",szBuffer, option); MessageBox(NULL, szBuffer, "Error in FreeFem++", MB_OK | MB_ICONINFORMATION); r=1; } } else r=2,MessageBox(NULL, "Error in system()", "Error in FreeFem++", MB_OK | MB_ICONINFORMATION); return r;}#elseint execute (const char * str){ cout << "exec: " << str << endl; return system(str);}#endifvoid setgrey(bool gg ){grey=gg;}int getgrey(){ return grey;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -