📄 macrgraf.cpp
字号:
//// SUMMARY : // ORG : UPMC// AUTHOR : Frederic Hecht// E-MAIL : hecht@ann.jussieu.fr///**************DO NOR REMOVE THIS BANNER***************//* FreeFEM++ : Language for a Finite Element Method *//* ------- Release 1.0: June 1994. *//* Authors: D. Bernardi, Y. Darmaillac F. Hecht, *//* O. Pironneau */// -*- Mode : c++ -*-/* 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 *//* out our consent : fax (33)1 44 27 44 11 *//* (fax) Olivier.Pironneau@ann.jussieu.fr *//******************************************************/// -*- Mode : c++ -*-//// SUMMARY : // USAGE : // ORG : /* Authors: D. Bernardi, Y. Darmaillac F. Hecht, *//* O. Pironneau */// 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 TARGET_API_MAC_CARBON 1#define FF_GRAPH_SET_PTR#include <MSLCarbonPrefix.h>#include <sioux.h>#include <SIOUXGlobals.h> //OP my hack#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>#define fill thequikdrawfill#include "rgraph.hpp"#include <Windows.h>#include <Fonts.h>#include <SegLoad.h>#include <Quickdraw.h>//#include <StandardFile.h>#include <Navigation.h>#include <time.h>#include <setjmp.h>#include <time.h>#include <unix.h>#include <SIOUX.h> #undef fillstatic FILE *psfile = 0;static FILE *psfile_save = 0;static bool grey=false;int pStrCopy (StringPtr p1, char * p2);#ifdef FREEFEM// pour imprimer la version FH #define STRING(i) #i#include <new.h>jmp_buf environ;static int myenviron = 0;TEHandle TESioux;void out_of_memory ();void NEW_HANDLER (void);void compile(char *fname);float scali(int i);float scalj(int j);void execute(char* what);int DoMouseDown (int windowPart, WindowPtr whichWindow, EventRecord *myEvent);char Getijc(int & x,int & y); void out_of_memory (){ cout << "FreeFEM error: operator new failed; not enough memory" << endl; if (myenviron) longjmp(environ,1); exit(2);}void NEW_HANDLER (void){ set_new_handler (&out_of_memory);}#endif#define ours(w) (w==grafWindow0)template<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 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 CWindowRecord wgRecord0;static WindowPtr grafWindow0;static GrafPtr grafPort0;static Rect boundsRect;static int nbcolor;static CursHandle CrossCurseur ;static CursHandle WatchCurseur ;static int ncolortable;static int LastColor; // LastColor=1 => Noir et Blanc static Pattern white,black;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 InitMac();// --------------------------------------------------------------------------------------------------------------// --------------------------------------------------------------------------------------------------------------// APPLE EVENT SUPPORT ROUTINES// --------------------------------------------------------------------------------------------------------------static OSStatus MissingParameterCheck( const AppleEvent *inputEvent)/* This routine checks an input AppleEvent for the missing keyword. If the missing keyword is found, that means that some required parameters were missing (ie, an error). However, if the missing keyword isn't found, that means that we aren't missing any required parameters (that is to say, all REQUIRED parameters were supplied by the person who created the event). SOME DAY, THE ABOVE COMMENT WILL MAKE SENSE TO YOU. IT STILL DOESN'T TO ME AND I WAS THE ONE WHO WROTE IT.*/{ OSStatus anErr; AEKeyword missingKeyword; DescType ignoredActualType; Size ignoredActualSize; anErr = AEGetAttributePtr( inputEvent, keyMissedKeywordAttr, typeWildCard, &ignoredActualType, (Ptr) &missingKeyword, sizeof(AEKeyword), &ignoredActualSize); if (anErr == noErr) anErr = errAEParamMissed; else if (anErr == errAEDescNotFound) anErr = noErr; return anErr; } // MissingParameterCheckstatic pascal OSErr DoOpenApp( const AppleEvent *inputEvent, AppleEvent *outputEvent, SInt32 handlerRefCon){/* #pragma unused (outputEvent, handlerRefCon) DoCommand(nil, cNew, 0, 0); // so that the initial document opens more quickly, we don't start // the threads until we get an OpenApp or OpenDocument AppleEvent if (gStarterThread != kNoThreadID) SetThreadState(gStarterThread, kReadyThreadState, gStarterThread);*/ return(MissingParameterCheck(inputEvent)); } // DoOpenApp// --------------------------------------------------------------------------------------------------------------static pascal OSErr DoReopenApp( const AppleEvent *inputEvent, AppleEvent *outputEvent, SInt32 handlerRefCon){/*#pragma unused (outputEvent, handlerRefCon) if (FrontWindow() == nil) DoCommand(nil, cNew, 0, 0);*/ return(MissingParameterCheck(inputEvent)); } // DoReopenApp// --------------------------------------------------------------------------------------------------------------// --------------------------------------------------------------------------------------------------------------static pascal OSStatus DoOpenFile( const AppleEvent *inputEvent ) // nil == 0, zero length == print to default, other == printer name{ OSStatus anErr, anErr2; AEDescList docList; // list of docs passed in long index, itemsInList; Boolean wasAlreadyOpen;/* anErr = AEGetParamDesc( inputEvent, keyDirectObject, typeAEList, &docList); nrequire(anErr, GetFileList); anErr = AECountItems( &docList, &itemsInList); // how many files passed in nrequire(anErr, CountDocs); for (index = 1; index <= itemsInList; index++) // handle each file passed in { AEKeyword keywd; DescType returnedType; Size actualSize; FSRef fileRef; FSCatalogInfo theCatInfo; anErr = AEGetNthPtr( &docList, index, typeFSRef, &keywd, &returnedType, (Ptr)(&fileRef), sizeof( fileRef ), &actualSize ); nrequire(anErr, AEGetNthPtr); anErr = FSGetCatalogInfo( &fileRef, kFSCatInfoFinderInfo, &theCatInfo, NULL, NULL, NULL );/* nrequire(anErr, FSGetCatalogInfo); if (anErr == noErr) anErr = DetermineWindowTypeOrOpen(&fileRef, ((FInfo*)&theCatInfo.finderInfo)->fdType, nil, nil, &wasAlreadyOpen); */ // } return anErr; } // DoOpenOrPrint// --------------------------------------------------------------------------------------------------------------static pascal OSErr DoOpenDocument( const AppleEvent *inputEvent, AppleEvent *outputEvent, SInt32 handlerRefCon){#pragma unused (outputEvent, handlerRefCon) OSStatus anErr=0; anErr = DoOpenFile(inputEvent); return anErr; } // DoOpenDocumentvoid InitMac(){#if TARGET_API_MAC_OS8 InitGraf(&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(0L); FlushEvents(everyEvent, 0L); MaxApplZone();#endif /* TARGET_API_MAC_OS8 */ MoreMasters(); InitCursor();#if TARGET_API_MAC_CARBON BitMap screenBitMap; Rect screenBits; Cursor theArrow; GetQDGlobalsScreenBits(&screenBitMap); screenBits = screenBitMap.bounds; SetCursor(GetQDGlobalsArrow(&theArrow));#else Rect screenBits = qd.screenBits.bounds; SetCursor(&qd.arrow);#endif /* TARGET_API_MAC_CARBON */ SIOUXSettings.initializeTB = 0; // else SIOUX initialize the toolbox for us SIOUXSettings.toppixel = 45; SIOUXSettings.leftpixel = 15; // SIOUXSettings.fontface = bold + italic;// or normal SIOUXSettings.asktosaveonclose = 0; short bas = screenBits.bottom; short droit = screenBits.right; SIOUXSettings.columns = (short)(2.+(float)droit/8.); SIOUXSettings.rows = (short)(10. + (float)bas/18.); SIOUXSetTitle("\pfreefem+ line output"); //marche pas!! SIOUXSettings.fontface = normal; SIOUXSettings.fontid = 22;// courier; SIOUXSettings.fontsize = 10; cout << "Initmac" << endl; #define INSTALL(event, handler) \ AEInstallEventHandler(kCoreEventClass, event, handler, 0, false) // AEC, changed to use the correct handler procs// INSTALL (kAEOpenApplication, NewAEEventHandlerUPP(DoOpenApp));// INSTALL (kAEReopenApplication, NewAEEventHandlerUPP(DoReopenApp)); INSTALL (kAEOpenDocuments, NewAEEventHandlerUPP(DoOpenDocument)); #undef INSTALL}class InitilisationMac { static int init; public: InitilisationMac(){ InitMac();}};static InitilisationMac Initmac; // to call InitMacint getprog(char* fn,int argc, char** argvptr){ OSErr anErr; 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, typeFSS, &theKeyword, &actualType,&documentFSSpec, sizeof(documentFSSpec), &actualSize); if (anErr == noErr) { 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);}#ifdef FREEFEM void thisexit(){ myexit();}int main (int argc, char **argv){ char *prog; char fname[256]; SIOUXSettings.sleep=1; 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(environ)) { myenviron=1; compile (fname); // cout << "No Error" << endl; } myenviron = 0; } else printf ("To launch freefem you must type freefem and a file name\n"); return 0;}#elseextern int mymain(int argc,char **argv);string StrVersionNumber();int main (int argc, char **argv){ SIOUXUseWaitNextEvent = true; SIOUXSettings.sleep=0; char * wn = new char [256]; for (int i=0;i<256;i++) wn[i] = 0; strcpy(wn," -- FreeFem++ "); strcat(wn,StrVersionNumber().c_str()); SIOUXSetTitle((unsigned char *) wn); int ret=15; try { ret=mymain(argc,argv);} catch( ...) { cerr << "catch exception ???";} catch( Error & err) { cerr << err.what() << endl; } return ret;} void myexit(int i) { exit(i); } #endifvoid coutmode(short i) { cout << flush; cerr << flush; // if(i)(**(SIOUXTextWindow->edit)).txFace = 0; // else (**(SIOUXTextWindow->edit)).txFace = 1;;}void 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;#if TARGET_API_MAC_CARBON BitMap screenBitMap; Rect screenBits; Cursor theArrow; GetQDGlobalsScreenBits(&screenBitMap); screenBits = screenBitMap.bounds; SetCursor(GetQDGlobalsArrow(&theArrow));#else Rect screenBits = qd.screenBits.bounds; SetCursor(&qd.arrow);#endif /* TARGET_API_MAC_CARBON */ 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, "\pFreeFem Graphics",true, 8, NULL, 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; carre = aspx == aspy; lacouleur = getcolor(); CrossCurseur = GetCursor(crossCursor); WatchCurseur = GetCursor(watchCursor); GetQDGlobalsWhite(&white); GetQDGlobalsBlack(&black); //if( (**(wgRecord0.port.portPixMap)).pixelSize>7) nbcolor= 256; //else // nbcolor= 2; ncolortable =0; LastColor=2;// En couleur pas defaul colortable=0; SetColorTable(2+6); // TextFont(fontNum); TextSize(9); // small size INITGRAPH = 1; }static RGBColor DefColorMacOs( int k,int nb,bool hsv, bool grey,int nbcolors,float *colors){ RGBColor 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; 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -