def __init__(self, parent, coords, addInstance, layerManager, controller): QDialog.__init__( self, parent ) self.setupUi(self) self._iface = iface self.coords = coords self.feature = addInstance self._layerManager = layerManager self._controller = controller # limit user inputs UiUtility.formMask(self) # set combo box defaults UiUtility.setFormCombos(self) # Make connections self.uFullNum.textEdited.connect(self.fullNumChanged) self.uPrefix.textEdited.connect(self.partNumChanged) self.uUnit.textEdited.connect(self.partNumChanged) self.uBase.textEdited.connect(self.partNumChanged) self.uHigh.textEdited.connect(self.partNumChanged) self.uAlpha.textEdited.connect(self.partNumChanged) self.uSubmitAddressButton.clicked.connect(self.submitAddress) self.uAbort.clicked.connect(self.closeDlg) self.rejected.connect(self.closeDlg) self.uGetRclToolButton.clicked.connect(self.getRcl) self.show()
def canvasReleaseEvent(self, mouseEvent): self._feature = None self._iface.setActiveLayer(self._layers.addressLayer()) results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if len(results) == 0: return elif len(results) == 1: # initialise an address object and populate from selected feature self._feature = UiUtility.mapResultsToAddObj(results[0], self._controller) else: # Stacked points identifiedFeatures=[] for i in range (0,len(results)): identifiedFeatures.append(dict( fullAddress=results[i].mFeature.attribute('fullAddress'), addressId= results[i].mFeature.attribute('addressId'))) dlg = updateAddressDialog(self._iface.mainWindow()) updFeatures = dlg.selectFeatures(identifiedFeatures) if updFeatures: updFeatureIds = [d['addressId'] for d in updFeatures] for result in results: if result.mFeature.attribute('addressId') in updFeatureIds: self._feature = UiUtility.mapResultsToAddObj(result, self._controller) break # Open form if self._feature: # highlight feature self.setMarker(results[0].mFeature.geometry().asPoint()) UpdateAddressDialog.updateAddress(self._feature, self._layers, self._controller, self._iface.mainWindow()) self._canvas.scene().removeItem(self._marker)
def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._feature = None self._iface.setActiveLayer(self._layers.addressLayer()) results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if len(results) == 0: return elif len(results) == 1: # initialise an address object and populate from selected feature self._feature = self._controller.uidm.singleFeatureObj( results[0].mFeature.attribute('addressId')) else: # Stacked points identifiedFeatures = [] for i in range(0, len(results)): identifiedFeatures.append( dict(fullAddress=results[i].mFeature.attribute( 'fullAddress'), addressId=results[i].mFeature.attribute('addressId'))) dlg = updateAddressDialog(self._iface.mainWindow()) updFeatures = dlg.selectFeatures(identifiedFeatures) if updFeatures: updFeatureIds = [d['addressId'] for d in updFeatures] for result in results: if result.mFeature.attribute('addressId') in updFeatureIds: self._feature = self._controller.uidm.singleFeatureObj( result.mFeature.attribute('addressId')) break # Open form if self._feature: # Hack to retrieve the properties missing on the # feature feed from the resolution feed respId = int(time.time()) self._controller.uidm.supplementAddress(self._feature, respId) self.feature = self._controller.RespHandler.handleResp( respId, FEEDS['AR'], 'supplement') # highlight feature self.setMarker(results[0].mFeature.geometry().asPoint()) self._controller._queues.uEditFeatureTab.setFeature( 'update', self._feature) self._controller._queues.tabWidget.setCurrentIndex(0) UiUtility.setEditability(self._controller._queues.uEditFeatureTab, 'update')
def submitAddress(self): ''' take users input from form and submit to AIMS API ''' # Run through the setters self.feature.set_x(self.coords.x()) self.feature.set_y(self.coords.y()) UiUtility.formToaddObj(self) # load address to AIMS Via API payload = self.feature.aimsObject() # Capture the returned response (response distilled down to list of errors) valErrors = self._controller.newAddress(payload) if len(valErrors) == 0: self.closeDlg() else: QMessageBox.warning(iface.mainWindow(),"Create Address Point", valErrors)
def NewAimsFeature( self, coords ): """ Get New Address Instance. Make Address Editing Form visible to user @param coords: QgsPoint @type coords: QgsPoint """ # init new address object and open form UiUtility.clearForm(self._controller._queues.tabWidget) coords = UiUtility.transform(self._iface, coords) self.setMarker(coords) addInstance = self.af.get() self._controller._queues.uEditFeatureTab.setFeature('add', addInstance, coords) self._controller._queues.tabWidget.setCurrentIndex(0) UiUtility.setEditability(self._controller._queues.uEditFeatureTab)
def fillform(self): """ Populate the Feature Editing form with Road Centreline information """ if self.rcl: self._parent.uRclId.setText(self.rcl) if self._parent.uAddressType.currentText() == 'Road': self._parent.uRoadPrefix.setText(UiUtility.nullEqualsNone(self.prefix)) self._parent.uRoadName.setText(UiUtility.nullEqualsNone(self.name)) self._parent.uRoadTypeName.setText(UiUtility.nullEqualsNone(self.type)) self._parent.uRoadSuffix.setText(UiUtility.nullEqualsNone(self.suffix)) else: self._parent.uWaterRouteName.setText(UiUtility.nullEqualsNone(self.waterName)) if self._parent.__class__.__name__ != 'QueueEditorWidget': self.highlight.setRcl(self.rclLine)
def canvasReleaseEvent(self, mouseEvent): """ Identify the Road Centreline the user clicked on @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self.rclLayer = self._layers.rclLayer() results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if len(results) == 0: return if len(results) == 1: coords = results[0].mFeature.geometry() self.rclLine = coords.asMultiPolyline () mapping = {'rcl' :'road_section_id', 'prefix' :'road_name_prefix_value', 'name' :'road_name_body', 'type' :'road_name_type_value', 'suffix' :'road_name_suffix_value', 'waterName' :'road_name_body',} for k, v in mapping.items(): setattr(self, k, unicode(UiUtility.nullEqualsNone(results[0].mFeature.attribute(v)))) self.fillform() self._controller.setPreviousMapTool()
def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._feature = None self._iface.setActiveLayer(self._layers.addressLayer()) results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if len(results) == 0: return elif len(results) == 1: # initialise an address object and populate from selected feature self._feature = self._controller.uidm.singleFeatureObj(results[0].mFeature.attribute('addressId')) else: # Stacked points identifiedFeatures=[] for i in range (0,len(results)): identifiedFeatures.append(dict( fullAddress=results[i].mFeature.attribute('fullAddress'), addressId= results[i].mFeature.attribute('addressId'))) dlg = updateAddressDialog(self._iface.mainWindow()) updFeatures = dlg.selectFeatures(identifiedFeatures) if updFeatures: updFeatureIds = [d['addressId'] for d in updFeatures] for result in results: if result.mFeature.attribute('addressId') in updFeatureIds: self._feature = self._controller.uidm.singleFeatureObj(result.mFeature.attribute('addressId')) break # Open form if self._feature: # Hack to retrieve the properties missing on the # feature feed from the resolution feed respId = int(time.time()) self._controller.uidm.supplementAddress(self._feature, respId) self.feature = self._controller.RespHandler.handleResp(respId, FEEDS['AR'], 'supplement') # highlight feature self.setMarker(results[0].mFeature.geometry().asPoint()) self._controller._queues.uEditFeatureTab.setFeature('update', self._feature ) self._controller._queues.tabWidget.setCurrentIndex(0) UiUtility.setEditability(self._controller._queues.uEditFeatureTab, 'update')
def NewAimsFeature(self, coords): """ Get New Address Instance. Make Address Editing Form visible to user @param coords: QgsPoint @type coords: QgsPoint """ # init new address object and open form UiUtility.clearForm(self._controller._queues.tabWidget) coords = UiUtility.transform(self._iface, coords) self.setMarker(coords) addInstance = self.af.get() self._controller._queues.uEditFeatureTab.setFeature( 'add', addInstance, coords) self._controller._queues.tabWidget.setCurrentIndex(0) UiUtility.setEditability(self._controller._queues.uEditFeatureTab)
def setPoint( self, coords ): ''' guarantee srs and pass to the API ''' self._enabled = False self.setMarker(coords) coords = UiUtility.transform(self._iface, coords) # init new address object and open form addInstance = self._controller.initialiseAddressObj() NewAddressDialog.newAddress(addInstance, self._layers, self._controller, self._iface.mainWindow(), coords) self._canvas.scene().removeItem(self._marker) self._enabled = True
def fillform(self): """ Populate the Feature Editing form with Road Centreline information """ if self.rcl: self._parent.uRclId.setText(self.rcl) if self._parent.uAddressType.currentText() == 'Road': self._parent.uRoadPrefix.setText( UiUtility.nullEqualsNone(self.prefix)) self._parent.uRoadName.setText( UiUtility.nullEqualsNone(self.name)) self._parent.uRoadTypeName.setText( UiUtility.nullEqualsNone(self.type)) self._parent.uRoadSuffix.setText( UiUtility.nullEqualsNone(self.suffix)) else: self._parent.uWaterRouteName.setText( UiUtility.nullEqualsNone(self.waterName)) if self._parent.__class__.__name__ != 'QueueEditorWidget': self.highlight.setRcl(self.rclLine)
def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._currentRevItem: if self._currentRevItem._changeType in ('Retire', 'AddLineage'): self._iface.messageBar().pushMessage( "{} review items cannot be relocated".format( self._currentRevItem._changeType), level=QgsMessageBar.WARNING, duration=5) return if len(results) == 0: coords = self.toMapCoordinates( QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() coords = list(UiUtility.transform(self._iface, coords)) respId = int(time.time()) if self._currentRevItem._changeType in ('Add', 'Update'): feedType = FEEDS['AR'] self._currentRevItem._addressedObject_addressPositions[ 0].setCoordinates(coords) self._controller.uidm.repairAddress(self._currentRevItem, respId) else: feedType = FEEDS['GR'] changeId = self._currentRevItem._changeId self._currentRevItem = self._currentRevItem.meta.entities[0] self._currentRevItem._addressedObject_addressPositions[ 0].setCoordinates(coords) self._currentRevItem.setChangeId(changeId) self._controller.uidm.repairAddress(self._currentRevItem, respId) self.RespHandler.handleResp(respId, feedType) self._controller.setPreviousMapTool()
def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._currentRevItem: if self._currentRevItem._changeType in ('Retire', 'AddLineage' ): self._iface.messageBar().pushMessage("{} review items cannot be relocated".format(self._currentRevItem._changeType), level=QgsMessageBar.WARNING, duration = 5) return if len(results) == 0: coords = self.toMapCoordinates(QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() coords = list(UiUtility.transform(self._iface, coords)) respId = int(time.time()) if self._currentRevItem._changeType in ('Add', 'Update'): feedType = FEEDS['AR'] self._currentRevItem._addressedObject_addressPositions[0].setCoordinates(coords) self._controller.uidm.repairAddress(self._currentRevItem, respId) else: feedType = FEEDS['GR'] changeId = self._currentRevItem._changeId self._currentRevItem = self._currentRevItem.meta.entities[0] self._currentRevItem._addressedObject_addressPositions[0].setCoordinates(coords) self._currentRevItem.setChangeId(changeId) self._controller.uidm.repairAddress(self._currentRevItem, respId) self.RespHandler.handleResp(respId, feedType) self._controller.setPreviousMapTool()
def canvasReleaseEvent(self, mouseEvent): rclLayer = self._layers.rclLayer() results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if len(results) == 0: return if len(results) == 1: self._canvas.scene().removeItem(self._marker) addressClass = self.parent.uAddressType.currentText() coords = results[0].mFeature.geometry() if addressClass == 'Road': self.parent.uRoadCentrelineId.setText(UiUtility.nullEqualsNone(str(results[0].mFeature.attribute('roadcentrelineid')))) self.parent.uRoadPrefix.setText(UiUtility.nullEqualsNone(str(results[0].mFeature.attribute('roadprefixname')))) self.parent.uRoadName.setText(UiUtility.nullEqualsNone(str(results[0].mFeature.attribute('roadname'))))# self.parent.uRoadTypeName.setText(UiUtility.nullEqualsNone(str(results[0].mFeature.attribute('roadtypename')))) #self.parent.uRoadSuffix.setText(nullEqualsNone(str(results[0].mFeature.attribute('roadnamesuffix')))) <-- does not exist in old scheme waiting for new roads scheme else: self.parent.uWaterRouteName.setText(UiUtility.nullEqualsNone(str(results[0].mFeature.attribute('roadSuffix')))) self.parent.uWaterName.setText(UiUtility.nullEqualsNone(str(results[0].mFeature.attribute('roadSuffix')))) self._marker = UiUtility.rclHighlight(self._canvas, coords,rclLayer)
def canvasReleaseEvent(self, mouseEvent): """ Identify the Road Centreline the user clicked on @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self.rclLayer = self._layers.rclLayer() results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if len(results) == 0: return if len(results) == 1: coords = results[0].mFeature.geometry() self.rclLine = coords.asMultiPolyline() mapping = { 'rcl': 'road_section_id', 'prefix': 'road_name_prefix_value', 'name': 'road_name_body', 'type': 'road_name_type_value', 'suffix': 'road_name_suffix_value', 'waterName': 'road_name_body', } for k, v in mapping.items(): setattr( self, k, unicode( UiUtility.nullEqualsNone( results[0].mFeature.attribute(v)))) self.fillform() self._controller.setPreviousMapTool()
def setMarker(self, coords): self._marker = UiUtility.highlight(self._iface, coords, QgsVertexMarker.ICON_X)
def canvasReleaseEvent(self, mouseEvent): self._iface.setActiveLayer(self._layers.addressLayer()) if mouseEvent.button() == Qt.LeftButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) # Ensure feature list and highlighting is reset self._features = [] self._canvas.scene().removeItem(self._marker) if len(results) == 0: return elif len(results) == 1: # Highlight feature coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) # create address object for feature. It is this obj properties that will be passed to API self._features.append(UiUtility.mapResultsToAddObj(results[0], self._controller)) self._sb.showMessage("Right click for features new location") else: # Stacked points identifiedFeatures=[] coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) for i in range (0,len(results)): identifiedFeatures.append(dict( fullAddress=results[i].mFeature.attribute('fullAddress'), addressId= results[i].mFeature.attribute('addressId') )) dlg = MoveAddressDialog(self._iface.mainWindow()) moveFeatures = dlg.selectFeatures(identifiedFeatures) if moveFeatures: # Form a list of Ids as selected by the user moveFeaturesIds = [d['addressId'] for d in moveFeatures] for result in results: if result.mFeature.attribute('addressId') in moveFeaturesIds: self._features.append(UiUtility.mapResultsToAddObj(result, self._controller)) self._sb.showMessage("Right click for features new location") else: self._features = None self._canvas.scene().removeItem(self._marker) # Right click for new position if mouseEvent.button() == Qt.RightButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._features: if len(results) == 0: coords = self.toMapCoordinates(QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() # set new coords for all selected features coords = UiUtility.transform(self._iface, coords) for feature in self._features: feature.set_x(coords[0]) feature.set_y(coords[1]) payload = feature.aimsObject() valErrors = self._controller.updateFeature(payload) if len(valErrors) == 0: pass #no errors else: QMessageBox.warning(self._iface.mainWindow(),"Move Feature", valErrors +'\n'*2 + feature._fullAddress ) self._features = [] self._canvas.scene().removeItem(self._marker) self._sb.clearMessage() else: QMessageBox.warning(self._iface.mainWindow(),"Move Feature", "You must first select a feature to move")
def setMarker(self, coords): self._marker = UiUtility.highlight(self._iface, coords)
def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) if mouseEvent.button() == Qt.LeftButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) # Ensure feature list and highlighting is reset self._features = [] self.hideMarker() if len(results) == 0: return elif len(results) == 1: # Highlight feature coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) # create address object for feature. It is this obj properties that will be passed to API self._features.append( self._controller.uidm.singleFeatureObj(results[0].mFeature.attribute("addressId")) ) self._sb.showMessage("Right click for features new location") else: # Stacked points identifiedFeatures = [] coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) for i in range(0, len(results)): identifiedFeatures.append( dict( fullAddress=results[i].mFeature.attribute("fullAddress"), addressId=results[i].mFeature.attribute("addressId"), ) ) dlg = MoveAddressDialog(self._iface.mainWindow()) moveFeatures = dlg.selectFeatures(identifiedFeatures) if moveFeatures: # Form a list of Ids as selected by the user moveFeaturesIds = [d["addressId"] for d in moveFeatures] for featureId in moveFeaturesIds: self._features.append(self._controller.uidm.singleFeatureObj(featureId)) self._sb.showMessage("Right click for features new location") else: self._features = None # Right click for new position if mouseEvent.button() == Qt.RightButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._features: if len(results) == 0: coords = self.toMapCoordinates(QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() # set new coords for all selected features coords = list(UiUtility.transform(self._iface, coords)) for feature in self._features: # Hack to retrieve the properties missing on the # feature feed from the resolution feed < respId = int(time.time()) self._controller.uidm.supplementAddress(feature, respId) feature = self._controller.RespHandler.handleResp(respId, FEEDS["AR"], "supplement") # /> feature._addressedObject_addressPositions[0].setCoordinates(coords) if feature._codes_isMeshblockOverride != True: feature.setMeshblock(None) feature = self.af[FeedType.CHANGEFEED].cast(feature) respId = int(time.time()) self._controller.uidm.updateAddress(feature, respId) self.RespHandler.handleResp(respId, FEEDS["AC"]) self._features = [] self.hideMarker() self._sb.clearMessage()
def fullNumChanged(self, newnumber): UiUtility.fullNumChanged(self, newnumber)
def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) if mouseEvent.button() == Qt.LeftButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) # Ensure feature list and highlighting is reset self._features = [] self.hideMarker() if len(results) == 0: return elif len(results) == 1: # Highlight feature coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) # create address object for feature. It is this obj properties that will be passed to API self._features.append( self._controller.uidm.singleFeatureObj( results[0].mFeature.attribute('addressId'))) self._sb.showMessage("Right click for features new location") else: # Stacked points identifiedFeatures = [] coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) for i in range(0, len(results)): identifiedFeatures.append( dict(fullAddress=results[i].mFeature.attribute( 'fullAddress'), addressId=results[i].mFeature.attribute( 'addressId'))) dlg = MoveAddressDialog(self._iface.mainWindow()) moveFeatures = dlg.selectFeatures(identifiedFeatures) if moveFeatures: # Form a list of Ids as selected by the user moveFeaturesIds = [d['addressId'] for d in moveFeatures] for featureId in moveFeaturesIds: self._features.append( self._controller.uidm.singleFeatureObj(featureId)) self._sb.showMessage( "Right click for features new location") else: self._features = None # Right click for new position if mouseEvent.button() == Qt.RightButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._features: if len(results) == 0: coords = self.toMapCoordinates( QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() # set new coords for all selected features coords = list(UiUtility.transform(self._iface, coords)) for feature in self._features: # Hack to retrieve the properties missing on the # feature feed from the resolution feed < respId = int(time.time()) self._controller.uidm.supplementAddress(feature, respId) feature = self._controller.RespHandler.handleResp( respId, FEEDS['AR'], 'supplement') # /> #feature.type = FEEDS['AF'] # below clone is part of a fix still to be tested clone = feature.clone(feature, self.aff.get()) clone._addressedObject_addressPositions[0].setCoordinates( coords, ) if clone._codes_isMeshblockOverride != True: clone.setMeshblock(None) respId = int(time.time()) clone = self.afc[FeedType.CHANGEFEED].cast(clone) self._controller.uidm.updateAddress(clone, respId) self.RespHandler.handleResp(respId, FEEDS['AC']) self._features = [] self.hideMarker() self._sb.clearMessage()