Changeset 5640 for trunk/gui


Ignore:
Timestamp:
May 31, 2015 4:36:54 PM (9 years ago)
Author:
ldelgass
Message:

style/whitespace

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/transferfunctioneditor.tcl

    r5562 r5640  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*-
    2 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    32# ----------------------------------------------------------------------
    4 #  COMPONENT: transferfunctioneditor - Rudimentary editor for 3D volume 
     3#  COMPONENT: transferfunctioneditor - Rudimentary editor for 3D volume
    54#                                      transfer functions
    65#
    7 #  This class is used to modify transfer functions used in volume rendering 
     6#  This class is used to modify transfer functions used in volume rendering
    87#  on 3D scalar/vector datasets.
    98#
     
    2019
    2120itcl::class Rappture::TransferFunctionEditor {
    22     private variable _nextId 0;         # Used to create unique marker names
    23     private variable _values;           # Relative values for each marker.
    24     private variable _limits;           # Over limits of transfer function.
    25     private variable _labels;           # Label id for each marker.
    26     private variable _ticks;            # Tick id for each marker.
    27     private variable _canvas    ""
    28     private variable _name "";          # Name of transfer function.
    29     private variable _activeMotion   0
    30     private variable _activePress    0
    31     private variable _id2name
    32     private common   _normalIcon [Rappture::icon nvlegendmark]
    33     private common   _activeIcon [Rappture::icon nvlegendmark2]
    34     public variable command ""
    35 
    36     private method SetAbsoluteValue { name x }
    37     private method GetAbsoluteValue { name }
    38     private method ContinueDrag { name x y }
    39     private method EnterTick { name }
    40     private method GetOverlappingMarkers { x y }
    41     private method GetScreenPosition { name }
    42     private method LeaveTick { name }
    43     private method SetRelativeValue  { name x }
    44     private method GetRelativeValue  { name }
    45     private method RemoveDuplicateMarkers {name x y}
    46     private method SetScreenPosition { name }
    47     private method SetVisibility { name bool }
    48     private method StartDrag { name x y }
    49     private method StopDrag { name x y }
    50     private method Activate { name }
    51     private method Deactivate { name }
    52     private method UpdateViewer {}
    53 
    5421    constructor {c name args} {}
    55     destructor {} 
     22    destructor {}
    5623    public method limits { min max }
    5724    public method names {}
     
    6532    public method hideMarkers { {list {}} }
    6633    public method showMarkers { {limits {}} }
    67 }
    68 
    69 itcl::body Rappture::TransferFunctionEditor::constructor {c name args} {
     34
     35    public variable command ""
     36
     37    private method SetAbsoluteValue { name x }
     38    private method GetAbsoluteValue { name }
     39    private method ContinueDrag { name x y }
     40    private method EnterTick { name }
     41    private method GetOverlappingMarkers { x y }
     42    private method GetScreenPosition { name }
     43    private method LeaveTick { name }
     44    private method SetRelativeValue  { name x }
     45    private method GetRelativeValue  { name }
     46    private method RemoveDuplicateMarkers {name x y}
     47    private method SetScreenPosition { name }
     48    private method SetVisibility { name bool }
     49    private method StartDrag { name x y }
     50    private method StopDrag { name x y }
     51    private method Activate { name }
     52    private method Deactivate { name }
     53    private method UpdateViewer {}
     54
     55    private variable _nextId 0;         # Used to create unique marker names
     56    private variable _values;           # Relative values for each marker.
     57    private variable _limits;           # Over limits of transfer function.
     58    private variable _labels;           # Label id for each marker.
     59    private variable _ticks;            # Tick id for each marker.
     60    private variable _canvas ""
     61    private variable _name "";                # Name of transfer function.
     62    private variable _activeMotion 0
     63    private variable _activePress 0
     64    private variable _id2name
     65
     66    private common _normalIcon [Rappture::icon nvlegendmark]
     67    private common _activeIcon [Rappture::icon nvlegendmark2]
     68}
     69
     70itcl::body Rappture::TransferFunctionEditor::constructor {c name args} {
    7071    set _canvas $c
    7172    set _name $name
    72     set _limits [list 0.0 1.0] 
     73    set _limits [list 0.0 1.0]
    7374    eval configure $args
    7475}
    7576
    76 itcl::body Rappture::TransferFunctionEditor::limits { min max } { 
     77itcl::body Rappture::TransferFunctionEditor::limits { min max } {
    7778    set _limits [list $min $max]
    7879}
    7980
    80 itcl::body Rappture::TransferFunctionEditor::names {} { 
     81itcl::body Rappture::TransferFunctionEditor::names {} {
    8182    return [lsort [array names _values]]
    8283}
    8384
    84 itcl::body Rappture::TransferFunctionEditor::values {} { 
     85itcl::body Rappture::TransferFunctionEditor::values {} {
    8586    set list {}
    8687    foreach name [array names _ticks] {
    87         lappend list [GetRelativeValue $name]
     88        lappend list [GetRelativeValue $name]
    8889    }
    8990    return [lsort -real $list]
    9091}
    9192
    92 itcl::body Rappture::TransferFunctionEditor::absoluteValues {} { 
     93itcl::body Rappture::TransferFunctionEditor::absoluteValues {} {
    9394    set list {}
    9495    foreach name [array names _values] {
    95         lappend list [GetAbsoluteValue $name]
     96        lappend list [GetAbsoluteValue $name]
    9697    }
    9798    return $list
    9899}
    99100
    100 itcl::body Rappture::TransferFunctionEditor::deleteMarker { x y } { 
     101itcl::body Rappture::TransferFunctionEditor::deleteMarker { x y } {
    101102    foreach marker [GetOverlappingMarkers $x $y] {
    102103        $_canvas delete $_ticks($marker)
     
    110111}
    111112
    112 itcl::body Rappture::TransferFunctionEditor::newMarker { x y state } { 
     113itcl::body Rappture::TransferFunctionEditor::newMarker { x y state } {
    113114    foreach id [$_canvas find overlapping \
    114115                    [expr $x-5] [expr $y-5] [expr $x+5] [expr $y+5]] {
    115         if { [info exists _id2name($id)] } {
     116        if { [info exists _id2name($id)] } {
    116117            puts stderr "Too close to existing marker"
    117             return;                     # Too close to existing marker
    118         }
     118            return;                     # Too close to existing marker
     119        }
    119120    }
    120121    set name "tick[incr _nextId]"
     
    132133    $_canvas bind $_ticks($name) <Leave> [itcl::code $this LeaveTick $name]
    133134    $_canvas bind $_ticks($name) <ButtonPress-1> \
    134         [itcl::code $this StartDrag $name %x %y]
     135        [itcl::code $this StartDrag $name %x %y]
    135136    $_canvas bind $_ticks($name) <B1-Motion> \
    136         [itcl::code $this ContinueDrag $name %x %y]
     137        [itcl::code $this ContinueDrag $name %x %y]
    137138    $_canvas bind $_ticks($name) <ButtonRelease-1> \
    138         [itcl::code $this StopDrag $name %x %y]
     139        [itcl::code $this StopDrag $name %x %y]
    139140
    140141    SetRelativeValue $name [expr {double($x-10)/($w-20)}]
     
    182183}
    183184
    184 itcl::body Rappture::TransferFunctionEditor::GetScreenPosition { name } { 
     185itcl::body Rappture::TransferFunctionEditor::GetScreenPosition { name } {
    185186    set x [GetRelativeValue $name]
    186187    if { $x < 0.0 } {
    187188        set x 0.0
    188189    } elseif { $x > 1.0 } {
    189         set x 1.0 
    190     }
    191     set low 10 
     190        set x 1.0
     191    }
     192    set low 10
    192193    set w [winfo width $_canvas]
    193194    set high [expr {$w  - 10}]
     
    196197}
    197198
    198 itcl::body Rappture::TransferFunctionEditor::SetScreenPosition { name } { 
     199itcl::body Rappture::TransferFunctionEditor::SetScreenPosition { name } {
    199200    set value $_values($name)
    200201    set x [GetScreenPosition $name]
     
    250251
    251252itcl::body Rappture::TransferFunctionEditor::StartDrag { name x y } {
    252     $_canvas raise $_ticks($name) 
     253    $_canvas raise $_ticks($name)
    253254    set _activePress 1
    254255    Activate $name
     
    258259
    259260itcl::body Rappture::TransferFunctionEditor::StopDrag { name x y } {
    260     ContinueDrag $name $x $y 
     261    ContinueDrag $name $x $y
    261262    RemoveDuplicateMarkers $name $x $y
    262263    set _activePress 0
     
    280281    set list {}
    281282    foreach id [$_canvas find overlapping $x $y $x $y] {
    282         if { [info exists _id2name($id)] } {
    283             lappend list $_id2name($id)
    284         }
     283        if { [info exists _id2name($id)] } {
     284            lappend list $_id2name($id)
     285        }
    285286    }
    286287    return $list
     
    289290itcl::body Rappture::TransferFunctionEditor::hideMarkers { {list {}} } {
    290291    if { $list == "" } {
    291         set list [array names _values]
     292        set list [array names _values]
    292293    }
    293294    foreach name $list {
    294         SetVisibility $name 0
     295        SetVisibility $name 0
    295296    }
    296297}
     
    298299itcl::body Rappture::TransferFunctionEditor::showMarkers { {limits {}} } {
    299300    if { $limits != "" } {
    300         set _limits $limits
    301         foreach name [array names _values] {
    302             SetScreenPosition $name
    303         }
     301        set _limits $limits
     302        foreach name [array names _values] {
     303            SetScreenPosition $name
     304        }
    304305    }
    305306    foreach name [array names _values] {
    306         SetVisibility $name 1
     307        SetVisibility $name 1
    307308    }
    308309}
     
    310311itcl::body Rappture::TransferFunctionEditor::RemoveDuplicateMarkers {name x y} {
    311312    foreach marker [GetOverlappingMarkers $x $y] {
    312         if { $marker != $name } {
    313             Activate $marker 
     313        if { $marker != $name } {
     314            Activate $marker
    314315            set markerx [GetScreenPosition $marker]
    315316            if { ($x < ($markerx-3)) || ($x > ($markerx+3)) } {
    316317                continue
    317318            }
    318             $_canvas delete $_ticks($marker)
    319             $_canvas delete $_labels($marker)
    320             array unset _ticks $marker
    321             array unset _labels $marker
    322             array unset _values $marker
     319            $_canvas delete $_ticks($marker)
     320            $_canvas delete $_labels($marker)
     321            array unset _ticks $marker
     322            array unset _labels $marker
     323            array unset _values $marker
    323324            bell
    324         }
     325        }
    325326    }
    326327}
     
    328329itcl::body Rappture::TransferFunctionEditor::addMarkers { values } {
    329330    foreach value $values {
    330         set name [newMarker 0 0 hidden]
    331         SetRelativeValue $name $value
     331        set name [newMarker 0 0 hidden]
     332        SetRelativeValue $name $value
    332333    }
    333334}
     
    335336itcl::body Rappture::TransferFunctionEditor::removeMarkers { names } {
    336337    if { $names == "" } {
    337         set names [array names _values]
     338        set names [array names _values]
    338339    }
    339340    foreach name $names {
    340         $_canvas delete $_ticks($name)
    341         $_canvas delete $_labels($name)
    342         array unset _ticks $name
    343         array unset _labels $name
    344         array unset _values $name
     341        $_canvas delete $_ticks($name)
     342        $_canvas delete $_labels($name)
     343        array unset _ticks $name
     344        array unset _labels $name
     345        array unset _values $name
    345346    }
    346347    UpdateViewer
     
    351352    # now that a marker position has changed.
    352353    if { $command != "" } {
    353         eval uplevel \#0 $command
    354     }
    355 }
     354        eval uplevel \#0 $command
     355    }
     356}
Note: See TracChangeset for help on using the changeset viewer.