Changeset 4314


Ignore:
Timestamp:
Apr 2, 2014, 12:19:53 AM (10 years ago)
Author:
ldelgass
Message:

Cleanout old camera code from mapviewer widget and add code to get/set the
viewpoint parameters that osgearth uses. Add a switch (_useServerManip) that
controls if client sends raw mouse events or pan/zoom/rotate commands. If
_useServerManip is turned off, we still send (compressed) mouse motion events
in order to update the coordinate display added by the server.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/mapviewer.tcl

    r4311 r4314  
    8686    protected method ReceiveImage { args }
    8787    protected method Rotate {option x y}
    88     protected method Zoom {option}
     88    protected method Zoom {option {x 0} {y 0}}
    8989
    9090    # The following methods are only used by this class.
     
    9696    private method EventuallyHandleMotionEvent { x y }
    9797    private method EventuallyResize { w h }
    98     private method EventuallyRotate { q }
     98    private method EventuallyRotate { dx dy }
    9999    private method GetImage { args }
    100     private method PanCamera {}
     100    private method GetNormalizedMouse { x y }
    101101    private method SetLayerStyle { dataobj layer }
    102102    private method SetTerrainStyle { style }
    103103    private method SetOpacity { dataset }
    104     private method SetOrientation { side }
    105104    private method UpdateLayerControls {}
    106105    private method EarthFile {}
    107106
    108     private variable _arcball ""
    109107    private variable _dlist "";         # list of data objects
    110108    private variable _obj2datasets
     
    113111                                        # layer in the server.
    114112    private variable _click;            # info used for rotate operations
    115     private variable _limits;           # autoscale min/max for all axes
    116113    private variable _view;             # view params for 3D view
    117114    private variable _settings
     
    136133    private variable _motion
    137134    private variable _sendEarthFile 0
     135    private variable _useServerManip 1
    138136}
    139137
     
    172170    $_parser alias image    [itcl::code $this ReceiveImage]
    173171    $_parser alias dataset  [itcl::code $this ReceiveDataset]
    174 
     172    $_parser alias camera   [itcl::code $this camera]
     173
     174    # Settings for mouse motion events: these are required
     175    # to update the Lat/Long coordinate display
    175176    array set _motion {
    176177        x               0
     
    180181        compress        0
    181182    }
    182     # Initialize the view to some default parameters.
     183    # This array holds the Viewpoint parameters that the
     184    # server sends on "camera get".
    183185    array set _view {
    184         qw              1.0
    185         qx              0.0
    186         qy              0.0
    187         qz              0.0
    188         zoom            1.0
    189         xpan            0.0
    190         ypan            0.0
    191     }
    192     set _arcball [blt::arcball create 100 100]
    193     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    194     $_arcball quaternion $q
    195 
    196     set _limits(zmin) 0.0
    197     set _limits(zmax) 1.0
     186        x               0.0
     187        y               0.0
     188        z               0.0
     189        heading         0.0
     190        pitch           0.0
     191        distance        0.0
     192        srs             ""
     193        verticalDatum   ""
     194    }
    198195
    199196    array set _settings [subst {
     
    235232            -highlightthickness 0 \
    236233            -image [Rappture::icon reset-view] \
    237             -command [itcl::code $this Zoom reset]
     234            -command [itcl::code $this camera reset]
    238235    } {
    239236        usual
     
    292289    blt::table configure $itk_component(plotarea) c1 -resize none
    293290
    294     # Bindings for keyboard events
    295     bind $itk_component(view) <KeyPress> \
    296         [itcl::code $this KeyPress %N]
    297     bind $itk_component(view) <KeyRelease> \
    298         [itcl::code $this KeyRelease %N]
    299 
    300     # Bindings for rotation via mouse
    301     bind $itk_component(view) <ButtonPress-1> \
    302         [itcl::code $this MouseClick 1 %x %y]
    303     bind $itk_component(view) <Double-1> \
    304         [itcl::code $this MouseDoubleClick 1 %x %y]
    305     bind $itk_component(view) <B1-Motion> \
    306         [itcl::code $this MouseDrag 1 %x %y]
    307     bind $itk_component(view) <ButtonRelease-1> \
    308         [itcl::code $this MouseRelease 1 %x %y]
    309291    bind $itk_component(view) <Configure> \
    310292        [itcl::code $this EventuallyResize %w %h]
    311293
    312     # Bindings for panning via mouse
    313     bind $itk_component(view) <ButtonPress-2> \
    314         [itcl::code $this MouseClick 2 %x %y]
    315     bind $itk_component(view) <Double-2> \
    316         [itcl::code $this MouseDoubleClick 2 %x %y]
    317     bind $itk_component(view) <B2-Motion> \
    318         [itcl::code $this MouseDrag 2 %x %y]
    319     bind $itk_component(view) <ButtonRelease-2> \
    320         [itcl::code $this MouseRelease 2 %x %y]
    321 
    322     bind $itk_component(view) <ButtonPress-3> \
    323         [itcl::code $this MouseClick 3 %x %y]
    324     bind $itk_component(view) <Double-3> \
    325         [itcl::code $this MouseDoubleClick 3 %x %y]
    326     bind $itk_component(view) <B3-Motion> \
    327         [itcl::code $this MouseDrag 3 %x %y]
    328     bind $itk_component(view) <ButtonRelease-3> \
    329         [itcl::code $this MouseRelease 3 %x %y]
    330 
    331     bind $itk_component(view) <Motion> \
    332         [itcl::code $this EventuallyHandleMotionEvent %x %y]
    333 
    334     if {0} {
    335     # Bindings for panning via keyboard
    336     bind $itk_component(view) <KeyPress-Left> \
    337         [itcl::code $this Pan set -10 0]
    338     bind $itk_component(view) <KeyPress-Right> \
    339         [itcl::code $this Pan set 10 0]
    340     bind $itk_component(view) <KeyPress-Up> \
    341         [itcl::code $this Pan set 0 -10]
    342     bind $itk_component(view) <KeyPress-Down> \
    343         [itcl::code $this Pan set 0 10]
     294    if {$_useServerManip} {
     295        # Bindings for keyboard events
     296        bind $itk_component(view) <KeyPress> \
     297            [itcl::code $this KeyPress %N]
     298        bind $itk_component(view) <KeyRelease> \
     299            [itcl::code $this KeyRelease %N]
     300
     301        # Bindings for rotation via mouse
     302        bind $itk_component(view) <ButtonPress-1> \
     303            [itcl::code $this MouseClick 1 %x %y]
     304        bind $itk_component(view) <Double-1> \
     305            [itcl::code $this MouseDoubleClick 1 %x %y]
     306        bind $itk_component(view) <B1-Motion> \
     307            [itcl::code $this MouseDrag 1 %x %y]
     308        bind $itk_component(view) <ButtonRelease-1> \
     309            [itcl::code $this MouseRelease 1 %x %y]
     310
     311        # Bindings for panning via mouse
     312        bind $itk_component(view) <ButtonPress-2> \
     313            [itcl::code $this MouseClick 2 %x %y]
     314        bind $itk_component(view) <Double-2> \
     315            [itcl::code $this MouseDoubleClick 2 %x %y]
     316        bind $itk_component(view) <B2-Motion> \
     317            [itcl::code $this MouseDrag 2 %x %y]
     318        bind $itk_component(view) <ButtonRelease-2> \
     319            [itcl::code $this MouseRelease 2 %x %y]
     320
     321        bind $itk_component(view) <ButtonPress-3> \
     322            [itcl::code $this MouseClick 3 %x %y]
     323        bind $itk_component(view) <Double-3> \
     324            [itcl::code $this MouseDoubleClick 3 %x %y]
     325        bind $itk_component(view) <B3-Motion> \
     326            [itcl::code $this MouseDrag 3 %x %y]
     327        bind $itk_component(view) <ButtonRelease-3> \
     328            [itcl::code $this MouseRelease 3 %x %y]
     329
     330        bind $itk_component(view) <Motion> \
     331            [itcl::code $this EventuallyHandleMotionEvent %x %y]
     332    } else {
     333        # Bindings for panning via mouse
     334        bind $itk_component(view) <ButtonPress-1> \
     335            [itcl::code $this Pan click %x %y]
     336        bind $itk_component(view) <B1-Motion> \
     337            [itcl::code $this Pan drag %x %y]
     338        bind $itk_component(view) <ButtonRelease-1> \
     339            [itcl::code $this Pan release %x %y]
     340
     341        # Bindings for rotation via mouse
     342        bind $itk_component(view) <ButtonPress-2> \
     343            [itcl::code $this Rotate click %x %y]
     344        bind $itk_component(view) <B2-Motion> \
     345            [itcl::code $this Rotate drag %x %y]
     346        bind $itk_component(view) <ButtonRelease-2> \
     347            [itcl::code $this Rotate release %x %y]
     348
     349        # Bindings for zoom via mouse
     350        bind $itk_component(view) <ButtonPress-3> \
     351            [itcl::code $this Zoom click %x %y]
     352        bind $itk_component(view) <B3-Motion> \
     353            [itcl::code $this Zoom drag %x %y]
     354        bind $itk_component(view) <ButtonRelease-3> \
     355            [itcl::code $this Zoom release %x %y]
     356
     357        # Bindings for panning via keyboard
     358        bind $itk_component(view) <KeyPress-Left> \
     359            [itcl::code $this Pan set 10 0]
     360        bind $itk_component(view) <KeyPress-Right> \
     361            [itcl::code $this Pan set -10 0]
     362        bind $itk_component(view) <KeyPress-Up> \
     363            [itcl::code $this Pan set 0 -10]
     364        bind $itk_component(view) <KeyPress-Down> \
     365            [itcl::code $this Pan set 0 10]
     366
     367        # Send (compressed) motion events to update Lat/Long
     368        set _motion(compress) 1
     369        bind $itk_component(view) <Motion> \
     370            [itcl::code $this EventuallyHandleMotionEvent %x %y]
     371    }
     372
    344373    bind $itk_component(view) <Shift-KeyPress-Left> \
     374        [itcl::code $this Pan set 2 0]
     375    bind $itk_component(view) <Shift-KeyPress-Right> \
    345376        [itcl::code $this Pan set -2 0]
    346     bind $itk_component(view) <Shift-KeyPress-Right> \
    347         [itcl::code $this Pan set 2 0]
    348377    bind $itk_component(view) <Shift-KeyPress-Up> \
    349378        [itcl::code $this Pan set 0 -2]
    350379    bind $itk_component(view) <Shift-KeyPress-Down> \
    351380        [itcl::code $this Pan set 0 2]
    352     }
    353381
    354382    # Bindings for zoom via keyboard
     
    362390    if {[string equal "x11" [tk windowingsystem]]} {
    363391        # Bindings for zoom via mouse
    364         #bind $itk_component(view) <4> [itcl::code $this Zoom out]
    365         #bind $itk_component(view) <5> [itcl::code $this Zoom in]
    366         bind $itk_component(view) <4> [itcl::code $this MouseScroll up]
    367         bind $itk_component(view) <5> [itcl::code $this MouseScroll down]
     392        if {$_useServerManip} {
     393            bind $itk_component(view) <4> [itcl::code $this MouseScroll up]
     394            bind $itk_component(view) <5> [itcl::code $this MouseScroll down]
     395        } else {
     396            bind $itk_component(view) <4> [itcl::code $this Zoom out]
     397            bind $itk_component(view) <5> [itcl::code $this Zoom in]
     398        }
    368399    }
    369400
     
    387418    image delete $_image(plot)
    388419    image delete $_image(download)
    389     catch { blt::arcball destroy $_arcball }
    390420}
    391421
     
    408438
    409439itcl::body Rappture::MapViewer::DoRotate {} {
    410     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    411     SendCmd "camera orient $q"
     440    SendCmd "camera rotate $_view(azimuth) $_view(elevation)"
    412441    set _rotatePending 0
    413442}
     
    416445    set _width $w
    417446    set _height $h
    418     $_arcball resize $w $h
    419447    if { !$_resizePending } {
    420448        set _resizePending 1
     
    423451}
    424452
    425 itcl::body Rappture::MapViewer::EventuallyRotate { q } {
    426     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     453itcl::body Rappture::MapViewer::EventuallyRotate { dx dy } {
     454    set _view(azimuth) $dx
     455    set _view(elevation) $dy
    427456    if { !$_rotatePending } {
    428457        set _rotatePending 1
     
    851880        set _width $w
    852881        set _height $h
    853         $_arcball resize $w $h
    854882        DoResize
    855883
     
    901929    }
    902930
    903     set _limits(zmin) ""
    904     set _limits(zmax) ""
    905931    set _first ""
    906932    set count 0
     
    944970    }
    945971    if { $_reset } {
    946         set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    947         $_arcball quaternion $q
    948         SendCmd "camera reset"
    949         DoRotate
    950         PanCamera
    951         Zoom reset
     972        camera reset
    952973    }
    953974    UpdateLayerControls
     
    10161037}
    10171038
    1018 itcl::body Rappture::MapViewer::MouseClick {button x y} {
    1019     if {0} {
     1039itcl::body Rappture::MapViewer::GetNormalizedMouse {x y} {
    10201040    set w [winfo width $itk_component(view)]
    10211041    set h [winfo height $itk_component(view)]
    10221042    set x [expr {(2.0 * double($x)/$w) - 1.0}]
    10231043    set y [expr {(2.0 * double($y)/$h) - 1.0}]
    1024     }
     1044    return [list $x $y]
     1045}
     1046
     1047itcl::body Rappture::MapViewer::MouseClick {button x y} {
    10251048    SendCmd "mouse click $button $x $y"
    10261049}
    10271050
    10281051itcl::body Rappture::MapViewer::MouseDoubleClick {button x y} {
    1029     if {0} {
    1030     set w [winfo width $itk_component(view)]
    1031     set h [winfo height $itk_component(view)]
    1032     set x [expr {(2.0 * double($x)/$w) - 1.0}]
    1033     set y [expr {(2.0 * double($y)/$h) - 1.0}]
    1034     }
    10351052    SendCmd "mouse dblclick $button $x $y"
    10361053}
    10371054
    10381055itcl::body Rappture::MapViewer::MouseDrag {button x y} {
    1039     if {0} {
    1040     set w [winfo width $itk_component(view)]
    1041     set h [winfo height $itk_component(view)]
    1042     set x [expr {(2.0 * double($x)/$w) - 1.0}]
    1043     set y [expr {(2.0 * double($y)/$h) - 1.0}]
    1044     }
    10451056    SendCmd "mouse drag $button $x $y"
    10461057}
    10471058
    10481059itcl::body Rappture::MapViewer::MouseRelease {button x y} {
    1049     if {0} {
    1050     set w [winfo width $itk_component(view)]
    1051     set h [winfo height $itk_component(view)]
    1052     set x [expr {(2.0 * double($x)/$w) - 1.0}]
    1053     set y [expr {(2.0 * double($y)/$h) - 1.0}]
    1054     }
    10551060    SendCmd "mouse release $button $x $y"
     1061}
     1062
     1063itcl::body Rappture::MapViewer::MouseMotion {} {
     1064    SendCmd "mouse motion $_motion(x) $_motion(y)"
     1065    set _motion(pending) 0
     1066}
     1067
     1068itcl::body Rappture::MapViewer::MouseScroll {direction} {
     1069    switch -- $direction {
     1070        "up" {
     1071            SendCmd "mouse scroll 1"
     1072        }
     1073        "down" {
     1074            SendCmd "mouse scroll -1"
     1075        }
     1076    }
    10561077}
    10571078
     
    10761097}
    10771098
    1078 itcl::body Rappture::MapViewer::MouseMotion {} {
    1079     if {0} {
    1080     set w [winfo width $itk_component(view)]
    1081     set h [winfo height $itk_component(view)]
    1082     set x [expr {(2.0 * double($_motion(x))/$w) - 1.0}]
    1083     set y [expr {(2.0 * double($_motion(y))/$h) - 1.0}]
    1084     }
    1085     SendCmd "mouse motion $_motion(x) $_motion(y)"
    1086     set _motion(pending) 0
    1087 }
    1088 
    1089 itcl::body Rappture::MapViewer::MouseScroll {direction} {
    1090     switch -- $direction {
    1091         "up" {
    1092             SendCmd "mouse scroll 1"
    1093         }
    1094         "down" {
    1095             SendCmd "mouse scroll -1"
    1096         }
    1097     }
    1098 }
    1099 
    11001099# ----------------------------------------------------------------------
    11011100# USAGE: Zoom in
    11021101# USAGE: Zoom out
    11031102# USAGE: Zoom reset
     1103#        $this Zoom click x y
     1104#        $this Zoom drag x y
     1105#        $this Zoom release x y
    11041106#
    11051107# Called automatically when the user clicks on one of the zoom
    11061108# controls for this widget.  Changes the zoom for the current view.
    1107 # ----------------------------------------------------------------------
    1108 itcl::body Rappture::MapViewer::Zoom {option} {
     1109# Also implements mouse zoom.
     1110# ----------------------------------------------------------------------
     1111itcl::body Rappture::MapViewer::Zoom {option {x 0} {y 0}} {
    11091112    switch -- $option {
    11101113        "in" {
    1111             set _view(zoom) [expr {$_view(zoom)*1.25}]
    1112             #SendCmd "camera zoom $_view(zoom)"
     1114            # z here is normalized mouse Y delta
    11131115            set z -0.25
    11141116            SendCmd "camera zoom $z"
    11151117        }
    11161118        "out" {
    1117             set _view(zoom) [expr {$_view(zoom)*0.8}]
    1118             #SendCmd "camera zoom $_view(zoom)"
     1119            # z here is normalized mouse Y delta
    11191120            set z 0.25
    11201121            SendCmd "camera zoom $z"
    11211122        }
    11221123        "reset" {
    1123             array set _view {
    1124                 qw      1.0
    1125                 qx      0.0
    1126                 qy      0.0
    1127                 qz      0.0
    1128                 zoom    1.0
    1129                 xpan    0.0
    1130                 ypan    0.0
    1131             }
    1132             if { $_first != "" } {
    1133                 set location [$_first hints camera]
    1134                 if { $location != "" } {
    1135                     array set _view $location
    1136                 }
    1137             }
    1138             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1139             $_arcball quaternion $q
    1140             DoRotate
    1141             SendCmd "camera reset"
    1142         }
    1143     }
    1144 }
    1145 
    1146 itcl::body Rappture::MapViewer::PanCamera {} {
    1147     set x $_view(xpan)
    1148     set y $_view(ypan)
    1149     SendCmd "camera pan $x $y"
     1124            SendCmd "camera dist $_view(distance)"
     1125        }
     1126        "click" {
     1127            set _click(x) $x
     1128            set _click(y) $y
     1129            $itk_component(view) configure -cursor hand1
     1130        }
     1131        "drag" {
     1132            if { ![info exists _click(x)] } {
     1133                set _click(x) $x
     1134            }
     1135            if { ![info exists _click(y)] } {
     1136                set _click(y) $y
     1137            }
     1138            set h [winfo height $itk_component(view)]
     1139            set dy [expr ($_click(y) - $y)/double($h)]
     1140            set _click(x) $x
     1141            set _click(y) $y
     1142            SendCmd "camera zoom $dy"
     1143        }
     1144        "release" {
     1145            Zoom drag $x $y
     1146            $itk_component(view) configure -cursor ""
     1147        }
     1148    }
    11501149}
    11511150
     
    11741173                    return
    11751174                }
    1176 
    1177                 if {[catch {
    1178                     # this fails sometimes for no apparent reason
    1179                     set dx [expr {double($x-$_click(x))/$w}]
    1180                     set dy [expr {double($y-$_click(y))/$h}]
    1181                 }]} {
    1182                     return
    1183                 }
    1184                 if { $dx == 0 && $dy == 0 } {
    1185                     return
    1186                 }
    1187                 set q [$_arcball rotate $x $y $_click(x) $_click(y)]
    1188                 EventuallyRotate $q
     1175                set dx [expr ($x - $_click(x))/double($w)]
     1176                set dy [expr ($_click(y) - $y)/double($h)]
    11891177                set _click(x) $x
    11901178                set _click(y) $y
     1179                SendCmd "camera rotate $dx $dy"
     1180                #EventuallyRotate $dx $dy
    11911181            }
    11921182        }
     
    12031193
    12041194# ----------------------------------------------------------------------
    1205 # USAGE: $this Pan click x y
     1195# USAGE: $this Pan set x y
     1196#        $this Pan click x y
    12061197#        $this Pan drag x y
    12071198#        $this Pan release x y
     
    12171208            set x [expr $x / double($w)]
    12181209            set y [expr $y / double($h)]
    1219             set _view(xpan) [expr $_view(xpan) + $x]
    1220             set _view(ypan) [expr $_view(ypan) + $y]
    1221             PanCamera
     1210            SendCmd "camera pan $x $y"
    12221211            return
    12231212        }
     
    12361225            set w [winfo width $itk_component(view)]
    12371226            set h [winfo height $itk_component(view)]
    1238             set dx [expr ($_click(x) - $x)/double($w)]
     1227            set dx [expr ($x - $_click(x))/double($w)]
    12391228            set dy [expr ($_click(y) - $y)/double($h)]
    12401229            set _click(x) $x
    12411230            set _click(y) $y
    1242             set _view(xpan) [expr $_view(xpan) - $dx]
    1243             set _view(ypan) [expr $_view(ypan) - $dy]
    1244             PanCamera
     1231            SendCmd "camera pan $dx $dy"
    12451232        }
    12461233        "release" {
     
    13321319itcl::body Rappture::MapViewer::limits { dataobj } {
    13331320    error "no limits"
    1334     foreach layer [$dataobj layers] {
    1335         set tag $dataobj-$layer
    1336 
    1337         foreach { xMin xMax yMin yMax zMin zMax} $_limits($tag) break
    1338         if {![info exists limits(xmin)] || $limits(xmin) > $xMin} {
    1339             set limits(xmin) $xMin
    1340         }
    1341         if {![info exists limits(xmax)] || $limits(xmax) < $xMax} {
    1342             set limits(xmax) $xMax
    1343         }
    1344         if {![info exists limits(ymin)] || $limits(ymin) > $yMin} {
    1345             set limits(ymin) $xMin
    1346         }
    1347         if {![info exists limits(ymax)] || $limits(ymax) < $yMax} {
    1348             set limits(ymax) $yMax
    1349         }
    1350         if {![info exists limits(zmin)] || $limits(zmin) > $zMin} {
    1351             set limits(zmin) $zMin
    1352         }
    1353         if {![info exists limits(zmax)] || $limits(zmax) < $zMax} {
    1354             set limits(zmax) $zMax
    1355         }
    1356     }
    1357     return [array get limits]
    13581321}
    13591322
     
    14551418    $inner configure -borderwidth 4
    14561419
    1457     label $inner.view_l -text "view" -font "Arial 9"
    1458     set f [frame $inner.view]
    1459     foreach side { front back left right top bottom } {
    1460         button $f.$side  -image [Rappture::icon view$side] \
    1461             -command [itcl::code $this SetOrientation $side]
    1462         Rappture::Tooltip::for $f.$side "Change the view to $side"
    1463         pack $f.$side -side left
    1464     }
    1465 
    1466     blt::table $inner \
    1467         0,0 $inner.view_l -anchor e -pady 2 \
    1468         0,1 $inner.view -anchor w -pady 2
    1469 
    1470     set labels { qx qy qz qw xpan ypan zoom }
    1471     set row 1
     1420    set row 0
     1421
     1422    set labels { x y z heading pitch distance }
    14721423    foreach tag $labels {
    14731424        label $inner.${tag}label -text $tag -font "Arial 9"
     
    14821433        incr row
    14831434    }
    1484 
    1485     checkbutton $inner.throw \
    1486         -text "Enable Throw" \
    1487         -font "Arial 9" \
    1488         -variable [itcl::scope _settings(camera-throw)] \
    1489         -command [itcl::code $this AdjustSetting camera-throw]
    1490     blt::table $inner \
    1491         $row,0 $inner.throw -anchor w -pady 2 -cspan 2
    1492     blt::table configure $inner r$row -resize none
    1493     incr row
     1435    set labels { srs verticalDatum }
     1436    foreach tag $labels {
     1437        label $inner.${tag}label -text $tag -font "Arial 9"
     1438        entry $inner.${tag} -font "Arial 9"  -bg white \
     1439            -textvariable [itcl::scope _view($tag)]
     1440        bind $inner.${tag} <KeyPress-Return> \
     1441            [itcl::code $this camera set ${tag}]
     1442        blt::table $inner \
     1443            $row,0 $inner.${tag}label -anchor e -pady 2 \
     1444            $row,1 $inner.${tag} -anchor w -pady 2
     1445        blt::table configure $inner r$row -resize none
     1446        incr row
     1447    }
     1448
     1449    if {$_useServerManip} {
     1450        checkbutton $inner.throw \
     1451            -text "Enable Throw" \
     1452            -font "Arial 9" \
     1453            -variable [itcl::scope _settings(camera-throw)] \
     1454            -command [itcl::code $this AdjustSetting camera-throw]
     1455        blt::table $inner \
     1456            $row,0 $inner.throw -anchor w -pady 2 -cspan 2
     1457        blt::table configure $inner r$row -resize none
     1458        incr row
     1459    }
    14941460
    14951461    blt::table configure $inner c* r* -resize none
     
    15011467#  camera --
    15021468#
     1469# USAGE: camera get
     1470#        This is called by the server to transfer the
     1471#        current Viewpoint settings
     1472# USAGE: camera reset
     1473#        Reset the camera to the default view
     1474#
    15031475itcl::body Rappture::MapViewer::camera {option args} {
    15041476    switch -- $option {
    1505         "show" {
    1506             puts [array get _view]
     1477        "get" {
     1478            # We got the camera settings from the server
     1479            foreach name {x y z heading pitch distance srs verticalDatum} value $args {
     1480                set _view($name) $value
     1481            }
     1482puts stderr "view: $_view(x), $_view(y), $_view(z), $_view(heading), $_view(pitch), $_view(distance), $_view(srs), $_view(verticalDatum)"
     1483        }
     1484        "reset" {
     1485            array set _view {
     1486                x               0.0
     1487                y               0.0
     1488                z               0.0
     1489                heading         0.0
     1490                pitch           0.0
     1491                distance        0.0
     1492                srs             ""
     1493                verticalDatum   ""
     1494            }
     1495            if { $_first != "" } {
     1496                # Check if the tool specified a default
     1497                set location [$_first hints camera]
     1498                if { $location != "" } {
     1499                    array set _view $location
     1500                    set duration 0.0
     1501                    SendCmd [list camera set $_view(x) $_view(y) $_view(z) $_view(heading) $_view(pitch) $_view(distance) $duration $_view(srs) $_view(verticalDatum)]
     1502                } else {
     1503                    SendCmd "camera reset"
     1504                    # Retrieve the settings
     1505                    SendCmd "camera get"
     1506                }
     1507            } else {
     1508                SendCmd "camera reset"
     1509                # Retrieve the settings
     1510                SendCmd "camera get"
     1511            }
    15071512        }
    15081513        "set" {
    15091514            set who [lindex $args 0]
    1510             set x $_view($who)
    1511             set code [catch { string is double $x } result]
    1512             if { $code != 0 || !$result } {
    1513                 return
     1515            if {$who != "srs" && $who != "verticalDatum"} {
     1516                set val $_view($who)
     1517                set code [catch { string is double $val } result]
     1518                if { $code != 0 || !$result } {
     1519                    return
     1520                }
    15141521            }
    15151522            switch -- $who {
    1516                 "xpan" - "ypan" {
    1517                     PanCamera
    1518                 }
    1519                 "qx" - "qy" - "qz" - "qw" {
    1520                     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1521                     $_arcball quaternion $q
    1522                     EventuallyRotate $q
    1523                 }
    1524                 "zoom" {
    1525                     SendCmd "camera zoom $_view(zoom)"
     1523                "x" - "y" - "z" - "heading" - "pitch" - "distance" - "srs" - "verticalDatum" {
     1524                    set duration 0.0
     1525                    SendCmd [list camera set $_view(x) $_view(y) $_view(z) $_view(heading) $_view(pitch) $_view(distance) $duration $_view(srs) $_view(verticalDatum)]
    15261526                }
    15271527            }
     
    17041704        }
    17051705    }
    1706 }
    1707 
    1708 itcl::body Rappture::MapViewer::SetOrientation { side } {
    1709     array set positions {
    1710         front "1 0 0 0"
    1711         back  "0 0 1 0"
    1712         left  "0.707107 0 -0.707107 0"
    1713         right "0.707107 0 0.707107 0"
    1714         top   "0.707107 -0.707107 0 0"
    1715         bottom "0.707107 0.707107 0 0"
    1716     }
    1717     foreach name { qw qx qy qz } value $positions($side) {
    1718         set _view($name) $value
    1719     }
    1720     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1721     $_arcball quaternion $q
    1722     SendCmd "camera orient $q"
    1723     #SendCmd "camera reset"
    1724     set _view(xpan) 0
    1725     set _view(ypan) 0
    1726     set _view(zoom) 1.0
    17271706}
    17281707
Note: See TracChangeset for help on using the changeset viewer.