Changeset 17


Ignore:
Timestamp:
Jun 11, 2005, 9:56:37 PM (19 years ago)
Author:
mmc
Message:

Added a capability to MainWin? to syncCutBuffer with the
application. The VNC Java client uses the cutbuffer
instead of the selection for Copy/Paste? to desktop, and
this mechanism keeps the two in sync so Copy/Paste? works
properly. Also, added Cut/Copy/Paste? menus to the right
mouse button of various widgets.

Fixed 3D plotting to work with the vtkCutter so it works
better. Also, added support for 3D meshes in addition
to clouds. Meshes store connectivity, so they are better
at representing holes in data. Fixed the 3D plotter so
that rotate is more intuitive, and added lights so you can
see your data better at any angle.

Fixed the loader so that it can load elements with the ""
value, and so that it doesn't duplicate entries found
more than once by *.xml pattern matching.

Location:
trunk/gui
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/driver

    r13 r17  
    4444option add *TemperatureGauge.textBackground white
    4545option add *Switch.textBackground white
     46
     47switch $tcl_platform(platform) {
     48    unix - windows {
     49        event add <<PopupMenu>> <ButtonPress-3>
     50    }
     51    macintosh {
     52        event add <<PopupMenu>> <Control-ButtonPress-1>
     53    }
     54}
    4655
    4756#
  • trunk/gui/scripts/analyzer.tcl

    r13 r17  
    379379        }
    380380
    381         if {"" != $label} {
     381        set hidden [$xmlobj get output.$item.hide]
     382        set hidden [expr {"" != $hidden && $hidden}]
     383
     384        if {"" != $label && !$hidden} {
    382385            set haveresults 1
    383386        }
     
    396399            }
    397400
    398             if {"" != $label} {
     401            set hidden [$xmlobj get output.$item.hide]
     402            set hidden [expr {"" != $hidden && $hidden}]
     403
     404            if {"" != $label && !$hidden} {
    399405                if {![info exists _label2page($label)]} {
    400406                    set name "page[incr _pages]"
  • trunk/gui/scripts/cloud.tcl

    r16 r17  
    2020
    2121    public method points {}
     22    public method mesh {}
    2223    public method size {}
    2324    public method dimensions {}
     
    156157
    157158# ----------------------------------------------------------------------
     159# USAGE: mesh
     160#
     161# Returns the vtk object representing the mesh.
     162# ----------------------------------------------------------------------
     163itcl::body Rappture::Cloud::mesh {} {
     164    return $this-points
     165}
     166
     167# ----------------------------------------------------------------------
    158168# USAGE: size
    159169#
     
    170180# ----------------------------------------------------------------------
    171181itcl::body Rappture::Cloud::dimensions {} {
    172 puts "dimensions for cloud [$_cloud element -as id]"
    173 puts [string range [$_cloud xml] 0 300]
    174182    # count the dimensions with real limits
    175183    set dims 0
    176184    foreach d {x y z} {
    177 puts "checking dims: $d => $_limits(${d}min) $_limits(${d}max)"
    178185        if {$_limits(${d}min) != $_limits(${d}max)} {
    179186            incr dims
  • trunk/gui/scripts/contourresult.tcl

    r16 r17  
    8686
    8787    protected method _rebuild {}
     88    protected method _clear {}
    8889    protected method _zoom {option}
    8990    protected method _move {option x y}
    9091    protected method _slice {option args}
     92    protected method _3dView {theta phi}
    9193    protected method _fixLimits {}
    9294    protected method _color2rgb {color}
    9395
    9496    private variable _dlist ""     ;# list of data objects
     97    private variable _dims ""      ;# dimensionality of data objects
    9598    private variable _obj2color    ;# maps dataobj => plotting color
    9699    private variable _obj2width    ;# maps dataobj => line width
     
    98101    private variable _obj2vtk      ;# maps dataobj => vtk objects
    99102    private variable _actors       ;# list of actors for each renderer
     103    private variable _lights       ;# list of lights for each renderer
    100104    private variable _click        ;# info used for _move operations
    101105    private variable _slicer       ;# vtk transform used for 3D slice plane
    102106    private variable _limits       ;# autoscale min/max for all axes
     107    private variable _view         ;# view params for 3D view
    103108
    104109    private common _counter 0      ;# used for auto-generated names
     
    117122
    118123    set _slicer(axis) ""
    119     set _slicer(xform) ""
     124    set _slicer(plane) ""
    120125    set _slicer(readout) ""
     126    set _view(theta) 0
     127    set _view(phi) 0
    121128
    122129    itk_component add controls {
     
    263270# ----------------------------------------------------------------------
    264271itcl::body Rappture::ContourResult::destructor {} {
     272    _clear
     273    after cancel [itcl::code $this _rebuild]
     274
    265275    rename $this-renWin ""
    266276    rename $this-ren ""
     
    270280    rename $this-ren2 ""
    271281    rename $this-iren2 ""
    272 
    273     after cancel [itcl::code $this _rebuild]
    274282}
    275283
     
    402410# ----------------------------------------------------------------------
    403411itcl::body Rappture::ContourResult::_rebuild {} {
    404     # clear out any old constructs
    405     foreach ren [array names _actors] {
    406         foreach actor $_actors($ren) {
    407             $ren RemoveActor $actor
    408         }
    409         set _actors($ren) ""
    410     }
    411     foreach dataobj [array names _obj2vtk] {
    412         foreach cmd $_obj2vtk($dataobj) {
    413             rename $cmd ""
    414         }
    415         set _obj2vtk($dataobj) ""
    416     }
    417     set _slicer(axis) ""
    418     set _slicer(xform) ""
    419     set _slicer(readout) ""
     412    _clear
    420413
    421414    # determine the dimensionality from the topmost (raised) object
     
    423416    set dataobj [lindex $dlist end]
    424417    if {$dataobj != ""} {
    425         set dims [$dataobj components -dimensions]
     418        set _dims [$dataobj components -dimensions]
    426419    } else {
    427         set dims "0D"
     420        set _dims "0D"
    428421    }
    429422
     
    432425    foreach dataobj [get] {
    433426        foreach comp [$dataobj components] {
    434             set pd $this-polydata$_counter
    435             vtkPolyData $pd
    436             $pd SetPoints [$dataobj mesh $comp]
    437             [$pd GetPointData] SetScalars [$dataobj values $comp]
    438 
     427            #
     428            # LOOKUP TABLE FOR COLOR CONTOURS
     429            #
    439430            # use vmin/vmax if possible, otherwise get from data
    440431            if {$_limits(vmin) == "" || $_limits(vmax) == ""} {
     
    445436            }
    446437
    447             set tr $this-triangles$_counter
    448             vtkDelaunay$dims $tr
    449             $tr SetInput $pd
    450             $tr SetTolerance 0.0000000000001
    451 
    452438            set lu $this-lookup$_counter
    453439            vtkLookupTable $lu
     
    456442            $lu Build
    457443
    458             lappend _obj2vtk($dataobj) $pd $tr $lu
     444            lappend _obj2vtk($dataobj) $lu
    459445
    460446            #
     
    462448            #
    463449            if {$_counter == 0} {
    464                 if {$dims == "3D"} {
     450                if {$_dims == "3D"} {
    465451                    pack $itk_component(slicer) -side bottom -padx 4 -pady 4
    466452                    pack $itk_component(zslice) -side bottom -padx 4 -pady 4
     
    469455
    470456                    #
     457                    # 3D LIGHTS (on both sides of all three axes)
     458                    #
     459                    set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}]
     460                    set ym [expr {0.5*($_limits(ymax)+$_limits(ymin))}]
     461                    set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}]
     462                    set xr [expr {$_limits(xmax)-$_limits(xmin)}]
     463                    set yr [expr {$_limits(ymax)-$_limits(ymin)}]
     464                    set zr [expr {$_limits(zmax)-$_limits(zmin)}]
     465
     466                    set lt $this-lightxm$_counter
     467                    vtkLight $lt
     468                    $lt SetColor 1 1 1
     469                    $lt SetAttenuationValues 0 0 0
     470                    $lt SetFocalPoint $xm $ym $zm
     471                    $lt SetPosition [expr {$xm-$xr}] 0 0
     472                    $this-ren AddLight $lt
     473                    lappend _lights($this-ren) $lt
     474
     475                    set lt $this-lightxp$_counter
     476                    vtkLight $lt
     477                    $lt SetColor 1 1 1
     478                    $lt SetAttenuationValues 0 0 0
     479                    $lt SetFocalPoint $xm $ym $zm
     480                    $lt SetPosition [expr {$xm+$xr}] 0 0
     481                    $this-ren AddLight $lt
     482                    lappend _lights($this-ren) $lt
     483
     484                    set lt $this-lightym$_counter
     485                    vtkLight $lt
     486                    $lt SetColor 1 1 1
     487                    $lt SetAttenuationValues 0 0 0
     488                    $lt SetFocalPoint $xm $ym $zm
     489                    $lt SetPosition 0 [expr {$ym-$yr}] 0
     490                    $this-ren AddLight $lt
     491                    lappend _lights($this-ren) $lt
     492
     493                    set lt $this-lightyp$_counter
     494                    vtkLight $lt
     495                    $lt SetColor 1 1 1
     496                    $lt SetAttenuationValues 0 0 0
     497                    $lt SetFocalPoint $xm $ym $zm
     498                    $lt SetPosition 0 [expr {$ym+$yr}] 0
     499                    $this-ren AddLight $lt
     500                    lappend _lights($this-ren) $lt
     501
     502                    set lt $this-lightzm$_counter
     503                    vtkLight $lt
     504                    $lt SetColor 1 1 1
     505                    $lt SetAttenuationValues 0 0 0
     506                    $lt SetFocalPoint $xm $ym $zm
     507                    $lt SetPosition 0 0 [expr {$zm-$zr}]
     508                    $this-ren AddLight $lt
     509                    lappend _lights($this-ren) $lt
     510
     511                    set lt $this-lightzp$_counter
     512                    vtkLight $lt
     513                    $lt SetColor 1 1 1
     514                    $lt SetAttenuationValues 0 0 0
     515                    $lt SetFocalPoint $xm $ym $zm
     516                    $lt SetPosition 0 0 [expr {$zm+$zr}]
     517                    $this-ren AddLight $lt
     518                    lappend _lights($this-ren) $lt
     519
     520                    #
     521                    # 3D DATA SET
     522                    #
     523                    set mesh [$dataobj mesh $comp]
     524                    switch -- [$mesh GetClassName] {
     525                      vtkPoints {
     526                        # handle cloud of 3D points
     527                        set pd $this-polydata$_counter
     528                        vtkPolyData $pd
     529                        $pd SetPoints $mesh
     530                        [$pd GetPointData] SetScalars [$dataobj values $comp]
     531
     532                        set tr $this-triangles$_counter
     533                        vtkDelaunay3D $tr
     534                        $tr SetInput $pd
     535                        $tr SetTolerance 0.0000000000001
     536                        set source [$tr GetOutput]
     537
     538                        set mp $this-mapper$_counter
     539                        vtkPolyDataMapper $mp
     540
     541                        lappend _obj2vtk($dataobj) $pd $tr $mp
     542                      }
     543                      vtkUnstructuredGrid {
     544                        # handle 3D grid with connectivity
     545                        set gr $this-grdata$_counter
     546                        vtkUnstructuredGrid $gr
     547                        $gr ShallowCopy $mesh
     548                        [$gr GetPointData] SetScalars [$dataobj values $comp]
     549                        set source $gr
     550
     551                        lappend _obj2vtk($dataobj) $gr
     552                      }
     553                      default {
     554                        error "don't know how to handle [$mesh GetClassName] data"
     555                      }
     556                    }
     557
     558                    #
    471559                    # 3D CUT PLANE
    472560                    #
    473561                    set pl $this-cutplane$_counter
    474                     vtkPlaneSource $pl
    475                     $pl SetResolution 50 50
    476 
    477                     set xf $this-cpxform$_counter
    478                     vtkTransform $xf
    479                     set _slicer(xform) $xf
     562                    vtkPlane $pl
     563                    set _slicer(plane) $pl
    480564                    _slice axis "z"
    481565
    482                     set pdf $this-cpfilter$_counter
    483                     vtkTransformPolyDataFilter $pdf
    484                     $pdf SetInput [$pl GetOutput]
    485                     $pdf SetTransform $xf
    486 
    487                     set pb $this-cpprobe$_counter
    488                     vtkProbeFilter $pb
    489                     $pb SetInput [$pdf GetOutput]
    490                     $pb SetSource [$tr GetOutput]
    491 
    492                     lappend _obj2vtk($dataobj) $pl $xf $pdf $pb
    493 
    494                     set mp $this-mapper$_counter
     566                    set ct $this-cutter$_counter
     567                    vtkCutter $ct
     568                    $ct SetInput $source
     569                    $ct SetCutFunction $pl
     570
     571                    set mp $this-cutmapper$_counter
    495572                    vtkPolyDataMapper $mp
    496                     $mp SetInput [$pb GetOutput]
     573                    $mp SetInput [$ct GetOutput]
    497574                    $mp SetScalarRange $v0 $v1
    498575                    $mp SetLookupTable $lu
     576
     577                    lappend _obj2vtk($dataobj) $pl $ct $mp
    499578
    500579                    set ac $this-actor$_counter
     
    505584                    $this-ren AddActor $ac
    506585                    lappend _actors($this-ren) $ac
    507 
    508                     lappend _obj2vtk($dataobj) $mp $ac
     586                    lappend _obj2vtk($dataobj) $ac
    509587
    510588                    set olf $this-3dolfilter$_counter
    511589                    vtkOutlineFilter $olf
    512                     $olf SetInput [$tr GetOutput]
     590                    $olf SetInput $source
    513591
    514592                    set olm $this-3dolmapper$_counter
     
    552630                    pack forget $itk_component(slicer)
    553631
     632                    set pd $this-polydata$_counter
     633                    vtkPolyData $pd
     634                    $pd SetPoints [$dataobj mesh $comp]
     635                    [$pd GetPointData] SetScalars [$dataobj values $comp]
     636
     637                    set tr $this-triangles$_counter
     638                    vtkDelaunay2D $tr
     639                    $tr SetInput $pd
     640                    $tr SetTolerance 0.0000000000001
     641                    set source [$tr GetOutput]
     642
    554643                    set mp $this-mapper$_counter
    555644                    vtkPolyDataMapper $mp
    556                     $mp SetInput [$tr GetOutput]
     645                    $mp SetInput $source
    557646                    $mp SetScalarRange $v0 $v1
    558647                    $mp SetLookupTable $lu
     
    566655                    lappend _actors($this-ren) $ac
    567656
    568                     lappend _obj2vtk($dataobj) $mp $ac
     657                    lappend _obj2vtk($dataobj) $pd $tr $mp $ac
    569658                }
    570659            }
     
    576665                set cf $this-clfilter$_counter
    577666                vtkContourFilter $cf
    578                 $cf SetInput [$tr GetOutput]
     667                $cf SetInput $source
    579668                $cf GenerateValues 20 $v0 $v1
    580669
     
    601690            set olf $this-olfilter$_counter
    602691            vtkOutlineFilter $olf
    603             $olf SetInput [$tr GetOutput]
     692            $olf SetInput $source
    604693
    605694            set olm $this-olmapper$_counter
     
    645734    _zoom reset
    646735
    647     if {$dims == "3D"} {
    648         # allow interactions in 3D
    649         catch {blt::busy release $itk_component(area)}
    650     } else {
    651         # prevent interactions in 2D
    652         blt::busy hold $itk_component(area) -cursor left_ptr
    653         bind $itk_component(area)_Busy <ButtonPress> \
    654             [itcl::code $this _move click %x %y]
    655         bind $itk_component(area)_Busy <B1-Motion> \
    656             [itcl::code $this _move drag %x %y]
    657         bind $itk_component(area)_Busy <ButtonRelease> \
    658             [itcl::code $this _move release %x %y]
    659     }
     736    # prevent interactions -- use our own
     737    blt::busy hold $itk_component(area) -cursor left_ptr
     738    bind $itk_component(area)_Busy <ButtonPress> \
     739        [itcl::code $this _move click %x %y]
     740    bind $itk_component(area)_Busy <B1-Motion> \
     741        [itcl::code $this _move drag %x %y]
     742    bind $itk_component(area)_Busy <ButtonRelease> \
     743        [itcl::code $this _move release %x %y]
     744}
     745
     746# ----------------------------------------------------------------------
     747# USAGE: _clear
     748#
     749# Used internally to clear the drawing area and tear down all vtk
     750# objects in the current scene.
     751# ----------------------------------------------------------------------
     752itcl::body Rappture::ContourResult::_clear {} {
     753    # clear out any old constructs
     754    foreach ren [array names _actors] {
     755        foreach actor $_actors($ren) {
     756            $ren RemoveActor $actor
     757        }
     758        set _actors($ren) ""
     759    }
     760    foreach ren [array names _lights] {
     761        foreach light $_lights($ren) {
     762            $ren RemoveLight $light
     763            rename $light ""
     764        }
     765        set _lights($ren) ""
     766    }
     767    foreach dataobj [array names _obj2vtk] {
     768        foreach cmd $_obj2vtk($dataobj) {
     769            rename $cmd ""
     770        }
     771        set _obj2vtk($dataobj) ""
     772    }
     773    set _slicer(axis) ""
     774    set _slicer(plane) ""
     775    set _slicer(readout) ""
    660776}
    661777
     
    671787    switch -- $option {
    672788        in {
    673             set camera [$this-ren GetActiveCamera]
    674             set zoom [$camera Zoom 1.25]
     789            [$this-ren GetActiveCamera] Zoom 1.25
    675790            $this-renWin Render
    676791        }
    677792        out {
    678             set camera [$this-ren GetActiveCamera]
    679             set zoom [$camera Zoom 0.8]
     793            [$this-ren GetActiveCamera] Zoom 0.8
    680794            $this-renWin Render
    681795        }
    682796        reset {
    683             $this-ren ResetCamera
    684             [$this-ren GetActiveCamera] Zoom 1.5
     797            if {$_dims == "3D"} {
     798                [$this-ren GetActiveCamera] SetViewAngle 30
     799                $this-ren ResetCamera
     800                _3dView 45 45
     801            } else {
     802                $this-ren ResetCamera
     803                [$this-ren GetActiveCamera] Zoom 1.5
     804            }
    685805            $this-renWin Render
    686806            $this-renWin2 Render
     
    703823            set _click(x) $x
    704824            set _click(y) $y
     825            set _click(theta) $_view(theta)
     826            set _click(phi) $_view(phi)
    705827        }
    706828        drag {
     
    712834                set dx [expr {double($x-$_click(x))/$w}]
    713835                set dy [expr {double($y-$_click(y))/$h}]
    714                 foreach actor $_actors($this-ren) {
    715                     foreach {ax ay az} [$actor GetPosition] break
    716                     $actor SetPosition [expr {$ax+$dx}] [expr {$ay-$dy}] 0
     836
     837                if {$_dims == "2D"} {
     838                    #
     839                    # Shift the contour plot in 2D
     840                    #
     841                    foreach actor $_actors($this-ren) {
     842                        foreach {ax ay az} [$actor GetPosition] break
     843                        $actor SetPosition [expr {$ax+$dx}] [expr {$ay-$dy}] 0
     844                    }
     845                    $this-renWin Render
     846                } elseif {$_dims == "3D"} {
     847                    #
     848                    # Rotate the camera in 3D
     849                    #
     850                    set theta [expr {$_view(theta) - $dy*180}]
     851                    if {$theta < 2} { set theta 2 }
     852                    if {$theta > 178} { set theta 178 }
     853                    set phi [expr {$_view(phi) - $dx*360}]
     854
     855                    _3dView $theta $phi
     856                    $this-renWin Render
    717857                }
    718                 $this-renWin Render
    719 
    720858                set _click(x) $x
    721859                set _click(y) $y
     
    743881# ----------------------------------------------------------------------
    744882itcl::body Rappture::ContourResult::_slice {option args} {
    745     if {$_slicer(xform) == ""} {
     883    if {$_slicer(plane) == ""} {
    746884        # no slicer? then bail out!
    747885        return
     
    754892            set axis [lindex $args 0]
    755893
     894            switch -- $axis {
     895                x { $_slicer(plane) SetNormal 1 0 0 }
     896                y { $_slicer(plane) SetNormal 0 1 0 }
     897                z { $_slicer(plane) SetNormal 0 0 1 }
     898                default {
     899                    error "bad axis \"$axis\": should be x, y, z"
     900                }
     901            }
     902
    756903            set _slicer(axis) $axis
    757904            $itk_component(slicer) set 50
     
    770917            set newval [lindex $args 0]
    771918
    772             switch -- $_slicer(axis) {
    773                 x {
    774                     # Rotate 90 around x-axis -- switch y/z scales
    775                     # limit z-motion according to y-scale
    776                     set min ymin; set max ymax
    777                     # switch scales for y/z
    778                     set sx [expr {$_limits(xmax)-$_limits(xmin)}]
    779                     set sy [expr {$_limits(zmax)-$_limits(zmin)}]
    780                     set sz [expr {$_limits(ymax)-$_limits(ymin)}]
    781                 }
    782                 y {
    783                     # Rotate 90 around x-axis -- switch x/z scales
    784                     # limit z-motion according to x-scale
    785                     set min xmin; set max xmax
    786                     # switch scales for x/z
    787                     set sx [expr {$_limits(zmax)-$_limits(zmin)}]
    788                     set sy [expr {$_limits(ymax)-$_limits(ymin)}]
    789                     set sz [expr {$_limits(xmax)-$_limits(xmin)}]
    790                 }
    791                 z {
    792                     # No rotation -- treat z-axis normally
    793                     set min zmin; set max zmax
    794                     set sx [expr {$_limits(xmax)-$_limits(xmin)}]
    795                     set sy [expr {$_limits(ymax)-$_limits(ymin)}]
    796                     set sz [expr {$_limits(zmax)-$_limits(zmin)}]
    797                 }
    798             }
    799 
    800             set zval [expr {0.01*($newval-50)
    801                 *($_limits($max)-$_limits($min))
    802                   + 0.5*($_limits($max)+$_limits($min))}]
    803 
    804             $_slicer(xform) Identity
    805             switch -- $_slicer(axis) {
    806                 x { $_slicer(xform) RotateX 90 }
    807                 y { $_slicer(xform) RotateY 90 }
    808                 z { # all set }
    809                 default { error "bad axis \"$axis\": should be x, y, z" }
    810             }
    811             $_slicer(xform) Translate 0 0 $zval
    812             $_slicer(xform) Scale $sx $sy $sz
     919            set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}]
     920            set ym [expr {0.5*($_limits(ymax)+$_limits(ymin))}]
     921            set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}]
     922
     923            set a $_slicer(axis)
     924            set newval [expr {0.01*($newval-50)
     925                *($_limits(${a}max)-$_limits(${a}min))
     926                  + 0.5*($_limits(${a}max)+$_limits(${a}min))}]
    813927
    814928            # show the current value in the readout
    815929            if {$_slicer(readout) != ""} {
    816                 set a $_slicer(axis)
    817                 set newval [expr {0.01*($newval-50)
    818                     *($_limits(${a}max)-$_limits(${a}min))
    819                       + 0.5*($_limits(${a}max)+$_limits(${a}min))}]
    820930                $_slicer(readout) SetInput "$a = $newval"
    821931            }
     932
     933            # keep a little inside the volume, or the slice will disappear!
     934            if {$newval == $_limits(${a}min)} {
     935                set range [expr {$_limits(${a}max)-$_limits(${a}min)}]
     936                set newval [expr {$newval + 1e-6*$range}]
     937            }
     938
     939            # xfer new value to the proper dimension and move the cut plane
     940            set ${a}m $newval
     941            $_slicer(plane) SetOrigin $xm $ym $zm
    822942
    823943            $this-renWin Render
     
    827947        }
    828948    }
     949}
     950
     951# ----------------------------------------------------------------------
     952# USAGE: _3dView <theta> <phi>
     953#
     954# Used internally to change the position of the camera for 3D data
     955# sets.  Sets the camera according to the angles <theta> (angle from
     956# the z-axis) and <phi> (angle from the x-axis in the x-y plane).
     957# Both angles are in degrees.
     958# ----------------------------------------------------------------------
     959itcl::body Rappture::ContourResult::_3dView {theta phi} {
     960    set deg2rad 0.0174532927778
     961    set xn [expr {sin($theta*$deg2rad)*cos($phi*$deg2rad)}]
     962    set yn [expr {sin($theta*$deg2rad)*sin($phi*$deg2rad)}]
     963    set zn [expr {cos($theta*$deg2rad)}]
     964
     965    set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}]
     966    set ym [expr {0.5*($_limits(ymax)+$_limits(ymin))}]
     967    set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}]
     968
     969    set cam [$this-ren GetActiveCamera]
     970    set zoom [$cam GetViewAngle]
     971    $cam SetViewAngle 30
     972
     973    $cam SetFocalPoint $xm $ym $zm
     974    $cam SetPosition [expr {$xm-$xn}] [expr {$ym-$yn}] [expr {$zm+$zn}]
     975    $cam ComputeViewPlaneNormal
     976    $cam SetViewUp 0 0 1  ;# z-dir is up
     977    $cam OrthogonalizeViewUp
     978    $this-ren ResetCamera
     979    $cam SetViewAngle $zoom
     980
     981    set _view(theta) $theta
     982    set _view(phi) $phi
    829983}
    830984
  • trunk/gui/scripts/curve.tcl

    r13 r17  
    117117    switch -- $which {
    118118        x { set pos 0 }
    119         y { set pos 1 }
     119        y - v { set pos 1 }
    120120        default {
    121121            error "bad option \"$which\": should be x or y"
  • trunk/gui/scripts/editor.tcl

    r11 r17  
    9191        [itcl::code $this _click %X %Y]
    9292
     93    itk_component add emenu {
     94        menu $itk_component(editor).menu -tearoff 0
     95    } {
     96        usual
     97        ignore -tearoff
     98        ignore -background -foreground
     99    }
     100    $itk_component(emenu) add command -label "Cut" -accelerator "^X" \
     101        -command [list event generate $itk_component(editor) <<Cut>>]
     102    $itk_component(emenu) add command -label "Copy" -accelerator "^C" \
     103        -command [list event generate $itk_component(editor) <<Copy>>]
     104    $itk_component(emenu) add command -label "Paste" -accelerator "^V" \
     105        -command [list event generate $itk_component(editor) <<Paste>>]
     106    bind $itk_component(editor) <<PopupMenu>> {
     107        tk_popup %W.menu %X %Y
     108    }
     109
    93110    eval itk_initialize $args
    94111}
     
    104121itcl::body Rappture::Editor::activate {} {
    105122    set e $itk_component(editor)
     123    if {[winfo ismapped $e]} {
     124        return  ;# already mapped -- nothing to do
     125    }
    106126
    107127    set info ""
     
    234254    if {[winfo containing $x $y] != $itk_component(editor)} {
    235255        deactivate
     256    } else {
     257        # make sure the editor has keyboard focus!
     258        # it loses focus sometimes during cut/copy/paste operations
     259        focus -force $itk_component(editor)
    236260    }
    237261}
  • trunk/gui/scripts/field.tcl

    r16 r17  
    9292    }
    9393    foreach name [array names _comp2vtk] {
    94         set cobj [lindex $_comp2vtk($name) 0]
    95         Rappture::Cloud::release $cobj
     94        set mobj [lindex $_comp2vtk($name) 0]
     95        set class [$mobj info class]
     96        ${class}::release $mobj
    9697
    9798        set fobj [lindex $_comp2vtk($name) 1]
     
    147148    }
    148149    if {[info exists _comp2vtk($what)]} {
    149         set cobj [lindex $_comp2vtk($what) 0]
    150         return [$cobj points]
     150        set mobj [lindex $_comp2vtk($what) 0]
     151        return [$mobj mesh]
    151152    }
    152153    error "bad option \"$what\": should be [join [lsort [array names _comp2dims]] {, }]"
     
    305306    }
    306307    foreach name [array names _comp2vtk] {
    307         set cobj [lindex $_comp2vtk($name) 0]
    308         Rappture::Cloud::release $cobj
     308        set mobj [lindex $_comp2vtk($name) 0]
     309        set class [$mobj info class]
     310        ${class}::release $mobj
    309311
    310312        set fobj [lindex $_comp2vtk($name) 1]
     
    390392            set path [$_field get $cname.mesh]
    391393            if {[$_xmlobj element $path] != ""} {
    392                 set cobj [Rappture::Cloud::fetch $_xmlobj $path]
    393                 if {[$cobj dimensions] > 1} {
     394                switch -- [$_xmlobj element -as type $path] {
     395                    cloud {
     396                        set mobj [Rappture::Cloud::fetch $_xmlobj $path]
     397                    }
     398                    mesh {
     399                        set mobj [Rappture::Mesh::fetch $_xmlobj $path]
     400                    }
     401                }
     402
     403                if {[$mobj dimensions] > 1} {
    394404                    #
    395405                    # 2D/3D data
     
    407417                    }
    408418
    409                     set _comp2dims($cname) "[$cobj dimensions]D"
    410                     set _comp2vtk($cname) [list $cobj $farray]
     419                    set _comp2dims($cname) "[$mobj dimensions]D"
     420                    set _comp2vtk($cname) [list $mobj $farray]
    411421                    incr _counter
    412422                } else {
     
    418428                    set yv [blt::vector create y$_counter]
    419429
    420                     set vtkpts [$cobj points]
     430                    set vtkpts [$mobj points]
    421431                    set max [$vtkpts GetNumberOfPoints]
    422432                    for {set i 0} {$i < $max} {incr i} {
     
    424434                        $xv append $xval
    425435                    }
    426                     Rappture::Cloud::release $cobj
     436                    set class [$mobj info class]
     437                    ${class}::release $mobj
    427438
    428439                    set values [$_field get $cname.values]
  • trunk/gui/scripts/gauge.tcl

    r11 r17  
    3838
    3939    public method value {args}
     40    public method edit {option}
    4041
    4142    protected method _redraw {}
     
    8788    bind $itk_component(value) <Enter> [itcl::code $this _hilite value on]
    8889    bind $itk_component(value) <Leave> [itcl::code $this _hilite value off]
     90
     91    bind $itk_component(value) <<Cut>> [itcl::code $this edit cut]
     92    bind $itk_component(value) <<Copy>> [itcl::code $this edit copy]
     93    bind $itk_component(value) <<Paste>> [itcl::code $this edit paste]
     94
     95    itk_component add emenu {
     96        menu $itk_component(value).menu -tearoff 0
     97    } {
     98        usual
     99        ignore -tearoff
     100    }
     101    $itk_component(emenu) add command -label "Cut" -accelerator "^X" \
     102        -command [list event generate $itk_component(value) <<Cut>>]
     103    $itk_component(emenu) add command -label "Copy" -accelerator "^C" \
     104        -command [list event generate $itk_component(value) <<Copy>>]
     105    $itk_component(emenu) add command -label "Paste" -accelerator "^V" \
     106        -command [list event generate $itk_component(value) <<Paste>>]
     107    bind $itk_component(value) <<PopupMenu>> {
     108        tk_popup %W.menu %X %Y
     109    }
    89110
    90111    itk_component add editor {
     
    196217
    197218# ----------------------------------------------------------------------
     219# USAGE: edit cut
     220# USAGE: edit copy
     221# USAGE: edit paste
     222#
     223# Used internally to handle cut/copy/paste operations for the current
     224# value.  Usually invoked by <<Cut>>, <<Copy>>, <<Paste>> events, but
     225# can also be called directly through this method.
     226# ----------------------------------------------------------------------
     227itcl::body Rappture::Gauge::edit {option} {
     228    switch -- $option {
     229        cut {
     230            edit copy
     231            _editor popup
     232            $itk_component(editor) value ""
     233            $itk_component(editor) deactivate
     234        }
     235        copy {
     236            clipboard clear
     237            clipboard append $_value
     238        }
     239        paste {
     240            _editor popup
     241            $itk_component(editor) value [clipboard get]
     242            $itk_component(editor) deactivate
     243        }
     244        default {
     245            error "bad option \"$option\": should be cut, copy, paste"
     246        }
     247    }
     248}
     249
     250# ----------------------------------------------------------------------
    198251# USAGE: _redraw
    199252#
  • trunk/gui/scripts/loader.tcl

    r14 r17  
    9696                        set label "Example #$_counter"
    9797                    }
    98                     $itk_component(combo) choices insert end $obj $label
    99 
    100                     if {[string equal $defval [file tail $fname]]} {
    101                         $xmlobj put $path.default $label
     98
     99                    # if this is new, add it
     100                    set i [$itk_component(combo) choices index -label $label]
     101                    if {$i < 0} {
     102                        $itk_component(combo) choices insert end $obj $label
     103
     104                        if {[string equal $defval [file tail $fname]]} {
     105                            $xmlobj put $path.default $label
     106                        }
    102107                    }
    103108                }
  • trunk/gui/scripts/mainwin.tcl

    r13 r17  
    1313# ======================================================================
    1414package require Itk
     15package require BLT
    1516
    1617option add *MainWin.mode desktop widgetDefault
     
    3132
    3233    public method draw {option args}
     34    public method syncCutBuffer {option args}
    3335
    3436    protected method _redraw {}
    3537
    3638    private variable _contents ""  ;# frame containing app
     39    private variable _sync         ;# to sync current selection and cut buffer
    3740    private variable _bgscript ""  ;# script of background drawing cmds
    3841    private variable _bgparser ""  ;# parser for bgscript
     
    9699    set btags [bindtags $itk_component(hull)]
    97100    bindtags $itk_component(hull) [lappend btags RapptureMainWin]
     101
     102    set _sync(cutbuffer) ""
     103    set _sync(selection) ""
     104    syncCutBuffer ifneeded
     105}
     106
     107# ----------------------------------------------------------------------
     108# USAGE: syncCutBuffer ifneeded
     109# USAGE: syncCutBuffer transfer <offset> <maxchars>
     110# USAGE: syncCutBuffer lostselection
     111#
     112# Invoked automatically whenever the mouse pointer enters or leaves
     113# a main window to sync the cut buffer with the primary selection.
     114# This helps applications work properly with the "Copy/Paste with
     115# Desktop" option on the VNC applet for the nanoHUB.
     116#
     117# The "ifneeded" option syncs the cutbuffer and the primary selection
     118# if either one has new data.
     119#
     120# The "fromselection" option syncs from the primary selection to the
     121# cut buffer.  If there's a primary selection, it gets copied to the
     122# cut buffer.
     123# ----------------------------------------------------------------------
     124itcl::body Rappture::MainWin::syncCutBuffer {option args} {
     125    set mainwin $itk_component(hull)
     126    switch -- $option {
     127        ifneeded {
     128            #
     129            # See if the incoming cut buffer has changed.
     130            # If so, then sync the new input to the primary selection.
     131            #
     132            set s [blt::cutbuffer get]
     133            if {"" != $s && ![string equal $s $_sync(cutbuffer)]} {
     134                set _sync(cutbuffer) $s
     135
     136                if {![string equal $s $_sync(selection)]
     137                      && [selection own -selection PRIMARY] != $mainwin} {
     138                    set _sync(selection) $s
     139
     140                    clipboard clear
     141                    clipboard append -- $s
     142                    selection handle -selection PRIMARY $mainwin \
     143                        [itcl::code $this syncCutBuffer transfer]
     144                    selection own -selection PRIMARY -command \
     145                        [itcl::code $this syncCutBuffer lostselection] \
     146                        $mainwin
     147                }
     148            }
     149
     150            #
     151            # See if the selection has changed.  If so, then sync
     152            # the new input to the cut buffer, so it's available
     153            # outside the VNC client.
     154            #
     155            set s ""
     156            if {[catch {selection get -selection PRIMARY} s] || "" == $s} {
     157                if {[catch {clipboard get} s]} {
     158                    set s ""
     159                }
     160            }
     161            if {"" != $s && ![string equal $s $_sync(selection)]} {
     162                set _sync(selection) $s
     163                blt::cutbuffer set $s
     164            }
     165
     166            # do this again soon
     167            after 1000 [itcl::code $this syncCutBuffer ifneeded]
     168        }
     169        transfer {
     170            if {[llength $args] != 2} {
     171                error "wrong # args: should be \"syncCutBuffer transfer offset max\""
     172            }
     173            set offset [lindex $args 0]
     174            set maxchars [lindex $args 1]
     175            return [string range $_currseln $offset [expr {$offset+$maxchars-1}]]
     176        }
     177        lostselection {
     178            # nothing to do
     179        }
     180        default {
     181            error "bad option \"$option\": should be ifneeded, transfer, or lostselection"
     182        }
     183    }
    98184}
    99185
     
    127213        }
    128214
     215        set bd 0  ;# optional border
    129216        set sw [winfo width $itk_component(area)]
    130217        set sh [winfo height $itk_component(area)]
     
    133220        set w [winfo reqwidth $itk_component(app)]
    134221        set h [winfo reqheight $itk_component(app)]
    135         if {$w > $sw} {
    136             set $w $sw
     222        if {$w > $sw-2*$bd} {
     223            set $w [expr {$sw-2*$bd}]
    137224            set clip 1
    138225        }
     
    141228            n {
    142229                set x [expr {$sw/2}]
    143                 set y 0
     230                set y $bd
    144231            }
    145232            s {
    146233                set x [expr {$sw/2}]
    147                 set y $sh
     234                set y [expr {$sh-$bd}]
    148235            }
    149236            center {
     
    152239            }
    153240            w {
    154                 set x 0
     241                set x $bd
    155242                set y [expr {$sh/2}]
    156243            }
    157244            e {
    158                 set x $sw
     245                set x [expr {$sw-$bd}]
    159246                set y [expr {$sh/2}]
    160247            }
    161248            nw {
    162                 set x 0
    163                 set y 0
     249                set x $bd
     250                set y $bd
    164251            }
    165252            ne {
    166                 set x $sw
    167                 set y 0
     253                set x [expr {$sw-$bd}]
     254                set y $bd
    168255            }
    169256            sw {
    170                 set x 0
    171                 set y $sh
     257                set x $bd
     258                set y [expr {$sh-$bd}]
    172259            }
    173260            se {
    174                 set x $sw
    175                 set y $sh
     261                set x [expr {$sw-$bd}]
     262                set y [expr {$sh-$bd}]
    176263            }
    177264        }
  • trunk/gui/scripts/mesh.tcl

    r14 r17  
    2323    public method points {}
    2424    public method elements {}
    25     public method size {}
     25    public method mesh {}
     26    public method size {{what -points}}
    2627    public method dimensions {}
    2728    public method limits {which}
     
    3637    private variable _units "m"  ;# system of units for this mesh
    3738    private variable _limits     ;# limits xmin, xmax, ymin, ymax, ...
    38     private variable _npts 0     ;# number of points
    39     private variable _nelems 0   ;# number of elements
    4039
    4140    private common _xp2obj       ;# used for fetch/release ref counting
     
    105104    }
    106105
     106    # create the vtk objects containing points and connectivity
     107    vtkPoints $this-points
     108    vtkVoxel $this-vox
     109    vtkUnstructuredGrid $this-grid
     110
    107111    foreach lim {xmin xmax ymin ymax zmin zmax} {
    108112        set _limits($lim) ""
    109113    }
    110114
     115    #
     116    # Extract each node and add it to the points list.
     117    #
    111118    foreach comp [$xmlobj children -type node $path] {
    112119        set xyz [$xmlobj get $path.$comp]
     
    133140            }
    134141        }
    135         incr _npts
    136     }
    137     set _nelems [llength [$xmlobj children -type element $path]]
     142        $this-points InsertNextPoint $x $y $z
     143    }
     144    $this-grid SetPoints $this-points
     145
     146    #
     147    # Extract each element and add it to the mesh.
     148    #
     149    foreach comp [$xmlobj children -type element $path] {
     150        set nlist [$_mesh get $comp.nodes]
     151        set i 0
     152        foreach n $nlist {
     153            [$this-vox GetPointIds] SetId $i $n
     154            incr i
     155        }
     156        $this-grid InsertNextCell [$this-vox GetCellType] \
     157            [$this-vox GetPointIds]
     158    }
    138159}
    139160
     
    144165    # don't destroy the _xmlobj! we don't own it!
    145166    itcl::delete object $_mesh
     167
     168    rename $this-points ""
     169    rename $this-vox ""
     170    rename $this-grid ""
    146171}
    147172
     
    153178itcl::body Rappture::Mesh::points {} {
    154179    # not implemented
    155     return ""
     180    return $this-points
    156181}
    157182
     
    198223
    199224# ----------------------------------------------------------------------
    200 # USAGE: size
     225# USAGE: mesh
     226#
     227# Returns the vtk object representing the mesh.
     228# ----------------------------------------------------------------------
     229itcl::body Rappture::Mesh::mesh {} {
     230    return $this-grid
     231}
     232
     233# ----------------------------------------------------------------------
     234# USAGE: size ?-points|-elements?
    201235#
    202236# Returns the number of points in this mesh.
    203237# ----------------------------------------------------------------------
    204 itcl::body Rappture::Mesh::size {} {
    205     return $_npts
     238itcl::body Rappture::Mesh::size {{what -points}} {
     239    switch -- $what {
     240        -points {
     241            return [$this-points GetNumberOfPoints]
     242        }
     243        -elements {
     244            return [$this-points GetNumberOfCells]
     245        }
     246        default {
     247            error "bad option \"$what\": should be -points or -elements"
     248        }
     249    }
    206250}
    207251
  • trunk/gui/scripts/textentry.tcl

    r11 r17  
    109109        if {$_mode == "entry"} {
    110110            $itk_component(entry) configure -state normal
     111            $itk_component(emenu) entryconfigure "Cut" -state normal
     112            $itk_component(emenu) entryconfigure "Copy" -state normal
     113            $itk_component(emenu) entryconfigure "Paste" -state normal
    111114            $itk_component(entry) delete 0 end
    112115            $itk_component(entry) insert 0 $newval
    113116            if {!$itk_option(-editable)} {
    114117                $itk_component(entry) configure -state disabled
     118                $itk_component(emenu) entryconfigure "Cut" -state disabled
     119                $itk_component(emenu) entryconfigure "Copy" -state disabled
     120                $itk_component(emenu) entryconfigure "Paste" -state disabled
    115121            }
    116122        } elseif {$_mode == "text"} {
    117123            $itk_component(text) configure -state normal
     124            $itk_component(tmenu) entryconfigure "Cut" -state normal
     125            $itk_component(tmenu) entryconfigure "Copy" -state normal
     126            $itk_component(tmenu) entryconfigure "Paste" -state normal
    118127            $itk_component(text) delete 1.0 end
    119128            $itk_component(text) insert end $newval
    120129            if {!$itk_option(-editable)} {
    121130                $itk_component(text) configure -state disabled
     131                $itk_component(tmenu) entryconfigure "Cut" -state disabled
     132                $itk_component(tmenu) entryconfigure "Copy" -state disabled
     133                $itk_component(tmenu) entryconfigure "Paste" -state disabled
    122134            }
    123135        }
     
    231243                -foreground $itk_option(-textforeground)
    232244
     245            itk_component add emenu {
     246                menu $itk_component(entry).menu -tearoff 0
     247            }
     248            $itk_component(emenu) add command -label "Cut" -accelerator "^X" \
     249                -command [list event generate $itk_component(entry) <<Cut>>]
     250            $itk_component(emenu) add command -label "Copy" -accelerator "^C" \
     251                -command [list event generate $itk_component(entry) <<Copy>>]
     252            $itk_component(emenu) add command -label "Paste" -accelerator "^V" \
     253                -command [list event generate $itk_component(entry) <<Paste>>]
     254            bind $itk_component(entry) <<PopupMenu>> {
     255                tk_popup %W.menu %X %Y
     256            }
     257
    233258            $itk_component(entry) insert end $val
    234259            if {!$itk_option(-editable)} {
     
    270295            $itk_component(scrollbars) contents $itk_component(text)
    271296
     297            itk_component add tmenu {
     298                menu $itk_component(text).menu -tearoff 0
     299            }
     300            $itk_component(tmenu) add command -label "Cut" -accelerator "^X" \
     301                -command [list event generate $itk_component(text) <<Cut>>]
     302            $itk_component(tmenu) add command -label "Copy" -accelerator "^C" \
     303                -command [list event generate $itk_component(text) <<Copy>>]
     304            $itk_component(tmenu) add command -label "Paste" -accelerator "^V" \
     305                -command [list event generate $itk_component(text) <<Paste>>]
     306            bind $itk_component(text) <<PopupMenu>> {
     307                tk_popup %W.menu %X %Y
     308            }
     309
    272310            $itk_component(text) insert end $val
    273311            if {!$itk_option(-editable)} {
    274312                $itk_component(text) configure -state disabled
     313                $itk_component(menu) entryconfigure "Cut" -state disabled
     314                $itk_component(menu) entryconfigure "Copy" -state disabled
     315                $itk_component(menu) entryconfigure "Paste" -state disabled
    275316            }
    276317            set _mode "text"
     
    306347    if {$_mode == "entry"} {
    307348        $itk_component(editor) configure -state $state
     349        $itk_component(emenu) entryconfigure "Cut" -state $state
     350        $itk_component(emenu) entryconfigure "Copy" -state $state
     351        $itk_component(emenu) entryconfigure "Paste" -state $state
    308352    } elseif {$_mode == "text"} {
    309353        $itk_component(text) configure -state $state
     354        $itk_component(tmenu) entryconfigure "Cut" -state $state
     355        $itk_component(tmenu) entryconfigure "Copy" -state $state
     356        $itk_component(tmenu) entryconfigure "Paste" -state $state
    310357    }
    311358}
  • trunk/gui/scripts/tool.tcl

    r13 r17  
    191191        if {"" != [$newobj element -as type $path.current]} {
    192192            set val [$newobj get $path.current]
    193             if {[string length $val] > 0} {
     193            if {[string length $val] > 0
     194                  || [llength [$newobj children $path.current]] == 0} {
    194195                $_path2widget($path) value $val
    195196            } else {
Note: See TracChangeset for help on using the changeset viewer.