1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
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.
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.
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,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/* ----------------------------------------------------------------- */
30
/* file iid1.c : contains the following routines
32
* IIDINIT : initialize structures
33
* IIDOPN_C : Open Display;
35
* pars24 : map 3 digits xyz -> co_flg, rd_flg, wr_flg
36
* = flag24[2], [1], [0]
38
*************************************************************************
39
* V 1.1 871201: P. Santin - Trieste Astronomical Observatory
40
* V 2.0 881130 Klaus Banse - ESO Garching
43
*************************************************************************
51
# include <idistruct.h>
52
# include <proto_idi.h>
53
# include <midas_def.h>
57
static int f_wndw[MAX_WST], f_lut[MAX_WST], f_RGB[MAX_WST];
58
static int start_flag = -1;
60
static char ididir[64];
66
int pars24(ival,flags)
88
else /* no special flag for copy/display */
94
if (wf == 2) /* 1 = on, 0 or 2 = off */
108
printf("sf = %d, rf = %d, wf = %d\n",flags[2],flags[1],flags[0]);
118
/************************************************************************/
128
for (i=0; i<MAX_DEV; i++)
130
ididev[i].opened = 0;
131
ididev[i].screen = 0;
132
ididev[i].devname[0] = '\0';
135
OSY_GETSYMB("DAZUNIT",muni,4);
138
for (i=0; i<MAX_WST; i++)
142
Xworkst[i].name[0] = '\0';
143
(void) strcpy(Xworkst[i].miduni,muni); /* save MIDAS unit */
146
(void) OSY_TRNLOG("MID_WORK",ididir,64,&m);
154
/************************************************************************
155
* IIDOPN_C routine : opens a new display for subsequent operations *
157
* synopsis IIDOPN_C (display, displayid); *
159
* char[] display; input device name *
160
* int *displayid; output display identifier *
161
************************************************************************/
163
int IIDOPN_C (display, displayid)
168
int x0, y0, fontno[4];
169
int devxoff, devyoff, devxdim, devydim, dstatus;
170
int shadow, ival[5], len, k1, screeno, gsize;
172
int limited, con_main, minlut, RGBmode, flag24;
175
unsigned int allbytes;
177
char dspchar, cbuf[12], record[100], name[24];
197
/* look, if we're here for the very first time */
199
if (start_flag == -1)
201
IIDINIT(); /* initialize the stuff */
205
else if (display[0] == ' ') /* we only wanted the connection */
207
for (i=0; i<MAX_DEV; i++)
209
if (ididev[i].devname[0] != '\0')
212
ididev [i].opened = 1;
213
loc_zero(i); /* reset locators */
214
return(ENTRYFND); /* indicate, that already there */
220
/* search through all opened ididevs */
222
for (i=0; i<MAX_DEV; i++)
224
if (strcmp(display,ididev[i].devname) == 0)
227
ididev [i].opened = 1;
228
loc_zero(i); /* reset locators */
229
return(ENTRYFND); /* indicate, that already there */
233
/* so look for empty ididev structure */
235
for (i=0; i<MAX_DEV; i++)
237
if (ididev[i].devname[0] == '\0')
244
return (NOAVAILDEV); /* return with error */
248
/* get ididev parameters from sxwAB...dat file */
249
/* ---------------------------------------------- */
258
dspchar = display[j++];
262
ididev[i].devtyp = 'g'; /* it's a graphics window */
265
case 'z': /* if "sxwAB0z", it's a zoom window */
266
ididev[i].devtyp = 'z';
268
case 'c': /* if "sxwAB0c" => cursor window */
269
ididev[i].devtyp = 'c';
272
case 's': /* "sxwAB0s", display shadow window */
273
ididev[i].devtyp = 'i';
276
case 't': /* "sxwAB0t", graphic shadow window */
277
ididev[i].devtyp = 'g';
282
ididev[i].devtyp = 'i'; /* everything else is image window */
285
(void) strcpy(record,ididir);
286
if (display[0] == ' ') /* we just wanted to connect */
289
(void) strcat(record,display);
290
(void) strcat(record,".dat");
292
fp = osaopen(record,READ);
294
{ /* wait 1 sec + try one more time */
299
fp = osaopen(record,READ);
302
(void) printf("IIDOPN: where is %s ?\n",record);
307
(void) strcpy (ididev[i].devname,display);
311
/* first of all get Xworkstation name */
313
if ((len = osaread(fp,record,72)) < 1) goto file_err;
314
for (nr=0; nr<len; nr++)
316
if (record[nr] == ' ')
323
if (strcmp(record,"default") == 0)
324
OSY_GETSYMB("DISPLAY",record,60);
326
else if ( ((record[0]=='z')&&(record[1]=='o')) ||
327
((record[0]=='c')&&(record[1]=='u')) ) /* zoom or cursor w. */
329
for (nr=0; nr<MAX_DEV; nr++) /* look for main window */
332
(ididev[nr].devname[0] != '\0') &&
333
(ididev[nr].devname[5] == display[5]) )
335
con_main = nr; /* save connected main window */
336
if (record[4] != ',') /* same Xstation */
338
screeno = ididev[nr].screen;
342
{ /* zoom,Xstation */
343
if (strcmp(&record[5],"default") == 0)
344
OSY_GETSYMB("DISPLAY",record,60);
346
(void) strcpy(record,&record[5]); /* move to begin */
352
dstatus = WSTNAMERR; /* no main window found */
357
/* look for same Xstation or attach new one */
360
j = (int) strlen(record) - 2; /* test last but one char. */
361
if (record[j] == ':')
363
j += 2; /* Xname:0 -> Xname:0.0 */
370
for (nr=0; nr<MAX_WST; nr++)
372
if (strcmp(record,Xworkst[nr].name) == 0)
378
for (nr=0; nr<MAX_WST; nr++)
380
if (Xworkst[nr].name[0] == '\0')
383
(void) strcpy(Xworkst[nr].name,record);
388
dstatus = WSTNAMERR; /* return with error */
392
/* check if we are a shadow window => update owner entry */
395
ididev[i].screen = screeno;
396
ididev[i].ref = '\0';
397
for (j=0; j<MAX_DEV; j++) ididev[i].shadow[j] = -1;
399
if (shadow == 0) /* read "shadow,ref-id" line */
401
if ((len = osaread(fp,record,72)) < 1) goto file_err;
402
len = CGN_INDEXC(record,',');
403
(void) strncpy(cbuf,display,5); /* construct name of ref. window */
404
cbuf[5] = record[++len];
405
if (ididev[i].devtyp == 'g')
406
(void) strcpy(&cbuf[6],"g");
409
for (nr=0; nr<MAX_DEV; nr++)
411
if (strcmp(cbuf,ididev[nr].devname) == 0)
413
shadow = nr; /* save owner id for later */
414
ididev[i].ref = cbuf[5]; /* save reference display */
418
dstatus = ILLSHADOW; /* no reference display found */
423
/* get alpha_memo flag, RGB mode, backgr. colour, 24bit flag */
426
if ((len = osaread(fp,record,72)) > 0)
427
len = CGN_CNVT(record,1,4,ival,&fval,&dval);
428
if (len < 4) goto file_err;
429
ididev[i].alpno = ival[0];
432
ididev[i].backpix = ival[2]; /* just save the index for now */
433
flag24 = ival[3]; /* serves as byte swap for special,read,write flag */
436
/* get display offset + dimensions */
438
if ((len = osaread(fp,record,72)) > 0)
439
len = CGN_CNVT(record,1,4,ival,&fval,&dval);
440
if (len < 4) goto file_err;
441
devxoff = ival[0]; devyoff = ival[1];
442
devxdim = ival[2]; devydim = ival[3];
445
/* get noLUTS, maxLUTsize, minLUTsize, ownLUT, LUToffset */
447
if ((len = osaread(fp,record,72)) > 0)
448
len = CGN_CNVT(record,1,5,ival,&fval,&dval);
449
if (len < 5) goto file_err;
451
ididev[i].lutoff = ival[4];
453
if (f_wndw[screeno] == 0)
454
{ /* connect to display */
455
dstatus = Xwstinit(0,Xworkst[screeno].name,screeno,fontno,minlut);
456
if (dstatus != II_SUCCESS) goto gen_err;
457
Xworkst[screeno].nolut = ival[0];
458
Xworkst[screeno].lutsize = ival[1];
459
Xworkst[screeno].ownlut = ival[3]; /* maybe modified by Xwstinit ... */
463
/* get font numbers for small, medium, large font */
465
if ((len = osaread(fp,record,72)) > 0)
467
len = CGN_CNVT(record,1,3,fontno,&fval,&dval); /* fontno[4] is special */
468
if (len < 3) goto file_err; /* we need 3 fonts */
471
ididev[i].opened = 1;
472
ididev[i].xsize = devxdim; /* set by display window section */
473
ididev[i].ysize = devydim; /* set by display window section */
475
ididev[i].trigger = 0; /* exit trigger is 0 */
476
ididev[i].inter_mask = 0;
477
ididev[i].n_inter = 0;
479
ididev[i].lutsect = 0; /* default to 1. (maybe only) LUT section */
480
ididev[i].lookup = 0;
482
ididev[i].hcopy = (char *) 0;
483
ididev[i].curswin = -1;
484
ididev[i].link[0] = 0;
485
ididev[i].link[1] = -1;
489
/* ----------------------- */
490
/* create virtual display */
491
/* ----------------------- */
495
name[0] = 'T'; /* TrueColor */
498
name[0] = 'P'; /* PseudoColor */
501
else if (RGBmode == 2)
502
name[1] = 'D'; /* on top of DirectColor */
506
name[1] = 'T'; /* on top of TrueColor */
510
if (f_wndw[screeno] == 0)
511
{ /* get fonts + colour maps */
512
if (ididev[i].devtyp == 'g')
513
f_wndw[screeno] = 2; /* graphics window is first */
515
f_wndw[screeno] = 1; /* display window is first */
517
dstatus = Xwstinit(f_wndw[screeno],name,screeno,fontno,minlut);
518
if (dstatus != II_SUCCESS) goto gen_err;
519
set_wcur(i,-1); /* create all cursor shapes */
520
if (Xworkst[screeno].lutflag != 0)
521
f_wndw[screeno] = 1; /* we did already everything */
522
if (Xworkst[screeno].visual == 4)
523
RGBmode = 2; /* emulate Pseudo on DirectColor */
525
f_RGB[screeno] = RGBmode;
528
else if (f_wndw[screeno] == 2)
530
if (ididev[i].devtyp != 'g') /* display window after graphics */
533
dstatus = Xwstinit(3,name,screeno,fontno,minlut);
534
if (dstatus != II_SUCCESS) goto gen_err;
538
RGBmode = f_RGB[screeno]; /* so all windows have same RGBflag */
540
/* flag24 uses 3 digits: x y z 1 = on, 2 = off (also 0 = off)
541
used for special_flag (x), read_flag (y), write_flag (z)
542
Xworkst[screeno].flag24[0,1,2] = z,y,x */
544
if (flag24 == 0) /* if not set, check it here */
546
if (test_swap(i) == 1) /* yes we swap bytes */
549
(void) pars24(flag24,Xworkst[screeno].flag24);
552
if (ididev[i].alpno >= 90)
554
ididev[i].alphx = devxdim-2; /* border width = 1 pixel */
555
ididev[i].alphy = 50;
556
ididev[i].alphxscal = 512./80.;
557
ididev[i].alphlinsz = 12; /* pixels per line */
558
m = devydim + ididev[i].alphy + 2; /* add space for alpha subwindow */
559
dstatus = crea_win(i,devxoff,devyoff,devxdim,m,dspchar);
560
crealph(i,devydim); /* create also the alphanumerics window */
564
ididev[i].alphy = -2;
565
dstatus = crea_win(i,devxoff,devyoff,devxdim,devydim,dspchar);
566
if (ididev[i].devtyp == 'c') /* cursor window have no alpha mem */
568
ididev[con_main].curswin = i;
569
ididev[i].curswin = -con_main; /* keep pointer to main w. */
573
if (dstatus != II_SUCCESS) goto gen_err;
574
sendX(i); /* flush out Xstuff */
575
x0 = ididev[i].xsize / 2;
576
y0 = ididev[i].ysize / 2;
577
ididev[i].depth = Xworkst[screeno].depth;
580
for (j=0; j<ididev[i].ncurs; j++)
582
allbytes = sizeof(struct curs_data);
583
curs = (struct curs_data *) malloc((size_t)allbytes);
584
if (curs == II_NULL) goto gen_err;
586
ididev[i].cursor[j] = curs;
587
curs->sh = -1; /* sh = -1 : cursor not defined */
594
allbytes = sizeof(struct roi_data);
595
roi = (struct roi_data *) malloc((size_t)allbytes);
596
if (roi == II_NULL) goto gen_err;
599
roi->sh = -1; /* roi_sh = -1 : ROI not defined */
611
allbytes = sizeof(struct conf_data);
612
conf = (struct conf_data *) malloc((size_t)allbytes);
613
if (conf == II_NULL) goto gen_err;
615
ididev[i].confptr = conf;
617
conf->RGBmode = RGBmode;
620
/* get no. of memories + size of GLIST segments */
622
if ((len = osaread(fp,record,72)) > 0)
623
len = CGN_CNVT(record,1,2,ival,&fval,&dval);
624
if (len < 2) goto file_err;
632
for (k=0; k<k1; k++) /* loop over memories */
634
allbytes = sizeof(struct mem_data);
635
mem = (struct mem_data *) malloc((size_t)allbytes);
636
if (mem == II_NULL) goto gen_err;
638
conf->memory[k] = mem;
639
if ((len = osaread(fp,record,72)) > 0)
640
len = CGN_CNVT(record,1,3,ival,&fval,&dval);
641
if (len < 3) goto file_err;
643
mem->xsize = ival[0];
644
mem->ysize = ival[1];
646
mem->depth = ididev[i].depth;
648
mem->depth = ival[2];
650
if (ididev[i].devtyp == 'g')
651
mem->type = II_GRAPHIC | II_TEXT;
653
mem->type = II_IMAGE | II_GRAPHIC | II_TEXT;
654
if (RGBmode == 1) mem->type = mem->type | II_RGB;
655
mem->mmbm = (char *) 0;
656
mem->zmbm = (char *) 0;
659
mem->visibility = 1; /* make first channel visible */
662
clmem(mem); /* set all memory parameters */
664
if (ididev[i].alpno >= 90)
665
{ /* allocate alpha memory */
666
allbytes = sizeof(struct alph_data);
667
alph = (struct alph_data *) malloc((size_t)allbytes);
668
if (alph == II_NULL) goto gen_err;
670
conf->alpmem[k] = alph;
671
for (nr=0; nr<16; nr++)
675
if (ididev[i].devtyp == 'g')
676
mem->ittpntr = (ITT_DATA *)0; /* no ITT for graph/cursor windows */
679
allbytes = sizeof(struct itt_data);
680
itt = (struct itt_data *) malloc((size_t)allbytes);
681
if (itt == II_NULL) goto gen_err;
683
itt->vis = 0; /* default to ITT visibility off */
684
for (nr=0; nr<Xworkst[screeno].lutlen; nr++)
689
mem->gpntr = (GLIST *)0; /* no graphics structure */
692
allbytes = sizeof(struct glist);
693
graph = (struct glist *) malloc((size_t)allbytes);
694
if (graph == II_NULL) goto gen_err;
697
graph->maxpnt = gsize;
698
len = graph->maxpnt/2;
699
allbytes = sizeof(int) * (2*graph->maxpnt + 4*len); /* for x,y */
700
graph->x = (int *) malloc((size_t)allbytes); /* color, lwidth, */
701
if (graph->x == II_NULL) goto gen_err;
702
graph->y = graph->x + graph->maxpnt;
703
graph->color = graph->y + graph->maxpnt;
704
graph->lwidth = graph->color + len;
705
graph->off = graph->lwidth + len;
706
graph->count = graph->off + len;
711
mem->tpntr = (TLIST *)0;
714
allbytes = sizeof(struct tlist);
715
txt = (struct tlist *) malloc((size_t)allbytes);
716
if (txt == II_NULL) goto gen_err;
727
/* for graphics window
728
the overlay channel is the image channel itself */
730
if (ididev[i].devtyp == 'g')
733
conf->overlay = conf->memid;
737
conf->nmem = k1 + 1; /* add 1 for overlay channel */
738
conf->overlay = k1; /* last channel */
741
/* now also init the structure for the added overlay/graphics channel */
743
allbytes = sizeof(struct mem_data);
744
mem = (struct mem_data *) malloc((size_t)allbytes);
745
if (mem == II_NULL) return(MEMALLERR);
747
conf->memory[k1] = mem;
748
mem->xsize = ival[0]; /* use values of last channel */
749
mem->ysize = ival[1];
750
mem->depth = ival[2];
751
mem->type = II_IMAGE | II_GRAPHIC | II_TEXT;
752
if (RGBmode == 1) mem->type = mem->type | II_RGB;
753
mem->mmbm = (char *) 0;
754
mem->zmbm = (char *) 0;
756
mem->visibility = 1; /* we enable overlay right away */
758
mem->ittpntr = (ITT_DATA *)0;
761
mem->gpntr = (GLIST *)0; /* no graphics structure */
764
allbytes = sizeof(struct glist);
765
graph = (struct glist *) malloc((size_t)allbytes);
766
if (graph == II_NULL) return(MEMALLERR);
769
graph->maxpnt = gsize;
770
len = graph->maxpnt/2;
771
allbytes = sizeof(int) * (2*graph->maxpnt + 4*len); /* for x,y */
772
graph->x = (int *) malloc((size_t)allbytes); /* color, lwidth, */
773
if (graph->x == II_NULL) return(MEMALLERR); /* off and count */
774
graph->y = graph->x + graph->maxpnt;
775
graph->color = graph->y + graph->maxpnt;
776
graph->lwidth = graph->color + len;
777
graph->off = graph->lwidth + len;
778
graph->count = graph->off + len;
782
allbytes = sizeof(struct tlist);
783
txt = (struct tlist *) malloc((size_t)allbytes);
784
if (txt == II_NULL) return(MEMALLERR);
791
if (limited != 2) /* not for cursor window */
793
for (j=0; j<MAX_INTER; j++)
795
allbytes = sizeof(struct inter_data);
796
ixter = (struct inter_data *) malloc((size_t)allbytes);
797
if (ixter == II_NULL) return(MEMALLERR);
799
ididev[i].inter[j] = ixter;
802
intdevtable[i].nloc = MAX_LOC;
803
intdevtable[i].ntrig = MAX_TRG;
805
for (j=0; j<intdevtable[i].nloc; j++)
807
allbytes = sizeof(struct locator);
808
loca = (struct locator *) malloc((size_t)allbytes);
809
if (loca == II_NULL) return(MEMALLERR);
812
loca->interactor = II_MOUSE;
814
loca->interactor = II_KEYB;
815
intdevtable[i].loc[j] = loca;
818
loc_zero(i); /* reset all locators */
820
for (j=0; j<intdevtable[i].ntrig; j++)
822
allbytes = sizeof(struct trigger);
823
trigg = (struct trigger *) malloc((size_t)allbytes);
824
if (trigg == II_NULL) return(MEMALLERR);
826
if (j < 2) /* assume 2 buttons on the mouse */
827
trigg->interactor = II_MOUSE;
829
trigg->interactor = II_KEYB;
830
intdevtable[i].trig[j] = trigg;
834
if (shadow >= 0) /* if shadow window update owner */
836
for (j=0; j<MAX_DEV; j++)
838
if (ididev[shadow].shadow[j] == -1)
840
ididev[shadow].shadow[j] = i;
848
/* create LUT bar structure */
850
allbytes = sizeof(struct lut_bar);
851
bar = (struct lut_bar *) malloc((size_t)allbytes);
852
if (bar == II_NULL) return(MEMALLERR);
859
/* check if we have own LUT handling */
861
if ( (limited > 0) ||
862
((Xworkst[screeno].visual != 4) && (Xworkst[screeno].ownlut == 0)) )
866
if (Xworkst[screeno].ownlut == -1)
868
for (nr=0; nr<256; nr++) /* add LUT offset at least... */
870
j = nr + ididev[i].lutoff;
872
Xworkst[screeno].mapin[nr] = j;
873
Xworkst[screeno].mapout[j] = nr;
879
allbytes = sizeof(struct lut_data);
880
lut = (struct lut_data *) malloc((size_t)allbytes);
881
if (lut == II_NULL) return(MEMALLERR);
882
ididev[i].lookup = lut;
883
lut->vis = 1; /* make LUT always visible */
886
/* send black + white LUT only the very first time */
888
if (f_lut[screeno] == 1)
893
len = Xworkst[screeno].lutlen;
894
rval = 1.0 / (len - 1.0);
898
for (nr=0; nr<len; nr++)
901
lut0[len + nr] = fval;
906
m = IILWLT_C(i,0,0,len,lut0);
907
LUTinstall(i); /* install LUT if needed */
910
rd_lut(i,lut); /* get current LUT */