/[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 614 by jonathan, Fri Apr 4 16:34:46 2003 UTC revision 615 by jonathan, Mon Apr 7 08:57:20 2003 UTC
# Line 44  ID_CLASSIFY_MOVEUP = 4006 Line 44  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  ID_CLASSIFY_EDITPROPS = 4009
47    ID_CLASSIFY_CLOSE = 4010
48    
49  # table columns  # table columns
50  COL_SYMBOL = 0  COL_SYMBOL = 0
# 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 334  class ClassTable(wxPyGridTableBase): Line 335  class ClassTable(wxPyGridTableBase):
335          self.GetView().EndBatch()          self.GetView().EndBatch()
336          self.GetView().FitInside()          self.GetView().FitInside()
337    
338        def GetClassification(self):
339            return self.clazz
340    
341      def SetClassification(self, clazz, group = None):      def SetClassification(self, clazz, group = None):
342    
343          self.GetView().BeginBatch()          self.GetView().BeginBatch()
344    
345          old_len = self.GetNumberRows()          old_len = self.GetNumberRows()
         self.tdata = []  
346    
347          #print "9------------------"          #print "9------------------"
348          #          #
# Line 347  class ClassTable(wxPyGridTableBase): Line 350  class ClassTable(wxPyGridTableBase):
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(None, 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------------------"
361    
362            #self.clazz = copy.deepcopy(clazz)
363            self.clazz = clazz
364    
365          self.__NotifyRowChanges(old_len, self.GetNumberRows())          self.__NotifyRowChanges(old_len, self.GetNumberRows())
366    
# Line 363  class ClassTable(wxPyGridTableBase): Line 369  class ClassTable(wxPyGridTableBase):
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()          self.GetView().FitInside()
376    
# Line 385  class ClassTable(wxPyGridTableBase): Line 393  class ClassTable(wxPyGridTableBase):
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    
# Line 398  class ClassTable(wxPyGridTableBase): Line 407  class ClassTable(wxPyGridTableBase):
407    
408          # either append or replace          # either append or replace
409          if row is None 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:          elif row < 0:
412              self.tdata.insert(0, group)              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 413  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 455  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 473  class ClassTable(wxPyGridTableBase): Line 495  class ClassTable(wxPyGridTableBase):
495          elif isinstance(group, ClassGroupRange):          elif isinstance(group, ClassGroupRange):
496              return _("%s - %s") % (group.GetMin(), group.GetMax())              return _("%s - %s") % (group.GetMin(), group.GetMax())
497    
498          assert False  # shouldn't get here          assert(False) # shouldn't get here
499          return None          return None
500    
501      def __ParseInput(self, value):      def __ParseInput(self, value):
# Line 532  class ClassTable(wxPyGridTableBase): Line 554  class ClassTable(wxPyGridTableBase):
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 606  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 638  class ClassTable(wxPyGridTableBase): Line 667  class ClassTable(wxPyGridTableBase):
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 654  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(None, 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 707  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 808  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 847  class Classifier(NonModalDialog): Line 881  class Classifier(NonModalDialog):
881          propDlg.Destroy()          propDlg.Destroy()
882                    
883    
884      def __BuildClassification(self, fieldIndex):      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 860  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 956  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 964  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 1051  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 1265  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.614  
changed lines
  Added in v.615

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26