1 |
jan |
1725 |
# Copyright (C) 2003 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Jan-Oliver Wagner <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
""" |
9 |
|
|
Classes for ArcView Objects as in '.apr'-files. |
10 |
|
|
|
11 |
|
|
The classes are only added to this module if they |
12 |
|
|
are considered to be complete and whenever possible |
13 |
|
|
accompanied by unit tests (see tests/). |
14 |
|
|
Experimental classes should remain in importAPR.py. |
15 |
|
|
""" |
16 |
|
|
|
17 |
|
|
__version__ = "$Revision$" |
18 |
|
|
|
19 |
|
|
from Thuban.Model.color import Color, Transparent, Black |
20 |
|
|
from Thuban.Model.range import Range |
21 |
|
|
|
22 |
|
|
from odb import ODBBaseObject |
23 |
|
|
|
24 |
|
|
class APR_LClass(ODBBaseObject): |
25 |
|
|
"""This object describes the range and label of a class |
26 |
|
|
within a legend. |
27 |
|
|
|
28 |
|
|
'IsText' determines whether 'MinStr'/'MaxStr' are given, else |
29 |
|
|
'MinNum'/'MaxNum' should be there. |
30 |
|
|
So far, only String-Ranges with identical 'MinStr'/'MaxStr' have |
31 |
|
|
been sighted. |
32 |
|
|
|
33 |
|
|
'MinNum' may not be there. In this case assume it to be -oo. |
34 |
|
|
|
35 |
|
|
There are objects with 'IsNoData' set to 1. Not yet sure how to |
36 |
|
|
treat them. |
37 |
|
|
|
38 |
|
|
However, objects have been sighted that only have 'IsText' and |
39 |
|
|
'Precision': We assume an empty label and a full range. |
40 |
|
|
|
41 |
|
|
No referenced objects. |
42 |
|
|
""" |
43 |
|
|
_obj_refs = [ ] |
44 |
|
|
_values = [ 'IsText', 'MinStr', 'MaxStr', 'MinNum', 'MaxNum', 'Label', |
45 |
|
|
'Precision', 'IsNoData' ] |
46 |
|
|
|
47 |
|
|
def GetThubanRange(self): |
48 |
|
|
"""Return a Thuban range that corresponds to this object.""" |
49 |
|
|
# build range |
50 |
|
|
if hasattr(self, 'MinNum'): |
51 |
|
|
range_str = ']' + self.MinNum + ';' |
52 |
|
|
else: |
53 |
|
|
range_str = ']-oo;' |
54 |
|
|
if hasattr(self, 'MaxNum'): |
55 |
|
|
range_str = range_str + self.MaxNum + ']' |
56 |
|
|
else: |
57 |
|
|
range_str = None |
58 |
|
|
|
59 |
|
|
if hasattr(self, 'MinNum') and hasattr(self, 'MaxNum'): |
60 |
|
|
if self.MinNum == self.MaxNum: |
61 |
|
|
range_str = '[' + self.MinNum + ';' + self.MaxNum + ']' |
62 |
|
|
return Range(range_str) |
63 |
|
|
|
64 |
|
|
def GetLabel(self): |
65 |
|
|
"""Return the label string. |
66 |
|
|
Return an empty string if there is no 'Label'. |
67 |
|
|
""" |
68 |
|
|
if hasattr(self, 'Label'): |
69 |
|
|
return self.Label |
70 |
|
|
else: |
71 |
|
|
return '' |
72 |
|
|
|
73 |
|
|
|
74 |
|
|
class APR_TClr(ODBBaseObject): |
75 |
|
|
"""Color object. Appears in 3 styles: |
76 |
|
|
1. no attributes: (so far assumed as black) |
77 |
|
|
2. only 'Name': a string that describes the color. |
78 |
|
|
Seen only "Transparent". |
79 |
|
|
3. 'Red', 'Green', 'Blue': RGB code. Each value in '0xffff' style. |
80 |
|
|
3.1 Only one or two of the colors are defined. It is assumed |
81 |
|
|
that in this case the rest is equal to 0x0000 |
82 |
|
|
3.2 Some hex-codes are incomplete (eg. 0xff). It is assumed |
83 |
|
|
that the missing digits are "0". |
84 |
|
|
|
85 |
|
|
No referenced objects. |
86 |
|
|
""" |
87 |
|
|
_obj_refs = [ ] |
88 |
|
|
_values = [ 'Name', 'Red', 'Green', 'Blue' ] |
89 |
|
|
|
90 |
|
|
def GetThubanColor(self): |
91 |
|
|
"""Return a Thuban Color object; returns None if a problem |
92 |
|
|
occured. |
93 |
|
|
""" |
94 |
|
|
if hasattr(self, 'Red') or hasattr(self, 'Green') or \ |
95 |
|
|
hasattr(self, 'Blue'): |
96 |
|
|
rgb = { 'Red': 0, 'Green': 0, 'Blue': 0 } # default for missing |
97 |
|
|
# parts: 0x0000 |
98 |
|
|
|
99 |
|
|
for color in [ 'Red', 'Green', 'Blue' ]: |
100 |
|
|
if hasattr(self, color): |
101 |
|
|
s = getattr(self, color) |
102 |
|
|
while len(s) < 6: |
103 |
|
|
s = s + '0' |
104 |
|
|
rgb[color] = int(s, 16)/float(int('0xffff', 16)) |
105 |
|
|
return Color(rgb['Red'], rgb['Green'], rgb['Blue']) |
106 |
|
|
elif hasattr(self, 'Name'): |
107 |
|
|
if self.Name == 'Transparent': |
108 |
|
|
return Transparent |
109 |
|
|
else: |
110 |
|
|
return None |
111 |
|
|
else: |
112 |
|
|
return Black |