source: trunk/gui/scripts/isomarker.tcl @ 1943

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

add unit cell to molvisviewer

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
17package 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        parray limits
117        if { $limits(vmax) == $limits(vmin) } {
118            set limits(min) 0.0
119            set limits(max) 1.0
120        }
121        if { [catch {expr $limits(vmax) - $limits(vmin)} r] != 0 } {
122            return 0.0
123        }           
124        absval [expr {($x * $r) + $limits(vmin)}]
125    }
126    private method HandleEvent { option args } {
127        switch -- $option {
128            enter {
129                set _activeMotion 1
130                activate yes
131                $_canvas raise $_tick
132            }
133            leave {
134                set _activeMotion 0
135                activate no
136            }
137            start {
138                $_canvas raise $_tick
139                set _activePress 1
140                activate yes
141                $_canvas itemconfigure limits -state hidden
142            }
143            update {
144                set w [winfo width $_canvas]
145                set x [lindex $args 0]
146                relval [expr {double($x-10)/($w-20)}]
147                $_nvobj overmarker $this $x
148                $_nvobj updatetransferfuncs
149            }
150            end {
151                set x [lindex $args 0]
152                if { ![$_nvobj rmdupmarker $this $x]} {
153                    eval HandleEvent update $args
154                }
155                set _activePress 0
156                activate no
157                $_canvas itemconfigure limits -state normal
158            }
159            default {
160                error "bad option \"$option\": should be start, update, end"
161            }
162        }
163    }
164}
Note: See TracBrowser for help on using the repository browser.