1
##########################################################################
3
# Panel to facilitate scale placement for finishing images produced
6
##########################################################################
9
# U.S. Army Construction Engineering Research Laboratory
11
# Major update of GUI Nov 2006, Michael Barton, Arizona State University
13
##########################################################################
14
# COPYRIGHT: (C) 2006 by Michael Barton and the GRASS Development Team
16
# This program is free software under the GNU General Public
17
# License (>=v2). Read the file COPYING that comes with GRASS
20
##########################################################################
25
# Panel specific globals
29
set Nv_(cursor) [$Nv_(TOP) cget -cursor]
31
##########################################################################
33
proc mkscalePanel { BASE } {
35
global scalebar_size scalebar
36
global bar_clr bar_text_clr
40
set scalebar_size 1000
42
set bar_text_clr "#DDDDDD"
43
set bar_text_size "non funct."
45
set panel [St_create {window name size priority} $BASE [G_msg "Scale bar"] 2 5]
46
frame $BASE -relief flat -borderwidth 0
47
Nv_mkPanelname $BASE [G_msg "Scale Bar Panel"]
49
# This section contains widgets for placing the scale bar
50
set rbase1 [frame $BASE.scale]
51
Label $rbase1.scalebar_lbl -text [G_msg "Scale bar: "] -fg black
52
LabelEntry $rbase1.scalebar_size -relief sunken -entrybg white \
53
-textvariable scalebar_size -width 8 \
54
-label [G_msg "length (in map units) "] -fg black -font $nviztxtfont
55
pack $rbase1.scalebar_lbl $rbase1.scalebar_size -side left -expand no -fill none
57
$rbase1.scalebar_size bind <Key> {if {$Nauto_draw == 1} {Ndraw_all}}
60
Button $rbase1.color -text [G_msg "Color"] \
61
-bg $bar_clr -width 8 -bd 1 \
62
-command "change_scale_color $rbase1.color scale" \
64
pack $rbase1.color -side right \
65
-expand yes -fill none -anchor e
67
pack $rbase1 -side top -expand yes -fill both -padx 3 -pady 4
69
# This section contains widgets for scale text
70
set rbase2 [frame $BASE.txt]
71
Label $rbase2.txt_lbl -text [G_msg "Scale text: "] -fg black
72
LabelEntry $rbase2.txt_size -relief sunken -entrybg grey \
73
-textvariable bar_text_size -width 8 -justify right\
74
-label [G_msg "size "] -fg black -labelfont $nviztxtfont
75
pack $rbase2.txt_lbl $rbase2.txt_size -side left -expand no -fill none
77
$rbase2.txt_size bind <Key> {if {$Nauto_draw == 1} {Ndraw_all}}
79
Button $rbase2.color -text [G_msg "Color"] \
80
-bg $bar_text_clr -width 8 -bd 1 \
81
-command "change_scale_color $rbase2.color text" \
83
pack $rbase2.color -side right \
84
-expand yes -fill none -anchor e
86
pack $rbase2 -side top -expand yes -fill both -padx 3
89
set rbase3 [frame $BASE.button]
90
Button $rbase3.place -text [G_msg "Place scale"] -bd 1 \
91
-command "sb_bind_mouse $Nv_(TOP).canvas; $Nv_(TOP) configure -cursor plus"
92
pack $rbase3.place -expand yes -side left -expand no -fill none
94
button $rbase3.close -text [G_msg "Close"] -command "Nv_closePanel $BASE" \
96
pack $rbase3.close -side right -fill none -expand no
97
pack $rbase3 -side top -fill both -expand yes -padx 3 -pady 4
102
proc sb_bind_mouse { W } {
105
if {$Nauto_draw == 1} {
109
$Nv_(TOP) configure -cursor $Nv_(cursor)
113
#############################################################
115
# Simple routine to change the colors
116
# text color not yet user settable.
117
proc change_scale_color { me type } {
119
global bar_clr bar_text_clr
122
# set color button background to match scale/text color
123
set clr [lindex [$me configure -bg] 4]
124
set clr [mkColorPopup .colorpop bar_clr $clr 1]
126
if {$type == "scale"} {
128
} elseif {$type == "text"} {
129
set bar_text_clr $clr
132
$me configure -bg $clr
134
# set color button text to black or white depending on
136
set clrnum [split $clr {}]
137
set rhex "0x[lindex $clrnum 1][lindex $clrnum 2]"
138
set ghex "0x[lindex $clrnum 3][lindex $clrnum 4]"
139
set bhex "0x[lindex $clrnum 5][lindex $clrnum 6]"
140
set clrsum [expr $rhex + $ghex +$bhex]
142
if {$clrsum < 400 } {
143
$me configure -fg "white"
145
$me configure -fg "black"
147
if {$Nauto_draw == 1} {
152
###########################
153
proc place_scale {W x y} {
155
global Nv_ scalebar scalebar_size
156
global scalebar_x scalebar_y scalebar_z
157
global bar_clr bar_text_clr
160
set y [expr $Nv_(height) - $y]
162
#Draw scale bar at selected point
163
set curr [Nget_current surf]
165
set location [Nset_ScaleBar $x $y $curr $scalebar_size]
166
set scalebar_x [lindex $location 0]
167
set scalebar_y [lindex $location 1]
168
set scalebar_z [lindex $location 2]
170
Ndraw_ScaleBar $scalebar_x $scalebar_y $scalebar_z $scalebar_size \
171
$bar_clr $bar_text_clr
176
#remove canvas binding