summaryrefslogtreecommitdiffstats
path: root/ds9/library/ruler.tcl
blob: d6bb9dd757cc06133815e7234e45dffa7c83e406 (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
#  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 RulerDialog {varname} {
    upvar #0 $varname var
    global $varname

    # see if we already have a header window visible
    if {[winfo exists $var(top)]} {
	raise $var(top)
	return
    }

    # variables
    set s [$var(frame) get marker $var(id) ruler system]
    set var(system) [lindex $s 0]
    set var(sky) [lindex $s 1]
    set var(skyformat) degrees
    set var(dcoord) [lindex $s 2]
    set var(dformat) [lindex $s 3]
    set var(spec) [$var(frame) get marker $var(id) ruler format]

    # procs
    set var(which) ruler
    set var(proc,apply) RulerApply
    set var(proc,coordCB) RulerCoordCB
    set var(proc,editCB) RulerEditCB
    set var(proc,distCB) RulerDistCB

    # base
    MarkerBaseLineDialog $varname 375 200

    set f $var(top).param

    # Axis Length
    ttk::label $f.tlen -text [msgcat::mc {Axis Length}]
    ttk::label $f.rx -textvariable ${varname}(distx) -relief groove -width 12 
    ttk::label $f.ry -textvariable ${varname}(disty) -relief groove -width 12 
    ttk::label $f.ulen -textvariable ${varname}(dcoord,msg)

    ttk::label $f.tspec -text [msgcat::mc {Format}]
    ttk::entry $f.spec -textvariable ${varname}(spec) -width 13

    grid $f.tlen $f.rx $f.ry $f.ulen -padx 2 -pady 2 -sticky w
    grid $f.tspec $f.spec -padx 2 -pady 2 -sticky w
}

# actions

proc RulerApply {varname} {
    upvar #0 $varname var
    global $varname

    $var(frame) marker $var(id) ruler point $var(system) $var(sky) \
	$var(x) $var(y) $var(x2) $var(y2)

    $var(frame) marker $var(id) ruler format "\"$var(spec)\""

    MarkerBaseLineApply $varname
}

# callbacks

proc RulerCoordCB {varname {dummy {}}} {
    upvar #0 $varname var
    global $varname

    global debug
    if {$debug(tcl,marker)} {
	puts stderr "RulerCoordCB"
    }

    MarkerBaseCoordCB $varname

    $var(frame) marker $var(id) ruler system $var(system) $var(sky) \
	$var(dcoord) $var(dformat)

    RulerEditCB $varname
}

proc RulerEditCB {varname {dummy {}}} {
    upvar #0 $varname var
    global $varname

    global debug
    if {$debug(tcl,marker)} {
	puts stderr "RulerEditCB"
    }

    MarkerBaseLineEditCB $varname

    set d [$var(frame) get marker $var(id) ruler length \
	       $var(dcoord) $var(dformat)]
    set var(dist) [lindex $d 0]
    set var(distx) [lindex $d 1]
    set var(disty) [lindex $d 2]

    set var(angle) [$var(frame) get marker $var(id) angle \
			$var(system) $var(sky)]
}

proc RulerDistCB {varname {dummy {}}} {
    upvar #0 $varname var
    global $varname

    global debug
    if {$debug(tcl,marker)} {
	puts stderr "RulerDistCB"
    }

    $var(frame) marker $var(id) ruler system $var(system) $var(sky) \
	$var(dcoord) $var(dformat)

    set d [$var(frame) get marker $var(id) ruler length \
	       $var(dcoord) $var(dformat)]
    set var(dist) [lindex $d 0]
    set var(distx) [lindex $d 1]
    set var(disty) [lindex $d 2]
}