1
##########################################################################
4
# further changes GRASS Development Team
5
# This file contains a palette of commonly used widgets. It is
6
# expected that Nviz panels will be constructed using these widgets
7
# plus basic Tk functionality.
8
##########################################################################
9
# Update by Michael Barton, Arizona State University, Nov. 2006
11
# COPYRIGHT: (C) 2006 GRASS Development Team
13
# This program is free software under the GNU General Public
14
# License (>=v2). Read the file COPYING that comes with GRASS
17
##########################################################################
18
if {![info exists Nauto_draw]} {set Nauto_draw 1}
20
##########################################################################
21
# procedure to drag canvas item
22
proc Nv_itemDrag {c info x y} {
23
set lastx [St_get $info lastx]
24
set lasty [St_get $info lasty]
25
set item [St_get $info item]
26
set w [St_get $info width]
27
set h [St_get $info height]
30
if { $item == "puck"} {
32
$c create line $x $y [expr $w/2] [expr $h/2] -fill gray70 -arrow last -tags line
34
$c move $item [expr $x-$lastx] [expr $y-$lasty]
39
##########################################################################
40
# procedure to get current x-y position of widget
41
# Returns position as [list x y] ratio
42
##########################################################################
43
proc Nv_getXYPos { iname } {
46
set x [St_get $Nv_($iname) lastx]
47
set y [St_get $Nv_($iname) lasty]
48
set w [St_get $Nv_($iname) width]
49
set h [St_get $Nv_($iname) height]
50
set x [expr $x/($w + 0.0) ]
51
set y [expr $y/($h + 0.0) ]
56
##########################################################################
57
# procedure to make x-y position "widget" as seen in Nviz
58
##########################################################################
59
proc Nv_mkXYScale {C {type puck} {name null} {height 100} {width 100} {x 50} {y 50} {cmd null} {upcmd null}} {
63
canvas $C -relief sunken -borderwidth 3 -height $height -width $width -bg white
68
if {[string compare $type puck] == 0} {
70
$C create text [expr $width - 2] [expr $height/2] -text [G_msg "E"] -fill black
71
$C create text 3 [expr $height/2] -text [G_msg "W"] -fill black -anchor w
72
$C create text [expr $width/2] 2 -text [G_msg "N"] -fill black -anchor n
73
$C create text [expr $width/2] $height -text [G_msg "S"] -fill black -anchor s
74
$C create line $x $y [expr $width/2] [expr $height/2] -tags line \
75
-fill gray70 -arrow last
76
$C create oval $x1 $y1 $x2 $y2 -width 1 -outline gray70 -fill LightGoldenrod \
79
$C create line [expr 0 -$width] $x [expr 2 * $width] $x \
80
-width 1 -tags cross -fill gray70
81
$C create line $y [expr 0 - $height] $y [expr 2*$height] \
82
-width 1 -tags cross -fill gray70
84
if {[string compare $name null] == 0} {set name $C.item}
85
set Nv_($name) [St_create {item lastx lasty width height} $type $x $y $width $height]
86
bind $C <1> "Nset_cancel 1"
87
bind $C <1> "+ Nv_itemDrag $C $Nv_($name) %x %y; Nv_xyCallback $cmd $width $height %x %y "
88
bind $C <B1-Motion> "Nv_itemDrag $C $Nv_($name) %x %y; Nv_xyCallback $cmd $width $height %x %y "
90
bind $C <ButtonRelease> "Nv_itemDrag $C $Nv_($name) %x %y; Nv_xyCallback $upcmd $width $height %x %y; dodraw"
97
if {$Nauto_draw == 1} {
103
proc Nv_xyCallback { cmd w h x y } {
106
if [string compare $cmd null] {
107
set x [expr (1.0*$x)/$w]
108
set y [expr (1.0*$y)/$h]
113
##########################################################################
114
# procedure to change scale setting
115
##########################################################################
116
proc Nv_changeScale {S {v 0}} {
121
proc Nv_setEntry {E V} {
122
$E delete 0 end; $E insert 0 $V
125
proc Nv_scaleCallback { S {who s} {decimal 0} {cmd null} {val 0} } {
128
set val [expr $val/pow(10,$decimal)]
129
Nv_setEntry $S.f.entry $val
130
} elseif {$who == "e"} {
131
set min [expr int([lindex [$S.scale configure -to] 4] / pow(10,$decimal))]
132
set max [expr int([lindex [$S.scale configure -from] 4] / pow(10,$decimal))]
139
set val [$S.f.entry get]
140
if {$val < $min} then {
141
$S.scale configure -to [expr int($val*pow(10,$decimal))]
143
if {$val > $max} then {
144
$S.scale configure -from [expr int($val*pow(10,$decimal))]
146
Nv_changeScale $S.scale [expr int($val*pow(10,$decimal))]
147
} elseif {$who == "b"} {
148
Nv_changeScale $S.scale $val
149
set tmpval [expr $val/pow(10,$decimal)]
150
Nv_setEntry $S.f.entry $tmpval
156
proc Nv_floatscaleCallback { S {who s} {decimal 0} {cmd null} {val 0} } {
157
# CMB Nov. 2006: As far as I can tell, decimal is completely ignored.
160
set num [llength [split [expr int($val * 1)] ""]]
164
set num [expr int($num + 2)]
165
set val [format %.5f $val]
168
set num [expr int($num + 4)]
169
set val [format %.3f $val]
173
set num [expr int($num + 3)]
174
set val [format %.2f $val]
176
$S.scale configure -digits $num
177
Nv_setEntry $S.f.entry $val
179
} elseif {$who == "e"} {
180
set min [lindex [$S.scale configure -to] 4]
181
set max [lindex [$S.scale configure -from] 4]
182
set res [lindex [$S.scale configure -resolution] 4]
183
set val [$S.f.entry get]
184
set num [llength [split [expr int($val * 1)] ""]]
186
set num [expr int($num + 4)]
188
set num [expr int($num + 2)]
191
set num [expr int($num + 3)]
194
if {[expr $val < $min]} then {
195
$S.scale configure -to $val
197
if {[expr $val > $max]} then {
198
$S.scale configure -from $val
201
if {[expr abs($val)] < [expr abs($res)]} {
202
set res [expr abs($val)]
204
set res [expr $val/floor($val/$res)]
206
$S.scale configure -digits $num
207
$S.scale configure -resolution $res
209
Nv_changeScale $S.scale $val
210
} elseif {$who == "b"} {
211
set min [lindex [$S.scale configure -to] 4]
212
set max [lindex [$S.scale configure -from] 4]
213
set res [lindex [$S.scale configure -resolution] 4]
214
set num [llength [split [expr int($val * 1)] ""]]
216
set num [expr int($num + 4)]
217
set val [format %.3f $val]
219
set num [expr int($num + 2)]
220
set val [format %.5f $val]
223
set num [expr int($num + 3)]
224
set val [format %.2f $val]
226
if {[expr $val < $min]} then {
227
$S.scale configure -to $val
229
if {[expr $val > $max]} then {
230
$S.scale configure -from $val
233
if {([expr abs($val)] < [expr abs($res)])} {
234
set res [expr abs($val)]
236
set res [expr abs($val/floor($val/$res))]
238
$S.scale configure -resolution $res
241
$S.scale configure -digits $num
242
Nv_changeScale $S.scale $val
243
Nv_setEntry $S.f.entry $val
250
##########################################################################
251
# procedures to make sliders
252
##########################################################################
253
proc Nv_mkScale { S {orient v} {name ---} {from 10000} {to 0} {curr 500} {cmd null} {decimal 0}} {
259
if { $orient == "v" } {
269
scale $S.scale -from $from -length 140 -showvalue 0 -orient $orient \
270
-tickinterval 0 -to $to -width 13 \
271
-activebackground gray80 -background gray90 \
272
-command "Nv_scaleCallback $S s $decimal $cmd"
274
label $S.f.label -text $name
276
Entry $S.f.entry -width 5 -borderwidth 2 -relief sunken \
278
Nv_scaleCallback $S e $decimal $cmd
279
if {$Nauto_draw == 1} {
285
pack $S.scale -side $side -anchor e
286
pack $S.f -side $side -anchor e
287
pack $S.f.label -side $text_side
288
pack $S.f.entry -side $text_side
290
#Bind For Re-Draw Surface
291
bind $S.scale <Any-ButtonRelease> {+
292
if {![llength [info commands tkCancelRepeat]]} {
293
tk::unsupported::ExposePrivateCommand tkCancelRepeat
296
if {![llength [info commands tkScaleEndDrag]]} {
297
tk::unsupported::ExposePrivateCommand tkScaleEndDrag
300
if {![llength [info commands tkScaleActivate]]} {
301
tk::unsupported::ExposePrivateCommand tkScaleActivate
303
tkScaleActivate %W %x %y
304
if {$Nauto_draw == 1} {
313
proc Nv_mkFloatScale { S {orient v} {name ---} {from 10000} {to 0} {curr 500} {cmd null} {decimal 0}} {
318
if { $orient == "v" } {
328
# permits loading of 3D points without surface
329
if {$name == [G_msg "height"] && $curr == inf} {
334
if {$name == [G_msg "z-exag"] && $from == 0.0 && $to == 0.0 && $curr == 0.0 } {
340
#calculate number length for digits var
341
set num [llength [split [expr int($curr * 1)] ""]]
343
set num [expr int($num + 4)]
345
set num [expr int($num + 2)]
348
set num [expr int($num + 3)]
351
scale $S.scale -from $from -length 140 -showvalue 0 -orient $orient \
352
-digits $num -resolution [expr -1.0 * (($to - $from)/140.0)] \
353
-tickinterval 0 -to $to -width 13 \
354
-command "Nv_floatscaleCallback $S s 0 $cmd " \
355
-activebackground gray80 -background gray90
357
label $S.f.label -text $name
358
Entry $S.f.entry -width 5 -borderwidth 2 -relief sunken \
360
Nv_floatscaleCallback $S e 0 $cmd
361
if {$Nauto_draw == 1} {
367
pack $S.scale -side $side
368
pack $S.f -side $side
369
pack $S.f.label -side $text_side
370
pack $S.f.entry -side $text_side
372
#Bind For Re-Draw Surface
373
bind $S.scale <Any-ButtonRelease> {+
374
if {![llength [info commands tkCancelRepeat]]} {
375
tk::unsupported::ExposePrivateCommand tkCancelRepeat
378
if {![llength [info commands tkScaleEndDrag]]} {
379
tk::unsupported::ExposePrivateCommand tkScaleEndDrag
382
if {![llength [info commands tkScaleActivate]]} {
383
tk::unsupported::ExposePrivateCommand tkScaleActivate
385
tkScaleActivate %W %x %y
386
if {$Nauto_draw == 1} {
392
Nv_floatscaleCallback $S b 0 $cmd $curr
397
############################################################################
398
# procedure to make pulldown menus for menu buttons
399
###########################################################################
400
proc Nv_mkMenu { P mname bnames underlines commands} {
403
menubutton $P -text $mname -menu $P.m -underline 0
407
set cmd [concat [lindex $commands $j] \"$i\"]
408
set underline [lindex $underlines $j]
409
if { [lindex $cmd 0] == "Separator"} {
411
} elseif { [lindex $cmd 0] == "Cascade"} {
412
set menu_name [lindex $cmd 1]
413
set menu_build [lindex $cmd 2]
414
$P.m add cascade -label $i -underline $underline -menu \
416
$menu_build $P.m.$menu_name
418
$P.m add command -label $i -underline $underline -command \
419
"inform [concat $i]; $cmd"
427
proc incrEntry { E } {
429
if {[catch {incr val}]} {set val 1}
434
proc decrEntry { E } {
436
if {[catch {incr val -1}]} {set val 1}
437
if {$val < 1} {set val 1}
444
proc Nv_mkArrows {A {name ""} {cmd null} {val 1} {orient v} } {
450
if { $orient == "v" } {
464
button $A.f1.up -bitmap @$bit_map_path/$up -command "incrEntry $A.f2.entry; $cmd $A.f2.entry"
465
button $A.f1.down -bitmap @$bit_map_path/$down -command "decrEntry $A.f2.entry; $cmd $A.f2.entry"
467
pack $A.f1.up $A.f1.down -side $text_side
468
label $A.f2.label -text $name
469
entry $A.f2.entry -width 5 -relief flat
470
$A.f2.entry delete 0 end
471
$A.f2.entry insert 0 $val
472
pack $A.f1 -side $side
473
pack $A.f2.label -side $text_side
474
pack $A.f2.entry -side $text_side
475
pack $A.f2 -side $side
479
############################################################
480
proc Nv_mkPanelname {P name} {
482
frame $P.name -relief groove -borderwidth 2
483
Label $P.name.label -text $name
484
pack $P.name -fill x -side top
485
pack $P.name.label -expand 1
490
#########################################################
491
proc Nv_mkAttbutton {P name} {
493
button $P.$name.b -text "$name" -anchor nw -width 10 \
494
-command "mkAttPopup $P.$name.pop $name 1"
496
set txt [get_curr_status $name]
498
label $P.$name.l -text $txt -anchor ne
499
pack $P.$name.b -side left
500
pack $P.$name.l -side right
505
###################################################################
506
# makes sunken frame with a checkbutton for each item in list L
507
###################################################################
508
proc Nv_mkSurfacelist { P L C type} {
510
frame $P -relief sunken
513
set name [Nget_map_name $i surf]
514
checkbutton $P.$j -relief flat -text $name -anchor w\
515
-command "change_surf_list $C $i" \
517
if {0 != [$C surf_is_selected Nsurf$i]} {
523
pack $P.$j -fill x -expand 1 -side top
530
proc change_surf_list {C id} {
532
if {0 != [$C surf_is_selected Nsurf$id]} {
533
$C unselect_surf Nsurf$id
535
$C select_surf Nsurf$id
540
proc auto_enable_data {id type} {
542
if {$type == "vect"} {
543
set list [Nget_vect_list]
545
if {0 == [Nvect$i surf_is_selected Nsurf$id]} {
546
Nvect$i select_surf Nsurf$id
550
if {$type == "site"} {
551
set list [Nget_site_list]
553
if {0 == [Nsite$i surf_is_selected Nsurf$id]} {
554
Nsite$i select_surf Nsurf$id
561
proc Nget_map_list { type } {
565
"surf" { set map_list [Nget_surf_list] }
566
"vect" { set map_list [Nget_vect_list] }
567
"site" { set map_list [Nget_site_list] }
568
"vol" { set map_list [Nget_vol_list] }
574
proc Nget_map_name {id type} {
577
set map_name [Nsurf$id get_att topo]
578
if {[lindex $map_name 0] == "map"} then {
579
return [lindex $map_name 1]
581
return "constant#$id"
584
"vect" { return [Nvect$id get_att map] }
585
"site" { return [Nsite$id get_att map] }
586
"vol" { return [Nvol$id get_att map] }
590
proc mkMapList { P type {cmd null}} {
592
set list [Nget_map_list $type]
593
set name [Nget_current $type]
595
if {[llength $list] == 0} {
596
set name [G_msg "None Loaded"]
598
set n [lsearch $list $name]
599
set list [lreplace $list $n $n]
600
set name [Nget_map_name $name $type]
603
menubutton $P -text $name -menu $P.m -relief sunken
606
set map_name [Nget_map_name $i $type]
607
$P.m add command -label "$map_name" \
608
-command "inform Current $type: $i; set_new_curr $type $i; $cmd $i"
615
proc set_new_curr {type name} {
618
if { $name != 0 } then {
619
set L [Nget_map_list $type]
620
set n [lsearch -exact $L $name]
621
#puts "NAME = [Nget_map_name $name $type] LIST = $L INTERNAL NAME: $name"
624
Nset_current $type $name
627
set cmd mk$type\Panel
628
set W $Nv_(P_AREA).$type
629
set pos [Q_get_pos $Nv_(Q) $Nv_($W)]
631
Nv_openPanel $type $pos
635
############################################################
636
# These two routines replace equivalent routines in C code #
637
############################################################
638
proc Nget_current { type } {
642
"surf" { return $Nv_(CurrSurf) }
643
"vect" { return $Nv_(CurrVect) }
644
"site" { return $Nv_(CurrSite) }
645
"sdiff" { return $Nv_(CurrSdiff) }
646
"vol" { return $Nv_(CurrVol) }
650
proc Nset_current { type id } {
654
"surf" { set Nv_(CurrSurf) $id }
655
"vect" { set Nv_(CurrVect) $id }
656
"site" { set Nv_(CurrSite) $id }
657
"sdiff" { set Nv_(CurrSdiff) $id }
658
"vol" { set Nv_(CurrVol) $id }
662
# Quick routine to make a separator widget
663
proc Nv_makeSeparator { name } {
664
canvas $name -relief raised -height 2m -width 5m -bg \#111111