[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} |
---|
[766] | 39 | public method parameters {title args} { # do nothing } |
---|
[468] | 40 | public method download {option args} |
---|
[436] | 41 | |
---|
| 42 | # resources file tells us the nanovis server |
---|
[462] | 43 | public common _nanovisHosts "" |
---|
| 44 | public proc setNanovisServer {namelist} { |
---|
| 45 | if {[regexp {^[a-zA-Z0-9\.]+:[0-9]+(,[a-zA-Z0-9\.]+:[0-9]+)*$} $namelist match]} { |
---|
| 46 | set _nanovisHosts $namelist |
---|
[436] | 47 | } else { |
---|
[462] | 48 | error "bad nanovis server address \"$namelist\": should be host:port,host:port,..." |
---|
[436] | 49 | } |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | # must use this name -- plugs into Rappture::resources::load |
---|
| 54 | proc field3d_init_resources {} { |
---|
| 55 | Rappture::resources::register \ |
---|
| 56 | nanovis_server Rappture::Field3DResult::setNanovisServer |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | itk::usual Field3DResult { |
---|
| 60 | keep -background -foreground -cursor -font |
---|
| 61 | keep -plotbackground -plotforeground |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | # ---------------------------------------------------------------------- |
---|
| 65 | # CONSTRUCTOR |
---|
| 66 | # ---------------------------------------------------------------------- |
---|
| 67 | itcl::body Rappture::Field3DResult::constructor {args} { |
---|
[460] | 68 | array set flags { |
---|
| 69 | -mode auto |
---|
| 70 | } |
---|
| 71 | array set flags $args |
---|
| 72 | |
---|
[462] | 73 | if {"" != $_nanovisHosts && $flags(-mode) != "vtk"} { |
---|
[436] | 74 | itk_component add renderer { |
---|
[462] | 75 | Rappture::NanovisViewer $itk_interior.ren $_nanovisHosts |
---|
[436] | 76 | } |
---|
| 77 | pack $itk_component(renderer) -expand yes -fill both |
---|
| 78 | |
---|
| 79 | # can't connect to rendering farm? then fall back to older viewer |
---|
| 80 | if {![$itk_component(renderer) isconnected]} { |
---|
| 81 | destroy $itk_component(renderer) |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | if {![info exists itk_component(renderer)]} { |
---|
| 86 | itk_component add renderer { |
---|
| 87 | Rappture::ContourResult $itk_interior.ren |
---|
| 88 | } |
---|
| 89 | pack $itk_component(renderer) -expand yes -fill both |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | eval itk_initialize $args |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | # ---------------------------------------------------------------------- |
---|
| 96 | # DESTRUCTOR |
---|
| 97 | # ---------------------------------------------------------------------- |
---|
| 98 | itcl::body Rappture::Field3DResult::destructor {} { |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | # ---------------------------------------------------------------------- |
---|
| 102 | # USAGE: add <dataobj> ?<settings>? |
---|
| 103 | # |
---|
| 104 | # Clients use this to add a data object to the plot. The optional |
---|
| 105 | # <settings> are used to configure the plot. Allowed settings are |
---|
| 106 | # -color, -brightness, -width, -linestyle, and -raise. |
---|
| 107 | # ---------------------------------------------------------------------- |
---|
| 108 | itcl::body Rappture::Field3DResult::add {dataobj {settings ""}} { |
---|
| 109 | eval $itk_component(renderer) add $dataobj [list $settings] |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | # ---------------------------------------------------------------------- |
---|
| 113 | # USAGE: get |
---|
| 114 | # |
---|
| 115 | # Clients use this to query the list of objects being plotted, in |
---|
| 116 | # order from bottom to top of this result. |
---|
| 117 | # ---------------------------------------------------------------------- |
---|
| 118 | itcl::body Rappture::Field3DResult::get {} { |
---|
| 119 | return [$itk_component(renderer) get] |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | # ---------------------------------------------------------------------- |
---|
| 123 | # USAGE: delete ?<dataobj1> <dataobj2> ...? |
---|
| 124 | # |
---|
| 125 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
| 126 | # are specified, then all dataobjs are deleted. |
---|
| 127 | # ---------------------------------------------------------------------- |
---|
| 128 | itcl::body Rappture::Field3DResult::delete {args} { |
---|
| 129 | eval $itk_component(renderer) delete $args |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | # ---------------------------------------------------------------------- |
---|
| 133 | # USAGE: scale ?<data1> <data2> ...? |
---|
| 134 | # |
---|
| 135 | # Sets the default limits for the overall plot according to the |
---|
| 136 | # limits of the data for all of the given <data> objects. This |
---|
| 137 | # accounts for all objects--even those not showing on the screen. |
---|
| 138 | # Because of this, the limits are appropriate for all objects as |
---|
| 139 | # the user scans through data in the ResultSet viewer. |
---|
| 140 | # ---------------------------------------------------------------------- |
---|
| 141 | itcl::body Rappture::Field3DResult::scale {args} { |
---|
| 142 | eval $itk_component(renderer) scale $args |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | # ---------------------------------------------------------------------- |
---|
| 146 | # USAGE: download coming |
---|
[468] | 147 | # USAGE: download controls <downloadCommand> |
---|
[436] | 148 | # USAGE: download now |
---|
| 149 | # |
---|
| 150 | # Clients use this method to create a downloadable representation |
---|
| 151 | # of the plot. Returns a list of the form {ext string}, where |
---|
| 152 | # "ext" is the file extension (indicating the type of data) and |
---|
| 153 | # "string" is the data itself. |
---|
| 154 | # ---------------------------------------------------------------------- |
---|
[468] | 155 | itcl::body Rappture::Field3DResult::download {option args} { |
---|
[436] | 156 | $itk_component(renderer) download $option |
---|
| 157 | } |
---|