/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/classgen.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/classgen.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 629 by jonathan, Wed Apr 9 10:09:44 2003 UTC revision 660 by jonathan, Mon Apr 14 14:15:44 2003 UTC
# Line 19  from Thuban.Model.color import Color Line 19  from Thuban.Model.color import Color
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
27  ID_CLASSGEN_CLOSE = 4002  ID_CLASSGEN_CLOSE = 4002
28  ID_CLASSGEN_COMBO = 4007  ID_CLASSGEN_GENCOMBO = 4007
29    ID_CLASSGEN_PROPCOMBO = 4008
30    
31  COMBOSTR_UNIFORM = _("Uniform Distribution")  USEALL_BMP  = "group_use_all"
32  COMBOSTR_UNIQUE = _("Unique Values")  USE_BMP     = "group_use"
33    USENOT_BMP  = "group_use_not"
34    USENONE_BMP = "group_use_none"
35    
36    GENCOMBOSTR_UNIFORM = _("Uniform Distribution")
37    GENCOMBOSTR_UNIQUE = _("Unique Values")
38    
39    PROPCOMBOSTR_CUSTOM     = _("Custom Ramp")
40    PROPCOMBOSTR_GREY       = _("Grey Ramp")
41    PROPCOMBOSTR_RED        = _("Red Ramp")
42    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                                                                                                                                                                    
# Line 64  class ClassGenDialog(wxDialog): Line 79  class ClassGenDialog(wxDialog):
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)
86          psizer.Add(wxStaticText(          psizer.Add(wxStaticText(self, -1, _("Generate:")),
             self, -1,  
             _("Generate:")),  
87              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
88    
89          self.genCombo = wxComboBox(self,          self.genCombo = wxComboBox(self,
90                                  ID_CLASSGEN_COMBO,                                     ID_CLASSGEN_GENCOMBO,
91                                  "", style = wxCB_READONLY)                                     "", style = wxCB_READONLY)
92          psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)          psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)
93          EVT_COMBOBOX(self, ID_CLASSGEN_COMBO, self._OnGenTypeSelect)          EVT_COMBOBOX(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)
94    
95          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
96    
# Line 86  class ClassGenDialog(wxDialog): Line 99  class ClassGenDialog(wxDialog):
99          self.genPanel = None          self.genPanel = None
100    
101          panel = GenUniquePanel(self, layer, fieldName, self.type)          panel = GenUniquePanel(self, layer, fieldName, self.type)
102          self.genCombo.Append(COMBOSTR_UNIQUE)          self.genCombo.Append(GENCOMBOSTR_UNIQUE, panel)
         self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel)  
103          sizer.Add(panel, 1, wxGROW | wxALL, 4)          sizer.Add(panel, 1, wxGROW | wxALL, 4)
104    
105          self.genPanel = panel          self.genPanel = panel
106    
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(COMBOSTR_UNIFORM)              self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel)
110              self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel)              sizer.Add(panel, 1, wxGROW | wxALL, 4)
             sizer.Add(panel, 0, wxGROW | wxALL, 4)  
111              sizer.Show(panel, False)              sizer.Show(panel, False)
112    
113            self.genCombo.SetSelection(0)
114    
115          #############          #############
116    
117          self.propPanel = None          psizer = wxBoxSizer(wxHORIZONTAL)
118            psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
119                0, wxALIGN_CENTER_VERTICAL, 0)
120    
121          panel = CustomRampPanel(self, layer.ShapeType())          self.propCombo = wxComboBox(self,
122                                       ID_CLASSGEN_PROPCOMBO,
123                                       "", style = wxCB_READONLY)
124            psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
125            EVT_COMBOBOX(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)
126            sizer.Add(psizer, 0, wxALL | wxGROW, 4)
127    
128          self.propPanel = panel          #############
129    
130            self.propPanel = None
131            panel = CustomRampPanel(self, layer.ShapeType())
132          sizer.Add(panel, 1, wxALL | wxGROW, 4)          sizer.Add(panel, 1, wxALL | wxGROW, 4)
133            sizer.Show(panel, False)
134    
135            self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())
136            self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())
137            self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())
138            self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())
139            self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
140            self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)
141    
142            self.propCombo.SetSelection(0)
143    
144    
145          #############          #############
146    
# Line 132  class ClassGenDialog(wxDialog): Line 165  class ClassGenDialog(wxDialog):
165    
166      def _OnGenerate(self, event):      def _OnGenerate(self, event):
167    
168          selIndex = self.genCombo.GetSelection()          index = self.genCombo.GetSelection()
169    
170          sel = self.genCombo.GetString(selIndex)          genSel = self.genCombo.GetString(index)
171          genPanel = self.genCombo.GetClientData(selIndex)          genPanel = self.genCombo.GetClientData(index)
         propPanel = self.propPanel  
172    
173          if sel == COMBOSTR_UNIFORM:          propPanel = self.propPanel
174    
175              min = genPanel.GetMin()          if genSel in (GENCOMBOSTR_UNIFORM, GENCOMBOSTR_UNIQUE):
             max = genPanel.GetMax()  
176              numGroups = genPanel.GetNumGroups()              numGroups = genPanel.GetNumGroups()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
177    
178              if min is not None \              index = self.propCombo.GetSelection()
                 and max is not None \  
                 and numGroups is not None:  
179    
180                  self.clazz = ClassGenerator().GenUnifromDistribution(              propSel = self.propCombo.GetString(index)
181                               min, max, numGroups, sp, ep,              propPanel = self.propCombo.GetClientData(index)
                              self.type == FIELDTYPE_INT)  
182    
183                  self.parent._SetClassification(self.clazz)              ramp = propPanel.GetRamp()
184    
185          elif sel == COMBOSTR_UNIQUE:              if genSel == GENCOMBOSTR_UNIFORM:
186    
187              list = genPanel.GetValueList()                  min = genPanel.GetMin()
188              numGroups = genPanel.GetNumGroups()                  max = genPanel.GetMax()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
189    
190              if len(list) > 0 \                  if min is not None \
191                  and numGroups is not None:                      and max is not None \
192                        and numGroups is not None:
193    
194                  self.clazz = ClassGenerator().GenSingletonsFromList(                      self.clazz = ClassGenerator().GenUnifromDistribution(
195                                  list, numGroups, sp, ep)                                  min, max, numGroups, ramp,
196                                    self.type == FIELDTYPE_INT)
197    
198                  self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
199    
200          else:              elif genSel == GENCOMBOSTR_UNIQUE:
201              pass  
202                    list = genPanel.GetValueList()
203    
204                    if len(list) > 0 \
205                        and numGroups is not None:
206    
207                        self.clazz = ClassGenerator().GenSingletonsFromList(
208                                        list, numGroups, ramp)
209    
210                        self.parent._SetClassification(self.clazz)
211    
212      def _OnCloseBtn(self, event):      def _OnCloseBtn(self, event):
213          self.Close()          self.Close()
# Line 193  class ClassGenDialog(wxDialog): Line 228  class ClassGenDialog(wxDialog):
228          self.sizer.SetSizeHints(self)          self.sizer.SetSizeHints(self)
229          self.sizer.Layout()          self.sizer.Layout()
230    
231        def _OnPropTypeSelect(self, event):
232            combo = event.GetEventObject()
233    
234            selIndex = combo.GetSelection()
235            sel = combo.GetString(selIndex)
236    
237            if isinstance(self.propPanel, wxPanel):
238                self.sizer.Show(self.propPanel, False)
239    
240            self.propPanel = combo.GetClientData(selIndex)
241    
242            if isinstance(self.propPanel, wxPanel):
243                self.sizer.Show(self.propPanel, True)
244    
245            self.sizer.SetSizeHints(self)
246            self.sizer.Layout()
247    
248    
249  ID_UNIFORM_MIN = 4001  ID_UNIFORM_MIN = 4001
250  ID_UNIFORM_MAX = 4002  ID_UNIFORM_MAX = 4002
# Line 238  class GenUniformPanel(wxPanel): Line 290  class GenUniformPanel(wxPanel):
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)
# Line 461  ID_UNIQUE_DONTUSE = 4004 Line 514  ID_UNIQUE_DONTUSE = 4004
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    
# Line 476  class GenUniquePanel(wxPanel): Line 531  class GenUniquePanel(wxPanel):
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 = []
# Line 487  class GenUniquePanel(wxPanel): Line 551  class GenUniquePanel(wxPanel):
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)
# Line 518  class GenUniquePanel(wxPanel): Line 591  class GenUniquePanel(wxPanel):
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._OnSortList)
597    
598          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse")))
599            EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList)
600    
601          sizer.Add(psizer, 1, wxGROW, 0)          psizer.Add(bsizer, 0, wxGROW, 0)
602    
603          bsizer = wxBoxSizer(wxVERTICAL)          sizer.Add(psizer, 1, wxGROW, 0)
         bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,  
                             _("Retrieve From Table")),  
                    0, wxGROW | wxALL, 4)  
   
         EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)  
604    
         sizer.Add(bsizer, 0, wxALL, 4)  
605    
606          topSizer.Add(sizer, 1, wxGROW, 0)          topSizer.Add(sizer, 1, wxGROW, 0)
607    
# Line 552  class GenUniquePanel(wxPanel): Line 622  class GenUniquePanel(wxPanel):
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()
# Line 583  class GenUniquePanel(wxPanel): Line 667  class GenUniquePanel(wxPanel):
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)
# Line 657  class CustomRampPanel(wxPanel): Line 738  class CustomRampPanel(wxPanel):
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,
# Line 696  class CustomRampPanel(wxPanel): Line 779  class CustomRampPanel(wxPanel):
779          self.SetAutoLayout(True)          self.SetAutoLayout(True)
780          topSizer.SetSizeHints(self)          topSizer.SetSizeHints(self)
781    
782      def GetStartProperties(self):      def GetRamp(self):
783          return self.startPropCtrl.GetProperties()          return CustomRamp(self.startPropCtrl.GetProperties(),
784                              self.endPropCtrl.GetProperties())
     def GetEndProperties(self):  
         return self.endPropCtrl.GetProperties()  
785    
786      def _OnCopyStart(self, event):      def _OnCopyStart(self, event):
787          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())
# Line 716  class CustomRampPanel(wxPanel): Line 797  class CustomRampPanel(wxPanel):
797    
798  class ClassGenerator:  class ClassGenerator:
799    
800      def GenSingletonsFromList(self, list, numGroups, prop1, prop2):      def GenSingletonsFromList(self, list, numGroups, ramp):
801          """Generate a new classification consisting solely of singletons.          """Generate a new classification consisting solely of singletons.
802    
803          The resulting classification will consist of at most 'numGroups'          The resulting classification will consist of at most 'numGroups'
# Line 738  class ClassGenerator: Line 819  class ClassGenerator:
819          clazz = Classification()          clazz = Classification()
820          if numGroups == 0: return clazz          if numGroups == 0: return clazz
821    
822          for value, prop in zip(list, CustomRamp(numGroups, prop1, prop2)):          ramp.SetNumGroups(numGroups)
823    
824            for value, prop in zip(list, ramp):
825              clazz.AppendGroup(ClassGroupSingleton(value, prop))              clazz.AppendGroup(ClassGroupSingleton(value, prop))
826    
827          return clazz          return clazz
828    
829      def GenSingletons(self, min, max, numGroups, prop1, prop2):      def GenSingletons(self, min, max, numGroups, ramp):
830    
831          clazz = Classification()          clazz = Classification()
832    
# Line 753  class ClassGenerator: Line 836  class ClassGenerator:
836          if numGroups > 0:          if numGroups > 0:
837              cur_value = min              cur_value = min
838    
839              for prop in CustomRamp(numGroups, prop1, prop2):              ramp.SetNumGroups(numGroups)
840    
841                for prop in ramp:
842                  clazz.AppendGroup(                  clazz.AppendGroup(
843                      ClassGroupSingleton(                      ClassGroupSingleton(
844                          Str2Num(str(cur_value)),                          Str2Num(str(cur_value)),
# Line 763  class ClassGenerator: Line 848  class ClassGenerator:
848          return clazz          return clazz
849    
850      def GenUnifromDistribution(self, min, max, numGroups,      def GenUnifromDistribution(self, min, max, numGroups,
851                                 prop1, prop2, intStep = False):                                 ramp, intStep = False):
852          """Generate a classification with numGroups range groups          """Generate a classification with numGroups range groups
853          each with the same interval.          each with the same interval.
854    
# Line 776  class ClassGenerator: Line 861  class ClassGenerator:
861          clazz = Classification()          clazz = Classification()
862          if numGroups == 0: return clazz          if numGroups == 0: return clazz
863    
864            ramp.SetNumGroups(numGroups)
865    
866          step = Str2Num(str((max - min) / float(numGroups)))          step = Str2Num(str((max - min) / float(numGroups)))
867    
868          if intStep:          if intStep:
# Line 785  class ClassGenerator: Line 872  class ClassGenerator:
872          cur_max = cur_min + step          cur_max = cur_min + step
873    
874          i = 0          i = 0
875          for prop in CustomRamp(numGroups, prop1, prop2):          for prop in ramp:
876    
877              if i == (numGroups - 1):              if i == (numGroups - 1):
878                  cur_max = max                  cur_max = max
# Line 808  CLR  = 0 Line 895  CLR  = 0
895  STEP = 1  STEP = 1
896  class CustomRamp:  class CustomRamp:
897    
898      def __init__(self, num, prop1, prop2):      def __init__(self, prop1, prop2):
899            self.prop1 = prop1
900            self.prop2 = prop2
901    
902            self.count = 0
903    
904        def __iter__(self):
905            return self
906    
907        def GetRamp(self):
908            return self
909    
910        def SetNumGroups(self, num):
911    
912            if num <= 0:
913                return False
914    
915          self.count = int(num)          self.count = int(num)
916          num = float(num)          num = float(num)
917    
918            prop1 = self.prop1
919            prop2 = self.prop2
920    
921          clr = prop1.GetLineColor()          clr = prop1.GetLineColor()
922          lineColor2 = prop2.GetLineColor()          lineColor2 = prop2.GetLineColor()
923                    
# Line 831  class CustomRamp: Line 936  class CustomRamp:
936          self.lineWidth = prop1.GetLineWidth()          self.lineWidth = prop1.GetLineWidth()
937          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num
938    
939      def __iter__(self):          return True
         return self  
940    
941      def next(self):      def next(self):
942          if self.count == 0:          if self.count == 0:
# Line 897  class CustomRamp: Line 1001  class CustomRamp:
1001    
1002    
1003          return (color, step)          return (color, step)
1004    
1005    class MonochromaticRamp(CustomRamp):
1006        def __init__(self, start, end):
1007            sp = ClassGroupProperties()
1008            sp.SetLineColor(start)
1009            sp.SetFill(start)
1010    
1011            ep = ClassGroupProperties()
1012            ep.SetLineColor(end)
1013            ep.SetFill(end)
1014    
1015            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):
1022        def __init__(self):
1023            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0))
1024    
1025    class GreenRamp(MonochromaticRamp):
1026        def __init__(self):
1027            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0))
1028    
1029    class BlueRamp(MonochromaticRamp):
1030        def __init__(self):
1031            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        

Legend:
Removed from v.629  
changed lines
  Added in v.660

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26