[GRASS-SVN] r36200 -
grass/branches/develbranch_6/visualization/nviz/scripts
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Mar 5 04:37:01 EST 2009
Author: marisn
Date: 2009-03-05 04:37:01 -0500 (Thu, 05 Mar 2009)
New Revision: 36200
Modified:
grass/branches/develbranch_6/visualization/nviz/scripts/flythrough.tcl
grass/branches/develbranch_6/visualization/nviz/scripts/panel_main.tcl
grass/branches/develbranch_6/visualization/nviz/scripts/position_procs.tcl
Log:
NVIZ experimental click to recenter feature
Modified: grass/branches/develbranch_6/visualization/nviz/scripts/flythrough.tcl
===================================================================
--- grass/branches/develbranch_6/visualization/nviz/scripts/flythrough.tcl 2009-03-04 23:04:24 UTC (rev 36199)
+++ grass/branches/develbranch_6/visualization/nviz/scripts/flythrough.tcl 2009-03-05 09:37:01 UTC (rev 36200)
@@ -49,12 +49,13 @@
fly_set_icons $bit_map_path/flythrough
################################################################################
-proc mkFlyButtons {BASE frame draw_lab draw_var1 draw_var2} {
+proc mkFlyButtons {BASE frame draw_lab draw_var1 draw_var2 draw_var4} {
global Nv_ fly draw_option
# Flythrough menus
set fly(EYE_RADIOBUTTON) $draw_var1
set fly(CENTER_RADIOBUTTON) $draw_var2
+ set fly(C2C_RADIOBUTTON) $draw_var4
set fly(FLY_RADIOBUTTON) [radiobutton $BASE.$frame.b3 \
-variable draw_option -value 3 -text "fly"\
@@ -73,7 +74,7 @@
fly_deselect
- pack $draw_lab $draw_var1 $draw_var2 $fly(FLY_RADIOBUTTON) $fly(FLY_MENUBUTTON) -side left -expand 0
+ pack $draw_lab $draw_var1 $draw_var2 $draw_var4 $fly(FLY_RADIOBUTTON) $fly(FLY_MENUBUTTON) -side left -expand 0
# Flythrough panel
@@ -274,6 +275,7 @@
global fly;
$fly(EYE_RADIOBUTTON) deselect
$fly(CENTER_RADIOBUTTON) deselect
+ $fly(C2C_RADIOBUTTON) deselect
$fly(FLY_RADIOBUTTON) select
$fly(FLY_MENUBUTTON) configure -text $fly(FLY_MODE)
Modified: grass/branches/develbranch_6/visualization/nviz/scripts/panel_main.tcl
===================================================================
--- grass/branches/develbranch_6/visualization/nviz/scripts/panel_main.tcl 2009-03-04 23:04:24 UTC (rev 36199)
+++ grass/branches/develbranch_6/visualization/nviz/scripts/panel_main.tcl 2009-03-05 09:37:01 UTC (rev 36200)
@@ -175,23 +175,27 @@
set draw_lab [label $BASE.midt.lablev1 -text "View method:" -anchor w]
set draw_var1 [radiobutton $BASE.midt.b1 -text "eye" \
- -variable draw_option -value 0 -width 8 \
+ -variable draw_option -value 0 -width 4 \
-command "change_display 1" ]
set draw_var2 [radiobutton $BASE.midt.b2 -text "center" \
- -variable draw_option -value 1 -width 8 \
+ -variable draw_option -value 1 -width 6 \
-command "change_display 0" ]
+
+ set draw_var4 [radiobutton $BASE.midt.b4 -text "C2C" \
+ -variable draw_option -value 4 -width 3 \
+ -command "C2C 1" ]
$draw_var1 select
help $BASE.midt.b1 balloon "Change view by moving eye position"
help $BASE.midt.b2 balloon "Change view by moving scene center position"
+ help $BASE.midt.b4 balloon "Click to change scene center position, scroll to zoom in and out"
-
if {$Nv_(FlyThrough)} {
- mkFlyButtons $BASE "midt" $draw_lab $draw_var1 $draw_var2
+ mkFlyButtons $BASE "midt" $draw_lab $draw_var1 $draw_var2 $draw_var4
} else {
# original code
- pack $draw_lab $draw_var1 $draw_var2 -side left -expand 0
+ pack $draw_lab $draw_var1 $draw_var2 $draw_var4 -side left -expand 0
}
help $BASE.midt.b3 balloon "Change view using mouse to control fly-through"
@@ -501,7 +505,8 @@
proc change_display {flag} {
global XY Nv_
global Nauto_draw
-
+
+ C2C 0
set NAME $XY
set NAME2 [winfo parent $NAME]
catch "destroy $XY"
@@ -588,7 +593,7 @@
update
}
- if {$draw_option == 1} {
+ if {$draw_option == 1 || $draw_option == 4} {
#Move center of view cross hair
set E [lindex [Nget_focus_gui] 0]
@@ -625,4 +630,3 @@
$can($mon) configure -cursor $Nv_(cursor)
return
}
-
Modified: grass/branches/develbranch_6/visualization/nviz/scripts/position_procs.tcl
===================================================================
--- grass/branches/develbranch_6/visualization/nviz/scripts/position_procs.tcl 2009-03-04 23:04:24 UTC (rev 36199)
+++ grass/branches/develbranch_6/visualization/nviz/scripts/position_procs.tcl 2009-03-05 09:37:01 UTC (rev 36200)
@@ -20,3 +20,84 @@
proc no_focus {} {
Nset_focus_state 0
}
+
+##############################
+# Click on canvas to reCenter
+# C2C code inspired from panel_pos.tcl and panel_rquery.tcl
+proc C2C { on } {
+ global Nv_
+
+ if {$on} {
+ change_display 0
+ bind $Nv_(TOP).canvas <Button> {click_recenter %x %y}
+ bind $Nv_(TOP).canvas <MouseWheel> {scroll_zoom %D}
+ if {[tk windowingsystem] eq {x11}} {
+ bind $Nv_(TOP).canvas <Button-4> {scroll_zoom 1}
+ bind $Nv_(TOP).canvas <Button-5> {scroll_zoom -1}
+ }
+ } else {
+ bind $Nv_(TOP).canvas <Button> {}
+ bind $Nv_(TOP).canvas <MouseWheel> {}
+ bind $Nv_(TOP).canvas <Button-4> {}
+ bind $Nv_(TOP).canvas <Button-5> {}
+ }
+ inform "Click to change scene center position, scroll to zoom in and out"
+}
+
+# Zoom in and out with mouse scroller
+proc scroll_zoom { amount } {
+ global Nv_
+ global Nauto_draw
+
+ set fov [Nget_fov]
+ if {[tk windowingsystem] eq "win32"} {
+ set newzoom [expr {(-$amount/120)+$fov}]
+ } else {
+ set newzoom [expr {(-1*$amount)+$fov}]
+ }
+
+ # Field of view is limited to range 1..120
+ if { $newzoom < 1 } { set newzoom 1 }
+ if { $newzoom > 120 } { set newzoom 120 }
+
+ Nv_scaleCallback $Nv_(main_BASE).bframe.cframe.pers b 0 Nchange_persp $newzoom
+ inform "Perspective has been changed"
+ if {$Nauto_draw == 1} {
+ Ndraw_all
+ }
+ update
+}
+
+# Move camera and center according to mouse click on canvas
+# Camera position is not rotated but just shifted by old/new center deltaX and deltaY
+proc click_recenter {cx cy} {
+ global Nauto_draw
+ global Nv_
+
+ # Get real position
+ set cy [expr $Nv_(height) - $cy]
+ set list [Nget_point_on_surf $cx $cy]
+ if {[llength $list] < 4} {
+ inform "Point not on surface"
+ return
+ }
+ set cx [lindex $list 0]
+ set cy [lindex $list 1]
+
+ # Calculate deltas for shifting
+ set from_loc [Nget_real_position 1]
+ set to_loc [Nget_real_position 2]
+ set dx [ expr { $cx - [lindex $to_loc 0] } ]
+ set dy [ expr { $cy - [lindex $to_loc 1] } ]
+ set fe [ expr { $dx + [lindex $from_loc 0] }]
+ set fn [ expr { $dy + [lindex $from_loc 1] }]
+
+ Nset_focus_real $cx $cy [lindex $to_loc 2]
+ Nmove_to_real $fe $fn [lindex $from_loc 2]
+
+ inform "New center of view has been set"
+ move_position
+ if {$Nauto_draw == 1} {Ndraw_all}
+ update
+}
+
More information about the grass-commit
mailing list