Changeset 36200


Ignore:
Timestamp:
Mar 5, 2009, 1:37:01 AM (15 years ago)
Author:
marisn
Message:

NVIZ experimental click to recenter feature

Location:
grass/branches/develbranch_6/visualization/nviz/scripts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • grass/branches/develbranch_6/visualization/nviz/scripts/flythrough.tcl

    r34008 r36200  
    5050################################################################################
    5151
    52 proc mkFlyButtons {BASE frame draw_lab draw_var1 draw_var2} {
     52proc mkFlyButtons {BASE frame draw_lab draw_var1 draw_var2 draw_var4} {
    5353        global Nv_ fly draw_option
    5454
     
    5656        set fly(EYE_RADIOBUTTON) $draw_var1
    5757        set fly(CENTER_RADIOBUTTON) $draw_var2
     58        set fly(C2C_RADIOBUTTON) $draw_var4
    5859
    5960        set fly(FLY_RADIOBUTTON) [radiobutton $BASE.$frame.b3 \
     
    7475        fly_deselect
    7576
    76     pack $draw_lab $draw_var1 $draw_var2 $fly(FLY_RADIOBUTTON) $fly(FLY_MENUBUTTON) -side left -expand 0
     77    pack $draw_lab $draw_var1 $draw_var2 $draw_var4 $fly(FLY_RADIOBUTTON) $fly(FLY_MENUBUTTON) -side left -expand 0
    7778
    7879
     
    275276        $fly(EYE_RADIOBUTTON) deselect
    276277        $fly(CENTER_RADIOBUTTON) deselect
     278        $fly(C2C_RADIOBUTTON) deselect
    277279        $fly(FLY_RADIOBUTTON) select
    278280
  • grass/branches/develbranch_6/visualization/nviz/scripts/panel_main.tcl

    r35073 r36200  
    176176
    177177        set draw_var1 [radiobutton $BASE.midt.b1 -text "eye" \
    178                 -variable draw_option -value 0 -width 8 \
     178                -variable draw_option -value 0 -width 4 \
    179179                -command "change_display 1" ]
    180180
    181181        set draw_var2 [radiobutton $BASE.midt.b2 -text "center" \
    182                 -variable draw_option -value 1 -width 8 \
     182                -variable draw_option -value 1 -width 6 \
    183183                -command "change_display 0" ]
     184
     185        set draw_var4 [radiobutton $BASE.midt.b4 -text "C2C" \
     186                -variable draw_option -value 4 -width 3 \
     187                -command "C2C 1" ]
    184188        $draw_var1 select
    185189
    186190        help $BASE.midt.b1 balloon "Change view by moving eye position"
    187191        help $BASE.midt.b2 balloon "Change view by moving scene center position"
    188 
     192        help $BASE.midt.b4 balloon "Click to change scene center position, scroll to zoom in and out"
    189193
    190194        if {$Nv_(FlyThrough)} {
    191                 mkFlyButtons $BASE "midt" $draw_lab $draw_var1 $draw_var2
     195                mkFlyButtons $BASE "midt" $draw_lab $draw_var1 $draw_var2 $draw_var4
    192196        } else {
    193197                # original code
    194                 pack $draw_lab $draw_var1 $draw_var2 -side left -expand 0
     198                pack $draw_lab $draw_var1 $draw_var2 $draw_var4 -side left -expand 0
    195199        }
    196200        help $BASE.midt.b3 balloon "Change view using mouse to control fly-through"
     
    502506        global XY Nv_
    503507        global Nauto_draw
    504 
     508       
     509        C2C 0
    505510        set NAME $XY
    506511        set NAME2 [winfo parent $NAME]
     
    589594        }
    590595
    591         if {$draw_option == 1} {
     596        if {$draw_option == 1 || $draw_option == 4} {
    592597                #Move center of view cross hair
    593598
     
    626631        return
    627632}
    628 
  • grass/branches/develbranch_6/visualization/nviz/scripts/position_procs.tcl

    r18066 r36200  
    2121    Nset_focus_state 0
    2222}
     23
     24##############################
     25# Click on canvas to reCenter
     26# C2C code inspired from panel_pos.tcl and panel_rquery.tcl
     27proc C2C { on } {
     28        global Nv_
     29
     30        if {$on} {
     31                change_display 0
     32                bind $Nv_(TOP).canvas <Button> {click_recenter %x %y}
     33                bind $Nv_(TOP).canvas <MouseWheel> {scroll_zoom %D}
     34                if {[tk windowingsystem] eq {x11}} {
     35                        bind $Nv_(TOP).canvas <Button-4> {scroll_zoom  1}
     36                        bind $Nv_(TOP).canvas <Button-5> {scroll_zoom -1}
     37                }
     38        } else {
     39                bind $Nv_(TOP).canvas <Button> {}
     40                bind $Nv_(TOP).canvas <MouseWheel> {}
     41                bind $Nv_(TOP).canvas <Button-4> {}
     42                bind $Nv_(TOP).canvas <Button-5> {}
     43        }
     44        inform "Click to change scene center position, scroll to zoom in and out"
     45}
     46
     47# Zoom in and out with mouse scroller
     48proc scroll_zoom { amount } {
     49        global Nv_
     50        global Nauto_draw
     51       
     52        set fov [Nget_fov]
     53        if {[tk windowingsystem] eq "win32"} {
     54                set newzoom [expr {(-$amount/120)+$fov}]
     55        } else {
     56                set newzoom [expr {(-1*$amount)+$fov}]
     57        }
     58       
     59        # Field of view is limited to range 1..120
     60        if { $newzoom < 1   } { set newzoom 1 }
     61        if { $newzoom > 120 } { set newzoom 120 }
     62       
     63        Nv_scaleCallback $Nv_(main_BASE).bframe.cframe.pers b 0 Nchange_persp $newzoom
     64        inform "Perspective has been changed"
     65        if {$Nauto_draw == 1} {
     66                Ndraw_all
     67        }
     68        update
     69}
     70
     71# Move camera and center according to mouse click on canvas
     72# Camera position is not rotated but just shifted by old/new center deltaX and deltaY
     73proc click_recenter {cx cy} {
     74        global Nauto_draw
     75        global Nv_
     76       
     77        # Get real position
     78        set cy [expr $Nv_(height) - $cy]
     79        set list [Nget_point_on_surf $cx $cy]
     80        if {[llength $list] < 4} {
     81                inform "Point not on surface"
     82                return
     83        }
     84        set cx [lindex $list 0]
     85        set cy [lindex $list 1]
     86       
     87        # Calculate deltas for shifting
     88        set from_loc [Nget_real_position 1]
     89        set to_loc [Nget_real_position 2]
     90        set dx [ expr { $cx - [lindex $to_loc 0] } ]
     91        set dy [ expr { $cy - [lindex $to_loc 1] } ]
     92        set fe [ expr { $dx + [lindex $from_loc 0] }]
     93        set fn [ expr { $dy + [lindex $from_loc 1] }]
     94       
     95        Nset_focus_real $cx $cy [lindex $to_loc 2]     
     96        Nmove_to_real $fe $fn [lindex $from_loc 2]
     97       
     98        inform  "New center of view has been set"
     99        move_position
     100        if {$Nauto_draw == 1} {Ndraw_all}
     101        update
     102}
     103
Note: See TracChangeset for help on using the changeset viewer.