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

Last change on this file since 1829 was 1646, checked in by gah, 14 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
17
18itcl::class Rappture::IsoMarker {
19    private variable value_     "";     # Absolute value of marker.
20    private variable label_     ""
21    private variable tick_      ""
22    private variable canvas_    ""
23    private variable nvobj_     "";     # Parent nanovis object.
24    private variable tf_        "";     # Transfer function that this marker is
25                                        # associated with.
26    private variable active_motion_   0
27    private variable active_press_    0
28    private common   normalIcon_ [Rappture::icon nvlegendmark]
29    private common   activeIcon_ [Rappture::icon nvlegendmark2]
30
31    constructor {c obj tf args} {
32        set canvas_ $c
33        set nvobj_ $obj
34        set tf_ $tf
35        set w [winfo width $canvas_]
36        set h [winfo height $canvas_]
37        set tick_ [$c create image 0 $h \
38                -image $normalIcon_ -anchor s \
39                -tags "$this $obj" -state hidden]
40        set label_ [$c create text 0 $h \
41                -anchor n -fill white -font "Helvetica 8" \
42                -tags "$this $obj" -state hidden]
43        $c bind $tick_ <Enter> [itcl::code $this HandleEvent "enter"]
44        $c bind $tick_ <Leave> [itcl::code $this HandleEvent "leave"]
45        $c bind $tick_ <ButtonPress-1> \
46            [itcl::code $this HandleEvent "start" %x %y]
47        $c bind $tick_ <B1-Motion> \
48            [itcl::code $this HandleEvent "update" %x %y]
49        $c bind $tick_ <ButtonRelease-1> \
50            [itcl::code $this HandleEvent "end" %x %y]
51    }
52    destructor {
53        $canvas_ delete $this
54    }
55    public method transferfunc {} {
56        return $tf_
57    }
58    public method activate { bool } {
59        if  { $bool || $active_press_ || $active_motion_ } {
60            $canvas_ itemconfigure $label_ -state normal
61            $canvas_ itemconfigure $tick_ -image $activeIcon_
62        } else {
63            $canvas_ itemconfigure $label_ -state hidden
64            $canvas_ itemconfigure $tick_ -image $normalIcon_
65        }
66    }
67    public method visible { bool } {
68        if { $bool } {
69            absval $value_
70            $canvas_ itemconfigure $tick_ -state normal
71            $canvas_ raise $tick_
72        } else {
73            $canvas_ itemconfigure $tick_ -state hidden
74        }
75    }
76    public method screenpos { } {
77        set x [relval]
78        if { $x < 0.0 } {
79            set x 0.0
80        } elseif { $x > 1.0 } {
81            set x 1.0
82        }
83        set low 10
84        set w [winfo width $canvas_]
85        set high [expr {$w  - 10}]
86        set x [expr {round($x*($high - $low) + $low)}]
87        return $x
88    }
89    public method absval { {x "-get"} } {
90        if { $x != "-get" } {
91            set value_ $x
92            set y 31
93            $canvas_ itemconfigure $label_ -text [format %.2g $value_]
94            set x [screenpos]
95            $canvas_ coords $tick_ $x [expr {$y+3}]
96            $canvas_ coords $label_ $x [expr {$y+5}]
97        }
98        return $value_
99    }
100    public method relval  { {x "-get"} } {
101        if { $x == "-get" } {
102            array set limits [$nvobj_ limits $tf_]
103            if { $limits(vmax) == $limits(vmin) } {
104                if { $limits(vmax) == 0.0 } {
105                    set limits(vmin) 0.0
106                    set limits(vmax) 1.0
107                } else {
108                    set limits(vmax) [expr $limits(vmin) + 1.0]
109                }
110            }
111            return [expr {($value_-$limits(vmin))/
112                          ($limits(vmax) - $limits(vmin))}]
113        }
114        array set limits [$nvobj_ limits $tf_]
115        if { $limits(vmax) == $limits(vmin) } {
116            set limits(min) 0.0
117            set limits(max) 1.0
118        }
119        set r [expr $limits(vmax) - $limits(vmin)]
120        absval [expr {($x * $r) + $limits(vmin)}]
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.