[436] | 1 | # ---------------------------------------------------------------------- |
---|
| 2 | # COMPONENT: field3dresult - plot a field in a ResultSet |
---|
| 3 | # |
---|
| 4 | # This widget visualizes scalar/vector fields on 3D meshes. |
---|
| 5 | # It is normally used in the ResultViewer to show results from the |
---|
| 6 | # run of a Rappture tool. Use the "add" and "delete" methods to |
---|
| 7 | # control the dataobjs showing on the plot. |
---|
| 8 | # ====================================================================== |
---|
| 9 | # AUTHOR: Michael McLennan, Purdue University |
---|
| 10 | # Copyright (c) 2004-2005 Purdue Research Foundation |
---|
| 11 | # |
---|
| 12 | # See the file "license.terms" for information on usage and |
---|
| 13 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 14 | # ====================================================================== |
---|
| 15 | package require Itk |
---|
| 16 | |
---|
| 17 | option add *Field3DResult.width 4i widgetDefault |
---|
| 18 | option add *Field3DResult.height 4i widgetDefault |
---|
| 19 | option add *Field3DResult.foreground black widgetDefault |
---|
| 20 | option add *Field3DResult.controlBackground gray widgetDefault |
---|
| 21 | option add *Field3DResult.controlDarkBackground #999999 widgetDefault |
---|
| 22 | option add *Field3DResult.plotBackground black widgetDefault |
---|
| 23 | option add *Field3DResult.plotForeground white widgetDefault |
---|
| 24 | option add *Field3DResult.font \ |
---|
[676] | 25 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
[436] | 26 | |
---|
| 27 | itcl::class Rappture::Field3DResult { |
---|
| 28 | inherit itk::Widget |
---|
| 29 | |
---|
[460] | 30 | itk_option define -mode mode Mode "auto" |
---|
| 31 | |
---|
[436] | 32 | constructor {args} { # defined below } |
---|
| 33 | destructor { # defined below } |
---|
| 34 | |
---|
| 35 | public method add {dataobj {settings ""}} |
---|
| 36 | public method get {} |
---|
| 37 | public method delete {args} |
---|
| 38 | public method scale {args} |
---|
[1717] | 39 | public method snap {w h} |
---|
[766] | 40 | public method parameters {title args} { # do nothing } |
---|
[468] | 41 | public method download {option args} |
---|
[436] | 42 | } |
---|
| 43 | |
---|
| 44 | itk::usual Field3DResult { |
---|
| 45 | keep -background -foreground -cursor -font |
---|
| 46 | keep -plotbackground -plotforeground |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | # ---------------------------------------------------------------------- |
---|
| 50 | # CONSTRUCTOR |
---|
| 51 | # ---------------------------------------------------------------------- |
---|
| 52 | itcl::body Rappture::Field3DResult::constructor {args} { |
---|
[460] | 53 | array set flags { |
---|
[1929] | 54 | -mode auto |
---|
[460] | 55 | } |
---|
| 56 | array set flags $args |
---|
[2205] | 57 | switch -- $flags(-mode) { |
---|
| 58 | "auto" - "nanovis" - "flowvis" { |
---|
| 59 | set servers [Rappture::VisViewer::GetServerList "nanovis"] |
---|
| 60 | } |
---|
[2504] | 61 | "vtkcontour" - "vtkstreamlines" { |
---|
[2205] | 62 | set servers [Rappture::VisViewer::GetServerList "vtkvis"] |
---|
| 63 | } |
---|
| 64 | "vtk" { |
---|
| 65 | # Old vtk contour widget |
---|
[2272] | 66 | set servers "" |
---|
[2205] | 67 | } |
---|
| 68 | default { |
---|
| 69 | puts stderr "unknown render mode \"$flags(-mode)\"" |
---|
| 70 | } |
---|
| 71 | } |
---|
[839] | 72 | if {"" != $servers && $flags(-mode) != "vtk"} { |
---|
[1929] | 73 | switch -- $flags(-mode) { |
---|
| 74 | "auto" - "nanovis" { |
---|
| 75 | itk_component add renderer { |
---|
| 76 | Rappture::NanovisViewer $itk_interior.ren $servers |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | "flowvis" { |
---|
| 80 | itk_component add renderer { |
---|
| 81 | Rappture::FlowvisViewer $itk_interior.ren $servers |
---|
| 82 | } |
---|
| 83 | } |
---|
[2504] | 84 | "vtkstreamlines" { |
---|
| 85 | itk_component add renderer { |
---|
| 86 | Rappture::VtkStreamlinesViewer $itk_interior.ren $servers |
---|
| 87 | } |
---|
| 88 | } |
---|
[1929] | 89 | default { |
---|
| 90 | puts stderr "unknown render mode \"$flags(-mode)\"" |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | pack $itk_component(renderer) -expand yes -fill both |
---|
[436] | 94 | |
---|
[1929] | 95 | # can't connect to rendering farm? then fall back to older viewer |
---|
| 96 | if {![$itk_component(renderer) isconnected]} { |
---|
| 97 | destroy $itk_component(renderer) |
---|
| 98 | } |
---|
[436] | 99 | } |
---|
| 100 | |
---|
| 101 | if {![info exists itk_component(renderer)]} { |
---|
[1929] | 102 | itk_component add renderer { |
---|
| 103 | Rappture::ContourResult $itk_interior.ren |
---|
| 104 | } |
---|
| 105 | pack $itk_component(renderer) -expand yes -fill both |
---|
[436] | 106 | } |
---|
| 107 | |
---|
| 108 | eval itk_initialize $args |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | # ---------------------------------------------------------------------- |
---|
| 112 | # DESTRUCTOR |
---|
| 113 | # ---------------------------------------------------------------------- |
---|
| 114 | itcl::body Rappture::Field3DResult::destructor {} { |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | # ---------------------------------------------------------------------- |
---|
| 118 | # USAGE: add <dataobj> ?<settings>? |
---|
| 119 | # |
---|
| 120 | # Clients use this to add a data object to the plot. The optional |
---|
| 121 | # <settings> are used to configure the plot. Allowed settings are |
---|
| 122 | # -color, -brightness, -width, -linestyle, and -raise. |
---|
| 123 | # ---------------------------------------------------------------------- |
---|
| 124 | itcl::body Rappture::Field3DResult::add {dataobj {settings ""}} { |
---|
| 125 | eval $itk_component(renderer) add $dataobj [list $settings] |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | # ---------------------------------------------------------------------- |
---|
| 129 | # USAGE: get |
---|
| 130 | # |
---|
| 131 | # Clients use this to query the list of objects being plotted, in |
---|
| 132 | # order from bottom to top of this result. |
---|
| 133 | # ---------------------------------------------------------------------- |
---|
| 134 | itcl::body Rappture::Field3DResult::get {} { |
---|
| 135 | return [$itk_component(renderer) get] |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | # ---------------------------------------------------------------------- |
---|
| 139 | # USAGE: delete ?<dataobj1> <dataobj2> ...? |
---|
| 140 | # |
---|
| 141 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
| 142 | # are specified, then all dataobjs are deleted. |
---|
| 143 | # ---------------------------------------------------------------------- |
---|
| 144 | itcl::body Rappture::Field3DResult::delete {args} { |
---|
| 145 | eval $itk_component(renderer) delete $args |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | # ---------------------------------------------------------------------- |
---|
| 149 | # USAGE: scale ?<data1> <data2> ...? |
---|
| 150 | # |
---|
| 151 | # Sets the default limits for the overall plot according to the |
---|
| 152 | # limits of the data for all of the given <data> objects. This |
---|
| 153 | # accounts for all objects--even those not showing on the screen. |
---|
| 154 | # Because of this, the limits are appropriate for all objects as |
---|
| 155 | # the user scans through data in the ResultSet viewer. |
---|
| 156 | # ---------------------------------------------------------------------- |
---|
| 157 | itcl::body Rappture::Field3DResult::scale {args} { |
---|
| 158 | eval $itk_component(renderer) scale $args |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | # ---------------------------------------------------------------------- |
---|
| 162 | # USAGE: download coming |
---|
[468] | 163 | # USAGE: download controls <downloadCommand> |
---|
[436] | 164 | # USAGE: download now |
---|
| 165 | # |
---|
| 166 | # Clients use this method to create a downloadable representation |
---|
| 167 | # of the plot. Returns a list of the form {ext string}, where |
---|
| 168 | # "ext" is the file extension (indicating the type of data) and |
---|
| 169 | # "string" is the data itself. |
---|
| 170 | # ---------------------------------------------------------------------- |
---|
[468] | 171 | itcl::body Rappture::Field3DResult::download {option args} { |
---|
[1854] | 172 | eval $itk_component(renderer) download $option $args |
---|
[436] | 173 | } |
---|
[1717] | 174 | |
---|
| 175 | itcl::body Rappture::Field3DResult::snap { w h } { |
---|
| 176 | return [$itk_component(renderer) snap $w $h] |
---|
| 177 | } |
---|