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