~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/display/libsrc/setcur.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1994-2009 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: midas@eso.org
 
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
.LANGUAGE    C
 
30
.AUTHOR      K. Banse                   IPG-ESO Garching
 
31
.KEYWORDS    Image Display, cursor
 
32
.IDENTIFIER  SETCUR_C
 
33
.PURPOSE     enable/disable fixed cursor(s) of different shapes or 
 
34
             programmable cursors and (optionally) set cursor coordinates
 
35
.ALGORITHM   use IDI interfaces for interacting with the Image Display
 
36
.INPUT/OUTPUT
 
37
   call as   SETCUR_C( dsplay, cursno, forma, colo, coords )
 
38
 
 
39
  input:
 
40
         int display :          Display unit no.
 
41
         int cursno  :          Cursor no. = 0, 1 or 2 for both cursors
 
42
                                           = 3 for two independent cursors
 
43
         int forma   :          actual cursor form no.
 
44
                                if = -1, make cursors/ROI not visible
 
45
                                if = 99, use last defined cursor form + colour
 
46
         int colo    :          cursor colour
 
47
         int *coords :          coordinates
 
48
         
 
49
.RETURNS     nothing
 
50
.COMMENTS    none
 
51
.ENVIRONment MIDAS
 
52
             #include <midas_def.h>   Prototypes for MIDAS interfaces
 
53
             #include <idinumd.h>     Global variables for DISPLAY interfaces
 
54
 
 
55
.VERSIONS    1.00       940425  F -> C conversion, RvH
 
56
.VERSIONS    1.10       941031  cleanup, KB
 
57
 
 
58
 090706         last modif
 
59
------------------------------------------------------------*/
 
60
 
 
61
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
 
62
 
 
63
#define  _POSIX_SOURCE 1
 
64
 
 
65
#include <midas_def.h>
 
66
#include <idinumd.h>
 
67
#include <proto_II.h>
 
68
 
 
69
/*
 
70
 
 
71
*/
 
72
 
 
73
void SETCUR_C(dsplay,cursno,forma,colo,coords)
 
74
int dsplay, cursno, forma, colo, *coords;
 
75
 
 
76
 
 
77
{
 
78
int form, colr, actvals, knul, ibuff[4];
 
79
register int  nr;
 
80
int roiid = 0;                  /* This parameter is not used by IDI */
 
81
int unit = 0;
 
82
 
 
83
 
 
84
if (cursno == 2)                /* handle ROIs */
 
85
   {
 
86
   int   kbuff[8];
 
87
 
 
88
   if (forma == 99)     
 
89
      {
 
90
      (void) SCKRDI("CURSOR",5,4,&actvals,ibuff,&unit,&knul);
 
91
      form = ibuff[0];
 
92
      colr = ibuff[1];
 
93
      }
 
94
   else
 
95
      {
 
96
      form = forma;
 
97
      colr = colo;
 
98
      }
 
99
 
 
100
   if (form < 0)                                     /* clear visibility */
 
101
      (void) IIRSRV_C(dsplay,roiid,0);
 
102
   else 
 
103
      {
 
104
      if (form == 2)                                        /* circ. ROI */
 
105
         (void) IICINR_C(dsplay,-1,colr,*coords,coords[1],coords[2],
 
106
                         coords[3],coords[4],&roiid);
 
107
      else                                                  /* rect. ROI */
 
108
         (void) IIRINR_C(dsplay,-1,colr,*coords,coords[1],coords[2],
 
109
                         coords[3],&roiid);
 
110
 
 
111
      (void) IIRSRV_C(dsplay,roiid,1);
 
112
      (void) SCKWRI("DAZHOLD",&form,16,1,&unit);
 
113
      }
 
114
    
 
115
   for (nr=0; nr<4; nr++) kbuff[nr] = coords[nr];
 
116
   kbuff[4] = kbuff[6] = form;
 
117
   kbuff[5] = kbuff[7] = colr;
 
118
   (void) SCKWRI("CURSOR",kbuff,1,8,&unit);
 
119
   }
 
120
 
 
121
else                            /* handle single cursor */
 
122
   {
 
123
   if (forma == 99)     
 
124
      {
 
125
      (void) SCKRDI("CURSOR",5,4,&actvals,ibuff,&unit,&knul);
 
126
      if ( cursno == 0 )
 
127
         {
 
128
         form = ibuff[0];
 
129
         colr = ibuff[1];
 
130
         }
 
131
      else
 
132
         {
 
133
         form = ibuff[2];
 
134
         colr = ibuff[3];
 
135
         }
 
136
      }
 
137
   else
 
138
      {
 
139
      form = forma;
 
140
      colr = colo;
 
141
      }
 
142
 
 
143
   (void) IICINC_C(dsplay,-1,cursno,form,colr,*coords,coords[1]);
 
144
 
 
145
   if (form >= 0)
 
146
      (void) IICSCV_C(dsplay,cursno,1);
 
147
   else
 
148
      (void) IICSCV_C(dsplay,cursno,0);
 
149
    
 
150
   ibuff[0] = form;
 
151
   ibuff[1] = colr;
 
152
   if (cursno == 0)
 
153
      {
 
154
      (void) SCKWRI("CURSOR",ibuff,5,2,&unit);
 
155
      (void) SCKWRI("CURSOR",coords,1,2,&unit);
 
156
      }
 
157
   else 
 
158
      {
 
159
      (void) SCKWRI("CURSOR",ibuff,7,2,&unit);
 
160
      (void) SCKWRI("CURSOR",coords,3,2,&unit);
 
161
      }
 
162
   }
 
163
 
 
164
 
 
165
/* Update also keyword DAZHOLD */
 
166
 
 
167
ibuff[0] = cursno;
 
168
ibuff[1] = form;
 
169
(void) SCKWRI("DAZHOLD",ibuff,1,2,&unit);
 
170
}
 
171
/*
 
172
 
 
173
*/
 
174
 
 
175
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
176
.COPYRIGHT   (c) 1994 European Southern Observatory
 
177
.IDENTIFIER  CURINF_C
 
178
.LANGUAGE    C
 
179
.AUTHOR      K. Banse                   IPG - ESO Garching
 
180
.KEYWORDS    Image Display, cursor
 
181
.PURPOSE     enable/disable fixed cursor(s) of different shapes or 
 
182
             programmable cursors and (optionally) set cursor coordinates
 
183
.ALGORITHM   use IDI interfaces for interacting with the Image Display
 
184
.INPUT/OUTPUT
 
185
   call as   CURINF_C( dsplay, nocurs, roiflg )
 
186
 
 
187
  input:
 
188
         int display :          Display unit no.
 
189
 
 
190
 output:
 
191
         int *nocurs :          Numberof available cursors -> 1 or 2
 
192
         int *roiflg :          = 1, if ROI is implemented
 
193
         
 
194
.RETURNS     nothing
 
195
 
 
196
.ENVIRONment MIDAS
 
197
#include <midas_def.h>   Prototypes for MIDAS interfaces
 
198
 
 
199
.VERSIONS    1.00       940425  F -> C conversion, RvH
 
200
.VERSIONS    1.10       941031  cleanup, KB
 
201
------------------------------------------------------------*/
 
202
 
 
203
void CURINF_C( dsplay, nocurs, roiflg )
 
204
int dsplay, *nocurs, *roiflg;
 
205
 
 
206
{
 
207
int ncap;
 
208
 
 
209
 
 
210
/* 40 = code for asking no. of cursors */
 
211
 
 
212
(void) IIDQCI_C(dsplay,40,1,nocurs,&ncap);   
 
213
 
 
214
 
 
215
/* 60 = code for asking for roi implementation */
 
216
 
 
217
(void) IIDQCI_C(dsplay,60,1,roiflg,&ncap);
 
218
}
 
219
/*
 
220
 
 
221
*/
 
222
 
 
223
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
224
.IDENTIFIER  GetScrPix
 
225
.LANGUAGE    C
 
226
.AUTHOR      K. Banse                   IPG - ESO Garching
 
227
             031216     creation
 
228
.KEYWORDS    Image Display, cursor
 
229
.PURPOSE     get the screen pixels for a given w.c. or f.p. value
 
230
.ALGORITHM   use keyword IDIMEMI/IDIMEMR to map w.c.s/f.p.s to screen pixels
 
231
.INPUT/OUTPUT
 
232
 call as   GetScrPix(imno,wc_flag,inval,xy_flag,scrpix)
 
233
 
 
234
 input:
 
235
         int imno:      image id
 
236
         int wc_flag:   = 1, inval is world coord value
 
237
                        = 0, inval is frame pixel value
 
238
         float inval:   w.c. or f.p. value 
 
239
         int xy_flag:   = 1, use x-direction
 
240
                        = 2, use y-direction
 
241
                        = 3, use average of x,y-direction
 
242
 
 
243
 output:
 
244
         int *scrpix:   corresponding screen pixels
 
245
 
 
246
 returns:
 
247
        int status:     = 0, if o.k.
 
248
                        > 0, if problems
 
249
 
 
250
.VERSION
 
251
 031217         last modif
 
252
 
 
253
-----------------------------------------------------------*/
 
254
 
 
255
int GetScrPix(imno,wc_flag,inval,xy_flag,scrpix)
 
256
int imno, wc_flag, xy_flag, *scrpix;
 
257
float inval;
 
258
 
 
259
{
 
260
int  stat, iav, kuni, knul;
 
261
int  newpix, idimi[8];
 
262
 
 
263
float rval, idimr[6];
 
264
 
 
265
double  dd1[3], dd2[3], dd3[3];
 
266
 
 
267
 
 
268
 
 
269
dd1[2] = dd2[2] = dd3[2] = 0.0;
 
270
 
 
271
stat = Pixconv("INIT",imno,dd1,dd2,dd3);
 
272
if (stat > 0) return (stat);
 
273
 
 
274
kuni = knul = 0;
 
275
(void) SCKRDI("IDIMEMI",1,7,&iav,idimi,&kuni,&knul);
 
276
/* idimi[1] = SSPX, idimi[2] = SSPY, idimi[5] = SFPX, idimi[6] = SFPY 
 
277
   idimi[3] = NSX, idimi[4] = NSY                                    */
 
278
 
 
279
(void) SCKRDR("IDIMEMR",1,6,&iav,idimr,&kuni,&knul);
 
280
/* idimr[0] = SWCX, idimr[1] = SWCY, idimr[2] = EWCX, idimr[3] = EWCY */
 
281
 
 
282
if (xy_flag == 2)
 
283
   {                                    /* move in y-direction */
 
284
   if (wc_flag == 1)
 
285
      {                         /* use w.c. in y */
 
286
      dd1[0] = (double) idimr[0];
 
287
      if (idimr[3] > idimr[1])          /* ystep > 0 */
 
288
         dd1[1] = (double) (idimr[1] + inval);  /* add offset to y */
 
289
      else                              /* ystep < 0 */
 
290
         dd1[1] = (double) (idimr[1] - inval);  /* add offset to y */
 
291
      stat = Pixconv("WRS",imno,dd1,dd2,dd3);
 
292
      }
 
293
   else
 
294
      {                         /* use f.p. in y */
 
295
      dd1[0] = (double) idimi[5];
 
296
      dd1[1] = (double) (idimi[6] + inval);     /* add f.p.s to y */
 
297
      stat = Pixconv("_RS",imno,dd1,dd2,dd3);
 
298
      }
 
299
 
 
300
   if (stat == 0) 
 
301
      {
 
302
      rval = (float) dd3[1];            /* screen y-pix */
 
303
      newpix = CGN_NINT(rval);
 
304
      *scrpix = newpix - idimi[2];      /* subtract SSPY */
 
305
 
 
306
      /* if (*scrpix > idimi[4]) SCTPUT("screen pixel value > NSY ..."); */
 
307
      }
 
308
   }
 
309
else if (xy_flag == 1)
 
310
   {                                    /* move in x-direction */
 
311
   if (wc_flag == 1)
 
312
      {                         /* use w.c. in x */
 
313
      if (idimr[2] > idimr[0])          /* xstep > 0 */
 
314
         dd1[0] = (double) (idimr[0] + inval);  /* add offset to x */
 
315
      else                              /* xstep < 0 */
 
316
         dd1[0] = (double) (idimr[0] - inval);  /* add offset to x */
 
317
      dd1[1] = (double) idimr[1];
 
318
      stat = Pixconv("WRS",imno,dd1,dd2,dd3);
 
319
      }
 
320
   else
 
321
      {                         /* use f.p. in x */
 
322
      dd1[0] = (double) (idimi[5] + inval);     /* add f.p.s to x */
 
323
      dd1[1] = (double) idimi[6];
 
324
      stat = Pixconv("_RS",imno,dd1,dd2,dd3);
 
325
      }
 
326
 
 
327
   if (stat == 0) 
 
328
      {
 
329
      rval = (float) dd3[0];            /* screen x-pix */
 
330
      newpix = CGN_NINT(rval);
 
331
      *scrpix = newpix - idimi[1];      /* subtract SSPX */
 
332
 
 
333
      /* if (*scrpix > idimi[3]) SCTPUT("screen pixel value > NSX ..."); */
 
334
      }
 
335
   }
 
336
else
 
337
   {                                    /* move in x and y-direction */
 
338
   int  xdif, ydif;
 
339
 
 
340
   if (wc_flag == 1)
 
341
      {                         /* use w.c. in x */
 
342
      if (idimr[2] > idimr[0])          /* xstep > 0 */
 
343
         dd1[0] = (double) (idimr[0] + inval);  /* add offset to x */
 
344
      else                              /* xstep < 0 */
 
345
         dd1[0] = (double) (idimr[0] - inval);  /* add offset to x */
 
346
      dd1[1] = (double) idimr[1];
 
347
      stat = Pixconv("WRS",imno,dd1,dd2,dd3);
 
348
      if (stat != 0) return stat;
 
349
 
 
350
      rval = (float) dd3[0];            /* screen x-pix */
 
351
      newpix = CGN_NINT(rval);
 
352
      xdif = newpix - idimi[1];         /* subtract SSPX */
 
353
 
 
354
      dd1[0] = (double) idimr[0];
 
355
      if (idimr[3] > idimr[1])          /* ystep > 0 */
 
356
         dd1[1] = (double) (idimr[1] + inval);  /* add offset to y */
 
357
      else                              /* ystep < 0 */
 
358
         dd1[1] = (double) (idimr[1] - inval);  /* add offset to y */
 
359
      stat = Pixconv("WRS",imno,dd1,dd2,dd3);
 
360
      }
 
361
 
 
362
   else
 
363
      {                         /* use f.p. in x */
 
364
      dd1[0] = (double) (idimi[5] + inval);     /* add offset to x */
 
365
      dd1[1] = (double) idimi[6];
 
366
      stat = Pixconv("_RS",imno,dd1,dd2,dd3);
 
367
      if (stat != 0) return stat;
 
368
 
 
369
      rval = (float) dd3[0];            /* screen x-pix */
 
370
      newpix = CGN_NINT(rval);
 
371
      xdif = newpix - idimi[1];         /* subtract SSPX */
 
372
 
 
373
      dd1[0] = (double) idimi[5];
 
374
      dd1[1] = (double) (idimi[6] + inval);     /* add offset to y */
 
375
      stat = Pixconv("_RS",imno,dd1,dd2,dd3);
 
376
      }
 
377
 
 
378
   if (stat == 0) 
 
379
      {
 
380
      rval = (float) dd3[1];            /* screen y-pix */
 
381
      newpix = CGN_NINT(rval);
 
382
      ydif = newpix - idimi[2];         /* subtract SSPY */
 
383
 
 
384
      *scrpix = (xdif + ydif) / 2;      /* take mean of x, y difference */
 
385
 
 
386
      /* if (*scrpix > (idimi[3]+idimi[4])/2) 
 
387
            SCTPUT("screen pixel value > (NSX+NSY)/2 ..."); */
 
388
      }
 
389
   }
 
390
 
 
391
return stat;
 
392
}
 
393