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