| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2005 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
/* ----------------------------------------------------------------- */ |
| 29 |
/* --------- III -------------------------------------------------- */ |
| 30 |
/* ----------------------------------------------------------------- */ |
| 31 |
|
| 32 |
/* file III.C : contains the following routines |
| 33 |
* |
| 34 |
* IIIENI_C : Enable Interaction; |
| 35 |
* IIISTI_C : Stop Interaction; |
| 36 |
* IIIEIW_C : Execute Interaction & Wait; |
| 37 |
* IIIGLD_C : get Locator Displacement; |
| 38 |
* IIIGLE_C : get Logical Evaluator; |
| 39 |
* IIIGSE_C : get String Evaluator; |
| 40 |
* IIIGCE_C : get (single) Character Evaluator ; |
| 41 |
* - this is an extension of the IDIs !! |
| 42 |
* |
| 43 |
* |
| 44 |
* version 2.2 890612 KB |
| 45 |
|
| 46 |
051012 last modif |
| 47 |
|
| 48 |
*/ |
| 49 |
|
| 50 |
# include <idi.h> |
| 51 |
# include <idistruct.h> |
| 52 |
# include <proto_idi.h> |
| 53 |
|
| 54 |
# include <stdio.h> |
| 55 |
|
| 56 |
|
| 57 |
extern int osawrite(); |
| 58 |
|
| 59 |
static char evchar[12]; |
| 60 |
|
| 61 |
static INTER_DATA *intdata; |
| 62 |
static LOCATOR *loca; |
| 63 |
|
| 64 |
/* |
| 65 |
|
| 66 |
*/ |
| 67 |
|
| 68 |
/************************************************************************ |
| 69 |
* IIIENI_C routine : enable interaction * |
| 70 |
* * |
| 71 |
* synopsis IIIENI_C (display , intype , intid , objtype , objid , * |
| 72 |
* oper , trigger); * |
| 73 |
* * |
| 74 |
* int display; input display identifier * |
| 75 |
* int intype; input interactor type * |
| 76 |
* int intid; input interactor id * |
| 77 |
* int objtype; input object type * |
| 78 |
* int objid; input object id * |
| 79 |
* int oper; input interactive operation * |
| 80 |
* int trigger; input exit trigger * |
| 81 |
************************************************************************/ |
| 82 |
|
| 83 |
int IIIENI_C (display, intype, intid, objtype, objid, oper, trigger) |
| 84 |
|
| 85 |
int intype , objtype , oper; |
| 86 |
int display , intid , objid , trigger; |
| 87 |
|
| 88 |
{ |
| 89 |
int noint; |
| 90 |
|
| 91 |
|
| 92 |
if (ididev[display].opened == 0) return(DEVNOTOP); |
| 93 |
noint = ididev[display].n_inter; |
| 94 |
|
| 95 |
|
| 96 |
/* check exit trigger with previous enabled interactions */ |
| 97 |
|
| 98 |
if ((noint > 0) && (trigger != ididev[display].trigger)) |
| 99 |
return(ILLTRIGGER); |
| 100 |
|
| 101 |
|
| 102 |
/* check max number of enabled interactions */ |
| 103 |
|
| 104 |
if (noint == MAX_INTER) |
| 105 |
{ |
| 106 |
(void) printf("max_inter = MAX_INTER, n_inter = %d\n",noint); |
| 107 |
return(MAXNOINT); |
| 108 |
} |
| 109 |
|
| 110 |
intdata = ididev[display].inter[noint]; |
| 111 |
intdata->inttype = intype; |
| 112 |
intdata->intid = intid; |
| 113 |
|
| 114 |
switch (intype) |
| 115 |
{ |
| 116 |
case II_LOC: |
| 117 |
if ((intid>= 0) && (intid < intdevtable[display].nloc)) |
| 118 |
intdata->interactor = intdevtable[display].loc[intid]->interactor; |
| 119 |
else |
| 120 |
return(ILLINTTYPE); |
| 121 |
break; |
| 122 |
|
| 123 |
case II_TRG: |
| 124 |
if ((intid>= 0) && (intid < intdevtable[display].ntrig)) |
| 125 |
{ |
| 126 |
intdata->interactor = intdevtable[display].trig[intid]->interactor; |
| 127 |
intdevtable[display].trig[intid]->def = II_TRG; |
| 128 |
} |
| 129 |
else |
| 130 |
return(ILLINTTYPE); |
| 131 |
break; |
| 132 |
|
| 133 |
case II_EVLC: |
| 134 |
if ((intid>= 0) && (intid < intdevtable[display].ntrig)) |
| 135 |
{ |
| 136 |
intdata->interactor = intdevtable[display].trig[intid]->interactor; |
| 137 |
intdevtable[display].trig[intid]->def = II_EVLC; |
| 138 |
} |
| 139 |
else |
| 140 |
return(ILLINTTYPE); |
| 141 |
break; |
| 142 |
|
| 143 |
default: |
| 144 |
return(ILLINTTYPE); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
intdata->objtype = objtype; |
| 149 |
intdata->objid = objid; |
| 150 |
|
| 151 |
switch (objtype) |
| 152 |
{ |
| 153 |
case II_NULL: |
| 154 |
case II_CURSOR: |
| 155 |
case II_ROI: |
| 156 |
break; |
| 157 |
|
| 158 |
default: |
| 159 |
return(ILLINTOBJ); |
| 160 |
} |
| 161 |
|
| 162 |
switch (oper) |
| 163 |
{ |
| 164 |
case II_USER: |
| 165 |
case II_MOVE: |
| 166 |
case II_MODIFY: |
| 167 |
intdata->oper = oper; |
| 168 |
break; |
| 169 |
|
| 170 |
default: |
| 171 |
return(ILLINTOPER); |
| 172 |
} |
| 173 |
|
| 174 |
ididev[display].trigger = trigger; |
| 175 |
ididev[display].n_inter ++; |
| 176 |
|
| 177 |
return(II_SUCCESS); |
| 178 |
} |
| 179 |
|
| 180 |
/* |
| 181 |
|
| 182 |
*/ |
| 183 |
|
| 184 |
/************************************************************************ |
| 185 |
* IIISTI_C routine : stop interaction * |
| 186 |
* * |
| 187 |
* synopsis IIISTI_C (display); * |
| 188 |
* * |
| 189 |
* int display; input display identifier * |
| 190 |
************************************************************************/ |
| 191 |
|
| 192 |
int IIISTI_C (display) |
| 193 |
|
| 194 |
int display; |
| 195 |
|
| 196 |
{ |
| 197 |
if (ididev[display].opened == 0) return(DEVNOTOP); |
| 198 |
|
| 199 |
ididev[display].n_inter = 0; |
| 200 |
int_disable (display); |
| 201 |
|
| 202 |
return(II_SUCCESS); |
| 203 |
} |
| 204 |
|
| 205 |
/* |
| 206 |
|
| 207 |
*/ |
| 208 |
|
| 209 |
/************************************************************************ |
| 210 |
* IIIEIW_C routine : execute interaction & wait * |
| 211 |
* * |
| 212 |
* synopsis IIIEIW_C (display , trgstatus); * |
| 213 |
* * |
| 214 |
* int display; input display identifier * |
| 215 |
* int trgstatus[]; output output trigger status * |
| 216 |
************************************************************************/ |
| 217 |
|
| 218 |
int IIIEIW_C (display , trgstatus) |
| 219 |
int display , trgstatus[MAX_TRG]; |
| 220 |
|
| 221 |
{ |
| 222 |
int i, trgflg, exitflg, trgno, userstatus; |
| 223 |
int evdata, evtype, evpos[2]; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
if (ididev[display].opened == 0) return(DEVNOTOP); |
| 229 |
|
| 230 |
|
| 231 |
/* check if any interaction has been enabled */ |
| 232 |
|
| 233 |
if (ididev[display].n_inter == 0) return(INTNOEN); |
| 234 |
|
| 235 |
int_enable (display); /* enable interactive ididevs */ |
| 236 |
exit_trg_enable (display); /* Exit trigger enable */ |
| 237 |
|
| 238 |
userstatus = 0; |
| 239 |
exitflg = 0; |
| 240 |
|
| 241 |
set_wcur(display,0); |
| 242 |
for (i = 0; i < MAX_TRG; i++) /* zero trigger status array */ |
| 243 |
trgstatus[i] = 0; |
| 244 |
|
| 245 |
|
| 246 |
/* loop on enabled interactions |
| 247 |
wait until exit trigger is fired or some USER interaction is verified */ |
| 248 |
|
| 249 |
waiting_loop: |
| 250 |
if (auto_cursor_fid > 0) |
| 251 |
send_event(display); /* if AUTO_CURSOR => an event */ |
| 252 |
wait_int (display,&evtype,&evdata,evchar,evpos); |
| 253 |
|
| 254 |
|
| 255 |
/* loop on multiple enabled interactions */ |
| 256 |
|
| 257 |
for (i=0; i<ididev[display].n_inter; i++) |
| 258 |
{ |
| 259 |
intdata = ididev[display].inter[i]; |
| 260 |
if (intdata->inttype == II_LOC) |
| 261 |
{ |
| 262 |
if (intdata->objtype == II_CURSOR) |
| 263 |
{ |
| 264 |
if (intdata->oper == II_MOVE) |
| 265 |
curmove(display,intdata->objid,intdata->intid,evdata,evpos); |
| 266 |
} |
| 267 |
|
| 268 |
else if (intdata->objtype == II_ROI) |
| 269 |
{ |
| 270 |
if (intdata->oper == II_MOVE) |
| 271 |
roimove(display,intdata->intid,evpos); |
| 272 |
else if (intdata->oper == II_MODIFY) |
| 273 |
{ |
| 274 |
loc_mod(display,intdata->intid,evdata); |
| 275 |
roimodify(display,intdata->intid); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
else |
| 280 |
loc_mod(display,intdata->intid,evdata); |
| 281 |
} |
| 282 |
|
| 283 |
else if ((intdata->inttype == II_TRG) || (intdata->inttype == II_EVLC)) |
| 284 |
{ |
| 285 |
trgno = intdata->intid; |
| 286 |
trgflg = trigsta(display,trgno,evtype,evdata,evchar); |
| 287 |
if (trgflg == 1) trgstatus[trgno] = 1; |
| 288 |
} |
| 289 |
|
| 290 |
if (intdata->oper == II_USER) /* look for user option */ |
| 291 |
userstatus = 1; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
/* check, if we are in record_cursor mode */ |
| 296 |
|
| 297 |
if (record_cursor_fid > 0) /* record all cursor/key input */ |
| 298 |
{ |
| 299 |
int do_store, fpos[2]; |
| 300 |
char cbuf[40]; |
| 301 |
|
| 302 |
do_store = 0; |
| 303 |
if ((evtype == 4) && (evdata == 1)) /* mouse button event */ |
| 304 |
{ |
| 305 |
do_store = 1; |
| 306 |
fpos[0] = evpos[0] + 2; /* because of epsi2 ... */ |
| 307 |
fpos[1] = ididev[display].ysize - evpos[1] + 1; |
| 308 |
(void) sprintf(cbuf,"1,%d,%d",fpos[0],fpos[1]); |
| 309 |
} |
| 310 |
|
| 311 |
else if (evtype == 2) /* keyboard event */ |
| 312 |
{ |
| 313 |
do_store = 1; |
| 314 |
if (evdata == -5) /* check for RETURN key */ |
| 315 |
{ |
| 316 |
fpos[0] = evpos[0] + 2; |
| 317 |
fpos[1] = ididev[display].ysize - evpos[1] + 1; |
| 318 |
(void) sprintf(cbuf,"1,%d,%d",fpos[0],fpos[1]); |
| 319 |
} |
| 320 |
else |
| 321 |
(void) sprintf(cbuf,"2,%d",evdata); |
| 322 |
} |
| 323 |
|
| 324 |
if (do_store == 1) |
| 325 |
(void) osawrite(record_cursor_fid,cbuf,(int)strlen(cbuf)); |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
/* test the exit trigger */ |
| 330 |
|
| 331 |
trgno = ididev[display].trigger; |
| 332 |
trgflg = trigsta(display,trgno,evtype,evdata,evchar); |
| 333 |
if (trgflg == 1) |
| 334 |
{ |
| 335 |
trgstatus[trgno] = 1; |
| 336 |
exitflg = 1; |
| 337 |
set_wcur(display,1); /* let window cursor show the end */ |
| 338 |
|
| 339 |
if (record_cursor_fid > 0) /* record also exit button */ |
| 340 |
(void) osawrite(record_cursor_fid,"0",1); |
| 341 |
} |
| 342 |
|
| 343 |
if ((userstatus != 1) && (exitflg != 1)) |
| 344 |
goto waiting_loop; |
| 345 |
|
| 346 |
return(II_SUCCESS); |
| 347 |
} |
| 348 |
|
| 349 |
/* |
| 350 |
|
| 351 |
*/ |
| 352 |
|
| 353 |
/************************************************************************ |
| 354 |
* IIIGLE_C routine : Get logical Evaluator |
| 355 |
* * |
| 356 |
* synopsis IIIGLE (display, evalno, cbuf) |
| 357 |
* * |
| 358 |
* int display; input display identifier * |
| 359 |
* int evalno; input evaluator no. * |
| 360 |
* < 0, wait for char. from keyboard, * |
| 361 |
* = 0, use character from interrupt before * |
| 362 |
* int *cbuf; output logical * |
| 363 |
************************************************************************/ |
| 364 |
|
| 365 |
int IIIGLE_C (display,evalno,cbuf) |
| 366 |
int display, evalno; |
| 367 |
int *cbuf; |
| 368 |
|
| 369 |
{ |
| 370 |
if (ididev[display].opened == 0) return(DEVNOTOP); |
| 371 |
|
| 372 |
/* just a dummy stub routine for now */ |
| 373 |
|
| 374 |
|
| 375 |
return(II_SUCCESS); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
/************************************************************************ |
| 381 |
* IIIGCE_C routine : Get character Evaluator |
| 382 |
* * |
| 383 |
* synopsis IIICSE (display, evalno, cbuf) |
| 384 |
* * |
| 385 |
* int display; input display identifier * |
| 386 |
* int evalno; input evaluator no. * |
| 387 |
* < 0, wait for char. from keyboard, * |
| 388 |
* = 0, use character from interrupt before * |
| 389 |
* char *cbuf; output character * |
| 390 |
************************************************************************/ |
| 391 |
|
| 392 |
int IIIGCE_C (display,evalno,cbuf) |
| 393 |
int display, evalno; |
| 394 |
char *cbuf; |
| 395 |
|
| 396 |
{ |
| 397 |
if (ididev[display].opened == 0) return(DEVNOTOP); |
| 398 |
|
| 399 |
if (evalno < 0) |
| 400 |
get_char(display,cbuf); |
| 401 |
else |
| 402 |
*cbuf = evchar[0]; |
| 403 |
|
| 404 |
return(II_SUCCESS); |
| 405 |
} |
| 406 |
|
| 407 |
/* |
| 408 |
|
| 409 |
*/ |
| 410 |
|
| 411 |
/************************************************************************ |
| 412 |
* IIIGSE_C routine : Get String Evaluator |
| 413 |
* * |
| 414 |
* synopsis IIIGSE (display, evalno, cbuf, lcbuf) |
| 415 |
* * |
| 416 |
* int display; input display identifier * |
| 417 |
* int evalno; input evaluator no. (not used...) * |
| 418 |
* char *cbuf; output character string * |
| 419 |
* int *lcbuf; output length of above * |
| 420 |
************************************************************************/ |
| 421 |
|
| 422 |
int IIIGSE_C (display, evalno, cbuf, lcbuf) |
| 423 |
int display, evalno, *lcbuf; |
| 424 |
char *cbuf; |
| 425 |
|
| 426 |
{ |
| 427 |
if (ididev[display].opened == 0) |
| 428 |
return(DEVNOTOP); |
| 429 |
else |
| 430 |
{ |
| 431 |
get_string(display,cbuf,lcbuf); |
| 432 |
return(II_SUCCESS); |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
/************************************************************************ |
| 438 |
* IIIGLD_C routine : Get Locator Displacement * |
| 439 |
* * |
| 440 |
* synopsis IIIGLD_C (display , locn , xdis , ydis); * |
| 441 |
* * |
| 442 |
* int display; input display identifier * |
| 443 |
* int locn; input locator number * |
| 444 |
* int *xdis; output X displacement * |
| 445 |
* int *ydis; output Y displacement * |
| 446 |
************************************************************************/ |
| 447 |
|
| 448 |
int IIIGLD_C(display,locn,xdis,ydis) |
| 449 |
int display , locn , *xdis , *ydis; |
| 450 |
|
| 451 |
{ |
| 452 |
if (ididev[display].opened == 0) return(DEVNOTOP); |
| 453 |
|
| 454 |
loca = intdevtable[display].loc[locn]; |
| 455 |
|
| 456 |
*xdis = loca->xdif * 3; |
| 457 |
*ydis = loca->ydif * 3; |
| 458 |
|
| 459 |
loca->xdif = 0; |
| 460 |
loca->ydif = 0; |
| 461 |
|
| 462 |
return(II_SUCCESS); |
| 463 |
} |