source: branches/blt4/gui/scripts/isomarker.tcl

Last change on this file was 2745, checked in by gah, 13 years ago

sync with trunk

File size: 5.7 KB
Line 
1
2# ----------------------------------------------------------------------
3#  COMPONENT: nanovisviewer::isomarker - Marker for 3D volume rendering
4#
5#  This widget performs volume rendering on 3D scalar/vector datasets.
6#  It connects to the Nanovis server running on a rendering farm,
7#  transmits data, and displays the results.
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# ======================================================================
15package require Itk
16package require BLT
17#package require Img
18
19itcl::class Rappture::IsoMarker {
20    private variable _value     0.0;    # Absolute value of marker.
21    private variable _label     ""
22    private variable _tick      ""
23    private variable _canvas    ""
24    private variable _nvobj     "";     # Parent nanovis object.
25    private variable _tf        "";     # Transfer function that this marker is
26                                        # associated with.
27    private variable _activeMotion   0
28    private variable _activePress    0
29    private common   _normalIcon [Rappture::icon nvlegendmark]
30    private common   _activeIcon [Rappture::icon nvlegendmark2]
31
32    constructor {c obj tf args} {
33        set _canvas $c
34        set _nvobj $obj
35        set _tf $tf
36        set w [winfo width $_canvas]
37        set h [winfo height $_canvas]
38        set _tick [$c create image 0 $h \
39                -image $_normalIcon -anchor s \
40                -tags "$this $obj" -state hidden]
41        set _label [$c create text 0 $h \
42                -anchor n -fill white -font "Helvetica 8" \
43                -tags "$this $obj" -state hidden]
44        $c bind $_tick <Enter> [itcl::code $this HandleEvent "enter"]
45        $c bind $_tick <Leave> [itcl::code $this HandleEvent "leave"]
46        $c bind $_tick <ButtonPress-1> \
47            [itcl::code $this HandleEvent "start" %x %y]
48        $c bind $_tick <B1-Motion> \
49            [itcl::code $this HandleEvent "update" %x %y]
50        $c bind $_tick <ButtonRelease-1> \
51            [itcl::code $this HandleEvent "end" %x %y]
52    }
53    destructor {
54        $_canvas delete $this
55    }
56    public method transferfunc {} {
57        return $_tf
58    }
59    public method activate { bool } {
60        if  { $bool || $_activePress || $_activeMotion } {
61            $_canvas itemconfigure $_label -state normal
62            $_canvas itemconfigure $_tick -image $_activeIcon
63        } else {
64            $_canvas itemconfigure $_label -state hidden
65            $_canvas itemconfigure $_tick -image $_normalIcon
66        }
67    }
68    public method visible { bool } {
69        if { $bool } {
70            absval $_value
71            $_canvas itemconfigure $_tick -state normal
72            $_canvas raise $_tick
73        } else {
74            $_canvas itemconfigure $_tick -state hidden
75        }
76    }
77    public method screenpos { } {
78        set x [relval]
79        if { $x < 0.0 } {
80            set x 0.0
81        } elseif { $x > 1.0 } {
82            set x 1.0
83        }
84        set low 10
85        set w [winfo width $_canvas]
86        set high [expr {$w  - 10}]
87        set x [expr {round($x*($high - $low) + $low)}]
88        return $x
89    }
90    public method absval { {x "-get"} } {
91        if { $x != "-get" } {
92            set _value $x
93            set y 31
94            $_canvas itemconfigure $_label -text [format %.2g $_value]
95            set x [screenpos]
96            $_canvas coords $_tick $x [expr {$y+3}]
97            $_canvas coords $_label $x [expr {$y+5}]
98        }
99        return $_value
100    }
101    public method relval  { {x "-get"} } {
102        if { $x == "-get" } {
103            array set limits [$_nvobj limits $_tf]
104            if { $limits(vmax) == $limits(vmin) } {
105                if { $limits(vmax) == 0.0 } {
106                    set limits(vmin) 0.0
107                    set limits(vmax) 1.0
108                } else {
109                    set limits(vmax) [expr $limits(vmin) + 1.0]
110                }
111            }
112            return [expr {($_value-$limits(vmin))/
113                          ($limits(vmax) - $limits(vmin))}]
114        }
115        array set limits [$_nvobj limits $_tf]
116        if { $limits(vmax) == $limits(vmin) } {
117            set limits(min) 0.0
118            set limits(max) 1.0
119        }
120        if { [catch {expr $limits(vmax) - $limits(vmin)} r] != 0 } {
121            return 0.0
122        }           
123        absval [expr {($x * $r) + $limits(vmin)}]
124    }
125    private method HandleEvent { option args } {
126        switch -- $option {
127            enter {
128                set _activeMotion 1
129                activate yes
130                $_canvas raise $_tick
131            }
132            leave {
133                set _activeMotion 0
134                activate no
135            }
136            start {
137                $_canvas raise $_tick
138                set _activePress 1
139                activate yes
140                $_canvas itemconfigure limits -state hidden
141            }
142            update {
143                set w [winfo width $_canvas]
144                set x [lindex $args 0]
145                relval [expr {double($x-10)/($w-20)}]
146                $_nvobj overmarker $this $x
147                $_nvobj updatetransferfuncs
148            }
149            end {
150                set x [lindex $args 0]
151                if { ![$_nvobj rmdupmarker $this $x]} {
152                    eval HandleEvent update $args
153                }
154                set _activePress 0
155                activate no
156                $_canvas itemconfigure limits -state normal
157            }
158            default {
159                error "bad option \"$option\": should be start, update, end"
160            }
161        }
162    }
163}
Note: See TracBrowser for help on using the repository browser.