home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum23.lzh / f23b / SOFTWARE / PDRAW / plotX11.c < prev    next >
Text File  |  1992-01-15  |  42KB  |  1,277 lines

  1. /*   plotX.c - all the X11 routines  ***/
  2.  
  3. #include <X11/Xlib.h>
  4. #include <X11/Xutil.h>
  5. #include <X11/Xos.h>
  6. #include <X11/keysym.h>
  7. #include <stdio.h>
  8. #include <strings.h>
  9. #include <math.h>
  10.  
  11. #include "header.h" 
  12. #include "Xdefs.h"
  13. #include "iconX11.ic"
  14.  
  15. /* colors */
  16. #define DEFAULT_BORDER_COLOR  "Blue"
  17. #define DEFAULT_BACK_COLOR    "MidNightBlue"
  18. #define DEFAULT_FORE_COLOR    "White"
  19. #define DEFAULT_MOUSE_COLOR   "White"
  20. #define DEFAULT_ICON_COLOR    "Red"
  21. #define BDR_C                 0
  22. #define BACK_C                1
  23. #define FORE_C                2
  24. #define MOUSE_C               3
  25. #define ICON_C                4
  26. #define LINE1_C               5
  27. #define LINE2_C               6
  28. #define LINE3_C               7
  29. #define LINE4_C               8
  30. #define LINE5_C               9
  31. #define BACK2_C               10
  32. #define MAX_COLORS            11
  33.  
  34. unsigned long     border_pixel;                   /* color of border */
  35. unsigned long     background_pixel;               /* color of background */
  36. unsigned long     foreground_pixel;               /* color of foreground */
  37. unsigned long     mouseground_pixel;              /* mouse cursor color */
  38. unsigned long     icon_pixel;                     /* icon color */
  39. unsigned long     colors[MAX_COLORS];             /* color pixel values */
  40. char              *clr_name[MAX_COLORS];          /* color names */
  41.  
  42. /* line-types */
  43. #  define DOTTED       2
  44. #  define SHORT_DOTTED 2
  45. #  define LONG_DOTTED  2
  46. #  define DASHED       2
  47. #  define DOT_DASHED   4
  48. #  define DASH_DOTTED  4
  49. #  define SHORT_DASHED 2
  50. #  define LONG_DASHED  2
  51. #  define EQUAL_DASHED 2
  52. #  define ODD_DASHED   3
  53.    static unsigned char dash_list_dotted[DOTTED]             = {1,6};
  54.    static unsigned char dash_list_short_dotted[SHORT_DOTTED] = {1,3};
  55.    static unsigned char dash_list_long_dotted[LONG_DOTTED]   = {1,8};
  56.    static unsigned char dash_list_dashed[DASHED]             = {4,4};
  57.    static unsigned char dash_list_dot_dashed[DOT_DASHED]     = {3,4,3,1};
  58.    static unsigned char dash_list_dash_dotted[DASH_DOTTED]   = {4,3,1,3};
  59.    static unsigned char dash_list_short_dashed[SHORT_DASHED] = {3,5};
  60.    static unsigned char dash_list_equal_dashed[EQUAL_DASHED] = {6,6};
  61.    static unsigned char dash_list_long_dashed[LONG_DASHED]   = {7,4};
  62.    static unsigned char dash_list_odd_dashed[ODD_DASHED]     = {1,2,3};
  63.  
  64. /* characters */
  65. #define EVO 1
  66. #define EVL 2
  67. #define EVJ 3
  68. #define EVK 4
  69. #define EVH 5
  70. #define EVF 6
  71. #define EVS 7
  72. #define EVD 8
  73. #define EVA 9
  74. #define EVX 10
  75. #define EVY 11
  76. #define EVZ 12
  77.  
  78. /* buttons */
  79. char button_label[10][100];
  80.  
  81. #define REVERSE          0
  82. #define NORMAL           1
  83. #define NBUTTONS         7
  84. #define B_HEIGHT         20
  85.  
  86. /* plot information */
  87. #define X_ORG            5
  88. #define Y_ORG            5
  89. #define X_DIM            600
  90. #define Y_DIM            600
  91. #define DEFAULT_BDR_DIM  100
  92.  
  93. int Width, Height;
  94.  
  95. /* Misc */
  96. #define DEFAULT_BORDER_WIDTH  3
  97. #define DEFAULT_FONT          "8x13"
  98.  
  99. short gray_bits[16] = {
  100.    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  101.    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  102.    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  103.    0xaaaa, 0x5555, 0xaaaa, 0x5555};
  104.  
  105. Display     *display;                   /* display */
  106. int         screen;                     /* screen */
  107. Window      vwwindow;                   /* parent window */
  108. Window      buttons[NBUTTONS];          /* button windows */
  109. XFontStruct *font_info;                 /* font information */
  110. XSizeHints  size_hints;                 /* window info for manager */
  111. GC          gc;                         /* graphics context */
  112. GC          bgc, bgcr;                  /* graphics context, buttons */
  113.  
  114. InitWindow(argc,argv)
  115. int  argc;
  116. char **argv;
  117. {
  118.    Pixmap     icon_pixmap;
  119.    XGCValues  gcvalues;
  120.    char       *sprintf(), default_geometry[100];
  121.    int        i, x, y, width, height;
  122.    double     bwd;
  123.  
  124.    /* Open display first, and get screen info */
  125.    if (!(display = XOpenDisplay(display_name))) {
  126.       fprintf(stderr,"%s:Could not open display %s\n",
  127.               progname,display_name);
  128.       exit(1);
  129.    }
  130.    screen = DefaultScreen(display);
  131.    sprintf(default_geometry,"=%dx%d+%d+%d",X_DIM,Y_DIM,X_ORG,Y_ORG);
  132.  
  133.    /* Merge the options first */
  134.    Merge_Options();
  135.  
  136.    /* allocate the colors */
  137.    Alloc_Colors();
  138.  
  139.    /* Initialize the window */
  140.    if (!XGeometry(display,screen,geometry,default_geometry,border_width,
  141.                  0,0,0,0,&x,&y,&width,&height)) {
  142.       x      = X_ORG;
  143.       y      = Y_ORG;
  144.       width  = X_DIM;
  145.       height = Y_DIM;
  146.    }
  147.    vwwindow = XCreateSimpleWindow(display, RootWindow(display,screen),
  148.                      x, y, width, height, border_width,
  149.                      border_pixel, background_pixel);
  150.  
  151.    /* make buttons */
  152.    bwd       = (width-10)/((double)(NBUTTONS-2));
  153.    buttons[0]= XCreateSimpleWindow(display, vwwindow,
  154.                      5, 5, (int)(width-10-bwd), B_HEIGHT,1,
  155.                      border_pixel, background_pixel);
  156.    buttons[1]= XCreateSimpleWindow(display, vwwindow,
  157.                      (int)(5+width-10-bwd), 5, (int)bwd, B_HEIGHT,1,
  158.                      border_pixel, background_pixel);
  159.    for (i=2; i<NBUTTONS; i++) {
  160.       buttons[i]= XCreateSimpleWindow(display, vwwindow,
  161.                      5+(int)(bwd*(i-2)),5+B_HEIGHT,
  162.                      (int)bwd,B_HEIGHT,1,
  163.                      border_pixel, background_pixel);
  164.    }
  165.  
  166.    /* Initialize size hint property for window manager */
  167.    size_hints.flags      = PPosition | PSize | PMinSize;
  168.    size_hints.x          = x;
  169.    size_hints.y          = y;
  170.    size_hints.width      = width;
  171.    size_hints.height     = height;
  172.    size_hints.min_width  = X_DIM;
  173.    size_hints.min_height = Y_DIM;
  174.  
  175.    /* Create pixmap of depth 1 (bitmap) for icon */
  176.    icon_pixmap = XCreateBitmapFromData(display, vwwindow, icon_bitmap_bits,
  177.                         icon_bitmap_width, icon_bitmap_height);
  178.  
  179.    /* set properties for window manager */
  180.    XSetStandardProperties(display, vwwindow, "Pdraw Program", "Pdraw",
  181.                           icon_pixmap, argv, argc, &size_hints);
  182.  
  183.    /* Select event types wanted */
  184.    XSelectInput(display,vwwindow,ExposureMask | ButtonPressMask  |
  185.                 ButtonReleaseMask | KeyPressMask | StructureNotifyMask );
  186.    for (i=0; i<NBUTTONS; i++) 
  187.       XSelectInput(display,buttons[i],ExposureMask | ButtonPressMask  |
  188.                    ButtonReleaseMask);
  189.  
  190.    /* Create GC for text and drawing */
  191.    gc = XCreateGC(display, vwwindow, 0, &gcvalues);
  192.  
  193.    /* create 2 graphics contexts for buttons */
  194.    bgc  = XCreateGC(display, vwwindow, 0, NULL);
  195.    XSetForeground(display, bgc, background_pixel);
  196.    bgcr = XCreateGC(display, vwwindow, 0, NULL);
  197.    XSetForeground(display, bgcr, foreground_pixel);
  198.  
  199.    /* Find a font and load it */
  200.    if (!(font_info = XLoadQueryFont(display,font_name))){
  201.       fprintf(stderr,"%s:Could not open font %s\n",progname,font_name);
  202.       exit(1);
  203.    }
  204.    XSetFont(display, gc, font_info->fid);
  205.  
  206.    /* specify foreground */
  207.    XSetForeground(display, gc, foreground_pixel);
  208.  
  209.    /* Display the window */
  210.    XMapSubwindows(display, vwwindow);
  211.    XMapWindow(display, vwwindow);
  212. }
  213.  
  214. /* Initialize and merge the various options */
  215. Merge_Options()
  216. {
  217.    char    *option;
  218.  
  219.    /* process the various options */
  220.    if (reverse < 0) {
  221.       if ((option = XGetDefault(display,progname,"ReverseVideo")) != NULL)
  222.          if (strcmp(option,"on")) reverse = 1;
  223.    }
  224.    if (!geometry) {
  225.       option = XGetDefault(display,progname,"Geometry");
  226.       geometry = option ? option : "=+5+5";
  227.    }
  228.    if (!font_name) {
  229.       /* option = XGetDefault(display,progname,"BodyFont"); */
  230.       font_name = DEFAULT_FONT;
  231.    }
  232.    if (!border_color) {
  233.       option = XGetDefault(display,progname,"Border");
  234.       border_color = option ? option : DEFAULT_BORDER_COLOR;
  235.    }
  236.    if (!back_color) {
  237.       option = XGetDefault(display,progname,"Background");
  238.       back_color = option ? option : DEFAULT_BACK_COLOR;
  239.    }
  240.    if (!fore_color) {
  241.       option = XGetDefault(display,progname,"Foreground");
  242.       fore_color = option ? option : DEFAULT_FORE_COLOR;
  243.    }
  244.    if (!mouse_color) {
  245.       option = XGetDefault(display,progname,"Mouse");
  246.       mouse_color = option ? option : DEFAULT_MOUSE_COLOR;
  247.    }
  248.    if (!icon_color) {
  249.       option = XGetDefault(display,progname,"Icon");
  250.       icon_color = option ? option : DEFAULT_ICON_COLOR;
  251.    }
  252.    if (border_width <= 0) {
  253.       option = XGetDefault(display,progname,"BorderWidth");
  254.       border_width = option ? atoi(option) : DEFAULT_BORDER_WIDTH;
  255.    }
  256. }
  257.  
  258. /* allocate the colors on color display */
  259. Alloc_Colors()
  260. {
  261.    XColor        cdef;
  262.    Colormap      cmap;
  263.    int           i, depth;
  264.    unsigned long tmp_pixel;
  265.  
  266.    /* get info on depth and colormap */
  267.    depth = DisplayPlanes(display,screen);
  268.    cmap  = DefaultColormap(display,screen);
  269.  
  270.    /* associate named colors with pixel values */
  271.    if (depth == 1) {       /* one-plane monochrome */
  272.       colors[BDR_C]     = BlackPixel(display,screen);
  273.       colors[BACK_C]    = BlackPixel(display,screen);
  274.       colors[BACK2_C]   = BlackPixel(display,screen);
  275.       colors[FORE_C]    = WhitePixel(display,screen);
  276.       colors[MOUSE_C]   = colors[FORE_C];            
  277.       colors[ICON_C]    = colors[FORE_C];            
  278.       for (i=LINE1_C; i<=LINE5_C; i++) colors[i] = colors[FORE_C];
  279.    } else {                /* color */
  280.       clr_name[BDR_C]   = border_color;
  281.       clr_name[BACK_C]  = back_color;
  282.       clr_name[BACK2_C] = "MediumBlue";
  283.       clr_name[FORE_C]  = fore_color;
  284.       clr_name[MOUSE_C] = mouse_color;
  285.       clr_name[ICON_C]  = icon_color;
  286.       clr_name[LINE1_C] = "red";
  287.       clr_name[LINE2_C] = "yellow";
  288.       clr_name[LINE3_C] = "MediumBlue";
  289.       clr_name[LINE4_C] = "green";
  290.       clr_name[LINE5_C] = "blue";
  291.       for (i=0; i<MAX_COLORS; i++) 
  292.          if (XAllocNamedColor(display,cmap,clr_name[i],&cdef,&cdef))
  293.             colors[i] = cdef.pixel;
  294.          else {
  295.             fprintf(stderr,"%s: Can't allocate color %s\n",
  296.                     progname, clr_name[i]);
  297.             exit(1);
  298.          } /* end if */
  299.    }  /* end if */
  300.  
  301.    /* assign pixel values */
  302.    border_pixel      = colors[BDR_C];
  303.    background_pixel  = colors[BACK_C];
  304.    foreground_pixel  = colors[FORE_C];
  305.    mouseground_pixel = colors[MOUSE_C];
  306.    icon_pixel        = colors[ICON_C];
  307.  
  308.    /* reverse video */
  309.    if (reverse) {
  310.       tmp_pixel        = background_pixel;
  311.       background_pixel = foreground_pixel;
  312.       foreground_pixel = tmp_pixel;
  313.       if (border_pixel == background_pixel)
  314.          border_pixel = foreground_pixel;
  315.       if (mouseground_pixel == background_pixel) 
  316.          mouseground_pixel = foreground_pixel;
  317.       for (i=LINE1_C; i<=LINE5_C; i++)
  318.          if (colors[i]==background_pixel) colors[i] = foreground_pixel;
  319.    }
  320. }
  321.  
  322. RunOps()
  323. {
  324.    XEvent   event;
  325.    KeySym   keysym;
  326.    XComposeStatus compose;
  327.    char     buffer[1];
  328.    int      bufsize = 1;
  329.    int      i;       
  330.    double   theta = 0.0;
  331.    double   phi   = 0.0;
  332.    unsigned int button;
  333.    static char *event_name[] = {
  334.       "",
  335.       "",
  336.       "KeyPress",
  337.       "KeyRelease",
  338.       "ButtonPress",
  339.       "ButtonRelease",
  340.       "MotionNotify",
  341.       "EnterNotify",
  342.       "LeaveNotify",
  343.       "FocusIn",
  344.       "FocusOut",
  345.       "KeymapNotify",
  346.       "Expose",
  347.       "GraphicsExpose",
  348.       "NoExpose",
  349.       "VisibilityNotify",
  350.       "CreateNotify",
  351.       "DestroyNotify",
  352.       "UnmapNotify",
  353.       "MapNotify",
  354.       "MapRequest",
  355.       "ReparentNotify",
  356.       "ConfigureNotify",
  357.       "ConfigureRequest",
  358.       "GravityNotify",
  359.       "ResizeRequest",
  360.       "CirculateNotify",
  361.       "CirculateRequest",
  362.       "PropertyNotify",
  363.       "SelectionClear",
  364.       "SelectionRequest",
  365.       "SelectionNotify",
  366.       "ColormapNotify",
  367.       "ClientMessage",
  368.       "MappingNotify",
  369.    };
  370.  
  371.    /* Initialize window size */
  372.    Width  = X_DIM;
  373.    Height = Y_DIM - 2*B_HEIGHT;
  374.  
  375.    /* event loop */
  376.    while(1) {
  377.       XNextEvent(display, &event);
  378.       /* printf("Event : %s\n",event_name[event.type]); */
  379.       switch (event.type) {
  380.       case Expose:
  381.      /* get rid of all other expose events */
  382.          while (XCheckTypedEvent(display,Expose,&event));
  383.          ShowView(theta,phi);
  384.          break;
  385.       case ButtonPress:
  386.          for (i=0; i<NBUTTONS; i++) {
  387.             if (event.xbutton.window == buttons[i]) {
  388.                paint_button(buttons[i],REVERSE,i,theta,phi);
  389.                button = event.xbutton.button;
  390.                /* get the matching button release on the same button */
  391.                while (1) {
  392.                   while (XCheckTypedEvent(display,ButtonPress,&event));
  393.                   /* wait for release; if on correct button, exit */
  394.                   XMaskEvent(display, ButtonReleaseMask, &event);
  395.                   if (event.xbutton.button == button) {
  396.                      paint_button(buttons[i],NORMAL,i,theta,phi);
  397.                      break;
  398.                   }
  399.                }
  400.                switch (i) {
  401.                case 0 : XUnloadFont(display, font_info->fid);
  402.                         XFreeGC(display, gc);
  403.                         XFreeGC(display, bgc);
  404.                         XFreeGC(display, bgcr);
  405.                         XCloseDisplay(display);
  406.                         return;
  407.                         break;
  408.                case 1 : if (hiddenline) hiddenline = FALSE; 
  409.                         else            hiddenline = TRUE ; 
  410.                         rotate_picture(100,&theta,&phi); break;
  411.                case 2 : rotate_picture(EVO,&theta,&phi); break;
  412.                case 3 : rotate_picture(EVH,&theta,&phi); break;
  413.                case 4 : rotate_picture(EVL,&theta,&phi); break;
  414.                case 5 : rotate_picture(EVK,&theta,&phi); break;
  415.                case 6 : rotate_picture(EVJ,&theta,&phi); break;
  416.                default: break;
  417.                }
  418.             }
  419.          }
  420.          /* don't do anything if button is pressed in general window */
  421.          break;
  422.       case ConfigureNotify:
  423.          /* window has been resized */
  424.          /* change width and height */
  425.          Width  = event.xconfigure.width;
  426.          Height = event.xconfigure.height - 2*B_HEIGHT;
  427.          break;
  428.       case KeyPress:
  429.          XLookupString(&event,buffer,bufsize,&keysym,&compose);
  430.          if ((keysym == XK_q) || (keysym == XK_Q)) {
  431.             XUnloadFont(display, font_info->fid);
  432.             XFreeGC(display, gc);
  433.             XFreeGC(display, bgc);
  434.             XFreeGC(display, bgcr);
  435.             XCloseDisplay(display);
  436.             return;
  437.          } else if ((keysym == XK_l) || (keysym == XK_L)) 
  438.             rotate_picture(EVL,&theta,&phi);
  439.          else if ((keysym == XK_k) || (keysym == XK_K)) 
  440.             rotate_picture(EVK,&theta,&phi);
  441.          else if ((keysym == XK_j) || (keysym == XK_J)) 
  442.             rotate_picture(EVJ,&theta,&phi);
  443.          else if ((keysym == XK_h) || (keysym == XK_H)) 
  444.             rotate_picture(EVH,&theta,&phi);
  445.          else if ((keysym == XK_o) || (keysym == XK_O)) 
  446.             rotate_picture(EVO,&theta,&phi);
  447.          else if ((keysym == XK_f) || (keysym == XK_F)) 
  448.             rotate_picture(EVF,&theta,&phi);
  449.          else if ((keysym == XK_d) || (keysym == XK_D)) 
  450.             rotate_picture(EVD,&theta,&phi);
  451.          else if ((keysym == XK_s) || (keysym == XK_S)) 
  452.             rotate_picture(EVS,&theta,&phi);
  453.          else if ((keysym == XK_a) || (keysym == XK_A)) 
  454.             rotate_picture(EVA,&theta,&phi);
  455.          else if ((keysym == XK_x) || (keysym == XK_X)) 
  456.             rotate_picture(EVX,&theta,&phi);
  457.          else if ((keysym == XK_y) || (keysym == XK_Y)) 
  458.             rotate_picture(EVY,&theta,&phi);
  459.          else if ((keysym == XK_z) || (keysym == XK_Z)) 
  460.             rotate_picture(EVZ,&theta,&phi);
  461.          break;
  462.       default:
  463.          break;
  464.       } /* end switch */
  465.    } /* end while */
  466. }
  467.  
  468. paint_button(win, mode, i,theta,phi)
  469. Window win;
  470. int    mode, i;
  471. double theta, phi;
  472. {
  473.    char *sprintf(), *strcpy();
  474.    GC   button_gc;
  475.    double theta0, phi0;
  476.  
  477.    if (mode == REVERSE) {
  478.       XSetWindowBackground(display,win,foreground_pixel); 
  479.       button_gc = bgc;
  480.    } else {
  481.       XSetWindowBackground(display,win,background_pixel); 
  482.       button_gc = bgcr;
  483.    }
  484.    /* clearing repaints the background */
  485.    XClearWindow(display,buttons[i]);
  486.  
  487.    /* assign button labels */
  488.    switch (i) {
  489.    case 0  : check_view_angles(&theta0,&phi0);
  490.              theta = (theta + theta0) * 180.0 / 3.14159;
  491.              while (theta > 360.0) theta -= 360.0;
  492.              while (theta < -0.01) theta += 360.0;
  493.              phi   = (phi + phi0)   * 180.0 / 3.14159;
  494.              while (phi   > 360.0) phi   -= 360.0;
  495.              while (phi   < -0.01) phi   += 360.0;
  496.              sprintf(button_label[i],
  497.                      "Quit :  Theta = %.3g   Phi = %.3g",theta,phi);
  498.              break;
  499.    case 1  : if (hiddenline) strcpy(button_label[i],"Hidden Lines"); 
  500.              else            strcpy(button_label[i],"Wire Frame"); 
  501.              break;
  502.    case 2  : strcpy(button_label[i],"Center"); break;
  503.    case 3  : strcpy(button_label[i],"Left"  ); break;
  504.    case 4  : strcpy(button_label[i],"Right" ); break;
  505.    case 5  : strcpy(button_label[i],"Up"    ); break;
  506.    case 6  : strcpy(button_label[i],"Down"  ); break;
  507.    default : fprintf(stderr,"Error! - Button %d has not been defined!\n",i);
  508.              strcpy(button_label[i],"");
  509.              break;
  510.    }
  511.    /*
  512.    printf("i = %d   label = %s\n",i,button_label[i]);
  513.    */
  514.  
  515.    /* draw text */
  516.    XDrawString(display,buttons[i],button_gc,
  517.                2,font_info->max_bounds.ascent,button_label[i],
  518.                strlen(button_label[i]));
  519. }
  520.  
  521. rotate_picture(mode,theta,phi)
  522. int mode;
  523. double *theta, *phi;
  524. {
  525.    double conv, theta0, phi0;
  526.  
  527.    conv = 3.14159/180.0;
  528.  
  529.    XClearWindow(display,vwwindow);
  530.    switch (mode) {
  531.    case EVL  : *theta = *theta + 10*conv;
  532.                read_view(*theta,*phi);
  533.                ShowView(*theta,*phi);
  534.                break;
  535.    case EVJ  : *phi = *phi - 10*conv;
  536.                read_view(*theta,*phi);
  537.                ShowView(*theta,*phi);
  538.                break;
  539.    case EVK  : *phi = *phi + 10*conv;
  540.                read_view(*theta,*phi);
  541.                ShowView(*theta,*phi);
  542.                break;
  543.    case EVH  : *theta = *theta - 10*conv;
  544.                read_view(*theta,*phi);
  545.                ShowView(*theta,*phi);
  546.                break;
  547.    case EVO  : *theta = 0.0;  *phi = 0.0;
  548.                read_view(*theta,*phi);
  549.                ShowView(*theta,*phi);
  550.                break;
  551.    case EVF  : *theta = *theta + 90*conv;
  552.                read_view(*theta,*phi);
  553.                ShowView(*theta,*phi);
  554.                break;
  555.    case EVS  : *phi = *phi - 90*conv;
  556.                read_view(*theta,*phi);
  557.                ShowView(*theta,*phi);
  558.                break;
  559.    case EVD  : *phi = *phi + 90*conv;
  560.                read_view(*theta,*phi);
  561.                ShowView(*theta,*phi);
  562.                break;
  563.    case EVA  : *theta = *theta - 90*conv;
  564.                read_view(*theta,*phi);
  565.                ShowView(*theta,*phi);
  566.                break;
  567.    case EVX  : check_view_angles(&theta0,&phi0);
  568.                *theta = -theta0 +  0*conv;
  569.                *phi   = -phi0   + 90*conv;
  570.                read_view(*theta,*phi);
  571.                ShowView(*theta,*phi);
  572.                break;
  573.    case EVY  : check_view_angles(&theta0,&phi0);
  574.                *theta = -theta0 + 90*conv;
  575.                *phi   = -phi0   + 90*conv;
  576.                read_view(*theta,*phi);
  577.                ShowView(*theta,*phi);
  578.                break;
  579.    case EVZ  : check_view_angles(&theta0,&phi0);
  580.                *theta = -theta0;
  581.                *phi = -phi0;
  582.                read_view(*theta,*phi);
  583.                ShowView(*theta,*phi);
  584.                break;
  585.    default   : read_view(*theta,*phi);
  586.                ShowView(*theta,*phi);
  587.                break;
  588.    }
  589. }
  590.   
  591.  
  592. ShowView(theta,phi)
  593. double theta,phi;
  594. {
  595.    int i;
  596.    for (i=0; i<NBUTTONS; i++)
  597.       paint_button(buttons[i],NORMAL,i,theta,phi);
  598.    back_axesX();
  599.    axesX();
  600.    plotX();
  601.    front_axesX();
  602. }
  603.  
  604. /* draw the toplabel and the z-axis */
  605. axesX()
  606. {
  607.    xyzdata  transform_point();
  608.    extern   double xmin, ymin, zmin, xmax, ymax, zmax;
  609.    int      text_len, text_width, text_xpos, text_ypos;
  610.    int      font_height, char_width;
  611.    xyzdata  point[4], newpt[4];
  612.    double   minx;
  613.    int      i, mini;
  614.  
  615.    /* Labels */
  616.    font_height = font_info->max_bounds.ascent +
  617.                  font_info->max_bounds.descent;
  618.  
  619.    /* Top Label */
  620.    text_len   = strlen(toplabel);
  621.    text_width = XTextWidth(font_info,toplabel,text_len);
  622.    text_xpos  = (Width - text_width)/2;
  623.    text_ypos  = Y_ORG + 2*B_HEIGHT + 2*font_height;
  624.    XDrawString(display,vwwindow,gc,text_xpos,text_ypos,toplabel,text_len);
  625.  
  626.    /*
  627.     * choose which z-axis to draw 
  628.     * There are 4 lines on the z-axis containing the 4 points below
  629.     */
  630.    point[0].x = xmin;   point[0].y = ymin;   point[0].z = zmin;
  631.    point[1].x = xmin;   point[1].y = ymax;   point[1].z = zmin;
  632.    point[2].x = xmax;   point[2].y = ymin;   point[2].z = zmin;
  633.    point[3].x = xmax;   point[3].y = ymax;   point[3].z = zmin;
  634.  
  635.    /* transform the 4 points */
  636.    for (i=0; i<4; i++) 
  637.       newpt[i] = transform_point(point[i],view_transfo);
  638.  
  639.    /*
  640.     * The line drawn will contain the smallest x-value of the
  641.     * 4 points decribed above (on the zplane)
  642.     */
  643.    minx = newpt[0].x; mini = 0;
  644.    for (i=0; i<4; i++)
  645.       if (newpt[i].x < minx) {
  646.          minx = newpt[i].x;
  647.          mini = i;
  648.       }
  649.  
  650.    /* draw the z-axis */
  651.    if (mini == 0)
  652.       draw_zaxis(xmin,ymin,zmin,xmin,ymin,zmax);
  653.    else if (mini == 1)
  654.       draw_zaxis(xmin,ymax,zmin,xmin,ymax,zmax);
  655.    else if (mini == 2)
  656.       draw_zaxis(xmax,ymin,zmin,xmax,ymin,zmax);
  657.    else if (mini == 3)
  658.       draw_zaxis(xmax,ymax,zmin,xmax,ymax,zmax);
  659. }
  660.  
  661. /* draw the axes that are further from the viewer */
  662. back_axesX()
  663. {
  664.    /* Draw the plane intersecting x-axis */
  665.    draw_back_xplane();
  666.  
  667.    /* Draw the plane intersecting y-axis */
  668.    draw_back_yplane();
  669.  
  670.    /* Draw the plane intersecting z-axis */
  671.    draw_back_zplane();
  672. }
  673.  
  674. /* draw the axes that are closer to the viewer */
  675. front_axesX()
  676. {
  677.    /* Draw the plane intersecting x-axis */
  678.    draw_front_xplane();
  679.  
  680.    /* Draw the plane intersecting y-axis */
  681.    draw_front_yplane();
  682.  
  683.    /* Draw the plane intersecting z-axis */
  684.    draw_front_zplane();
  685. }
  686.  
  687. /* Draw the axis - parallel to X */
  688. draw_xaxis(xa,ya,za,xb,yb,zb)
  689. double xa,ya,za,xb,yb,zb;
  690. {
  691.    xyzdata  midpoint();
  692.    xyzdata  transform_point();
  693.    char     *strcpy();
  694.    extern   double   xmin, ymin, zmin, xmax, ymax, zmax;
  695.    xyzdata  midpt;
  696.    int      text_len, text_width, text_xpos, text_ypos;
  697.    int      font_height, char_width;
  698.    int      i;
  699.    char     text[100];
  700.    double   xtmp, ratio, dl;
  701.  
  702.    /* 
  703.     * xa = xmin    xb = xmax
  704.     * ya = yb = (ymin ? ymax)
  705.     * za = zb = (zmin ? zmax)
  706.     */
  707.  
  708.    /* Labels */
  709.    font_height = font_info->max_bounds.ascent +
  710.                  font_info->max_bounds.descent;
  711.    char_width = XTextWidth(font_info,"a",1);
  712.  
  713.    /* midpoint of the line */
  714.    dl = (ya == ymin) ? -0.2*(ymax-ymin) : 0.2*(ymax-ymin);
  715.    midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
  716.  
  717.    /* X-Axis Label */
  718.    strcpy(text,xlabel);
  719.    text_len   = strlen(text);
  720.    text_width = XTextWidth(font_info,text,text_len);
  721.    text_xpos  = (int)(midpt.x) - char_width/2;
  722.    text_ypos  = Height - (int)(midpt.y) + 2*font_height;
  723.    XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
  724.  
  725.    /* Draw the tick marks */
  726.    dl    = 0.5*dl;
  727.    for (i=0; i<=xticks; i++) {
  728.       ratio = i/(double)xticks;
  729.       xtmp  = xa + (xb-xa)*ratio;
  730.       draw_Xline(xtmp,ya,za,xtmp,ya+dl,za,2);
  731.       midpt.x = xtmp;
  732.       midpt.y = ya+dl;
  733.       midpt.z = za;
  734.       midpt = transform_point(midpt,view_transfo);
  735.       sprintf(text,"%.3g",xtmp);
  736.       text_len   = strlen(text);
  737.       text_width = XTextWidth(font_info,text,text_len);
  738.       text_xpos  = (int)(midpt.x);
  739.       text_ypos  = Height - (int)(midpt.y) + 10;
  740.       XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
  741.    }
  742. }
  743.  
  744. /* Draw the axis - parallel to Y */
  745. draw_yaxis(xa,ya,za,xb,yb,zb)
  746. double xa,ya,za,xb,yb,zb;
  747. {
  748.    xyzdata  midpoint();
  749.    xyzdata  transform_point();
  750.    char     *strcpy();
  751.    extern   double   xmin, ymin, zmin, xmax, ymax, zmax;
  752.    xyzdata  midpt;
  753.    int      text_len, text_width, text_xpos, text_ypos;
  754.    int      font_height, char_width, i;
  755.    char     text[100];
  756.    double   ytmp, ratio, dl;
  757.  
  758.    /* 
  759.     * xa = xb = (xmin ? xmax)
  760.     * ya = ymin    yb = ymax 
  761.     * za = zb = (zmin ? zmax)
  762.     */
  763.  
  764.    /* Labels */
  765.    font_height = font_info->max_bounds.ascent +
  766.                  font_info->max_bounds.descent;
  767.    char_width = XTextWidth(font_info,"a",1);
  768.  
  769.    /* midpoint of the line */
  770.    dl = (xa == xmin) ? -0.2*(xmax-xmin) : 0.2*(xmax-xmin);
  771.    midpt = midpoint(xa+dl,ya,za,xb+dl,yb,zb,0.5);
  772.  
  773.    /* Y-Axis Label */
  774.    strcpy(text,ylabel);
  775.    text_len   = strlen(text);
  776.    text_width = XTextWidth(font_info,text,text_len);
  777.    text_xpos  = (int)(midpt.x) - char_width/2;
  778.    text_ypos  = Height - (int)(midpt.y) + 2*font_height;
  779.    XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
  780.  
  781.    /* Draw the tick marks */
  782.    dl    = 0.5*dl; 
  783.    for (i=0; i<=yticks; i++) {
  784.       ratio = i/(double)yticks;
  785.       ytmp  = ya + (yb-ya)*ratio;
  786.       draw_Xline(xa,ytmp,za,xa+dl,ytmp,za,2);
  787.       midpt.x = xa + dl;
  788.       midpt.y = ytmp;
  789.       midpt.z = za;
  790.       midpt = transform_point(midpt,view_transfo);
  791.       sprintf(text,"%.3g",ytmp);
  792.       text_len   = strlen(text);
  793.       text_width = XTextWidth(font_info,text,text_len);
  794.       text_xpos  = (int)(midpt.x) ;
  795.       text_ypos  = Height - (int)(midpt.y) + 10;
  796.       XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
  797.    }
  798. }
  799.  
  800. /* Draw the axis - parallel to Z */
  801. draw_zaxis(xa,ya,za,xb,yb,zb)
  802. double xa,ya,za,xb,yb,zb;
  803. {
  804.    xyzdata  midpoint();
  805.    xyzdata  transform_point();
  806.    char     *strcpy();
  807.    extern   double   xmin, ymin, zmin, xmax, ymax, zmax;
  808.    xyzdata  midpt;
  809.    int      text_len, text_width, text_xpos, text_ypos;
  810.    int      font_height, char_width, i;
  811.    char     text[100];
  812.    double   ztmp, ratio, dl;
  813.  
  814.    /* 
  815.     * xa = xb = (xmin ? xmax)
  816.     * ya = yb = (ymin ? ymax)
  817.     * za = zmin    zb = zmax
  818.     */
  819.  
  820.    /* Labels */
  821.    font_height = font_info->max_bounds.ascent +
  822.                  font_info->max_bounds.descent;
  823.    char_width = XTextWidth(font_info,"a",1);
  824.  
  825.    /* midpoint of the line */
  826.    dl = (ya == ymin) ? -0.2*(ymax-ymin) : 0.2*(ymax-ymin);
  827.    midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
  828.  
  829.    /* Z-Axis Label */
  830.    strcpy(text,zlabel);
  831.    text_len   = strlen(text);
  832.    text_width = XTextWidth(font_info,text,text_len);
  833.    text_xpos  = (int)(midpt.x) - char_width/2;
  834.    text_ypos  = Height - (int)(midpt.y) + 2*font_height;
  835.    XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
  836.  
  837.    /* Draw the tick marks */
  838.    dl    = 0.5*dl; 
  839.    for (i=0; i<=zticks; i++) {
  840.       ratio = i/(double)zticks;
  841.       ztmp  = za + (zb-za)*ratio;
  842.       draw_Xline(xa,ya,ztmp,xa,ya+dl,ztmp,2);
  843.       midpt.x = xa;
  844.       midpt.y = ya+dl;
  845.       midpt.z = ztmp;
  846.       midpt = transform_point(midpt,view_transfo);
  847.       sprintf(text,"%.3g",ztmp);
  848.       text_len   = strlen(text);
  849.       text_width = XTextWidth(font_info,text,text_len);
  850.       text_xpos  = (int)(midpt.x) - (int)(1.5*text_width);
  851.       text_ypos  = Height - (int)(midpt.y) - 20;
  852.       XDrawString(display,vwwindow,gc,text_xpos,text_ypos,text,text_len);
  853.    }
  854. }
  855.  
  856. /* draw the back x-plane */
  857. draw_back_xplane()
  858. {
  859.    xyzdata transform_point();
  860.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  861.    xyzdata point1, point2, point[5], newpt;
  862.    XPoint  xpoint[5];
  863.    int     i;
  864.  
  865.    /* 2 planes intersecting the x-axis */
  866.    point1.x = xmin + 0.0*(xmax-xmin);
  867.    point1.y = ymin + 0.5*(ymax-ymin);
  868.    point1.z = zmin + 0.5*(zmax-zmin);
  869.    point1   = transform_point(point1,view_transfo);
  870.    point2.x = xmin + 1.0*(xmax-xmin);
  871.    point2.y = ymin + 0.5*(ymax-ymin);
  872.    point2.z = zmin + 0.5*(zmax-zmin);
  873.    point2   = transform_point(point2,view_transfo);
  874.  
  875.    if (point1.z > point2.z) {
  876.       /* draw the lesser - point2 contains xmax */
  877.       point[0].x = xmax;  point[0].y = ymin;  point[0].z = zmin;
  878.       point[1].x = xmax;  point[1].y = ymin;  point[1].z = zmax;
  879.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  880.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  881.       /* repeat point 1 */
  882.       point[4].x = xmax;  point[4].y = ymin;  point[4].z = zmin;
  883.    } else {
  884.       /* draw the lesser - point1 contains xmin */
  885.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  886.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  887.       point[2].x = xmin;  point[2].y = ymax;  point[2].z = zmax;
  888.       point[3].x = xmin;  point[3].y = ymax;  point[3].z = zmin;
  889.       /* repeat point 1 */
  890.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  891.    }
  892.  
  893.    /* rescale the points */
  894.    for (i=0; i<5; i++) {
  895.       newpt = transform_point(point[i],view_transfo);
  896.       xpoint[i].x = (int)newpt.x;
  897.       xpoint[i].y = Height - (int)newpt.y;
  898.    }
  899.  
  900.    XSetForeground(display,gc,colors[BACK2_C]);
  901.    XFillPolygon(display,vwwindow,gc,xpoint,5,
  902.                          Convex,CoordModeOrigin);
  903.    XSetForeground(display,gc,foreground_pixel);
  904.    XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
  905.    XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
  906. }
  907.  
  908. /* draw the back y-plane */
  909. draw_back_yplane()
  910. {
  911.    xyzdata transform_point();
  912.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  913.    xyzdata point1, point2, point[5], newpt;
  914.    XPoint  xpoint[5];
  915.    int     i;
  916.  
  917.    /* 2 planes intersecting the x-axis */
  918.    point1.x = xmin + 0.5*(xmax-xmin);
  919.    point1.y = ymin + 0.0*(ymax-ymin);
  920.    point1.z = zmin + 0.5*(zmax-zmin);
  921.    point1   = transform_point(point1,view_transfo);
  922.    point2.x = xmin + 0.5*(xmax-xmin);
  923.    point2.y = ymin + 1.0*(ymax-ymin);
  924.    point2.z = zmin + 0.5*(zmax-zmin);
  925.    point2   = transform_point(point2,view_transfo);
  926.  
  927.    if (point1.z > point2.z) {
  928.       /* draw the lesser - point2 contains ymax */
  929.       point[0].x = xmin;  point[0].y = ymax;  point[0].z = zmin;
  930.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  931.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  932.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  933.       /* repeat point 1 */
  934.       point[4].x = xmin;  point[4].y = ymax;  point[4].z = zmin;
  935.    } else {
  936.       /* draw the lesser - point1 contains ymin */
  937.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  938.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  939.       point[2].x = xmax;  point[2].y = ymin;  point[2].z = zmax;
  940.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  941.       /* repeat point 1 */
  942.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  943.    }
  944.  
  945.    /* rescale the points */
  946.    for (i=0; i<5; i++) {
  947.       newpt = transform_point(point[i],view_transfo);
  948.       xpoint[i].x = (int)newpt.x;
  949.       xpoint[i].y = Height - (int)newpt.y;
  950.    }
  951.  
  952.    XSetForeground(display,gc,colors[BACK2_C]);
  953.    XFillPolygon(display,vwwindow,gc,xpoint,5,
  954.                          Convex,CoordModeOrigin);
  955.    XSetForeground(display,gc,foreground_pixel);
  956.    XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
  957.    XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
  958. }
  959.  
  960. /* draw the back z-plane */
  961. draw_back_zplane()
  962. {
  963.    xyzdata transform_point();
  964.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  965.    xyzdata point1, point2, point[5], newpt;
  966.    XPoint  xpoint[5];
  967.    double  ztmp, maxy;
  968.    int     i, maxi;
  969.  
  970.    /* 2 planes intersecting the z-axis */
  971.    point1.x = xmin + 0.5*(xmax-xmin);
  972.    point1.y = ymin + 0.5*(ymax-ymin);
  973.    point1.z = zmin + 0.0*(zmax-zmin);
  974.    point1   = transform_point(point1,view_transfo);
  975.    point2.x = xmin + 0.5*(xmax-xmin);
  976.    point2.y = ymin + 0.5*(ymax-ymin);
  977.    point2.z = zmin + 1.0*(zmax-zmin);
  978.    point2   = transform_point(point2,view_transfo);
  979.  
  980.    if (point1.z > point2.z) {
  981.       /* draw the lesser - point2 contains zmax */
  982.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmax;
  983.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  984.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  985.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmax;
  986.       /* repeat point 1 */
  987.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmax;
  988.    } else {
  989.       /* draw the lesser - point1 contains zmin */
  990.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  991.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmin;
  992.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmin;
  993.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  994.       /* repeat point 1 */
  995.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  996.    }
  997.  
  998.    /* rescale the points */
  999.    for (i=0; i<5; i++) {
  1000.       newpt = transform_point(point[i],view_transfo);
  1001.       xpoint[i].x = (int)newpt.x;
  1002.       xpoint[i].y = Height - (int)newpt.y;
  1003.    }
  1004.  
  1005.    XSetForeground(display,gc,colors[BACK2_C]);
  1006.    XFillPolygon(display,vwwindow,gc,xpoint,5,
  1007.                          Convex,CoordModeOrigin);
  1008.    XSetForeground(display,gc,foreground_pixel);
  1009.    XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
  1010.    XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
  1011.  
  1012.    /*
  1013.     * The line drawn will contain the largest y-value of the
  1014.     * 4 points on the z-plane
  1015.     */
  1016.    maxy = xpoint[0].y; maxi = 0;
  1017.    for (i=0; i<4; i++)
  1018.       if (xpoint[i].y > maxy) {
  1019.          maxy = xpoint[i].y;
  1020.          maxi = i;
  1021.       }
  1022.    ztmp = (point1.z > point2.z) ? zmax : zmin;
  1023.  
  1024.    /* draw the x-axis first */
  1025.    if (maxi == 0 || maxi == 3)
  1026.       draw_xaxis(xmin,ymin,ztmp,xmax,ymin,ztmp);
  1027.    else if (maxi == 1 || maxi == 2)
  1028.       draw_xaxis(xmin,ymax,ztmp,xmax,ymax,ztmp);
  1029.  
  1030.    /* draw the y-axis first */
  1031.    if (maxi == 0 || maxi == 1)
  1032.       draw_yaxis(xmin,ymin,ztmp,xmin,ymax,ztmp);
  1033.    else if (maxi == 2 || maxi == 3)
  1034.       draw_yaxis(xmax,ymin,ztmp,xmax,ymax,ztmp);
  1035. }
  1036.  
  1037. /* draw the front x-plane */
  1038. draw_front_xplane()
  1039. {
  1040.    xyzdata transform_point();
  1041.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  1042.    xyzdata point1, point2, point[5], newpt;
  1043.    XPoint  xpoint[5];
  1044.    int     i;
  1045.  
  1046.    /* 2 planes intersecting the x-axis */
  1047.    point1.x = xmin + 0.0*(xmax-xmin);
  1048.    point1.y = ymin + 0.5*(ymax-ymin);
  1049.    point1.z = zmin + 0.5*(zmax-zmin);
  1050.    point1   = transform_point(point1,view_transfo);
  1051.    point2.x = xmin + 1.0*(xmax-xmin);
  1052.    point2.y = ymin + 0.5*(ymax-ymin);
  1053.    point2.z = zmin + 0.5*(zmax-zmin);
  1054.    point2   = transform_point(point2,view_transfo);
  1055.  
  1056.    if (point1.z < point2.z) {
  1057.       /* draw the greater - point2 contains xmax */
  1058.       point[0].x = xmax;  point[0].y = ymin;  point[0].z = zmin;
  1059.       point[1].x = xmax;  point[1].y = ymin;  point[1].z = zmax;
  1060.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  1061.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  1062.       /* repeat point 1 */
  1063.       point[4].x = xmax;  point[4].y = ymin;  point[4].z = zmin;
  1064.    } else {
  1065.       /* draw the greater - point1 contains xmin */
  1066.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  1067.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  1068.       point[2].x = xmin;  point[2].y = ymax;  point[2].z = zmax;
  1069.       point[3].x = xmin;  point[3].y = ymax;  point[3].z = zmin;
  1070.       /* repeat point 1 */
  1071.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  1072.    }
  1073.  
  1074.    /* rescale the points */
  1075.    for (i=0; i<5; i++) {
  1076.       newpt = transform_point(point[i],view_transfo);
  1077.       xpoint[i].x = (int)newpt.x;
  1078.       xpoint[i].y = Height - (int)newpt.y;
  1079.    }
  1080.  
  1081.    XSetForeground(display,gc,foreground_pixel);
  1082.    XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
  1083.    XSetDashes(display,gc,0,dash_list_dashed,DASHED);
  1084.    XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
  1085.    XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
  1086. }
  1087.  
  1088. /* draw the front y-plane */
  1089. draw_front_yplane()
  1090. {
  1091.    xyzdata transform_point();
  1092.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  1093.    xyzdata point1, point2, point[5], newpt;
  1094.    XPoint  xpoint[5];
  1095.    int     i;
  1096.  
  1097.    /* 2 planes intersecting the x-axis */
  1098.    point1.x = xmin + 0.5*(xmax-xmin);
  1099.    point1.y = ymin + 0.0*(ymax-ymin);
  1100.    point1.z = zmin + 0.5*(zmax-zmin);
  1101.    point1   = transform_point(point1,view_transfo);
  1102.    point2.x = xmin + 0.5*(xmax-xmin);
  1103.    point2.y = ymin + 1.0*(ymax-ymin);
  1104.    point2.z = zmin + 0.5*(zmax-zmin);
  1105.    point2   = transform_point(point2,view_transfo);
  1106.  
  1107.    if (point1.z < point2.z) {
  1108.       /* draw the greater - point2 contains ymax */
  1109.       point[0].x = xmin;  point[0].y = ymax;  point[0].z = zmin;
  1110.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  1111.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  1112.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  1113.       /* repeat point 1 */
  1114.       point[4].x = xmin;  point[4].y = ymax;  point[4].z = zmin;
  1115.    } else {
  1116.       /* draw the greater - point1 contains ymin */
  1117.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  1118.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  1119.       point[2].x = xmax;  point[2].y = ymin;  point[2].z = zmax;
  1120.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  1121.       /* repeat point 1 */
  1122.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  1123.    }
  1124.  
  1125.    /* rescale the points */
  1126.    for (i=0; i<5; i++) {
  1127.       newpt = transform_point(point[i],view_transfo);
  1128.       xpoint[i].x = (int)newpt.x;
  1129.       xpoint[i].y = Height - (int)newpt.y;
  1130.    }
  1131.  
  1132.    XSetForeground(display,gc,foreground_pixel);
  1133.    XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
  1134.    XSetDashes(display,gc,0,dash_list_dashed,DASHED);
  1135.    XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
  1136.    XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
  1137. }
  1138.  
  1139. /* draw the front z-plane */
  1140. draw_front_zplane()
  1141. {
  1142.    xyzdata transform_point();
  1143.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  1144.    xyzdata point1, point2, point[5], newpt;
  1145.    XPoint  xpoint[5];
  1146.    int     i;
  1147.  
  1148.    /* 2 planes intersecting the z-axis */
  1149.    point1.x = xmin + 0.5*(xmax-xmin);
  1150.    point1.y = ymin + 0.5*(ymax-ymin);
  1151.    point1.z = zmin + 0.0*(zmax-zmin);
  1152.    point1   = transform_point(point1,view_transfo);
  1153.    point2.x = xmin + 0.5*(xmax-xmin);
  1154.    point2.y = ymin + 0.5*(ymax-ymin);
  1155.    point2.z = zmin + 1.0*(zmax-zmin);
  1156.    point2   = transform_point(point2,view_transfo);
  1157.  
  1158.    if (point1.z < point2.z) {
  1159.       /* draw the greater - point2 contains zmax */
  1160.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmax;
  1161.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  1162.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  1163.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmax;
  1164.       /* repeat point 1 */
  1165.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmax;
  1166.    } else {
  1167.       /* draw the greater - point1 contains zmin */
  1168.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  1169.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmin;
  1170.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmin;
  1171.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  1172.       /* repeat point 1 */
  1173.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  1174.    }
  1175.  
  1176.    /* rescale the points */
  1177.    for (i=0; i<5; i++) {
  1178.       newpt = transform_point(point[i],view_transfo);
  1179.       xpoint[i].x = (int)newpt.x;
  1180.       xpoint[i].y = Height - (int)newpt.y;
  1181.    }
  1182.  
  1183.    XSetForeground(display,gc,foreground_pixel);
  1184.    XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
  1185.    XSetDashes(display,gc,0,dash_list_dashed,DASHED);
  1186.    XDrawLines(display,vwwindow,gc,xpoint,5,CoordModeOrigin);
  1187.    XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
  1188. }
  1189.  
  1190. draw_Xline(x1, y1, z1, x2, y2, z2, ithk)
  1191. double x1, y1, z1, x2, y2, z2;
  1192. int ithk;
  1193. {
  1194.    xyzdata point1, point2, newpt1, newpt2;
  1195.    xyzdata transform_point();
  1196.    int     ix1, iy1, ix2, iy2;
  1197.  
  1198.    point1.x = x1;
  1199.    point1.y = y1;
  1200.    point1.z = z1;
  1201.  
  1202.    point2.x = x2;
  1203.    point2.y = y2;
  1204.    point2.z = z2;
  1205.  
  1206.    newpt1 = transform_point(point1,view_transfo);
  1207.    newpt2 = transform_point(point2,view_transfo);
  1208.  
  1209.    ix1 = (int)newpt1.x;
  1210.    iy1 = Height-(int)newpt1.y;
  1211.    ix2 = (int)newpt2.x;
  1212.    iy2 = Height-(int)newpt2.y;
  1213.  
  1214.    /* draw the line */
  1215.    XSetLineAttributes(display,gc,ithk,LineSolid,CapButt,JoinBevel);
  1216.    XDrawLine(display,vwwindow,gc,ix1,iy1,ix2,iy2);
  1217. }
  1218.  
  1219. /* draw the plot */
  1220. plotX()
  1221. {
  1222.    xyzdata transform_point();
  1223.  
  1224.    extern double  xmin, ymin, zmin, xmax, ymax, zmax;
  1225.    extern int     hiddenline, quick_sort;
  1226.    extern segmptr segmhead;
  1227.  
  1228.    XPoint  points[MAXPTS];
  1229.    segmptr S;
  1230.    nodeptr Nd;
  1231.    int     j,npts;
  1232.    xyzdata point, newpt;
  1233.  
  1234.    /* reset the line attributes n*/
  1235.    XSetLineAttributes(display,gc,0,LineSolid,CapButt,JoinBevel);
  1236.  
  1237.    /* now draw the plot */
  1238.    if (hiddenline==ON) {
  1239.       /* sort the mesh */
  1240.       if (quick_sort)
  1241.          do_quick_sort();
  1242.       else 
  1243.          bubble_sort();
  1244.    }
  1245.  
  1246.    S  = segmhead;
  1247.    for ( ; S!=NULL; S=S->next) {
  1248.       /* rescale points */
  1249.       j = 0;
  1250.       for (Nd=S->head; Nd!=NULL; Nd=Nd->next) {
  1251.          point.x = Nd->x;
  1252.          point.y = Nd->y;
  1253.          point.z = Nd->z;
  1254.          newpt = transform_point(point,view_transfo);
  1255.          points[j].x = (int)newpt.x;
  1256.          points[j].y = Height - (int)newpt.y;
  1257.          j++;
  1258.       }
  1259.       npts = j;
  1260.  
  1261.       /* plot the points */
  1262.       if (line == ON) {
  1263.          if (hiddenline == ON) {
  1264.             XSetForeground(display,gc,colors[LINE2_C]); 
  1265.             XFillPolygon(display,vwwindow,gc,points,npts,
  1266.                          Complex,CoordModeOrigin);
  1267.          }
  1268.          XSetForeground(display,gc,colors[LINE1_C]); 
  1269.          XDrawLines(display,vwwindow,gc,points,npts,CoordModeOrigin);
  1270.       }
  1271.    }
  1272.  
  1273.    /* reset the color */
  1274.    XSetForeground(display,gc,foreground_pixel); 
  1275. }
  1276.  
  1277.