summaryrefslogtreecommitdiffstats
path: root/ds9/library/mzoom.tcl
blob: a1235c81dba9d0781e2a9d9dcc2d37bb97e368f8 (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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#  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

# Menus

proc ZoomMainMenu {} {
    global ds9

    menu $ds9(mb).zoom
    $ds9(mb).zoom add command -label [msgcat::mc {Center Image}] \
	-command CenterCurrentFrame
    $ds9(mb).zoom add checkbutton -label [msgcat::mc {Align}] \
	-variable current(align) -command AlignWCSFrame
    $ds9(mb).zoom add separator
    $ds9(mb).zoom add command -label [msgcat::mc {Zoom In}] \
	-command {Zoom 2 2}
    $ds9(mb).zoom add command -label [msgcat::mc {Zoom Out}] \
	-command {Zoom .5 .5}
    $ds9(mb).zoom add command -label [msgcat::mc {Zoom Fit}] \
	-command ZoomToFit
    $ds9(mb).zoom add separator
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 1/32" \
	-variable current(zoom) -value {0.03125 0.03125} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 1/16" \
	-variable current(zoom) -value {0.0625 0.0625}  -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 1/8" \
	-variable current(zoom) -value {0.125 0.125}  -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 1/4" \
	-variable current(zoom) -value {0.25 0.25} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 1/2" \
	-variable current(zoom) -value {0.5 0.5} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 1" \
	-variable current(zoom) -value {1 1} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 2" \
	-variable current(zoom) -value {2 2} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 4" \
	-variable current(zoom) -value {4 4} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 8" \
	-variable current(zoom) -value {8 8} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 16" \
	-variable current(zoom) -value {16 16} -command ChangeZoom
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Zoom}] 32" \
	-variable current(zoom) -value {32 32} -command ChangeZoom
    $ds9(mb).zoom add separator
    $ds9(mb).zoom add radiobutton -label [msgcat::mc {None}] \
	-variable current(orient) -value none -command ChangeOrient
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Invert}] X" \
	-variable current(orient) -value x -command ChangeOrient
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Invert}] Y" \
	-variable current(orient) -value y -command ChangeOrient
    $ds9(mb).zoom add radiobutton -label "[msgcat::mc {Invert}] XY" \
	-variable current(orient) -value xy -command ChangeOrient
    $ds9(mb).zoom add separator
    $ds9(mb).zoom add radiobutton -label "0 [msgcat::mc {Degrees}]" \
	-variable current(rotate) -value 0 -command ChangeRotate
    $ds9(mb).zoom add radiobutton -label "90 [msgcat::mc {Degrees}]" \
	-variable current(rotate) -value 90 -command ChangeRotate
    $ds9(mb).zoom add radiobutton -label "180 [msgcat::mc {Degrees}]" \
	-variable current(rotate) -value 180 -command ChangeRotate
    $ds9(mb).zoom add radiobutton -label "270 [msgcat::mc {Degrees}]" \
	-variable current(rotate) -value 270 -command ChangeRotate
    $ds9(mb).zoom add separator
    $ds9(mb).zoom add command -label "[msgcat::mc {Crop Parameters}]..." \
	-command CropDialog
    $ds9(mb).zoom add separator
    $ds9(mb).zoom add command \
	-label "[msgcat::mc {Pan Zoom Rotate Parameters}]..." \
	-command PanZoomDialog
}

proc PrefsDialogZoomMenu {w} {
    set f [ttk::labelframe $w.mzoom -text [msgcat::mc {Zoom}]]

    ttk::menubutton $f.menu -text [msgcat::mc {Menu}] -menu $f.menu.menu
    PrefsDialogButtonbarZoom $f.buttonbar

    grid $f.menu $f.buttonbar -padx 2 -pady 2
    
    set m $f.menu.menu
    menu $m
    $m add checkbutton -label [msgcat::mc {Align}] \
	-variable pcurrent(align)
    $m add separator
    $m add radiobutton -label "[msgcat::mc {Zoom}] 1/32" \
	-variable pcurrent(zoom) -value {0.03125 0.03125}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 1/16" \
	-variable pcurrent(zoom) -value {0.0625 0.0625}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 1/8" \
	-variable pcurrent(zoom) -value {0.125 0.125}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 1/4" \
	-variable pcurrent(zoom) -value {0.25 0.25}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 1/2" \
	-variable pcurrent(zoom) -value {0.5 0.5}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 1" \
	-variable pcurrent(zoom) -value {1 1}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 2" \
	-variable pcurrent(zoom) -value {2 2}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 4" \
	-variable pcurrent(zoom) -value {4 4}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 8" \
	-variable pcurrent(zoom) -value {8 8}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 16" \
	-variable pcurrent(zoom) -value {16 16}
    $m add radiobutton -label "[msgcat::mc {Zoom}] 32" \
 	-variable pcurrent(zoom) -value {32 32}
    $m add separator
    $m add radiobutton -label [msgcat::mc {None}] \
	-variable pcurrent(orient) -value none
    $m add radiobutton -label "[msgcat::mc {Invert}] X" \
	-variable pcurrent(orient) -value x
    $m add radiobutton -label "[msgcat::mc {Invert}] Y" \
	-variable pcurrent(orient) -value y
    $m add radiobutton -label "[msgcat::mc {Invert}] XY" \
	-variable pcurrent(orient) -value xy
    $m add separator
    $m add radiobutton -label "0 [msgcat::mc {Degrees}]" \
	-variable pcurrent(rotate) -value 0 
    $m add radiobutton -label "90 [msgcat::mc {Degrees}]" \
	-variable pcurrent(rotate) -value 90
    $m add radiobutton -label "180 [msgcat::mc {Degrees}]" \
	-variable pcurrent(rotate) -value 180
    $m add radiobutton -label "270 [msgcat::mc {Degrees}]" \
	-variable pcurrent(rotate) -value 270

    pack $f -side top -fill both -expand true
}

proc PrefsDialogZoom {} {
    global dprefs

    set w $dprefs(tab)

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

    # PanZoom
    set f [ttk::labelframe $w.zoom.panzoom -text [msgcat::mc {Pan Zoom}]]

    ttk::radiobutton $f.click -text [msgcat::mc {Click to Center}] \
	-variable ppanzoom(mode) -value click
    ttk::radiobutton $f.drag -text [msgcat::mc {Drag to Center}] \
	-variable ppanzoom(mode) -value drag
    ttk::radiobutton $f.panzoom -text [msgcat::mc {Pan then Zoom}] \
	-variable ppanzoom(mode) -value panzoom

    grid $f.click $f.drag $f.panzoom -padx 2 -pady 2 -sticky w

    # Mouse
    set f [ttk::labelframe $w.zoom.mouse -text [msgcat::mc {Mouse Wheel Zoom}]]

    ttk::checkbutton $f.click -text [msgcat::mc {Enable}] \
	-variable ppanzoom(wheel)
    ttk::label $f.title2 -text [msgcat::mc {Factor}]
    ttk::entry $f.factor -textvariable ppanzoom(wheel,factor) -width 10

    grid $f.click $f.title2 $f.factor -padx 2 -pady 2 -sticky w

    pack $w.zoom.panzoom $w.zoom.mouse -side top -fill both -expand true
}

# Buttons

proc ButtonsZoomDef {} {
    global pbuttons

    array set pbuttons {
	zoom,center 0 
	zoom,align 0

	zoom,in 1
	zoom,out 1
	zoom,fit 1
	zoom,i32 0
	zoom,i16 0
	zoom,i8 0
	zoom,i4 1
	zoom,i2 1
	zoom,1 1
	zoom,2 1
	zoom,4 1
	zoom,8 0
	zoom,16 0
	zoom,32 0

	zoom,none 0
	zoom,x 0
	zoom,y 0
	zoom,xy 0

	zoom,0 0
	zoom,90 0
	zoom,180 0
	zoom,270 0

	zoom,crop 0
	zoom,params 0
    }
}

proc CreateButtonsZoom {} {
    global buttons
    global ds9

    ttk::frame $ds9(buttons).zoom

    ButtonButton $ds9(buttons).zoom.center \
	[string tolower [msgcat::mc {Center}]] CenterCurrentFrame
    CheckButton $ds9(buttons).zoom.align \
	[msgcat::mc {Align}] current(align) AlignWCSFrame

    ButtonButton $ds9(buttons).zoom.in \
	[string tolower [msgcat::mc {Zoom In}]] {Zoom 2 2}
    ButtonButton $ds9(buttons).zoom.out \
	[string tolower [msgcat::mc {Zoom Out}]] {Zoom .5 .5}
    ButtonButton $ds9(buttons).zoom.fit \
	[string tolower [msgcat::mc {Zoom Fit}]] ZoomToFit
    RadioButton $ds9(buttons).zoom.i32 \
 	"[string tolower [msgcat::mc {Zoom}]] 1/32" \
	current(zoom) {0.03125 0.03125} ChangeZoom
    RadioButton $ds9(buttons).zoom.i16 \
	"[string tolower [msgcat::mc {Zoom}]] 1/16" \
	current(zoom) {0.0625 0.0625} ChangeZoom
    RadioButton $ds9(buttons).zoom.i8 \
	"[string tolower [msgcat::mc {Zoom}]] 1/8" \
	current(zoom) {0.125 0.125} ChangeZoom
    RadioButton $ds9(buttons).zoom.i4 \
	"[string tolower [msgcat::mc {Zoom}]] 1/4" \
	current(zoom) {0.25 0.25} ChangeZoom
    RadioButton $ds9(buttons).zoom.i2 \
	"[string tolower [msgcat::mc {Zoom}]] 1/2" \
	current(zoom) {0.5 0.5} ChangeZoom
    RadioButton $ds9(buttons).zoom.1 \
	"[string tolower [msgcat::mc {Zoom}]] 1" \
	current(zoom) {1 1} ChangeZoom
    RadioButton $ds9(buttons).zoom.2 \
	"[string tolower [msgcat::mc {Zoom}]] 2" \
	current(zoom) {2 2} ChangeZoom
    RadioButton $ds9(buttons).zoom.4 \
	"[string tolower [msgcat::mc {Zoom}]] 4" \
	current(zoom) {4 4} ChangeZoom
    RadioButton $ds9(buttons).zoom.8 \
	"[string tolower [msgcat::mc {Zoom}]] 8" \
	current(zoom) {8 8} ChangeZoom
    RadioButton $ds9(buttons).zoom.16 \
	"[string tolower [msgcat::mc {Zoom}]] 16" \
	current(zoom) {16 16} ChangeZoom
    RadioButton $ds9(buttons).zoom.32 \
 	"[string tolower [msgcat::mc {Zoom}]] 32" \
 	current(zoom) {32 32} ChangeZoom

    RadioButton $ds9(buttons).zoom.none \
	[string tolower [msgcat::mc {None}]] \
	current(orient) none ChangeOrient
    RadioButton $ds9(buttons).zoom.x {x} current(orient) x ChangeOrient
    RadioButton $ds9(buttons).zoom.y {y} current(orient) y ChangeOrient
    RadioButton $ds9(buttons).zoom.xy {xy} current(orient) xy ChangeOrient

    RadioButton $ds9(buttons).zoom.0 {0} current(rotate) 0 ChangeRotate
    RadioButton $ds9(buttons).zoom.90 {90} current(rotate) 90 ChangeRotate
    RadioButton $ds9(buttons).zoom.180 {180} current(rotate) 180 ChangeRotate
    RadioButton $ds9(buttons).zoom.270 {270} current(rotate) 270 ChangeRotate

    ButtonButton $ds9(buttons).zoom.crop \
	[string tolower [msgcat::mc {Crop}]] CropDialog
    ButtonButton $ds9(buttons).zoom.params \
	[string tolower [msgcat::mc {Parameters}]] PanZoomDialog

    set buttons(zoom) "
        $ds9(buttons).zoom.center pbuttons(zoom,center)
	$ds9(buttons).zoom.align pbuttons(zoom,align)

	$ds9(buttons).zoom.in pbuttons(zoom,in)
	$ds9(buttons).zoom.out pbuttons(zoom,out)
	$ds9(buttons).zoom.fit pbuttons(zoom,fit)
	$ds9(buttons).zoom.i32 pbuttons(zoom,i32)
	$ds9(buttons).zoom.i16 pbuttons(zoom,i16)
	$ds9(buttons).zoom.i8 pbuttons(zoom,i8)
	$ds9(buttons).zoom.i4 pbuttons(zoom,i4)
	$ds9(buttons).zoom.i2 pbuttons(zoom,i2)
	$ds9(buttons).zoom.1 pbuttons(zoom,1)
	$ds9(buttons).zoom.2 pbuttons(zoom,2)
	$ds9(buttons).zoom.4 pbuttons(zoom,4)
	$ds9(buttons).zoom.8 pbuttons(zoom,8)
	$ds9(buttons).zoom.16 pbuttons(zoom,16)
	$ds9(buttons).zoom.32 pbuttons(zoom,32)

	$ds9(buttons).zoom.none pbuttons(zoom,none)
	$ds9(buttons).zoom.x pbuttons(zoom,x)
	$ds9(buttons).zoom.y pbuttons(zoom,y)
	$ds9(buttons).zoom.xy pbuttons(zoom,xy)

	$ds9(buttons).zoom.0 pbuttons(zoom,0)
	$ds9(buttons).zoom.90 pbuttons(zoom,90)
	$ds9(buttons).zoom.180 pbuttons(zoom,180)
	$ds9(buttons).zoom.270 pbuttons(zoom,270)

	$ds9(buttons).zoom.crop pbuttons(zoom,crop)
	$ds9(buttons).zoom.params pbuttons(zoom,params)
    "
}

proc PrefsDialogButtonbarZoom {f} {
    global buttons
    global pbuttons

    ttk::menubutton $f -text [msgcat::mc {Buttonbar}] -menu $f.menu
    
    set m $f.menu
    menu $m
    $m add checkbutton -label [msgcat::mc {Center Image}] \
	-variable pbuttons(zoom,center) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label [msgcat::mc {Align}] \
	-variable pbuttons(zoom,align) -command {UpdateButtons buttons(zoom)}
    $m add separator
    $m add checkbutton -label [msgcat::mc {Zoom In}] \
	-variable pbuttons(zoom,in) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label [msgcat::mc {Zoom Out}] \
	-variable pbuttons(zoom,out) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label [msgcat::mc {Zoom Fit}] \
	-variable pbuttons(zoom,fit) -command {UpdateButtons buttons(zoom)}
    $m add separator
    $m add checkbutton -label "[msgcat::mc {Zoom}] 1/32" \
 	-variable pbuttons(zoom,i32) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 1/16" \
	-variable pbuttons(zoom,i16) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 1/8" \
	-variable pbuttons(zoom,i8) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 1/4" \
	-variable pbuttons(zoom,i4) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 1/2" \
	-variable pbuttons(zoom,i2) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 1" \
	-variable pbuttons(zoom,1) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 2" \
	-variable pbuttons(zoom,2) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 4" \
	-variable pbuttons(zoom,4) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 8" \
	-variable pbuttons(zoom,8) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 16" \
	-variable pbuttons(zoom,16) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Zoom}] 32" \
 	-variable pbuttons(zoom,32) -command {UpdateButtons buttons(zoom)}
    $m add separator
    $m add checkbutton -label [msgcat::mc {None}] \
	-variable pbuttons(zoom,none) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Invert}] X" \
	-variable pbuttons(zoom,x) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Invert}] Y" \
	-variable pbuttons(zoom,y) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "[msgcat::mc {Invert}] XY" \
	-variable pbuttons(zoom,xy) -command {UpdateButtons buttons(zoom)}
    $m add separator
    $m add checkbutton -label "0 [msgcat::mc {Degrees}]" \
	-variable pbuttons(zoom,0) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "90 [msgcat::mc {Degrees}]" \
	-variable pbuttons(zoom,90) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "180 [msgcat::mc {Degrees}]" \
	-variable pbuttons(zoom,180) -command {UpdateButtons buttons(zoom)}
    $m add checkbutton -label "270 [msgcat::mc {Degrees}]" \
	-variable pbuttons(zoom,270) -command {UpdateButtons buttons(zoom)}
    $m add separator
    $m add checkbutton -label "[msgcat::mc {Crop Parameters}]..." \
	-variable pbuttons(zoom,crop) -command {UpdateButtons buttons(zoom)}
    $m add separator
    $m add checkbutton -label "[msgcat::mc {Pan Zoom Rotate Parameters}]..." \
	-variable pbuttons(zoom,params) -command {UpdateButtons buttons(zoom)}
}

# Support

proc UpdateZoomMenu {} {
    global ds9
    global current
    global panzoom
    
    global debug
    if {$debug(tcl,update)} {
	puts stderr "UpdateZoomMenu"
    }

    if {$ds9(active,num) > 0} {
	$ds9(mb) entryconfig [msgcat::mc {Zoom}] -state normal
	ConfigureButtons zoom normal
    } else {
	$ds9(mb) entryconfig [msgcat::mc {Zoom}] -state disabled
	ConfigureButtons zoom disabled
    }

    if {$current(frame) == {}} {
	$ds9(mb).zoom entryconfig [msgcat::mc {Align}] -state disabled
    } else {
	$ds9(mb).zoom entryconfig [msgcat::mc {Align}]  -state normal

	set panzoom(preserve) [$current(frame) get pan preserve]
	set current(zoom) [$current(frame) get zoom]
	set current(rotate) [$current(frame) get rotate]
	set current(orient) [$current(frame) get orient]
	set current(align) [$current(frame) get wcs align]
    }
}