summaryrefslogtreecommitdiffstats
path: root/ds9/library/iexam.tcl
blob: a2f52019187e5589ddf35926230e1661b58319b6 (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
#  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} {
    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) {}
}