1 | # ---------------------------------------------------------------------- |
---|
2 | # RAPPTURE OBJECT: integer |
---|
3 | # |
---|
4 | # A integer is an integral value. It is usually used as an input, |
---|
5 | # but it can also be an output from 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 integer -extends base { |
---|
16 | palettes "Inputs" "Outputs" |
---|
17 | |
---|
18 | help http://rappture.org/wiki/rp_xml_ele_integer |
---|
19 | |
---|
20 | attr default -title "Default Value" -type string:validate=int -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." |
---|
21 | |
---|
22 | attr min -title "Minimum Value" -type string:validate=int -path min -only input -tooltip "Sets the minimum value for this integer. The value can be equal to the minimum, but no lower." |
---|
23 | |
---|
24 | attr max -title "Maximum Value" -type string:validate=int -path max -only input -tooltip "Sets the maximum value for this integer. The value can be equal to the maximum, but no higher." |
---|
25 | |
---|
26 | |
---|
27 | check default { |
---|
28 | if {[string length [string trim $attr(default)]] == 0} { |
---|
29 | return [list error "Must have a default value for this integer."] |
---|
30 | } |
---|
31 | if {"" != $attr(min) && $attr(default) < $attr(min)} { |
---|
32 | return [list error "Default value is less than the minimum that you've specified for this value."] |
---|
33 | } |
---|
34 | if {"" != $attr(max) && $attr(default) > $attr(max)} { |
---|
35 | return [list error "Default value is greater than the maximum that you've specified for this value."] |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | check min { |
---|
40 | if {"" != $attr(min) && "" != $attr(max) && $attr(min) >= $attr(max)} { |
---|
41 | return [list error "Minimum value should be less than the maximum. If you don't want to see a min/max range, you can clear out either or both values."] |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | storage { |
---|
46 | private variable _val 0 ;# integer value |
---|
47 | } |
---|
48 | |
---|
49 | import xml {xmlobj path} { |
---|
50 | attr import $xmlobj $path |
---|
51 | import_string [$xmlobj get $path.current] |
---|
52 | } |
---|
53 | |
---|
54 | export xml {xmlobj path} { |
---|
55 | $xmlobj put $path $_val |
---|
56 | } |
---|
57 | |
---|
58 | import string {val} { |
---|
59 | if {[string is integer -strict $val]} { |
---|
60 | set _val $val |
---|
61 | } else { |
---|
62 | error "don't recognize value" |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | export string {var} { |
---|
67 | upvar $var v |
---|
68 | set v $_val |
---|
69 | } |
---|
70 | |
---|
71 | compare { |
---|
72 | if {$_val < $_val2} { |
---|
73 | return -1 |
---|
74 | } elseif {$_val > $_val2} { |
---|
75 | return 1 |
---|
76 | } else { |
---|
77 | return 0 |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|