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

Last change on this file since 1399 was 1376, checked in by gah, 16 years ago
File size: 4.6 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::NanovisViewer::IsoMarker {
20    private variable value_     "";     # 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 active_motion_   0
28    private variable active_press_    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 || $active_press_ || $active_motion_ } {
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(max) == $limits(min) } {
105                if { $limits(max) == 0.0 } {
106                    set limits(min) 0.0
107                    set limits(max) 1.0
108                } else {
109                    set limits(max) [expr $limits(min) + 1.0]
110                }
111            }
112            return [expr {($value_-$limits(min))/($limits(max) - $limits(min))}]
113        }
114        array set limits [$nvobj_ limits $tf_]
115        if { $limits(max) == $limits(min) } {
116            set limits(min) 0.0
117            set limits(max) 1.0
118        }
119        set r [expr $limits(max) - $limits(min)]
120        absval [expr {($x * $r) + $limits(min)}]
121    }
122    private method HandleEvent { option args } {
123        switch -- $option {
124            enter {
125                set active_motion_ 1
126                activate yes
127                $canvas_ raise $tick_
128            }
129            leave {
130                set active_motion_ 0
131                activate no
132            }
133            start {
134                $canvas_ raise $tick_
135                set active_press_ 1
136                activate yes
137                $canvas_ itemconfigure limits -state hidden
138            }
139            update {
140                set w [winfo width $canvas_]
141                set x [lindex $args 0]
142                relval [expr {double($x-10)/($w-20)}]
143                $nvobj_ overmarker $this $x
144                $nvobj_ updatetransferfuncs
145            }
146            end {
147                set x [lindex $args 0]
148                if { ![$nvobj_ rmdupmarker $this $x]} {
149                    eval HandleEvent update $args
150                }
151                set active_press_ 0
152                activate no
153                $canvas_ itemconfigure limits -state normal
154            }
155            default {
156                error "bad option \"$option\": should be start, update, end"
157            }
158        }
159    }
160}
Note: See TracBrowser for help on using the repository browser.