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

Last change on this file since 1247 was 1247, checked in by gah, 16 years ago

Fix for interrupted nanovis session

File size: 4.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::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 GetTransferFunction {} {
57        return $tf_
58    }
59    public method GetAbsoluteValue {} {
60        return $value_
61    }
62    public method GetRelativeValue {} {
63        array set limits [$nvobj_ GetLimits $tf_]
64        if { $limits(max) == $limits(min) } {
65            if { $limits(max) == 0.0 } {
66                set limits(min) 0.0
67                set limits(max) 1.0
68            } else {
69                set limits(max) [expr $limits(min) + 1.0]
70            }
71        }
72        return [expr {($value_-$limits(min))/($limits(max) - $limits(min))}]
73    }
74    public method Activate { bool } {
75        if  { $bool || $active_press_ || $active_motion_ } {
76            $canvas_ itemconfigure $label_ -state normal
77            $canvas_ itemconfigure $tick_ -image $activeIcon_
78        } else {
79            $canvas_ itemconfigure $label_ -state hidden
80            $canvas_ itemconfigure $tick_ -image $normalIcon_
81        }
82    }
83    public method Show {} {
84        SetAbsoluteValue $value_
85        $canvas_ itemconfigure $tick_ -state normal
86        $canvas_ raise $tick_
87    }
88    public method Hide {} {
89        $canvas_ itemconfigure $tick_ -state hidden
90    }
91    public method GetScreenPosition { } {
92        set x [GetRelativeValue]
93        if { $x < 0.0 } {
94            set x 0.0
95        } elseif { $x > 1.0 } {
96            set x 1.0
97        }
98        set low 10
99        set w [winfo width $canvas_]
100        set high [expr {$w  - 10}]
101        set x [expr {round($x*($high - $low) + $low)}]
102        return $x
103    }
104    public method SetAbsoluteValue { x } {
105        set value_ $x
106        set y 31
107        $canvas_ itemconfigure $label_ -text [format %.2g $value_]
108        set x [GetScreenPosition]
109        $canvas_ coords $tick_ $x [expr {$y+3}]
110        $canvas_ coords $label_ $x [expr {$y+5}]
111    }
112    public method SetRelativeValue { x } {
113        array set limits [$nvobj_ GetLimits $tf_]
114        if { $limits(max) == $limits(min) } {
115            set limits(min) 0.0
116            set limits(max) 1.0
117        }
118        set r [expr $limits(max) - $limits(min)]
119        SetAbsoluteValue [expr {($x * $r) + $limits(min)}]
120    }
121    public method HandleEvent { option args } {
122        switch -- $option {
123            enter {
124                set active_motion_ 1
125                Activate yes
126                $canvas_ raise $tick_
127            }
128            leave {
129                set active_motion_ 0
130                Activate no
131            }
132            start {
133                $canvas_ raise $tick_
134                set active_press_ 1
135                Activate yes
136                $canvas_ itemconfigure limits -state hidden
137            }
138            update {
139                set w [winfo width $canvas_]
140                set x [lindex $args 0]
141                SetRelativeValue [expr {double($x-10)/($w-20)}]
142                $nvobj_ OverIsoMarker $this $x
143                $nvobj_ UpdateTransferFunctions
144            }
145            end {
146                set x [lindex $args 0]
147                if { ![$nvobj_ RemoveDuplicateIsoMarker $this $x]} {
148                    eval HandleEvent update $args
149                }
150                set active_press_ 0
151                Activate no
152                $canvas_ itemconfigure limits -state normal
153            }
154            default {
155                error "bad option \"$option\": should be start, update, end"
156            }
157        }
158    }
159}
Note: See TracBrowser for help on using the repository browser.