[5949] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
| 2 | # ---------------------------------------------------------------------- |
---|
| 3 | # COMPONENT: geomapdataprovidercolorramp - |
---|
| 4 | # holds data source information for a geomap |
---|
| 5 | # raster colorramp layer |
---|
| 6 | # |
---|
| 7 | # ====================================================================== |
---|
| 8 | # AUTHOR: Derrick Kearney, Purdue University |
---|
| 9 | # Copyright (c) 2004-2015 HUBzero Foundation, LLC |
---|
| 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 | package require Itcl |
---|
| 15 | package require BLT |
---|
| 16 | |
---|
| 17 | namespace eval Rappture { |
---|
| 18 | # forward declaration |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | itcl::class Rappture::GeoMapDataProviderColorramp { |
---|
| 23 | inherit Rappture::GeoMapDataProvider |
---|
| 24 | |
---|
| 25 | constructor {url args} { |
---|
| 26 | Rappture::GeoMapDataProvider::constructor "image" "colorramp" $url |
---|
| 27 | } { |
---|
| 28 | # defined below |
---|
| 29 | } |
---|
| 30 | destructor { |
---|
| 31 | # defined below |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public variable colormap "0 0 0 0 1 1 1 1 1 1" |
---|
| 35 | public variable elevdriver "gdal" |
---|
| 36 | public variable profile "geodetic" |
---|
| 37 | |
---|
| 38 | public method exportToBltTree { tree } |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | # ---------------------------------------------------------------------- |
---|
| 42 | # CONSTRUCTOR |
---|
| 43 | # ---------------------------------------------------------------------- |
---|
| 44 | itcl::body Rappture::GeoMapDataProviderColorramp::constructor {url args} { |
---|
| 45 | |
---|
| 46 | eval configure $args |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | # ---------------------------------------------------------------------- |
---|
| 51 | # DESTRUCTOR |
---|
| 52 | # ---------------------------------------------------------------------- |
---|
| 53 | itcl::body Rappture::GeoMapDataProviderColorramp::destructor {} { |
---|
| 54 | |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | # ---------------------------------------------------------------------- |
---|
| 59 | # colormap: set colormap for this data source |
---|
| 60 | # ---------------------------------------------------------------------- |
---|
| 61 | itcl::configbody Rappture::GeoMapDataProviderColorramp::colormap { |
---|
| 62 | |
---|
| 63 | # colormap should be non-empty list |
---|
| 64 | if {[llength $colormap] == 0} { |
---|
| 65 | error "bad value \"$colormap\": should be a non-empty list of doubles" |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | # colormap entries should have 5 values each |
---|
| 69 | set lcm [llength $colormap] |
---|
| 70 | if { [expr {$lcm % 5}] != 0 } { |
---|
| 71 | error "bad value \"$colormap\": colormap entries should have 5 values each" |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | foreach {p r g b a} $colormap { |
---|
| 75 | # point should be a double precision value |
---|
| 76 | if {[string is double $p] == 0} { |
---|
| 77 | error "bad value \"$p\": should be a double" |
---|
| 78 | } |
---|
| 79 | # r g b and a should be double precision values in range [0.0,1.0] |
---|
| 80 | foreach v [list $r $g $b $a] { |
---|
| 81 | if {[string is double $v] == 0} { |
---|
| 82 | error "bad value \"$v\": should be a double" |
---|
| 83 | } |
---|
| 84 | if {[expr {$v < 0.0}] == 1 || [expr {$v > 1.0}] == 1} { |
---|
| 85 | error "bad value \"$v\": should be in range \[0.0,1.0\]" |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | # normalize spacing and save the colormap |
---|
| 91 | set colormap [regsub -all "\[ \t\r\n\]+" [string trim $colormap] " "] |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | # ---------------------------------------------------------------------- |
---|
| 95 | # elevdriver: get/set elevdriver to be used by this datasource |
---|
| 96 | # ---------------------------------------------------------------------- |
---|
| 97 | itcl::configbody Rappture::GeoMapDataProviderColorramp::elevdriver { |
---|
| 98 | |
---|
| 99 | set valids {gdal tms} |
---|
| 100 | |
---|
| 101 | if {[string compare "" $elevdriver] == 0} { |
---|
| 102 | error "bad value \"$elevdriver\": should be a non-empty string" |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | if {[lsearch $valids $elevdriver] < 0} { |
---|
| 106 | error "bad value \"$elevdriver\": should be one of \"$valids\"" |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | # ---------------------------------------------------------------------- |
---|
| 112 | # profile: get/set profile for to be used for this datasource |
---|
| 113 | # |
---|
| 114 | # example profiles include: |
---|
| 115 | # global-geodetic |
---|
| 116 | # global-mercator |
---|
| 117 | # geodetic |
---|
| 118 | # mercator |
---|
| 119 | # ---------------------------------------------------------------------- |
---|
| 120 | itcl::configbody Rappture::GeoMapDataProviderColorramp::profile { |
---|
| 121 | |
---|
| 122 | # set valids {global-geodetic global-mercator geodetic mercator} |
---|
| 123 | |
---|
| 124 | if {[string compare "" $profile] == 0} { |
---|
| 125 | error "bad value \"$profile\": should be a non-empty string" |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | # if {[lsearch $valids $profile] < 0} { |
---|
| 129 | # error "bad value \"$profile\": should be one of \"$valids\"" |
---|
| 130 | # } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | # ---------------------------------------------------------------------- |
---|
| 135 | # ExportToBltTree: export object to a blt::tree |
---|
| 136 | # |
---|
| 137 | # ExportToBltTree $tree |
---|
| 138 | # |
---|
| 139 | # ---------------------------------------------------------------------- |
---|
| 140 | itcl::body Rappture::GeoMapDataProviderColorramp::exportToBltTree {tree} { |
---|
| 141 | |
---|
| 142 | Rappture::GeoMapDataProvider::exportToBltTree $tree |
---|
| 143 | |
---|
| 144 | $tree set root \ |
---|
| 145 | colorramp.url [url] \ |
---|
| 146 | colorramp.colormap $colormap \ |
---|
| 147 | colorramp.elevdriver $elevdriver \ |
---|
| 148 | profile $profile \ |
---|
| 149 | } |
---|
| 150 | |
---|