19 |
|
|
20 |
import classifier |
import classifier |
21 |
|
|
22 |
|
import resource |
23 |
|
|
24 |
from Thuban.common import Str2Num |
from Thuban.common import Str2Num |
25 |
|
|
26 |
ID_CLASSGEN_GEN = 4001 |
ID_CLASSGEN_GEN = 4001 |
28 |
ID_CLASSGEN_GENCOMBO = 4007 |
ID_CLASSGEN_GENCOMBO = 4007 |
29 |
ID_CLASSGEN_PROPCOMBO = 4008 |
ID_CLASSGEN_PROPCOMBO = 4008 |
30 |
|
|
31 |
|
USEALL_BMP = "group_use_all" |
32 |
|
USE_BMP = "group_use" |
33 |
|
USENOT_BMP = "group_use_not" |
34 |
|
USENONE_BMP = "group_use_none" |
35 |
|
|
36 |
GENCOMBOSTR_UNIFORM = _("Uniform Distribution") |
GENCOMBOSTR_UNIFORM = _("Uniform Distribution") |
37 |
GENCOMBOSTR_UNIQUE = _("Unique Values") |
GENCOMBOSTR_UNIQUE = _("Unique Values") |
38 |
|
|
39 |
PROPCOMBOSTR_CUSTOM = _("Custom Ramp") |
PROPCOMBOSTR_CUSTOM = _("Custom Ramp") |
40 |
PROPCOMBOSTR_RED = _("Red Ramp") |
PROPCOMBOSTR_GREY = _("Grey Ramp") |
41 |
PROPCOMBOSTR_GREEN = _("Green Ramp") |
PROPCOMBOSTR_RED = _("Red Ramp") |
42 |
PROPCOMBOSTR_BLUE = _("Blue Ramp") |
PROPCOMBOSTR_GREEN = _("Green Ramp") |
43 |
|
PROPCOMBOSTR_BLUE = _("Blue Ramp") |
44 |
|
PROPCOMBOSTR_HOT2COLD = _("Hot-to-Cold Ramp") |
45 |
|
|
46 |
class ClassGenDialog(wxDialog): |
class ClassGenDialog(wxDialog): |
47 |
|
|
79 |
0, wxALL, 4) |
0, wxALL, 4) |
80 |
sizer.Add(wxStaticText( |
sizer.Add(wxStaticText( |
81 |
self, -1, |
self, -1, |
82 |
_("Field Type: %s") % classifier.Classifier.type2string[self.type]), |
_("Data Type: %s") % classifier.Classifier.type2string[self.type]), |
83 |
0, wxALL, 4) |
0, wxALL, 4) |
84 |
|
|
85 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
107 |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
108 |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
109 |
self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel) |
self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel) |
110 |
sizer.Add(panel, 0, wxGROW | wxALL, 4) |
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
111 |
sizer.Show(panel, False) |
sizer.Show(panel, False) |
112 |
|
|
113 |
|
self.genCombo.SetSelection(0) |
114 |
|
|
115 |
############# |
############# |
116 |
|
|
117 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
118 |
psizer.Add(wxStaticText(self, -1, _("Color Schemes:")), |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
119 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
120 |
|
|
121 |
self.propCombo = wxComboBox(self, |
self.propCombo = wxComboBox(self, |
132 |
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
133 |
sizer.Show(panel, False) |
sizer.Show(panel, False) |
134 |
|
|
135 |
|
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp()) |
136 |
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
137 |
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
138 |
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
139 |
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
140 |
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel) |
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel) |
141 |
|
|
142 |
|
self.propCombo.SetSelection(0) |
143 |
|
|
144 |
|
|
145 |
############# |
############# |
290 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
291 |
|
|
292 |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
293 |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT) |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, |
294 |
|
style=wxTE_RIGHT) |
295 |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
296 |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
297 |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
514 |
ID_UNIQUE_USENONE = 4005 |
ID_UNIQUE_USENONE = 4005 |
515 |
ID_UNIQUE_SORTAVAIL = 4006 |
ID_UNIQUE_SORTAVAIL = 4006 |
516 |
ID_UNIQUE_SORTUSE = 4007 |
ID_UNIQUE_SORTUSE = 4007 |
517 |
|
ID_UNIQUE_REVAVAIL = 4008 |
518 |
|
ID_UNIQUE_REVUSE = 4009 |
519 |
|
|
520 |
class GenUniquePanel(wxPanel): |
class GenUniquePanel(wxPanel): |
521 |
|
|
531 |
wxVERTICAL) |
wxVERTICAL) |
532 |
|
|
533 |
|
|
534 |
|
#bsizer = wxBoxSizer(wxVERTICAL) |
535 |
|
topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE, |
536 |
|
_("Retrieve From Table")), |
537 |
|
0, wxALL | wxALIGN_RIGHT, 4) |
538 |
|
|
539 |
|
EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve) |
540 |
|
|
541 |
|
#topSizer.Add(bsizer, 0, wxALL, 4) |
542 |
|
|
543 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
544 |
|
|
545 |
self.dataList = [] |
self.dataList = [] |
551 |
self.list_avail_data = [] |
self.list_avail_data = [] |
552 |
psizer.Add(self.list_avail, 1, wxGROW, 0) |
psizer.Add(self.list_avail, 1, wxGROW, 0) |
553 |
|
|
554 |
psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort"))) |
bsizer = wxBoxSizer(wxHORIZONTAL) |
555 |
|
bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort"))) |
556 |
|
EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList) |
557 |
|
|
558 |
EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList) |
bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse"))) |
559 |
|
EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList) |
560 |
|
|
561 |
|
psizer.Add(bsizer, 0, wxGROW, 0) |
562 |
sizer.Add(psizer, 1, wxGROW, 0) |
sizer.Add(psizer, 1, wxGROW, 0) |
563 |
|
|
564 |
|
|
565 |
bsizer = wxBoxSizer(wxVERTICAL) |
bsizer = wxBoxSizer(wxVERTICAL) |
566 |
bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")), |
|
567 |
|
bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM) |
568 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp), |
569 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
570 |
bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")), |
bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM) |
571 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp), |
572 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
573 |
bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")), |
bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM) |
574 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp), |
575 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
576 |
bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")), |
bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM) |
577 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp), |
578 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
579 |
|
|
580 |
EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll) |
EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll) |
591 |
self.list_use_data = [] |
self.list_use_data = [] |
592 |
psizer.Add(self.list_use, 1, wxGROW, 0) |
psizer.Add(self.list_use, 1, wxGROW, 0) |
593 |
|
|
594 |
psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort"))) |
bsizer = wxBoxSizer(wxHORIZONTAL) |
595 |
|
bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort"))) |
596 |
EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList) |
EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList) |
597 |
|
|
598 |
sizer.Add(psizer, 1, wxGROW, 0) |
bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse"))) |
599 |
|
EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList) |
600 |
|
|
601 |
bsizer = wxBoxSizer(wxVERTICAL) |
psizer.Add(bsizer, 0, wxGROW, 0) |
|
bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE, |
|
|
_("Retrieve From Table")), |
|
|
0, wxGROW | wxALL, 4) |
|
602 |
|
|
603 |
EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve) |
sizer.Add(psizer, 1, wxGROW, 0) |
604 |
|
|
|
sizer.Add(bsizer, 0, wxALL, 4) |
|
605 |
|
|
606 |
topSizer.Add(sizer, 1, wxGROW, 0) |
topSizer.Add(sizer, 1, wxGROW, 0) |
607 |
|
|
622 |
list.append(self.dataList[self.list_use.GetItemData(i)]) |
list.append(self.dataList[self.list_use.GetItemData(i)]) |
623 |
return list |
return list |
624 |
|
|
625 |
def _OnSortAvailList(self, event): |
def _OnSortList(self, event): |
626 |
self.list_avail.SortItems(lambda i1, i2: |
id = event.GetId() |
627 |
cmp(self.dataList[i1], |
|
628 |
self.dataList[i2])) |
if id == ID_UNIQUE_SORTUSE: |
629 |
|
list = self.list_use |
630 |
def _OnSortUseList(self, event): |
else: |
631 |
self.list_use.SortItems(lambda i1, i2: |
list = self.list_avail |
632 |
cmp(self.dataList[i1], |
|
633 |
self.dataList[i2])) |
list.SortItems(lambda i1, i2: cmp(self.dataList[i1], |
634 |
|
self.dataList[i2])) |
635 |
|
|
636 |
|
def _OnReverseList(self, event): |
637 |
|
id = event.GetId() |
638 |
|
|
639 |
|
if id == ID_UNIQUE_REVUSE: |
640 |
|
list = self.list_use |
641 |
|
else: |
642 |
|
list = self.list_avail |
643 |
|
|
644 |
|
# |
645 |
|
# always returning 1 reverses the list |
646 |
|
# |
647 |
|
list.SortItems(lambda i1, i2: 1) |
648 |
|
|
649 |
def _OnRetrieve(self, event): |
def _OnRetrieve(self, event): |
650 |
self.list_use.DeleteAllItems() |
self.list_use.DeleteAllItems() |
667 |
self.__MoveListItem(0, self.list_avail, self.list_use) |
self.__MoveListItem(0, self.list_avail, self.list_use) |
668 |
|
|
669 |
def _OnUse(self, event): |
def _OnUse(self, event): |
|
print "_OnUse" |
|
670 |
self.__MoveSelectedItems(self.list_avail, self.list_use) |
self.__MoveSelectedItems(self.list_avail, self.list_use) |
671 |
|
|
672 |
def _OnDontUse(self, event): |
def _OnDontUse(self, event): |
|
print "_OnDontUse" |
|
673 |
self.__MoveSelectedItems(self.list_use, self.list_avail) |
self.__MoveSelectedItems(self.list_use, self.list_avail) |
674 |
|
|
675 |
def _OnUseNone(self, event): |
def _OnUseNone(self, event): |
|
print "_OnUseNone" |
|
676 |
|
|
677 |
for i in range(self.list_use.GetItemCount()): |
for i in range(self.list_use.GetItemCount()): |
678 |
self.__MoveListItem(0, self.list_use, self.list_avail) |
self.__MoveListItem(0, self.list_use, self.list_avail) |
738 |
| wxALIGN_CENTER_VERTICAL, \ |
| wxALIGN_CENTER_VERTICAL, \ |
739 |
4) |
4) |
740 |
|
|
741 |
|
bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM) |
742 |
bsizer = wxBoxSizer(wxVERTICAL) |
bsizer = wxBoxSizer(wxVERTICAL) |
743 |
bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")), |
bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp), |
744 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
745 |
bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")), |
bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM) |
746 |
|
bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp), |
747 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
748 |
|
|
749 |
topSizer.Add(bsizer, |
topSizer.Add(bsizer, |
1014 |
|
|
1015 |
CustomRamp.__init__(self, sp, ep) |
CustomRamp.__init__(self, sp, ep) |
1016 |
|
|
1017 |
|
class GreyRamp(MonochromaticRamp): |
1018 |
|
def __init__(self): |
1019 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0)) |
1020 |
|
|
1021 |
class RedRamp(MonochromaticRamp): |
class RedRamp(MonochromaticRamp): |
1022 |
def __init__(self): |
def __init__(self): |
1023 |
MonochromaticRamp.__init__(self, Color(.2, 0, 0), Color(1, 0, 0)) |
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0)) |
1024 |
|
|
1025 |
class GreenRamp(MonochromaticRamp): |
class GreenRamp(MonochromaticRamp): |
1026 |
def __init__(self): |
def __init__(self): |
1027 |
MonochromaticRamp.__init__(self, Color(0, .2, 0), Color(0, 1, 0)) |
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0)) |
1028 |
|
|
1029 |
class BlueRamp(MonochromaticRamp): |
class BlueRamp(MonochromaticRamp): |
1030 |
def __init__(self): |
def __init__(self): |
1031 |
MonochromaticRamp.__init__(self, Color(0, 0, .2), Color(0, 0, 1)) |
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8)) |
1032 |
|
|
1033 |
|
class HotToColdRamp: |
1034 |
|
|
1035 |
|
def __iter__(self): |
1036 |
|
return self |
1037 |
|
|
1038 |
|
def GetRamp(self): |
1039 |
|
return self |
1040 |
|
|
1041 |
|
def SetNumGroups(self, num): |
1042 |
|
if num < 0: |
1043 |
|
return False |
1044 |
|
|
1045 |
|
self.num = float(num) |
1046 |
|
self.index = 0 |
1047 |
|
|
1048 |
|
return True |
1049 |
|
|
1050 |
|
def next(self): |
1051 |
|
if self.index == self.num: |
1052 |
|
raise StopIteration |
1053 |
|
|
1054 |
|
clr = [1.0, 1.0, 1.0] |
1055 |
|
|
1056 |
|
if self.index < (.25 * self.num): |
1057 |
|
clr[0] = 0 |
1058 |
|
clr[1] = 4 * self.index / self.num |
1059 |
|
elif self.index < (.5 * self.num): |
1060 |
|
clr[0] = 0 |
1061 |
|
clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num |
1062 |
|
elif self.index < (.75 * self.num): |
1063 |
|
clr[0] = 4 * (self.index - .5 * self.num) / self.num |
1064 |
|
clr[2] = 0 |
1065 |
|
else: |
1066 |
|
clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num |
1067 |
|
clr[2] = 0 |
1068 |
|
|
1069 |
|
self.index += 1 |
1070 |
|
|
1071 |
|
prop = ClassGroupProperties() |
1072 |
|
prop.SetLineColor(Color(clr[0], clr[1], clr[2])) |
1073 |
|
prop.SetFill(Color(clr[0], clr[1], clr[2])) |
1074 |
|
|
1075 |
|
return prop |
1076 |
|
|
1077 |
|
#class Colors16Ramp: |
1078 |
|
# |
1079 |
|
#def __iter__(self): |
1080 |
|
#return self |
1081 |
|
# |
1082 |
|
#def GetRamp(self): |
1083 |
|
#return self |
1084 |
|
# |
1085 |
|
#def SetNumGroups(self, num): |
1086 |
|
#if num < 0: |
1087 |
|
#return False |
1088 |
|
# |
1089 |
|
#self.index = 0 |
1090 |
|
# |
1091 |
|
#return True |
1092 |
|
|
1093 |
|
|