⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcrgraph.cpp

📁 FreeFem++可以生成高质量的有限元网格。可以用于流体力学
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    float r=1,g=1,b=1;    if (colortable) {      if (c>0 && c < ncolortable)  {    r =  (float) colortable[c].r /255.;    g =  (float) colortable[c].g /255.;    b =  (float) colortable[c].b /255.;  }    }    else if (c!=0)      r=g=b=0;        fprintf(psfile,"%.3f %.3f %.3f C\n",r,g,b);  }}int LaCouleur(){return cstatic;}//* Control on the graphic windowvoid rattente(int waitm){   int i=0, j=0;   char c;   if (waitm)     if(!(winf_flg&winf_NOWAIT)) c = Getijc(i,j);}char Getijc(int & x,int & y){  char char1=' ';  if(!INITGRAPH)     {      x = 0;      y = 0;         return char1;    }   int  cont=1;   POINT xy;    xy.x =0;    xy.y =0;  MSG msg;      	SetWindowText(hWnd,"Click mouse to continue");  do   {         GetMessage(&msg,hWnd,0,0);// all message      GetCursorPos(&xy);      switch (msg.message)       {         case WM_LBUTTONDOWN:char1=char(251), cont=0;         		break;          // with shift 248                          case WM_RBUTTONDOWN:char1=char(253), cont=0;         break;           // with shit 250         // if the 2 buttom, 252, et shith 249;         case WM_CLOSE:	myexit(2);         case WM_DESTROY:   myexit(3);         case WM_CHAR: char1 = (TCHAR)msg.wParam; cont = 0; break;               //case WM_KEYDOWN: char1 = (TCHAR)msg.wParam;  cont=0; break;       default:  					TranslateMessage(&msg);     				DispatchMessage(&msg);       	break;       }    }    while (cont); //    ScreenToClient(hWnd,&xy); 	ShowWindow(hWnd, SW_SHOW ); // SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);    SetWindowText(hWnd,   PACKAGE_STRING  " works..."); 	RECT rc;    ScreenToClient(hWnd,&xy); 	GetClientRect(hWnd, &rc);  	x = xy.x-rc.left; 	y = xy.y-rc.top; //	cout << " x = " << x << " y = " << y  << " char = " << ((unsigned char)char1 > 127 ? '*': char1) << ")" << endl; 	return char1;}char Getxyc(float &x,float &y){   char c=' ';  int i=0,j=0;  if(!(winf_flg&winf_NOWAIT)) c = Getijc( i,j);  x = scali(i);  y = scalj(j);  //rattente(1);  return c;}//* clear the screen with whitevoid reffecran(void){      HBRUSH hbr; RECT rc; GetClientRect(hWnd, &rc); hbr = CreateSolidBrush(RGB(255, 255, 255)); FillRect(hdc,&rc,hbr); DeleteObject(hbr);}BOOL ShowOpenDialogBox(char *fileName){  OPENFILENAME ofn;   char szDirName[256];     char *strFilter="PCgFEM Files (*.edp)\0*.edp\0All Files (*.*)\0*.*\0\0";     memset(&ofn, 0, sizeof(OPENFILENAME));  getcwd(szDirName,sizeof(szDirName));  ofn.lStructSize = sizeof(OPENFILENAME);  ofn.hwndOwner = NULL;  ofn.lpstrFilter = strFilter;  ofn.lpstrFileTitle = fileName;  ofn.nMaxFileTitle = 80;  ofn.lpstrInitialDir=szDirName;  ofn.lpstrTitle ="Choose you freefem '*.edp' File";  ofn.Flags=OFN_SHOWHELP|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;    return GetOpenFileName(&ofn);} void coutmode(short r) { ;}// will be done later   void initgraphique(void)       {   if (INITGRAPH) return;  hdc=GetDC(hWnd);  hpen=0;  SetColorTable(2+6);  RECT rc;  GetClientRect(hWnd, &rc);  aspx = (float)(rc.right - rc.left);  aspy = (float)(rc.bottom - rc.top);  width = rc.right - rc.left;  height = rc.bottom - rc.top;  carre = aspx == aspy;  // Define the font style    LOGFONT lf;    TEXTMETRIC tm;		HFONT hFont, hOldFont;    memset(&lf, 0, sizeof lf);    lf.lfHeight = -9;    lstrcpy(lf.lfFaceName,"Arial");    lf.lfOutPrecision = OUT_TT_PRECIS;    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;    lf.lfQuality = PROOF_QUALITY;    lf.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;    hFont = ::CreateFontIndirect(&lf);    hOldFont = (HFONT)::SelectObject(hdc,hFont);    ::GetTextMetrics(hdc, &tm);    ::DeleteObject(hOldFont);    fontH =  static_cast<int>((tm.tmHeight + tm.tmExternalLeading)*0.6);  // end of font style  INITGRAPH = 1;  // cout << flush << "end  inigraphique " << endl;}void closegraphique(void){ 	if(INITGRAPH) {		if(hpen) 		   DeleteObject(hpen), delete [] colortable;		if (hbr)   DeleteObject(hbr),     INITGRAPH =0; // before DestroyWindow to avoid loop     ReleaseDC(hWnd,hdc); //    DestroyWindow(hWnd);	}}void GetScreenSize(int & ix,int &iy){  ix = width ;  iy = height;}void openPS(const char *filename ){   RECT rc;  GetClientRect(hWnd, &rc);  width = rc.right - rc.left;  height = rc.bottom - rc.top;  closePS();  time_t t_loc;  float s=0.5;    const int shiftx=50,shifty=50;  time(&t_loc);  printf(" Save Postscript in file '%s'\n",filename?filename:"freefem.ps"),  psfile=fopen(filename?filename:"freefem.ps","w");  if(psfile==0) {printf("Erreur %s \n",filename);exit(1);}    if(psfile) {  fprintf(psfile,"%%!PS-Adobe-2.0 EPSF-2.0\n%%%%Creator: %s\n%%%%Title: FreeFem++\n","user");  fprintf(psfile,"%%%%CreationDate: %s",ctime(&t_loc));  fprintf(psfile,"%%%%Pages: 1\n");  fprintf(psfile,"%%%%BoundingBox:       %d %d %d %d\n",shiftx,shifty,int(shiftx+width*s),int(shifty+height*s));  fprintf(psfile,"%%%%EndComments\n");  fprintf(psfile," /L {  lineto currentpoint stroke newpath moveto} def\n");  fprintf(psfile," /M {  moveto } def\n");  fprintf(psfile," /C {setrgbcolor} def\n");  fprintf(psfile," /rec {newpath 4 copy 8 1 roll moveto 3 -1 roll lineto 4 2 roll exch lineto lineto closepath} def\n");  fprintf(psfile," %d %d  translate \n",shiftx,shifty);  fprintf(psfile," %f %f  scale \n",s,s);  fprintf(psfile," 0 %d 0 %d rec clip newpath\n",int(width),int(height));  fprintf(psfile," /Helvetica findfont 10 scalefont setfont\n");  fprintf(psfile," /S { show} def\n");  fprintf(psfile," /bF  { mark} def \n");  fprintf(psfile," /eF {newpath moveto counttomark 2 idiv {lineto} repeat closepath fill cleartomark} def\n");  fprintf(psfile," /P { /yy exch def /xx exch def   xx xx 1 add yy yy 1 add  rec  fill } def\n");  fprintf(psfile," 1 setlinewidth\n");	  psfile_save=psfile;  }}void closePS(void){  if(psfile_save)   {    fprintf(psfile_save,"showpage\n");//fprintf(psfile,"showpage\n");    fclose(psfile_save);//fclose(psfile);    }      psfile=0;  psfile_save=0;  }  void Commentaire(const char * c)    {  if(psfile)   {    fprintf(psfile,"%% %s\n",c);   }  };  void NoirEtBlanc(int NB)  {    if(NB) LastColor=1;    else LastColor=ncolortable?ncolortable:2;  }   void MettreDansPostScript(int in)   {     if(in)  psfile=psfile_save;          else   psfile=0;   }// Various works when the program will endvoid myexit(int err){ 	time_t ltime;         // write the time stump in console 	struct tm *now; 	time(&ltime);           // write the end time 	now = localtime(&ltime); 	cout << "\nEnd Time: " << asctime(now) << endl;  if (err==0) {  // normal end		cout << "end No Error " << endl << flush ;	}  else    	cout << "end by Error (no.=" << err << ')' << endl;  rattente(1);	  if (GetConsoleBuff()==FALSE) 		FatalErr("Log file creation error !",0); 	if (!(winf_flg&winf_NOEDIT)) EditLog();  if (INITGRAPH)   closegraphique();  	FreeConsole();	PostQuitMessage(0); 	exit(err);}// initialize the consolevoid SetcppIo(){  FILE *fp=NULL,*fin=NULL;  // Get the standard output   fin = GetConsoleHandle(STD_INPUT_HANDLE);      if(fin!=NULL)     *stdin = *fin;      // get the standard output   if((fp = GetConsoleHandle(STD_OUTPUT_HANDLE)) == NULL)     *stdout = *fp;   freopen("conin$", "r", stdin);   freopen("conout$", "w", stdout);   // freopen("conout$", "w", stderr);      using namespace __gnu_cxx;   stdio_filebuf<char> * ccout = new stdio_filebuf<char>(stdout, std::ios_base::out);   //static  stdio_filebuf<char> ccerr(stderr, std::ios_base::out);   stdio_filebuf<char> *ccin= new stdio_filebuf<char>(stdin, std::ios_base::in);      cout.rdbuf(ccout);   cin.rdbuf(ccin);   cerr.rdbuf(ccout);   ios::sync_with_stdio();}BOOL inittext(VOID){  OSVERSIONINFO osVer; // for GetVersionEx()  osVer.dwOSVersionInfoSize = sizeof(osVer);  GetVersionEx(&osVer);  if (osVer.dwPlatformId == VER_PLATFORM_WIN32s) {    MessageBox(NULL,         "This FreeFEM++ cannot run on Windows 3.1.\n"        "This application will now terminate.",        "Error: Windows NT or Windows 95 Required to Run",  MB_OK );        return FALSE;       // Console API is not able in Windows 3.1     }  // FreeConsole();          // If the console is already used   AllocConsole();         // Use the console API   SetcppIo();   /*   freopen("conin$", "r", stdin);   freopen("conout$", "w", stdout);   freopen("conout$", "w", stderr);   */   SetConsoleTitle(PACKAGE_STRING  " console");   return TRUE;}//*------- Modules for MS-Windows//*OT  12/3/1999//* Get the buffer of the console//* The buffer is stored in the filename.log BOOL GetConsoleBuff(){  CONSOLE_SCREEN_BUFFER_INFO csbi; //* to get buffer info  GetConsoleScreenBufferInfo(hConOut, &csbi);  COORD coordLine = {0,0};  CHAR *szLine;  //* buffer to read from the console (a line)  DWORD dwCharsRead;  char fname[255];  FILE *fp;  strcpy(fname,ChangePdeToExt(shortName,"log"));  if ((fp = fopen(fname,"w"))==NULL) {		perror(fname);     return FALSE;	}	  szLine = (CHAR *)malloc((csbi.dwSize.X+1) * sizeof(CHAR));  for (int i=0; i<csbi.dwCursorPosition.Y; i++) {  	if (ReadConsoleOutputCharacter(hConOut, szLine,              csbi.dwSize.X, coordLine, &dwCharsRead)== FALSE) {       				perror("ReadConsoleOutputCharacter");              return FALSE;    }    int j=csbi.dwSize.X-1;    while ((szLine[j] == ' ') && (j > 0)) szLine[j--] =0;    if (j < csbi.dwSize.X-1) szLine[j+1] = '\n';     fprintf(fp,"%s",szLine);    coordLine.Y++;  }  fclose(fp);  return TRUE;}//*OT  12/3/1999//* Open the filename.log by the editor//* default editor is notepad.exe//* Using variable "ffemEd", we can change the editor BOOL EditLog(){  char *editor, fname[256], cmdLine[255];    strcpy(fname,ChangePdeToExt(shortName,"log"));  editor = getenv("ffed");  if (editor == 0)  	sprintf(cmdLine,"notepad.exe %s",fname);	else	  sprintf(cmdLine,"%s %s",editor,fname);  if (WinExec(cmdLine,SW_SHOWNORMAL) < 31) {  	sprintf(errbuf,"Cannot execute [%s]",cmdLine);  	FatalErr(errbuf,99);  	return FALSE;  }  FreeConsole();  return true;}void Usage(){   cout << "Usage: freefem++ [options]" << endl;   cout << "Select a program file by the dialog box if option is omitted.\n[option]" << endl;   cout << "-f filename: Run the program file \"filename\"." << endl;   cout << "    In this mode, all plotted datas are stored in the \".\\cache\"." << endl;   cout << "    The stored datas are used in \"WinfFEM\" (IDE for freefem+)." << endl;   cout << "    You can get this from  <http://barnard.cs.hkg.ac.jp>." << endl;   cout << "-s    : No wait at end." << endl;   cout << "-b    : Do not use the color" << endl;   cout << "-n    : Do not open the log file at end. The editor is the notepad if you do not" << endl;   cout << "        set \"ffed=[name of editor]\" in environments." << endl;   cout << "-h    : Display the usage (this)." << endl;}// freefem+  arg1  arg2 arg3// Hack the args and analysis int StoreFname(char Line[], int len){  char msg[256]; char *ext;  // ALH - 2/6/04 - add treatments for names surrounded with quotes  // (but still breaks on names including quotes).  char stopchar = ' ';  bool skipone = false;  if(Line[0] == '"' || Line[0] == '\''){    stopchar = Line[0];    skipone = true;  }  // Copies the name string, including its surrounding quotes if  // necessary.  int i;  int j=0;  for (i=0; i<len; i++){    if (Line[i] != stopchar) fullName[j++] = Line[i];    else{      if(skipone) skipone = false;      else break;    }  }  fullName[j] = '\0'; 	  ofstream check(fullName,ios::in);  if (!check.is_open()) {    sprintf(msg,"\"%s\" does not exist!",fullName);    FatalErr(msg,-1);  }  else check.close(); 	     ext = strrchr(fullName,'.'); ext++;  /*  if (toupper(*ext) != 'E'      || toupper(*(ext+1)) != 'D'      || toupper(*(ext+2)) != 'P') {    sprintf(msg,"\"%s\" is not a FreeFem++ script!",fullName);    FatalErr(msg,-1);  }*/	  GetFileName(fullName,shortName);  return i;}// freefem+  arg1  arg2 arg3// Hack the args and analysis DWORD GetOption(char lpszCmdLine[]){  int i = 0;  int CmdLen = strlen(lpszCmdLine);  DWORD dwStyle = WS_OVERLAPPEDWINDOW;  cout << "getOp: " ;  while (i < CmdLen) {     cout << lpszCmdLine[i] ;    while (lpszCmdLine[i] == ' ')      i++;    if (lpszCmdLine[i] == '-') {      i++;      switch(lpszCmdLine[i]) {      case 'f':      	i++;      	while (lpszCmdLine[i] == ' ')	  ++i;      	i += StoreFname(&lpszCmdLine[i],CmdLen-i);	winf_flg |= winf_VFFEM;      	break;      case 'v':      {  string vv;	  char c;	  while  (i < CmdLen &&( (isspace(c=lpszCmdLine[i++])&& vv.length()>0 )||isdigit(c) ))	    if(isdigit(c)) vv+= c;	  verbosity=atoi(vv.c_str());	        }      case 's':  // not wait at end of execution	winf_flg |= winf_NOWAIT; ++i;	break;      case 'b':	// no color	winf_flg |= winf_NOCOLOR; ++i;	break;      case 'n':	winf_flg |= winf_NOEDIT; ++i;	break;      case 'h':	winf_flg |= winf_Usage; ++i;	break;      default:	while (lpszCmdLine[i]!=' ' && (i < CmdLen))	  i++;      }    }    else  {      i += StoreFname(&lpszCmdLine[i],CmdLen-i);      break;    }  }  cout << " v = " << verbosity << endl;  return 0;}/* * Init      *     Initialization for the program is done here: *     1)  Register the window class (if this is the first instance) *     2)  Create the desktop window for the app. *     3)  Show the desktop window in the manner requested by the User. * */BOOL Init(HINSTANCE hInstance,   HINSTANCE hPrevInstance,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -