source: trunk/lang/tcl/scripts/objects/number/number.rp @ 2080

Last change on this file since 2080 was 2080, checked in by mmc, 13 years ago

Part 1 of a major reorganization of content. Moving "instant" to "builder"
and setting up "builder" more like the "gui" part as a package. Moving the
Rappture::object stuff from the builder into the main installation, so it
can be shared by the tester as well. Moving "driver" into gui/scripts
where it belongs. Creating a new "launcher.tcl" script that decides
which of the three parts to launch based on command line options. Still
need to sort out the Makefiles to get this all right...

File size: 3.7 KB
Line 
1object number -extends base {
2    palettes "Inputs"
3    help http://rappture.org/wiki/rp_xml_ele_number
4    attr default -title "Default Value" -type string:validate=number -path default
5    attr units -title "Units of Measurement" -type units -path units
6    attr min -title "Minimum Value" -type string:validate=number -path min
7    attr max -title "Maximum Value" -type string:validate=number -path max
8    attr color -title "Color" -type color -path color
9
10    check label {
11        if {[string length [string trim $attr(label)]] == 0} {
12            return [list warning "Should set a label that describes this value"]
13        }
14    }
15    check description {
16        set desc [string trim $attr(description)]
17        if {[string length $desc] == 0} {
18            return [list warning "Should include a description of what this value represents, typical settings, etc."]
19        } elseif {[string equal $desc $attr(label)]} {
20            return [list warning "Description should be different from the label and give additional information about the value."]
21        }
22    }
23
24    check default {
25        if {[string length [string trim $attr(default)]] == 0} {
26            return [list error "Must have a default value for this number."]
27        }
28        if {"" != $attr(units)} {
29            set base [Rappture::Units::System::for $attr(units)]
30            if {[validate_number_parse $attr(default) num units]
31               && "" != $units
32               && ![string equal [Rappture::Units::System::for $units] $base]} {
33                return [list error "Units for default value don't match the expected units for this value"]
34            }
35
36            set dval [Rappture::Units::convert $attr(default) -context $attr(units) -to $attr(units) -units off]
37
38            if {[validate_number_parse $attr(min) num units]
39                 && [catch {Rappture::Units::convert $attr(min) -context $attr(units) -to $attr(units) -units off} min] == 0
40                 && $dval < $min} {
41                return [list error "Default value is less than the minimum that you've specified for this value."]
42            }
43
44            if {[validate_number_parse $attr(max) num units]
45                 && [catch {Rappture::Units::convert $attr(max) -context $attr(units) -to $attr(units) -units off} max] == 0
46                 && $dval > $max} {
47                return [list error "Default value is greater than the maximum that you've specified for this value."]
48            }
49        }
50    }
51
52    check min {
53        if {"" != $attr(units)} {
54            set base [Rappture::Units::System::for $attr(units)]
55            if {[validate_number_parse $attr(min) num units]
56               && "" != $units
57               && ![string equal [Rappture::Units::System::for $units] $base]} {
58                return [list error "Units for minimum value don't match the expected units for this value"]
59            }
60        }
61        if {[catch {Rappture::Units::convert $attr(min) -context $attr(units) -to $attr(units) -units off} min] == 0
62              && [catch {Rappture::Units::convert $attr(max) -context $attr(units) -to $attr(units) -units off} max] == 0
63              && $min >= $max} {
64            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."]
65        }
66    }
67
68    check max {
69        if {"" != $attr(units)} {
70            set base [Rappture::Units::System::for $attr(units)]
71            if {[validate_number_parse $attr(max) num units]
72               && "" != $units
73               && ![string equal [Rappture::Units::System::for $units] $base]} {
74                return [list error "Units for maximum value don't match the expected units for this value"]
75            }
76        }
77    }
78}
Note: See TracBrowser for help on using the repository browser.