1 |
jan |
2629 |
# Copyright (C) 2003-2005 by Intevation GmbH |
2 |
jan |
1725 |
# 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 |
jan |
1883 |
from math import ceil |
20 |
|
|
|
21 |
jan |
1725 |
from Thuban.Model.color import Color, Transparent, Black |
22 |
|
|
from Thuban.Model.range import Range |
23 |
jan |
1883 |
from Thuban.Model.classification import ClassGroupProperties |
24 |
jan |
1725 |
|
25 |
|
|
from odb import ODBBaseObject |
26 |
|
|
|
27 |
jan |
1883 |
class APR_BLnSym(ODBBaseObject): |
28 |
|
|
"""Line symbol object. |
29 |
|
|
Always references a color object TClr via 'Color'. |
30 |
|
|
|
31 |
|
|
The stroke width 'Width' is always given, but the scale is |
32 |
|
|
unclear so far (e.g. which width is actually meant with value '0.1'?). |
33 |
|
|
Meanwhile, the ceiling of 'Width' is applied to be stroke width |
34 |
|
|
in pixels. |
35 |
|
|
|
36 |
|
|
Finally, there seems always to be a 'Pattern'-List consisting of |
37 |
|
|
float values. No idea so far, how to interpret this (Thuban does |
38 |
|
|
not support pattern yet anyway). |
39 |
|
|
""" |
40 |
|
|
_obj_refs = [ 'Color' ] |
41 |
|
|
_values = [ 'Width', 'Pattern' ] |
42 |
|
|
|
43 |
|
|
def GetThubanProp(self): |
44 |
|
|
"""Create a Thuban ClassGroupProperty from this object and |
45 |
|
|
return it. |
46 |
|
|
""" |
47 |
|
|
prop = ClassGroupProperties() |
48 |
|
|
prop.SetLineColor(self.Get('Color').GetThubanColor()) |
49 |
|
|
prop.SetLineWidth(int(ceil(float(self.Get('Width'))))) |
50 |
|
|
return prop |
51 |
|
|
|
52 |
|
|
class APR_BMkSym(ODBBaseObject): |
53 |
|
|
"""Point symbol object. |
54 |
|
|
Always references a Color and a Background Color via 'Color', 'BgColor'. |
55 |
|
|
For Thuban, Color is interpreted as line color and BGColor is |
56 |
|
|
interpreted as fill color. |
57 |
|
|
|
58 |
|
|
Next, there is always a 'Font' reference. Probably this defines |
59 |
|
|
the font for the label. This is not interpreted for Thuban. |
60 |
|
|
|
61 |
jan |
2378 |
There is always a Size element. It is not clear how 'size' |
62 |
|
|
defined in ArcView. |
63 |
jan |
1883 |
|
64 |
|
|
There is always a Angle element, but I don't know how this is |
65 |
|
|
defined. I only sighted the value of 360 so far. |
66 |
|
|
|
67 |
|
|
|
68 |
|
|
Finally, there seems always to be a 'Pattern'-List consisting of |
69 |
|
|
float values. No idea so far, how to interpret this (Thuban does |
70 |
|
|
not support pattern yet anyway). |
71 |
|
|
""" |
72 |
|
|
|
73 |
|
|
_obj_refs = [ 'Color', 'BgColor', 'Font' ] |
74 |
|
|
_values = [ 'Angle', 'Size', 'Pattern' ] |
75 |
|
|
|
76 |
|
|
def GetThubanProp(self): |
77 |
|
|
"""Create a Thuban ClassGroupProperty from this object and |
78 |
|
|
return it. |
79 |
|
|
|
80 |
|
|
In Thuban, the points have all the same size, |
81 |
|
|
but we can vary the width of the line. |
82 |
|
|
""" |
83 |
|
|
prop = ClassGroupProperties() |
84 |
jan |
2378 |
prop.SetSize(int(ceil(float(self.Get('Size'))))) |
85 |
jan |
1883 |
prop.SetLineColor(self.Get('Color').GetThubanColor()) |
86 |
|
|
prop.SetFill(self.Get('BgColor').GetThubanColor()) |
87 |
|
|
return prop |
88 |
|
|
|
89 |
|
|
class APR_BShSym(ODBBaseObject): |
90 |
jan |
2629 |
"""Polygon symbol object, either filled with a single color or |
91 |
|
|
with a pattern. |
92 |
|
|
. |
93 |
jan |
1883 |
Always references TClr objects via 'Color', 'OutlineColor' and 'BgColor'. |
94 |
|
|
Always has attributes 'OutlineWidth' and 'Outline'. |
95 |
jan |
2378 |
|
96 |
jan |
1883 |
OutlineColor is interpreted to be the Thuban line color, OutlineWidth |
97 |
|
|
as the Thuban line width. |
98 |
|
|
'Color' is interpreted to be the Thuban fill color. |
99 |
jan |
2629 |
'BgColor' is not interpreted and probably has something to do with |
100 |
|
|
patterns (Stripple). |
101 |
|
|
'Stripple' ist not interpreted in Thuban. It is a pattern definition |
102 |
|
|
based on a bitpattern. Thuban has no Patterns yet. |
103 |
jan |
1883 |
|
104 |
|
|
It is unclear what 'Outline' defines and thus is not used for Tuban. |
105 |
|
|
""" |
106 |
jan |
2629 |
_obj_refs = [ 'Color', 'OutlineColor', 'BgColor', 'Stripple' ] |
107 |
jan |
1883 |
_values = [ 'OutlineWidth', 'Outline' ] |
108 |
|
|
|
109 |
|
|
def GetThubanProp(self): |
110 |
|
|
"""Create a Thuban ClassGroupProperty from this object and |
111 |
|
|
return it. |
112 |
|
|
""" |
113 |
|
|
prop = ClassGroupProperties() |
114 |
|
|
prop.SetLineWidth(int(ceil(float(self.Get('OutlineWidth'))))) |
115 |
|
|
prop.SetLineColor(self.Get('OutlineColor').GetThubanColor()) |
116 |
|
|
prop.SetFill(self.Get('Color').GetThubanColor()) |
117 |
|
|
return prop |
118 |
|
|
|
119 |
jan |
1725 |
class APR_LClass(ODBBaseObject): |
120 |
|
|
"""This object describes the range and label of a class |
121 |
|
|
within a legend. |
122 |
|
|
|
123 |
|
|
'IsText' determines whether 'MinStr'/'MaxStr' are given, else |
124 |
|
|
'MinNum'/'MaxNum' should be there. |
125 |
|
|
So far, only String-Ranges with identical 'MinStr'/'MaxStr' have |
126 |
|
|
been sighted. |
127 |
|
|
|
128 |
|
|
'MinNum' may not be there. In this case assume it to be -oo. |
129 |
|
|
|
130 |
|
|
There are objects with 'IsNoData' set to 1. Not yet sure how to |
131 |
|
|
treat them. |
132 |
|
|
|
133 |
|
|
However, objects have been sighted that only have 'IsText' and |
134 |
|
|
'Precision': We assume an empty label and a full range. |
135 |
|
|
|
136 |
|
|
No referenced objects. |
137 |
|
|
""" |
138 |
|
|
_obj_refs = [ ] |
139 |
|
|
_values = [ 'IsText', 'MinStr', 'MaxStr', 'MinNum', 'MaxNum', 'Label', |
140 |
|
|
'Precision', 'IsNoData' ] |
141 |
|
|
|
142 |
|
|
def GetThubanRange(self): |
143 |
jan |
1733 |
"""Return a Thuban range that corresponds to this object. |
144 |
jan |
2378 |
|
145 |
jan |
1733 |
The returned object is a |
146 |
|
|
- Range-Object in case of a numerical range. |
147 |
|
|
- String-Object in case of a text range (assuming that |
148 |
|
|
text objects occur only with 'MinStr' == 'MaxStr'. |
149 |
|
|
""" |
150 |
|
|
if hasattr(self, 'IsText'): |
151 |
|
|
if hasattr(self, 'MinStr'): |
152 |
|
|
return self.MinStr |
153 |
|
|
else: |
154 |
|
|
return '' |
155 |
|
|
|
156 |
jan |
1725 |
# build range |
157 |
|
|
if hasattr(self, 'MinNum'): |
158 |
|
|
range_str = ']' + self.MinNum + ';' |
159 |
|
|
else: |
160 |
|
|
range_str = ']-oo;' |
161 |
|
|
if hasattr(self, 'MaxNum'): |
162 |
|
|
range_str = range_str + self.MaxNum + ']' |
163 |
|
|
else: |
164 |
|
|
range_str = None |
165 |
|
|
|
166 |
|
|
if hasattr(self, 'MinNum') and hasattr(self, 'MaxNum'): |
167 |
|
|
if self.MinNum == self.MaxNum: |
168 |
|
|
range_str = '[' + self.MinNum + ';' + self.MaxNum + ']' |
169 |
|
|
return Range(range_str) |
170 |
|
|
|
171 |
|
|
def GetLabel(self): |
172 |
|
|
"""Return the label string. |
173 |
|
|
Return an empty string if there is no 'Label'. |
174 |
|
|
""" |
175 |
|
|
if hasattr(self, 'Label'): |
176 |
|
|
return self.Label |
177 |
|
|
else: |
178 |
|
|
return '' |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
class APR_TClr(ODBBaseObject): |
182 |
|
|
"""Color object. Appears in 3 styles: |
183 |
|
|
1. no attributes: (so far assumed as black) |
184 |
|
|
2. only 'Name': a string that describes the color. |
185 |
|
|
Seen only "Transparent". |
186 |
|
|
3. 'Red', 'Green', 'Blue': RGB code. Each value in '0xffff' style. |
187 |
|
|
3.1 Only one or two of the colors are defined. It is assumed |
188 |
|
|
that in this case the rest is equal to 0x0000 |
189 |
|
|
3.2 Some hex-codes are incomplete (eg. 0xff). It is assumed |
190 |
|
|
that the missing digits are "0". |
191 |
|
|
|
192 |
|
|
No referenced objects. |
193 |
|
|
""" |
194 |
|
|
_obj_refs = [ ] |
195 |
|
|
_values = [ 'Name', 'Red', 'Green', 'Blue' ] |
196 |
|
|
|
197 |
|
|
def GetThubanColor(self): |
198 |
|
|
"""Return a Thuban Color object; returns None if a problem |
199 |
|
|
occured. |
200 |
|
|
""" |
201 |
|
|
if hasattr(self, 'Red') or hasattr(self, 'Green') or \ |
202 |
|
|
hasattr(self, 'Blue'): |
203 |
|
|
rgb = { 'Red': 0, 'Green': 0, 'Blue': 0 } # default for missing |
204 |
|
|
# parts: 0x0000 |
205 |
|
|
|
206 |
|
|
for color in [ 'Red', 'Green', 'Blue' ]: |
207 |
|
|
if hasattr(self, color): |
208 |
|
|
s = getattr(self, color) |
209 |
jan |
2629 |
# It seems that ArcView sometimes uses only |
210 |
|
|
# 2 bytes for a color definition, eg. 0xff. |
211 |
|
|
# It is assumed that this is the same as |
212 |
|
|
# 0x00ff (and not the same as 0xff00). At |
213 |
|
|
# least color comparison shows this. |
214 |
|
|
# Thus we do not need to append "00" if length |
215 |
|
|
# of s is < 6. The following conversion does is |
216 |
|
|
# right even for the short strings. |
217 |
jan |
1725 |
rgb[color] = int(s, 16)/float(int('0xffff', 16)) |
218 |
|
|
return Color(rgb['Red'], rgb['Green'], rgb['Blue']) |
219 |
|
|
elif hasattr(self, 'Name'): |
220 |
|
|
if self.Name == 'Transparent': |
221 |
|
|
return Transparent |
222 |
|
|
else: |
223 |
|
|
return None |
224 |
|
|
else: |
225 |
|
|
return Black |