📄 xgcommands.c
字号:
#include "xgrafixint.h"#include <stdlib.h>#include <signal.h>#ifdef XPMENABLED#include <X11/xpm.h>#endifstatic double xtemp1, ytemp1;int C_CreateWindowProc(ClientData, Tcl_Interp *, int, char **);int C_KillGraphicsProc();void StartGraphics(void);void Signal_KillGraphicsProc(int i);void Signal_RestoreGraphicsProc(int i) { signal(SIGUSR1,SIG_IGN); theRunWithXFlag = TRUE;}void Signal_KillGraphicsProc(int i) { signal(SIGUSR1,SIG_IGN);#ifdef Tcl75_Tk41 Tcl_DoWhenIdle((Tcl_IdleProc*) C_KillGraphicsProc,(ClientData)NULL);#endif#ifdef Tcl74_Tk40 Tk_DoWhenIdle((Tk_IdleProc*) C_KillGraphicsProc,(ClientData)NULL);#endif}void XG_Quit(){ Quit(); if (theCodeName) free(theCodeName); if (theInputFile) free(theInputFile); if (theDumpFile) free(theDumpFile); if (theEPSFile) free(theEPSFile); if (theRunWithXFlag == TRUE) { Tcl_DeleteInterp(interp); XFreeFont(theDisplay,theFontStruct); XCloseDisplay(theDisplay); } exit(0);}void StartGraphics() { WindowType theWindow; int i; FILE *f; char str[80]; char xgdisfile[512]; sprintf(xgdisfile,"%s/.xgdisplay",getenv("HOME")); f = fopen(xgdisfile, "r"); if (f == NULL) { printf("File %s could not be read.\n",xgdisfile); printf("Continuing without X.\n"); theRunWithXFlag = FALSE; return; } fgets(str, 79, f); strcpy(ReqDisp, str); i = strlen(ReqDisp) - 1; if (ReqDisp[i] == '\n') { ReqDisp[i] = '\0'; } fclose(f); if ((theDisplay = XOpenDisplay(ReqDisp)) == NULL) { printf("Couldn't open display: %s\n", ReqDisp); printf("Continuing without X.\n"); theRunWithXFlag = FALSE; return; } XCloseDisplay(theDisplay); /* Reinitialize the X and Tcl/Tk stuff. */ XGInitX(); XGInitTclTk(); /* Reinitialize the special dialog box. */ for (i=0; i<numberOfSpecials; i++) { sprintf(TclCommand, "SetUpNewVar %d \"%s\" \"%s\"\n", i, theSpecialArray[i]->Varname, ( theSpecialArray[i]->Type == INTEGER ) ? "integer" : (( theSpecialArray[i]->Type == FLOAT ) ? "float" : (( theSpecialArray[i]->Type == DOUBLE ) ? "double" : "char" ))); Tcl_Eval(interp, TclCommand); } /* Recreate all the diagnostic windows. */ for (i=0; i<numberOfWindows; i++) { theWindow = theWindowArray[i]; sprintf(TclCommand, "SetupWindow \"%s\" %s %d %d %c %.3g %.3g %d %.3g %.3g %d %.3g %.3g %d %s %.3g %.3g %d %d %d %d %d %d %s \"%s\" \"%s\"\n", theWindow->plot_title, "closed", theWindow->ulxc, theWindow->ulyc, theWindow->type, theWindow->label->X_Min, theWindow->label->X_Max, Is_X_AutoRescale(theWindow), theWindow->label->Y_Min, theWindow->label->Y_Max, Is_Y_AutoRescale(theWindow), theWindow->label->Z_Min, theWindow->label->Z_Max, Is_Z_AutoRescale(theWindow), theWindow->eps_file_name, theWindow->theta, theWindow->phi,Is_Shading_On(theWindow), Is_ColorCode_On(theWindow), Is_Grid_On(theWindow), Is_X_Log(theWindow), Is_Y_Log(theWindow), Is_Z_Log(theWindow), theDumpFile, theWindow->label->X_Label, theWindow->label->Y_Label); if (Tcl_Eval(interp, TclCommand) != TCL_OK) { printf("Error re-creating window.\n"); } } theRunWithXFlag = TRUE; theRunFlag = FALSE;}void DoGraphics(ClientData cl){ /* printf("c doGraph\n"); */ sprintf(TclCommand,"UpdateTime %g ; update; DoGraphics; update idletasks\n", *theTimeStep); Tcl_Eval(interp,TclCommand); if(theRunFlag==TRUE) {#ifdef Tcl75_Tk41 Tcl_CreateTimerHandler(0, DoMain,(ClientData)NULL);#endif#ifdef Tcl74_Tk40 Tk_CreateTimerHandler(0, DoMain,(ClientData)NULL);#endif }}void DoMain(ClientData cl){ char thePDumpFile[80], thePDFRoot[80]; strncpy(thePDFRoot,theDumpFile,findlen(theDumpFile)); thePDFRoot[findlen(theDumpFile)] = '\0'; sprintf(TclCommand,"update \n"); Tcl_Eval(interp,TclCommand); /* printf("c domain\n"); */ if (theNumberOfSteps==0 || theCurrentStep<=theNumberOfSteps) { int il; for(il=0;il<iterationsPerXUpdate;il++) { XGMainLoop(); if (theDumpPeriod!=0 && theCurrentStep%theDumpPeriod==0) { sprintf(thePDumpFile,"%s%d%s",thePDFRoot, theCurrentStep/theDumpPeriod,theDumpExtension); if (theIDumpFlag) Dump(thePDumpFile); else Dump(theDumpFile); } theCurrentStep++; }#ifdef Tcl75_Tk41 Tcl_CreateTimerHandler(0, DoGraphics,(ClientData)NULL);#endif#ifdef Tcl74_Tk40 Tk_CreateTimerHandler(0, DoGraphics,(ClientData)NULL);#endif } else { if(theExitFlag) { if ((theDumpPeriod!=0) && (theIDumpFlag)) { sprintf(thePDumpFile,"%s%d%s",thePDFRoot, theCurrentStep/theDumpPeriod+1,theDumpExtension); Dump(thePDumpFile); } else Dump(theDumpFile); XG_Quit(); } else { theNumberOfSteps = 0; Tcl_Eval(interp,".lbframe.run invoke\n"); Tcl_Eval(interp,".lbframe.save invoke\n"); } }}void XGStart(){ char thePDumpFile[80], thePDFRoot[80]; strncpy(thePDFRoot,theDumpFile,findlen(theDumpFile)); thePDFRoot[findlen(theDumpFile)] = '\0'; while (!theExitFlag) { if (theRunWithXFlag == TRUE) { SortWindows(); if(numberOfSpecials!=0) if(Tcl_Eval(interp,"CreateSpecialDialog\n")!=TCL_OK) { printf("Error creating Special Dialog\n"); printf("%s\n",interp->result); } sprintf(TclCommand,"UpdateTime %g ; DoGraphics; update idletasks\n",*theTimeStep); /* Tcl_Eval(interp,TclCommand); put below */ if(Tcl_Eval(interp,"Tk_XGStart\n")!=TCL_OK) { printf("Error calling Tk_XGStart\n"); } Tcl_Eval(interp,TclCommand); if (theNumberOfSteps != 0) { Tcl_Eval(interp,".lbframe.run invoke\n"); } /* Change the procedure for the HUP signal. */ signal(SIGUSR1, Signal_KillGraphicsProc); Tk_MainLoop(); } if (theRunWithXFlag == FALSE) { signal(SIGUSR1, Signal_RestoreGraphicsProc); while ((theNumberOfSteps==0 || theCurrentStep<=theNumberOfSteps) && (theRunWithXFlag == FALSE)) { XGMainLoop(); if (theDumpPeriod!=0 && theCurrentStep%theDumpPeriod==0) { sprintf(thePDumpFile,"%s%d%s",thePDFRoot, theCurrentStep/theDumpPeriod,theDumpExtension); if (theIDumpFlag) Dump(thePDumpFile); else Dump(theDumpFile); } theCurrentStep++; } if ((theDumpPeriod!=0) && (theCurrentStep%theDumpPeriod==0)) { sprintf(thePDumpFile,"%s%d%s",thePDFRoot, theCurrentStep/theDumpPeriod,theDumpExtension); if (theIDumpFlag) Dump(thePDumpFile); else Dump(theDumpFile); } if(theCurrentStep>theNumberOfSteps && (theRunWithXFlag == FALSE)) { XG_Quit(); } if (theRunWithXFlag == TRUE) StartGraphics(); } } XG_Quit();}int C_OpenProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv){ WindowType theWindow; int index = atoi(argv[1]); theWindow = theWindowArray[index]; if (theWindow->openFlag) { *theWindow->openFlag = TRUE; } return TCL_OK;}int C_CloseProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv){ WindowType theWindow; int i, m; int index = atoi(argv[1]); theWindow = theWindowArray[index]; if(theWindow->pixmap_buffer) { XFreePixmap(theDisplay, theWindow->pixmap_buffer); theWindow->pixmap_buffer = 0; } if(theWindow->theMesh) { m = *(theWindow->data->mpoints); for (i = 0; i < m; i++) free(theWindow->theMesh[i]); free(theWindow->theMesh); theWindow->theMesh = 0; } if (theWindow->openFlag) { *theWindow->openFlag = FALSE; } return TCL_OK;}int C_RunProc(){ theRunFlag=TRUE;#ifdef Tcl75_Tk41 Tcl_DoWhenIdle(DoMain,(ClientData)NULL);#endif#ifdef Tcl74_Tk40 Tk_DoWhenIdle(DoMain,(ClientData)NULL);#endif return TCL_OK;}int C_StopProc(){ theRunFlag=FALSE; return TCL_OK;}int C_KillGraphicsProc(){ int i; theRunWithXFlag = FALSE; for (i=0; i<numberOfWindows; i++) { XFreePixmap(theDisplay, theWindowArray[i]->pixmap_buffer); theWindowArray[i]->pixmap_buffer = 0; } sprintf(TclCommand, "set WaitVariable 2 ; destroy .\n"); Tcl_Eval(interp, TclCommand); return TCL_OK;}int C_QuitProc() { theExitFlag = TRUE; return TCL_OK;}int C_StepProc(){ if(theRunFlag==TRUE) { Tcl_Eval(interp,".lbframe.run invoke\n"); }#ifdef Tcl75_Tk41 Tcl_DoWhenIdle(DoMain,(ClientData)NULL);#endif#ifdef Tcl74_Tk40 Tk_DoWhenIdle(DoMain,(ClientData)NULL);#endif return TCL_OK;}int C_SaveProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv){ Dump(argv[1]); return TCL_OK;}int C_printfProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv){ printf("%s\n", argv[1]); return TCL_OK;}int C_pauseProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv){ int i; float f; for (i=0; i<=10000; i++) f = cos(sqrt(3.14*i)); printf("wait done - %s\n", argv[1]); return TCL_OK;}int C_RefreshGraphicsProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv){ WindowType Window = theWindowArray[atoi(argv[1])]; RedrawWindow(Window); return TCL_OK;}int C_RescaleProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv){ LabelType label; WindowType Window = theWindowArray[atoi(argv[1])]; label = Window->label; label->X_Min = atof(argv[2]); label->X_Max = atof(argv[3]); label->X_Auto_Rescale = atoi(argv[4]); if(label->X_Auto_Rescale) X_AutoRescale(Window); else X_AutoRescale_Off(Window); if(atoi(argv[5])) Set_X_Log(Window); else Set_X_Lin(Window); label->Y_Min = atof(argv[6]); label->Y_Max = atof(argv[7]); label->Y_Auto_Rescale = atoi(argv[8]); if(label->Y_Auto_Rescale) Y_AutoRescale(Window); else Y_AutoRescale_Off(Window); if(atoi(argv[9])) Set_Y_Log(Window); else Set_Y_Lin(Window); label->Z_Min = atof(argv[10]); label->Z_Max = atof(argv[11]); label->Z_Auto_Rescale = atoi(argv[12]); if(label->Z_Auto_Rescale) { Set_ThreeD(theNewWindow); ColorCode_On(theNewWindow);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -