~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to gui/tcltk/d.m/legend.tcl

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# 1 Sept 2005
2
 
# panel for d.legend
3
 
# Michael Barton, Arizona State University
4
 
 
5
 
namespace eval DmLegend {
6
 
    variable array opt # legend options
7
 
    variable count 1
8
 
}
9
 
 
10
 
 
11
 
proc DmLegend::create { tree parent } {
12
 
    variable opt
13
 
    variable count
14
 
    global dmpath
15
 
 
16
 
    set node "legend:$count"
17
 
 
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]
23
 
 
24
 
    image create photo legico -file "$dmpath/legend.gif"
25
 
    set ico [label $frm.ico -image legico -bd 1 -relief raised]
26
 
    
27
 
    pack $check $ico -side left
28
 
    
29
 
    $tree insert end $parent $node \
30
 
        -text  "legend $count"\
31
 
        -window    $frm \
32
 
        -drawcross auto  
33
 
        
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 
51
 
    
52
 
    incr count
53
 
    return $node
54
 
}
55
 
 
56
 
proc DmLegend::set_option { node key value } {
57
 
    variable opt
58
 
 
59
 
    set id [Dm::node_id $node]
60
 
    set opt($id,$key) $value
61
 
}
62
 
 
63
 
proc DmLegend::select_map { id } {
64
 
    variable tree
65
 
    variable node
66
 
    set m [GSelect cell]
67
 
    if { $m != "" } { 
68
 
        set DmLegend::opt($id,map) $m
69
 
        Dm::autoname "legend for $m"
70
 
    }
71
 
}
72
 
 
73
 
# legend options
74
 
proc DmLegend::options { id frm } {
75
 
    variable opt
76
 
    global dmpath
77
 
    global bgcolor
78
 
 
79
 
    # raster name
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) \
85
 
          -background white
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
93
 
 
94
 
    # monitor for legend
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
103
 
 
104
 
    # text color
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"} \
110
 
                    -entrybg white
111
 
    pack $row.a $row.b -side left
112
 
    pack $row -side top -fill both -expand yes
113
 
 
114
 
    # display lines
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
121
 
    
122
 
    # thin
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
129
 
    
130
 
    # labelnum
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
137
 
    
138
 
    # at
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 \
142
 
            -entrybg white
143
 
    pack $row.a $row.b -side left
144
 
    pack $row -side top -fill both -expand yes
145
 
        
146
 
    # use cats
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 \
150
 
            -entrybg white
151
 
    pack $row.a $row.b -side left
152
 
    pack $row -side top -fill both -expand yes
153
 
    
154
 
    # range
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 \
158
 
            -entrybg white
159
 
    pack $row.a $row.b -side left
160
 
    pack $row -side top -fill both -expand yes
161
 
    
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
170
 
 
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
181
 
 
182
 
    # mouse
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
189
 
}
190
 
 
191
 
proc DmLegend::save { tree depth node } {
192
 
    variable opt
193
 
    
194
 
    set id [Dm::node_id $node]
195
 
 
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)"
199
 
    } 
200
 
}
201
 
 
202
 
 
203
 
proc DmLegend::display { node } {
204
 
    variable opt
205
 
    set line ""
206
 
    set input ""
207
 
    global dmpath
208
 
    set cmd ""
209
 
 
210
 
    set tree $Dm::tree
211
 
    set id [Dm::node_id $node]
212
 
 
213
 
 
214
 
    if { ! ( $opt($id,_check) ) } { return } 
215
 
 
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)"
220
 
 
221
 
    # use cats
222
 
    if { $opt($id,use) != "" } { 
223
 
        append cmd " use=$opt($id,use)"
224
 
    }
225
 
 
226
 
    # range
227
 
    if { $opt($id,range) != "" } { 
228
 
        append cmd " range=$opt($id,range)"
229
 
    }
230
 
 
231
 
    # nolbl
232
 
    if { $opt($id,nolbl) != 0 } { 
233
 
        append cmd " -v"
234
 
    }
235
 
 
236
 
    # noval
237
 
    if { $opt($id,noval) != 0 } { 
238
 
        append cmd " -c"
239
 
    }
240
 
 
241
 
    # skip
242
 
    if { $opt($id,skip) != 0} { 
243
 
        append cmd " -n"
244
 
    }
245
 
 
246
 
    # smooth
247
 
    if { $opt($id,smooth) != 0 } { 
248
 
        append cmd " -s"
249
 
    }
250
 
    
251
 
    # mouse
252
 
    if { $opt($id,mouse) != 0 } { 
253
 
        append cmd " -m"
254
 
    }
255
 
    
256
 
    # flip
257
 
    if { $opt($id,flip) != 0 } { 
258
 
        append cmd " -f"
259
 
    }
260
 
 
261
 
    #display legend in selected monitor
262
 
    if { $cmd != "" } { 
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
267
 
                }              
268
 
            }
269
 
        }
270
 
 
271
 
        Dm::displmon $opt($id,legmon)
272
 
        if { $opt($id,erase) == 1 } {run "d.erase white"}
273
 
        run_panel $cmd
274
 
        run "d.mon select=$currmon"
275
 
    }
276
 
        close $input
277
 
}
278
 
 
279
 
proc DmLegend::print { file node } {
280
 
    variable opt
281
 
    
282
 
    set tree $Dm::tree
283
 
    set id [Dm::node_id $node]
284
 
 
285
 
    if { ! ( $opt($id,_check) ) } { return } 
286
 
 
287
 
    if { $opt($id,map) == "" } { return } 
288
 
 
289
 
    puts $file "legend $opt($id,map)"
290
 
}
291
 
 
292
 
 
293
 
proc DmLegend::duplicate { tree parent node id } {
294
 
    variable opt
295
 
    variable count 
296
 
    global dmpath
297
 
 
298
 
    set node "legend:$count"
299
 
 
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]
305
 
 
306
 
    image create photo legico -file "$dmpath/legend.gif"
307
 
    set ico [label $frm.ico -image legico -bd 1 -relief raised]
308
 
    
309
 
    pack $check $ico -side left
310
 
 
311
 
        if { $opt($id,map) == ""} {
312
 
        $tree insert end $parent $node \
313
 
                -text      "legend $count" \
314
 
                -window    $frm \
315
 
                -drawcross auto
316
 
        } else {
317
 
            $tree insert end $parent $node \
318
 
                -text      "legend for $opt($id,map)" \
319
 
                -window    $frm \
320
 
                -drawcross auto
321
 
        }
322
 
 
323
 
    set opt($count,_check) $opt($id,_check)
324
 
 
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)" 
340
 
 
341
 
    incr count
342
 
    return $node
343
 
}