📄 xrgraph.cpp
字号:
/********** DO NOT REMOVE THIS BANNER **********/// -*- Mode : c++ -*-//// SUMMARY : // USAGE : // ORG : // AUTHOR: D. Bernardi, F. Hecht, O. Pironneau , Y. Darmaillac // 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 *//******************************************************************/const char * edpfilenamearg=0; bool waitatend=true;#define FF_GRAPH_SET_PTR#include <math.h>#include <time.h>#include <stdlib.h>#include <stdio.h>#include <iostream>#include <cassert>#include "strversionnumber.hpp"using namespace std;#define MAXSHORT 0xFFFF#ifdef HPPA#ifndef __GNUC__typedef char *caddr_t;#endif#endif#ifdef __MWERKS__#include <Xlib.h>#include <Xutil.h>#include <Xos.h>#include <Xatom.h>#include <keysym.h>#include <cursorfont.h>#else#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/Xos.h>#include <X11/Xatom.h>#include <X11/keysym.h>#include <X11/cursorfont.h>#endif#include "rgraph.hpp"#ifdef macintoshxx#include <ConditionalMacros.h>#include <unix.h>#else#include <sys/stat.h>#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 long cube6[7][3] ={ { 65535,32000,32000},{ 65535, 65535,0},{0, 65535,0},{0, 65535, 65535},{0,0, 65535} , { 65535,0, 65535},{ 32000,0,0} }; static long grey6[2][3] ={ {65534,65534,65534},{0,0,0} }; static FILE *psfile = 0;static FILE *psfile_save = 0;static bool grey=false;static int LastColor=2; // pour est en couleur par defautconst float fMinPixel = -32000;const float fMaxPixel = +32000;#define reel float static Display *display;static Window win;static XSizeHints size_hints;// static XEvent report;static int ncolortable,fcolor;static XColor *colortable;static GC gc;static XFontStruct *font_info;static int shift, control,shiftlock,alt;static reel echx,echy,rxmin,rxmax,rymin,rymax;static int lacouleur,screen, width, height, currx, curry;static unsigned long background,foreground;static Cursor cursor_watch,cursor_arrow;static long NbErrX11 =0;Colormap color_map,color_map_sys;#define call(i) istatic Visual *visual;static int INITGRAPH=0;void myend(){ if (INITGRAPH) closegraphique(); cout << "the end" <<endl;// ExitToShell();}void myexit(int err) { cout << " The End err=" << err << endl; exit(err);}#ifdef FREEFEM#include <fstream.h>#include <new.h>void out_of_memory ();void myexit(int );void compile(char *fname);int main (int argc, char **argv){ atexit(myend); int OPTION = 0; if (argc == 2) { printf ("PROGRAM FreeFem 1.0 %s \n",argv[1]); initgraphique(); compile (argv[1]); closegraphique(); } else printf ("To launch freefem you must type freefem and a file name\n"); return 0;}#elseextern int mymain(int argc,char **argv);int main (int argc, char **argv){ return mymain(argc,argv);}#endifvoid message(char *s){ printf("%s \n",s);}void erreur(char *s){ message(s); exit(0);}void *safecalloc(size_t nb, size_t size){ void* p=NULL; p = calloc(nb, size); if (p == NULL) printf("Run out of Memory!\n"); return p;}void safefree(void** f){ if(*f){ free((char*) *f); *f=NULL;}}void rflush(){ XEvent report; XNextEvent(display, &report); if (report.type == Expose) while (XCheckTypedEvent(display, Expose, &report)); XFlush(display);}int xerror (Display *display,XErrorEvent * myerr){ if (NbErrX11++<10) { char msg[80]; XGetErrorText(display, myerr->error_code, msg, 80); fprintf(stderr, "Error code %s\n", msg);} return 0;}/*void xerror(){ fprintf(stderr, "Probleme avec X-Windows\n"); assert(0);}*/void xerrorio(){ fprintf(stderr, "Fatal erreur avec X-Windows\n"); assert(0); exit(2);}void MyXSelectInput(Display * dpy,Window w,int mask){ XSetWindowAttributes attributes; attributes.event_mask = mask; XChangeWindowAttributes(dpy, w, CWEventMask, &attributes);}int LaCouleur() {return lacouleur;}void couleur(int c){ if ( lacouleur == c) // small optim return; c= c > LastColor ? 1 : c; // c=Min(c,LastColor); pour noir et blanc lacouleur = c; if (colortable) { if (c>=0 && c < ncolortable) XSetForeground(display,gc,colortable[c].pixel); else XSetForeground(display,gc,foreground); }else if ( c == 0 ) XSetForeground(display,gc,background); else XSetForeground(display,gc,foreground); if (psfile) { float r=1,g=1,b=1; if (colortable) { if (c>0 && c < ncolortable) { r = (float) colortable[c].red /65535.; g = (float) colortable[c].green /65535.; b = (float) colortable[c].blue /65535.; } } else if (c!=0) r=g=b=0; fprintf(psfile,"%.3f %.3f %.3f C\n",r,g,b); }}static XColor DefColorX11( int k,int nb, bool hsv,bool grey,int nbcolors,float *colors){ XColor C; float r,g,b;extern void DefColor(float & r, float & g, float & b, int k,int nb, bool hsv,bool grey,int nbcolors,float *colors); DefColor(r,g,b, k,nb,hsv,grey,nbcolors,colors); C.red=65535*r; C.green=65535*g; C.blue=65535*b; C.flags = DoRed | DoGreen | DoBlue; C.pixel=k; // cout << " color : " << k << " " << C.red << " "<< C.green << " " << C.blue << " " << r << endl; return C;} void SetColorTable1(int nb,bool hsv,int nbcolors,float *colors){ static bool greyo = !grey; static float * colorso =0; if(!INITGRAPH) return; if (ncolortable == nb && greyo == grey && colorso == colors ) return;// optim greyo = grey; colorso=colors; if (fcolor && nb>2 && nb < 256) { if(colortable) delete [] colortable; colortable = new XColor[nb]; ncolortable = nb; if(LastColor>1) LastColor=nb-1; for (int i0=0;i0<nb;i0++) { colortable[i0]=DefColorX11(i0,nb,hsv,grey,nbcolors,colors); } background=0; foreground=1; if (visual->c_class != TrueColor) { // cout << "XStoreColors( not TrueColor)" << ncolortable << " " << XStoreColors (display, color_map, colortable, ncolortable) ; // << endl; } else { // cout << "XAllocColor (TrueColor)" << endl; for (int i=0;i<ncolortable;i++) XAllocColor(display, color_map, colortable+i ); background =colortable[background].pixel; foreground =colortable[foreground].pixel; } if (win) { XGCValues gcvalues; gcvalues.foreground = foreground; gcvalues.background = background; gc = XCreateGC(display, win, GCForeground | GCBackground , &gcvalues); } }}void SetColorTable(int nb){ int i; if (fcolor && nb>2 && nb < 256) { nb = Max(nb,8); if (ncolortable == nb) return;// optim if(colortable) delete [] colortable; colortable = new XColor[nb]; ncolortable = nb; if(LastColor>1) LastColor=nb-1; int k=0; colortable[k].pixel=k; colortable[k].red= 65535; colortable[k].green= 65535; colortable[k].blue= 65535; colortable[k].flags = DoRed | DoGreen | DoBlue; background=k; k++; colortable[k].pixel=k; colortable[k].red=0; colortable[k].green=0; colortable[k].blue=0; colortable[k].flags = DoRed | DoGreen | DoBlue; foreground=k; k++; nb = nb -2; for (long i0=0;i0<nb;i0++,k++) { // long i1 = nb - i0; long i6 = i0*6; long j0 = i6/nb;// in 0..6 long j1 = j0+1;// in 1..6 long k0 = i0 - (nb*j0)/6L; long k1 = (nb*j1)/6L-i0; long kk = k0+k1; // cout <<k << " " << i0 << " " << j0 << " " << j1 << " " << k0 << " " << k1 << endl; if ( kk <= 0) { cerr << kk << " " << nb << " " << k0 << " " << k1 << " " << endl; assert(kk); } colortable[k].pixel= (unsigned long) k; colortable[k].flags = DoRed | DoGreen | DoBlue; if (! grey) { colortable[k].red = (unsigned short) ((long) (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk); colortable[k].green = (unsigned short) ((long) (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk); colortable[k].blue = (unsigned short) ((long) (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk); } else { kk=nb-1; k1 = i0; k0 = nb - i0 -1; j0=1; j1=0; colortable[k].red = (unsigned short) ((long) (grey6[j1][0]*k0+grey6[j0][0]*k1)/kk); colortable[k].green = (unsigned short) ((long) (grey6[j1][1]*k0+grey6[j0][1]*k1)/kk); colortable[k].blue = (unsigned short) ((long) (grey6[j1][2]*k0+grey6[j0][2]*k1)/kk); } assert(k<ncolortable); // cout <<colortable[k].pixel // << " r=" << colortable[k].red // << " g=" << colortable[k].green // << " b=" <<colortable[k].blue <<endl; } if (visual->c_class != TrueColor) { // cout << "XStoreColors( not TrueColor)" << ncolortable << " " << XStoreColors (display, color_map, colortable, ncolortable) ; // << endl; } else { // cout << "XAllocColor (TrueColor)" << endl; for (i=0;i<ncolortable;i++) XAllocColor(display, color_map, colortable+i ); background =colortable[background].pixel; foreground =colortable[foreground].pixel; } if (win) { XGCValues gcvalues; gcvalues.foreground = foreground; gcvalues.background = background; gc = XCreateGC(display, win, GCForeground | GCBackground , &gcvalues); } }// a faire }void FlushEvent(){ XEvent event;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -