Debian Codegraph @

libsrc/display/dco.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2007 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 .IDENTIFIER DCO
30 .LANGUAGE C
31 .AUTHOR K. Banse, R.M. van Hees IPG-ESO Garching
32 .KEYWORDS High level image display interfaces
33 .PURPOSE Takes care of opening and closing of display devices
34 .ALGORITHM updates display keywords and global variables
35 uses IDI interfaces
36 .COMMENTS holds high level interfaces: DCOPEN, DCCLOS, DCGICH & DCPICH
37 static functions : OpenIDI & CloseIDI
38
39 .ENVIRONment MIDAS and IDI
40 #include <midas_def.h> Prototypes for MIDAS interfaces
41 #include <idinumd.h> Global variables for DISPLAY interfaces
42
43 .VERSIONS 1.00 9406012 created from opnidi.c by R.M. van Hees
44
45 071005 last modif
46 ------------------------------------------------------------*/
47
48 /* Define _POSIX_SOURCE to indicate that this is a POSIX program */
49
50 #define _POSIX_SOURCE 1
51
52 /* definition of the used functions in this module */
53
54 #include <stdio.h>
55 #include <string.h>
56
57 #include <idi.h>
58 #include <idinumd.h>
59 #include <proto_idi.h>
60 #include <midas_def.h>
61
62
63 char dzmemc[IDI_CLEN];
64 int dzdev[50];
65 int dzmemi[IDI_ILEN];
66 float dzmemr[IDI_RLEN];
67
68 static int YesIdi = 0;
69
70 /*
71
72 */
73
74 /*++++++++++++++++++++++++++++++
75 .IDENTIFIER OpenIDI
76 .PURPOSE opens a image display, NO updating of global variables
77 .INPUT/OUTPUT
78 call as stat = OpenIDI( munit, disp_id, flag, dspinfo );
79
80 input:
81 char *munit : Midas unit (2 chars)
82 char *disp_id : display id (currently 1 char)
83 int flag : 1 for display window
84 2 for graphics window
85 3 for zoom window (display)
86 output:
87 int *dspinfo : display no. + create_flag
88
89 .RETURNS status: 0 if o.k.
90 retstat (!= 0) of idiserver if problems
91 .COMMENTS static function
92 --------------------------------*/
93 #ifdef __STDC__
94 static int OpenIDI(char *munit,char *disp_id,int flag,int *dspinfo)
95 #else
96 static int OpenIDI(munit,disp_id,flag,dspinfo)
97 char *munit, *disp_id;
98 int flag, *dspinfo;
99 #endif
100
101 {
102 int stat;
103
104 char file[16];
105
106 /*
107 * build up name `sxwXYnZ'
108 */
109
110 (void) strcpy( file, "sxw " );
111 file[3] = munit[0];
112 file[4] = munit[1];
113
114 if ( flag == 2 ) /* graphics window */
115 file[6] = 'g';
116 else if ( flag == 3 ) /* zoom window */
117 file[6] = 'z';
118 else /* display window */
119 file[6] = '\0';
120
121 file[5] = *disp_id;
122
123 if ( (stat = IIDOPN_C(file,dspinfo)) == 0 )
124 dspinfo[1] = 2; /* new window created */
125 else if (stat == ENTRYFND)
126 dspinfo[1] = 1; /* existing window opened */
127 else
128 return stat; /* must be != 0 */
129
130 YesIdi = 1;
131
132 return 0;
133 }
134
135 /*
136
137 */
138
139 /*++++++++++++++++++++++++++++++
140 .IDENTIFIER CloseIDI
141 .PURPOSE Closes a image display, NO updating of display keywords
142 .INPUT/OUTPUT
143 call as stat = CloseIDI( dispno );
144
145 input:
146 int dispno : display number
147
148 .RETURNS status: 0 if o.k.
149 -1 no window to close
150 -2 window died in the meantime
151
152 .COMMENTS static function
153 --------------------------------*/
154 #ifdef __STDC__
155 static int CloseIDI(int dispno)
156 #else
157 static int CloseIDI(dispno)
158 int dispno;
159 #endif
160
161 {
162 if ( YesIdi == 0 ) return (-1); /* there was no connection with server */
163
164 if ( IIDCLO_C(dispno) == DEVNOTOP )
165 return -2; /* window died in the meantime */
166 else
167 return 0;
168 }
169
170 /*
171
172 */
173
174 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
175 .IDENTIFIER DCOPEN
176 .PURPOSE connect to IDI device + save info in keyword IDIDEV
177 .INPUT/OUTPUT
178 call as DCOPEN( flag );
179 input:
180 int flag : 1 for display window
181 2 for graphics window
182 3 for zoom window (display)
183 .RETURNS nothing
184 -----------------------------------------------------------*/
185 #ifdef __STDC__
186 void DCOPEN(int flag)
187 #else
188 void DCOPEN(flag)
189 int flag;
190 #endif
191
192 {
193 int null, unit, iav;
194 int dspinfo[2];
195 int nconf, xdev, ydev, depthdev, maxlutn, maxittn, kk;
196
197 char dspid, midunit[2], cbuf[16];
198
199 static char *info_mes1 =
200 "display x-,y-size changed to %d, %d - reload last image...\n";
201
202
203
204 (void) SCKRDI("IDIDEV",1,25,&iav,dzdev,&unit,&null);
205
206 /* if NULL device, stop entire application */
207 if (dzdev[17] == -1) SCSEPI();
208
209
210 (void) SCKRDC("MID$SESS",1,1,12,&iav,cbuf,&unit,&null);
211 midunit[0] = cbuf[10];
212 midunit[1] = cbuf[11];
213
214 if ( flag == 2 ) /* graphics w. */
215 dspid = cbuf[6];
216 else /* display or zoom window */
217 dspid = cbuf[5];
218 if ( dspid == ' ' ) dspid = '0';
219
220 iav = OpenIDI(midunit,&dspid,flag,dspinfo);
221 if (iav != 0) /* report error back */
222 SCETER(iav,"DCOPEN: can not open display...");
223
224 QDZFND = dspinfo[1];
225 if (flag == 2) /* graphics window */
226 GDSPNO = *dspinfo;
227 else if (flag == 3) /* zoom window */
228 ZDSPNO = *dspinfo;
229 else
230 QDSPNO = *dspinfo;
231
232
233 /* get size of display - may be it has changed in the meantime */
234
235 (void) IIDQDV_C(*dspinfo,&nconf,&xdev,&ydev,&depthdev,&maxlutn,&maxittn,&kk);
236
237 if (flag == 1) /* display window */
238 {
239 if ((xdev != QDSZX) || (ydev != QDSZY))
240 {
241 (void) printf(info_mes1,xdev,ydev);
242 if ((xdev > QDSZX) || (ydev > QDSZY))
243 {
244 QMSZX = xdev; /* update also the memory size */
245 QMSZY = ydev;
246 }
247 QDSZX = xdev; /* update the display size */
248 QDSZY = ydev;
249 }
250 }
251
252 else if ( flag == 3 ) /* zoom window */
253 {
254 if ((xdev != QXAUX) || (ydev != QYAUX))
255 {
256 QXAUX = xdev; /* update also the memory size */
257 QYAUX = ydev;
258 }
259 }
260
261 (void) SCKWRI("IDIDEV",dzdev,1,25,&unit); /* save device info */
262
263 if ((flag != 2) && (QIMCH != QOVCH))
264 {
265 iav = DCGICH(QIMCH); /* get also the image memory info */
266 if (iav < 0) SCETER(69,"DCOPEN: IDIserver out of sync...");
267 }
268 }
269
270 /*
271
272 */
273
274 /*++++++++++++++++++++++++++++++
275 .IDENTIFIER DCCLOS
276 .PURPOSE close display & save global array dzdev
277 .INPUT/OUTPUT
278 call as DAZOUT_C( dispno )
279
280 input:
281 int dispno : display number
282
283 .RETURNS nothing
284 ------------------------------*/
285 #ifdef __STDC__
286 void DCCLOS(int dispno )
287 #else
288 void DCCLOS(dispno)
289 int dispno;
290 #endif
291
292 {
293 int unit;
294
295 if ( CloseIDI( dispno ) != 0 )
296 SCETER( 1, "DAZOUT: FATAL display was not opened..." );
297 else
298 (void) SCKWRI( "IDIDEV", dzdev, 1, 26, &unit );
299 }
300
301 /*
302
303 */
304
305 /*++++++++++++++++++++++++++++++
306 .IDENTIFIER DCGICH
307 .PURPOSE return info about given channel in the image display
308 .INPUT/OUTPUT
309 call as stat = DCGICH( chanl );
310 input:
311 int chanl : channel (image memory) number
312 .RETURNS status: 0 = o.k.
313 1 = nothing loaded into channel
314 -1 = something wrong at server side!
315
316 --------------------------------*/
317 #ifdef __STDC__
318 int DCGICH(int chanl)
319 #else
320 int DCGICH(chanl)
321 int chanl;
322 #endif
323
324 {
325 int stat, unit;
326
327 /* get loaded frame, related integer, real info */
328
329 stat = IIEGDB_C(QDSPNO,1,chanl,dzmemc,dzmemi,dzmemr);
330 if (stat != II_SUCCESS) return (-1);
331
332 SCROLY += (QDSZY-1); /* yscroll => top of display */
333 (void) SCKWRC("IDIMEMC",1,dzmemc,1,IDI_CLEN,&unit);
334 (void) SCKWRI("IDIMEMI",dzmemi,1,IDI_ILEN,&unit);
335 (void) SCKWRR("IDIMEMR",dzmemr,1,IDI_RLEN,&unit);
336
337 if (SOURCE == 0) /* nothing loaded */
338 return 1;
339 else
340 return 0;
341 }
342
343 /*
344
345 */
346
347 /*++++++++++++++++++++++++++++++
348 .IDENTIFIER DCPICH
349 .PURPOSE writes info about given channel in the image display
350 .INPUT/OUTPUT
351 call as DCPICH(chanl)
352 input:
353 int chanl : channel (image memory) number
354 .RETURNS nothing
355 --------------------------------*/
356 #ifdef __STDC__
357 void DCPICH(int chanl)
358 #else
359 void DCPICH(chanl)
360 int chanl;
361 #endif
362
363 {
364 int unit;
365
366 (void) IIESDB_C(QDSPNO,1,chanl,dzmemc,dzmemi,dzmemr); /* SCROLY not used.. */
367
368 (void) SCKWRC("IDIMEMC",1,dzmemc,1,IDI_CLEN,&unit);
369 (void) SCKWRI("IDIMEMI",dzmemi,1,IDI_ILEN,&unit);
370 (void) SCKWRR("IDIMEMR",dzmemr,1,IDI_RLEN,&unit);
371 }
372
373 /*
374
375 */
376
377 /*++++++++++++++++++++++++++++++
378 .IDENTIFIER DCSINF
379 .PURPOSE send info to IDI Server
380 .INPUT/OUTPUT
381 call as DCSINF(dispno,option,ibuf,rbuf,cbuf)
382 input:
383 int option: 1 set parent window
384 2 do XQueryTree
385 3 do MapSubwindows
386 4 do XGetWindowAttributes + XGetGeometry
387 .RETURNS nothing
388 --------------------------------*/
389 #ifdef __STDC__
390 int DCSINF(int dispno, int option, int* ibuf, float* rbuf, char* cbuf)
391 #else
392 int DCSINF(dispno,option,ibuf,rbuf,cbuf)
393
394 int dispno, option, *ibuf;
395 float *rbuf;
396 char *cbuf;
397 #endif
398
399 {
400 int auxid;
401
402
403
404 option += 100; /* option = 1, already used */
405 auxid = *ibuf;
406
407 (void) IIESDB_C(dispno,option,auxid,cbuf,&ibuf[1],rbuf);
408
409 return 0;
410 }
411
412
413
414