~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/psvp/parameter.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # parameter.tcl --
  2 #
  3 #       This file defines the Parameter class and many subclasses.
  4 #
  5 # Copyright (c) 1998-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 
 31 # Each subclass of Parameter must provide implementations for
 32 # the following methods:
 33 #
 34 # get
 35 # set
 36 # type
 37 # domain
 38 
 39 Class Parameter;
 40 
 41 Parameter instproc init args {
 42     eval $self next $args;
 43 }
 44 
 45 Class ColorParameter -superclass Parameter
 46 
 47 ColorParameter instproc init args {
 48     $self instvar from_l_ to_l_ from_cr_ to_cr_ from_cb_ to_cb_
 49     $self instvar current_l_ current_cr_ current_cb_
 50 
 51     set from_l_ 0
 52     set to_l_ 255
 53     set from_cr_ 0
 54     set to_cr_ 255
 55     set from_cb_ 0
 56     set to_cb_ 255
 57     set current_l_ 0
 58     set current_cr_ 128
 59     set current_cb_ 128
 60 
 61     eval $self next $args
 62 }
 63 
 64 ColorParameter instproc from args {
 65     $self instvar from_l_ from_cr_ from_cb_
 66 
 67     if {[llength $args] == 1} {
 68         set from_l_ [lindex [lindex $args 0] 0]
 69         set from_cr_ [lindex [lindex $args 0] 1]
 70         set from_cb_ [lindex [lindex $args 0] 2]
 71     }
 72     return [list $from_l_ $from_cr_ $from_cb_];
 73 }
 74 
 75 ColorParameter instproc to args {
 76     $self instvar to_l_ to_cr_ to_cb_
 77 
 78     if {[llength $args] == 1} {
 79         set to_l_ [lindex [lindex $args 0] 0]
 80         set to_cr_ [lindex [lindex $args 0] 1]
 81         set to_cb_ [lindex [lindex $args 0] 2]
 82     }
 83     return [list $to_l_ $to_cr_ $to_cb_];
 84 }
 85 
 86 ColorParameter instproc get {} {
 87     $self instvar current_l_ current_cr_ current_cb_
 88 
 89     return [list $current_l_ $current_cr_ $current_cb_]
 90 }
 91 
 92 ColorParameter instproc set {color} {
 93     $self instvar from_l_ from_cr_ from_cb_
 94     $self instvar current_l_ current_cr_ current_cb_
 95     $self instvar to_l_ to_cr_ to_cb_
 96 
 97     set new_l [lindex $color 0]
 98     set new_cr [lindex $color 1]
 99     set new_cb [lindex $color 2]
100 
101 
102     if {$new_l < $from_l_} {
103         set current_l_ $from_l_;
104     } elseif {$new_l > $to_l_} {
105         set current_l_ $to_l_
106     } else {
107         set current_l_ $new_l
108     }
109 
110     if {$new_cr < $from_cr_} {
111         set current_cr_ $from_cr_;
112     } elseif {$new_cr > $to_cr_} {
113         set current_cr_ $to_cr_
114     } else {
115         set current_cr_ $new_cr
116     }
117 
118     if {$new_cb < $from_cb_} {
119         set current_cb_ $from_cb_;
120     } elseif {$new_cb > $to_cb_} {
121         set current_cb_ $to_cb_
122     } else {
123         set current_cb_ $new_cb
124     }
125 
126     return [$self get];
127 }
128 
129 ColorParameter instproc type {} {
130     return "color"
131 }
132 
133 ColorParameter instproc domain {} {
134     $self instvar from_l_ to_l_
135     $self instvar from_cr_ to_cr_
136     $self instvar from_cb_ to_cb_
137 
138     return "{{$from_l_ $from_cr_ $from_cb_} {$to_l_ $to_cr_ $to_cb_}}"
139 }
140 
141 Class RealParameter -superclass Parameter
142 
143 RealParameter instproc init args {
144     $self instvar from_ to_ current_;
145     set from_ 0.0;
146     set to_ 1.0;
147     set current_ 0.0;
148     eval $self next $args;
149 }
150 
151 RealParameter instproc from args {
152     $self instvar from_;
153 
154     if {[llength $args] == 1} {
155         set from_ $args;
156     }
157     return $from_;
158 }
159 
160 RealParameter instproc to args {
161     $self instvar to_;
162 
163     if {[llength $args] == 1} {
164         set to_ $args;
165     }
166     return $to_;
167 }
168 
169 RealParameter instproc get {} {
170     $self instvar current_;
171 
172     return $current_;
173 }
174 
175 RealParameter instproc set value {
176     $self instvar current_ from_ to_;
177 
178     if {$value < $from_} {
179         set current_ $from_;
180     } elseif {$value > $to_} {
181         set current_ $to_;
182     } else {
183         set current_ $value;
184     }
185     return $current_;
186 }
187 
188 RealParameter instproc type {} {
189     return "real";
190 }
191 
192 RealParameter instproc domain {} {
193     $self instvar from_ to_;
194 
195     return "($from_,$to_)"
196 }
197 
198 Class IntParameter -superclass Parameter
199 
200 IntParameter instproc init args {
201     $self instvar from_ to_ current_;
202 
203     set from_ 0;
204     set to_ 1;
205     set current_ 0;
206     eval $self next $args;
207 }
208 
209 IntParameter instproc from args {
210     $self instvar from_;
211 
212     if {[llength $args] == 1} {
213         set from_ [expr int($args)];
214     }
215     return $from_;
216 }
217 
218 IntParameter instproc to args {
219     $self instvar to_;
220 
221     if {[llength $args] == 1} {
222         set to_ [expr int($args)];
223     }
224     return $to_;
225 }
226 
227 IntParameter instproc get {} {
228     $self instvar current_;
229 
230     return $current_;
231 }
232 
233 IntParameter instproc set value {
234     $self instvar current_ from_ to_;
235 
236     if {$value < $from_} {
237         set current_ $from_;
238     } elseif {$value > $to_} {
239         set current_ $to_;
240     } else {
241         set current_ [expr int($value)];
242     }
243     return $current_;
244 }
245 
246 IntParameter instproc type {} {
247     return "int";
248 }
249 
250 IntParameter instproc domain {} {
251     $self instvar from_ to_;
252 
253     return "($from_,$to_)"
254 }
255 
256 Class TextParameter -superclass Parameter
257 
258 TextParameter instproc init args {
259     $self instvar current_;
260     set current_ "";
261     eval $self next $args;
262 }
263 
264 TextParameter instproc get {} {
265     $self instvar current_;
266 
267     return $current_;
268 }
269 
270 TextParameter instproc set value {
271     $self instvar current_;
272 
273     set current_ $value;
274     return $current_;
275 }
276 
277 TextParameter instproc type {} {
278     return "text";
279 }
280 
281 TextParameter instproc domain {} {
282     return "all"
283 }
284 
285 Class ExclusiveChoiceParameter -superclass Parameter
286 
287 ExclusiveChoiceParameter instproc init args {
288     $self instvar current_;
289     $self instvar choices_;
290     set current_ "";
291     set choices_ "";
292     eval $self next $args;
293 }
294 
295 ExclusiveChoiceParameter instproc get {} {
296     $self instvar current_;
297 
298     return $current_;
299 }
300 
301 ExclusiveChoiceParameter instproc set value {
302     $self instvar current_ choices_
303 
304     if {[lsearch $choices_ $value] != -1} {
305         set current_ $value;
306         return $current_;
307     }
308 }
309 
310 ExclusiveChoiceParameter instproc type {} {
311     return "exclusive_choice";
312 }
313 
314 ExclusiveChoiceParameter instproc domain {} {
315     $self instvar choices_;
316     return $choices_;
317 }
318 
319 ExclusiveChoiceParameter instproc add {new_choice} {
320     $self instvar choices_;
321 
322     lappend choices_ $new_choice;
323 }
324 
325 Class RectSubregionParameter -superclass Parameter
326 
327 RectSubregionParameter instproc init args {
328     $self instvar current_
329 
330     set current_ "0.25 0.25 0.75 0.75";
331     eval $self next $args;
332 }
333 
334 RectSubregionParameter instproc get {} {
335     $self instvar current_;
336 
337     return $current_;
338 }
339 
340 RectSubregionParameter instproc set value {
341     $self instvar current_;
342 
343     set current_ $value;
344     return $current_;
345 }
346 
347 RectSubregionParameter instproc type {} {
348     return "rect_subregion";
349 }
350 
351 RectSubregionParameter instproc domain {} {
352     return "all"
353 }
354 
355 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.