summaryrefslogtreecommitdiffstats
path: root/ds9/library/iexam.tcl
blob: aeea7569bd7ef94dfa27c9dfe52322444c951137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#  Copyright (C) 1999-2018
#  Smithsonian Astrophysical Observatory, Cambridge, MA, USA
#  For conditions of distribution and use, see copyright notice in "copyright"

package provide DS9 1.0

proc IExamDef {} {
    global iexam
    
    set iexam(button) 0
    set iexam(key) 0
    set iexam(any) 0
    set iexam(frame) {}
    set iexam(x) {}
    set iexam(y) {}
    set iexam(event) {}
    set iexam(mode) {}
}

proc IExamButton {which xx yy} {
    global iexam
    global imarker

    if {$iexam(button) || $iexam(any)} {
	# we need this cause MarkerMotion maybe called, 
	# and we don't want it
	set imarker(motion) none
	set imarker(handle) -1

	set iexam(frame) $which
	set iexam(x) $xx
	set iexam(y) $yy

	if {$iexam(any)} {
	    set iexam(event) {<1>}
	}
	set iexam(button) 0
	set iexam(any) 0
    }
}

proc IExamKey {which K xx yy} {
    global iexam

    if {$iexam(key) || $iexam(any)} {
	set iexam(frame) $which
	set iexam(x) $xx
	set iexam(y) $yy
	set iexam(event) $K

	set iexam(key) 0
	set iexam(any) 0
    }
}

proc ProcessSendIExamCmd {proc id param {sock {}} {fn {}}} {
    global parse
    set parse(proc) $proc
    set parse(id) $id

    global iexam
    global icursor
    global current
    set iexam(frame) {}
    set iexam(x) {}
    set iexam(y) {}
    set iexam(event) {}
    set iexam(mode) $current(mode)

    set current(mode) iexam

    set iexam(button) 1
    set iexam(key) 0
    set iexam(any) 0

    global cvarname
    set cvarname {iexam(button)}

    # turn on blinking cursor
    set icursor(timer) 1
    CursorTimer

    iexamsend::YY_FLUSH_BUFFER
    iexamsend::yy_scan_string $param
    iexamsend::yyparse

    # turn off blinking cursor
    set icursor(timer) 0

    set current(mode) $iexam(mode)

    set iexam(button) 0
    set iexam(key) 0

    set iexam(frame) {}
    set iexam(x) {}
    set iexam(y) {}
    set iexam(event) {}
    set iexam(mode) {}

    unset cvarname
}

proc IExamSendCmdDest {which} {
    global iexam
    global cvarname

    set iexam($which) 1
    set cvarname "iexam($which)"
}

proc IExamSendCmdData {ww hh} {
    global iexam
    
    global cvarname
    vwait $cvarname
    ProcessSendCmdTxt "$iexam(event) [$iexam(frame) get data canvas $iexam(x) $iexam(y) $ww $hh]"
}

proc IExamSendCmdCoord {sys sky skyformat} {
    global iexam

    global cvarname
    vwait $cvarname
    ProcessSendCmdTxt "$iexam(event) [$iexam(frame) get coordinates $iexam(x) $iexam(y) $sys $sky $skyformat]"
}

proc IExamSendCmdMacro {cmd} {
    global iexam

    global cvarname
    vwait $cvarname

    # $width,$height,$depth,$bitpix
    ParseXYBitpixMacro cmd $iexam(frame)

    # $filename[$regions]
    ParseFilenameRegionMacro cmd $iexam(frame)

    # $filename
    ParseFilenameMacro cmd $iexam(frame)

    # $regions
    ParseRegionMacro cmd $iexam(frame)

    # $env
    ParseEnvMacro cmd

    # $pan
    ParsePanMacro cmd $iexam(frame)

    # $value
    ParseValueMacro cmd $iexam(frame) $iexam(x) $iexam(y)

    # $x,$y
    ParseXYMacro cmd $iexam(frame) $iexam(x) $iexam(y)

    # $z
    ParseZMacro cmd $iexam(frame)

    ProcessSendCmdTxt "$iexam(event) $cmd"
}

proc ProcessSendIExamCmdOld {proc id param {sock {}} {fn {}}} {
    global iexam

    global icursor
    global current

    set iexam(frame) {}
    set iexam(x) {}
    set iexam(y) {}
    set iexam(event) {}
    set iexam(mode) $current(mode)

    set current(mode) iexam

    set iexam(button) 0
    set iexam(key) 0
    set iexam(any) 0

    # turn on blinking cursor
    set icursor(timer) 1
    CursorTimer

    switch -- [string tolower [lindex $param 0]] {
	button {
	    set iexam(button) 1
	    set varname {iexam(button)}
	    set param [join [lreplace $param 0 0]]
	}
	key {
	    set iexam(key) 1
	    set varname {iexam(key)}
	    set param [join [lreplace $param 0 0]]
	}
	any {
	    set iexam(any) 1
	    set varname {iexam(any)}
	    set param [join [lreplace $param 0 0]]
	}
	default {
	    set iexam(button) 1
	    set varname {iexam(button)}
	}
    }

    switch -- [string tolower [lindex $param 0]] {
	value -
	data {
	    vwait $varname
	    set w [lindex $param 1]
	    set h [lindex $param 2]
	    if {$w == {}} {
		set w 1
	    }
	    if {$h == {}} {
		set h 1
	    }
	    $proc $id "$iexam(event) [$iexam(frame) get data canvas $iexam(x) $iexam(y) $w $h]\n"
	}
	coordinate {
	    set sys [lindex $param 1]
	    set sky [lindex $param 2]
	    set skyformat [lindex $param 3]
	    switch -- $skyformat {
		{} {set skyformat degrees}
	    }
	    switch -- $sky {
		{} {set sky fk5}
	    }
	    switch -- $sys {
		{} {set sys physical}
		fk4 -
		fk5 -
		icrs -
		galactic -
		ecliptic {set sky $sys; set sys wcs}
	    }

	    vwait $varname
	    $proc $id "$iexam(event) [$iexam(frame) get coordinates $iexam(x) $iexam(y) $sys $sky $skyformat]\n"
	}
	{} {
	    vwait $varname
	    $proc $id "$iexam(event) [$iexam(frame) get coordinates $iexam(x) $iexam(y) image fk5 degrees]\n"
	}
	default {
	    vwait $varname
	    set cmd $param

	    # $width,$height,$depth,$bitpix
	    ParseXYBitpixMacro cmd $iexam(frame)

	    # $filename[$regions]
	    ParseFilenameRegionMacro cmd $iexam(frame)

	    # $filename
	    ParseFilenameMacro cmd $iexam(frame)

	    # $regions
	    ParseRegionMacro cmd $iexam(frame)

	    # $env
	    ParseEnvMacro cmd

	    # $pan
	    ParsePanMacro cmd $iexam(frame)

	    # $value
	    ParseValueMacro cmd $iexam(frame) $iexam(x) $iexam(y)

	    # $x,$y
	    ParseXYMacro cmd $iexam(frame) $iexam(x) $iexam(y)

	    # $z
	    ParseZMacro cmd $iexam(frame)

	    $proc $id "$iexam(event) $cmd\n"
	}
    }

    # turn off blinking cursor
    set icursor(timer) 0

    set current(mode) $iexam(mode)

    set iexam(button) 0
    set iexam(key) 0

    set iexam(frame) {}
    set iexam(x) {}
    set iexam(y) {}
    set iexam(event) {}
    set iexam(mode) {}
}