home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / iraffdbk.c < prev    next >
C/C++ Source or Header  |  1990-05-02  |  9KB  |  259 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    iraffdbk.c (IRAF Feedback)
  6.  * Purpose:    Set the mouse pointer icon for each window and mode
  7.  * Subroutine:    set_cursor_from_iraf()        returns: void
  8.  * Subroutine:    send_curpos_to_iraf()        returns: void
  9.  * Subroutine:    trigger_curpos_to_iraf()    returns: int
  10.  * Subroutine:    set_curpos_to_iraf_trigger()    returns: void
  11.  * Origin:    Some sections modeled after code by Doug Tody, NOAO
  12.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  13.  *        You may do anything you like with this file except remove
  14.  *        this copyright.  The Smithsonian Astrophysical Observatory
  15.  *        makes no representations about the suitability of this
  16.  *        software for any purpose.  It is provided "as is" without
  17.  *        express or implied warranty.
  18.  * Modified:    {0} Michael VanHilst    initial version         15 Aug 1989
  19.  *        {1} MVH use generalized remote connection IO    28 March 1990
  20.  *        {n} <who> -- <does what> -- <when>
  21.  */
  22.  
  23. #ifdef IMTOOL
  24.  
  25. #include <stdio.h>            /* stderr, NULL, etc. */
  26. #include <ctype.h>            /* isspace, isprint, etc. */
  27. #include <X11/Xlib.h>            /* X window stuff */
  28. #include <X11/Xutil.h>            /* window manager stuff */
  29. #include "hfiles/constant.h"        /* constants and codes */
  30. #include "hfiles/struct.h"        /* all struct record types */
  31. #include "hfiles/extern.h"        /* major declared structs */
  32.  
  33. #define    SZ_IMCURVAL    160
  34. static char *NO_OUT_MSG = "Warning: output connection not open\n";
  35. /*
  36.  * Subroutine:    set_cursor_from_iraf
  37.  * Purpose:    Respond to an imtool IMCURSOR/IIS_WRITE packet from the pipe
  38.  * Note:    imtool equiv.: Write (set) the logical image cursor position.
  39.  */
  40. void set_cursor_from_iraf ( fileX, fileY )
  41.      double fileX, fileY;    /* i: cursor coords in file coord system */
  42. {
  43.   float winX, winY;
  44.   float bufX, bufY;
  45.   PolyPoint *poly;
  46.   unsigned long background;    /* l: temp for switch of colors */
  47.   void d_transform(), add_polygon_vertex(), draw_magnifier(), disp_region();
  48.   void set_cursor_from_file_coords(), set_annuli_from_file_coords();
  49.   void label_region_cycle_magnifier(), save_cursor_as_region(), erase_cursor();
  50.   void disp_cursor(), disp_dispbox();
  51.  
  52.   /* erase current cursor if it can be erased */
  53.   if( cursor.overwrites_image_data == 0 )
  54.     erase_cursor(&cursor);
  55.  
  56.   cursor.file.X = (float)fileX;
  57.   cursor.file.Y = (float)fileY;
  58.   /* get window coordinates */
  59.   d_transform(&coord.filetodisp, fileX, fileY, &winX, &winY);
  60.   if( cursor.type == COP_Polygon ) {
  61.     /* add polygon vertex at end of vertex list */
  62.     cursor.win.X = winX;
  63.     cursor.win.Y = winY;
  64.     cursor.win.x = (int)winX;
  65.     cursor.win.y = (int)winY;
  66.     poly = &cursor.poly[cursor.poly_cnt];
  67.     add_polygon_vertex(&cursor, cursor.poly_cnt, (int)winX, (int)winY);
  68.     poly->winX = winX;
  69.     poly->winY = winY;
  70.     poly->fileX = (float)fileX;
  71.     poly->fileY = (float)fileY;
  72.     poly->unset = 0;
  73.   } else {
  74.     if( cursor.annuli ) {
  75.       /* move center for all annuli */
  76.       set_annuli_from_file_coords(&cursor, &coord.filetodisp);
  77.     } else
  78.       /* move cursor center */
  79.       set_cursor_from_file_coords(&cursor, &coord.filetodisp);
  80.   }
  81.   if( cursor.type == COP_Point ) {
  82.     /* save point as region, and draw it */
  83.     save_cursor_as_region(&cursor, 0);
  84.     cursor.index = cursor.next_region->index;
  85.     disp_region(cursor.next_region);
  86.   } else {
  87.     if( cursor.overwrites_image_data )
  88.       /* redraw image and any saved cursors */
  89.       disp_dispbox();
  90.     else
  91.       disp_cursor(&cursor);
  92.   }
  93.   /* show cursor position in magnifier, including coordinate label */
  94.   d_transform(&coord.disptobuf, cursor.win.X, cursor.win.Y, &bufX, &bufY);
  95.   draw_magnifier ((double)bufX, (double)bufY);
  96.   background = cursor.draw->background;
  97.   cursor.draw->background = color.gcset.excl.background;
  98.   label_region_cycle_magnifier (&cursor, 0);
  99.   cursor.draw->background = background;
  100. }
  101.  
  102. /*
  103.  * Subroutine:    send_curpos_to_iraf
  104.  * Purpose:    Return the cursor value on the output datastream to the
  105.  *        client which requested the cursor read.
  106.  * Note:    imtool equivalent subroutine: gio_retcursorval()
  107.  */
  108. void send_curpos_to_iraf ( fileX, fileY, frameno, z, key, strval )
  109.      double fileX, fileY;    /* i: cursor coordinates */
  110.      int frameno;        /* i: frame number given by last WCS packet */
  111.      int z;            /* i: value of request packet iis.z */
  112.      int key;            /* i: keystroke used as trigger */
  113.      char *strval;        /* i: optional string value */
  114. {
  115.   char    curval[SZ_IMCURVAL];
  116.   char    keystr[20];
  117.   int write_connection();
  118.  
  119.   if( control.IRAF_out.open == 0 ) {
  120.     (void)fprintf(stderr, NO_OUT_MSG);
  121.     return;
  122.   }
  123.   if( key == EOF ) {
  124.     /* user indicated abort of readback process */
  125.     sprintf(curval, "EOF\n");
  126.   } else {
  127.     if( isprint(key) && (!isspace(key)) ) {
  128.       keystr[0] = key;
  129.       keystr[1] = '\0';
  130.     } else
  131.       sprintf(keystr, "\\%03o", key);
  132.     /* Encode the cursor value and key. */
  133.     sprintf(curval, "%10.3f %10.3f %d %s %s\n",
  134.           fileX, fileY, (frameno * 100) + z, keystr, strval);
  135.   }
  136.   /* Send it to the client program. */
  137.   /* Send it to the client program. */
  138.   (void)write_connection(&control.IRAF_out, curval, sizeof(curval));
  139. }
  140.  
  141. static int trigger_request_count = 0;
  142. static int frame, iis_z;
  143. /*
  144.  * Subroutine:    set_curpos_to_iraf_trigger
  145.  * Purpose:    Set up mode to send cursor position when a key is struck
  146.  * Note:    Equivalent imtool subroutine: gio_readcursor()
  147.  * GIO_READCURSOR -- Initiate an image cursor read.  Save the current
  148.  * mouse coordinates if outside the imtool window, restore the mouse to the
  149.  * imtool window, and change the cursor shape to indicate that a cursor read
  150.  * is in progress.  May be called while a cursor read is already in progress
  151.  * to reset the cursor-read cursor pixrect.
  152.  */
  153. void set_curpos_to_iraf_trigger ( frameno, z )
  154.      int frameno;
  155.      int z;        /* i: z value from iis packet which requested mode */
  156. {
  157.   void set_trigger_key_mouse(), set_iraf_key_trigger();
  158.  
  159.   if( control.IRAF_out.open == 0 ) {
  160.     (void)fprintf(stderr, NO_OUT_MSG);
  161.     return;
  162.   }
  163.   if( trigger_request_count == 0 ) {
  164.     /* change display window cursor */
  165.     set_trigger_key_mouse(1);
  166.     /* put trigger in key response subroutine */
  167.     set_iraf_key_trigger(1);
  168.   }
  169.   frame = frameno;
  170.   iis_z = z;
  171.   trigger_request_count++;
  172. }
  173.  
  174. /*
  175.  * Subroutine:    trigger_curpos_to_iraf
  176.  * Purpose:    Send cursor position to IRAF in response to trigger event
  177.  */
  178. int trigger_curpos_to_iraf ( event, key )
  179.      XKeyEvent *event;
  180.      int key;
  181. {
  182.   float fileX, fileY;
  183.   PolyPoint *poly;
  184.   void update_annuli_centers(), send_curpos_to_iraf(), set_trigger_key_mouse();
  185.   void i_transform(), erase_cursor(), disp_dispbox(), set_cursor_file_coords();
  186.   void save_cursor_as_region(), set_iraf_key_trigger(), add_polygon_vertex();
  187.   void note_trigger_key_position(), move_annuli(), disp_region();
  188.   void make_cursor();
  189.  
  190.   if( control.IRAF_out.open == 0 ) {
  191.     (void)fprintf(stderr, NO_OUT_MSG);
  192.     return(0);
  193.   }
  194.   /* Map ctrl/d and ctrl/z into EOF. */
  195.   i_transform(&coord.disptofile, event->x, event->y, &fileX, &fileY);
  196.   if( (key == '\004') || (key == '\032') ) {
  197.     key = EOF;
  198.   } else {
  199. #ifdef CURTOO
  200.     if( control.mode == COP ) {
  201.       if( cursor.annuli ) {
  202.     move_annuli(&cursor, event->x, event->y);
  203.     update_annuli_centers(&cursor);
  204.     save_cursor_as_region(&cursor, 0);
  205.       } else {
  206.     if( cursor.overwrites_image_data == 0 )
  207.       erase_cursor(&cursor);
  208.     cursor.win.X = (double)event->x + 0.5;
  209.     cursor.win.Y = (double)event->y + 0.5;
  210.     cursor.win.x = event->x;
  211.     cursor.win.y = event->y;
  212.     if( cursor.type == COP_Polygon ) {
  213.       /* add polygon vertex at end of vertex list */
  214.       poly = &cursor.poly[cursor.poly_cnt];
  215.       add_polygon_vertex(&cursor, cursor.poly_cnt, event->x, event->y);
  216.       poly->winX = (double)event->x;
  217.       poly->winY = (double)event->y;
  218.       poly->fileX = fileX;
  219.       poly->fileY = fileY;
  220.       poly->unset = 0;
  221.     } else {
  222.       /* force file coordinates into agreement with window coordinates */
  223.       set_cursor_file_coords(&cursor, &coord.disptofile, 0);
  224.       set_cursor_file_coords(&cursor, &coord.disptofile, 1);
  225.       /* make new drawing vertices */
  226.       make_cursor(&cursor);
  227.       save_cursor_as_region(&cursor, 0);
  228.     }
  229.       }
  230.       if( cursor.overwrites_image_data )
  231.     /* redraw image and any saved cursors */
  232.     disp_dispbox();
  233.       if( cursor.type != COP_Polygon )
  234.     disp_region(cursor.next_region);
  235.     }
  236. #endif
  237.   }
  238.   /* send the coords and key through the fifo */
  239.   send_curpos_to_iraf((double)fileX, (double)fileY, frame, iis_z, key, "");
  240.   /* note the current position for returning the mouse pointer */
  241.   note_trigger_key_position((int)event->x, (int)event->y);
  242.   if( --trigger_request_count <= 0 ) {
  243.     /* restore display window cursor */
  244.     set_trigger_key_mouse(0);
  245.     /* clear trigger in key response subroutine */
  246.     set_iraf_key_trigger(0);
  247.   }
  248.   return( 1 );
  249. }
  250.  
  251. #endif
  252.               
  253.                                                                
  254.                                                                
  255.                                                                
  256.                                                                
  257.                                                                
  258.                                                      
  259.