⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x11u.c

📁 这是著名FEAP(Finite Element Analysis Program)程序的低版本(FEAP源代码没找到)
💻 C
📖 第 1 页 / 共 3 页
字号:
       /******************************/

static void gdx11_flush(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  gdx11_term_polyline(dw);
  gdx11_refresh_digwin(dw);
  XFlush(dw->xdisplay);
}

       /***********************/
       /* 6. - RELEASE DEVICE */
       /***********************/

static void gdx11_release_device(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  /*
   *  This routine should really close out the window system,
   *  but we want to be able to get back to this same device if
   *  it gets reopened.  So just leave the window around and don't
   *  clear it.
   */
  return;
}

       /**************************************/
       /* 7. - RETURN DEVICE CHARACTERISTICS */
       /**************************************/

static void gdx11_return_device(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  (*x_data)[0] = 11.0;                      /* Nonzero device ID */
  if (dw!=NULL && dw->xwin != ((Window)NULL) )
    {
      (*x_data)[1] = dw->x_len/dw->x_scale; /* X Length in cm. */
      (*x_data)[2] = dw->y_len/dw->y_scale; /* Y Length in cm. */
      (*x_data)[3] = dw->x_scale;           /* X pixels per cm */
      (*x_data)[4] = dw->y_scale;           /* Y pixels per cm */
      (*x_data)[5] = dw->num_fg_colors;     /* Number of foreground colors */
    }
  else
    {
      (*x_data)[1] = 0.001;                 /* X Length in cm. */
      (*x_data)[2] = 0.001;                 /* Y Length in cm. */
      (*x_data)[3] = 1.0;                   /* X pixels per cm */
      (*x_data)[4] = 1.0;                   /* Y pixels per cm */
      (*x_data)[5] = 1.0;                   /* Number of foreground colors */
    }
  (*x_data)[6] = RASTER_DEVICE+CAN_DRAW_IN_BACKGROUND+
    CAN_DO_GIN+CAN_DRAW_FILLED_POLYGONS+
      CAN_DO_LOCATOR_INPUT;                 /* FEAP device capabilities */
  (*x_data)[7] = 1.0;                       /* Fill every line */
  return;
}

       /******************************/
       /* 8. - SELECT PLOTTING COLOR */
       /******************************/

static void gdx11_select_color(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  int new_pv = (int) (*x_data)[0];

  /* Set gray scale for monochrome monitors */
  if (dw->num_fg_colors == 1) {
       switch (new_pv) {
            case 0:
              dw->current_gray_value = 0;
              break;
            case 2:
              dw->current_gray_value = 1;
              break;
            case 7:
              dw->current_gray_value = 2;
              break;
            case 3:
              dw->current_gray_value = 3;
              break;
            case 5:
              dw->current_gray_value = 4;
              break;
            case 4:
              dw->current_gray_value = 5;
              break;
            case 6:
              dw->current_gray_value = 6;
              break;
            case 1:
              dw->current_gray_value = 7;
              break;
        }

       new_pv = (new_pv > 1) ? 1 : new_pv;

     }

     if (new_pv>=0 && new_pv<=dw->num_fg_colors &&
        (new_pv = dw->pixel_value_for_color[new_pv])
        !=dw->current_pixel_value)
      {
        gdx11_term_polyline(dw);
        dw->current_pixel_value = new_pv;
      }
}

static void gdx11_get_input(dw,cursor,allow_keys,left,middle,right,
                            press,x,y)
     DIGWin *dw;
     Cursor cursor;
     int allow_keys, left, middle, right;
     int *press, *x, *y;
{
  Display *disp = dw->xdisplay;
  Window w = dw->xwin;
  XEvent event;
  long int event_mask = (ButtonPressMask|ExposureMask|StructureNotifyMask|
                         KeyPressMask);
  int no_button = 1;

  /* First, toss all events on this window already in the queue */
  while (XCheckWindowEvent(disp,w,event_mask,&event))
    gdx11_handle_digwin_event(dw,&event,0,0);


  /* Put up cursor to signal we want input */
  XDefineCursor(disp,w,cursor);

  /* Now look for GIN event */
  while(no_button)
    {
      XWindowEvent(disp,w,event_mask,&event);
      switch((int)event.type)
        {
        case KeyPress:
          {
            XKeyEvent *key_event = (XKeyEvent *)(&event);
            int length;
            char buf[8];
            KeySym ks;

            /* Get the key pressed! */
            length = XLookupString(key_event,buf,8,&ks,&lookup_status);
            if (length>0)
              {
                *press = buf[0];
                *x = key_event->x;
                *y = key_event->y;
                no_button = 0;
              }
            break;
          }
        case ButtonPress:
          {
            XButtonEvent *DiglibEvent = (XButtonEvent *)(&event);

            if (DiglibEvent->button == Button3)
              *press = BUTTON3_KEY;
            else if (DiglibEvent->button == Button2)
              *press = BUTTON2_KEY;
            else if (DiglibEvent->button == Button1)
              *press = BUTTON1_KEY;
            else
              *press = 0;
            *x = DiglibEvent->x;
            *y = DiglibEvent->y;
            no_button = 0;
          }
        default:
          gdx11_handle_digwin_event(dw,&event,0,0);
          break;
        }
    }
  /* Remove cross_hair_cursor */
  XUndefineCursor(disp,w);
}

       /**********************/
       /* 9. - GET GIN INPUT */
       /**********************/

static Cursor gin_cursor;
static int have_gin_cursor = 0;

static void gdx11_gin(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  int key;
  int x,y;

  /* Make sure we have a cross hair cursor */
  if (!have_gin_cursor)
    {
      gin_cursor = XCreateFontCursor(dw->xdisplay,XC_crosshair);
      have_gin_cursor = 1;
    }

  gdx11_get_input(dw,gin_cursor,1,BUTTON1_KEY,BUTTON2_KEY,BUTTON3_KEY,
                  &key,&x,&y);
  (*x_data)[0] = key;
  (*x_data)[1] = x_untranslate(dw,x);
  (*x_data)[2] = y_untranslate(dw,y);
}

       /********************************/
       /* 10. - DEFINE COLOR USING RGB */
       /********************************/

/* Not yet implemented */
/* Because colors are allocated READ-ONLY, this will take some work! */
static void gdx11_set_color_map_rgb(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
/*  int color_index = (*x_data)[0]; */
}

       /********************************/
       /* 11. - DEFINE COLOR USING HLS */
       /********************************/

/* Not yet implemented, probably never will be */
static void gdx11_set_color_map_hls( op_code, x_data, y_data )
     int   *op_code;
     float (* x_data)[], (* y_data)[];
{
}

       /***************************/
       /* 12. - GET LOCATOR INPUT */
       /***************************/

static Cursor locator_cursor;
static int have_locator_cursor = 0;

static void gdx11_button_input(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  int button;
  int x,y;

  /* Make sure we have a cross hair cursor */
  if (!have_locator_cursor)
    {
      locator_cursor = XCreateFontCursor(dw->xdisplay,XC_diamond_cross);
      have_locator_cursor = 1;
    }

  gdx11_get_input(dw,locator_cursor,0,1,2,4,&button,&x,&y);
  (*x_data)[0] = button;
  (*x_data)[1] = x_untranslate(dw,x);
  (*x_data)[2] = y_untranslate(dw,y);
}

       /*****************************/
       /*  13. - SET LINE STYLE     */
       /*****************************/
/*  Added by RLT on 1/22/93  */
static void gdx11_set_line (dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  unsigned int line_width;
  int          line_style;
  int          cap_style;
  int          join_style;
  int new_ln = (int) (*x_data)[0];
  int new_wd = (int) (*y_data)[0];

  /* Change GC for this window */

  XGCValues setgc;

  /* First flush buffer with any current events */

  gdx11_term_polyline(dw);
  gdx11_refresh_digwin(dw);

  XFlush(dw->xdisplay);

  gdx11_init_polylines(dw);
  gdx11_init_strings(dw);

  setgc.foreground = dw->pixel_value_for_color[1];
  setgc.background = dw->pixel_value_for_color[0];
  setgc.function = GXcopy;

  if  (new_ln <= 1)
      line_style = LineSolid;
  else if (new_ln == 2)
      line_style = LineOnOffDash;
  else
      line_style = LineDoubleDash;

  setgc.fill_style = FillSolid;

  if  (new_wd <= 1)
      line_width = 0;
  else if (new_wd == 2)
      line_width = 1;
  else if (new_wd == 3)
      line_width = 2;
  else if (new_wd == 4)
      line_width = 3;
  else
      line_width = 4;

  join_style = JoinMiter;
  cap_style  = CapButt;

  XSetLineAttributes( dw->xdisplay, dw->xgc, line_width, line_style,
                      cap_style, join_style);

  /* Monochrome gray scale stuff */

  if(dw->num_fg_colors == 1){
       XSetLineAttributes( dw->xdisplay, dw->xgc, line_width, line_style,
                           cap_style, join_style);
       XSetFillStyle(dw->xdisplay,dw->xgc_mono_fill,FillOpaqueStippled);
  }
}
       /*************************/
       /* 14. - Set Clip Window */
       /*************************/

static void gdx11_clip_mask(dw,x_data,y_data)
  DIGWin *dw;
  float (* x_data)[], (* y_data)[];
{
  register int new_x;
  XRectangle rectangles[1];
  int clip_x_origin, clip_y_origin;
  int nrects;
  int ordering;

  new_x = x_translate(dw,(*x_data)[2]);
  if (new_x == 0)
    XSetClipMask( dw->xdisplay, dw->xgc, None );
  else {
    clip_x_origin = x_translate(dw,(*x_data)[0]);
    clip_y_origin = y_translate(dw,(*y_data)[0]);
    rectangles->x = clip_x_origin;
    rectangles->y = clip_y_origin;
    rectangles->width  = x_translate(dw,(*x_data)[1]);
    rectangles->height = y_translate(dw,(*y_data)[1]);
    nrects = 1;
    ordering = Unsorted;
    XSetClipRectangles(dw->xdisplay, dw->xgc, clip_x_origin,
                       clip_y_origin, rectangles, nrects, ordering );

  }
}
       /**************************************/
       /*  MAX_OPCODE-1 - DRAW TEXT STRING   */
       /**************************************/

static void gdx11_draw_text(dw,n,x_data,y_data)
     DIGWin *dw;
     int n ;
     float (* x_data)[], (* y_data)[];
{
  int i ;
  dw->textx[dw->nstrings] = x_translate(dw,(*x_data)[0]);
  dw->texty[dw->nstrings] = y_translate(dw,(*y_data)[0]);
  dw->strflg[dw->nstrings] = (int)(*y_data)[1];
  dw->strlen[dw->nstrings] = n;
  for ( i = 1; i <= n; ++i)
    dw->strings[dw->nstrings*80+i-1]=(int)(*x_data)[i];

/* prepare for next text string */
  ++dw->nstrings;
  if(dw->nstrings==MAX_TEXT) {
    gdx11_refresh_digwin(dw);
    dw->nstrings = 0;
  }
}

       /************************************/
       /* MAX_OPCODE - DRAW FILLED POLYGON */
       /************************************/

static void gdx11_draw_polygon(dw,n,x_data,y_data)
     DIGWin *dw;
     int n;
     float (* x_data)[], (* y_data)[];
{
  int    i;
/*  Display *disp = dw->xdisplay;*/

  dw->current_x = x_translate(dw,(*x_data)[n-1]);
  dw->current_y = y_translate(dw,(*y_data)[n-1]);
  gdx11_start_polygon(dw,n+1,dw->current_x,dw->current_y);
  for ( i = 0; i < n; ++i)
    gdx11_add_point_to_polyline(dw,x_translate(dw,(*x_data)[i]),
                                y_translate(dw,(*y_data)[i]));
  gdx11_end_polygon(dw);
}

       /*********************/
       /* X11 DEVICE DRIVER */
       /*********************/

/* FORTRAN Interace */

/* HP  and IBM use :
void gdx11( op_code, x_data, y_data )
 */
/* SUN and DEC use :
 */
void gdx11_( op_code, x_data, y_data )
     int    *op_code;        /* holds device independent op-code */
     float  (* x_data)[];    /* x coordinate data */
     float  (* y_data)[];    /* y coordinate data */
{
  /* An array of pointers to function */
  /*  i.e. a jump table that is global to this compilation unit */

  static void (* jump_table[MAX_OPCODE])() =
    {
      gdx11_init_device,           /*  1 = initialize new device */
      gdx11_clear_page,            /*  2 = erase the window      */
      gdx11_move_to,               /*  3 = move - no draw        */
      gdx11_draw_to,               /*  4 = draw - draw line      */
      gdx11_flush,                 /*  5 = flush buffer          */
      gdx11_release_device,        /*  6 = release device = NULL */
      gdx11_return_device,         /*  7 = return device feature */
      gdx11_select_color,          /*  8 = select colors         */
      gdx11_gin,                   /*  9 = gin input selection   */
      gdx11_set_color_map_rgb,     /* 10 = RGB color map = NULL  */
      gdx11_set_color_map_hls,     /* 11 = HLS color map = NULL  */
      gdx11_button_input,          /* 12 = locator input w/mouse */
      gdx11_set_line,              /* 13 = set line style        */
      gdx11_clip_mask,             /* 14 = set clip region       */
      gdx11_draw_text,             /* MAX_OP - 1 = draw text     */
      gdx11_draw_polygon           /* MAX_OP     = polygon fill  */
      };                           /*      MAX_OPCODE = 15       */

  if (DEBUG>=3) fprintf(stderr,"FEAP-X11 called, op_code = %d\n",*op_code);
  /* Check for correct op-code, and run */
  if (*op_code > 1024)
    jump_table[MAX_OPCODE-1](current_dw,*op_code-1024,x_data,y_data);
  else if (*op_code < -1024)
    jump_table[MAX_OPCODE-2](current_dw,-*op_code-1024,x_data,y_data);
  else if ((0 <= *op_code) && (*op_code <= MAX_OPCODE-1))
    jump_table[*op_code-1](current_dw,x_data,y_data);
  if (DEBUG>=3) fprintf(stderr,"FEAP-X11 done with op_code = %d\n",*op_code);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -