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 / plotNOX.c < prev    next >
Text File  |  1992-01-15  |  42KB  |  1,320 lines

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