3
# Michael Barton, Arizona State University
5
namespace eval DmLegend {
6
variable array opt # legend options
11
proc DmLegend::create { tree parent } {
16
set node "legend:$count"
18
set frm [ frame .legendicon$count]
19
set fon [font create -size 10]
20
set check [checkbutton $frm.check -font $fon \
21
-variable DmLegend::opt($count,_check) \
22
-height 1 -padx 0 -width 0]
24
image create photo legico -file "$dmpath/legend.gif"
25
set ico [label $frm.ico -image legico -bd 1 -relief raised]
27
pack $check $ico -side left
29
$tree insert end $parent $node \
30
-text "legend $count"\
34
set opt($count,_check) 1
35
set opt($count,map) ""
36
set opt($count,legmon) "x1"
37
set opt($count,erase) 1
38
set opt($count,color) "black"
39
set opt($count,lines) 0
40
set opt($count,thin) 1
41
set opt($count,labelnum) 5
42
set opt($count,at) "5,95,5,10"
43
set opt($count,use) ""
44
set opt($count,range) ""
45
set opt($count,nolbl) 0
46
set opt($count,noval) 0
47
set opt($count,skip) 0
48
set opt($count,smooth) 0
49
set opt($count,mouse) 0
50
set opt($count,flip) 0
56
proc DmLegend::set_option { node key value } {
59
set id [Dm::node_id $node]
60
set opt($id,$key) $value
63
proc DmLegend::select_map { id } {
68
set DmLegend::opt($id,map) $m
69
Dm::autoname "legend for $m"
74
proc DmLegend::options { id frm } {
80
set row [ frame $frm.map ]
81
Button $row.a -text [G_msg "Raster map for legend:"] \
82
-command "DmLegend::select_map $id"
83
Entry $row.b -width 40 -text " $opt($id,map)" \
84
-textvariable DmLegend::opt($id,map) \
86
Button $row.c -text [G_msg "Help"] \
87
-image [image create photo -file "$dmpath/grass.gif"] \
88
-command "run g.manual d.legend" \
89
-background $bgcolor \
90
-helptext [G_msg "Help"]
91
pack $row.a $row.b $row.c -side left
92
pack $row -side top -fill both -expand yes
95
set row [ frame $frm.monitor ]
96
Label $row.a -text [G_msg "Display legend in monitor: "]
97
ComboBox $row.b -padx 2 -width 3 -textvariable DmLegend::opt($id,legmon) \
98
-values {"x0" "x1" "x2" "x3" "x4" "x5" "x6"} -entrybg white
99
checkbutton $row.c -text [G_msg " erase monitor before drawing legend"] -variable \
100
DmLegend::opt($id,erase)
101
pack $row.a $row.b $row.c -side left
102
pack $row -side top -fill both -expand yes
105
set row [ frame $frm.color ]
106
Label $row.a -text [G_msg "Text color: "]
107
ComboBox $row.b -padx 0 -width 10 -textvariable DmLegend::opt($id,color) \
108
-values {"white" "grey" "gray" "black" "brown" "red" "orange" \
109
"yellow" "green" "aqua" "cyan" "indigo" "blue" "purple" "violet" "magenta"} \
111
pack $row.a $row.b -side left
112
pack $row -side top -fill both -expand yes
115
set row [ frame $frm.lines ]
116
Label $row.a -text "Number of lines to display (0=display all):"
117
SpinBox $row.b -range {0 1000 1} -textvariable DmLegend::opt($id,lines) \
118
-entrybg white -width 5 -helptext "Lines to display"
119
pack $row.a $row.b -side left
120
pack $row -side top -fill both -expand yes
123
set row [ frame $frm.thin ]
124
Label $row.a -text "Interval between categories (thinning interval) of integer maps:"
125
SpinBox $row.b -range {1 1000 1} -textvariable DmLegend::opt($id,thin) \
126
-entrybg white -width 5 -helptext "Thinning interval"
127
pack $row.a $row.b -side left
128
pack $row -side top -fill both -expand yes
131
set row [ frame $frm.labelnum ]
132
Label $row.a -text "Maximum number of labels for smooth gradients"
133
SpinBox $row.b -range {2 100 1} -textvariable DmLegend::opt($id,labelnum) \
134
-entrybg white -width 4 -helptext "Maximum labels for gradient"
135
pack $row.a $row.b -side left
136
pack $row -side top -fill both -expand yes
139
set row [ frame $frm.at ]
140
Label $row.a -text "Place legend at 0-100% from bottom left (bottom,top,left,right)"
141
LabelEntry $row.b -textvariable DmLegend::opt($id,at) -width 15 \
143
pack $row.a $row.b -side left
144
pack $row -side top -fill both -expand yes
147
set row [ frame $frm.use ]
148
Label $row.a -text "Display only these categories"
149
LabelEntry $row.b -textvariable DmLegend::opt($id,use) -width 42 \
151
pack $row.a $row.b -side left
152
pack $row -side top -fill both -expand yes
155
set row [ frame $frm.range ]
156
Label $row.a -text "Display only this range of values"
157
LabelEntry $row.b -textvariable DmLegend::opt($id,range) -width 39 \
159
pack $row.a $row.b -side left
160
pack $row -side top -fill both -expand yes
162
# no category labels or numbers
163
set row [ frame $frm.cats ]
164
checkbutton $row.a -text [G_msg "do not show cat labels"] -variable \
165
DmLegend::opt($id,nolbl)
166
checkbutton $row.b -text [G_msg "do not show cat numbers"] -variable \
167
DmLegend::opt($id,noval)
168
pack $row.a $row.b -side left
169
pack $row -side top -fill both -expand yes
171
# skip, gradient, and flip
172
set row [ frame $frm.opts ]
173
checkbutton $row.a -text [G_msg "skip cats with no labels"] -variable \
174
DmLegend::opt($id,skip)
175
checkbutton $row.b -text [G_msg "draw smooth gradient"] -variable \
176
DmLegend::opt($id,smooth)
177
checkbutton $row.c -text [G_msg "flip legend"] -variable \
178
DmLegend::opt($id,flip)
179
pack $row.a $row.b $row.c -side left
180
pack $row -side top -fill both -expand yes
183
set row [ frame $frm.mouse ]
184
checkbutton $row.a -text \
185
[G_msg "place with mouse (cannot save placement with group)"] \
186
-variable DmLegend::opt($id,mouse)
187
pack $row.a -side left
188
pack $row -side top -fill both -expand yes
191
proc DmLegend::save { tree depth node } {
194
set id [Dm::node_id $node]
196
foreach key { _check map color lines thin labelnum at use range \
197
legmon nolbl noval skip smooth mouse flip } {
198
Dm::rc_write $depth "$key $opt($id,$key)"
203
proc DmLegend::display { node } {
211
set id [Dm::node_id $node]
214
if { ! ( $opt($id,_check) ) } { return }
216
if { $opt($id,map) == "" } { return }
217
set cmd "d.legend map=$opt($id,map) color=$opt($id,color) \
218
lines=$opt($id,lines) thin=$opt($id,thin) \
219
labelnum=$opt($id,labelnum) at=$opt($id,at)"
222
if { $opt($id,use) != "" } {
223
append cmd " use=$opt($id,use)"
227
if { $opt($id,range) != "" } {
228
append cmd " range=$opt($id,range)"
232
if { $opt($id,nolbl) != 0 } {
237
if { $opt($id,noval) != 0 } {
242
if { $opt($id,skip) != 0} {
247
if { $opt($id,smooth) != 0 } {
252
if { $opt($id,mouse) != 0 } {
257
if { $opt($id,flip) != 0 } {
261
#display legend in selected monitor
263
if ![catch {open "|d.mon -L" r} input] {
264
while {[gets $input line] >= 0} {
265
if {[regexp -nocase {.*(selected).*} $line]} {
266
regexp -nocase {..} $line currmon
271
Dm::displmon $opt($id,legmon)
272
if { $opt($id,erase) == 1 } {run "d.erase white"}
274
run "d.mon select=$currmon"
279
proc DmLegend::print { file node } {
283
set id [Dm::node_id $node]
285
if { ! ( $opt($id,_check) ) } { return }
287
if { $opt($id,map) == "" } { return }
289
puts $file "legend $opt($id,map)"
293
proc DmLegend::duplicate { tree parent node id } {
298
set node "legend:$count"
300
set frm [ frame .legendicon$count]
301
set fon [font create -size 10]
302
set check [checkbutton $frm.check -font $fon \
303
-variable DmLegend::opt($count,_check) \
304
-height 1 -padx 0 -width 0]
306
image create photo legico -file "$dmpath/legend.gif"
307
set ico [label $frm.ico -image legico -bd 1 -relief raised]
309
pack $check $ico -side left
311
if { $opt($id,map) == ""} {
312
$tree insert end $parent $node \
313
-text "legend $count" \
317
$tree insert end $parent $node \
318
-text "legend for $opt($id,map)" \
323
set opt($count,_check) $opt($id,_check)
325
set opt($count,map) "$opt($id,map)"
326
set opt($count,legmon) "$opt($id,legmon)"
327
set opt($count,color) "$opt($id,color)"
328
set opt($count,lines) "$opt($id,lines)"
329
set opt($count,thin) "$opt($id,thin)"
330
set opt($count,labelnum) "$opt($id,labelnum)"
331
set opt($count,at) "$opt($id,at)"
332
set opt($count,use) "$opt($id,use)"
333
set opt($count,range) "$opt($id,range)"
334
set opt($count,nolbl) "$opt($id,nolbl)"
335
set opt($count,noval) "$opt($id,noval)"
336
set opt($count,skip) "$opt($id,skip)"
337
set opt($count,smooth) "$opt($id,smooth)"
338
set opt($count,mouse) "$opt($id,mouse)"
339
set opt($count,flip) "$opt($id,flip)"