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

Last change on this file since 5520 was 5259, checked in by ldelgass, 10 years ago

whitespace

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