📄 xmdview.c
字号:
/* * xv.c - *//* * Include files required by functions. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <X11/Xlib.h>#include "particle.h"#include "cdhouse.h"#include "cdcor.h"#include "cdalloc.h"#include "hideatom.h"#include "llist2.h"#include "grdevsub.h"#include "iofunc.h"/* * Include files required for all Toolkit programs. */#include <X11/Intrinsic.h>#include <X11/StringDefs.h>/* * Public include file for widgets we actually use in this file. */#include <X11/Shell.h> /* For popup dialog box shells */#include <X11/Xaw/SmeBSB.h> /* For menu buttons */#include <X11/Xaw/MenuButton.h> /* Menu (cascade) buttons */#include <X11/Xaw/SimpleMenu.h> /* Pop up menus */#include <X11/Xaw/Command.h> /* Command (push) buttons */#include <X11/Xaw/Box.h> /* Main window */#include <X11/Xaw/Dialog.h> /* For dialog boxes */#include <X11/Xaw/Repeater.h> /* For holding down buttons */#include <X11/Xaw/Label.h> /* For help screen */#include "checkmark" /* Check mark for selected menu items *//* * All the headers for menus, toolbar buttons, and local functions */#include "xmdview.h"/* * Defines */#define BOOLEAN int#define TRUE 1#define FALSE 0#define NSTR 255#define ATOM_MARGIN_X0 20#define ATOM_MARGIN_X1 20#define ATOM_MARGIN_Y0 20#define ATOM_MARGIN_Y1 20 #define MENU_BOX_HEIGHT 35#define INFO_BOX_HEIGHT 75#define ATOM_RADIUS_0 1e-8#define DEG_TO_RAD 0.017453293#define STEREO_INC 0.5#define XPAGE 8.5 #define YPAGE 11.0#define XMARG 1.0#define TOP_MARG 1.0#define BOTTOM_MARG 1.0/* * Macro definitions */#define WRITEMSG \ { \ printf("\nIn file, %s, at line, %d.", __FILE__, __LINE__); \ fflush(stdout); \ }#define DISPLAY_BW Display_m,Window_m,GC_m#define DISPLAY_TYPE(i) Display_m,Window_m,GC_Type_m[i]#define REFRESH \ { \ ClearBox(AtomBox_m); \ DrawInfoBox(); \ DrawAtomsFunction(); \ XFlush(Display_m); \ }#define DRAWATOM(DISP,XPOS,YPOS,WIDTH) \ { \ XFillArc(DISP, XPOS, YPOS, WIDTH, WIDTH, 0, 360*64); \ XDrawArc(DISPLAY_BW, XPOS, YPOS, WIDTH, WIDTH, 0, 360*64); \ }#define ASSERT(TEST) if (!(TEST)) \ printf ("Failed assertion (%s) in file %s line %i.\n", \ #TEST, __FILE__, __LINE__);#define ROTATE(ROT,C) \ { \ ROT[X] = Rotation_m[X][X]*C[X] + Rotation_m[X][Y]*C[Y] + \ Rotation_m[X][Z]*C[Z]; \ ROT[Y] = Rotation_m[Y][X]*C[X] + Rotation_m[Y][Y]*C[Y] + \ Rotation_m[Y][Z]*C[Z]; \ ROT[Z] = Rotation_m[Z][X]*C[X] + Rotation_m[Z][Y]*C[Y] + \ Rotation_m[Z][Z]*C[Z]; \ }/* * Type definitions */typedef enum { Points, Circles, NumCirc, NumPts } ADType_t; /* * Module wide variables */GC GC_m; /* A black FG on white BG */GC *GC_Type_m = NULL; /* Pointer to GC for each atom type */int Num_GC_Type_m = 0; /* Number of GC types */char *ColorFileName_m = NULL; /* Name of optional color file */Display *Display_m;Window Window_m;XFontStruct *FontInfo_m;FILE *InputFile_m=NULL; /* Input file name */char InputFileName_m[255]= /* Input file */ "(no file specified)";Particle_t *a; /* Actual particle information */double CenterGeom_m[NDIR]; long Step_m; /* Current step in simulation */XRectangle AtomBox_m; /* Coordinates of the drawable atom box */XRectangle InfoBox_m; /* Coordinates of the drawable info box */double Zoom_m=1.0; /* Zoom factor modification */double ZoomIncrement_m = 0.1; /* Zoom factor increment for changing zoom */double Move_m[2]={0.0,0.0}; /* Displacement of lattice center */double MoveIncrement_m = 1e-8; /* Increment for changing above */ADType_t AtomDrawType_m=Points; /* Style to draw atoms */double Rotation_m[NDIR][NDIR]= {1,0,0, 0,1,0, 0,0,1};double Orient_m[NDIR][NDIR]= {1,0,0, 0,1,0, 0,0,1};double RefOrient_m[NDIR][NDIR]= {1,0,0, 0,1,0, 0,0,1};double RotationIncrement_m = 0.087266465; /* radians */LinkList_t FileMarkers_m; /* Linked list of file positions and steps */Link_t CurLocation_m; /* Current node in the above list */int SelectAtom_m=-1; /* Number of selected atom */int NeighAtom_m=-1; /* Number of neighbor atom */BOOLEAN LeftClick_m = FALSE; /* Type of mouse button click */ Pixmap Mark_m; /* Pixmap of the X-logo */double AtomCenSize_m=0.0; /* Percentage of atom radius to use for atom center */double AtomCenPos_m[2]={0.0,0.0}; /* Percentage of atom radius to displace atom center */char TypeList_m[MAX_TYPE_NAMES][255]; /* List of type names read from xyz files */BOOLEAN HideAtoms_m=FALSE; /* Toggle hiding atoms with mouse click */int MaxParticles_m=0; /* Maximum number of particles */BOOLEAN *HideList_m=NULL; /* For each atom, TRUE if hidden, FALSE otherwise */BOOLEAN Stereo_m = FALSE; /* Toggle between stereo vision */double StereoAngle_m = STEREO_INC*DEG_TO_RAD; /* Stereo vision rotation angle */BOOLEAN Clip_m = FALSE; /* Toggle use of clipping plane */double Scale_m=-1.0; /* Scale from cm to pixels */double Range_m; /* Maximum distance from center of geometry */ double AtomRadius_m=ATOM_RADIUS_0; /* Atom radius in cm */double AtomIncrement_m = 0.1e-8; /* Value for changing atom size */double AtomDisplayRadius_m=0; /* Atom radius in pixels *//* Certain widgets used in dialog boxes must be module-wide */Widget fileShell_m;Widget openButton_m;Widget printButton_m;Widget printShell_m;Widget refOrientShell_m;Widget refOrientButton_m;Widget rotationShell_m;Widget setRotationButton_m;Widget moveShell_m;Widget setMoveButton_m;Widget zoomShell_m;Widget setZoomButton_m; Widget atomShell_m;Widget setAtomButton_m;Widget atomCenSizeShell_m;Widget setAtomCenSizeButton_m;Widget atomCenPosShell_m;Widget setAtomCenPosButton_m;Widget gotoShell_m;Widget gotoButton_m;Widget filtnghShell_m;Widget filtnghButton_m;Widget topicShell_m;Widget topicButton_m;Widget aboutShell_m;Widget aboutButton_m;Widget atTypeToolButton_m;Widget stereoButton_m;Widget atNumButton_m;Widget hideAtomsButton_m;Widget clipAtomsButton_m;/* Sort variables */static unsigned *_x;static double *_d, _xd, _td;static int _j;/* * Menu creation function headers */void MakeFileMenu(Widget parent, Widget top, Widget *fileB, Widget *menu, Widget *openB, Widget *fileS, Widget *fileSelD, Widget *fileOKB, Widget *fileCancelB, Widget *printB, Widget *printS, Widget *printD, Widget *printOKB, Widget *printCancelB, Widget *quitB);void MakeOptionsMenu(Widget parent, Widget top, Widget *optionsB, Widget *menu, Widget *resetB, Widget *setRotationB, Widget *rotationS, Widget *rotationD, Widget *rotationOKB, Widget *rotationCancelB, Widget *setMoveB, Widget *moveS, Widget *moveD, Widget *moveOKB, Widget *moveCancelB, Widget *setZoomB, Widget *zoomS, Widget *zoomD, Widget *zoomOKB, Widget *zoomCancelB, Widget *setAtomB, Widget *atomS, Widget *atomD, Widget *atomOKB, Widget *atomCancelB, Widget *refOrientB, Widget *refOrientS, Widget *refOrientD, Widget *refOrientOKB, Widget *refOrientCancelB, Widget *setAtomCenSizeB, Widget *atomCenSizeS, Widget *atomCenSizeD, Widget *atomCenSizeOKB, Widget *atomCenSizeCancelB, Widget *setAtomCenPosB, Widget *atomCenPosS, Widget *atomCenPosD, Widget *atomCenPosOKB, Widget *atomCenPosCancelB, Widget *atNumB, Widget *stereoB, Widget *hideAtomsB, Widget *unHideAtomsB, Widget *clipAtomsB, Widget *gotoB, Widget *gotoS, Widget *gotoD, Widget *gotoOKB, Widget *gotoCancelB);void MakeFilterMenu(Widget parent, Widget top, Widget *filterB, Widget *menu, Widget *filtnghB, Widget *filtnghS, Widget *filtnghD);void MakeHelpMenu(Widget parent, Widget top, Widget *helpB, Widget *menu, Widget *topicB, Widget *topicS, Widget *topicF, Widget *topicL, Widget *topicOKB, Widget *aboutB, Widget *aboutS, Widget *aboutD, Widget *aboutOKB);void MakeToolBar(Widget parent, Widget *firstToolB, Widget *backToolB, Widget *nextToolB, Widget *lastToolB, Widget *resetToolB, Widget *rtLeftToolB, Widget *rtRightToolB, Widget *rtUpToolB, Widget *rtDownToolB, Widget *mvLeftToolB, Widget *mvRightToolB, Widget *mvUpToolB, Widget *mvDownToolB, Widget *zmInToolB, Widget *zmOutToolB, Widget *atPlusToolB, Widget *atMinusToolB, Widget *stAnglePlusToolB, Widget *stAngleMinusToolB, Widget *atTypeToolB);BOOLEAN FindStereoAtom(int x, int y, BOOLEAN Left);void HideAtomsButtonFunction(Widget w, XtPointer client_data, XtPointer call_data);void UnHideAtomsButtonFunction(Widget w, XtPointer client_data, XtPointer call_data);void ClipAtomsButtonFunction(Widget w, XtPointer client_data, XtPointer call_data);void PrintButtonFunction(Widget w, XtPointer client_data, XtPointer call_data);void OKPrintFunction(Widget w, XtPointer client_data, XtPointer call_data);void CancelPrintFunction(Widget w, XtPointer client_data, XtPointer call_data);void PrintAtoms(char *filename);void PrintStereoAtoms(BOOLEAN Left, double InchToPixel);void MakeColorGC (Widget *workArea, char **ColorList, char ncol);void PrintUsage (void);/* * Main routine */main(argc, argv)int argc;char **argv;{ int iopt; XtAppContext app_context; Widget topLevel, menuBar, frameWindow; Widget fileButton, fileMenu, fileSelDialog, fileOKButton, fileCancelButton, printDialog, printOKButton, printCancelButton, quitButton; Widget optionsButton, optionsMenu, resetButton, rotationDialog, rotationOKButton, rotationCancelButton, moveDialog, moveOKButton, moveCancelButton, zoomDialog, zoomOKButton, zoomCancelButton, atomDialog, atomOKButton, atomCancelButton, refOrientDialog, refOrientOKButton, refOrientCancelButton, atomCenSizeDialog, atomCenSizeOKButton, atomCenSizeCancelButton, atomCenPosDialog, atomCenPosOKButton, atomCenPosCancelButton, unHideAtomsButton, gotoDialog, gotoOKButton, gotoCancelButton; Widget filterButton, filterMenu, filtnghDialog; Widget helpButton, helpMenu, topicForm, topicLabel, topicOKButton, aboutDialog, aboutOKButton; Widget firstToolButton, backToolButton, nextToolButton, lastToolButton, resetToolButton, rtLeftToolButton, rtRightToolButton, rtUpToolButton, rtDownToolButton, mvLeftToolButton, mvRightToolButton, mvUpToolButton, mvDownToolButton, zmInToolButton, zmOutToolButton, atPlusToolButton, atMinusToolButton, stAnglePlusToolButton, stAngleMinusToolButton; /* * Create and initialize root widget */ XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); topLevel = XtVaAppInitialize( &app_context, /* Application context */ "XHello", /* Application class */ NULL, 0, /* command line option list */ &argc, argv, /* command line args */ NULL, /* for missing app-defaults file */ NULL); /* terminate varargs list */ /* Test for file option */ iopt=1; if (argc>1) { if (!strncmp("-f",argv[1],2)) { if (argv[1][2]!='\0') { ColorFileName_m = strdup (argv[1]+2); iopt=2; } else if (argc> 2) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -