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

Last change on this file since 4288 was 4166, checked in by ldelgass, 11 years ago

More transfer function fixes: Fix moving markers in flowvisviewer (was broken
in r3930), fix marker label colors in nanovis. Note: there is probably a better
way to propagate the foreground color to the transfer function editor widget.

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    private method EnterTick {}
33    private method LeaveTick {}
34    private method StartDrag { x y }
35    private method ContinueDrag { x y }
36    private method StopDrag { x y }
37
38    constructor {c obj tf args} {}
39    destructor {}
40    public method transferfunc {}
41    public method activate { bool }
42    public method visible { bool }
43    public method screenpos {}
44    public method absval { {x "-get"} }
45    public method relval  { {x "-get"} }
46}
47
48itcl::body Rappture::IsoMarker::constructor {c obj tf args} {
49    set _canvas $c
50    set _nvobj $obj
51    set _tf $tf
52    set w [winfo width $_canvas]
53    set h [winfo height $_canvas]
54    set _tick [$c create image 0 $h \
55                   -image $_normalIcon -anchor s \
56                   -tags "tick $this $obj" -state hidden]
57    set _label [$c create text 0 $h \
58                    -anchor n -fill white -font "Helvetica 8" \
59                    -tags "labels $this $obj" -state hidden]
60    $c bind $_tick <Enter>           [itcl::code $this EnterTick]
61    $c bind $_tick <Leave>           [itcl::code $this LeaveTick]
62    $c bind $_tick <ButtonPress-1>   [itcl::code $this StartDrag %x %y]
63    $c bind $_tick <B1-Motion>       [itcl::code $this ContinueDrag %x %y]
64    $c bind $_tick <ButtonRelease-1> [itcl::code $this StopDrag %x %y]
65}
66
67itcl::body Rappture::IsoMarker::destructor {} {
68    $_canvas delete $this
69}
70
71itcl::body Rappture::IsoMarker::transferfunc {} {
72    return $_tf
73}
74
75itcl::body Rappture::IsoMarker::activate { bool } {
76    if  { $bool || $_activePress || $_activeMotion } {
77        $_canvas itemconfigure $_label -state normal
78        $_canvas itemconfigure $_tick -image $_activeIcon
79        $_canvas itemconfigure title -state hidden
80    } else {
81        $_canvas itemconfigure $_label -state hidden
82        $_canvas itemconfigure $_tick -image $_normalIcon
83        $_canvas itemconfigure title -state normal
84    }
85}
86
87itcl::body Rappture::IsoMarker::visible { bool } {
88    if { $bool } {
89        absval $_value
90        $_canvas itemconfigure $_tick -state normal
91        $_canvas raise $_tick
92    } else {
93        $_canvas itemconfigure $_tick -state hidden
94    }
95}
96
97itcl::body Rappture::IsoMarker::screenpos { } {
98    set x [relval]
99    if { $x < 0.0 } {
100        set x 0.0
101    } elseif { $x > 1.0 } {
102        set x 1.0
103    }
104    set low 10
105    set w [winfo width $_canvas]
106    set high [expr {$w  - 10}]
107    set x [expr {round($x*($high - $low) + $low)}]
108    return $x
109}
110
111itcl::body Rappture::IsoMarker::absval { {x "-get"} } {
112    if { $x != "-get" } {
113        set _value $x
114        set y 31
115        $_canvas itemconfigure $_label -text [format %.2g $_value]
116        set x [screenpos]
117        $_canvas coords $_tick $x [expr {$y+3}]
118        $_canvas coords $_label $x [expr {$y+5}]
119    }
120    return $_value
121}
122
123itcl::body Rappture::IsoMarker::relval  { {x "-get"} } {
124    foreach {min max} [$_nvobj limits $_tf] break
125    if { $x == "-get" } {
126        if { $max == $min } {
127            if { $max == 0.0 } {
128                set min 0.0
129                set max 1.0
130            } else {
131                set max [expr $min + 1.0]
132            }
133        }
134        return [expr {($_value - $min) / ($max - $min)}]
135    }
136    if { $max == $min } {
137        set min 0.0
138        set max 1.0
139    }
140    if { [catch {expr $max - $min} r] != 0 } {
141        return 0.0
142    }           
143    absval [expr {($x * $r) + $min}]
144}
145
146itcl::body Rappture::IsoMarker::EnterTick {} {
147    set _activeMotion 1
148    activate yes
149    $_canvas raise $_tick
150}
151
152itcl::body Rappture::IsoMarker::LeaveTick {} {
153    set _activeMotion 0
154    activate no
155}
156
157itcl::body Rappture::IsoMarker::StartDrag { x y } {
158    $_canvas raise $_tick
159    set _activePress 1
160    activate yes
161    $_canvas itemconfigure limits -state hidden
162    $_canvas itemconfigure title -state hidden
163}
164
165itcl::body Rappture::IsoMarker::StopDrag { x y } {
166    if { ![$_nvobj removeDuplicateMarker $this $x]} {
167        ContinueDrag $x $y
168    }
169    set _activePress 0
170    activate no
171    $_canvas itemconfigure limits -state normal
172    $_canvas itemconfigure title -state normal
173}
174
175itcl::body Rappture::IsoMarker::ContinueDrag { x y } {
176    set w [winfo width $_canvas]
177    relval [expr {double($x-10)/($w-20)}]
178    $_nvobj overMarker $this $x
179    $_nvobj updateTransferFunctions
180    $_canvas raise $_tick
181    set _activePress 1
182    activate yes
183    $_canvas itemconfigure limits -state hidden
184    $_canvas itemconfigure title -state hidden
185}
186
Note: See TracBrowser for help on using the repository browser.