summaryrefslogtreecommitdiffstats
path: root/ds9/library/markerdialog.tcl
blob: 1856f65ac8a1ae7ba06ae8e1951b6388fbed9390 (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
#  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 MarkerLoadDialog {} {
    global marker
    global ed
    global current
    global wcs

    set w {.mkd}

    set ed(ok) 0
    set ed(format) $marker(format)
    set ed(load) $marker(load)
    set ed(frame) $current(frame)

    set ed(system) $wcs(system)
    set ed(sky) $wcs(sky)
    set ed(skyformat) $wcs(skyformat)
    AdjustCoordSystem ed system

    DialogCreate $w [msgcat::mc {Load Regions}] ed(ok)

    # Param
    set f [ttk::frame $w.param]

    ttk::label $f.formattitle -text [msgcat::mc {Format}]
    set m $f.formatbutton.menu
    ttk::menubutton $f.formatbutton -textvariable ed(format) -menu $m
    ttk::label $f.coordtitle -text [msgcat::mc {Coordinate System}]
    set ed(cb) $f.coordbutton
    CoordMenuButton $ed(cb) ed system 1 sky skyformat {}
    ttk::radiobutton $f.current -text [msgcat::mc {Load into Current Frame}] \
	-variable ed(load) -value current
    ttk::radiobutton $f.all -text [msgcat::mc {Load into All Frames}] \
	-variable ed(load) -value all

    menu $m
    $m add radiobutton -label {DS9/Funtools} -variable ed(format) -value ds9 \
	-command UpdateMarkerLoadDialog
    $m add radiobutton -label {XML} -variable ed(format) -value xml \
	-command UpdateMarkerLoadDialog
    $m add radiobutton -label {CIAO} -variable ed(format) -value ciao \
	-command UpdateMarkerLoadDialog
    $m add radiobutton -label {SAOtng} -variable ed(format) -value saotng \
	-command UpdateMarkerLoadDialog
    $m add radiobutton -label {SAOimage} -variable ed(format) -value saoimage \
	-command UpdateMarkerLoadDialog
    $m add radiobutton -label {IRAF PROS} -variable ed(format) -value pros \
	-command UpdateMarkerLoadDialog
    $m add radiobutton -label {X Y} -variable ed(format) -value xy \
	-command UpdateMarkerLoadDialog

    grid $f.formattitle $f.formatbutton -padx 2 -pady 2 -sticky w
    grid $f.coordtitle $f.coordbutton -padx 2 -pady 2 -sticky w
    grid $f.current - -padx 2 -pady 2 -sticky w
    grid $f.all - -padx 2 -pady 2 -sticky w

    # Button
    set f [ttk::frame $w.buttons]
    ttk::button $f.ok -text [msgcat::mc {OK}] -command {set ed(ok) 1} \
	-default active 
    ttk::button $f.cancel -text [msgcat::mc {Cancel}] -command {set ed(ok) 0}
    pack $f.ok $f.cancel -side left -expand true -padx 2 -pady 4

    bind $w <Return> {set ed(ok) 1}

    # Fini
    ttk::separator $w.sep -orient horizontal
    pack $w.buttons $w.sep -side bottom -fill x
    pack $w.param -side top -fill both -expand true

    UpdateMarkerLoadDialog

    DialogCenter $w 
    DialogWait $w ed(ok)
    DialogDismiss $w

    if {$ed(ok)} {
	set marker(format) $ed(format)
	set marker(system) $ed(system)
	set marker(sky) $ed(sky)
	set marker(skyformat) $ed(skyformat)
	set marker(load) $ed(load)
    }

    set rr $ed(ok)
    unset ed
    return $rr
}

proc UpdateMarkerLoadDialog {} {
    global ed
    global current

    set mm $ed(cb).menu
    set ed(frame) $current(frame)
    CoordMenuEnable $mm ed system 1 sky skyformat

    switch -- $ed(format) {
	xy {$ed(cb) configure -state normal}
	default {$ed(cb) configure -state disabled}
    }

    AdjustCoordSystem ed system
    CoordMenuButtonCmd ed system sky {}
}

proc MarkerSaveDialog {title} {
    global marker
    global ed
    global current
    global wcs

    set w {.mkd}

    set ed(ok) 0
    set ed(format) $marker(format)
    set ed(frame) $current(frame)

    set ed(system) $wcs(system)
    set ed(sky) $wcs(sky)
    set ed(skyformat) $wcs(skyformat)
    AdjustCoordSystem ed system

    DialogCreate $w $title ed(ok)

    # Param
    set f [ttk::frame $w.param]

    ttk::label $f.formattitle -text [msgcat::mc {Format}]
    set m $f.formatbutton.menu
    ttk::menubutton $f.formatbutton -textvariable ed(format) -menu $m
    ttk::label $f.coordtitle -text [msgcat::mc {Coordinate System}]
    set ed(cb) $f.coordbutton

    CoordMenuButton $ed(cb) ed system 1 sky skyformat UpdateMarkerSaveDialog

    menu $m
    $m add radiobutton -label {DS9/Funtools} -variable ed(format) -value ds9 \
	-command UpdateMarkerSaveDialog
    $m add radiobutton -label {XML} -variable ed(format) -value xml \
	-command UpdateMarkerSaveDialog
    $m add radiobutton -label {CIAO} -variable ed(format) -value ciao \
	-command UpdateMarkerSaveDialog
    $m add radiobutton -label {SAOtng} -variable ed(format) -value saotng \
	-command UpdateMarkerSaveDialog
    $m add radiobutton -label {SAOimage} -variable ed(format) -value saoimage \
	-command UpdateMarkerSaveDialog
    $m add radiobutton -label {IRAF PROS} -variable ed(format) -value pros \
	-command UpdateMarkerSaveDialog
    $m add radiobutton -label {X Y} -variable ed(format) -value xy \
	-command UpdateMarkerSaveDialog

    grid $f.formattitle $f.formatbutton -padx 2 -pady 2 -sticky w
    grid $f.coordtitle $f.coordbutton -padx 2 -pady 2 -sticky w

    # Button
    set f [ttk::frame $w.buttons]
    ttk::button $f.ok -text [msgcat::mc {OK}] -command {set ed(ok) 1} \
	-default active 
    ttk::button $f.cancel -text [msgcat::mc {Cancel}] -command {set ed(ok) 0}
    pack $f.ok $f.cancel -side left -expand true -padx 2 -pady 4

    bind $w <Return> {set ed(ok) 1}

    # Fini
    ttk::separator $w.sep -orient horizontal
    pack $w.buttons $w.sep -side bottom -fill x
    pack $w.param -side top -fill both -expand true

    UpdateMarkerSaveDialog

    DialogCenter $w 
    DialogWait $w ed(ok)
    DialogDismiss $w

    if {$ed(ok)} {
	set marker(format) $ed(format)
	set marker(system) $ed(system)
	set marker(sky) $ed(sky)
	set marker(skyformat) $ed(skyformat)
    }

    set rr $ed(ok)
    unset ed
    return $rr
}

proc UpdateMarkerSaveDialog {} {
    global ed
    global current

    set mm $ed(cb).menu
    set ed(frame) $current(frame)
    CoordMenuEnable $mm ed system 1 sky skyformat

    switch -- $ed(format) {
	ds9 -
	xml -
	xy {}

	ciao {
	    switch -- $ed(system) {
		detector -
		amplifier -
		physical -
		image {set ed(system) physical}
		wcs -
		default {set ed(system) wcs}
	    }

	    set ed(sky) fk5
	    set ed(skyformat) sexagesimal

	    $mm entryconfig [msgcat::mc {Multiple WCS}] -state disabled
	    $mm entryconfig [msgcat::mc {Image}] -state disabled
	    $mm entryconfig [msgcat::mc {Amplifier}] -state disabled
	    $mm entryconfig [msgcat::mc {Detector}] -state disabled

	    $mm entryconfig [msgcat::mc {FK4}] -state disabled
	    $mm entryconfig [msgcat::mc {ICRS}] -state disabled
	    $mm entryconfig [msgcat::mc {Galactic}] -state disabled
	    $mm entryconfig [msgcat::mc {Ecliptic}] -state disabled

	    $mm entryconfig [msgcat::mc {Degrees}] -state disabled
	}

	saotng {
	    switch -- $ed(system) {
		detector -
		amplifier -
		image -
		physical {set ed(system) image}
		wcs -
		default {set ed(system) wcs}
	    }

	    $mm entryconfig [msgcat::mc {Multiple WCS}] -state disabled
	    $mm entryconfig [msgcat::mc {Physical}] -state disabled
	    $mm entryconfig [msgcat::mc {Amplifier}] -state disabled
	    $mm entryconfig [msgcat::mc {Detector}] -state disabled
	}

	saoimage {
	    set ed(system) image

	    $mm entryconfig [msgcat::mc {WCS}] -state disabled
	    $mm entryconfig [msgcat::mc {Multiple WCS}] -state disabled
	    $mm entryconfig [msgcat::mc {Physical}] -state disabled
	    $mm entryconfig [msgcat::mc {Amplifier}] -state disabled
	    $mm entryconfig [msgcat::mc {Detector}] -state disabled

	    $mm entryconfig [msgcat::mc {FK4}] -state disabled
	    $mm entryconfig [msgcat::mc {FK5}] -state disabled
	    $mm entryconfig [msgcat::mc {ICRS}] -state disabled
	    $mm entryconfig [msgcat::mc {Galactic}] -state disabled
	    $mm entryconfig [msgcat::mc {Ecliptic}] -state disabled

	    $mm entryconfig [msgcat::mc {Degrees}] -state disabled
	    $mm entryconfig {Sexagesimal} -state disabled
	}

	pros {
	    switch -- $ed(system) {
		detector -
		physical -
		amplifier {set ed(system) physical}
		image {}
		wcs -
		default {set ed(system) wcs}
	    }
	    if {$ed(sky) == {icrs}} {
		set ed(sky) fk5
	    }

	    $mm entryconfig [msgcat::mc {Multiple WCS}] -state disabled
	    $mm entryconfig [msgcat::mc {Amplifier}] -state disabled
	    $mm entryconfig [msgcat::mc {Detector}] -state disabled

	    $mm entryconfig [msgcat::mc {ICRS}] -state disabled
	}
    }

    AdjustCoordSystem ed system
    CoordMenuButtonCmd ed system sky {}
}