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

« back to all changes in this revision

Viewing changes to gui/tcltk/gis.m/maptext.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
 
###############################################################
2
 
# maptext.tcl - TclTk canvas postscript text layer options file for GRASS GIS Manager
3
 
# February 2006 Michael Barton, Arizona State University
4
 
# COPYRIGHT:    (C) 1999 - 2006 by the GRASS Development Team
5
 
#
6
 
#               This program is free software under the GNU General Public
7
 
#               License (>=v2). Read the file COPYING that comes with GRASS
8
 
#               for details.
9
 
#
10
 
##########################################################################
11
 
 
12
 
namespace eval GmCtext {
13
 
    variable array opt ;# ctext options
14
 
    variable placement ;#entry widget for x,y coordinates
15
 
    variable count 1
16
 
    variable optlist
17
 
}
18
 
 
19
 
proc GmCtext::create { tree parent } {
20
 
    variable opt
21
 
    variable count
22
 
        variable dup
23
 
        variable optlist
24
 
    global iconpath
25
 
    global env
26
 
 
27
 
    set node "ctext:$count"
28
 
 
29
 
    set frm [ frame .ctexticon$count]
30
 
    set check [checkbutton $frm.check \
31
 
                -variable GmCtext::opt($count,1,_check) \
32
 
                -height 1 -padx 0 -width 0]
33
 
 
34
 
    image create photo ctico -file "$iconpath/gui-maptext.gif"
35
 
    set ico [label $frm.ico -image ctico -bd 1 -relief raised]
36
 
 
37
 
    bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
38
 
 
39
 
    pack $check $ico -side left
40
 
    
41
 
        #insert new layer
42
 
        if {[$tree selection get] != "" } {
43
 
                set sellayer [$tree index [$tree selection get]]
44
 
    } else { 
45
 
        set sellayer "end" 
46
 
    }
47
 
 
48
 
    $tree insert $sellayer $parent $node \
49
 
        -text  "PS text layer $count"\
50
 
        -window    $frm \
51
 
        -drawcross auto  
52
 
        
53
 
    set opt($count,1,_check) 1 
54
 
        set opt($count,1,opacity) 1.0
55
 
    set opt($count,1,text) "" 
56
 
    set opt($count,1,at) "100,100"
57
 
    set opt($count,1,font) "times 12" 
58
 
    set opt($count,1,fill) \#000000 
59
 
    set opt($count,1,width)  100
60
 
    set opt($count,1,anchor) "center_left" 
61
 
    set opt($count,1,anchorlv) ""
62
 
    set opt($count,1,justify) "left"
63
 
    set opt($count,1,justifylv) ""
64
 
    set opt($count,1,coordinates) "pixels"
65
 
    set opt($count,1,coordinateslv) ""
66
 
    set opt($count,1,mouseset) 0
67
 
    
68
 
    set optlist { _check opacity text at font fill width anchor justify coordinates mouseset}
69
 
    
70
 
    foreach key $optlist {
71
 
                set opt($count,0,$key) $opt($count,1,$key)
72
 
    } 
73
 
 
74
 
    incr count
75
 
    return $node
76
 
}
77
 
 
78
 
###############################################################################
79
 
proc GmCtext::select_font { id frm } {
80
 
        global mon
81
 
        variable opt
82
 
    
83
 
    set fon [SelectFont $frm.fontset -type dialog -sampletext [G_msg "This is font sample text."] -title [G_msg "Select label font"] -font $opt($id,1,font) ]
84
 
        if { $fon != "" } {set opt($id,1,font) $fon}
85
 
}
86
 
 
87
 
###############################################################################
88
 
proc GmCtext::set_option { node key value } {
89
 
    variable opt
90
 
 
91
 
    set id [GmTree::node_id $node]
92
 
    set opt($id,1,$key) $value
93
 
}
94
 
 
95
 
###############################################################################
96
 
 
97
 
proc GmCtext::mouseset { id } {
98
 
        # use mouse to set scalebar placement coordinates
99
 
        global mon pctentry pixelentry geogentry
100
 
        variable placement
101
 
        if { $GmCtext::opt($id,1,mouseset) == 1} {
102
 
                if {$GmCtext::opt($id,1,coordinates) == "pixels"} {
103
 
                        set pixelentry $GmCtext::placement
104
 
                } else {
105
 
                        set pixelentry ""
106
 
                }
107
 
                if {$GmCtext::opt($id,1,coordinates) == "percent"} {
108
 
                        set pctentry $GmCtext::placement
109
 
                } else {
110
 
                        set pctentry ""
111
 
                }
112
 
                if {$GmCtext::opt($id,1,coordinates) == "geographic"} {
113
 
                        set geogentry $GmCtext::placement
114
 
                } else {
115
 
                        set geogentry ""
116
 
                }
117
 
        }
118
 
}
119
 
###############################################################################
120
 
 
121
 
# ctext options
122
 
proc GmCtext::options { id frm } {
123
 
    variable opt
124
 
        variable placement
125
 
    global iconpath
126
 
 
127
 
    # Panel heading
128
 
    set row [ frame $frm.heading ]
129
 
    Label $row.a -text [G_msg "Create postscript text object (for postscript eps, pdf, and print output only)"] \
130
 
        -fg MediumBlue
131
 
    pack $row.a -side left
132
 
    pack $row -side top -fill both -expand yes
133
 
 
134
 
    # text
135
 
    set row [ frame $frm.text ]
136
 
    Label $row.a -text [G_msg "Text to display:"]
137
 
    LabelEntry $row.b -textvariable GmCtext::opt($id,1,text) -width 45 
138
 
    pack $row.a $row.b -side left
139
 
    pack $row -side top -fill both -expand yes
140
 
    
141
 
    # coordinates1
142
 
    set row [ frame $frm.east_north ]
143
 
    set placement [LabelEntry $row.a -label [G_msg "Text placement: x,y coordinates (from upper left) "] \
144
 
        -textvariable GmCtext::opt($id,1,at) -width 24]
145
 
    pack $row.a -side left
146
 
    pack $row -side top -fill both -expand yes
147
 
        
148
 
    # coordinates2
149
 
    set row [ frame $frm.textcoord2 ]
150
 
    Label $row.a -text [G_msg "     coordinate type for text placement "] 
151
 
    ComboBox $row.b -padx 2 -width 10 -textvariable GmCtext::opt($id,1,coordinates) \
152
 
        -values {"pixels" "percent" "geographic" } -modifycmd "GmCtext::mouseset $id" \
153
 
        -labels [list [G_msg "pixels"] [G_msg "percent"] [G_msg "geographic"]] -labelsvariable GmCtext::opt($id,1,coordinateslv)
154
 
    checkbutton $row.c -text [G_msg "place with mouse"] \
155
 
        -variable GmCtext::opt($id,1,mouseset) \
156
 
        -command "GmCtext::mouseset $id"
157
 
    pack $row.a $row.b $row.c -side left
158
 
    pack $row -side top -fill both -expand yes
159
 
        
160
 
    # text options1
161
 
    set row [ frame $frm.textopt1 ]
162
 
    Label $row.a -text [G_msg "     align text with coordinate point  "] 
163
 
    ComboBox $row.b -padx 2 -width 16 -textvariable GmCtext::opt($id,1,anchor) \
164
 
                -values {"lower_left" "bottom_center" "lower_right" "center_left" "center" 
165
 
                "center_right" "upper_left" "top_center" "upper_right" } \
166
 
                -labels [list [G_msg "lower left"] [G_msg "bottom center"] [G_msg "lower right"] [G_msg "center left"] [G_msg "center"] [G_msg "center right"] [G_msg "upper left"] [G_msg "top center"] [G_msg "upper right"]] -labelsvariable GmCtext::opt($id,1,anchorlv)
167
 
    pack $row.a $row.b -side left
168
 
    pack $row -side top -fill both -expand yes
169
 
 
170
 
    # text options2
171
 
    set row [ frame $frm.textopt2 ]
172
 
    Label $row.a -text [G_msg "     justification"] 
173
 
    ComboBox $row.b -padx 2 -width 10 -textvariable GmCtext::opt($id,1,justify) \
174
 
                -values {"left" "center" "right"} \
175
 
                -labels [list [G_msg "left"] [G_msg "center"] [G_msg "right"]] -labelsvariable GmCtext::opt($id,1,justifylv)
176
 
    Label $row.c -text [G_msg "  line width"]
177
 
    LabelEntry $row.d -textvariable GmCtext::opt($id,1,width) -width 5 
178
 
    pack $row.a $row.b $row.c $row.d -side left
179
 
    pack $row -side top -fill both -expand yes
180
 
        
181
 
    # select font
182
 
    set row [ frame $frm.font ]
183
 
    Label $row.a -text [G_msg "Font:"] 
184
 
    Button $row.b -image [image create photo -file "$iconpath/gui-font.gif"] \
185
 
        -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1  \
186
 
        -helptext [G_msg "select font for text"] \
187
 
            -command "GmCtext::select_font $id $frm"
188
 
    Entry $row.c -width 15 -text "$opt($id,1,font)" \
189
 
            -textvariable GmCtext::opt($id,1,font) 
190
 
    Label $row.d -text [G_msg "  color"] 
191
 
    SelectColor $row.e -type menubutton -variable GmCtext::opt($id,1,fill)
192
 
    pack $row.a $row.b $row.c $row.d $row.e -side left
193
 
    pack $row -side top -fill both -expand yes
194
 
 
195
 
 
196
 
}
197
 
 
198
 
###############################################################################
199
 
proc GmCtext::save { tree depth node } {
200
 
    variable opt
201
 
    variable optlist
202
 
    
203
 
    set id [GmTree::node_id $node]
204
 
 
205
 
    foreach key $optlist {
206
 
        GmTree::rc_write $depth "$key $opt($id,1,$key)"
207
 
    } 
208
 
}
209
 
 
210
 
###############################################################################
211
 
proc GmCtext::display { node } {
212
 
    variable opt
213
 
    variable tree
214
 
    variable can
215
 
    global mon
216
 
 
217
 
    set tree($mon) $GmTree::tree($mon)
218
 
    set id [GmTree::node_id $node]
219
 
    set canvas_w($mon) $MapCanvas::canvas_w($mon)
220
 
    set canvas_h($mon) $MapCanvas::canvas_h($mon)
221
 
    
222
 
 
223
 
    set can($mon) $MapCanvas::can($mon)
224
 
    
225
 
    
226
 
    if {$opt($id,1,_check) == 0 } { return } 
227
 
 
228
 
    if { $opt($id,1,text) == "" } { return } 
229
 
        
230
 
    switch $opt($id,1,anchor) {
231
 
        "lower_left"    { set anchor "sw"}
232
 
        "bottom_center" { set anchor "s" }
233
 
        "lower_right"   { set anchor "se"}
234
 
        "center_left"   { set anchor "w" }
235
 
        "center"                { set anchor "center" }
236
 
        "center_right"  { set anchor "e" }
237
 
        "upper_left"    { set anchor "nw"}
238
 
        "top_center"    { set anchor "n" }
239
 
        "upper_right"   { set anchor "ne"}
240
 
    }
241
 
     
242
 
    set xcoord [lindex [split $opt($id,1,at) ","] 0]
243
 
    set ycoord [lindex [split $opt($id,1,at) ","] 1]    
244
 
    
245
 
    if {$opt($id,1,coordinates) == "geographic"} {
246
 
                set xcoord [MapCanvas::mape2scrx $mon $xcoord]
247
 
                set ycoord [MapCanvas::mapn2scry $mon $ycoord]
248
 
                $can($mon) create text $xcoord $ycoord \
249
 
                        -anchor $anchor \
250
 
                        -justify $opt($id,1,justify) \
251
 
                        -width $opt($id,1,width) \
252
 
                        -fill $opt($id,1,fill) \
253
 
                        -font $opt($id,1,font) \
254
 
                        -text $opt($id,1,text)
255
 
    } elseif {$opt($id,1,coordinates) == "percent"} {
256
 
                set xpct [expr ($xcoord/100.0) * $canvas_w($mon)]
257
 
                set ypct [expr ($ycoord/100.0) * $canvas_h($mon)]
258
 
                $can($mon) create text $xpct $ypct \
259
 
                        -anchor $anchor \
260
 
                        -justify $opt($id,1,justify) \
261
 
                        -width $opt($id,1,width) \
262
 
                        -fill $opt($id,1,fill) \
263
 
                        -font $opt($id,1,font) \
264
 
                        -text $opt($id,1,text)
265
 
    } else {
266
 
                $can($mon) create text $xcoord $ycoord \
267
 
                        -anchor $anchor \
268
 
                        -justify $opt($id,1,justify) \
269
 
                        -width $opt($id,1,width) \
270
 
                        -fill $opt($id,1,fill) \
271
 
                        -font $opt($id,1,font) \
272
 
                        -text $opt($id,1,text)
273
 
        }
274
 
}
275
 
###############################################################################
276
 
 
277
 
proc GmCtext::duplicate { tree parent node id } {
278
 
    variable opt
279
 
    variable count
280
 
        variable dup
281
 
        variable optlist
282
 
    global iconpath
283
 
 
284
 
    set node "ctext:$count"
285
 
 
286
 
    set frm [ frame .ctexticon$count]
287
 
    set check [checkbutton $frm.check \
288
 
                -variable GmCtext::opt($count,1,_check) \
289
 
                -height 1 -padx 0 -width 0]
290
 
 
291
 
    image create photo ctico -file "$iconpath/gui-maptext.gif"
292
 
    set ico [label $frm.ico -image ctico -bd 1 -relief raised]
293
 
 
294
 
    bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
295
 
 
296
 
    pack $check $ico -side left
297
 
    
298
 
        #insert new layer
299
 
        if {[$tree selection get] != "" } {
300
 
                set sellayer [$tree index [$tree selection get]]
301
 
    } else { 
302
 
        set sellayer "end" 
303
 
    }
304
 
 
305
 
    $tree insert $sellayer $parent $node \
306
 
        -text  "PS text layer $count"\
307
 
        -window    $frm \
308
 
        -drawcross auto  
309
 
        
310
 
        set opt($count,1,opacity) $opt($id,1,opacity)
311
 
    set first 1
312
 
    
313
 
    foreach key $optlist {
314
 
        set opt($count,1,$key) $opt($id,1,$key)
315
 
                set opt($count,0,$key) $opt($count,1,$key)
316
 
    } 
317
 
        
318
 
 
319
 
    incr count
320
 
    return $node
321
 
}