summaryrefslogtreecommitdiffstats
path: root/ds9/library/coord.tcl
blob: 15f0dba5eb050dcc5539759e6b9a65c47960bb53 (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
#  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 CoordDef {} {
    global pcoord

    # prefs only
    set pcoord(filename) 0
    set pcoord(value) 1
    set pcoord(image) 1
    set pcoord(physical) 0
    set pcoord(amplifier) 0
    set pcoord(detector) 0
    set pcoord(wcs) 1
    foreach l {a b c d e f g h i j k l m n o p q r s t u v w x y z} {
	set "pcoord(wcs$l)" 0
    }
}

proc SetCoordSystem {varname system sky skyformat} {
    upvar #0 $varname var
    global $varname

    global current
    switch $var(system) {
	image -
	physical -
	detector -
	amplifier {}
	default {
	    if {$current(frame) != {}} {
		set rr [$current(frame) get wcs]
		set var($system) [lindex $rr 0]
		if {$sky != {}} {
		    set var($sky) [lindex $rr 1]
		}
		if {$skyformat != {}} {
		    set var($skyformat) [lindex $rr 2]
		}
	    }
	}
    }
}

proc AdjustCoordSystem {varname system} {
    upvar #0 $varname var
    global $varname

    global current
    switch -- $var($system) {
	image -
	physical -
	amplifier -
	detector {}
	wcs {
	    if {$current(frame) != {}} {
		if {![$current(frame) has wcs $var($system)]} {
		    set ${varname}($system) physical
		}
	    }
	}
	default {
	    if {$current(frame) != {}} {
		if {![$current(frame) has wcs $var($system)]} {
		    if {[$current(frame) has wcs wcs]} {
			set ${varname}($system) wcs
		    } else {
			set ${varname}($system) physical
		    }
		}
	    }
	}
    }
}

proc AdjustCoordSystem3d {varname system} {
    upvar #0 $varname var
    global $varname

    global current
    switch -- $var($system) {
	image {}
	wcs {
	    if {$current(frame) != {}} {
		if {![$current(frame) has wcs 3d $var($system)]} {
		    set ${varname}($system) image
		}
	    }
	}
	default {
	    if {$current(frame) != {}} {
		if {![$current(frame) has wcs 3d $var($system)]} {
		    if {[$current(frame) has wcs wcs]} {
			set ${varname}($system) wcs
		    } else {
			set ${varname}($system) image
		    }
		}
	    }
	}
    }
}

proc DisplayCoordDialog {which x y} {
    global pcoord
    global wcs

    set r {}

    if {$pcoord(filename)} {
	append r "[$which get fits file name full]"
    }

    foreach l {{} a b c d e f g h i j k l m n o p q r s t u v w x y z} {
	if {"$pcoord(wcs$l)" && [$which has wcs "wcs$l"]} {
	    set cd "[$which get coordinates $x $y wcs$l $wcs(sky) $wcs(skyformat)]"

	    if {[$which has wcs equatorial "wcs$l"]} {
		append r " [lindex $cd 0] [lindex $cd 1] $wcs(sky)"
	    } else {
		set name [$which get wcs name "wcs$l"]
		if {$name != {}} {
		    append r " [lindex $cd 0] [lindex $cd 1] $name"
		} else {
		    append r " [lindex $cd 0] [lindex $cd 1] [lindex $cd 3]"
		}
	    }
	}
    }

    if {$pcoord(detector) && [$which has detector]} {
	append r " [$which get coordinates $x $y detector] detector"
    }

    if {$pcoord(amplifier) && [$which has amplifier]} {
	append r " [$which get coordinates $x $y amplifier] amplifier"
    }

    if {$pcoord(physical) && [$which has physical]} {
	append r " [$which get coordinates $x $y physical] physical"
    }

    if {$pcoord(image)} {
	append r " [$which get coordinates $x $y image]"
    }

    if {$pcoord(value)} {
	append r " [$which get value canvas $x $y]"
    }

    append r " \n"

    SimpleTextDialog coordtxt [msgcat::mc {Coordinates}] \
	80 20 append bottom "$r"
}

proc PrefsDialogCoord {} {
    global dprefs

    set w $dprefs(tab)

    $dprefs(list) insert end [msgcat::mc {Print Coordinates}]
    lappend dprefs(tabs) [ttk::frame $w.coord]

    # Print
    set f [ttk::labelframe $w.coord.print -text [msgcat::mc {Print}]]

    ttk::checkbutton $f.filename -text [msgcat::mc {Filename}] \
	-variable pcoord(filename)
    ttk::checkbutton $f.value -text [msgcat::mc {Value}] \
	-variable pcoord(value)
    ttk::checkbutton $f.wcs -text [msgcat::mc {WCS}] -variable pcoord(wcs)
    ttk::menubutton $f.mwcs -text [msgcat::mc {Multiple WCS}] -menu $f.mwcs.menu

    ttk::checkbutton $f.image -text [msgcat::mc {Image}] \
	-variable pcoord(image)
    ttk::checkbutton $f.physical -text [msgcat::mc {Physical}] \
	-variable pcoord(physical)
    ttk::checkbutton $f.amplifier -text [msgcat::mc {Amplifier}] \
	-variable pcoord(amplifier)
    ttk::checkbutton $f.detector -text [msgcat::mc {Detector}] \
	-variable pcoord(detector)

    set m $f.mwcs.menu
    menu $m
    foreach l {a b c d e f g h i j k l m n o p q r s t u v w x y z} {
	$m add checkbutton -label "[msgcat::mc {WCS}] $l" \
	    -variable "pcoord(wcs$l)"
    }

    grid $f.filename -padx 2 -pady 2 -sticky w
    grid $f.value -padx 2 -pady 2 -sticky w
    grid $f.wcs $f.mwcs -padx 2 -pady 2 -sticky w
    grid $f.image -padx 2 -pady 2 -sticky w
    grid $f.physical -padx 2 -pady 2 -sticky w
    grid $f.amplifier -padx 2 -pady 2 -sticky w
    grid $f.detector -padx 2 -pady 2 -sticky w

    pack $w.coord.print -side top -fill both -expand true
}