📄 glrgraph.hpp
字号:
/**************DO NOR REMOVE THIS BANNER***************//* FreeFEM : Language for a Finite Element Method *//* ------- Release 2.0: June 2007. *//* Authors: D. Bernardi, Y. Darmaillac F. Hecht, *//* O. Pironneau */// ********** DO NOT REMOVE THIS BANNER **********/* // SUMMARY : // USAGE : // ORG : // AUTHOR : Frederic Hecht // E-MAIL : hecht@ann.jussieu.fr This file is part of Freefem++ Freefem++ is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Freefem++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Freefem++; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *//* (fax) Olivier.Pironneau@ann.jussieu.fr *//******************************************************///#define FREEFEM// AGL apple // XGL X11 // WGL window (a faire) const char * edpfilenamearg=0; bool waitatend=true;#ifdef AGL#define TARGET_API_MAC_CARBON 1#define CALL_IN_SPOCKETS_BUT_NOT_IN_CARBON 1#include <Carbon/Carbon.h> #include <AGL/agl.h>#include <OpenGL/gl.h>#include <OpenGL/glu.h>#endif#ifdef XGL#include <GL/glx.h>#include <X11/cursorfont.h>#include <X11/keysymdef.h>#endif#ifndef AGL#include <GL/gl.h>#include <GL/glu.h>#endif#include <sys/stat.h>#include "error.hpp"#include <fstream>#include <iostream>#include <stdlib.h>using namespace std;#include <errno.h>#include <stdio.h>#include <math.h>#include <string.h>#include "rgraph.hpp"#include <time.h>#include <setjmp.h>#include <time.h>int currx=0,curry=0;static FILE *psfile = 0;static FILE *psfile_save = 0;#ifdef AGLstatic AGLPixelFormat fmt;static AGLContext ctx;int pStrCopy (StringPtr p1, char * p2);StringPtr c2p(const char * p,char *buf);#endif#ifdef XGLstatic Display *dpy;static Window win;static XSizeHints size_hints;//static GC gc;static XFontStruct *font_info;GLXContext cx;int stensize;static Cursor cursor_watch,cursor_arrow;static int shift, control,shiftlock,alt;static GLuint basefont; #endifextern long verbosity; // level off printing#ifdef FREEFEMvoid myenviron (){ cout << "FreeFEM error: operator new failed; not enough memory" << endl; if (myenviron) longjmp(myenvironj,1); exit(2);}// pour imprimer la version FH #define STRING(i) #i#include <new.h>jmp_buf myenvironj;static int myenviron = 0;void out_of_memory ();void NEW_HANDLER (void);void compile(char *fname);float scali(int i);float scalj(int j);void execute(char* what);char Getijc(int & x,int & y);int DoMouseDown (int windowPart, WindowPtr whichWindow, EventRecord *myEvent); void NEW_HANDLER (void){ set_new_handler (&myenvironj);}#endifstatic int nbcolor;static int ncolortable;static int LastColor; // LastColor=1 => Noir et Blanc #ifdef AGL#define ours(w) (w==grafWindow0)static WindowPtr grafWindow0;static GrafPtr grafPort0;static Rect boundsRect;static CursHandle CrossCurseur ;static CursHandle WatchCurseur ;static Pattern white,black;#elsestruct RGBColor { unsigned short red; /*magnitude of red component*/ unsigned short green; /*magnitude of green component*/ unsigned short blue; /*magnitude of blue component*/};#endiftemplate<class T> inline T Min (const T &a,const T &b){return a < b ? a : b;}template<class T> inline T Max (const T &a,const T & b){return a > b ? a : b;}static bool grey=false;static int cube6[7][3] ={ {65534,0,0},{65534,65534,0},{0,65534,0},{0,65534,65534},{0,0,65534} , {65534,0,65534},{65534,0,0} }; static int grey6[2][3] ={ {65534,65534,65534},{0,0,0} }; char errbuf[255];static int INITGRAPH=0;static float aspx, aspy, echx,echy,ech,rxmin,rxmax,rymin,rymax;static int carre, lacouleur;static GLuint fontList;static int width,height;static RGBColor * colortable;int getcolor();void putpixel(int ix,int iy, int couleur);int scalx(float x);int scaly(float y);void thisexit();void DrawCStringGL (const char * cstrOut, GLuint fontList){ GLint i = 0; glRasterPos3d(currx,height-curry,0); while (cstrOut [i]) glCallList (fontList + cstrOut[i++]);}#ifdef AGLvoid InitMac();// --------------------------------------------------------------------------------------------------------------// --------------------------------------------------------------------------------------------------------------// APPLE EVENT SUPPORT ROUTINES// --------------------------------------------------------------------------------------------------------------StringPtr c2p(const char * p, unsigned char * buf){ int l=strlen(p); assert(l<255); buf[0]=l; memcpy(buf+1,p,l); return buf; }int pStrCopy (StringPtr p1, char * p2)/* copies a pascal string `p1 into a C string */{ int len,i; len = (*p1++) %256; for(i=1;i<=len;i++) *p2++=*p1++; *p2 = 0; return 0;}void InitMac(){ BitMap screenBitMap; Rect screenBits; Cursor theArrow; GetQDGlobalsScreenBits(&screenBitMap); screenBits = screenBitMap.bounds; SetCursor(GetQDGlobalsArrow(&theArrow));}class InitilisationMac { static int init; public: InitilisationMac(){ InitMac();}};static InitilisationMac Initmac; // to call InitMacint getprog(char* fn,int argc, char** argv){ if (argc > 1) { int ret=0; for (int i=1; i<argc;i++) if (ret ==0 && strcmp(argv[i],"-f")==0 && i+1 < argc ) { strcpy(fn,argv[i+1]); i++; ret=1; } else if (strcmp(argv[i],"-v")==0 && i+1 < argc) { verbosity = atoi(argv[i+1]); i++; } else if(ret==0) { strcpy(fn,argv[i]); ret=1; } if(ret==0) { if(argc>0) cerr << " Syntaxe : " << argv[0] << " -f filename [-v verbosity] " << endl; else cerr << " Syntaxe : FreeFem++-agl -f filename [-v verbosity] " << endl; return ret; } return 1; } else { OSErr anErr; FSRef fsRef; NavDialogOptions dialogOptions; NavReplyRecord reply; anErr=NavGetDefaultDialogOptions(& dialogOptions); if( anErr != noErr) return -1; anErr =NavChooseFile(0,&reply,&dialogOptions,0,0,0,0,0) ; if (anErr == noErr && reply.validRecord) { // Deal with multiple file selection long count; anErr = AECountItems(&(reply.selection), &count); // Set up index for file list if (anErr == noErr) { long index; for (index = 1; index <= count; index++) { AEKeyword theKeyword; DescType actualType; Size actualSize; FSSpec documentFSSpec; // Get a pointer to selected file anErr = AEGetNthPtr(&(reply.selection), index, typeFSRef, &theKeyword, &actualType,&fsRef, sizeof(fsRef), &actualSize); if (anErr == noErr) { anErr=FSRefMakePath(&fsRef,(UInt8*)fn,256); if ( anErr == noErr ) { cout << "Path : " << fn << endl; char * ff=fn,*fff=0; while ( *ff) { if (*ff=='/') fff=ff; ff++; } if (fff) { *fff=0; cout << "chdir to "<< fn << endl; chdir(fn); *fff='/';} } else cout << "Err: "<< anErr << endl; /* anErr = AEGetNthPtr(&(reply.selection), index, typeFSS, &theKeyword, &actualType,&documentFSSpec, sizeof(documentFSSpec), &actualSize); anErr = HSetVol(0,documentFSSpec.vRefNum,documentFSSpec.parID); pStrCopy(documentFSSpec.name, fn);*/ } } } // Dispose of NavReplyRecord, resources, descriptors anErr = NavDisposeReply(&reply); } else return 0; // erreur cancel return (2); }}//-----------------------------------------------------------------------------------------------------------------------GLuint BuildFontGL (AGLContext ctx, GLint fontID, Style face, GLint size){ GLuint listBase = glGenLists (256); if (aglUseFont (ctx, fontID , face, size, 0, 256, (long) listBase)) { glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); return listBase; } else { glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glDeleteLists (listBase, 256); return 0; }}#else#include "getprog-unix.hpp"#endif#ifdef XGLvoid MyXSelectInput(Display * dpy,Window w,int mask){ XSetWindowAttributes attributes; attributes.event_mask = mask; XChangeWindowAttributes(dpy, w, CWEventMask, &attributes);}#endif//-----------------------------------------------------------------------------------------------------------------------void DeleteFontGL (GLuint fontList){ if (fontList) glDeleteLists (fontList, 256);}void coutmode(short i) { cout << flush; cerr << flush;;}#ifdef FREEFEMvoid myexit(int err){ if (INITGRAPH) { rattente(0); closegraphique(); } if (err !=0) cout << "Error: freefem+ has ended with error code " <<err<<endl;// else cout << "Normal exit 0" << endl; if (myenviron) longjmp(myenvironj,1);}void thisexit(){ myexit();}int main (int argc, char **argv){ char *prog; char fname[256]; argc = getprog (fname, argc, argv); atexit(thisexit); NEW_HANDLER (); // see dependent system files ({pc,x,mac}rgraph.{h,cpp}) int OPTION = 0; if (argc == 2) { initgraphique(); if(0==setjmp(myenvironj)) { myenviron=1; compile (fname); // cout << "No Error" << endl; } myenviron = 0; } else printf ("To launch freefem you must type the keyword freefem and a file name\n"); return 0;}#elseextern int mymain(int argc,char **argv);string StrVersionNumber();int main (int argc, char **argv){ char * wn = new char [256]; for (int i=0;i<256;i++) wn[i] = 0; strcpy(wn," -- FreeFem++ "); strcat(wn,StrVersionNumber().c_str()); int ret=15; try { ret=mymain(argc,argv);} catch( Error & err) { ret=err.errcode(); cerr << err.what() << endl; } catch( ...) { cerr << "catch exception ???";} return ret;}void myexit(int err) { cout << " The End err=" << err << endl; exit(err);}#endifvoid message(char *s){ printf("%s \n", s);}void erreur(char *s){ cout << endl; cerr << "##Fatal error :" << s << endl << "exit(1)" << endl; exit(1);}void *safecalloc(long nb, long size){ void* p=NULL; p = calloc(nb, size); if (p == NULL) erreur("Out of Memory!\n"); return p;}void safefree(void** f){ if(*f) { free(*f); *f=NULL; }}void initgraphique(void){ if(INITGRAPH) return; // cout <<"Initgraphique \n" ; fontList=0;#ifdef AGL unsigned char buf40[40]; BitMap screenBitMap; Rect screenBits; Cursor theArrow; GetQDGlobalsScreenBits(&screenBitMap); screenBits = screenBitMap.bounds; SetCursor(GetQDGlobalsArrow(&theArrow)); boundsRect.top = 45; boundsRect.left = (short) (15 + (0.35 * screenBits.right)); boundsRect.bottom = screenBits.bottom - 25; boundsRect.right = screenBits.right- 25; if((boundsRect.bottom - boundsRect.top) < (boundsRect.right - boundsRect.left)) boundsRect.right = boundsRect.left + boundsRect.bottom - boundsRect.top; else boundsRect.bottom = boundsRect.top + boundsRect.right - boundsRect.left; grafWindow0=NewCWindow(0, &boundsRect, c2p("FreeFem Graphics",buf40),true, 8, (WindowPtr) -1L, true, 0); //ShowWindow(grafWindow0); BringToFront(grafWindow0); //SelectWindow(grafWindow0); SetPortWindowPort(grafWindow0); GetPort(&grafPort0); height = boundsRect.bottom - boundsRect.top - 10; width = boundsRect.right - boundsRect.left -10; aspx = boundsRect.right - boundsRect.left -10; aspy = boundsRect.bottom - boundsRect.top - 10; GLint attrib[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_NONE }; fmt = aglChoosePixelFormat(NULL, 0, attrib); /* Choose pixel format */ ctx = aglCreateContext(fmt, NULL); /* Create an AGL context */ aglDestroyPixelFormat(fmt); // pixel format is no longer needed aglSetDrawable(ctx, GetWindowPort (grafWindow0)); /* Attach the context to the window */ { EventRecord event; WaitNextEvent (everyEvent, &event, 1, NULL); } aglSetCurrentContext(ctx);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -