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: |
if len(dataInfo) == 1: |
221 |
if type != ClassData.POINT: |
if not isinstance(data, ClassGroupSingleton): |
222 |
data = ClassDataPoint(classData = data) |
ndata = ClassGroupSingleton(prop = data) |
223 |
data.SetValue(dataInfo[1]) |
ndata.SetValue(dataInfo[1]) |
224 |
self.tdata[row][COL_VALUE] = data.GetValue() |
elif len(dataInfo) == 2: |
225 |
elif dataInfo[0] == ClassData.RANGE: |
if not isinstance(data, ClassGroupRange): |
|
if type != ClassData.RANGE: |
|
226 |
data = ClassDataRange(classData = data) |
data = ClassDataRange(classData = data) |
227 |
data.SetRange(dataInfo[1], dataInfo[2]) |
data.SetRange(dataInfo[1], dataInfo[2]) |
|
self.tdata[row][COL_VALUE] = \ |
|
|
"%s - %s" % (data.GetMin(), data.GetMax()) |
|
228 |
|
|
229 |
self.tdata[row][COL_VISUAL] = data |
ndata.SetLabel(data.GetLabel()) |
230 |
|
self.__SetRow(row, ndata) |
231 |
|
|
232 |
|
#self.tdata[row][COL_VISUAL] = data |
233 |
|
|
234 |
self.GetView().Refresh() |
self.GetView().Refresh() |
235 |
|
|
251 |
|
|
252 |
return attr |
return attr |
253 |
|
|
254 |
def GetClassData(self, row): |
def GetClassGroup(self, row): |
255 |
return self.tdata[row][COL_VISUAL] |
return self.tdata[row][COL_VISUAL] |
256 |
|
|
257 |
def __Modified(self): |
def __Modified(self): |
290 |
style = wxCB_READONLY) |
style = wxCB_READONLY) |
291 |
|
|
292 |
self.num_cols = layer.table.field_count() |
self.num_cols = layer.table.field_count() |
293 |
self.__cur_prop = -1 |
# just assume the first field in case one hasn't been |
294 |
|
# specified in the file. |
295 |
|
self.__cur_prop = 0 |
296 |
field = layer.GetClassification().GetField() |
field = layer.GetClassification().GetField() |
297 |
for i in range(self.num_cols): |
for i in range(self.num_cols): |
298 |
type, name, len, decc = layer.table.field_info(i) |
type, name, len, decc = layer.table.field_info(i) |
356 |
|
|
357 |
if numRows > 0: |
if numRows > 0: |
358 |
table = self.classGrid.GetTable() |
table = self.classGrid.GetTable() |
359 |
clazz.SetDefaultData(table.GetClassData(0)) |
clazz.SetDefaultGroup(table.GetClassGroup(0)) |
360 |
|
|
361 |
for i in range(1, numRows): |
for i in range(1, numRows): |
362 |
clazz.AddClassData(table.GetClassData(i)) |
clazz.AddGroup(table.GetClassGroup(i)) |
363 |
|
|
364 |
return clazz |
return clazz |
365 |
|
|
409 |
r = event.GetRow() |
r = event.GetRow() |
410 |
c = event.GetCol() |
c = event.GetCol() |
411 |
if c == COL_VISUAL: |
if c == COL_VISUAL: |
412 |
prop = self.classGrid.GetTable().GetValueAsCustom(r, c, None) |
# XXX: getting the properties is only possible with non-Maps!!! |
413 |
|
group = self.classGrid.GetTable().GetValueAsCustom(r, c, None) |
414 |
|
prop = group.GetProperties() |
415 |
propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType()) |
propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType()) |
416 |
if propDlg.ShowModal() == wxID_OK: |
if propDlg.ShowModal() == wxID_OK: |
417 |
new_prop = propDlg.GetClassData() |
new_prop = propDlg.GetClassGroupProperties() |
418 |
prop.SetStroke(new_prop.GetStroke()) |
prop.SetStroke(new_prop.GetStroke()) |
419 |
prop.SetStrokeWidth(new_prop.GetStrokeWidth()) |
prop.SetStrokeWidth(new_prop.GetStrokeWidth()) |
420 |
prop.SetFill(new_prop.GetFill()) |
prop.SetFill(new_prop.GetFill()) |
435 |
wxDialog.__init__(self, parent, -1, _("Select Properties"), |
wxDialog.__init__(self, parent, -1, _("Select Properties"), |
436 |
style = wxRESIZE_BORDER) |
style = wxRESIZE_BORDER) |
437 |
|
|
438 |
self.prop = ClassData(classData = prop) |
self.prop = ClassGroupProperties(prop) |
439 |
|
|
440 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
441 |
|
|
532 |
self.prop.SetFill(clr) |
self.prop.SetFill(clr) |
533 |
self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer |
self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer |
534 |
|
|
535 |
def GetClassData(self): |
def GetClassGroupProperties(self): |
536 |
return self.prop |
return self.prop |
537 |
|
|
538 |
|
|
539 |
class ClassDataPreviewer(wxWindow): |
class ClassDataPreviewer(wxWindow): |
540 |
|
|
541 |
def __init__(self, rect, data, shapeType, |
def __init__(self, rect, prop, shapeType, |
542 |
parent = None, id = -1, size = wxDefaultSize): |
parent = None, id = -1, size = wxDefaultSize): |
543 |
if parent is not None: |
if parent is not None: |
544 |
wxWindow.__init__(self, parent, id, size=size) |
wxWindow.__init__(self, parent, id, size=size) |
545 |
EVT_PAINT(self, self.OnPaint) |
EVT_PAINT(self, self.OnPaint) |
546 |
|
|
547 |
self.rect = rect |
self.rect = rect |
548 |
self.data = data |
self.prop = prop |
549 |
self.shapeType = shapeType |
self.shapeType = shapeType |
550 |
|
|
551 |
def OnPaint(self, event): |
def OnPaint(self, event): |
556 |
|
|
557 |
self.Draw(dc, None) |
self.Draw(dc, None) |
558 |
|
|
559 |
def Draw(self, dc, rect, data = None, shapeType = None): |
def Draw(self, dc, rect, prop = None, shapeType = None): |
560 |
|
|
561 |
if data is None: data = self.data |
if prop is None: prop = self.prop |
562 |
if shapeType is None: shapeType = self.shapeType |
if shapeType is None: shapeType = self.shapeType |
563 |
|
|
564 |
if rect is None: |
if rect is None: |
570 |
w = rect.GetWidth() |
w = rect.GetWidth() |
571 |
h = rect.GetHeight() |
h = rect.GetHeight() |
572 |
|
|
573 |
stroke = data.GetStroke() |
stroke = prop.GetStroke() |
574 |
if stroke is Color.None: |
if stroke is Color.None: |
575 |
pen = wxTRANSPARENT_PEN |
pen = wxTRANSPARENT_PEN |
576 |
else: |
else: |
577 |
pen = wxPen(Color2wxColour(stroke), |
pen = wxPen(Color2wxColour(stroke), |
578 |
data.GetStrokeWidth(), |
prop.GetStrokeWidth(), |
579 |
wxSOLID) |
wxSOLID) |
580 |
|
|
581 |
stroke = data.GetFill() |
stroke = prop.GetFill() |
582 |
if stroke is Color.None: |
if stroke is Color.None: |
583 |
brush = wxTRANSPARENT_BRUSH |
brush = wxTRANSPARENT_BRUSH |
584 |
else: |
else: |
597 |
shapeType == SHAPETYPE_POLYGON: |
shapeType == SHAPETYPE_POLYGON: |
598 |
|
|
599 |
dc.DrawCircle(x + w/2, y + h/2, |
dc.DrawCircle(x + w/2, y + h/2, |
600 |
(min(w, h) - data.GetStrokeWidth())/2) |
(min(w, h) - prop.GetStrokeWidth())/2) |
601 |
|
|
602 |
class ClassRenderer(wxPyGridCellRenderer): |
class ClassRenderer(wxPyGridCellRenderer): |
603 |
|
|
616 |
dc.DrawRectangle(rect.GetX(), rect.GetY(), |
dc.DrawRectangle(rect.GetX(), rect.GetY(), |
617 |
rect.GetWidth(), rect.GetHeight()) |
rect.GetWidth(), rect.GetHeight()) |
618 |
|
|
619 |
self.previewer.Draw(dc, rect, data) |
if not isinstance(data, ClassGroupMap): |
620 |
|
self.previewer.Draw(dc, rect, data.GetProperties()) |
621 |
|
|
622 |
if isSelected: |
if isSelected: |
623 |
dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255), |
dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255), |