source: branches/1.3/gui/scripts/isomarker.tcl @ 4215

Last change on this file since 4215 was 3362, checked in by ldelgass, 12 years ago

Merge nanovis2 branch to trunk

File size: 5.8 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2
3# ----------------------------------------------------------------------
4#  COMPONENT: nanovisviewer::isomarker - Marker for 3D volume rendering
5#
6#  This widget performs volume rendering on 3D scalar/vector datasets.
7#  It connects to the Nanovis server running on a rendering farm,
8#  transmits data, and displays the results.
9# ======================================================================
10#  AUTHOR:  Michael McLennan, Purdue University
11#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
12#
13#  See the file "license.terms" for information on usage and
14#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15# ======================================================================
16package require Itk
17package require BLT
18package require Img
19
20itcl::class Rappture::IsoMarker {
21    private variable _value     0.0;    # Absolute value of marker.
22    private variable _label     ""
23    private variable _tick      ""
24    private variable _canvas    ""
25    private variable _nvobj     "";     # Parent nanovis object.
26    private variable _tf        "";     # Transfer function that this marker is
27                                        # associated with.
28    private variable _activeMotion   0
29    private variable _activePress    0
30    private common   _normalIcon [Rappture::icon nvlegendmark]
31    private common   _activeIcon [Rappture::icon nvlegendmark2]
32
33    constructor {c obj tf args} {
34        set _canvas $c
35        set _nvobj $obj
36        set _tf $tf
37        set w [winfo width $_canvas]
38        set h [winfo height $_canvas]
39        set _tick [$c create image 0 $h \
40                -image $_normalIcon -anchor s \
41                -tags "$this $obj" -state hidden]
42        set _label [$c create text 0 $h \
43                -anchor n -fill white -font "Helvetica 8" \
44                -tags "$this $obj" -state hidden]
45        $c bind $_tick <Enter> [itcl::code $this HandleEvent "enter"]
46        $c bind $_tick <Leave> [itcl::code $this HandleEvent "leave"]
47        $c bind $_tick <ButtonPress-1> \
48            [itcl::code $this HandleEvent "start" %x %y]
49        $c bind $_tick <B1-Motion> \
50            [itcl::code $this HandleEvent "update" %x %y]
51        $c bind $_tick <ButtonRelease-1> \
52            [itcl::code $this HandleEvent "end" %x %y]
53    }
54    destructor {
55        $_canvas delete $this
56    }
57    public method transferfunc {} {
58        return $_tf
59    }
60    public method activate { bool } {
61        if  { $bool || $_activePress || $_activeMotion } {
62            $_canvas itemconfigure $_label -state normal
63            $_canvas itemconfigure $_tick -image $_activeIcon
64        } else {
65            $_canvas itemconfigure $_label -state hidden
66            $_canvas itemconfigure $_tick -image $_normalIcon
67        }
68    }
69    public method visible { bool } {
70        if { $bool } {
71            absval $_value
72            $_canvas itemconfigure $_tick -state normal
73            $_canvas raise $_tick
74        } else {
75            $_canvas itemconfigure $_tick -state hidden
76        }
77    }
78    public method screenpos { } {
79        set x [relval]
80        if { $x < 0.0 } {
81            set x 0.0
82        } elseif { $x > 1.0 } {
83            set x 1.0
84        }
85        set low 10
86        set w [winfo width $_canvas]
87        set high [expr {$w  - 10}]
88        set x [expr {round($x*($high - $low) + $low)}]
89        return $x
90    }
91    public method absval { {x "-get"} } {
92        if { $x != "-get" } {
93            set _value $x
94            set y 31
95            $_canvas itemconfigure $_label -text [format %.2g $_value]
96            set x [screenpos]
97            $_canvas coords $_tick $x [expr {$y+3}]
98            $_canvas coords $_label $x [expr {$y+5}]
99        }
100        return $_value
101    }
102    public method relval  { {x "-get"} } {
103        if { $x == "-get" } {
104            array set limits [$_nvobj limits $_tf]
105            if { $limits(vmax) == $limits(vmin) } {
106                if { $limits(vmax) == 0.0 } {
107                    set limits(vmin) 0.0
108                    set limits(vmax) 1.0
109                } else {
110                    set limits(vmax) [expr $limits(vmin) + 1.0]
111                }
112            }
113            return [expr {($_value-$limits(vmin))/
114                          ($limits(vmax) - $limits(vmin))}]
115        }
116        array set limits [$_nvobj limits $_tf]
117        if { $limits(vmax) == $limits(vmin) } {
118            set limits(vmin) 0.0
119            set limits(vmax) 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.