2 @package mapdisp_vdigit.py
4 @brief Map display canvas extended for vector digitizer
6 See also vdigit.py, wxvdriver.py and wxvdigit.py
11 (C) 2011 by the GRASS Development Team
12 This program is free software under the GNU General Public
13 License (>=v2). Read the file COPYING that comes with GRASS
16 @author Martin Landa <landa.martin gmail.com>
24 from debug
import Debug
25 from mapdisp_window
import BufferedWindow
26 from preferences
import globalSettings
as UserSettings
27 from utils
import ListOfCatsToRange
28 from globalvar
import QUERYLAYER
29 from vdigit
import VDigitCategoryDialog
30 from vdigit
import VDigitZBulkDialog
31 from vdigit
import VDigitDuplicatesDialog
34 """!A Buffered window extended for vector digitizer.
36 def __init__(self, parent, id = wx.ID_ANY,
37 Map =
None, tree =
None, lmgr =
None,
38 style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):
39 BufferedWindow.__init__(self, parent, id, Map, tree, lmgr,
43 self.
toolbar = self.parent.toolbars[
'vdigit']
46 self.Bind(wx.EVT_KEY_DOWN, self.
OnKeyDown)
49 """!Set up related toolbar
53 def _onMotion(self, coord, precision):
54 """!Track mouse motion and update statusbar (see self.Motion)
56 @parem coord easting, northing
57 @param precision formatting precision
61 if self.toolbar.GetAction() !=
'addLine' or \
62 self.toolbar.GetAction(
'type')
not in (
'line',
'boundary')
or \
67 distance_seg = self.Distance(self.
polycoords[-1],
68 (e, n), screen =
False)[0]
69 distance_tot = distance_seg
71 distance_tot += self.Distance(self.
polycoords[idx-1],
74 self.parent.statusbar.SetStatusText(
"%.*f, %.*f (seg: %.*f; tot: %.*f)" % \
75 (precision, e, precision, n,
76 precision, distance_seg,
77 precision, distance_tot), 0)
83 shift = event.ShiftDown()
84 kc = event.GetKeyCode()
89 event = wx.CommandEvent(winid = self.toolbar.addPoint)
90 tool = self.toolbar.OnAddPoint
92 event = wx.CommandEvent(winid = self.toolbar.addLine)
93 tool = self.toolbar.OnAddLine
95 self.toolbar.OnTool(event)
100 not self.toolbar.GetLayer():
104 self.digit.GetDisplay().UpdateRegion()
109 self.pdcVector.RemoveAll()
112 item = self.tree.FindItemByData(
'maplayer', self.toolbar.GetLayer())
116 if item
and self.tree.IsItemChecked(item):
118 self.digit.GetDisplay().DrawMap()
121 if self.toolbar.GetAction() ==
'moveLine' and \
122 hasattr(self,
"moveInfo"):
126 self.pdcTmp.TranslateId(id,
132 """!Left mouse button pressed - add new feature
135 mapLayer = self.toolbar.GetLayer().GetName()
139 if self.toolbar.GetAction(
'type')
in [
'point',
'centroid']:
141 east, north = self.Pixel2Cell(self.mouse[
'begin'])
142 nfeat, fids = self.digit.AddFeature(self.toolbar.GetAction(
'type'), [(east, north)])
146 self.UpdateMap(render =
False)
149 if UserSettings.Get(group =
'vdigit', key =
"addRecord", subkey =
'enabled'):
152 UserSettings.Get(group =
'vdigit', key =
"layer", subkey =
'value') :
153 (UserSettings.Get(group =
'vdigit', key =
"category", subkey =
'value'), )
156 posWindow = self.ClientToScreen((self.mouse[
'end'][0] + self.dialogOffset,
157 self.mouse[
'end'][1] + self.dialogOffset))
164 if self.toolbar.GetAction(
'type') ==
'centroid':
167 self.
_geomAttrb(fid, addRecordDlg,
'perimeter')
169 if addRecordDlg.mapDBInfo
and \
170 addRecordDlg.ShowModal() == wx.ID_OK:
171 sqlfile = tempfile.NamedTemporaryFile(mode =
"w")
172 for sql
in addRecordDlg.GetSQLString():
173 sqlfile.file.write(sql +
";\n")
176 gcmd.RunCommand(
'db.execute',
179 input = sqlfile.name)
181 if addRecordDlg.mapDBInfo:
184 elif self.toolbar.GetAction(
'type')
in [
"line",
"boundary",
"area"]:
186 self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
187 self.DrawLines(pdc = self.pdcTmp)
189 def _geomAttrb(self, fid, dialog, attrb):
190 """!Define geometry attributes
192 mapLayer = self.toolbar.GetLayer()
193 item = self.tree.FindItemByData(
'maplayer', mapLayer)
194 vdigit = self.tree.GetPyData(item)[0][
'vdigit']
196 'geomAttr' not in vdigit
or \
197 attrb
not in vdigit[
'geomAttr']:
201 if attrb ==
'length':
202 val = self.digit.GetLineLength(fid)
204 elif attrb ==
'area':
205 val = self.digit.GetAreaSize(fid)
207 elif attrb ==
'perimeter':
208 val = self.digit.GetAreaPerimeter(fid)
212 layer = int(UserSettings.Get(group =
'vdigit', key =
"layer", subkey =
'value'))
213 column = vdigit[
'geomAttr'][attrb][
'column']
214 val = UnitsConvertValue(val, type, vdigit[
'geomAttr'][attrb][
'units'])
215 dialog.SetColumnValue(layer, column, val)
218 def _geomAttrbUpdate(self, fids):
219 """!Update geometry atrributes of currently selected features
221 @param fid list feature id
223 mapLayer = self.parent.toolbars[
'vdigit'].GetLayer()
224 vectorName = mapLayer.GetName()
225 item = self.tree.FindItemByData(
'maplayer', mapLayer)
226 vdigit = self.tree.GetPyData(item)[0][
'vdigit']
228 if vdigit
is None or 'geomAttr' not in vdigit:
232 sqlfile = tempfile.NamedTemporaryFile(mode =
"w")
234 for layer, cats
in self.digit.GetLineCats(fid).iteritems():
235 table = dbInfo.GetTable(layer)
236 for attrb, item
in vdigit[
'geomAttr'].iteritems():
238 if attrb ==
'length':
239 val = self.digit.GetLineLength(fid)
241 elif attrb ==
'area':
242 val = self.digit.GetAreaSize(fid)
244 elif attrb ==
'perimeter':
245 val = self.digit.GetAreaPerimeter(fid)
250 val = UnitsConvertValue(val, type, item[
'units'])
253 sqlfile.write(
'UPDATE %s SET %s = %f WHERE %s = %d;\n' % \
254 (table, item[
'column'], val,
255 dbInfo.GetKeyColumn(layer), cat))
258 gcmd.RunCommand(
'db.execute',
261 input = sqlfile.name)
263 def _updateATM(self):
264 """!Update open Attribute Table Manager
266 @todo: use AddDataRow() instead
269 digitVector = self.toolbar.GetLayer().GetName()
271 for atm
in self.lmgr.dialogs[
'atm']:
272 atmVector = atm.GetVectorName()
273 if atmVector == digitVector:
274 layer = UserSettings.Get(group =
'vdigit', key =
"layer", subkey =
'value')
279 """!Left mouse button pressed - edit linear feature - add new
282 self.polycoords.append(self.Pixel2Cell(self.mouse[
'begin']))
283 self.
moveInfo[
'id'].append(wx.NewId())
284 self.DrawLines(pdc = self.pdcTmp)
287 """!Left mouse button pressed - vector digitizer move
288 feature/vertex, edit linear feature
297 if self.toolbar.GetAction()
in [
"moveVertex",
"editLine"]:
298 pcolor = UserSettings.Get(group =
'vdigit', key =
"symbol",
299 subkey = [
"highlight",
"color"])
301 width = 2, style = wx.SHORT_DASH)
302 self.pdcTmp.SetPen(self.
polypen)
305 """!Left mouse button pressed - vector digitizer display categories
309 mapLayer = self.toolbar.GetLayer().GetName()
313 coords = self.Pixel2Cell(self.mouse[
'begin'])
316 self.digit.GetDisplay().SetSelected([])
320 self.digit.GetDisplay().SelectLineByPoint(coords)
322 if not self.digit.GetDisplay().GetSelected():
323 for key
in (
'attributes',
'category'):
324 if self.parent.dialogs[key]
and \
325 self.parent.dialogs[key].IsShown():
326 self.parent.dialogs[key].Hide()
327 self.UpdateMap(render =
False, renderVector =
True)
330 if UserSettings.Get(group =
'vdigit', key =
'checkForDupl',
332 lines = self.digit.GetDisplay().GetSelected()
334 lines = (self.digit.GetDisplay().GetSelected()[0],)
337 cats[line] = self.digit.GetLineCats(line)
339 posWindow = self.ClientToScreen((self.mouse[
'end'][0] + self.dialogOffset,
340 self.mouse[
'end'][1] + self.dialogOffset))
342 if self.toolbar.GetAction() ==
"displayAttrs":
344 if self.parent.dialogs[
'attributes']
is None:
345 self.parent.dialogs[
'attributes'] = \
351 self.parent.dialogs[
'attributes'].
UpdateDialog(cats = cats)
353 if self.parent.dialogs[
'attributes']:
354 if len(cats.keys()) > 0:
356 if not self.parent.dialogs[
'attributes'].IsShown():
357 self.parent.dialogs[
'attributes'].Show()
359 if self.parent.dialogs[
'attributes']
and \
360 self.parent.dialogs[
'attributes'].IsShown():
361 self.parent.dialogs[
'attributes'].Hide()
364 if self.parent.dialogs[
'category']
is None:
366 dlg = VDigitCategoryDialog(parent = self,
367 vectorName = mapLayer,
370 title = _(
"Update categories"))
371 self.parent.dialogs[
'category'] = dlg
374 self.parent.dialogs[
'category'].
UpdateDialog(cats = cats)
376 if self.parent.dialogs[
'category']:
377 if len(cats.keys()) > 0:
379 if not self.parent.dialogs[
'category'].IsShown():
380 self.parent.dialogs[
'category'].Show()
382 if self.parent.dialogs[
'category'].IsShown():
383 self.parent.dialogs[
'category'].Hide()
385 self.UpdateMap(render =
False, renderVector =
True)
388 """!Left mouse button pressed - vector digitizer copy
389 categories or attributes action
391 if not hasattr(self,
"copyCatsList"):
395 self.mouse[
'box'] =
'box'
398 """!Left mouse button pressed - vector digitizer copy lines
401 if not hasattr(self,
"copyIds"):
406 """!Left mouse button pressed - vector digitizer label 3D
411 self.ClearLines(pdc = self.pdcTmp)
412 self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
415 end = self.Pixel2Cell(self.mouse[
'end'])
418 begin = self.Pixel2Cell(self.mouse[
'begin'])
420 self.DrawLines(self.pdcTmp, polycoords = (begin, end))
423 """!Left mouse button pressed with control key - vector
424 digitizer undo functionality
426 if self.mouse[
"use"] !=
"pointer" or not self.
toolbar:
429 action = self.toolbar.GetAction()
430 if (action ==
"addLine" and \
431 self.toolbar.GetAction(
'type')
in [
"line",
"boundary",
"area"])
or \
432 action ==
"editLine":
435 removed = self.polycoords.pop()
436 Debug.msg(4,
"BufferedWindow.OnMiddleDown(): polycoords_poped=%s" % \
442 if action ==
"editLine":
447 self.UpdateMap(render =
False, renderVector =
False)
449 elif action
in [
"deleteLine",
"moveLine",
"splitLine",
450 "addVertex",
"removeVertex",
"moveVertex",
451 "copyCats",
"flipLine",
"mergeLine",
452 "snapLine",
"connectLine",
"copyLine",
453 "queryLine",
"breakLine",
"typeConv"]:
455 self.digit.GetDisplay().SetSelected([])
456 if action
in [
"moveLine",
"moveVertex",
"editLine"]
and \
457 hasattr(self,
"moveInfo"):
460 elif action ==
"copyCats":
464 except AttributeError:
467 elif action ==
"copyLine":
471 self.UpdateMap(render =
True, renderVector =
False)
475 self.UpdateMap(render =
False)
477 elif action ==
"zbulkLine":
480 self.digit.GetDisplay().SetSelected([])
481 self.UpdateMap(render =
False)
484 self.UpdateMap(render =
False, renderVector =
False)
486 def _onLeftDown(self, event):
487 """!Left mouse button donw - vector digitizer various actions
490 mapLayer = self.toolbar.GetLayer().GetName()
493 message = _(
"No vector map selected for editing."))
497 action = self.toolbar.GetAction()
501 if action
not in (
"moveVertex",
506 self.
pen = wx.Pen(colour =
'Red', width = 2, style = wx.SHORT_DASH)
507 self.
polypen = wx.Pen(colour =
'dark green', width = 2, style = wx.SOLID)
509 if action
in (
"addVertex",
513 self.digit.GetDisplay().SetSelected([])
515 if action ==
"addLine":
518 elif action ==
"editLine" and \
519 hasattr(self,
"moveInfo"):
522 elif action
in (
"moveLine",
"moveVertex",
"editLine")
and \
523 not hasattr(self,
"moveInfo"):
526 elif action
in (
"displayAttrs"
530 elif action
in (
"copyCats",
534 elif action ==
"copyLine":
537 elif action ==
"zbulkLine":
541 """!Left mouse button released - vector digitizer various
544 pos1 = self.Pixel2Cell(self.mouse[
'begin'])
545 pos2 = self.Pixel2Cell(self.mouse[
'end'])
548 action = self.toolbar.GetAction()
550 if action
in (
"moveVertex",
552 if len(self.digit.GetDisplay().GetSelected()) == 0:
553 nselected = self.digit.GetDisplay().SelectLineByPoint(pos1)[
'point']
555 if action ==
"editLine":
557 selVertex = self.digit.GetDisplay().GetSelectedVertex(pos1)[0]
563 ids = self.digit.GetDisplay().GetSelected(grassId =
False)
568 e, n = self.Pixel2Cell(self.pdcVector.GetIdBounds(id)[0:2])
569 self.polycoords.append((e, n))
570 self.digit.GetDisplay().DrawSelected(
False)
572 if selVertex < ids[-1] / 2:
575 self.polycoords.reverse()
578 self.digit.GetDisplay().SetSelected([])
581 self.UpdateMap(render =
False)
583 elif action
in (
"copyCats",
585 if not hasattr(self,
"copyCatsIds"):
587 nselected = self.digit.GetDisplay().SelectLineByPoint(pos1)[
'point']
589 self.
copyCatsList = self.digit.GetDisplay().GetSelected()
592 self.digit.GetDisplay().SetSelected([])
594 nselected = self.digit.GetDisplay().SelectLinesByBox((pos1, pos2))
596 if self.digit.GetDisplay().SelectLineByPoint(pos1)
is not None:
600 self.
copyCatsIds = self.digit.GetDisplay().GetSelected()
602 elif action ==
"queryLine":
603 selected = self.digit.SelectLinesByQuery(bbox = (pos1, pos2))
604 nselected = len(selected)
606 self.digit.GetDisplay().SetSelected(selected)
610 if action ==
'moveLine' and \
611 len(self.digit.GetDisplay().GetSelected()) > 0:
614 if action ==
'moveLine':
619 nselected = self.digit.GetDisplay().SelectLinesByBox(bbox = (pos1, pos2),
622 if self.digit.GetDisplay().SelectLineByPoint(pos1)
is not None:
626 if action
in (
"moveLine",
"moveVertex")
and \
627 hasattr(self,
"moveInfo"):
629 if action ==
"moveLine":
631 self.
moveInfo[
'id'] = self.digit.GetDisplay().GetSelected(grassId =
False)
633 self.
moveInfo[
'id'] = self.digit.GetDisplay().GetSelectedVertex(pos1)
635 self.digit.GetDisplay().SetSelected([])
640 if UserSettings.Get(group =
'vdigit', key =
'checkForDupl', subkey =
'enabled'):
641 dupl = self.digit.GetDisplay().GetDuplicates()
642 self.UpdateMap(render =
False)
645 posWindow = self.ClientToScreen((self.mouse[
'end'][0] + self.dialogOffset,
646 self.mouse[
'end'][1] + self.dialogOffset))
648 dlg = VDigitDuplicatesDialog(parent = self, data = dupl, pos = posWindow)
650 if dlg.ShowModal() == wx.ID_OK:
651 self.digit.GetDisplay().UnSelect(dlg.GetUnSelected())
653 self.UpdateMap(render =
False)
655 if action !=
"editLine":
657 self.UpdateMap(render =
False)
660 if not (action
in (
"moveLine",
662 hasattr(self,
"moveInfo")
and \
665 self.UpdateMap(render =
False, renderVector =
False)
668 """!Left mouse button released - vector digitizer split line,
669 add/remove vertex action
671 pos1 = self.Pixel2Cell(self.mouse[
'begin'])
673 pointOnLine = self.digit.GetDisplay().SelectLineByPoint(pos1)[
'point']
677 if self.toolbar.GetAction()
in [
"splitLine",
"addVertex"]:
678 self.UpdateMap(render =
False)
679 self.DrawCross(pdc = self.pdcTmp, coords = self.Cell2Pixel((pointOnLine[0], pointOnLine[1])),
684 id = self.digit.GetDisplay().GetSelectedVertex(pos1)[0]
689 x, y = self.pdcVector.GetIdBounds(id)[0:2]
690 self.pdcVector.RemoveId(id)
691 self.UpdateMap(render =
False)
692 self.DrawCross(pdc = self.pdcTmp, coords = (x, y),
696 self.digit.GetDisplay().SetSelected([])
697 self.UpdateMap(render =
False)
700 """!Left mouse button released - vector digitizer copy feature
703 pos1 = self.Pixel2Cell(self.mouse[
'begin'])
704 pos2 = self.Pixel2Cell(self.mouse[
'end'])
706 if UserSettings.Get(group =
'vdigit', key =
'bgmap',
707 subkey =
'value', internal =
True) ==
'':
709 nselected = self.bdigit.GetDisplay().SelectLinesByBox((pos1, pos2))
713 self.UpdateMap(render =
False)
715 self.UpdateMap(render =
False, renderVector =
False)
718 self.
copyIds = self.digit.SelectLinesFromBackgroundMap(bbox = (pos1, pos2))
720 color = UserSettings.Get(group =
'vdigit', key =
'symbol',
721 subkey = [
'highlight',
'color'])
722 colorStr = str(color[0]) +
":" + str(color[1]) +
":" + str(color[2])
723 dVectTmp = [
'd.vect',
724 'map=%s' % UserSettings.Get(group =
'vdigit', key =
'bgmap',
725 subkey =
'value', internal =
True),
728 'color=%s' % colorStr,
729 'fcolor=%s' % colorStr,
730 'type=point,line,boundary,centroid',
734 self.
layerTmp = self.Map.AddLayer(type =
'vector',
738 self.layerTmp.SetCmd(dVectTmp)
744 self.UpdateMap(render =
True, renderVector =
True)
747 """!Left mouse button released - vector digitizer z-bulk line
753 nselected = self.digit.GetDisplay().SelectLinesByBox((pos1, pos2))
757 self.UpdateMap(render =
False)
758 self.DrawLines(pdc = self.pdcTmp)
760 self.UpdateMap(render =
False, renderVector =
False)
763 """!Left mouse button released - vector digitizer connect line
766 if len(self.digit.GetDisplay().GetSelected()) > 0:
767 self.UpdateMap(render =
False)
769 def _onLeftUp(self, event):
770 """!Left mouse button released"""
771 if hasattr(self,
"moveInfo"):
772 if len(self.digit.GetDisplay().GetSelected()) == 0:
773 self.
moveInfo[
'begin'] = self.Pixel2Cell(self.mouse[
'begin'])
776 self.mouse[
'begin'] = self.mouse[
'end']
778 action = self.toolbar.GetAction()
779 if action
in (
"deleteLine",
794 elif action
in (
"splitLine",
799 elif action ==
"copyLine":
802 elif action ==
"zbulkLine" and \
806 elif action ==
"connectLine":
809 if len(self.digit.GetDisplay().GetSelected()) > 0:
812 def _onRightDown(self, event):
814 action = self.toolbar.GetAction()
815 if action
in (
"moveLine",
"moveVertex")
and \
816 hasattr(self,
"moveInfo"):
818 pTo = self.Pixel2Cell(event.GetPositionTuple())
820 move = (pTo[0] - pFrom[0],
823 if action ==
"moveLine":
825 if self.digit.MoveSelectedLines(move) < 0:
827 elif action ==
"moveVertex":
829 fid = self.digit.MoveSelectedVertex(pFrom, move)
837 def _onRightUp(self, event):
838 """!Right mouse button released (confirm action)
840 action = self.toolbar.GetAction()
841 if action ==
"addLine" and \
842 self.toolbar.GetAction(
'type')
in [
"line",
"boundary",
"area"]:
845 mapName = self.toolbar.GetLayer().GetName()
849 message = _(
"No vector map selected for editing."))
852 if self.toolbar.GetAction(
'type') ==
'line':
860 nfeat, fids = self.digit.AddFeature(self.toolbar.GetAction(
'type'), self.
polycoords)
864 position = self.Cell2Pixel(self.
polycoords[-1])
866 self.UpdateMap(render =
False)
871 if UserSettings.Get(group =
'vdigit', key =
"addRecord", subkey =
'enabled')
and \
873 (
not line
and nfeat > 0)):
874 posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
875 position[1] + self.dialogOffset))
879 UserSettings.Get(group =
'vdigit', key =
"layer", subkey =
'value') :
880 (UserSettings.Get(group =
'vdigit', key =
"category", subkey =
'value'), )
892 self.
_geomAttrb(fid, addRecordDlg,
'perimeter')
895 if addRecordDlg.mapDBInfo
and \
896 addRecordDlg.ShowModal() == wx.ID_OK:
897 sqlfile = tempfile.NamedTemporaryFile(mode =
"w")
898 for sql
in addRecordDlg.GetSQLString():
899 sqlfile.file.write(sql +
";\n")
901 gcmd.RunCommand(
'db.execute',
904 input = sqlfile.name)
906 if addRecordDlg.mapDBInfo:
909 elif action ==
"deleteLine":
911 if self.digit.DeleteSelectedLines() < 0:
914 elif action ==
"splitLine":
916 if self.digit.SplitLine(self.Pixel2Cell(self.mouse[
'begin'])) < 0:
918 elif action ==
"addVertex":
920 fid = self.digit.AddVertex(self.Pixel2Cell(self.mouse[
'begin']))
923 elif action ==
"removeVertex":
925 fid = self.digit.RemoveVertex(self.Pixel2Cell(self.mouse[
'begin']))
929 elif action
in (
"copyCats",
"copyAttrs"):
930 if action ==
'copyCats':
944 elif action ==
"editLine" and \
945 hasattr(self,
"moveInfo"):
946 line = self.digit.GetDisplay().GetSelected()[0]
947 if self.digit.EditLine(line, self.
polycoords) < 0:
952 elif action ==
"flipLine":
953 if self.digit.FlipLine() < 0:
955 elif action ==
"mergeLine":
956 if self.digit.MergeLine() < 0:
958 elif action ==
"breakLine":
959 if self.digit.BreakLine() < 0:
961 elif action ==
"snapLine":
962 if self.digit.SnapLine() < 0:
964 elif action ==
"connectLine":
965 if len(self.digit.GetDisplay().GetSelected()) > 1:
966 if self.digit.ConnectLine() < 0:
968 elif action ==
"copyLine":
969 if self.digit.CopyLine(self.
copyIds) < 0:
974 self.UpdateMap(render =
True, renderVector =
False)
977 elif action ==
"zbulkLine" and len(self.
polycoords) == 2:
981 selected = self.digit.GetDisplay().GetSelected()
982 dlg = VDigitZBulkDialog(parent = self, title = _(
"Z bulk-labeling dialog"),
983 nselected = len(selected))
984 if dlg.ShowModal() == wx.ID_OK:
985 if self.digit.ZBulkLines(pos1, pos2, dlg.value.GetValue(),
986 dlg.step.GetValue()) < 0:
988 self.UpdateMap(render =
False)
989 elif action ==
"typeConv":
993 if self.digit.TypeConvForSelectedLines() < 0:
996 if action !=
"addLine":
998 self.digit.GetDisplay().SetSelected([])
1000 self.UpdateMap(render =
False)
1002 def _onMouseMoving(self, event):
1003 self.mouse[
'end'] = event.GetPositionTuple()[:]
1005 Debug.msg (5,
"BufferedWindow.OnMouseMoving(): coords=%f,%f" % \
1006 (self.mouse[
'end'][0], self.mouse[
'end'][1]))
1008 action = self.toolbar.GetAction()
1009 if action ==
"addLine" and \
1010 self.toolbar.GetAction(
'type')
in [
"line",
"boundary",
"area"]:
1012 self.MouseDraw(pdc = self.pdcTmp, begin = self.Cell2Pixel(self.
polycoords[-1]))
1014 elif action
in [
"moveLine",
"moveVertex",
"editLine"] \
1015 and hasattr(self,
"moveInfo"):
1016 dx = self.mouse[
'end'][0] - self.mouse[
'begin'][0]
1017 dy = self.mouse[
'end'][1] - self.mouse[
'begin'][1]
1020 if action ==
"moveLine" and \
1024 self.pdcTmp.TranslateId(id, dx, dy)
1025 elif action
in [
"moveVertex",
"editLine"]:
1031 if action ==
"moveVertex" and \
1034 self.pdcTmp.RemoveId(self.
moveInfo[
'id'][0])
1036 x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.
moveInfo[
'id'][1])[0:2])
1037 self.pdcTmp.RemoveId(self.
moveInfo[
'id'][1] + 1)
1038 self.polycoords.append((x, y))
1039 self.polycoords.append(self.Pixel2Cell(self.mouse[
'end']))
1042 x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.
moveInfo[
'id'][2])[0:2])
1043 self.pdcTmp.RemoveId(self.
moveInfo[
'id'][2]-1)
1044 self.polycoords.append((x, y))
1046 self.ClearLines(pdc = self.pdcTmp)
1047 self.DrawLines(pdc = self.pdcTmp)
1049 if action ==
"editLine":
1050 self.MouseDraw(pdc = self.pdcTmp,
1051 begin = self.Cell2Pixel(self.
polycoords[-1]))
1054 self.mouse[
'begin'] = self.mouse[
'end']
1056 elif action ==
"zbulkLine":
1059 self.MouseDraw(self.pdcTmp)
1061 def _zoom(self, event):
1062 tmp1 = self.mouse[
'end']
1063 tmp2 = self.Cell2Pixel(self.
moveInfo[
'begin'])
1064 dx = tmp1[0] - tmp2[0]
1065 dy = tmp1[1] - tmp2[1]
1066 self.
moveInfo[
'beginDiff'] = (dx, dy)
1068 self.pdcTmp.RemoveId(id)