1 | # ---------------------------------------------------------------------- |
---|
2 | # RAPPTURE OBJECT: periodicelement |
---|
3 | # |
---|
4 | # A set of mutually-exclusive choices, as in Model A or Model B. |
---|
5 | # Usually used as an input to a simulation. |
---|
6 | # |
---|
7 | # ====================================================================== |
---|
8 | # AUTHOR: Michael McLennan, Purdue University |
---|
9 | # Copyright (c) 2004-2011 Purdue Research Foundation |
---|
10 | # |
---|
11 | # See the file "license.terms" for information on usage and |
---|
12 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | # ====================================================================== |
---|
14 | |
---|
15 | object periodicelement -extends base { |
---|
16 | palettes "Inputs" |
---|
17 | |
---|
18 | help http://rappture.org/wiki/rp_xml_ele_periodicelement |
---|
19 | |
---|
20 | attr active -title "Active Elements" \ |
---|
21 | -type string -path default -only input \ |
---|
22 | -tooltip "Specifies the set of elements that can be selected.\n\nCan be a list of element symbols or groups: actinoid, alkali-metal, alkaline-earth-metal, halogen, lanthanoid, metalloid, noble-gas, other-non-metal, post-transition-metal, transition-metal, or unknown." |
---|
23 | attr inactive -title "Inactive Elements" \ |
---|
24 | -type string -path default -only input \ |
---|
25 | -tooltip "Specifies the set of elements that can't be selected.\n\nCan be a list of element symbols or groups: actinoid, alkali-metal, alkaline-earth-metal, halogen, lanthanoid, metalloid, noble-gas, other-non-metal, post-transition-metal, transition-metal, or unknown." |
---|
26 | |
---|
27 | attr returnvalue -title "Return value" -type string -path default -only input -tooltip "Specifies the return value: name, symbol, number, or weight." |
---|
28 | |
---|
29 | attr default -title "Default Value" -type string -path default -only input -tooltip "Sets the value that this input has when the program first starts. This value is used by default unless the user explicitly changes it." |
---|
30 | |
---|
31 | check default { |
---|
32 | if {[llength $attr(options)] > 0} { |
---|
33 | if {[string length [string trim $attr(default)]] == 0} { |
---|
34 | return [list error "Must have a default value for this periodicelement."] |
---|
35 | } |
---|
36 | |
---|
37 | # make sure that the default is really a choice |
---|
38 | set defval [string trim $attr(default)] |
---|
39 | set found 0 |
---|
40 | foreach rec $attr(options) { |
---|
41 | set label [string trim [lindex $rec 0]] |
---|
42 | set value [string trim [lindex $rec 1]] |
---|
43 | if {$defval eq $label || $defval eq $value} { |
---|
44 | set found 1 |
---|
45 | break |
---|
46 | } |
---|
47 | } |
---|
48 | if {!$found} { |
---|
49 | return [list error "Default value must be a label or value for one of the current periodicelements."] |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | storage { |
---|
55 | private variable _val ;# current periodicelement |
---|
56 | } |
---|
57 | |
---|
58 | import xml {xmlobj path} { |
---|
59 | attr import $xmlobj $path |
---|
60 | import_string [$xmlobj get $path.current] |
---|
61 | } |
---|
62 | |
---|
63 | export xml {xmlobj path} { |
---|
64 | $xmlobj put $path $_val |
---|
65 | } |
---|
66 | |
---|
67 | import string {val} { |
---|
68 | set _val $val |
---|
69 | } |
---|
70 | |
---|
71 | export string {var} { |
---|
72 | upvar $var v |
---|
73 | set v $_val |
---|
74 | } |
---|
75 | |
---|
76 | compare { |
---|
77 | return [string compare $_val $_val2] |
---|
78 | } |
---|
79 | } |
---|