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

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

merging in placard configuration updates, placard example, feature select example, and add-remove layer example from geomap branch r5971,r5990,r5991,r5993

File size: 8.7 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    private variable _placardstyle_default {fill: #B6B6B688; text-fill: #000000; text-size: 12.0;}
30
31    public variable label ""
32    public variable description ""
33    public variable attribution ""
34    public variable visibility "true"
35    public variable opacity "1.0"
36    public variable placardattributes ""
37    public variable placardstyle ""
38    public variable placardpadding 5
39
40    private method Provider { provider }
41
42    public method type { }
43    public method driver { }
44    public method url { }
45    public method cache { }
46
47    public method export { args }
48}
49
50# ----------------------------------------------------------------------
51# CONSTRUCTOR
52# ----------------------------------------------------------------------
53itcl::body Rappture::GeoMapLayer::constructor {provider args} {
54
55    Provider $provider
56
57    set placardstyle ${_placardstyle_default}
58
59    eval configure $args
60}
61
62
63# ----------------------------------------------------------------------
64# DESTRUCTOR
65# ----------------------------------------------------------------------
66itcl::body Rappture::GeoMapLayer::destructor {} {
67    itcl::delete object $_provider
68}
69
70
71# ----------------------------------------------------------------------
72# Provider: set data source for the layer
73# ----------------------------------------------------------------------
74itcl::body Rappture::GeoMapLayer::Provider { provider } {
75
76    if {![$provider isa Rappture::GeoMapDataProvider]} {
77        error "bad value: \"$provider\": should be a Rappture::GeoMapDataProvider object"
78    }
79
80    set _provider $provider
81}
82
83
84# ----------------------------------------------------------------------
85# Label: get/set label variable
86# ----------------------------------------------------------------------
87itcl::configbody Rappture::GeoMapLayer::label {
88
89    if {[string compare "" $label] == 0} {
90        error "bad value: \"$label\": label should be a non-empty string"
91    }
92}
93
94
95# ----------------------------------------------------------------------
96# Description: get/set description variable
97# ----------------------------------------------------------------------
98itcl::configbody Rappture::GeoMapLayer::description {
99
100    if {[string compare "" $description] == 0} {
101        error "bad value: \"$description\": description should be a non-empty string"
102    }
103}
104
105
106# ----------------------------------------------------------------------
107# Attribution: get/set attribution variable
108# ----------------------------------------------------------------------
109itcl::configbody Rappture::GeoMapLayer::attribution {
110
111    if {[string compare "" $attribution] == 0} {
112        error "bad value: \"$attribution\": attribution should be a non-empty string"
113    }
114}
115
116
117# ----------------------------------------------------------------------
118# Visibility: get/set the initial visibility of the layer
119# ----------------------------------------------------------------------
120itcl::configbody Rappture::GeoMapLayer::visibility {
121
122    if {[string is bool $visibility] == 0} {
123        error "bad value: \"$visibility\": visibility should be a boolean"
124    }
125}
126
127
128# ----------------------------------------------------------------------
129# Opacity: set the initial opacity of the layer
130# ----------------------------------------------------------------------
131itcl::configbody Rappture::GeoMapLayer::opacity {
132
133    if {[string is double $opacity] == 0} {
134        error "bad value: \"$opacity\": opacity should be a double"
135    }
136
137    if {[expr {$opacity < 0.0}] == 1 || [expr {$opacity > 1.0}] == 1} {
138        error "bad value: \"$opacity\": opacity should be in range \[0.0,1.0\]"
139    }
140}
141
142
143# ----------------------------------------------------------------------
144# placardattributes: key value list of attributes to show in the placard
145# ----------------------------------------------------------------------
146itcl::configbody Rappture::GeoMapLayer::placardattributes {
147
148    if { [expr {[llength $placardattributes] % 2}] != 0 } {
149        error "bad value \"$placardattributes\": uneven number of placard attributes"
150    }
151
152    regsub -all "\[ \t\r\n\]+" [string trim $placardattributes] " " placardattributes
153}
154
155
156# ----------------------------------------------------------------------
157# placardstyle: CSS formatted style definition for text and background
158# ----------------------------------------------------------------------
159itcl::configbody Rappture::GeoMapLayer::placardstyle {
160
161    if {[string equal $placardstyle ""]} {
162        # blank value sets style back to the default
163        set placardstyle ${_placardstyle_default}
164    }
165
166    regsub -all "\[ \t\r\n\]+" [string trim $placardstyle] " " placardstyle
167}
168
169
170# ----------------------------------------------------------------------
171# placardpadding: pixels between attribute labels and edge of the backing quad
172# ----------------------------------------------------------------------
173itcl::configbody Rappture::GeoMapLayer::placardpadding {
174
175    if {[string is integer $placardpadding] == 0} {
176        error "bad value \"$placardpadding\": placardpadding should be a positive integer"
177    }
178
179    if {$placardpadding < 0} {
180        error "bad value \"$placardpadding\": placardpadding should be a positive integer"
181    }
182}
183
184
185# ----------------------------------------------------------------------
186# type: clients use this public method to query type of this layer
187#
188# ----------------------------------------------------------------------
189itcl::body Rappture::GeoMapLayer::type {} {
190    return [$_provider type]
191}
192
193
194# ----------------------------------------------------------------------
195# driver: clients use this public method to query the driver for this layer
196#
197# ----------------------------------------------------------------------
198itcl::body Rappture::GeoMapLayer::driver {} {
199    return [$_provider driver]
200}
201
202
203# ----------------------------------------------------------------------
204# url: clients use this public method to query the initial
205#      value of the urlf or this layer
206#
207# ----------------------------------------------------------------------
208itcl::body Rappture::GeoMapLayer::url {} {
209    return [$_provider url]
210}
211
212
213# ----------------------------------------------------------------------
214# cache: clients use this public method to query the initial
215#           value of the cache flag for this layer
216#
217# ----------------------------------------------------------------------
218itcl::body Rappture::GeoMapLayer::cache {} {
219    return [$_provider cache]
220}
221
222
223# ----------------------------------------------------------------------
224# export: clients use this public method to serialize the object to a
225#       blt::tree object
226#
227# export -format blt_tree
228#
229# ----------------------------------------------------------------------
230itcl::body Rappture::GeoMapLayer::export {args} {
231    set valids "-format"
232    set format "blt_tree"
233
234    while {[llength $args] > 0} {
235        set flag [lindex $args 0]
236        switch -- $flag {
237            "-format" {
238                if {[llength $args] > 1} {
239                    set format [lindex $args 1]
240                    set args [lrange $args 2 end]
241                } else {
242                    error "wrong number args: should be ?-format <format>?"
243                }
244            }
245            default {
246                error "invalid option \"$flag\": should be one of $valids"
247            }
248        }
249    }
250
251    set valids "blt_tree"
252
253    switch -- $format {
254        "blt_tree" {
255            set t [blt::tree create]
256            $_provider exportToBltTree $t
257            $t set root \
258                label $label \
259                description $description \
260                attribution $attribution \
261                visible $visibility \
262                opacity $opacity \
263                placard [list \
264                    attrlist $placardattributes\
265                    style $placardstyle\
266                    padding $placardpadding\
267                ]
268        }
269        default {
270            error "bad format \"$format\": should be one of $valids"
271        }
272    }
273
274    return $t
275}
276
Note: See TracBrowser for help on using the repository browser.