/* @(#)iid1.c 17.1.1.1 (ESO-DMD) 01/25/02 17:34:26 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. Correspondence concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /* ----------------------------------------------------------------- */ /* file iid1.c : contains the following routines * * IIDOPN_C : Open Display; * ************************************************************************* * V 1.1 871201: P. Santin - Trieste Astronomical Observatory * V 2.0 881130 Klaus Banse - ESO Garching * 010528 last modif * ************************************************************************* */ # include # include # include # include # include extern void OSY_GETSYMB(); extern int OSY_TRNLOG(), OSY_SLEEP(), CGN_INDEXC(), CGN_CNVT(); extern int osaopen(), osaread(), osaclose(); static int f_wndw[MAX_WST], f_lut[MAX_WST], f_RGB[MAX_WST]; static int start_flag = -1; static char ididir[64]; /* */ /************************************************************************/ void IIDINIT() { int i, m; char muni[4]; for (i=0; i cursor window */ ididev[i].devtyp = 'c'; limited = 2; break; case 's': /* "sxwAB0s", display shadow window */ ididev[i].devtyp = 'i'; shadow = 0; break; case 't': /* "sxwAB0t", graphic shadow window */ ididev[i].devtyp = 'g'; limited = 1; shadow = 0; break; default: ididev[i].devtyp = 'i'; /* everything else is image window */ } (void) strcpy(record,ididir); (void) strcat(record,display); (void) strcat(record,".dat"); fp = osaopen(record,READ); if (fp < 0) { /* wait 1 sec + try one more time */ unsigned int ms; ms = 1000; OSY_SLEEP(ms,0); fp = osaopen(record,READ); if (fp < 0) return(DCTFILERR); } (void) strcpy (ididev[i].devname,display); con_main = -1; /* first of all get Xworkstation name */ if ((len = osaread(fp,record,72)) < 1) goto file_err; for (nr=0; nr Xname:0.0 */ record[j++] = '.'; record[j++] = '0'; record[j] = '\0'; } for (nr=0; nr update owner entry */ xwst_ok: ididev[i].screen = screeno; ididev[i].ref = '\0'; for (j=0; j 0) len = CGN_CNVT(record,1,3,ival,&fval,&dval); if (len < 3) goto file_err; ididev[i].alpno = ival[0]; RGBmode = ival[1]; k = ival[2]; ididev[i].backpix = ival[2]; /* just save the index for now */ /* get display offset + dimensions */ if ((len = osaread(fp,record,72)) > 0) len = CGN_CNVT(record,1,4,ival,&fval,&dval); if (len < 4) goto file_err; devxoff = ival[0]; devyoff = ival[1]; devxdim = ival[2]; devydim = ival[3]; /* get noLUTS, maxLUTsize, minLUTsize, ownLUT, LUToffset */ if ((len = osaread(fp,record,72)) > 0) len = CGN_CNVT(record,1,5,ival,&fval,&dval); if (len < 5) goto file_err; minlut = ival[2]; ididev[i].lutoff = ival[4]; if (f_wndw[screeno] == 0) { /* connect to display */ dstatus = Xwstinit(0,Xworkst[screeno].name,screeno,fontno,minlut); if (dstatus != II_SUCCESS) goto gen_err; Xworkst[screeno].nolut = ival[0]; Xworkst[screeno].lutsize = ival[1]; Xworkst[screeno].ownlut = ival[3]; /* maybe modified by Xwstinit ... */ } /* get font numbers for small, medium, large font */ if ((len = osaread(fp,record,72)) > 0) { len = CGN_CNVT(record,1,3,fontno,&fval,&dval); /* fontno[4] is special */ if (len < 3) goto file_err; /* we need 3 fonts */ } ididev[i].opened = 1; ididev[i].xsize = devxdim; /* set by display window section */ ididev[i].ysize = devydim; /* set by display window section */ ididev[i].trigger = 0; /* exit trigger is 0 */ ididev[i].inter_mask = 0; ididev[i].n_inter = 0; ididev[i].ncurs = 2; ididev[i].lutsect = 0; /* default to 1. (maybe only) LUT section */ ididev[i].lookup = 0; ididev[i].bar = 0; ididev[i].hcopy = (char *) 0; ididev[i].curswin = -1; ididev[i].link[0] = 0; ididev[i].link[1] = -1; /* ----------------------- */ /* create virtual display */ /* ----------------------- */ if (RGBmode == 1) name[0] = 'T'; /* TrueColor */ else { name[0] = 'P'; /* PseudoColor */ if (RGBmode == 0) name[1] = 'S'; else if (RGBmode == 2) name[1] = 'D'; /* on top of DirectColor */ else { RGBmode = 2; name[1] = 'T'; /* on top of TrueColor */ } } if (f_wndw[screeno] == 0) { /* get fonts + colour maps */ if (ididev[i].devtyp == 'g') f_wndw[screeno] = 2; /* graphics window is first */ else f_wndw[screeno] = 1; /* display window is first */ dstatus = Xwstinit(f_wndw[screeno],name,screeno,fontno,minlut); if (dstatus != II_SUCCESS) goto gen_err; set_wcur(i,-1); /* create all cursor shapes */ if (Xworkst[screeno].lutflag != 0) f_wndw[screeno] = 1; /* we did already everything */ if (Xworkst[screeno].visual == 4) RGBmode = 2; /* emulate Pseudo on DirectColor */ f_RGB[screeno] = RGBmode; } else if (f_wndw[screeno] == 2) { if (ididev[i].devtyp != 'g') /* display window after graphics */ { f_wndw[screeno] = 1; dstatus = Xwstinit(3,name,screeno,fontno,minlut); if (dstatus != II_SUCCESS) goto gen_err; } } RGBmode = f_RGB[screeno]; /* so all windows have same RGBflag */ if (ididev[i].alpno >= 90) { ididev[i].alphx = devxdim-2; /* border width = 1 pixel */ ididev[i].alphy = 50; ididev[i].alphxscal = 512./80.; ididev[i].alphlinsz = 12; /* pixels per line */ m = devydim + ididev[i].alphy + 2; /* add space for alpha subwindow */ dstatus = crea_win(i,devxoff,devyoff,devxdim,m,dspchar); crealph(i,devydim); /* create also the alphanumerics window */ } else { ididev[i].alphy = -2; dstatus = crea_win(i,devxoff,devyoff,devxdim,devydim,dspchar); if (ididev[i].devtyp == 'c') /* cursor window have no alpha mem */ { ididev[con_main].curswin = i; ididev[i].curswin = -con_main; /* keep pointer to main w. */ } } if (dstatus != II_SUCCESS) goto gen_err; sendX(i); /* flush out Xstuff */ x0 = ididev[i].xsize / 2; y0 = ididev[i].ysize / 2; ididev[i].depth = Xworkst[screeno].depth; dstatus = MEMALLERR; for (j=0; jsh = -1; /* sh = -1 : cursor not defined */ curs->col = 0; curs->vis = 0; curs->xpos = x0; curs->ypos = y0; } allbytes = sizeof(struct roi_data); roi = (struct roi_data *) malloc(allbytes); if (roi == II_NULL) goto gen_err; ididev[i].roi = roi; roi->sh = -1; /* roi_sh = -1 : ROI not defined */ roi->col = 0; roi->vis = 0; roi->xmin = x0 - 20; roi->ymin = y0 - 20; roi->xmax = x0 + 20; roi->ymax = y0 + 20; roi->radiusi = 20; roi->radiusm = 0; roi->radiuso = 0; roi->radno = 4; allbytes = sizeof(struct conf_data); conf = (struct conf_data *) malloc(allbytes); if (conf == II_NULL) goto gen_err; ididev[i].confptr = conf; conf->memid = 0; conf->RGBmode = RGBmode; /* get no. of memories + size of GLIST segments */ if ((len = osaread(fp,record,72)) > 0) len = CGN_CNVT(record,1,2,ival,&fval,&dval); if (len < 2) goto file_err; if (RGBmode == 1) k1 = 1; else k1 = ival[0]; gsize = ival[1]; for (k=0; kmemory[k] = mem; if ((len = osaread(fp,record,72)) > 0) len = CGN_CNVT(record,1,3,ival,&fval,&dval); if (len < 3) goto file_err; mem->xsize = ival[0]; mem->ysize = ival[1]; if (ival[2] < 0) mem->depth = ididev[i].depth; else mem->depth = ival[2]; if (ididev[i].devtyp == 'g') mem->type = II_GRAPHIC | II_TEXT; else mem->type = II_IMAGE | II_GRAPHIC | II_TEXT; if (RGBmode > 0) mem->type = mem->type | II_RGB; mem->mmbm = (char *) 0; mem->zmbm = (char *) 0; mem->pixmap = 0; if (k == 0) mem->visibility = 1; /* make first channel visible */ else mem->visibility = 0; clmem(mem); /* set all memory parameters */ if (ididev[i].alpno >= 90) { /* allocate alpha memory */ allbytes = sizeof(struct alph_data); alph = (struct alph_data *) malloc(allbytes); if (alph == II_NULL) goto gen_err; conf->alpmem[k] = alph; for (nr=0; nr<16; nr++) alph->savx[nr] = -1; } if (ididev[i].devtyp == 'g') mem->ittpntr = (ITT_DATA *)0; /* no ITT for graph/cursor windows */ else { allbytes = sizeof(struct itt_data); itt = (struct itt_data *) malloc(allbytes); if (itt == II_NULL) goto gen_err; mem->ittpntr = itt; itt->vis = 0; /* default to ITT visibility off */ for (nr=0; nrval[nr] = nr; } if (gsize <= 0) mem->gpntr = (GLIST *)0; /* no graphics structure */ else { allbytes = sizeof(struct glist); graph = (struct glist *) malloc(allbytes); if (graph == II_NULL) goto gen_err; mem->gpntr = graph; graph->geln = 0; graph->maxpnt = gsize; len = graph->maxpnt/2; allbytes = sizeof(int) * (2*graph->maxpnt + 4*len); /* for x,y */ graph->x = (int *) malloc(allbytes); /* color, lwidth, */ if (graph->x == II_NULL) goto gen_err; graph->y = graph->x + graph->maxpnt; graph->color = graph->y + graph->maxpnt; graph->lwidth = graph->color + len; graph->off = graph->lwidth + len; graph->count = graph->off + len; *(graph->off) = 0; } if (limited > 0) mem->tpntr = (TLIST *)0; else { allbytes = sizeof(struct tlist); txt = (struct tlist *) malloc(allbytes); if (txt == II_NULL) goto gen_err; mem->tpntr = txt; txt->teln = 0; txt->off[0] = 0; } mem->plane_no = 1; } osaclose(fp); /* for graphics window the overlay channel is the image channel itself */ if (ididev[i].devtyp == 'g') { conf->nmem = k1; conf->overlay = conf->memid; } else { conf->nmem = k1 + 1; /* add 1 for overlay channel */ conf->overlay = k1; /* last channel */ /* now also init the structure for the added overlay/graphics channel */ allbytes = sizeof(struct mem_data); mem = (struct mem_data *) malloc(allbytes); if (mem == II_NULL) return(MEMALLERR); conf->memory[k1] = mem; mem->xsize = ival[0]; /* use values of last channel */ mem->ysize = ival[1]; mem->depth = ival[2]; mem->type = II_IMAGE | II_GRAPHIC | II_TEXT; if (RGBmode > 0) mem->type = mem->type | II_RGB; mem->mmbm = (char *) 0; mem->zmbm = (char *) 0; mem->pixmap = 0; mem->visibility = 1; /* we enable overlay right away */ clmem(mem); mem->ittpntr = (ITT_DATA *)0; if (gsize <= 0) mem->gpntr = (GLIST *)0; /* no graphics structure */ else { allbytes = sizeof(struct glist); graph = (struct glist *) malloc(allbytes); if (graph == II_NULL) return(MEMALLERR); mem->gpntr = graph; graph->geln = 0; graph->maxpnt = gsize; len = graph->maxpnt/2; allbytes = sizeof(int) * (2*graph->maxpnt + 4*len); /* for x,y */ graph->x = (int *) malloc(allbytes); /* color, lwidth, */ if (graph->x == II_NULL) return(MEMALLERR); /* off and count */ graph->y = graph->x + graph->maxpnt; graph->color = graph->y + graph->maxpnt; graph->lwidth = graph->color + len; graph->off = graph->lwidth + len; graph->count = graph->off + len; *(graph->off) = 0; } allbytes = sizeof(struct tlist); txt = (struct tlist *) malloc(allbytes); if (txt == II_NULL) return(MEMALLERR); mem->tpntr = txt; txt->teln = 0; txt->off[0] = 0; mem->plane_no = 1; } if (limited != 2) /* not for cursor window */ { for (j=0; jinteractor = II_MOUSE; else loca->interactor = II_KEYB; intdevtable[i].loc[j] = loca; } loc_zero(i); /* reset all locators */ for (j=0; jinteractor = II_MOUSE; else trigg->interactor = II_KEYB; intdevtable[i].trig[j] = trigg; } } if (shadow >= 0) /* if shadow window update owner */ { for (j=0; jwp = 0; bar->vis = 0; /* check if we have own LUT handling */ if ( (limited > 0) || ((Xworkst[screeno].visual != 4) && (Xworkst[screeno].ownlut == 0)) ) return(II_SUCCESS); if (Xworkst[screeno].ownlut == -1) { for (nr=0; nr<256; nr++) /* add LUT offset at least... */ { j = nr + ididev[i].lutoff; if (j > 255) j = 0; Xworkst[screeno].mapin[nr] = j; Xworkst[screeno].mapout[j] = nr; } return(II_SUCCESS); } allbytes = sizeof(struct lut_data); lut = (struct lut_data *) malloc(allbytes); if (lut == II_NULL) return(MEMALLERR); ididev[i].lookup = lut; lut->vis = 1; /* make LUT always visible */ /* send black + white LUT only the very first time */ if (f_lut[screeno] == 1) { float lut0[768]; f_lut[screeno] = 0; len = Xworkst[screeno].lutlen; rval = 1.0 / (len - 1.0); m = len + len; fval = 0.0; for (nr=0; nr