[GRASS-SVN] r43694 -
grass/branches/releasebranch_6_4/gui/tcltk/gis.m
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 26 09:29:41 EDT 2010
Author: marisn
Date: 2010-09-26 13:29:41 +0000 (Sun, 26 Sep 2010)
New Revision: 43694
Modified:
grass/branches/releasebranch_6_4/gui/tcltk/gis.m/maplabels.tcl
Log:
gis.m: Fix most of PS label rendering issues. (Synced from develbranch_6)
Modified: grass/branches/releasebranch_6_4/gui/tcltk/gis.m/maplabels.tcl
===================================================================
--- grass/branches/releasebranch_6_4/gui/tcltk/gis.m/maplabels.tcl 2010-09-26 12:20:53 UTC (rev 43693)
+++ grass/branches/releasebranch_6_4/gui/tcltk/gis.m/maplabels.tcl 2010-09-26 13:29:41 UTC (rev 43694)
@@ -14,23 +14,21 @@
# * Not all label file options are in use, also not all options are in labelfiles.
# (because this is TclTk text, v.label options don't exactly map onto what is available
# in TclTk. AFAICT, all possible matches are implemented)
-# * Label configuration options are not separated from displayed label options. It causes
-# label options to change after every screen redraw. This way it was already working :)
-# (Unless you check the "override" box, it will default to the values in the labels file.
-# I fixed a few that might not have been sticking also - CMB)
# * Ability to override single option. Like: use whatever defined in labelfile, except font size
# (Agreed. A TODO if there is time. Needs substantial reconfiguration of options panel)
# * Label rotation. (not available in TclTk - CMB)
# * Somtime label enclosing box height is not calculated correctly.
-# * Ability to display label point and configure it. (I don't understand this)
+# * Ability to display label point (coordinates as site) and configure it.
#
namespace eval GmCLabels {
- variable array opt ;# labels current options
+ variable array opt ;# labels current global options
+ variable array ropt;# labels resulting options (global or read from file)
variable count 1
variable array tree ;# mon
variable optlist
variable array dup ;# layer
+ variable canvasId ;# List of canvas item ID's for deletion on update
}
@@ -39,6 +37,7 @@
variable count
variable optlist
variable dup
+ variable canvasId
global mon
global iconpath
@@ -68,7 +67,8 @@
-window $frm \
-drawcross auto
- set opt($count,1,_check) 1
+ set opt($count,1,_check) 1
+ set ropt($count,1,_check) 1
set dup($count) 0
set opt($count,1,xcoord) 1.0
@@ -90,8 +90,9 @@
set opt($count,1,ltxt) ""
set opt($count,1,lhoffset) 2 ;# space between label and enclosing box
set opt($count,1,lvoffset) 2 ;# space between label and enclosing box
- set opt($count,1,lopaque) "yes"
- set opt($count,1,lboxbenable) "yes"
+ set opt($count,1,lopaque) 1
+ set opt($count,1,lboxenable) 1
+ set opt($count,1,lboxbenable) 1
set opt($count,1,lborder) "black"
set opt($count,1,lbackground) "yellow"
set opt($count,1,lbwidth) 1
@@ -100,12 +101,14 @@
set optlist { _check xcoord ycoord xoffset yoffset labels lfont lfontfamily lfontsize \
lfontweight lfontslant lfontunderline lfontoverstrike lfill lwidth \
- lanchor ljust ltxt lhoffset lvoffset lopaque lboxbenable lborder lbackground \
+ lanchor ljust ltxt lhoffset lvoffset lopaque lboxenable lboxbenable lborder lbackground \
lbwidth lboxlenable override }
foreach key $optlist {
set opt($count,0,$key) $opt($count,1,$key)
- }
+ }
+
+ set canvasId [ list ] ;# CanvasId is an empty list
incr count
return $node
@@ -119,7 +122,7 @@
}
proc GmCLabels::select_labels { id } {
- set m [GSelect paint/labels title "Label file"]
+ set m [GSelect paint/labels title [G_msg "Label file"]]
if { $m != "" } {
set GmCLabels::opt($id,1,labels) $m
GmTree::autonamel $m
@@ -219,13 +222,10 @@
# labels options3
set row [ frame $frm.lbltopt3 ]
- Label $row.a -text [G_msg "Enclose label in box: "]
+ Label $row.a -text [G_msg "Enclose label in box: "]
checkbutton $row.b -variable GmCLabels::opt($id,1,lboxenable)
- $row.b select
Label $row.c -text [G_msg "Draw label background: "]
- checkbutton $row.d -variable GmCLabels::opt($id,1,lopaque) \
- -command " if { $opt($id,1,lopaque) } { set opt($id,1,lboxenable) 1 } else { set opt($id,1,lboxenable) 0 }"
- $row.d select
+ checkbutton $row.d -variable GmCLabels::opt($id,1,lopaque)
Label $row.e -text [G_msg "Background color:"]
SelectColor $row.f -type menubutton -variable GmCLabels::opt($id,1,lbackground)
pack $row.a $row.b $row.c $row.d $row.e $row.f -side left
@@ -233,14 +233,12 @@
# labels options4
set row [ frame $frm.lbltopt4 ]
- Label $row.a -text [G_msg "Draw box outline: "]
- checkbutton $row.b -variable GmCLabels::opt($id,1,lboxbenable) \
- -command " if { $opt($id,1,lboxbenable) } { set opt($id,1,lboxenable) 1 } else { set opt($id,1,lboxenable) 0 }"
- $row.b select
+ Label $row.a -text [G_msg "Draw box outline: "]
+ checkbutton $row.b -variable GmCLabels::opt($id,1,lboxbenable)
Label $row.c -text [G_msg "Border width:"]
Entry $row.d -width 3 -text "$opt($id,1,lbwidth)" \
-textvariable GmCLabels::opt($id,1,lbwidth)
- Label $row.e -text [G_msg "Border color:"]
+ Label $row.e -text [G_msg "Border color:"]
SelectColor $row.f -type menubutton -variable GmCLabels::opt($id,1,lborder)
pack $row.a $row.b $row.c $row.d $row.e $row.f -side left
pack $row -side top -fill both -expand yes
@@ -269,7 +267,7 @@
Label $row.e -text [G_msg "size:"]
Entry $row.f -width 5 -text GmCLabels::opt($id,1,lfontsize) \
-textvariable GmCLabels::opt($id,1,lfontsize)
- Label $row.g -text [G_msg " color"]
+ Label $row.g -text [G_msg " color"]
SelectColor $row.h -type menubutton -variable GmCLabels::opt($id,1,lfill)
pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g $row.h -side left
pack $row -side top -fill both -expand yes
@@ -304,10 +302,13 @@
variable tree
variable dup
variable count
+ variable canvasId
set tree($mon) $GmTree::tree($mon)
set id [GmTree::node_id $node]
+ # No need to do anything, if we are invisible/unset.
+ if { ! ( $opt($id,1,_check) ) } { return }
if {$opt($id,1,labels) == "" } {return}
set can($mon) $MapCanvas::can($mon)
@@ -318,8 +319,6 @@
} else {
set labelpath "$env(GISDBASE)/$env(LOCATION_NAME)/$env(MAPSET)/paint/labels/$opt($id,1,labels)"
}
-
- if { ! ( $opt($id,1,_check) ) } { return }
# open the v.label file for reading
if { [catch {set labelfile [open $labelpath r]} err ] } {
@@ -327,6 +326,10 @@
return
}
+ # Delete current labels on Canvas and empty ID list
+ $can($mon) delete canvasId
+ set canvasId [ list ] ;# CanvasId is an empty list
+
#loop through coordinates and options for each label
while { [gets $labelfile in] > -1 } {
set key ""
@@ -340,55 +343,57 @@
switch $key {
"east" {
set east $val
- set opt($id,1,xcoord) [MapCanvas::mape2scrx $mon $east]
+ set ropt($id,1,xcoord) [MapCanvas::mape2scrx $mon $east]
}
"north" {
set north $val
- set opt($id,1,ycoord) [MapCanvas::mapn2scry $mon $north]
+ set ropt($id,1,ycoord) [MapCanvas::mapn2scry $mon $north]
}
"xoffset" {
if { $opt($id,1,override) == 0 } {
- set opt($id,1,xoffset) $val
+ set ropt($id,1,xoffset) $val
+ set ropt($id,1,xcoord) [expr $ropt($id,1,xcoord) + $ropt($id,1,xoffset)]
+ } else {
+ set ropt($id,1,xcoord) [expr $ropt($id,1,xcoord) + $opt($id,1,xoffset)]
}
- if { $opt($id,1,xoffset) != "" } {
- set opt($id,1,xcoord) [expr $opt($id,1,xcoord) + $opt($id,1,xoffset)]
- }
}
"yoffset" {
if { $opt($id,1,override) == 0 } {
- set opt($id,1,yoffset) $val
+ set ropt($id,1,yoffset) $val
+ set ropt($id,1,ycoord) [expr $ropt($id,1,ycoord) + $ropt($id,1,yoffset)]
+ } else {
+ set ropt($id,1,ycoord) [expr $ropt($id,1,ycoord) + $opt($id,1,yoffset)]
}
- if { $opt($id,1,yoffset) != "" } {
- set opt($id,1,ycoord) [expr $opt($id,1,ycoord) + $opt($id,1,yoffset)]
- }
}
"ref" {
if { $opt($id,1,override) == 0 } {
- set opt($id,1,lanchor) $val
+ set ropt($id,1,lanchor) $val
+ } else {
+ set ropt($id,1,lanchor) $opt($id,1,lanchor)
}
- switch $opt($id,1,lanchor) {
- "lower left" { set opt($id,1,anchor) "ne"}
- "left lower" { set opt($id,1,anchor) "ne"}
- "lower" { set opt($id,1,anchor) "n" }
- "lower center" { set opt($id,1,anchor) "n" }
- "center lower" { set opt($id,1,anchor) "n" }
- "lower right" { set opt($id,1,anchor) "nw"}
- "right lower" { set opt($id,1,anchor) "nw"}
- "left" { set opt($id,1,anchor) "e" }
- "center left" { set opt($id,1,anchor) "e" }
- "left center" { set opt($id,1,anchor) "e" }
- "center" { set opt($id,1,anchor) "center" }
- "right" { set opt($id,1,anchor) "w" }
- "center right" { set opt($id,1,anchor) "w" }
- "right center" { set opt($id,1,anchor) "w" }
- "upper left" { set opt($id,1,anchor) "se"}
- "left upper" { set opt($id,1,anchor) "se"}
- "upper" { set opt($id,1,anchor) "s" }
- "upper center" { set opt($id,1,anchor) "s" }
- "center upper" { set opt($id,1,anchor) "s" }
- "upper right" { set opt($id,1,anchor) "sw"}
- "right upper" { set opt($id,1,anchor) "sw"}
- default { set opt($id,1,anchor) "w" }
+ switch $ropt($id,1,lanchor) {
+ "lower left" { set ropt($id,1,anchor) "ne"}
+ "left lower" { set ropt($id,1,anchor) "ne"}
+ "lower" { set ropt($id,1,anchor) "n" }
+ "lower center" { set ropt($id,1,anchor) "n" }
+ "center lower" { set ropt($id,1,anchor) "n" }
+ "lower right" { set ropt($id,1,anchor) "nw"}
+ "right lower" { set ropt($id,1,anchor) "nw"}
+ "left" { set ropt($id,1,anchor) "e" }
+ "center left" { set ropt($id,1,anchor) "e" }
+ "left center" { set ropt($id,1,anchor) "e" }
+ "center" { set ropt($id,1,anchor) "center" }
+ "right" { set ropt($id,1,anchor) "w" }
+ "center right" { set ropt($id,1,anchor) "w" }
+ "right center" { set ropt($id,1,anchor) "w" }
+ "upper left" { set ropt($id,1,anchor) "se"}
+ "left upper" { set ropt($id,1,anchor) "se"}
+ "upper" { set ropt($id,1,anchor) "s" }
+ "upper center" { set ropt($id,1,anchor) "s" }
+ "center upper" { set ropt($id,1,anchor) "s" }
+ "upper right" { set ropt($id,1,anchor) "sw"}
+ "right upper" { set ropt($id,1,anchor) "sw"}
+ default { set ropt($id,1,anchor) "w" }
}
}
"font" {
@@ -397,17 +402,17 @@
}
"color" {
if { $opt($id,1,override) == 0 } {
- set opt($id,1,lfill) [color_grass_to_tcltk $val]
+ set ropt($id,1,lfill) [color_grass_to_tcltk $val]
+ } else {
+ set ropt($id,1,lfill) $opt($id,1,lfill)
}
- if { $opt($id,1,lfill) == "" } {
- set opt($id,1,lfill) "#000000"
+ if { $ropt($id,1,lfill) == "" } {
+ set ropt($id,1,lfill) "#000000"
}
}
- "fontsize" {
- if { $opt($id,1,override) == 0 } {set opt($id,1,lfontsize) $val}
- }
"width" {
- if { $opt($id,1,override) == 0 } {set opt($id,1,lbwidth) $val}
+ if { $opt($id,1,override) == 0 } { set ropt($id,1,lbwidth) $val
+ } else { set ropt($id,1,lbwidth) $opt($id,1,lbwidth) }
}
"hcolor" {
# not available in TclTk
@@ -419,124 +424,145 @@
}
"background" {
if { $opt($id,1,override) == 0 } {
- if {$val != "none"} {
- set opt($id,1,lbackground) [color_grass_to_tcltk $val]
- } else {
- set opt($id,1,lbackground) ""
- }
+ if {$val != "none"} {
+ set ropt($id,1,lbackground) [color_grass_to_tcltk $val]
+ } else {
+ set ropt($id,1,lbackground) ""
+ }
+ } else {
+ set ropt($id,1,lbackground) $opt($id,1,lbackground)
}
}
"border" {
if { $opt($id,1,override) == 0 } {
- if {$val != "none"} {
- set opt($id,1,lborder) [color_grass_to_tcltk $val]
- } else {
- set opt($id,1,lborder) ""
- }
+ if {$val != "none"} {
+ set ropt($id,1,lborder) [color_grass_to_tcltk $val]
+ } else {
+ set ropt($id,1,lborder) ""
+ }
+ } else {
+ set ropt($id,1,lborder) $opt($id,1,lborder)
}
}
"opaque" {
- if { $opt($id,1,override) == 0 } {set opt($id,1,lopaque) $val}
+ if { $opt($id,1,override) == 0 } { set ropt($id,1,lopaque) $val
+ } else { set ropt($id,1,lopaque) $opt($id,1,lopaque) }
}
"rotate" {
# not available in TclTk
set x ""
}
+ "fontsize" {
+ # Fontsize and size are exclusive options.
+ if { $opt($id,1,override) == 0 } {
+ set ropt($id,1,lfontsize) $val
+ } else {
+ set ropt($id,1,lfontsize) $opt($id,1,lfontsize)
+ }
+ set ropt($id,1,lwidth) $opt($id,1,lwidth)
+ }
"size" {
- if { $opt($id,1,override) == 0 } {set opt($id,1,lwidth) $val}
+ # Size is font size in location units (i.e. meters)
+ # No support for such feature in gis.m unless somebody will open a bug for it.
+ set ropt($id,1,lfontsize) $opt($id,1,lfontsize)
+ set ropt($id,1,lwidth) $opt($id,1,lwidth)
}
"text" {
- set opt($id,1,ltxt) [subst -nocommands -novariables $val]
+ set ropt($id,1,ltxt) [subst -nocommands -novariables $val]
+ set ropt($id,1,lfont) $opt($id,1,lfont)
# check to see if there are line breaks in the text
- set newlines [expr [llength [split $opt($id,1,ltxt) "\n"]] - 1]
+ set newlines [llength [split $ropt($id,1,ltxt) "\n"]]
# create each label when loop gets to a text line in the labels file
# Here should be set all font related options, that come from labelfile
- if {[info exists opt($id,1,lfontsize)]} {
- font configure $opt($id,1,lfont) -size $opt($id,1,lfontsize)
+ if {[info exists ropt($id,1,lfontsize)]} {
+ font configure $ropt($id,1,lfont) -size $ropt($id,1,lfontsize)
}
# set the label width and height
- set linelen [font measure $opt($id,1,lfont) $opt($id,1,ltxt)]
- if {$linelen < $opt($id,1,lwidth)} {
- set wid [expr $linelen + 8]
- set lineh [expr $newlines * [font metrics $opt($id,1,lfont) -linespace] + 8]
+ set linelen [font measure $ropt($id,1,lfont) $ropt($id,1,ltxt)]
+ if {$linelen < $ropt($id,1,lwidth)} {
+ set wid [expr $linelen + 2]
+ set lineh [expr $newlines * [font metrics $ropt($id,1,lfont) -linespace]]
} else {
- set wid $opt($id,1,lwidth)
- set lineh [expr $newlines * (ceil($linelen/$opt($id,1,lwidth))+1)\
- * [font metrics $opt($id,1,lfont) -linespace] + 8]
+ set wid $opt($id,1,lwidth); # This is too wide as wrapped text lines might be shorter.
+ set lineh [expr $newlines * (ceil($linelen/($ropt($id,1,lwidth)-10.0)))\
+ * [font metrics $ropt($id,1,lfont) -linespace]]; # Somtimes font measure gives wrong length. -10.0 is a hack.
}
- if {$opt($id,1,lopaque) != "yes"} {
+ # transparent background
+ if {!$ropt($id,1,lopaque)} {
set lbackground ""
- } else { set lbackground $opt($id,1,lbackground) }
+ } else { set lbackground $ropt($id,1,lbackground) }
+ # no box line
if {!$opt($id,1,lboxbenable)} {
set wdth 0
- } else { set wdth $opt($id,1,lbwidth) }
+ } else { set wdth $ropt($id,1,lbwidth) }
# create box around text
-
- switch $opt($id,1,anchor) {
- "ne" {
- set boxcenter_x [expr {$opt($id,1,xcoord) - ($wid-4) / 2}]
- set boxcenter_y [expr {$opt($id,1,ycoord) + ($lineh+4) / 2}]
- }
- "n" {
- set boxcenter_x $opt($id,1,xcoord)
- set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
- }
- "nw" {
- set boxcenter_x [expr {$opt($id,1,xcoord) + ($wid-4) / 2}]
- set boxcenter_y [expr {$opt($id,1,ycoord) + ($lineh+4) / 2}]
- }
- "e" {
- set boxcenter_x [expr {$opt($id,1,xcoord) - ($wid-4) / 2}]
- set boxcenter_y $opt($id,1,ycoord)
- }
- "center" {
- set boxcenter_x $opt($id,1,xcoord)
- set boxcenter_y $opt($id,1,ycoord)
- }
- "w" {
- set boxcenter_x [expr {$opt($id,1,xcoord) + ($wid-4) / 2}]
- set boxcenter_y $opt($id,1,ycoord)
- }
- "se" {
- set boxcenter_x [expr {$opt($id,1,xcoord) - ($wid-4) / 2}]
- set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
- }
- "s" {
- set boxcenter_x $opt($id,1,xcoord)
- set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
- }
- "sw" {
- set boxcenter_x [expr {$opt($id,1,xcoord) + ($wid-4) / 2}]
- set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
- }
- default {
- set boxcenter_x $opt($id,1,xcoord)
- set boxcenter_y $opt($id,1,ycoord)
- }
+ if {$opt($id,1,lboxenable)} {
+ switch $ropt($id,1,anchor) {
+ "ne" {
+ set boxcenter_x [expr {$ropt($id,1,xcoord) - ($wid-4) / 2}]
+ set boxcenter_y [expr {$ropt($id,1,ycoord) + ($lineh+4) / 2}]
+ }
+ "n" {
+ set boxcenter_x $ropt($id,1,xcoord)
+ set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
+ }
+ "nw" {
+ set boxcenter_x [expr {$ropt($id,1,xcoord) + ($wid-4) / 2}]
+ set boxcenter_y [expr {$ropt($id,1,ycoord) + ($lineh+4) / 2}]
+ }
+ "e" {
+ set boxcenter_x [expr {$ropt($id,1,xcoord) - ($wid-4) / 2}]
+ set boxcenter_y $ropt($id,1,ycoord)
+ }
+ "center" {
+ set boxcenter_x $ropt($id,1,xcoord)
+ set boxcenter_y $ropt($id,1,ycoord)
+ }
+ "w" {
+ set boxcenter_x [expr {$ropt($id,1,xcoord) + ($wid-4) / 2}]
+ set boxcenter_y $ropt($id,1,ycoord)
+ }
+ "se" {
+ set boxcenter_x [expr {$ropt($id,1,xcoord) - ($wid-4) / 2}]
+ set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
+ }
+ "s" {
+ set boxcenter_x $ropt($id,1,xcoord)
+ set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
+ }
+ "sw" {
+ set boxcenter_x [expr {$ropt($id,1,xcoord) + ($wid-4) / 2}]
+ set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
+ }
+ default {
+ set boxcenter_x $ropt($id,1,xcoord)
+ set boxcenter_y $ropt($id,1,ycoord)
+ }
+ }
}
if {$opt($id,1,lboxenable)} {
# draw recangle around label
- $can($mon) create rectangle \
+ lappend canvasId [$can($mon) create rectangle \
[expr {$boxcenter_x - $opt($id,1,lhoffset) - $wid / 2}] \
[expr {$boxcenter_y -2- $opt($id,1,lvoffset) - $lineh / 2}]\
[expr {$boxcenter_x + $opt($id,1,lhoffset) + $wid / 2}] \
[expr {$boxcenter_y + $opt($id,1,lvoffset) + $lineh / 2}]\
-width $wdth \
- -outline $opt($id,1,lborder) \
- -fill $lbackground
+ -outline $ropt($id,1,lborder) \
+ -fill $lbackground]
}
- $can($mon) create text $opt($id,1,xcoord) $opt($id,1,ycoord) \
- -anchor $opt($id,1,anchor) \
+ lappend canvasId [$can($mon) create text $ropt($id,1,xcoord) $ropt($id,1,ycoord) \
+ -anchor $ropt($id,1,anchor) \
-justify $opt($id,1,ljust) \
-width $wid \
- -fill $opt($id,1,lfill) \
- -font $opt($id,1,lfont) \
- -text $opt($id,1,ltxt)
+ -fill $ropt($id,1,lfill) \
+ -font $ropt($id,1,lfont) \
+ -text $ropt($id,1,ltxt)]
}
default {
#for anything else, just move on
@@ -562,7 +588,7 @@
variable dup
global iconpath
- set node "PS labels:$count"
+ set node "clabels:$count"
set dup($count) 1
set frm [ frame .clabelsicon$count]
@@ -586,12 +612,12 @@
if { $opt($id,1,labels) == ""} {
$tree insert $sellayer $parent $node \
- -text "clabels $count" \
+ -text "PS labels $count" \
-window $frm \
-drawcross auto
} else {
$tree insert $sellayer $parent $node \
- -text "$opt($id,1,clabels)" \
+ -text "$opt($id,1,labels)" \
-window $frm \
-drawcross auto
}
More information about the grass-commit
mailing list