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

📄 x11u.c

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

  gdx11_adjust_digwin(dw);
  return(dw);
}

       /****************************************/
       /* Create a FEAP XWindow from scratch */
       /****************************************/

DIGWin *gdx11_create_digwin(xservername,window_width,window_height)
     char *xservername ;
     int window_width, window_height;
{
  Display *disp;
  Window xwin;
  Screen *def_screen;
  Colormap cmap;
  XColor screen_def, exact_def;
  XSetWindowAttributes setwin;
/*  XGCValues setgc; */
  XSizeHints size_hints;
  XEvent event;
  DIGWin *dw;
  unsigned long background_pixel, foreground_pixel;

/* Window Location on Screen */

  if (!(disp = XOpenDisplay(xservername)))
    {
      fprintf(stderr,
              "FEAP X11 Driver unable to open X windows connection.\n");
      exit(0);
    }
  if (DEBUG>=4)
    fprintf(stderr,"gdx11_init_device: Inform : X Display opened\n");

  /* Get screen for window */
  def_screen = DefaultScreenOfDisplay(disp);

  /* Get colors straight */
  cmap = DefaultColormapOfScreen(def_screen);
  if (XAllocNamedColor(disp,cmap,"BLACK",&screen_def,&exact_def))
    background_pixel = screen_def.pixel;
  else
    background_pixel = BlackPixelOfScreen(def_screen);
  if (XAllocNamedColor(disp,cmap,"WHITE",&screen_def,&exact_def))
    foreground_pixel = screen_def.pixel;
  else
    foreground_pixel = WhitePixelOfScreen(def_screen);

  /* Setup gray scale masks */

  /* Create an Xwindow */
  setwin.event_mask = (ButtonPressMask|ExposureMask|StructureNotifyMask|
                       KeyPressMask);
  setwin.background_pixel = background_pixel;
  setwin.backing_store    = Always;
  xwin = XCreateWindow(disp,
                       RootWindowOfScreen(def_screen),
                       DEFAULT_X,DEFAULT_Y,
                       window_width,window_height,
                       4,
                       DefaultDepthOfScreen(def_screen),
                       InputOutput,
                       DefaultVisualOfScreen(def_screen),
                       (CWBackPixel|CWEventMask|CWBackingStore),
                       &setwin);

  /* Map the window onto the display */
  size_hints.x      = 0             ;
  size_hints.y      = 0             ;
  size_hints.width  = window_width  ;
  size_hints.height = window_height ;
  size_hints.min_width  = 20;
  size_hints.min_height = 20;
  size_hints.flags = USPosition|PSize|PMinSize;
  XSetStandardProperties(disp,xwin,"FEAP Graphics Window","FEAP Win",
                         None,0,0,&size_hints);
  XMapWindow(disp,xwin);

  /* Wait for exposure event before proceeding - otherwise, some */
  /*  drawing command might get tossed                           */
  XWindowEvent(disp,xwin,ExposureMask,&event);

  /* Now turn the XWindow into a FEAP XWindow */
  dw = gdx11_make_digwin_from_xwin(disp,xwin,
                                   background_pixel,foreground_pixel,
                                   2,2,0,100,0,100,0);
  return(dw);
}

/* FORTRAN Interface */

/* HP  and IBM use :
DIGWin *gdx11cdw(xservername,widthptr,heightptr)
*/
/* SUN and DEC use :
*/
DIGWin *gdx11cdw_(xservername,widthptr,heightptr)
     char *xservername;
     int *widthptr, *heightptr;
{
  return(gdx11_create_digwin(xservername,*widthptr,*heightptr));
}

       /*****************************/
       /* Set FEAP Drawing Window */
       /*****************************/

DIGWin *gdx11_set_current_digwin(dw)
     DIGWin *dw;
{
  DIGWin *old_dw = current_dw;

  current_dw = dw;

  /* Force FEAP to do equivalent of a DEVSEL! This is necessary to get */
  /*  FEAP to notice the change in the window. Unfortunately, it also  */
  /*  has the side effect of resetting all those things DEVSEL resets,   */
  /*  e.g. line type, clipping limits, etc.                              */

  /* Finally, return the old FEAP window */
  return(old_dw);
}

/* FORTRAN Interace */
/* HP  and IBM use :
DIGWin *gdx11setdw(dw)
*/
/* SUN and DEC use :
*/
DIGWin *gdx11setdw_(dw)
     DIGWin **dw;
{
  return(gdx11_set_current_digwin(*dw));
}

       /****************************/
       /* Set Default Xwindow Size */
       /****************************/

void gdx11_set_def_window_size(width,height)
     int width, height;
{
  default_width = width;
  default_height = height;
}

/* FORTRAN Interface */
/* HP  and IBM use :
void gdx11setwindow(widthptr,heightptr)
*/
/* SUN and DEC use :
*/
void gdx11setwindow_(widthptr,heightptr)
     int *widthptr, *heightptr;
{
  gdx11_set_def_window_size(*widthptr,*heightptr);
}

       /********************/
       /* Free FEAP Window */
       /********************/

void gdx11_free_digwin(dw)
     DIGWin *dw;
{
  if (current_dw == dw) current_dw = NULL;
  if (default_dw == dw) default_dw = NULL;
  free(dw->npoints);
  free(dw->polyline_pixel_value);
  free(dw->polyline_gray_value);
  free(dw->points);
  free(dw);
}

       /***********************************************************/
       /* Simple Function to Handle Single X Event in FEAP Window */
       /***********************************************************/

static XComposeStatus lookup_status;

int gdx11_handle_digwin_event(dw,eventptr,term_char,term_button)
     DIGWin *dw;
     XEvent *eventptr;
     char term_char;
     unsigned int term_button;
{
  int terminator = 0;

  switch (eventptr->type)
    {
    case MappingNotify:
      XRefreshKeyboardMapping((XMappingEvent *)eventptr);
      break;
    case Expose:
      gdx11_refresh_digwin(dw);
      break;
    case ConfigureNotify:
      gdx11_adjust_digwin(dw);
      gdx11_refresh_digwin(dw);
      break;
    case KeyPress:
      {
        XKeyEvent *key_event = (XKeyEvent *)eventptr;
        int length;
        char buf[8];
        KeySym ks;

        length = XLookupString(key_event,buf,8,&ks,&lookup_status);
        if (length > 0 && term_char != 0 && term_char == buf[0])
          terminator = 1;
        break;
      }
    case ButtonPress:
      {
        XButtonEvent *button_event = (XButtonEvent *)eventptr;

        if (term_button != 0 &&
            term_button == button_event->button) terminator = 1;
      }
    default:
      break;
    }
  return(terminator);
}

       /*******************************/
       /* Keep FEAP windows "alive" */
       /*******************************/

void gdx11_maintain_digwins(dws,ndigwin,term_char,term_button)
     DIGWin *dws[];
     int ndigwin;
     char term_char;
     unsigned int term_button;
{
  int i;
  DIGWin *dw;
  XEvent event;
  int terminated = 0;
  do
    {
      for (i=0;i<ndigwin;++i)
        {
          dw = dws[i];
          if (XCheckWindowEvent(dw->xdisplay,dw->xwin,
                                dw->xwa.your_event_mask,&event))
            terminated = gdx11_handle_digwin_event(dw,&event,term_char,
                                                   term_button);
        }
    } while (!terminated);
}

/* FORTRAN Interface */

/* HP  and IBM use :
void gdx11maintain(dws,ndigwinptr,term_char_ptr,term_button_ptr)
*/
/* SUN and DEC use :
*/
void gdx11maintain_(dws,ndigwinptr,term_char_ptr,term_button_ptr)
     DIGWin *dws[];
     int *ndigwinptr;
     char *term_char_ptr;
     int *term_button_ptr;
{
  gdx11_maintain_digwins(dws,*ndigwinptr,*term_char_ptr,term_button_ptr);
}

       /******************/
       /* String support */
       /******************/

static void gdx11_init_strings(dw)
     DIGWin *dw;
{
  dw->nstrings = 0;
}

       /********************/
       /* Polyline support */
       /********************/

static void gdx11_init_polylines(dw)
     DIGWin *dw;
{
  dw->npolylines = 0;
  dw->npoints[0] = 0;
  dw->next_point = 0;
}

static void gdx11_term_polyline(dw)
     DIGWin *dw;
{
  /* Terminate previous polyline if necessary */
  if (dw->npoints[dw->npolylines]>=2)
    ++dw->npolylines;
  else
    dw->next_point -= dw->npoints[dw->npolylines];
  dw->npoints[dw->npolylines] = 0;
}

static gdx11_end_polygon(dw)
     DIGWin *dw;
{
  int npoly = dw->npolylines;

  if (dw->npoints[npoly]>=2)
    {
      dw->npoints[npoly] = -dw->npoints[npoly];
      ++dw->npolylines;
    }
  else
    dw->next_point -= dw->npoints[dw->npolylines];
  dw->npoints[dw->npolylines] = 0;
}

static void gdx11_check_polyline_overflow(dw,n)
     DIGWin *dw;
     int n;
{
  if (dw->next_point+n > MAX_POINTS ||
      dw->npolylines>=MAX_SEG)
    {
      gdx11_term_polyline(dw);
      gdx11_refresh_digwin(dw);
      gdx11_init_polylines(dw);

    }
}

static void gdx11_start_polyline(dw,x,y)
     DIGWin *dw;
     int x, y;
{
  gdx11_term_polyline(dw);
  gdx11_check_polyline_overflow(dw,2);

  /* Initialize current polyline */
  dw->points[dw->next_point].x = x;
  dw->points[dw->next_point++].y = y;
  dw->npoints[dw->npolylines] = 1;
  dw->polyline_pixel_value[dw->npolylines] = dw->current_pixel_value;
  if(dw->num_fg_colors == 1)
       dw->polyline_gray_value[dw->npolylines] = dw->current_gray_value;
  return;
}

static void gdx11_start_polygon(dw,n,x,y)
     DIGWin *dw;
     int n;
     int x, y;
{
  gdx11_term_polyline(dw);
  gdx11_check_polyline_overflow(dw,n);
  gdx11_start_polyline(dw,x,y);
  return;
}

static void gdx11_add_point_to_polyline(dw,x,y)
     DIGWin *dw;
     int x,y;
{
  if (dw->npoints[dw->npolylines]==0)
    gdx11_start_polyline(dw,dw->current_x,dw->current_y);
  gdx11_check_polyline_overflow(dw,1);
  dw->points[dw->next_point].x = x;
  dw->points[dw->next_point++].y = y;
  ++dw->npoints[dw->npolylines];
}

       /**************************/
       /* 1. - INITIALIZE DEVICE */
       /**************************/

static void gdx11_init_device(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  /* If we do not yet have a diglib Xwindow get one */
  if (dw == NULL)
    {
      if (default_dw == NULL)
        dw = default_dw =
          gdx11_create_digwin("",default_width,default_height);
      else
        dw = default_dw;
    }

  /* Now fix the correct screen-size */

  current_dw = dw;
  gdx11_adjust_digwin(dw);
}

       /******************************************************/
       /* 2. - GET FRESH PLOTTING SURFACE, i.e. ERASE WINDOW */
       /******************************************************/

static void gdx11_clear_page(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  dw->current_pixel_value = dw->pixel_value_for_color[1];
  gdx11_init_polylines(dw);
  gdx11_init_strings(dw);

  if ((*x_data)[0] >= 0.0)
  {
    if (DEBUG>=4) fprintf(stderr,"Clearing Window ... ");
    XClearWindow(dw->xdisplay,dw->xwin);
    if (DEBUG>=4) fprintf(stderr,"done!\n");
    gdx11_adjust_digwin(dw);
  }
}

       /**********************/
       /* 3. - MOVE TO (X,Y) */
       /**********************/

static void gdx11_move_to(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{

  int x = x_translate(dw,(*x_data)[0]);
  int y = y_translate(dw,(*y_data)[0]);

  if (x==dw->current_x && y==dw->current_y) return;

  /* Start polyline */
  gdx11_start_polyline(dw,x,y);

  dw->current_x = x;
  dw->current_y = y;
}

       /**********************/
       /* 4. - DRAW TO (X,Y) */
       /**********************/

static void gdx11_draw_to(dw,x_data,y_data)
     DIGWin *dw;
     float (* x_data)[], (* y_data)[];
{
  register int new_x, new_y;

  new_x = x_translate(dw,(*x_data)[0]);
  new_y = y_translate(dw,(*y_data)[0]);
  gdx11_add_point_to_polyline(dw,new_x,new_y);
  dw->current_x = new_x;
  dw->current_y = new_y;
}

       /******************************/
       /* 5. - FLUSH GRAPHICS BUFFER */

⌨️ 快捷键说明

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