source: trunk/gui/scripts/deviceEditor.tcl @ 168

Last change on this file since 168 was 168, checked in by mmc, 16 years ago
  • Fixed the license terms to comply with the official open source license from Purdue's OTC office.
  • Fixed the scroller to handle scrollbars properly. They weren't always popping up when needed. Sometimes you had to scroll a little first. Better now.
  • Fixed the DeviceEditor? to pack its internal widgets better, so images within a DeviceViewer1D structure can change size and will show up properly.
  • Fixed the analyzer to take down the progress bar properly when there's an error during execution.
  • Fixed the Rappture::exec command to initialize execctl properly, in case there's an error during execution.
File size: 5.2 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: deviceEditor - general-purpose device editor
3#
4#  This widget takes a <structure> description and chooses a specific
5#  editor appropriate for the contents of the structure.  If the
6#  <structure> contains a molecule, then it chooses a MoleculeViewer.
7#  If it contains a 1D device, then it chooses a deviceViewer1D.
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
16
17option add *DeviceEditor.autoCleanUp yes widgetDefault
18
19itcl::class Rappture::DeviceEditor {
20    inherit itk::Widget Rappture::ControlOwner
21
22    itk_option define -autocleanup autoCleanUp AutoCleanUp 1
23
24    constructor {owner args} {
25        Rappture::ControlOwner::constructor $owner
26    } { # defined below }
27
28    public method value {args}
29
30    protected method _redraw {}
31    protected method _type {xmlobj}
32
33    private variable _current ""  ;# active device editor
34}
35                                                                               
36itk::usual DeviceEditor {
37}
38
39# ----------------------------------------------------------------------
40# CONSTRUCTOR
41# ----------------------------------------------------------------------
42itcl::body Rappture::DeviceEditor::constructor {owner args} {
43    itk_component add top {
44        frame $itk_interior.top
45    }
46    pack $itk_component(top) -fill x
47
48    eval itk_initialize $args
49}
50
51
52# ----------------------------------------------------------------------
53# USAGE: value ?-check? ?<newval>?
54#
55# Clients use this to query/set the value for this widget.  With
56# no args, it returns the current value for the widget.  If the
57# <newval> is specified, it sets the value of the widget and
58# sends a <<Value>> event.  If the -check flag is included, the
59# new value is not actually applied, but just checked for correctness.
60# ----------------------------------------------------------------------
61itcl::body Rappture::DeviceEditor::value {args} {
62    set onlycheck 0
63    set i [lsearch -exact $args -check]
64    if {$i >= 0} {
65        set onlycheck 1
66        set args [lreplace $args $i $i]
67    }
68
69    if {[llength $args] == 1} {
70        if {$_xmlobj != ""} {
71            if {$itk_option(-autocleanup)} {
72                # delete any existing object
73                itcl::delete object $_xmlobj
74            }
75            set _xmlobj ""
76        }
77
78        set newval [lindex $args 0]
79        if {$newval != ""} {
80            if {$onlycheck} {
81                return
82            }
83            if {![Rappture::library isvalid $newval]} {
84                error "bad value \"$newval\": should be Rappture::Library"
85            }
86            set _xmlobj $newval
87        }
88        _redraw
89        event generate $itk_component(hull) <<Value>>
90
91    } elseif {[llength $args] == 0} {
92        sync  ;# querying -- must sync controls with the value
93    } else {
94        error "wrong # args: should be \"value ?-check? ?newval?\""
95    }
96    return $_xmlobj
97}
98
99# ----------------------------------------------------------------------
100# USAGE: _redraw
101#
102# Used internally to load new device data into the appropriate
103# editor.  If the editor needs to be created, it is created and
104# activated within this widget.  Then, the data is loaded into
105# the editor.
106# ----------------------------------------------------------------------
107itcl::body Rappture::DeviceEditor::_redraw {} {
108    if {$_current != ""} {
109        $_current configure -device ""
110        set _current ""
111    }
112    switch -- [_type $_xmlobj] {
113        molecule {
114            if {![winfo exists $itk_component(hull).mol]} {
115                catch {destroy $itk_component(hull).dev}
116                Rappture::MoleculeViewer $itk_component(hull).mol $this
117                pack $itk_component(hull).mol -expand yes -fill both
118            }
119            $itk_component(hull).mol configure -device $_xmlobj
120
121            set _current $itk_component(hull).mol
122        }
123        device1D {
124            if {![winfo exists $itk_component(hull).dev]} {
125                catch {destroy $itk_component(hull).mol}
126                Rappture::DeviceViewer1D $itk_component(hull).dev $this
127                pack $itk_component(hull).dev -expand yes -fill both
128            }
129            $itk_component(hull).dev configure -device $_xmlobj
130
131            set _current $itk_component(hull).dev
132        }
133    }
134}
135
136# ----------------------------------------------------------------------
137# USAGE: _type <xmlobj>
138#
139# Used internally to determine the type of the device data stored
140# within the <xmlobj>.  Returns a name such as "molecule" or
141# "device1D" indicating the type of editor that should be used to
142# display the data.
143# ----------------------------------------------------------------------
144itcl::body Rappture::DeviceEditor::_type {xmlobj} {
145    if {$xmlobj == ""} {
146        return ""
147    }
148    if {[llength [$xmlobj children -type molecule components]] > 0} {
149        return "molecule"
150    }
151    return "device1D"
152}
Note: See TracBrowser for help on using the repository browser.