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

Last change on this file since 6480 was 5639, checked in by ldelgass, 9 years ago

code style

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