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

Last change on this file since 11 was 11, checked in by mmc, 19 years ago

Major reorganization of the entire package. The config.xml file
is now irrelevant. All the action is in the tool.xml file. The
main program now organizes all input into 1) side-by-side pages,
2) input/result (wizard-style) pages, or 3) a series of wizard-
style pages. The <input> can have <phase> parts representing
the various pages.

Added a new ContourResult? widget based on Swaroop's vtk plotting
code.

Also, added easymesh and showmesh to the "tools" directory.
We need these for Eric Polizzi's code.

File size: 5.0 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
11#  Purdue Research Foundation, West Lafayette, IN
12# ======================================================================
13package require Itk
14
15option add *DeviceEditor.width 5i widgetDefault
16option add *DeviceEditor.height 5i widgetDefault
17
18itcl::class Rappture::DeviceEditor {
19    inherit itk::Widget
20
21    constructor {tool args} { # defined below }
22
23    public method value {args}
24
25    protected method _redraw {}
26    protected method _type {xmlobj}
27
28    private variable _tool ""        ;# tool containing this editor
29    private variable _xmlobj ""      ;# XML <structure> object
30}
31                                                                               
32itk::usual DeviceEditor {
33}
34
35# ----------------------------------------------------------------------
36# CONSTRUCTOR
37# ----------------------------------------------------------------------
38itcl::body Rappture::DeviceEditor::constructor {tool args} {
39    set _tool $tool
40
41    itk_option add hull.width hull.height
42    pack propagate $itk_component(hull) no
43
44    itk_component add top {
45        frame $itk_interior.top
46    }
47    pack $itk_component(top) -fill x
48
49    itk_component add editors {
50        Rappture::Notebook $itk_interior.editors
51    }
52    pack $itk_component(editors) -expand yes -fill both
53
54    eval itk_initialize $args
55}
56
57
58# ----------------------------------------------------------------------
59# USAGE: value ?-check? ?<newval>?
60#
61# Clients use this to query/set the value for this widget.  With
62# no args, it returns the current value for the widget.  If the
63# <newval> is specified, it sets the value of the widget and
64# sends a <<Value>> event.  If the -check flag is included, the
65# new value is not actually applied, but just checked for correctness.
66# ----------------------------------------------------------------------
67itcl::body Rappture::DeviceEditor::value {args} {
68    set onlycheck 0
69    set i [lsearch -exact $args -check]
70    if {$i >= 0} {
71        set onlycheck 1
72        set args [lreplace $args $i $i]
73    }
74
75    if {[llength $args] == 1} {
76        # delete any existing object
77        if {$_xmlobj != ""} {
78            itcl::delete object $_xmlobj
79            set _xmlobj ""
80        }
81        set newval [lindex $args 0]
82        if {$newval != ""} {
83            if {$onlycheck} {
84                return
85            }
86            if {![Rappture::library isvalid $newval]} {
87                error "bad value \"$newval\": should be Rappture::Library"
88            }
89            set _xmlobj $newval
90        }
91        _redraw
92        event generate $itk_component(hull) <<Value>>
93
94    } elseif {[llength $args] != 0} {
95        error "wrong # args: should be \"value ?-check? ?newval?\""
96    }
97    return $_xmlobj
98}
99
100# ----------------------------------------------------------------------
101# USAGE: _redraw
102#
103# Used internally to load new device data into the appropriate
104# editor.  If the editor needs to be created, it is created and
105# activated within this widget.  Then, the data is loaded into
106# the editor.
107# ----------------------------------------------------------------------
108itcl::body Rappture::DeviceEditor::_redraw {} {
109    switch -- [_type $_xmlobj] {
110        molecule {
111            if {[catch {$itk_component(editors) page molecule} p]} {
112                set p [$itk_component(editors) insert end molecule]
113                Rappture::MoleculeViewer $p.mol $_tool
114                pack $p.mol -expand yes -fill both
115            }
116            $p.mol configure -device $_xmlobj
117            $itk_component(editors) current molecule
118        }
119        device1D {
120            if {[catch {$itk_component(editors) page device1D} p]} {
121                set p [$itk_component(editors) insert end device1D]
122                Rappture::DeviceViewer1D $p.dev $_tool
123                pack $p.dev -expand yes -fill both
124            }
125            $p.dev configure -device $_xmlobj
126            $itk_component(editors) current device1D
127        }
128    }
129}
130
131# ----------------------------------------------------------------------
132# USAGE: _type <xmlobj>
133#
134# Used internally to determine the type of the device data stored
135# within the <xmlobj>.  Returns a name such as "molecule" or
136# "device1D" indicating the type of editor that should be used to
137# display the data.
138# ----------------------------------------------------------------------
139itcl::body Rappture::DeviceEditor::_type {xmlobj} {
140    if {$xmlobj == ""} {
141        return ""
142    }
143    if {[llength [$xmlobj children -type molecule components]] > 0} {
144        return "molecule"
145    }
146    return "device1D"
147}
Note: See TracBrowser for help on using the repository browser.