/[thuban]/trunk/thuban/Thuban/UI/classifier.py
ViewVC logotype

Diff of /trunk/thuban/Thuban/UI/classifier.py

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

revision 570 by jonathan, Fri Mar 28 17:06:26 2003 UTC revision 615 by jonathan, Mon Apr 7 08:57:20 2003 UTC
# Line 27  from Thuban.Model.color import Color Line 27  from Thuban.Model.color import Color
27    
28  from Thuban.Model.layer import Layer, SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT  from Thuban.Model.layer import Layer, SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT
29    
30    from Thuban.UI.classgen import ClassGenDialog, ClassGenerator
31    
32  from dialogs import NonModalDialog  from dialogs import NonModalDialog
33    
34  # widget id's  # widget id's
# Line 36  ID_CLASS_TABLE = 40011 Line 38  ID_CLASS_TABLE = 40011
38  ID_CLASSIFY_OK = 4001  ID_CLASSIFY_OK = 4001
39  ID_CLASSIFY_CANCEL = 4002  ID_CLASSIFY_CANCEL = 4002
40  ID_CLASSIFY_ADD = 4003  ID_CLASSIFY_ADD = 4003
41  ID_CLASSIFY_GENRANGE = 4004  ID_CLASSIFY_GENCLASS = 4004
42  ID_CLASSIFY_REMOVE = 4005  ID_CLASSIFY_REMOVE = 4005
43  ID_CLASSIFY_MOVEUP = 4006  ID_CLASSIFY_MOVEUP = 4006
44  ID_CLASSIFY_MOVEDOWN = 4007  ID_CLASSIFY_MOVEDOWN = 4007
45  ID_CLASSIFY_APPLY = 4008  ID_CLASSIFY_APPLY = 4008
46    ID_CLASSIFY_EDITPROPS = 4009
47    ID_CLASSIFY_CLOSE = 4010
48    
49  # table columns  # table columns
50  COL_SYMBOL = 0  COL_SYMBOL = 0
# Line 60  import weakref Line 64  import weakref
64  class ClassGrid(wxGrid):  class ClassGrid(wxGrid):
65    
66    
67      def __init__(self, parent):      def __init__(self, parent, classifier):
68          """Constructor.          """Constructor.
69    
70          parent -- the parent window          parent -- the parent window
# Line 73  class ClassGrid(wxGrid): Line 77  class ClassGrid(wxGrid):
77          wxGrid.__init__(self, parent, ID_CLASS_TABLE)          wxGrid.__init__(self, parent, ID_CLASS_TABLE)
78          #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True)          #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True)
79    
80            self.classifier = classifier
81    
82          self.currentSelection = []          self.currentSelection = []
83    
84          EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick)          EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick)
85          EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange)          EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange)
86          EVT_GRID_SELECT_CELL(self, self._OnSelectedCell)          EVT_GRID_SELECT_CELL(self, self._OnSelectedCell)
87            EVT_GRID_COL_SIZE(self, self._OnCellResize)
88            EVT_GRID_ROW_SIZE(self, self._OnCellResize)
89    
90          print "123123123: ", ('Show' in dir(self))          #print "123123123: ", ('Show' in dir(self))
91    
92      def Show(self):      #def Show(self):
93          print "SHOW!"          #print "SHOW!"
94    
95      def Refresh(self):      #def Refresh(self):
96          self.Show()          #self.Show()
97      def Update(self):      #def Update(self):
98          self.Show()          #self.Show()
99    
100      def CreateTable(self, clazz, shapeType, group = None):      def CreateTable(self, clazz, shapeType, group = None):
101    
102          assert(isinstance(clazz, Classification))          assert isinstance(clazz, Classification)
103    
         self.shapeType = shapeType  
104          table = self.GetTable()          table = self.GetTable()
105          if table is None:          if table is None:
106              w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize()              w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize()
# Line 107  class ClassGrid(wxGrid): Line 114  class ClassGrid(wxGrid):
114          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
115          self.ClearSelection()          self.ClearSelection()
116    
117          print "8------------------"          #print "8------------------"
118          table.Reset(clazz, self.shapeType, group)          table.Reset(clazz, shapeType, group)
119          print "9------------------"          #print "9------------------"
120    
121  #   def Show(self, show = True):  #   def Show(self, show = True):
122  #       print "SHOW!"  #       print "SHOW!"
# Line 125  class ClassGrid(wxGrid): Line 132  class ClassGrid(wxGrid):
132      def GetCurrentSelection(self):      def GetCurrentSelection(self):
133          """Return the currently highlighted rows as an increasing list          """Return the currently highlighted rows as an increasing list
134             of row numbers."""             of row numbers."""
135          print "@@ ", self.currentSelection          #print "@@ ", self.currentSelection
136          sel = copy.copy(self.currentSelection)          sel = copy.copy(self.currentSelection)
137          sel.sort()          sel.sort()
138          return sel          return sel
# Line 203  class ClassGrid(wxGrid): Line 210  class ClassGrid(wxGrid):
210      def SelectGroup(self, group, makeVisible = True):      def SelectGroup(self, group, makeVisible = True):
211          if group is None: return          if group is None: return
212    
213          assert(isinstance(group, ClassGroup))          assert isinstance(group, ClassGroup)
214    
215          table = self.GetTable()          table = self.GetTable()
216    
217          assert(table is not None)          assert table is not None
218    
219    
220          print "-- ", group          #print "-- ", group
221          for i in range(table.GetNumberRows()):          for i in range(table.GetNumberRows()):
222              g = table.GetClassGroup(i)              g = table.GetClassGroup(i)
223              print "1", g              #print "1", g
224              if g is group:              if g is group:
225                  print "2"                  #print "2"
226                  self.SelectRow(i)                  self.SelectRow(i)
227                  if makeVisible:                  if makeVisible:
228                      print "3"                      #print "3"
229                      self.MakeCellVisible(i, 0)                      self.MakeCellVisible(i, 0)
230                  break                  break
231    
# Line 241  class ClassGrid(wxGrid): Line 248  class ClassGrid(wxGrid):
248          r = event.GetRow()          r = event.GetRow()
249          c = event.GetCol()          c = event.GetCol()
250          if c == COL_SYMBOL:          if c == COL_SYMBOL:
251              prop = self.GetTable().GetValueAsCustom(r, c, None)              self.classifier.EditGroupProperties(r)
             #prop = group.GetProperties()  
252    
             # get a new ClassGroupProperties object and copy the  
             # values over to our current object  
             propDlg = SelectPropertiesDialog(NULL, prop, self.shapeType)  
             if propDlg.ShowModal() == wxID_OK:  
                 new_prop = propDlg.GetClassGroupProperties()  
                 #prop.SetProperties(new_prop)  
                 self.GetTable().SetValueAsCustom(r, c, None, new_prop)  
             propDlg.Destroy()  
253    
254      #      #
255      # _OnSelectedRange() and _OnSelectedCell() were borrowed      # _OnSelectedRange() and _OnSelectedCell() were borrowed
# Line 263  class ClassGrid(wxGrid): Line 261  class ClassGrid(wxGrid):
261          if event.Selecting():          if event.Selecting():
262              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
263                  if index not in self.currentSelection:                  if index not in self.currentSelection:
264                      print "    ", index                      #print "    ", index
265                      self.currentSelection.append( index )                      self.currentSelection.append( index )
266          else:          else:
267              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
268                  while index in self.currentSelection:                  while index in self.currentSelection:
269                      print "    ", index                      #print "    ", index
270                      self.currentSelection.remove( index )                      self.currentSelection.remove( index )
271          #self.ConfigureForSelection()          #self.ConfigureForSelection()
272    
273          print self.GetCurrentSelection()          #print self.GetCurrentSelection()
274          event.Skip()          event.Skip()
275    
276      def _OnSelectedCell( self, event ):      def _OnSelectedCell( self, event ):
277          """Internal update to the selection tracking list"""          """Internal update to the selection tracking list"""
278          print "selecting cell: ", event.GetRow()          #print "selecting cell: ", event.GetRow()
279          self.currentSelection = [ event.GetRow() ]          self.currentSelection = [ event.GetRow() ]
280          #self.ConfigureForSelection()          #self.ConfigureForSelection()
281          event.Skip()          event.Skip()
282    
283        def _OnCellResize(self, event):
284            self.FitInside()
285    
286  class ClassTable(wxPyGridTableBase):  class ClassTable(wxPyGridTableBase):
287      """Represents the underlying data structure for the grid."""      """Represents the underlying data structure for the grid."""
288    
# Line 302  class ClassTable(wxPyGridTableBase): Line 303  class ClassTable(wxPyGridTableBase):
303          wxPyGridTableBase.__init__(self)          wxPyGridTableBase.__init__(self)
304    
305          self.SetView(view)          self.SetView(view)
306          self.tdata = []          self.clazz = None
307    
308          #self.Reset(clazz, shapeType)          #self.Reset(clazz, shapeType)
309    
# Line 320  class ClassTable(wxPyGridTableBase): Line 321  class ClassTable(wxPyGridTableBase):
321          shapeType -- the type of shape that the layer uses          shapeType -- the type of shape that the layer uses
322          """          """
323    
324          assert(isinstance(clazz, Classification))          assert isinstance(clazz, Classification)
325    
326          self.GetView().BeginBatch()          self.GetView().BeginBatch()
327    
328          self.fieldType = clazz.GetFieldType()          self.fieldType = clazz.GetFieldType()
329          self.shapeType = shapeType          self.shapeType = shapeType
330    
331          old_len = len(self.tdata)          self.SetClassification(clazz, group)
332            self.__Modified(-1)
333            #print "11------------------"
334    
335            self.GetView().EndBatch()
336            self.GetView().FitInside()
337    
338        def GetClassification(self):
339            return self.clazz
340    
341        def SetClassification(self, clazz, group = None):
342    
343            self.GetView().BeginBatch()
344    
345          self.tdata = []          old_len = self.GetNumberRows()
346    
347          print "9------------------"          #print "9------------------"
348          #          #
349          # copy the data out of the classification and into our          # copy the data out of the classification and into our
350          # array          # array
351          #          #
352          row = -1          row = -1
353          for g in clazz:  #       for g in clazz:
354              ng = copy.deepcopy(g)  #           ng = copy.deepcopy(g)
355              self.__SetRow(-1, ng)  #           self.__SetRow(None, ng)
356              if g is group:  #           if g is group:
357                  row = self.GetNumberRows() - 1  #               row = self.GetNumberRows() - 1
358                  print "selecting row..."  #               #print "selecting row..."
359    
360          print "10------------------"          #print "10------------------"
   
         self.__Modified(-1)  
361    
362          self.__NotifyRowChanges(old_len, len(self.tdata))          #self.clazz = copy.deepcopy(clazz)
363          print "11------------------"          self.clazz = clazz
364    
365            self.__NotifyRowChanges(old_len, self.GetNumberRows())
366    
367          if row > -1:          if row > -1:
368              self.GetView().ClearSelection()              self.GetView().ClearSelection()
369              self.GetView().SelectRow(row)              self.GetView().SelectRow(row)
370              self.GetView().MakeCellVisible(row, 0)              self.GetView().MakeCellVisible(row, 0)
371                
372            self.__Modified()
373    
374          self.GetView().EndBatch()          self.GetView().EndBatch()
375            self.GetView().FitInside()
376    
377      def __NotifyRowChanges(self, curRows, newRows):      def __NotifyRowChanges(self, curRows, newRows):
378          #          #
# Line 372  class ClassTable(wxPyGridTableBase): Line 388  class ClassTable(wxPyGridTableBase):
388          elif newRows < curRows:          elif newRows < curRows:
389              msg = wxGridTableMessage(self,              msg = wxGridTableMessage(self,
390                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,
391                          curRows - newRows,    # position                          curRows,              # position
392                          curRows - newRows)    # how many                          curRows - newRows)    # how many
393              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
394              self.GetView().FitInside()              self.GetView().FitInside()
395    
396    
397      def __SetRow(self, row, group):      def __SetRow(self, row, group):
398          """Set a row's data to that of the group.          """Set a row's data to that of the group.
399    
400          The table is considered modified after this operation.          The table is considered modified after this operation.
401    
402          row -- if row is -1 or greater than the current number of rows          row -- if row is < 0 'group' is inserted at the top of the table
403                 then group is appended to the end.                 if row is >= GetNumberRows() or None 'group' is append to
404                        the end of the table.
405                   otherwise 'group' replaces row 'row'
406          """          """
407    
408          # either append or replace          # either append or replace
409          if row == -1 or row >= self.GetNumberRows():          if row is None or row >= self.GetNumberRows():
410              self.tdata.append(group)              self.clazz.AppendGroup(group)
411            elif row < 0:
412                self.clazz.InsertGroup(0, group)
413          else:          else:
414              self.tdata[row] = group              if row == 0:
415                    self.clazz.SetDefaultGroup(group)
416                else:
417                    self.clazz.ReplaceGroup(row - 1, group)
418    
419          self.__Modified()          self.__Modified()
420    
# Line 401  class ClassTable(wxPyGridTableBase): Line 425  class ClassTable(wxPyGridTableBase):
425      def GetRowLabelValue(self, row):      def GetRowLabelValue(self, row):
426          """Return the label for the given row."""          """Return the label for the given row."""
427    
428          group = self.tdata[row]          if row == 0:
429          if isinstance(group, ClassGroupDefault):   return _("Default")              return _("Default")
430          if isinstance(group, ClassGroupSingleton): return _("Singleton")          else:
431          if isinstance(group, ClassGroupRange):     return _("Range")              group = self.clazz.GetGroup(row - 1)
432          if isinstance(group, ClassGroupMap):       return _("Map")              if isinstance(group, ClassGroupDefault):   return _("Default")
433                if isinstance(group, ClassGroupSingleton): return _("Singleton")
434                if isinstance(group, ClassGroupRange):     return _("Range")
435                if isinstance(group, ClassGroupMap):       return _("Map")
436    
437          assert(False) # shouldn't get here          assert False # shouldn't get here
438          return _("")          return _("")
439    
440      def GetNumberRows(self):      def GetNumberRows(self):
441          """Return the number of rows."""          """Return the number of rows."""
442          return len(self.tdata)          if self.clazz is None:
443                return 0
444    
445            return self.clazz.GetNumGroups() + 1 # +1 for default group
446    
447      def GetNumberCols(self):      def GetNumberCols(self):
448          """Return the number of columns."""          """Return the number of columns."""
# Line 443  class ClassTable(wxPyGridTableBase): Line 473  class ClassTable(wxPyGridTableBase):
473          typeName -- unused, but needed to overload wxPyGridTableBase          typeName -- unused, but needed to overload wxPyGridTableBase
474          """          """
475    
476          group = self.tdata[row]          if row == 0:
477                group = self.clazz.GetDefaultGroup()
478            else:
479                group = self.clazz.GetGroup(row - 1)
480    
481    
482          if col == COL_SYMBOL:          if col == COL_SYMBOL:
483              return group.GetProperties()              return group.GetProperties()
# Line 452  class ClassTable(wxPyGridTableBase): Line 486  class ClassTable(wxPyGridTableBase):
486              return group.GetLabel()              return group.GetLabel()
487    
488          # col must be COL_VALUE          # col must be COL_VALUE
489          assert(col == COL_VALUE)          assert col == COL_VALUE
490    
491          if isinstance(group, ClassGroupDefault):          if isinstance(group, ClassGroupDefault):
492              return _("DEFAULT")              return _("DEFAULT")
# Line 501  class ClassTable(wxPyGridTableBase): Line 535  class ClassTable(wxPyGridTableBase):
535    
536                  return (conv(Str2Num(value[:i])), conv(Str2Num(value[i+1:])))                  return (conv(Str2Num(value[:i])), conv(Str2Num(value[i+1:])))
537    
538          assert(False) # shouldn't get here          assert False  # shouldn't get here
539          return (0,)          return (0,)
540                            
541    
# Line 517  class ClassTable(wxPyGridTableBase): Line 551  class ClassTable(wxPyGridTableBase):
551          typeName -- unused, but needed to overload wxPyGridTableBase          typeName -- unused, but needed to overload wxPyGridTableBase
552          """          """
553    
554          assert(col >= 0 and col < self.GetNumberCols())          assert col >= 0 and col < self.GetNumberCols()
555          assert(row >= 0 and row < self.GetNumberRows())          assert row >= 0 and row < self.GetNumberRows()
556    
557          group = self.tdata[row]          if row == 0:
558                group = self.clazz.GetDefaultGroup()
559            else:
560                group = self.clazz.GetGroup(row - 1)
561    
562          mod = True # assume the data will change          mod = True # assume the data will change
563    
# Line 563  class ClassTable(wxPyGridTableBase): Line 600  class ClassTable(wxPyGridTableBase):
600                              changed = True                              changed = True
601                          ngroup.SetRange(dataInfo[0], dataInfo[1])                          ngroup.SetRange(dataInfo[0], dataInfo[1])
602                      else:                      else:
603                          assert(False)                          assert False
604                          pass                          pass
605    
606                      if changed:                      if changed:
607                          ngroup.SetLabel(group.GetLabel())                          ngroup.SetLabel(group.GetLabel())
608                          self.SetClassGroup(row, ngroup)                          self.SetClassGroup(row, ngroup)
609          else:          else:
610              assert(False) # shouldn't be here              assert False # shouldn't be here
611              pass              pass
612    
613          if mod:          if mod:
# Line 594  class ClassTable(wxPyGridTableBase): Line 631  class ClassTable(wxPyGridTableBase):
631      def GetClassGroup(self, row):      def GetClassGroup(self, row):
632          """Return the ClassGroup object representing row 'row'."""          """Return the ClassGroup object representing row 'row'."""
633    
634          return self.tdata[row] # self.GetValueAsCustom(row, COL_SYMBOL, None)          #return self.GetValueAsCustom(row, COL_SYMBOL, None)
635            if row == 0:
636                return self.clazz.GetDefaultGroup()
637            else:
638                return self.clazz.GetGroup(row - 1)
639    
640      def SetClassGroup(self, row, group):      def SetClassGroup(self, row, group):
641          self.__SetRow(row, group)          self.__SetRow(row, group)
# Line 625  class ClassTable(wxPyGridTableBase): Line 666  class ClassTable(wxPyGridTableBase):
666          The table is considered modified if any rows are removed.          The table is considered modified if any rows are removed.
667          """          """
668    
669          assert(pos >= 0)          assert pos >= 0
670          old_len = len(self.tdata)          old_len = self.GetNumberRows()
671          for row in range(pos, pos - numRows, -1):          for row in range(pos, pos - numRows, -1):
672              group = self.GetClassGroup(row)              group = self.GetClassGroup(row)
673              if not isinstance(group, ClassGroupDefault):              if row != 0:
674                  self.tdata.pop(row)                  self.clazz.RemoveGroup(row - 1)
675                  self.__Modified()                  self.__Modified()
676            
677          if self.IsModified():          if self.IsModified():
678              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
679    
680      def AppendRows(self, numRows = 1):      def AppendRows(self, numRows = 1):
681          """Append 'numRows' empty rows to the end of the table.          """Append 'numRows' empty rows to the end of the table.
# Line 642  class ClassTable(wxPyGridTableBase): Line 683  class ClassTable(wxPyGridTableBase):
683          The table is considered modified if any rows are appended.          The table is considered modified if any rows are appended.
684          """          """
685    
686          old_len = len(self.tdata)          old_len = self.GetNumberRows()
687          for i in range(numRows):          for i in range(numRows):
688              np = ClassGroupSingleton()              np = ClassGroupSingleton()
689              self.__SetRow(-1, np)              self.__SetRow(None, np)
690    
691          if self.IsModified():          if self.IsModified():
692              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
693    
694    
695  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
# Line 695  class Classifier(NonModalDialog): Line 736  class Classifier(NonModalDialog):
736    
737              if name == field:              if name == field:
738                  self.__cur_field = i + 1                  self.__cur_field = i + 1
739                  self.fields.SetClientData(i + 1, self.originalClass)                  self.fields.SetClientData(i + 1,
740                                              copy.deepcopy(self.originalClass))
741              else:              else:
742                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
743    
# Line 733  class Classifier(NonModalDialog): Line 775  class Classifier(NonModalDialog):
775          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
776          self.controlButtons.append(button)          self.controlButtons.append(button)
777    
778          button = wxButton(panel, ID_CLASSIFY_GENRANGE, _("Generate Ranges"))          button = wxButton(panel, ID_CLASSIFY_EDITPROPS, _("Edit Properties"))
779            controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
780            self.controlButtons.append(button)
781    
782            button = wxButton(panel, ID_CLASSIFY_GENCLASS, _("Generate Class"))
783          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
784          self.controlButtons.append(button)          self.controlButtons.append(button)
785    
# Line 757  class Classifier(NonModalDialog): Line 803  class Classifier(NonModalDialog):
803          # Classification data table          # Classification data table
804          #          #
805    
806          self.classGrid = ClassGrid(panel)          self.classGrid = ClassGrid(panel, self)
807          #self.__SetGridTable(self.__cur_field, group)          #self.__SetGridTable(self.__cur_field, group)
808          #self.fields.SetSelection(self.__cur_field)          #self.fields.SetSelection(self.__cur_field)
809    
810          # calling __SelectField after creating the classGrid fills in the          # calling __SelectField after creating the classGrid fills in the
811          # grid with the correct information          # grid with the correct information
812          print "2------------------"          #print "2------------------"
813            self.fields.SetSelection(self.__cur_field)
814          self.__SelectField(self.__cur_field, group = group)          self.__SelectField(self.__cur_field, group = group)
815    
816          #self.classGrid.SelectGroup(group)          #self.classGrid.SelectGroup(group)
# Line 776  class Classifier(NonModalDialog): Line 823  class Classifier(NonModalDialog):
823          panelBox.Add(controlBox, 1, wxGROW, 10)          panelBox.Add(controlBox, 1, wxGROW, 10)
824    
825          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)
826            EVT_BUTTON(self, ID_CLASSIFY_EDITPROPS, self._OnEditGroupProperties)
827          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)
828          EVT_BUTTON(self, ID_CLASSIFY_GENRANGE, self._OnGenRange)          EVT_BUTTON(self, ID_CLASSIFY_GENCLASS, self._OnGenClass)
829          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)
830          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)
831    
# Line 790  class Classifier(NonModalDialog): Line 838  class Classifier(NonModalDialog):
838          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),
839                        0, wxALL, 4)                        0, wxALL, 4)
840          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
841            buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")),
842                          0, wxALL, 4)
843            buttonBox.Add(60, 20, 0, wxALL, 4)
844          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),
845                        0, wxALL, 4)                        0, wxALL, 4)
846          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
847    
848          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)
849          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)
850            EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn)
851          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)
852    
853          ###########          ###########
# Line 805  class Classifier(NonModalDialog): Line 857  class Classifier(NonModalDialog):
857          panel.SetSizer(panelBox)          panel.SetSizer(panelBox)
858          panelBox.SetSizeHints(panel)          panelBox.SetSizeHints(panel)
859    
860          topBox.Add(panel, 1, wxGROW, 0)          topBox.Add(panel, 1, wxGROW, 0)
861          panelBox.SetSizeHints(self)          panelBox.SetSizeHints(self)
862          self.SetAutoLayout(True)          self.SetAutoLayout(True)
863          self.SetSizer(topBox)          self.SetSizer(topBox)
864    
865          print "1------------------"          #print "1------------------"
866          #self.Fit()          #self.Fit()
867          ######################          ######################
868    
869          self.haveApplied = False          self.haveApplied = False
870    
871      def __BuildClassification(self, fieldIndex):      def EditGroupProperties(self, row):
872            table = self.classGrid.GetTable()
873            prop = table.GetValueAsCustom(row, COL_SYMBOL, None)
874    
875            # get a new ClassGroupProperties object and copy the
876            # values over to our current object
877            propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())
878            if propDlg.ShowModal() == wxID_OK:
879                new_prop = propDlg.GetClassGroupProperties()
880                table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)
881            propDlg.Destroy()
882            
883    
884        def __BuildClassification(self, fieldIndex, copyClass = False):
885    
886          numRows = self.classGrid.GetNumberRows()  #       numRows = self.classGrid.GetNumberRows()
887          assert(numRows > 0) # there should always be a default row  #       assert numRows > 0  # there should always be a default row
888    
889          clazz = Classification()  #       clazz = Classification()
890          if fieldIndex == 0:          if fieldIndex == 0:
891              fieldName = None              fieldName = None
892              fieldType = None              fieldType = None
# Line 829  class Classifier(NonModalDialog): Line 894  class Classifier(NonModalDialog):
894              fieldName = self.fields.GetString(fieldIndex)              fieldName = self.fields.GetString(fieldIndex)
895              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
896    
897            clazz = self.classGrid.GetTable().GetClassification()
898    
899            if copyClass:
900                clazz = copy.deepcopy(clazz)
901    
902          clazz.SetField(fieldName)          clazz.SetField(fieldName)
903          clazz.SetFieldType(fieldType)          clazz.SetFieldType(fieldType)
904    
905    
906          table = self.classGrid.GetTable()  #       table = self.classGrid.GetTable()
907          clazz.SetDefaultGroup(table.GetClassGroup(0))  #       clazz.SetDefaultGroup(table.GetClassGroup(0))
908    
909          for i in range(1, numRows):  #       for i in range(1, numRows):
910              clazz.AddGroup(table.GetClassGroup(i))  #           clazz.AppendGroup(table.GetClassGroup(i))
911    
912          return clazz          return clazz
913    
# Line 856  class Classifier(NonModalDialog): Line 926  class Classifier(NonModalDialog):
926              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
927              clazz.SetFieldType(fieldType)              clazz.SetFieldType(fieldType)
928                                    
929          print "6------------------"          #print "6------------------"
930          self.classGrid.CreateTable(clazz, self.layer.ShapeType(), group)          self.classGrid.CreateTable(clazz, self.layer.ShapeType(), group)
931          print "7------------------"          #print "7------------------"
932    
933    
934    
# Line 871  class Classifier(NonModalDialog): Line 941  class Classifier(NonModalDialog):
941          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
942          fieldType = self.layer.GetFieldType(fieldName)          fieldType = self.layer.GetFieldType(fieldName)
943    
944          assert(Classifier.type2string.has_key(fieldType))          assert Classifier.type2string.has_key(fieldType)
945    
946          text = Classifier.type2string[fieldType]          text = Classifier.type2string[fieldType]
947    
948          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)
949    
950      def __SelectField(self, newIndex, oldIndex = -1, group = None):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
951            """This method assumes that the current selection for the
952            combo has already been set by a call to SetSelection().
953            """
954    
955          print "3------------------"          #print "3------------------"
   
         assert(oldIndex >= -1)  
956    
957          self.fields.SetSelection(newIndex)          assert oldIndex >= -1
958    
959          if oldIndex != -1:          if oldIndex != -1:
960              clazz = self.__BuildClassification(oldIndex)              clazz = self.__BuildClassification(oldIndex)
961              self.fields.SetClientData(oldIndex, clazz)              self.fields.SetClientData(oldIndex, clazz)
962    
963          print "4------------------"          #print "4------------------"
964          self.__SetGridTable(newIndex, group)          self.__SetGridTable(newIndex, group)
965          print "5------------------"          #print "5------------------"
966    
967          enabled = newIndex != 0          enabled = newIndex != 0
968    
# Line 901  class Classifier(NonModalDialog): Line 972  class Classifier(NonModalDialog):
972          self.__SetFieldTypeText(newIndex)          self.__SetFieldTypeText(newIndex)
973    
974    
975        def _OnEditGroupProperties(self, event):
976            sel = self.classGrid.GetCurrentSelection()
977    
978            if len(sel) == 1:
979                self.EditGroupProperties(sel[0])
980    
981      def _OnFieldSelect(self, event):      def _OnFieldSelect(self, event):
982          index = self.fields.GetSelection()          index = self.fields.GetSelection()
983          self.__SelectField(index, self.__cur_field)          self.__SelectField(index, self.__cur_field)
# Line 918  class Classifier(NonModalDialog): Line 995  class Classifier(NonModalDialog):
995          # to begin with or it has been modified          # to begin with or it has been modified
996          #          #
997          if clazz is None or self.classGrid.GetTable().IsModified():          if clazz is None or self.classGrid.GetTable().IsModified():
998              clazz = self.__BuildClassification(self.__cur_field)              clazz = self.__BuildClassification(self.__cur_field, True)
999    
1000          self.layer.SetClassification(clazz)          self.layer.SetClassification(clazz)
1001    
# Line 926  class Classifier(NonModalDialog): Line 1003  class Classifier(NonModalDialog):
1003    
1004      def _OnOK(self, event):      def _OnOK(self, event):
1005          self._OnApply(event)          self._OnApply(event)
1006          self.OnClose(event)          self.Close()
1007    
1008        def _OnCloseBtn(self, event):
1009            """Close is similar to Cancel except that any changes that were
1010            made and applied remain applied, but the currently displayed
1011            classification is discarded.
1012            """
1013    
1014            self.Close()
1015    
1016      def _OnCancel(self, event):      def _OnCancel(self, event):
1017          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
1018          if self.haveApplied:          if self.haveApplied:
1019              self.layer.SetClassification(self.originalClass)              self.layer.SetClassification(self.originalClass)
1020    
1021          self.OnClose(event)          self.Close()
1022    
1023      def _OnAdd(self, event):      def _OnAdd(self, event):
1024          self.classGrid.AppendRows()          self.classGrid.AppendRows()
# Line 941  class Classifier(NonModalDialog): Line 1026  class Classifier(NonModalDialog):
1026      def _OnRemove(self, event):      def _OnRemove(self, event):
1027          self.classGrid.DeleteSelectedRows()          self.classGrid.DeleteSelectedRows()
1028    
1029      def _OnGenRange(self, event):      def _OnGenClass(self, event):
1030          print "Classifier._OnGenRange()"  
1031            genDlg = ClassGenDialog(self,
1032                                    self.layer.table,
1033                                    self.fields.GetString(self.__cur_field))
1034    
1035            if genDlg.ShowModal() == wxID_OK:
1036                clazz = genDlg.GetClassification()
1037                self.fields.SetClientData(self.__cur_field, clazz)
1038                self.classGrid.GetTable().SetClassification(clazz)
1039            genDlg.Destroy()
1040    
1041      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1042          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
1043    
1044          print "sel: ", sel          #print "sel: ", sel
1045    
1046          if len(sel) == 1:          if len(sel) == 1:
1047              i = sel[0]              i = sel[0]
# Line 1004  class SelectPropertiesDialog(wxDialog): Line 1098  class SelectPropertiesDialog(wxDialog):
1098              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
1099          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,
1100                                              self, ID_SELPROP_PREVIEW, (40, 40))                                              self, ID_SELPROP_PREVIEW, (40, 40))
1101          previewBox.Add(self.previewWin, 1, wxGROW, 15)          previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)
1102    
1103          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
1104    
# Line 1086  class SelectPropertiesDialog(wxDialog): Line 1180  class SelectPropertiesDialog(wxDialog):
1180    
1181      def __GetColor(self, cur):      def __GetColor(self, cur):
1182          dialog = wxColourDialog(self)          dialog = wxColourDialog(self)
1183          dialog.GetColourData().SetColour(Color2wxColour(cur))          if cur is not Color.Transparent:
1184                dialog.GetColourData().SetColour(Color2wxColour(cur))
1185    
1186          ret = None          ret = None
1187          if dialog.ShowModal() == wxID_OK:          if dialog.ShowModal() == wxID_OK:
1188              ret = wxColour2Color(dialog.GetColourData().GetColour())              ret = wxColour2Color(dialog.GetColourData().GetColour())
# Line 1102  class SelectPropertiesDialog(wxDialog): Line 1198  class SelectPropertiesDialog(wxDialog):
1198          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1199    
1200      def _OnChangeLineColorTrans(self, event):      def _OnChangeLineColorTrans(self, event):
1201          self.prop.SetLineColor(Color.None)          self.prop.SetLineColor(Color.Transparent)
1202          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1203                    
1204      def _OnChangeFillColor(self, event):      def _OnChangeFillColor(self, event):
# Line 1112  class SelectPropertiesDialog(wxDialog): Line 1208  class SelectPropertiesDialog(wxDialog):
1208          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1209    
1210      def _OnChangeFillColorTrans(self, event):      def _OnChangeFillColorTrans(self, event):
1211          self.prop.SetFill(Color.None)          self.prop.SetFill(Color.Transparent)
1212          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1213    
1214      def GetClassGroupProperties(self):      def GetClassGroupProperties(self):
# Line 1151  class ClassDataPreviewer: Line 1247  class ClassDataPreviewer:
1247    
1248      def Draw(self, dc, rect, prop, shapeType):      def Draw(self, dc, rect, prop, shapeType):
1249    
1250          assert(dc is not None)          assert dc is not None
1251          assert(isinstance(prop, ClassGroupProperties))          assert isinstance(prop, ClassGroupProperties)
1252    
1253          if rect is None:          if rect is None:
1254              x = 0              x = 0
# Line 1165  class ClassDataPreviewer: Line 1261  class ClassDataPreviewer:
1261              h = rect.GetHeight()              h = rect.GetHeight()
1262    
1263          stroke = prop.GetLineColor()          stroke = prop.GetLineColor()
1264          if stroke is Color.None:          if stroke is Color.Transparent:
1265              pen = wxTRANSPARENT_PEN              pen = wxTRANSPARENT_PEN
1266          else:          else:
1267              pen = wxPen(Color2wxColour(stroke),              pen = wxPen(Color2wxColour(stroke),
# Line 1173  class ClassDataPreviewer: Line 1269  class ClassDataPreviewer:
1269                          wxSOLID)                          wxSOLID)
1270    
1271          stroke = prop.GetFill()          stroke = prop.GetFill()
1272          if stroke is Color.None:          if stroke is Color.Transparent:
1273              brush = wxTRANSPARENT_BRUSH              brush = wxTRANSPARENT_BRUSH
1274          else:          else:
1275              brush = wxBrush(Color2wxColour(stroke), wxSOLID)              brush = wxBrush(Color2wxColour(stroke), wxSOLID)
# Line 1187  class ClassDataPreviewer: Line 1283  class ClassDataPreviewer:
1283                             wxPoint(x + w/2, y + h/4*3),                             wxPoint(x + w/2, y + h/4*3),
1284                             wxPoint(x + w, y)])                             wxPoint(x + w, y)])
1285    
1286          elif shapeType == SHAPETYPE_POINT or \          elif shapeType == SHAPETYPE_POINT:
              shapeType == SHAPETYPE_POLYGON:  
1287    
1288              dc.DrawCircle(x + w/2, y + h/2,              dc.DrawCircle(x + w/2, y + h/2,
1289                            (min(w, h) - prop.GetLineWidth())/2)                            (min(w, h) - prop.GetLineWidth())/2)
1290    
1291            elif shapeType == SHAPETYPE_POLYGON:
1292                dc.DrawRectangle(x, y, w, h)
1293    
1294  class ClassRenderer(wxPyGridCellRenderer):  class ClassRenderer(wxPyGridCellRenderer):
1295    
1296      def __init__(self, shapeType):      def __init__(self, shapeType):
# Line 1214  class ClassRenderer(wxPyGridCellRenderer Line 1312  class ClassRenderer(wxPyGridCellRenderer
1312              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)
1313    
1314          if isSelected:          if isSelected:
1315              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),              dc.SetPen(wxPen(wxBLACK, 1, wxSOLID))
                       4, wxSOLID))  
1316              dc.SetBrush(wxTRANSPARENT_BRUSH)              dc.SetBrush(wxTRANSPARENT_BRUSH)
1317    
1318              dc.DrawRectangle(rect.GetX(), rect.GetY(),              dc.DrawRectangle(rect.GetX(), rect.GetY(),
1319                               rect.GetWidth(), rect.GetHeight())                               rect.GetWidth(), rect.GetHeight())
1320    

Legend:
Removed from v.570  
changed lines
  Added in v.615

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26