1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
#ifndef lint
static char SccsId[] = "%W% %G%";
#endif
/* Module: rgnctrl.c (Region Control)
* Purpose: Respond to region commands from various sources
* Subroutine: point_region() returns: void
* Subroutine: ascii_region() returns: void
* Subroutine: select_region() returns: void
* Copyright: 1989 Smithsonian Astrophysical Observatory
* You may do anything you like with this file except remove
* this copyright. The Smithsonian Astrophysical Observatory
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
* Modified: {0} Michael VanHilst initial version 26 May 1989
* {n} <who> -- <does what> -- <when>
*/
#include <stdio.h> /* Define stderr, NULL */
#include <X11/Xlib.h> /* X window stuff */
#include <X11/Xutil.h> /* X window manager stuff, visuals */
#include <X11/keysym.h>
#include <X11/keysymdef.h>
#include "hfiles/constant.h" /* Define codes */
#include "hfiles/struct.h" /* Declare structure types */
#include "hfiles/extern.h" /* Extern main parameter structures */
struct cursorRec *cycle_region = 0;
#ifdef ANSIC
void point_region( XButtonEvent *xbutton);
void ascii_region( XKeyEvent *xkey, KeySym keysym);
static void cycle_regions();
static void reset_regions();
#else
struct cursorRec *region_indicated_by_pointer();
int match_region();
void unsave_region(), set_cursor_file_coords(), disp_dispbox();
void save_cursor_as_region(), disp_region(), unsave_region();
void enable_annuli_button(), delete_annuli(), erase_cursor();
void copy_region_to_cursor(), disp_cursor(), d_transform(), draw_magnifier();
void label_region_cycle_magnifier(), touch_submenu_button();
void set_submenu_toggle(), enable_ortho_button();
void toggle_region_labeling(), toggle_region_visibility();
void write_regions(), read_regions(), free_cursor();
static void cycle_regions(), reset_regions();
#endif
/* Subroutine: point_region
* Purpose: Respond to a mouse activated request for a point region
* Note: In cursor point mode the mouse buttons map directly:
* left - save for include, middle - save for exclude, right - delete
*/
#ifdef ANSIC
void point_region ( XButtonEvent *xbutton )
#else
void point_region ( xbutton )
XButtonEvent *xbutton;
#endif
{
struct cursorRec *region;
/* Right button is a delete request in point cursor mode */
if( xbutton->button == Button3 ) {
/* See if mouse indicates a region to delete */
region = region_indicated_by_pointer(&cursor, xbutton->x, xbutton->y, 1);
if( region != NULL ) {
unsave_region(&cursor, region);
disp_dispbox();
}
} else if( (xbutton->button == Button1) || (xbutton->button == Button2) ) {
cursor.win.x = xbutton->x;
cursor.win.y = xbutton->y;
cursor.win.X = (double)cursor.win.x + 0.5;
cursor.win.Y = (double)cursor.win.y + 0.5;
/* Force file coordinates into agreement with window coordinates */
set_cursor_file_coords(&cursor, &coord.disptofile, 1);
/* Save cursor as a region */
if( xbutton->button == Button1 )
save_cursor_as_region(&cursor, 0);
else
save_cursor_as_region(&cursor, 1);
cursor.index = cursor.next_region->index;
disp_region(cursor.next_region);
}
}
/* Subroutine: ascii_region
* Purpose: Keyboard control of regions
*/
#ifdef ANSIC
void ascii_region ( XKeyEvent *xkey, KeySym keysym )
#else
void ascii_region ( xkey, keysym )
XKeyEvent *xkey;
KeySym keysym;
#endif
{
int exclude;
struct cursorRec *region;
if( cursor.type == COP_Point ) {
cursor.win.x = xkey->x;
cursor.win.y = xkey->y;
cursor.win.X = (double)cursor.win.x + 0.5;
cursor.win.Y = (double)cursor.win.y + 0.5;
}
/* Initialize values used or switched in overlapping functions */
region = cursor.next_region;
exclude = 0;
switch( keysym ) {
case XK_E:
case XK_e:
exclude = 1;
case XK_S:
case XK_s:
/* Force file coordinates into agreement with window coordinates */
set_cursor_file_coords(&cursor, &coord.disptofile, 0);
set_cursor_file_coords(&cursor, &coord.disptofile, 1);
save_cursor_as_region(&cursor, exclude);
disp_region(cursor.next_region);
break;
case XK_D:
case XK_d:
region = region_indicated_by_pointer(&cursor, xkey->x, xkey->y, 0);
case XK_Delete:
if( region != NULL ) {
unsave_region(&cursor, region);
disp_dispbox();
}
break;
default:
break;
}
}
/* Subroutine: select_region
* Purpose: Act on commands from the region button panel
*/
void select_region ( )
{
switch( control.response[1] ) {
/* This case comes up when the main menu button is pressed */
case 0:
break;
case ROP_Cycle:
cycle_regions();
break;
case ROP_Label:
toggle_region_labeling();
break;
case ROP_Omit:
if( match_region(&cursor, cycle_region) ) {
unsave_region(&cursor, cycle_region);
/* Redisplay without the omitted region */
disp_dispbox();
}
break;
case ROP_View:
toggle_region_visibility();
break;
case ROP_Reset:
reset_regions();
break;
case ROP_Write:
write_regions(&cursor, &img, img.file_type);
break;
case ROP_Read:
read_regions();
break;
default:
break;
}
}
/* Subroutine: cycle_regions
* Purpose: Cylce cursor through saved regions
*/
static void cycle_regions()
{
float bufx, bufy;
int annuli_disabled, annuli_on;
/* There must be saved regions through which to cycle */
if( cursor.next_region == NULL ) {
(void)fprintf(stderr, "Warning: no saved regions.\n");
return;
}
/* Determine if annuli button is currently disabled or on */
annuli_on = 0;
if( (cursor.type != COP_Point) && (cursor.type != COP_Polygon) ) {
annuli_disabled = 0;
if( cursor.annuli )
annuli_on = 1;
} else
annuli_disabled = 1;
/* Erase the cursor while we still know it */
if( cursor.overwrites_image_data ) {
/* Redraw image and any saved cursors, but not the cursor */
if( cursor.next_annulus != NULL )
delete_annuli (&cursor, 0);
cursor.annuli = 0;
cursor.point_cnt = 0;
cursor.rectangle_cnt = 0;
disp_dispbox();
} else {
if( cursor.next_annulus != NULL )
/* Delete_annuli does an erase cursor */
delete_annuli(&cursor, 0);
else
erase_cursor(&cursor);
}
/* Get next region in cycle */
if( cycle_region == NULL )
cycle_region = cursor.next_region;
else
cycle_region = cycle_region->next_region;
/* If at end of list, go back to head of list */
if( cycle_region == NULL )
cycle_region = cursor.next_region;
/* Make cursor be a copy of this region */
copy_region_to_cursor(&cursor, cycle_region);
/* If this is a text cursor, set the editor info for this string */
if( cursor.type == COP_Text )
reload_textcursor();
if( cursor.type != COP_Point )
/* Draw the cursor */
disp_cursor(&cursor);
/* Announce the coordinates */
if( control.verbose )
report_cursor_info (&cursor);
/* Show exact region position in magnifier */
d_transform(&coord.disptobuf, cursor.win.X, cursor.win.Y, &bufx, &bufy);
draw_magnifier((double)bufx, (double)bufy);
/* Label what we just drew */
label_region_cycle_magnifier (cycle_region, 1);
/* Make sure cursor buttons are correct */
touch_submenu_button(COP, cursor.type);
if( (cursor.type == COP_Box) ||
(cursor.type == COP_Circle) ||
(cursor.type == COP_Ellipse) ) {
if( annuli_disabled )
enable_annuli_button(1);
if( annuli_on != cursor.annuli )
set_submenu_toggle(COP, COP_Annuli, cursor.annuli);
if( cursor.type == COP_Circle )
enable_ortho_button(0);
else
enable_ortho_button(1);
} else if( !annuli_disabled ) {
enable_annuli_button(0);
enable_ortho_button(0);
}
}
/* Subroutine: reset_regions
* Purpose: Reset all save cursor areas
*/
static void reset_regions()
{
struct cursorRec *region, *next, *annulus;
if( (next = cursor.next_region) != NULL ) {
while( next != NULL ) {
region = next;
next = next->next_region;
/* Free deleted region and any annuli it might have */
do {
annulus = region->next_annulus;
free_cursor(region);
region = annulus;
} while( region != NULL );
}
/* Reset cycle pointer */
cycle_region = NULL;
cursor.next_region = NULL;
/* Redisplay image without the regions */
disp_dispbox();
}
}
|