source: branches/blt4_geovis/gui/scripts/geomaplayer.tcl @ 5964

Last change on this file since 5964 was 5964, checked in by dkearney, 7 years ago

merging r5956 from trunk to blt4_geovis
includes tcl map layer api, examples, and tests.
code was written for blt2.4, fixes for blt4 will be applied soon.

File size: 6.6 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: geomaplayer - holds layer information for a geomap
4#
5# ======================================================================
6#  AUTHOR:  Derrick Kearney, Purdue University
7#  Copyright (c) 2004-2015  HUBzero Foundation, LLC
8#
9#  See the file "license.terms" for information on usage and
10#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11# ======================================================================
12package require Itcl
13package require BLT
14
15namespace eval Rappture {
16    # forward declaration
17}
18
19
20itcl::class Rappture::GeoMapLayer {
21    constructor {provider args} {
22        # defined below
23    }
24    destructor {
25        # defined below
26    }
27
28    private variable _provider ""
29
30    public variable label ""
31    public variable description ""
32    public variable attribution ""
33    public variable visibility "true"
34    public variable opacity "1.0"
35
36    private method Provider { provider }
37
38    public method type { }
39    public method driver { }
40    public method url { }
41    public method cache { }
42
43    public method export { args }
44}
45
46# ----------------------------------------------------------------------
47# CONSTRUCTOR
48# ----------------------------------------------------------------------
49itcl::body Rappture::GeoMapLayer::constructor {provider args} {
50
51    Provider $provider
52
53    eval configure $args
54}
55
56
57# ----------------------------------------------------------------------
58# DESTRUCTOR
59# ----------------------------------------------------------------------
60itcl::body Rappture::GeoMapLayer::destructor {} {
61    itcl::delete object $_provider
62}
63
64
65# ----------------------------------------------------------------------
66# Provider: set data source for the layer
67# ----------------------------------------------------------------------
68itcl::body Rappture::GeoMapLayer::Provider { provider } {
69
70    if {![$provider isa Rappture::GeoMapDataProvider]} {
71        error "bad value: \"$provider\": should be a Rappture::GeoMapDataProvider object"
72    }
73
74    set _provider $provider
75}
76
77
78# ----------------------------------------------------------------------
79# Label: get/set label variable
80# ----------------------------------------------------------------------
81itcl::configbody Rappture::GeoMapLayer::label {
82
83    if {[string compare "" $label] == 0} {
84        error "bad value: \"$label\": should be a non-empty string"
85    }
86}
87
88
89# ----------------------------------------------------------------------
90# Description: get/set description variable
91# ----------------------------------------------------------------------
92itcl::configbody Rappture::GeoMapLayer::description {
93
94    if {[string compare "" $description] == 0} {
95        error "bad value: \"$description\": should be a non-empty string"
96    }
97}
98
99
100# ----------------------------------------------------------------------
101# Attribution: get/set attribution variable
102# ----------------------------------------------------------------------
103itcl::configbody Rappture::GeoMapLayer::attribution {
104
105    if {[string compare "" $attribution] == 0} {
106        error "bad value: \"$attribution\": should be a non-empty string"
107    }
108}
109
110
111# ----------------------------------------------------------------------
112# Visibility: get/set the initial visibility of the layer
113# ----------------------------------------------------------------------
114itcl::configbody Rappture::GeoMapLayer::visibility {
115
116    if {[string is bool $visibility] == 0} {
117        error "bad value: \"$visibility\": should be a boolean"
118    }
119}
120
121
122# ----------------------------------------------------------------------
123# Opacity: set the initial opacity of the layer
124# ----------------------------------------------------------------------
125itcl::configbody Rappture::GeoMapLayer::opacity {
126
127    if {[string is double $opacity] == 0} {
128        error "bad value: \"$opacity\": should be a double"
129    }
130
131    if {[expr {$opacity < 0.0}] == 1 || [expr {$opacity > 1.0}] == 1} {
132        error "bad value: \"$opacity\": should be in range \[0.0,1.0\]"
133    }
134}
135
136
137# ----------------------------------------------------------------------
138# type: clients use this public method to query type of this layer
139#
140# ----------------------------------------------------------------------
141itcl::body Rappture::GeoMapLayer::type {} {
142    return [$_provider type]
143}
144
145
146# ----------------------------------------------------------------------
147# driver: clients use this public method to query the driver for this layer
148#
149# ----------------------------------------------------------------------
150itcl::body Rappture::GeoMapLayer::driver {} {
151    return [$_provider driver]
152}
153
154
155# ----------------------------------------------------------------------
156# url: clients use this public method to query the initial
157#      value of the urlf or this layer
158#
159# ----------------------------------------------------------------------
160itcl::body Rappture::GeoMapLayer::url {} {
161    return [$_provider url]
162}
163
164
165# ----------------------------------------------------------------------
166# cache: clients use this public method to query the initial
167#           value of the cache flag for this layer
168#
169# ----------------------------------------------------------------------
170itcl::body Rappture::GeoMapLayer::cache {} {
171    return [$_provider cache]
172}
173
174
175# ----------------------------------------------------------------------
176# export: clients use this public method to serialize the object to a
177#       blt::tree object
178#
179# export -format blt_tree
180#
181# ----------------------------------------------------------------------
182itcl::body Rappture::GeoMapLayer::export {args} {
183    set valids "-format"
184    set format "blt_tree"
185
186    while {[llength $args] > 0} {
187        set flag [lindex $args 0]
188        switch -- $flag {
189            "-format" {
190                if {[llength $args] > 1} {
191                    set format [lindex $args 1]
192                    set args [lrange $args 2 end]
193                } else {
194                    error "wrong number args: should be ?-format <format>?"
195                }
196            }
197            default {
198                error "invalid option \"$flag\": should be one of $valids"
199            }
200        }
201    }
202
203    set valids "blt_tree"
204
205    switch -- $format {
206        "blt_tree" {
207            set t [blt::tree create]
208            $_provider exportToBltTree $t
209            $t set root \
210                label $label \
211                description $description \
212                attribution $attribution \
213                visible $visibility \
214                opacity $opacity \
215
216        }
217        default {
218            error "bad format \"$format\": should be one of $valids"
219        }
220    }
221
222    return $t
223}
224
Note: See TracBrowser for help on using the repository browser.