16 |
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
17 |
FIELDTYPE_STRING |
FIELDTYPE_STRING |
18 |
|
|
19 |
|
from Thuban.Model.layer import SHAPETYPE_ARC |
20 |
from Thuban.Model.range import Range |
from Thuban.Model.range import Range |
21 |
|
from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor |
22 |
|
|
23 |
import classifier, resource |
import classifier, resource |
24 |
|
|
25 |
from Thuban.Model.classgen import ClassGenerator, \ |
from Thuban.Model.classgen import \ |
26 |
|
generate_uniform_distribution, generate_singletons, generate_quantiles, \ |
27 |
CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \ |
CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \ |
28 |
HotToColdRamp |
HotToColdRamp |
29 |
|
|
30 |
|
|
31 |
USEALL_BMP = "group_use_all" |
USEALL_BMP = "group_use_all" |
32 |
USE_BMP = "group_use" |
USE_BMP = "group_use" |
33 |
USENOT_BMP = "group_use_not" |
USENOT_BMP = "group_use_not" |
48 |
ID_CLASSGEN_GENCOMBO = 4007 |
ID_CLASSGEN_GENCOMBO = 4007 |
49 |
ID_CLASSGEN_PROPCOMBO = 4008 |
ID_CLASSGEN_PROPCOMBO = 4008 |
50 |
|
|
51 |
|
ID_BORDER_COLOR = 4009 |
52 |
|
ID_BORDER_COLOR_CHANGE = 4010 |
53 |
|
|
54 |
class ClassGenDialog(wxDialog): |
class ClassGenDialog(wxDialog): |
55 |
|
|
56 |
def __init__(self, parent, layer, fieldName): |
def __init__(self, parent, layer, fieldName): |
66 |
self.layer = layer |
self.layer = layer |
67 |
self.clazz = None |
self.clazz = None |
68 |
|
|
69 |
col = layer.table.Column(fieldName) |
col = layer.ShapeStore().Table().Column(fieldName) |
70 |
self.type = col.type |
self.type = col.type |
71 |
|
|
72 |
self.fieldName = fieldName |
self.fieldName = fieldName |
81 |
# panels they will call AllowGenerate() which uses genButton. |
# panels they will call AllowGenerate() which uses genButton. |
82 |
# |
# |
83 |
self.genButton = wxButton(self, wxID_OK, _("Generate")) |
self.genButton = wxButton(self, wxID_OK, _("Generate")) |
84 |
|
self.cancelButton = wxButton(self, wxID_CANCEL, _("Close")) |
85 |
self.genButton.SetDefault() |
self.genButton.SetDefault() |
86 |
|
|
87 |
self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
88 |
|
|
89 |
self.genpanels.append((GENCOMBOSTR_UNIQUE, GenUniquePanel)) |
self.genpanels.append((GENCOMBOSTR_UNIQUE, GenUniquePanel)) |
96 |
|
|
97 |
self.genChoice.SetSelection(0) |
self.genChoice.SetSelection(0) |
98 |
|
|
99 |
self.propPanel = None |
for i in range(self.genChoice.GetCount()): |
100 |
custom_ramp_panel = CustomRampPanel(self, layer.ShapeType()) |
clazz, obj = self.genChoice.GetClientData(i) |
101 |
|
|
102 |
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
if obj is None: |
103 |
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp()) |
obj = clazz(self, self.layer, self.fieldName, self.fieldType) |
104 |
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
obj.Hide() |
105 |
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
self.genChoice.SetClientData(i, [clazz, obj]) |
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel) |
|
106 |
|
|
|
self.propCombo.SetSelection(0) |
|
107 |
|
|
108 |
############# |
############# |
109 |
|
|
129 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
130 |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
131 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
132 |
|
|
133 |
|
# Properties (Ramp) ComboBox |
134 |
|
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
135 |
|
|
136 |
|
self.propPanel = None |
137 |
|
custom_ramp_panel = CustomRampPanel(self, layer.ShapeType()) |
138 |
|
|
139 |
|
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp) |
140 |
|
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp) |
141 |
|
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp) |
142 |
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp) |
143 |
|
self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp) |
144 |
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
145 |
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel) |
146 |
|
|
147 |
|
self.propCombo.SetSelection(0) |
148 |
|
|
149 |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
150 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
151 |
|
|
152 |
|
if layer.ShapeType() != SHAPETYPE_ARC: |
153 |
|
psizer = wxBoxSizer(wxHORIZONTAL) |
154 |
|
self.fix_border_check = wxCheckBox(self, -1, _("Fix Border Color")) |
155 |
|
psizer.Add(self.fix_border_check, 0, wxALL | wxGROW, 4) |
156 |
|
self.border_color = classifier.ClassGroupPropertiesCtrl( |
157 |
|
self, ID_BORDER_COLOR, |
158 |
|
ClassGroupProperties(), SHAPETYPE_ARC, |
159 |
|
style=wxSIMPLE_BORDER, size=(40, 20)) |
160 |
|
psizer.Add(self.border_color, 0, wxALL | wxGROW, 4) |
161 |
|
psizer.Add(wxButton(self, ID_BORDER_COLOR_CHANGE, _("Change")), |
162 |
|
0, wxALL, 4) |
163 |
|
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
164 |
|
EVT_BUTTON(self, ID_BORDER_COLOR_CHANGE, self.OnBorderColorChange) |
165 |
|
else: |
166 |
|
self.border_color = None |
167 |
|
|
168 |
sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4) |
sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4) |
169 |
sizer.Show(custom_ramp_panel, False) |
sizer.Show(custom_ramp_panel, False) |
170 |
|
|
171 |
|
# Finally place the main buttons |
172 |
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
173 |
buttonSizer.Add(self.genButton, 0, wxALL, 4) |
buttonSizer.Add(self.genButton, 0, wxRIGHT|wxEXPAND, 10) |
174 |
buttonSizer.Add(60, 20, 0, wxALL, 4) |
buttonSizer.Add(self.cancelButton, 0, wxRIGHT|wxEXPAND, 10) |
175 |
buttonSizer.Add(wxButton(self, wxID_CANCEL, _("Close")), |
sizer.Add(buttonSizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10) |
|
0, wxALL, 4) |
|
|
sizer.Add(buttonSizer, 0, |
|
|
wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4) |
|
176 |
|
|
177 |
self.SetSizer(sizer) |
self.SetSizer(sizer) |
178 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
223 |
propPanel = self.propCombo.GetClientData(index) |
propPanel = self.propCombo.GetClientData(index) |
224 |
|
|
225 |
ramp = propPanel.GetRamp() |
ramp = propPanel.GetRamp() |
226 |
|
if self.border_color and self.fix_border_check.IsChecked(): |
227 |
|
props = self.border_color.GetProperties() |
228 |
|
lineColor = props.GetLineColor() |
229 |
|
lineWidth = props.GetLineWidth() |
230 |
|
else: |
231 |
|
lineColor = None |
232 |
|
lineWidth = None |
233 |
|
|
234 |
if genSel == GENCOMBOSTR_UNIFORM: |
if genSel == GENCOMBOSTR_UNIFORM: |
235 |
|
|
240 |
and max is not None \ |
and max is not None \ |
241 |
and numGroups is not None: |
and numGroups is not None: |
242 |
|
|
243 |
self.clazz = ClassGenerator().GenUniformDistribution( |
self.clazz = generate_uniform_distribution( |
244 |
min, max, numGroups, ramp, |
min, max, numGroups, ramp, |
245 |
self.type == FIELDTYPE_INT) |
self.type == FIELDTYPE_INT, |
246 |
|
fixes = (lineColor, lineWidth, None)) |
247 |
|
|
248 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
249 |
|
|
251 |
|
|
252 |
list = genPanel.GetValueList() |
list = genPanel.GetValueList() |
253 |
|
|
254 |
if len(list) > 0 \ |
if len(list) > 0: |
255 |
and numGroups is not None: |
self.clazz = generate_singletons(list, ramp, |
256 |
|
(lineColor, lineWidth, None)) |
|
self.clazz = ClassGenerator().GenSingletonsFromList( |
|
|
list, numGroups, ramp) |
|
|
|
|
257 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
258 |
|
|
259 |
elif genSel == GENCOMBOSTR_QUANTILES: |
elif genSel == GENCOMBOSTR_QUANTILES: |
265 |
delta = 1 / float(numGroups) |
delta = 1 / float(numGroups) |
266 |
percents = [delta * i for i in range(1, numGroups + 1)] |
percents = [delta * i for i in range(1, numGroups + 1)] |
267 |
adjusted, self.clazz = \ |
adjusted, self.clazz = \ |
268 |
ClassGenerator().GenQuantiles(_list, percents, ramp, _range) |
generate_quantiles(_list, percents, ramp, _range, |
269 |
|
(lineColor, lineWidth, None)) |
270 |
|
|
271 |
if adjusted: |
if adjusted: |
272 |
dlg = wxMessageDialog(self, |
dlg = wxMessageDialog(self, |
284 |
def OnCancel(self, event): |
def OnCancel(self, event): |
285 |
self.Close() |
self.Close() |
286 |
|
|
287 |
|
def OnBorderColorChange(self, event): |
288 |
|
self.border_color.DoEdit() |
289 |
|
|
290 |
def _OnGenTypeSelect(self, event): |
def _OnGenTypeSelect(self, event): |
291 |
self.__DoOnGenTypeSelect() |
self.__DoOnGenTypeSelect() |
292 |
return |
return |
330 |
|
|
331 |
clazz, obj = choice.GetClientData(sel) |
clazz, obj = choice.GetClientData(sel) |
332 |
|
|
|
if obj is None: |
|
|
obj = clazz(self, self.layer, self.fieldName, self.fieldType) |
|
|
choice.SetClientData(sel, [clazz, obj]) |
|
|
|
|
333 |
if self.curGenPanel is not None: |
if self.curGenPanel is not None: |
334 |
self.curGenPanel.Hide() |
self.curGenPanel.Hide() |
335 |
self.sizer_genPanel.Remove(self.curGenPanel) |
self.sizer_genPanel.Remove(self.curGenPanel) |
535 |
self.parent.AllowGenerate(False) |
self.parent.AllowGenerate(False) |
536 |
|
|
537 |
def _OnRetrieve(self, event): |
def _OnRetrieve(self, event): |
538 |
|
table = self.layer.ShapeStore().Table() |
539 |
if self.layer.table is not None: |
if table is not None: |
540 |
wxBeginBusyCursor() |
ThubanBeginBusyCursor() |
541 |
min, max = self.layer.table.ValueRange(self.fieldName) |
try: |
542 |
self.minCtrl.SetValue(str(min)) |
min, max = table.ValueRange(self.fieldName) |
543 |
self.maxCtrl.SetValue(str(max)) |
self.minCtrl.SetValue(str(min)) |
544 |
wxEndBusyCursor() |
self.maxCtrl.SetValue(str(max)) |
545 |
|
finally: |
546 |
|
ThubanEndBusyCursor() |
547 |
|
|
548 |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
549 |
|
|
585 |
return valid |
return valid |
586 |
|
|
587 |
def __CalcStepping(self, min, max, ngroups): |
def __CalcStepping(self, min, max, ngroups): |
|
step = (max - min) / float(ngroups) |
|
588 |
if self.fieldType == FIELDTYPE_INT: |
if self.fieldType == FIELDTYPE_INT: |
589 |
step = int(step) |
step = int((max - min + 1) / float(ngroups)) |
590 |
|
else: |
591 |
|
step = (max - min) / float(ngroups) |
592 |
|
|
593 |
return step |
return step |
594 |
|
|
705 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
706 |
topSizer.SetSizeHints(self) |
topSizer.SetSizeHints(self) |
707 |
|
|
708 |
|
width, height = self.list_avail.GetSizeTuple() |
709 |
|
self.list_avail.SetColumnWidth(0,width) |
710 |
|
width, height = self.list_use.GetSizeTuple() |
711 |
|
self.list_use.SetColumnWidth(0,width) |
712 |
|
|
713 |
self.parent.AllowGenerate(False) |
self.parent.AllowGenerate(False) |
714 |
|
|
715 |
def GetNumGroups(self): |
def GetNumGroups(self): |
751 |
self.list_avail.DeleteAllItems() |
self.list_avail.DeleteAllItems() |
752 |
self.list_avail_data = [] |
self.list_avail_data = [] |
753 |
|
|
754 |
list = self.layer.table.UniqueValues(self.fieldName) |
ThubanBeginBusyCursor() |
755 |
index = 0 |
try: |
756 |
for v in list: |
list = self.layer.ShapeStore().Table().UniqueValues(self.fieldName) |
757 |
self.dataList.append(v) |
index = 0 |
758 |
i = self.list_avail.InsertStringItem(index, str(v)) |
for v in list: |
759 |
self.list_avail.SetItemData(index, i) |
self.dataList.append(v) |
760 |
|
i = self.list_avail.InsertStringItem(index, str(v)) |
761 |
self.list_avail_data.append(v) |
self.list_avail.SetItemData(index, i) |
762 |
index += 1 |
|
763 |
|
self.list_avail_data.append(v) |
764 |
|
index += 1 |
765 |
|
finally: |
766 |
|
ThubanEndBusyCursor() |
767 |
|
|
768 |
def _OnUseAll(self, event): |
def _OnUseAll(self, event): |
769 |
for i in range(self.list_avail.GetItemCount()): |
for i in range(self.list_avail.GetItemCount()): |
867 |
return self.__range |
return self.__range |
868 |
|
|
869 |
def GetList(self): |
def GetList(self): |
|
|
|
870 |
_list = [] |
_list = [] |
871 |
|
table = self.layer.ShapeStore().Table() |
872 |
if self.layer.table is not None: |
if table is not None: |
873 |
wxBeginBusyCursor() |
ThubanBeginBusyCursor() |
874 |
|
try: |
875 |
# |
# |
876 |
# FIXME: Replace with a call to table when the method |
# FIXME: Replace with a call to table when the method |
877 |
# has been written to get all the values |
# has been written to get all the values |
878 |
# |
# |
879 |
table = self.layer.table |
for i in range(table.NumRows()): |
880 |
for i in range(table.NumRows()): |
_list.append(table.ReadValue(i, self.fieldName)) |
881 |
_list.append(table.ReadValue(i, self.fieldName)) |
finally: |
882 |
|
ThubanEndBusyCursor() |
|
wxEndBusyCursor() |
|
883 |
|
|
884 |
return _list |
return _list |
885 |
|
|
896 |
self.text_range.SetForegroundColour(wxRED) |
self.text_range.SetForegroundColour(wxRED) |
897 |
|
|
898 |
def OnRetrieve(self, event): |
def OnRetrieve(self, event): |
899 |
|
table = self.layer.ShapeStore().Table() |
900 |
if self.layer.table is not None: |
if table is not None: |
901 |
wxBeginBusyCursor() |
ThubanBeginBusyCursor() |
902 |
min, max = self.layer.table.ValueRange(self.fieldName) |
try: |
903 |
self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]") |
min, max = table.ValueRange(self.fieldName) |
904 |
wxEndBusyCursor() |
self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]") |
905 |
|
finally: |
906 |
|
ThubanEndBusyCursor() |
907 |
|
|
908 |
ID_CUSTOMRAMP_COPYSTART = 4001 |
ID_CUSTOMRAMP_COPYSTART = 4001 |
909 |
ID_CUSTOMRAMP_COPYEND = 4002 |
ID_CUSTOMRAMP_COPYEND = 4002 |