16 |
|
|
17 |
from Thuban import _ |
from Thuban import _ |
18 |
from Thuban.common import * |
from Thuban.common import * |
19 |
|
from Thuban.UI.common import * |
20 |
|
|
21 |
from Thuban.Model.classification import * #Classification, ClassData |
from Thuban.Model.classification import * #Classification, ClassData |
22 |
|
|
66 |
|
|
67 |
__col_labels = [_("Visual"), _("Value"), _("Label")] |
__col_labels = [_("Visual"), _("Value"), _("Label")] |
68 |
|
|
|
# this is tied to the values of classification.ClassData |
|
|
__row_labels = [_("Default"), _("Point"), _("Range"), _("Map")] |
|
|
|
|
69 |
def __init__(self, clazz, shapeType, view = None): |
def __init__(self, clazz, shapeType, view = None): |
70 |
wxPyGridTableBase.__init__(self) |
wxPyGridTableBase.__init__(self) |
71 |
self.SetView(view) |
self.SetView(view) |
87 |
if clazz is None: |
if clazz is None: |
88 |
clazz = Classification() |
clazz = Classification() |
89 |
|
|
90 |
p = clazz.GetDefaultData() |
# p = clazz.GetDefaultGroup() |
91 |
np = ClassDataDefault(classData = p) |
# np = ClassDataDefault(classData = p) |
92 |
self.tdata.append([np, 'DEFAULT', np.GetLabel()]) |
# self.tdata.append([np, 'DEFAULT', np.GetLabel()]) |
93 |
|
|
94 |
for p in clazz.points.values(): |
# for p in clazz.points.values(): |
95 |
np = ClassDataPoint(p.GetValue(), classData = p) |
# np = ClassDataPoint(p.GetValue(), classData = p) |
96 |
self.tdata.append([np, np.GetValue(), np.GetLabel()]) |
# self.tdata.append([np, np.GetValue(), np.GetLabel()]) |
97 |
|
|
98 |
for p in clazz.ranges: |
# for p in clazz.ranges: |
99 |
np = ClassDataRange(p.GetMin(), p.GetMax(), classData = p) |
# np = ClassDataRange(p.GetMin(), p.GetMax(), classData = p) |
100 |
self.tdata.append([np, |
# self.tdata.append([np, |
101 |
'%s - %s' % (np.GetMin(), np.GetMax()), |
# '%s - %s' % (np.GetMin(), np.GetMax()), |
102 |
np.GetLabel()]) |
# np.GetLabel()]) |
103 |
|
|
104 |
|
i = 0 |
105 |
|
for p in clazz: |
106 |
|
np = copy.copy(p) |
107 |
|
self.__SetRow(i, np) |
108 |
|
i += 1 |
109 |
|
|
110 |
|
|
111 |
self.modified = 0 |
self.modified = 0 |
112 |
|
|
113 |
# |
# |
130 |
|
|
131 |
self.GetView().EndBatch() |
self.GetView().EndBatch() |
132 |
|
|
133 |
|
def __SetRow(self, row, group): |
134 |
|
|
135 |
|
if isinstance(group, ClassGroupDefault): |
136 |
|
data = [group, 'DEFAULT', group.GetLabel()] |
137 |
|
elif isinstance(group, ClassGroupSingleton): |
138 |
|
data = [group, group.GetValue(), group.GetLabel()] |
139 |
|
elif isinstance(group, ClassGroupRange): |
140 |
|
data = [group, |
141 |
|
'%s - %s' % (group.GetMin(), group.GetMax()), |
142 |
|
group.GetLabel()] |
143 |
|
|
144 |
|
if row >= len(self.tdata): |
145 |
|
self.tdata.append(data) |
146 |
|
else: |
147 |
|
self.tdata[row] = data |
148 |
|
|
149 |
def GetColLabelValue(self, col): |
def GetColLabelValue(self, col): |
150 |
return self.__col_labels[col] |
return self.__col_labels[col] |
151 |
|
|
152 |
def GetRowLabelValue(self, row): |
def GetRowLabelValue(self, row): |
153 |
data = self.tdata[row][COL_VISUAL] |
data = self.tdata[row][COL_VISUAL] |
154 |
type = data.GetType() |
if isinstance(data, ClassGroupDefault): return _("Default") |
155 |
return self.__row_labels[type] |
if isinstance(data, ClassGroupSingleton): return _("Singleton") |
156 |
|
if isinstance(data, ClassGroupRange): return _("Range") |
157 |
|
if isinstance(data, ClassGroupMap): return _("Map") |
158 |
|
|
159 |
def GetNumberRows(self): |
def GetNumberRows(self): |
160 |
return len(self.tdata) |
return len(self.tdata) |
190 |
# function. |
# function. |
191 |
# |
# |
192 |
try: |
try: |
193 |
return (ClassData.POINT, Str2Num(value)) |
return (Str2Num(value),) |
194 |
except: |
except: |
195 |
i = value.find('-') |
i = value.find('-') |
196 |
if i == 0: |
if i == 0: |
197 |
i = value.find('-', 1) |
i = value.find('-', 1) |
198 |
|
|
199 |
return (ClassData.RANGE, |
return (Str2Num(value[:i]), Str2Num(value[i+1:])) |
|
Str2Num(value[:i]), |
|
|
Str2Num(value[i+1:])) |
|
200 |
|
|
201 |
|
|
202 |
def SetValueAsCustom(self, row, col, typeName, value): |
def SetValueAsCustom(self, row, col, typeName, value): |
206 |
self.tdata[row][COL_VISUAL] = value |
self.tdata[row][COL_VISUAL] = value |
207 |
elif col == COL_VALUE: |
elif col == COL_VALUE: |
208 |
if row != 0: # DefaultData row |
if row != 0: # DefaultData row |
|
type = data.GetType() |
|
209 |
|
|
210 |
if type == ClassData.MAP: |
if isinstance(data, ClassGroupMap): |
211 |
# something special |
# something special |
212 |
pass |
pass |
213 |
else: # POINT, RANGE |
else: # POINT, RANGE |
217 |
# bad input, ignore the request |
# bad input, ignore the request |
218 |
else: |
else: |
219 |
|
|
220 |
if dataInfo[0] == ClassData.POINT: |
ndata = data |
221 |
if type != ClassData.POINT: |
if len(dataInfo) == 1: |
222 |
data = ClassDataPoint(classData = data) |
if not isinstance(data, ClassGroupSingleton): |
223 |
data.SetValue(dataInfo[1]) |
ndata = ClassGroupSingleton(prop = data) |
224 |
self.tdata[row][COL_VALUE] = data.GetValue() |
ndata.SetValue(dataInfo[0]) |
225 |
elif dataInfo[0] == ClassData.RANGE: |
elif len(dataInfo) == 2: |
226 |
if type != ClassData.RANGE: |
if not isinstance(data, ClassGroupRange): |
227 |
data = ClassDataRange(classData = data) |
data = ClassDataRange(classData = data) |
228 |
data.SetRange(dataInfo[1], dataInfo[2]) |
data.SetRange(dataInfo[0], dataInfo[1]) |
229 |
self.tdata[row][COL_VALUE] = \ |
|
230 |
"%s - %s" % (data.GetMin(), data.GetMax()) |
ndata.SetLabel(data.GetLabel()) |
231 |
|
self.__SetRow(row, ndata) |
232 |
|
|
233 |
self.tdata[row][COL_VISUAL] = data |
#self.tdata[row][COL_VISUAL] = data |
234 |
|
|
235 |
self.GetView().Refresh() |
self.GetView().Refresh() |
236 |
|
|
252 |
|
|
253 |
return attr |
return attr |
254 |
|
|
255 |
def GetClassData(self, row): |
def GetClassGroup(self, row): |
256 |
return self.tdata[row][COL_VISUAL] |
return self.tdata[row][COL_VISUAL] |
257 |
|
|
258 |
def __Modified(self): |
def __Modified(self): |
291 |
style = wxCB_READONLY) |
style = wxCB_READONLY) |
292 |
|
|
293 |
self.num_cols = layer.table.field_count() |
self.num_cols = layer.table.field_count() |
294 |
self.__cur_prop = -1 |
# just assume the first field in case one hasn't been |
295 |
|
# specified in the file. |
296 |
|
self.__cur_prop = 0 |
297 |
field = layer.GetClassification().GetField() |
field = layer.GetClassification().GetField() |
298 |
for i in range(self.num_cols): |
for i in range(self.num_cols): |
299 |
type, name, len, decc = layer.table.field_info(i) |
type, name, len, decc = layer.table.field_info(i) |
357 |
|
|
358 |
if numRows > 0: |
if numRows > 0: |
359 |
table = self.classGrid.GetTable() |
table = self.classGrid.GetTable() |
360 |
clazz.SetDefaultData(table.GetClassData(0)) |
clazz.SetDefaultGroup(table.GetClassGroup(0)) |
361 |
|
|
362 |
for i in range(1, numRows): |
for i in range(1, numRows): |
363 |
clazz.AddClassData(table.GetClassData(i)) |
clazz.AddGroup(table.GetClassGroup(i)) |
364 |
|
|
365 |
return clazz |
return clazz |
366 |
|
|
410 |
r = event.GetRow() |
r = event.GetRow() |
411 |
c = event.GetCol() |
c = event.GetCol() |
412 |
if c == COL_VISUAL: |
if c == COL_VISUAL: |
413 |
prop = self.classGrid.GetTable().GetValueAsCustom(r, c, None) |
# XXX: getting the properties is only possible with non-Maps!!! |
414 |
|
group = self.classGrid.GetTable().GetValueAsCustom(r, c, None) |
415 |
|
prop = group.GetProperties() |
416 |
propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType()) |
propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType()) |
417 |
if propDlg.ShowModal() == wxID_OK: |
if propDlg.ShowModal() == wxID_OK: |
418 |
new_prop = propDlg.GetClassData() |
new_prop = propDlg.GetClassGroupProperties() |
419 |
prop.SetStroke(new_prop.GetStroke()) |
prop.SetStroke(new_prop.GetStroke()) |
420 |
prop.SetStrokeWidth(new_prop.GetStrokeWidth()) |
prop.SetStrokeWidth(new_prop.GetStrokeWidth()) |
421 |
prop.SetFill(new_prop.GetFill()) |
prop.SetFill(new_prop.GetFill()) |
436 |
wxDialog.__init__(self, parent, -1, _("Select Properties"), |
wxDialog.__init__(self, parent, -1, _("Select Properties"), |
437 |
style = wxRESIZE_BORDER) |
style = wxRESIZE_BORDER) |
438 |
|
|
439 |
self.prop = ClassData(classData = prop) |
self.prop = ClassGroupProperties(prop) |
440 |
|
|
441 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
442 |
|
|
533 |
self.prop.SetFill(clr) |
self.prop.SetFill(clr) |
534 |
self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer |
self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer |
535 |
|
|
536 |
def GetClassData(self): |
def GetClassGroupProperties(self): |
537 |
return self.prop |
return self.prop |
538 |
|
|
539 |
|
|
540 |
class ClassDataPreviewer(wxWindow): |
class ClassDataPreviewer(wxWindow): |
541 |
|
|
542 |
def __init__(self, rect, data, shapeType, |
def __init__(self, rect, prop, shapeType, |
543 |
parent = None, id = -1, size = wxDefaultSize): |
parent = None, id = -1, size = wxDefaultSize): |
544 |
if parent is not None: |
if parent is not None: |
545 |
wxWindow.__init__(self, parent, id, size=size) |
wxWindow.__init__(self, parent, id, size=size) |
546 |
EVT_PAINT(self, self.OnPaint) |
EVT_PAINT(self, self.OnPaint) |
547 |
|
|
548 |
self.rect = rect |
self.rect = rect |
549 |
self.data = data |
self.prop = prop |
550 |
self.shapeType = shapeType |
self.shapeType = shapeType |
551 |
|
|
552 |
def OnPaint(self, event): |
def OnPaint(self, event): |
557 |
|
|
558 |
self.Draw(dc, None) |
self.Draw(dc, None) |
559 |
|
|
560 |
def Draw(self, dc, rect, data = None, shapeType = None): |
def Draw(self, dc, rect, prop = None, shapeType = None): |
561 |
|
|
562 |
if data is None: data = self.data |
if prop is None: prop = self.prop |
563 |
if shapeType is None: shapeType = self.shapeType |
if shapeType is None: shapeType = self.shapeType |
564 |
|
|
565 |
if rect is None: |
if rect is None: |
571 |
w = rect.GetWidth() |
w = rect.GetWidth() |
572 |
h = rect.GetHeight() |
h = rect.GetHeight() |
573 |
|
|
574 |
stroke = data.GetStroke() |
stroke = prop.GetStroke() |
575 |
if stroke is Color.None: |
if stroke is Color.None: |
576 |
pen = wxTRANSPARENT_PEN |
pen = wxTRANSPARENT_PEN |
577 |
else: |
else: |
578 |
pen = wxPen(Color2wxColour(stroke), |
pen = wxPen(Color2wxColour(stroke), |
579 |
data.GetStrokeWidth(), |
prop.GetStrokeWidth(), |
580 |
wxSOLID) |
wxSOLID) |
581 |
|
|
582 |
stroke = data.GetFill() |
stroke = prop.GetFill() |
583 |
if stroke is Color.None: |
if stroke is Color.None: |
584 |
brush = wxTRANSPARENT_BRUSH |
brush = wxTRANSPARENT_BRUSH |
585 |
else: |
else: |
598 |
shapeType == SHAPETYPE_POLYGON: |
shapeType == SHAPETYPE_POLYGON: |
599 |
|
|
600 |
dc.DrawCircle(x + w/2, y + h/2, |
dc.DrawCircle(x + w/2, y + h/2, |
601 |
(min(w, h) - data.GetStrokeWidth())/2) |
(min(w, h) - prop.GetStrokeWidth())/2) |
602 |
|
|
603 |
class ClassRenderer(wxPyGridCellRenderer): |
class ClassRenderer(wxPyGridCellRenderer): |
604 |
|
|
617 |
dc.DrawRectangle(rect.GetX(), rect.GetY(), |
dc.DrawRectangle(rect.GetX(), rect.GetY(), |
618 |
rect.GetWidth(), rect.GetHeight()) |
rect.GetWidth(), rect.GetHeight()) |
619 |
|
|
620 |
self.previewer.Draw(dc, rect, data) |
if not isinstance(data, ClassGroupMap): |
621 |
|
self.previewer.Draw(dc, rect, data.GetProperties()) |
622 |
|
|
623 |
if isSelected: |
if isSelected: |
624 |
dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255), |
dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255), |