Changeset 5526 for trunk


Ignore:
Timestamp:
May 17, 2015, 4:33:53 PM (9 years ago)
Author:
ldelgass
Message:

Add VTK download from nano/flowvisviewer

Location:
trunk/gui/scripts
Files:
3 edited

Legend:

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

    r5463 r5526  
    13351335        set cname "component"
    13361336    }
     1337    # VTK file data:
     1338    if { [info exists _comp2vtk($cname)] } {
     1339        return $_comp2vtk($cname)
     1340    }
    13371341    # DX: Convert DX to VTK
    13381342    if {[info exists _comp2dx($cname)]} {
    13391343        set data $_comp2dx($cname)
    1340         set data [Rappture::encoding::decode $data]
     1344        set data [Rappture::encoding::decode -as zb64 $data]
    13411345        return [Rappture::DxToVtk $data]
    1342     }
    1343     # VTK file data:
    1344     if { [info exists _comp2vtk($cname)] } {
    1345         return $_comp2vtk($cname)
    13461346    }
    13471347    # Points on mesh:  Construct VTK file output.
  • trunk/gui/scripts/flowvisviewer.tcl

    r5381 r5526  
    7575    private method BuildCameraTab {}
    7676    private method BuildCutplanesTab {}
     77    private method BuildDownloadPopup { widget command }
    7778    private method BuildViewTab {}
    7879    private method BuildVolumeComponents {}
     
    9091    private method GetDatasetsWithComponent { cname }
    9192    private method GetFlowInfo { widget }
     93    private method GetImage { args }
    9294    private method GetMovie { widget width height }
    9395    private method GetPngImage { widget width height }
     96    private method GetVtkData { args }
    9497    private method InitSettings { args }
    9598    private method NameTransferFunction { dataobj comp }
     
    787790# ----------------------------------------------------------------------
    788791itcl::body Rappture::FlowvisViewer::download {option args} {
    789     set popup .flowvisviewerdownload
    790792    switch $option {
    791793        coming {
     
    798800        }
    799801        controls {
    800             if {![winfo exists $popup]} {
    801                 # if we haven't created the popup yet, do it now
    802                 Rappture::Balloon $popup \
    803                     -title "[Rappture::filexfer::label downloadWord] as..."
    804                 set inner [$popup component inner]
    805                 label $inner.summary -text "" -anchor w
    806                 pack $inner.summary -side top
    807                 set img $_image(plot)
    808                 set res "[image width $img]x[image height $img]"
    809                 radiobutton $inner.draft -text "Image (draft $res)" \
    810                     -variable Rappture::FlowvisViewer::_downloadPopup(format) \
    811                     -value draft
    812                 pack $inner.draft -anchor w
    813 
    814                 set res "640x480"
    815                 radiobutton $inner.medium -text "Movie (standard $res)" \
    816                     -variable Rappture::FlowvisViewer::_downloadPopup(format) \
    817                     -value $res
    818                 pack $inner.medium -anchor w
    819 
    820                 set res "1024x768"
    821                 radiobutton $inner.high -text "Movie (high quality $res)" \
    822                     -variable Rappture::FlowvisViewer::_downloadPopup(format) \
    823                     -value $res
    824                 pack $inner.high -anchor w
    825                 button $inner.go -text [Rappture::filexfer::label download] \
    826                     -command [lindex $args 0]
    827                 pack $inner.go -pady 4
    828                 $inner.draft select
     802            set popup .flowvisviewerdownload
     803            if { ![winfo exists $popup] } {
     804                set inner [BuildDownloadPopup $popup [lindex $args 0]]
    829805            } else {
    830806                set inner [$popup component inner]
    831807            }
    832             set num [llength [get]]
    833             set num [expr {($num == 1) ? "1 result" : "$num results"}]
     808            # FIXME: we only support download of current active component
     809            #set num [llength [get]]
     810            #set num [expr {($num == 1) ? "1 result" : "$num results"}]
     811            set num "current flow"
    834812            set word [Rappture::filexfer::label downloadWord]
    835813            $inner.summary configure -text "$word $num in the following format:"
    836             update idletasks ;# fix initial sizes
    837             update
     814            update idletasks            ;# Fix initial sizes
    838815            return $popup
    839816        }
    840817        now {
     818            set popup .flowvisviewerdownload
    841819            if { [winfo exists $popup] } {
    842820                $popup deactivate
    843821            }
    844822            switch -- $_downloadPopup(format) {
    845                 draft {
    846                     # Get the image data (as base64) and decode it back to
    847                     # binary.  This is better than writing to temporary
    848                     # files.  When we switch to the BLT picture image it
    849                     # won't be necessary to decode the image data.
    850                     set bytes [$_image(plot) data -format "jpeg -quality 100"]
    851                     set bytes [Rappture::encoding::decode -as b64 $bytes]
    852                     return [list .jpg $bytes]
    853                 }
    854823                "640x480" {
    855824                    return [$this GetMovie [lindex $args 0] 640 480]
     
    857826                "1024x768" {
    858827                    return [$this GetMovie [lindex $args 0] 1024 768]
     828                }
     829                "image" {
     830                    return [$this GetImage [lindex $args 0]]
     831                }
     832                "vtk" {
     833                    return [$this GetVtkData [lindex $args 0]]
    859834                }
    860835                default {
     
    27442719}
    27452720
     2721itcl::body Rappture::FlowvisViewer::GetVtkData { args } {
     2722    # FIXME: We can only put one component of one dataset in a single
     2723    # VTK file.  To download all components/results, we would need
     2724    # to put them in an archive (e.g. zip or tar file)
     2725    if { $_first != "" } {
     2726        set cname [lindex [$_first components] 0]
     2727        set bytes [$_first vtkdata $cname]
     2728        return [list .vtk $bytes]
     2729    }
     2730    puts stderr "Failed to get vtkdata for $_first-$_current"
     2731    return ""
     2732}
     2733
     2734itcl::body Rappture::FlowvisViewer::GetImage { args } {
     2735    if { [image width $_image(download)] > 0 &&
     2736         [image height $_image(download)] > 0 } {
     2737        set bytes [$_image(download) data -format "jpeg -quality 100"]
     2738        set bytes [Rappture::encoding::decode -as b64 $bytes]
     2739        return [list .jpg $bytes]
     2740    }
     2741    return ""
     2742}
     2743
    27462744itcl::body Rappture::FlowvisViewer::GetPngImage { widget width height } {
    27472745    set token "print[incr _nextToken]"
     
    28782876}
    28792877
     2878itcl::body Rappture::FlowvisViewer::BuildDownloadPopup { popup command } {
     2879    Rappture::Balloon $popup \
     2880        -title "[Rappture::filexfer::label downloadWord] as..."
     2881    set inner [$popup component inner]
     2882    label $inner.summary -text "" -anchor w
     2883    radiobutton $inner.vtk_button -text "VTK data file" \
     2884        -variable [itcl::scope _downloadPopup(format)] \
     2885        -font "Arial 9" \
     2886        -value vtk
     2887    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
     2888
     2889    radiobutton $inner.image_button -text "Image File" \
     2890        -variable [itcl::scope _downloadPopup(format)] \
     2891        -font "Arial 9 " \
     2892        -value image
     2893    Rappture::Tooltip::for $inner.image_button \
     2894        "Save as digital image."
     2895
     2896    set res "640x480"
     2897    radiobutton $inner.movie_std -text "Movie (standard $res)" \
     2898        -variable [itcl::scope _downloadPopup(format)] \
     2899        -value $res
     2900    Rappture::Tooltip::for $inner.movie_std \
     2901        "Save as movie file."
     2902
     2903    set res "1024x768"
     2904    radiobutton $inner.movie_high -text "Movie (high quality $res)" \
     2905        -variable [itcl::scope _downloadPopup(format)] \
     2906        -value $res
     2907    Rappture::Tooltip::for $inner.movie_high \
     2908        "Save as movie file."
     2909
     2910    button $inner.ok -text "Save" \
     2911        -highlightthickness 0 -pady 2 -padx 3 \
     2912        -command $command \
     2913        -compound left \
     2914        -image [Rappture::icon download]
     2915
     2916    button $inner.cancel -text "Cancel" \
     2917        -highlightthickness 0 -pady 2 -padx 3 \
     2918        -command [list $popup deactivate] \
     2919        -compound left \
     2920        -image [Rappture::icon cancel]
     2921
     2922    blt::table $inner \
     2923        0,0 $inner.summary -cspan 2  \
     2924        1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \
     2925        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
     2926        3,0 $inner.movie_std -anchor w -cspan 2 -padx { 4 0 } \
     2927        4,0 $inner.movie_high -anchor w -cspan 2 -padx { 4 0 } \
     2928        6,1 $inner.cancel -width .9i -fill y \
     2929        6,0 $inner.ok -padx 2 -width .9i -fill y
     2930    blt::table configure $inner r5 -height 4
     2931    blt::table configure $inner r6 -pady 4
     2932    raise $inner.image_button
     2933    $inner.vtk_button invoke
     2934    return $inner
     2935}
     2936
    28802937itcl::body Rappture::FlowvisViewer::str2millisecs { value } {
    28812938    set parts [split $value :]
  • trunk/gui/scripts/nanovisviewer.tcl

    r5514 r5526  
    7171    private method BuildCameraTab {}
    7272    private method BuildCutplanesTab {}
     73    private method BuildDownloadPopup { widget command }
    7374    private method BuildViewTab {}
    7475    private method BuildVolumeComponents {}
     
    8687    private method GetColormap { cname color }
    8788    private method GetDatasetsWithComponent { cname }
     89    private method GetImage { args }
     90    private method GetVtkData { args }
    8891    private method HideAllMarkers {}
    8992    private method InitComponentSettings { cname }
     
    602605        }
    603606        controls {
    604             # no controls for this download yet
    605             return ""
     607            set popup .nanovisdownload
     608            if { ![winfo exists $popup] } {
     609                set inner [BuildDownloadPopup $popup [lindex $args 0]]
     610            } else {
     611                set inner [$popup component inner]
     612            }
     613            # FIXME: we only support download of current active component
     614            #set num [llength [get]]
     615            #set num [expr {($num == 1) ? "1 result" : "$num results"}]
     616            set num "current field component"
     617            set word [Rappture::filexfer::label downloadWord]
     618            $inner.summary configure -text "$word $num in the following format:"
     619            update idletasks            ;# Fix initial sizes
     620            return $popup
    606621        }
    607622        now {
    608             # Get the image data (as base64) and decode it back to binary.
    609             # This is better than writing to temporary files.  When we switch
    610             # to the BLT picture image it won't be necessary to decode the
    611             # image data.
    612             if { [image width $_image(plot)] > 0 &&
    613                  [image height $_image(plot)] > 0 } {
    614                 set bytes [$_image(plot) data -format "jpeg -quality 100"]
    615                 set bytes [Rappture::encoding::decode -as b64 $bytes]
    616                 return [list .jpg $bytes]
     623            set popup .nanovisdownload
     624            if { [winfo exists $popup] } {
     625                $popup deactivate
     626            }
     627            switch -- $_downloadPopup(format) {
     628                "image" {
     629                    return [$this GetImage [lindex $args 0]]
     630                }
     631                "vtk" {
     632                    return [$this GetVtkData [lindex $args 0]]
     633                }
    617634            }
    618635            return ""
     
    20202037}
    20212038
     2039itcl::body Rappture::NanovisViewer::GetVtkData { args } {
     2040    # FIXME: We can only put one component of one dataset in a single
     2041    # VTK file.  To download all components/results, we would need
     2042    # to put them in an archive (e.g. zip or tar file)
     2043    if { $_first != "" && $_current != "" } {
     2044        set bytes [$_first vtkdata $_current]
     2045        return [list .vtk $bytes]
     2046    }
     2047    puts stderr "Failed to get vtkdata for $_first-$_current"
     2048    return ""
     2049}
     2050
     2051itcl::body Rappture::NanovisViewer::GetImage { args } {
     2052    if { [image width $_image(download)] > 0 &&
     2053         [image height $_image(download)] > 0 } {
     2054        set bytes [$_image(download) data -format "jpeg -quality 100"]
     2055        set bytes [Rappture::encoding::decode -as b64 $bytes]
     2056        return [list .jpg $bytes]
     2057    }
     2058    return ""
     2059}
     2060
     2061itcl::body Rappture::NanovisViewer::BuildDownloadPopup { popup command } {
     2062    Rappture::Balloon $popup \
     2063        -title "[Rappture::filexfer::label downloadWord] as..."
     2064    set inner [$popup component inner]
     2065    label $inner.summary -text "" -anchor w
     2066
     2067    radiobutton $inner.vtk_button -text "VTK data file" \
     2068        -variable [itcl::scope _downloadPopup(format)] \
     2069        -font "Arial 9" \
     2070        -value vtk
     2071    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
     2072
     2073    radiobutton $inner.image_button -text "Image File" \
     2074        -variable [itcl::scope _downloadPopup(format)] \
     2075        -font "Arial 9 " \
     2076        -value image
     2077    Rappture::Tooltip::for $inner.image_button \
     2078        "Save as digital image."
     2079
     2080    button $inner.ok -text "Save" \
     2081        -highlightthickness 0 -pady 2 -padx 3 \
     2082        -command $command \
     2083        -compound left \
     2084        -image [Rappture::icon download]
     2085
     2086    button $inner.cancel -text "Cancel" \
     2087        -highlightthickness 0 -pady 2 -padx 3 \
     2088        -command [list $popup deactivate] \
     2089        -compound left \
     2090        -image [Rappture::icon cancel]
     2091
     2092    blt::table $inner \
     2093        0,0 $inner.summary -cspan 2  \
     2094        1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \
     2095        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
     2096        4,1 $inner.cancel -width .9i -fill y \
     2097        4,0 $inner.ok -padx 2 -width .9i -fill y
     2098    blt::table configure $inner r3 -height 4
     2099    blt::table configure $inner r4 -pady 4
     2100    raise $inner.image_button
     2101    $inner.vtk_button invoke
     2102    return $inner
     2103}
     2104
    20222105itcl::body Rappture::NanovisViewer::SetOrientation { side } {
    20232106    array set positions {
Note: See TracChangeset for help on using the changeset viewer.