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
6
# This program is free software under the GNU General Public
7
# License (>=v2). Read the file COPYING that comes with GRASS
10
##########################################################################
12
namespace eval GmCtext {
13
variable array opt ;# ctext options
14
variable placement ;#entry widget for x,y coordinates
19
proc GmCtext::create { tree parent } {
27
set node "ctext:$count"
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]
34
image create photo ctico -file "$iconpath/gui-maptext.gif"
35
set ico [label $frm.ico -image ctico -bd 1 -relief raised]
37
bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
39
pack $check $ico -side left
42
if {[$tree selection get] != "" } {
43
set sellayer [$tree index [$tree selection get]]
48
$tree insert $sellayer $parent $node \
49
-text "PS text layer $count"\
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
68
set optlist { _check opacity text at font fill width anchor justify coordinates mouseset}
70
foreach key $optlist {
71
set opt($count,0,$key) $opt($count,1,$key)
78
###############################################################################
79
proc GmCtext::select_font { id frm } {
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}
87
###############################################################################
88
proc GmCtext::set_option { node key value } {
91
set id [GmTree::node_id $node]
92
set opt($id,1,$key) $value
95
###############################################################################
97
proc GmCtext::mouseset { id } {
98
# use mouse to set scalebar placement coordinates
99
global mon pctentry pixelentry geogentry
101
if { $GmCtext::opt($id,1,mouseset) == 1} {
102
if {$GmCtext::opt($id,1,coordinates) == "pixels"} {
103
set pixelentry $GmCtext::placement
107
if {$GmCtext::opt($id,1,coordinates) == "percent"} {
108
set pctentry $GmCtext::placement
112
if {$GmCtext::opt($id,1,coordinates) == "geographic"} {
113
set geogentry $GmCtext::placement
119
###############################################################################
122
proc GmCtext::options { id frm } {
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)"] \
131
pack $row.a -side left
132
pack $row -side top -fill both -expand yes
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
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
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
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
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
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
198
###############################################################################
199
proc GmCtext::save { tree depth node } {
203
set id [GmTree::node_id $node]
205
foreach key $optlist {
206
GmTree::rc_write $depth "$key $opt($id,1,$key)"
210
###############################################################################
211
proc GmCtext::display { node } {
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)
223
set can($mon) $MapCanvas::can($mon)
226
if {$opt($id,1,_check) == 0 } { return }
228
if { $opt($id,1,text) == "" } { return }
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"}
242
set xcoord [lindex [split $opt($id,1,at) ","] 0]
243
set ycoord [lindex [split $opt($id,1,at) ","] 1]
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 \
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 \
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)
266
$can($mon) create text $xcoord $ycoord \
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)
275
###############################################################################
277
proc GmCtext::duplicate { tree parent node id } {
284
set node "ctext:$count"
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]
291
image create photo ctico -file "$iconpath/gui-maptext.gif"
292
set ico [label $frm.ico -image ctico -bd 1 -relief raised]
294
bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
296
pack $check $ico -side left
299
if {[$tree selection get] != "" } {
300
set sellayer [$tree index [$tree selection get]]
305
$tree insert $sellayer $parent $node \
306
-text "PS text layer $count"\
310
set opt($count,1,opacity) $opt($id,1,opacity)
313
foreach key $optlist {
314
set opt($count,1,$key) $opt($id,1,$key)
315
set opt($count,0,$key) $opt($count,1,$key)