1
##########################################################################
3
# Panel to facilitate north arrow 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]
30
set Nv_(arw_font) {"helvetica" "17"}
32
##########################################################################
34
proc mkarrowPanel { BASE } {
36
global n_arrow_size n_arrow arw_text_size
37
global arw_clr arw_text_clr
40
# defaults (for some reason not recognizing globals)
41
set n_arrow_size [expr int([Nget_longdim]/8.)]
43
set arw_text_clr "#DDDDDD"
44
#This doesn't do anything currently
45
set arw_text_size "not funct."
47
set panel [St_create {window name size priority} $BASE [G_msg "North arrow"] 2 5]
48
frame $BASE -relief flat -borderwidth 0
49
Nv_mkPanelname $BASE [G_msg "North Arrow Panel"]
51
# This section contains widgets for placing the north arrow
52
set rbase1 [frame $BASE.arrow]
53
Label $rbase1.arrow_lbl -text [G_msg "Arrow: "] -fg black
54
LabelEntry $rbase1.arrow_size -relief sunken -entrybg white \
55
-textvariable n_arrow_size -width 8 -justify right\
56
-label [G_msg "size (in map units) "] -fg black -labelfont $nviztxtfont
57
pack $rbase1.arrow_lbl $rbase1.arrow_size -side left -expand no -fill none
59
$rbase1.arrow_size bind <Key> {if {$Nauto_draw == 1} {Ndraw_all}}
61
Button $rbase1.color -text [G_msg "Color"] \
62
-bg $arw_clr -width 8 -bd 1 \
63
-command "change_arrow_color $rbase1.color arrow" \
65
pack $rbase1.color -side right \
66
-expand yes -fill none -anchor e
68
pack $rbase1 -side top -expand yes -fill both -padx 3 -pady 4
70
# This section contains widgets for north text
71
set rbase2 [frame $BASE.txt]
72
Label $rbase2.txt_lbl -text [G_msg "North text: "] -fg black
73
Button $rbase2.font -text [G_msg "Font"] \
74
-width 8 -command "select_arw_font $rbase2.font" -bd 1 \
75
-helptext [G_msg "Select font family, size, and style"]
76
pack $rbase2.txt_lbl $rbase2.font -side left -expand no -fill none
78
Button $rbase2.color -text [G_msg "Color"] \
79
-bg $arw_text_clr -width 8 -bd 1 \
80
-command "change_arrow_color $rbase2.color text" \
82
pack $rbase2.color -side right \
83
-expand yes -fill none -anchor e
85
pack $rbase2 -side top -expand yes -fill both -padx 3
88
set rbase3 [frame $BASE.button]
89
Button $rbase3.place -text [G_msg "Place arrow"] -bd 1 \
90
-command "bind_mouse $Nv_(TOP).canvas; $Nv_(TOP) configure -cursor plus"
91
pack $rbase3.place -expand yes -side left -expand no -fill none
93
button $rbase3.close -text [G_msg "Close"] -command "Nv_closePanel $BASE" \
95
pack $rbase3.close -side right -fill none -expand no
96
pack $rbase3 -side top -fill both -expand yes -padx 3 -pady 4
101
proc bind_mouse { W } {
104
place_narrow %W %x %y
105
if {$Nauto_draw == 1} {
109
$Nv_(TOP) configure -cursor $Nv_(cursor)
114
###############################################################################
115
# use Tk dialog to select fonts
116
proc select_arw_font {fbutton} {
119
set fon [SelectFont $fbutton.fontset -type dialog -sampletext [G_msg "The quick brown fox jumps over the lazy dog"] -title [G_msg "Select font"] -font Nv_(arw_font)]
120
if { $fon != "" } {set Nv_(arw_font) $fon}
123
#############################################################
125
# Simple routine to change the color of Arrow.
126
# text color not yet user settable.
127
proc change_arrow_color { me type } {
129
global arw_clr arw_text_clr
132
# set color button background to match arrow color
133
set clr [lindex [$me configure -bg] 4]
134
set clr [mkColorPopup .colorpop arw_clr $clr 1]
135
if {$type == "arrow"} {
137
} elseif {$type == "text"} {
138
set arw_text_clr $clr
140
$me configure -bg $clr
142
# set color button text to black or white depending on
144
set clrnum [split $clr {}]
145
set rhex "0x[lindex $clrnum 1][lindex $clrnum 2]"
146
set ghex "0x[lindex $clrnum 3][lindex $clrnum 4]"
147
set bhex "0x[lindex $clrnum 5][lindex $clrnum 6]"
148
set clrsum [expr $rhex + $ghex +$bhex]
150
if {$clrsum < 400 } {
151
$me configure -fg "white"
153
$me configure -fg "black"
155
if {$Nauto_draw == 1} {
160
###########################
161
proc place_narrow {W x y} {
163
global Nv_ n_arrow n_arrow_size
164
global n_arrow_x n_arrow_y n_arrow_z
165
global arw_clr arw_text_clr
168
set y [expr $Nv_(height) - $y]
170
#create font description
174
set clr $arw_text_clr
176
if {[lindex $Nv_(arw_font) 0] != ""} {set Nv_(arw_FontType) [lindex $Nv_(arw_font) 0]}
177
if {[lindex $Nv_(arw_font) 1] != ""} {set Nv_(arw_FontSize) [lindex $Nv_(arw_font) 1]}
178
if {[lsearch $Nv_(arw_font) "bold"] != -1} {set weight "bold"}
179
if {[lsearch $Nv_(arw_font) "italic"] != -1} {set slant "i"}
180
if {[lsearch $Nv_(arw_font) "underline"] != -1} {set style "underline"}
181
if {[lsearch $Nv_(arw_font) "overstrike"] != -1} {set style "overstrike"}
183
set font "*-$Nv_(arw_FontType)-$weight-$slant-normal-$style-$Nv_(arw_FontSize)-*-*-*-*-*-*-*"
185
# Nplace_label $Nv_(label_text) $font $Nv_(arw_FontSize) $arw_text_clr $sx $sy
187
#Draw North Arrow at selected point
188
set curr [Nget_current surf]
190
set location [Nset_Narrow $x $y $curr $n_arrow_size]
191
set n_arrow_x [lindex $location 0]
192
set n_arrow_y [lindex $location 1]
193
set n_arrow_z [lindex $location 2]
195
Ndraw_Narrow $n_arrow_x $n_arrow_y $n_arrow_z $n_arrow_size \
196
$arw_clr $arw_text_clr
201
#remove canvas binding