1 |
jonathan |
372 |
# Copyright (c) 2001 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Jonathan Coles <[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 |
|
|
"""Dialog for classifying how layers are displayed""" |
9 |
|
|
|
10 |
|
|
__version__ = "$Revision$" |
11 |
|
|
|
12 |
jonathan |
376 |
import copy |
13 |
|
|
|
14 |
jonathan |
372 |
from wxPython.wx import * |
15 |
|
|
from wxPython.grid import * |
16 |
|
|
|
17 |
jan |
374 |
from Thuban import _ |
18 |
|
|
|
19 |
jonathan |
392 |
from Thuban.Model.classification import Classification |
20 |
|
|
|
21 |
|
|
from Thuban.Model.layer import SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT |
22 |
|
|
|
23 |
jonathan |
372 |
ID_PROPERTY_SELECT = 4010 |
24 |
|
|
ID_CLASS_TABLE = 40011 |
25 |
|
|
|
26 |
|
|
ID_CLASSIFY_OK = 4001 |
27 |
|
|
ID_CLASSIFY_CANCEL = 4002 |
28 |
|
|
|
29 |
jonathan |
376 |
class ClassTable(wxPyGridTableBase): |
30 |
|
|
|
31 |
|
|
def __init__(self, clinfo): |
32 |
|
|
wxPyGridTableBase.__init__(self) |
33 |
|
|
|
34 |
|
|
self.tdata = [] |
35 |
|
|
|
36 |
jonathan |
398 |
self.tdata.append([clinfo.DefaultData, 'DEFAULT']) |
37 |
jonathan |
392 |
|
38 |
jonathan |
398 |
for value, data in clinfo.points.items(): |
39 |
jonathan |
376 |
self.tdata.append([data, value]) |
40 |
|
|
|
41 |
|
|
for range in self.clinfo.ranges: |
42 |
|
|
self.tdata.append([range[2], '%s-%s' % range[0], range[1]]) |
43 |
|
|
|
44 |
jonathan |
379 |
self.SetColLabelValue(1, _("Data Values")) |
45 |
jonathan |
376 |
|
46 |
|
|
def GetNumberRows(self): |
47 |
|
|
return len(self.tdata) |
48 |
|
|
|
49 |
|
|
def GetNumberCols(self): |
50 |
|
|
return 2 |
51 |
|
|
|
52 |
|
|
def IsEmptyCell(self, row, col): |
53 |
|
|
return false |
54 |
|
|
|
55 |
|
|
def GetValue(self, row, col): |
56 |
|
|
return self.tdata[row][col] |
57 |
|
|
|
58 |
|
|
def SetValue(self, row, col, value): |
59 |
jonathan |
392 |
self.tdata[row][col] = value |
60 |
jonathan |
376 |
|
61 |
jonathan |
392 |
def GetValueAsCustom(self, row, col, typeName): |
62 |
|
|
return self.tdata[row][col] |
63 |
jonathan |
376 |
|
64 |
jonathan |
392 |
|
65 |
jonathan |
372 |
class Classifier(wxDialog): |
66 |
|
|
|
67 |
|
|
def __init__(self, parent, layer): |
68 |
jan |
374 |
wxDialog.__init__(self, parent, -1, _("Classify"), |
69 |
jonathan |
372 |
style = wxRESIZE_BORDER) |
70 |
|
|
|
71 |
|
|
topBox = wxBoxSizer(wxVERTICAL) |
72 |
|
|
|
73 |
|
|
propertyBox = wxBoxSizer(wxHORIZONTAL) |
74 |
jan |
374 |
propertyBox.Add(wxStaticText(self, -1, _("Property")), |
75 |
jonathan |
372 |
0, wxALIGN_CENTER | wxALL, 4) |
76 |
|
|
|
77 |
|
|
self.properties = wxComboBox(self, ID_PROPERTY_SELECT, "", |
78 |
|
|
style = wxCB_READONLY) |
79 |
|
|
|
80 |
|
|
self.num_cols = layer.table.field_count() |
81 |
jonathan |
376 |
cur_hilight = 0 |
82 |
jonathan |
372 |
for i in range(self.num_cols): |
83 |
|
|
type, name, len, decc = layer.table.field_info(i) |
84 |
jonathan |
376 |
if name == layer.classification.field: |
85 |
|
|
cur_hilight = i |
86 |
jonathan |
372 |
self.properties.Append(name) |
87 |
|
|
|
88 |
jonathan |
376 |
self.properties.SetSelection(cur_hilight) |
89 |
jonathan |
392 |
propertyBox.Add(self.properties, 1, wxGROW, 4) |
90 |
jonathan |
372 |
EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnPropertySelect) |
91 |
|
|
|
92 |
jonathan |
376 |
topBox.Add(propertyBox, 0, wxGROW, 4) |
93 |
jonathan |
372 |
|
94 |
|
|
# |
95 |
|
|
# Classification data table |
96 |
|
|
# |
97 |
|
|
|
98 |
jonathan |
376 |
self.classTable = wxGrid(self, ID_CLASS_TABLE, size=(300, 150)) |
99 |
|
|
|
100 |
|
|
table = ClassTable(layer.classification) |
101 |
jonathan |
372 |
self.classTable.SetTable(table, true) |
102 |
jonathan |
392 |
self.classTable.EnableEditing(false) |
103 |
|
|
cr = ClassRenderer(layer.ShapeType()) |
104 |
|
|
for i in range(self.classTable.GetNumberRows()): |
105 |
|
|
self.classTable.SetCellRenderer(i, 0, cr) |
106 |
jonathan |
376 |
|
107 |
jonathan |
392 |
topBox.Add(self.classTable, 1, wxGROW, 0) |
108 |
jonathan |
372 |
|
109 |
|
|
# |
110 |
|
|
# Control buttons: |
111 |
|
|
# |
112 |
|
|
buttonBox = wxBoxSizer(wxHORIZONTAL) |
113 |
jan |
374 |
buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")), |
114 |
jonathan |
372 |
0, wxALL, 4) |
115 |
jan |
374 |
buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")), |
116 |
jonathan |
372 |
0, wxALL, 4) |
117 |
|
|
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10) |
118 |
|
|
|
119 |
|
|
EVT_BUTTON(self, ID_CLASSIFY_OK, self.OnOK) |
120 |
|
|
EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self.OnCancel) |
121 |
|
|
|
122 |
|
|
self.SetAutoLayout(true) |
123 |
|
|
self.SetSizer(topBox) |
124 |
|
|
topBox.Fit(self) |
125 |
|
|
topBox.SetSizeHints(self) |
126 |
|
|
|
127 |
|
|
def OnPropertySelect(self, event): pass |
128 |
|
|
|
129 |
|
|
def OnOK(self, event): |
130 |
|
|
self.EndModal(wxID_OK) |
131 |
|
|
|
132 |
|
|
def OnCancel(self, event): |
133 |
|
|
self.EndModal(wxID_CANCEL) |
134 |
|
|
|
135 |
jonathan |
392 |
|
136 |
|
|
class ClassRenderer(wxPyGridCellRenderer): |
137 |
|
|
|
138 |
|
|
def __init__(self, shapeType): |
139 |
|
|
wxPyGridCellRenderer.__init__(self) |
140 |
|
|
self.shapeType = shapeType |
141 |
|
|
|
142 |
|
|
def Draw(self, grid, attr, dc, rect, row, col, isSelected): |
143 |
|
|
value = grid.GetTable().GetValueAsCustom(row, col, "") |
144 |
|
|
# XXX: check if value is a dictionary |
145 |
|
|
stroke = value.GetStroke() |
146 |
|
|
if stroke is None: |
147 |
|
|
pen = wxTRANSPARENT_PEN |
148 |
|
|
else: |
149 |
|
|
pen = wxPen(wxColour(stroke.red * 255, |
150 |
|
|
stroke.green * 255, |
151 |
|
|
stroke.blue * 255), |
152 |
|
|
value.GetStrokeWidth(), |
153 |
|
|
wxSOLID) |
154 |
|
|
|
155 |
|
|
stroke = value.GetFill() |
156 |
|
|
if stroke is None: |
157 |
|
|
brush = wxTRANSPARENT_BRUSH |
158 |
|
|
else: |
159 |
|
|
brush = wxBrush(wxColour(stroke.red * 255, |
160 |
|
|
stroke.green * 255, |
161 |
|
|
stroke.blue * 255), wxSOLID) |
162 |
|
|
|
163 |
|
|
dc.SetClippingRegion(rect.GetX(), rect.GetY(), |
164 |
|
|
rect.GetWidth(), rect.GetHeight()) |
165 |
|
|
dc.SetPen(wxPen(wxLIGHT_GREY)) |
166 |
|
|
dc.SetBrush(wxBrush(wxLIGHT_GREY, wxSOLID)) |
167 |
|
|
dc.DrawRectangle(rect.GetX(), rect.GetY(), |
168 |
|
|
rect.GetWidth(), rect.GetHeight()) |
169 |
|
|
|
170 |
|
|
dc.SetPen(pen) |
171 |
|
|
dc.SetBrush(brush) |
172 |
|
|
|
173 |
|
|
if self.shapeType == SHAPETYPE_ARC: |
174 |
|
|
dc.DrawSpline([wxPoint(rect.GetX(), rect.GetY() + rect.GetHeight()), |
175 |
|
|
wxPoint(rect.GetX() + rect.GetWidth()/2, |
176 |
|
|
rect.GetY() + rect.GetHeight()/4), |
177 |
|
|
wxPoint(rect.GetX() + rect.GetWidth()/2, |
178 |
|
|
rect.GetY() + rect.GetHeight()/4*3), |
179 |
|
|
wxPoint(rect.GetX() + rect.GetWidth(), rect.GetY())]) |
180 |
|
|
|
181 |
|
|
elif self.shapeType == SHAPETYPE_POINT or self.shapeType == SHAPETYPE_POLYGON: |
182 |
|
|
dc.DrawCircle(rect.GetX() + rect.GetWidth()/2, |
183 |
|
|
rect.GetY() + rect.GetHeight()/2, |
184 |
|
|
(min(rect.GetWidth(), rect.GetHeight()) |
185 |
|
|
- value.GetStrokeWidth())/2) |
186 |
|
|
|
187 |
|
|
dc.DestroyClippingRegion() |
188 |
|
|
|
189 |
|
|
|