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