def OnLeftDownAddLine(self, event): """Left mouse button pressed - add new feature""" try: mapLayer = self.toolbar.GetLayer().GetName() except: return if self.toolbar.GetAction("type") in ["point", "centroid"]: # add new point / centroiud east, north = self.Pixel2Cell(self.mouse["begin"]) nfeat, fids = self.digit.AddFeature( self.toolbar.GetAction("type"), [(east, north)] ) if nfeat < 1: return self.UpdateMap(render=False) # redraw map # add new record into attribute table if UserSettings.Get(group="vdigit", key="addRecord", subkey="enabled"): # select attributes based on layer and category cats = { fids[0]: { UserSettings.Get(group="vdigit", key="layer", subkey="value"): ( UserSettings.Get( group="vdigit", key="category", subkey="value" ), ) } } posWindow = self.ClientToScreen( ( self.mouse["end"][0] + self.dialogOffset, self.mouse["end"][1] + self.dialogOffset, ) ) addRecordDlg = DisplayAttributesDialog( parent=self, map=mapLayer, cats=cats, pos=posWindow, action="add", ignoreError=True, ) if self.toolbar.GetAction("type") == "centroid": for fid in fids: self._geomAttrb(fid, addRecordDlg, "area") self._geomAttrb(fid, addRecordDlg, "perimeter") if addRecordDlg.IsFound(): addRecordDlg.ShowModal() addRecordDlg.Destroy() elif self.toolbar.GetAction("type") in ["line", "boundary", "area"]: # add new point to the line self.polycoords.append(self.Pixel2Cell(event.GetPosition())) self.DrawLines(pdc=self.pdcTmp)
def _onRightUp(self, event): """Right mouse button released (confirm action)""" action = self.toolbar.GetAction() if action == "addLine" and self.toolbar.GetAction("type") in [ "line", "boundary", "area", ]: # -> add new line / boundary try: mapName = self.toolbar.GetLayer().GetName() except: mapName = None GError(parent=self, message=_("No vector map selected for editing.")) if mapName: if self.toolbar.GetAction("type") == "line": line = True else: line = False if len(self.polycoords) < 2: # ignore 'one-point' lines return nfeat, fids = self.digit.AddFeature( self.toolbar.GetAction("type"), self.polycoords ) if nfeat < 0: return position = self.Cell2Pixel(self.polycoords[-1]) self.polycoords = [] self.UpdateMap(render=False) self.redrawAll = True self.Refresh() # add new record into attribute table if self._addRecord() and (line is True or (not line and nfeat > 0)): posWindow = self.ClientToScreen( ( position[0] + self.dialogOffset, position[1] + self.dialogOffset, ) ) # select attributes based on layer and category cats = { fids[0]: { UserSettings.Get( group="vdigit", key="layer", subkey="value" ): ( UserSettings.Get( group="vdigit", key="category", subkey="value" ), ) } } addRecordDlg = DisplayAttributesDialog( parent=self, map=mapName, cats=cats, pos=posWindow, action="add", ignoreError=True, ) for fid in fids: self._geomAttrb(fid, addRecordDlg, "length") # auto-placing centroid self._geomAttrb(fid, addRecordDlg, "area") self._geomAttrb(fid, addRecordDlg, "perimeter") if addRecordDlg.IsFound(): addRecordDlg.ShowModal() addRecordDlg.Destroy() elif action == "deleteLine": # -> delete selected vector features if self.digit.DeleteSelectedLines() < 0: return self._updateATM() elif action == "deleteArea": # -> delete selected vector areas if self.digit.DeleteSelectedAreas() < 0: return self._updateATM() elif action == "splitLine": # split line if self.digit.SplitLine(self.Pixel2Cell(self.mouse["begin"])) < 0: return elif action == "addVertex": # add vertex fid = self.digit.AddVertex(self.Pixel2Cell(self.mouse["begin"])) if fid < 0: return elif action == "removeVertex": # remove vertex fid = self.digit.RemoveVertex(self.Pixel2Cell(self.mouse["begin"])) if fid < 0: return self._geomAttrbUpdate( [ fid, ] ) elif action in ("copyCats", "copyAttrs") and hasattr(self, "copyCatsIds"): if action == "copyCats": if ( self.digit.CopyCats( self.copyCatsList, self.copyCatsIds, copyAttrb=False ) < 0 ): return else: if ( self.digit.CopyCats( self.copyCatsList, self.copyCatsIds, copyAttrb=True ) < 0 ): return del self.copyCatsList del self.copyCatsIds self._updateATM() elif action == "editLine" and hasattr(self, "moveInfo"): line = self.digit.GetDisplay().GetSelected()[0] if self.digit.EditLine(line, self.polycoords) < 0: return del self.moveInfo elif action == "flipLine": if self.digit.FlipLine() < 0: return elif action == "mergeLine": if self.digit.MergeLine() < 0: return elif action == "breakLine": if self.digit.BreakLine() < 0: return elif action == "snapLine": if self.digit.SnapLine() < 0: return elif action == "connectLine": if len(self.digit.GetDisplay().GetSelected()) > 1: if self.digit.ConnectLine() < 0: return elif action == "copyLine": if self.digit.CopyLine(self.copyIds) < 0: return del self.copyIds if self.layerTmp: self.Map.DeleteLayer(self.layerTmp) self.UpdateMap(render=True, renderVector=False) del self.layerTmp elif action == "zbulkLine" and len(self.polycoords) == 2: pos1 = self.polycoords[0] pos2 = self.polycoords[1] selected = self.digit.GetDisplay().GetSelected() dlg = VDigitZBulkDialog( parent=self, title=_("Z bulk-labeling dialog"), nselected=len(selected) ) if dlg.ShowModal() == wx.ID_OK: if ( self.digit.ZBulkLines( pos1, pos2, dlg.value.GetValue(), dlg.step.GetValue() ) < 0 ): return self.UpdateMap(render=False) elif action == "typeConv": # -> feature type conversion # - point <-> centroid # - line <-> boundary if self.digit.TypeConvForSelectedLines() < 0: return if action != "addLine": # unselect and re-render self.digit.GetDisplay().SetSelected([]) self.polycoords = [] self.UpdateMap(render=False)
def OnLeftDownAddLine(self, event): """Left mouse button pressed - add new feature """ try: mapLayer = self.toolbar.GetLayer().GetName() except: return if self.toolbar.GetAction('type') in ['point', 'centroid']: # add new point / centroiud east, north = self.Pixel2Cell(self.mouse['begin']) nfeat, fids = self.digit.AddFeature(self.toolbar.GetAction('type'), [(east, north)]) if nfeat < 1: return self.UpdateMap(render=False) # redraw map # add new record into atribute table if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled'): # select attributes based on layer and category cats = { fids[0]: { UserSettings.Get(group='vdigit', key="layer", subkey='value'): (UserSettings.Get(group='vdigit', key="category", subkey='value'), ) } } posWindow = self.ClientToScreen( (self.mouse['end'][0] + self.dialogOffset, self.mouse['end'][1] + self.dialogOffset)) addRecordDlg = DisplayAttributesDialog(parent=self, map=mapLayer, cats=cats, pos=posWindow, action="add", ignoreError=True) if self.toolbar.GetAction('type') == 'centroid': for fid in fids: self._geomAttrb(fid, addRecordDlg, 'area') self._geomAttrb(fid, addRecordDlg, 'perimeter') if addRecordDlg.IsFound() and \ addRecordDlg.ShowModal() == wx.ID_OK: sqlfile = tempfile.NamedTemporaryFile(mode="w") for sql in addRecordDlg.GetSQLString(): sqlfile.file.write(sql + ";\n") sqlfile.file.flush() RunCommand('db.execute', parent=self, quiet=True, input=sqlfile.name) if addRecordDlg.mapDBInfo: self._updateATM() elif self.toolbar.GetAction('type') in ["line", "boundary", "area"]: # add new point to the line self.polycoords.append(self.Pixel2Cell( event.GetPositionTuple()[:])) self.DrawLines(pdc=self.pdcTmp)