def openItem(self, item): if not Settings.siteServerUrl(): self._plugin.showWarningMessage('ARK link not configured, please set the ARK URL in Settings.') elif not self.haveItem(item): self._plugin.showWarningMessage('Item not in ARK.') else: mod_cd = item.classCode() + '_cd' item_cd = item.siteCode() + '_' + item.itemId() url = Settings.siteServerUrl() + '/micro_view.php?item_key=' + mod_cd + '&' + mod_cd + '=' + item_cd try: webbrowser.get().open_new_tab(url) except Exception: QApplication.clipboard().setText(url) self._plugin.showWarningMessage('Unable to open browser, ARK link has been copied to the clipboard')
def _loadOnlineClassIndex(self, classCode): if not Settings.siteServerUrl(): return False if self._ark is None: self._createArkSession() if self._ark is None: return False response = self._ark.getItems(classCode + '_cd') if response.error: self._plugin.logMessage(response.url) self._plugin.logMessage(response.message) self._plugin.logMessage(response.raw) else: lst = response.data[classCode] items = set() for record in lst: item = Item(record['ste_cd'], classCode, record[classCode + '_no']) if item.isValid(): items.add(item) self.items[classCode] = sorted(items) self._plugin.logMessage('ARK Items ' + classCode + ' = ' + str(len(self.items[classCode]))) if (len(self.items[classCode]) > 0): self._indexLoaded = True return True return False
def _showItem(self, item): if not Settings.siteServerUrl(): return self._prevItem = item url = '' if item.isValid() and self.haveItem(item): url = self._ark.transcludeSubformUrl( item.classCode() + '_cd', item.itemValue(), item.classCode() + '_apisum') self._dock.setItemUrl(url)
def loadProject(self, plugin): if Settings.siteServerUrl(): self.loadArkTool.setEnabled(True) self._enableArkNav(False) self.siteCodeCombo.clear() for siteCode in sorted(set(Settings.siteCodes())): self.siteCodeCombo.addItem(siteCode, siteCode) idx = self.siteCodeCombo.findData(Settings.siteCode()) if idx >= 0: self.siteCodeCombo.setCurrentIndex(idx) self.resetContext()
def _getOnlineLinks(self, item, linkClassCode): if not Settings.siteServerUrl(): return [] xmi = unicode('conf_field_' + item.classCode() + linkClassCode + 'xmi') data = self.getItemFields(item, [xmi]) items = [] try: for link in data[xmi]: itemkey = link[u'xmi_itemkey'] itemvalue = link[u'xmi_itemvalue'].split(u'_') item = Item(itemvalue[0], itemkey[:3], itemvalue[1]) items.append(item) except Exception: return [] return items
def _enableArkData(self, enable=True): if Settings.siteServerUrl(): self._dock.enableArkData(enable)
def loadSite(self): self.setUrl(Settings.siteServerUrl()) self.setUser(Settings.siteServerUser()) self.setPassword(Settings.siteServerPassword())
def __init__(self, item, plugin, parent=None): super(IdentifyItemAction, self).__init__(parent) self._iface = plugin.iface self.item = item self.setText(item.itemLabel()) menu = QMenu() sourceSet = set() area = [] haveSchematic = False sectionSchematics = [] for feature in plugin.project().collection('plan').layer('polygons').getFeatures(item.featureRequest()): category = feature.attribute('category') if category == 'sch' or category == 'scs': haveSchematic = True source = Source() source.fromFeature(feature) if source.isValid(): sourceSet.add(source) if category == 'sch': area.append(feature.geometry().area()) sourceDict = {} for source in sourceSet: if source.sourceCode not in sourceDict: sourceDict[source.sourceCode] = set() sourceDict[source.sourceCode].add(source.items) self.zoomAction = QAction('Zoom to Item', parent) self.zoomAction.triggered.connect(self._zoomToItem) menu.addAction(self.zoomAction) self.panAction = QAction('Pan to Item', parent) self.panAction.triggered.connect(self._panToItem) menu.addAction(self.panAction) self.filterAction = QAction('Filter Item', parent) self.filterAction.triggered.connect(self._filterItem) menu.addAction(self.filterAction) self.excludeFilterAction = QAction('Exclude Item from Filter', parent) self.excludeFilterAction.triggered.connect(self._excludeFilterItem) menu.addAction(self.excludeFilterAction) self.highlightAction = QAction('Select Item', parent) self.highlightAction.triggered.connect(self._highlightItem) menu.addAction(self.highlightAction) self.addHighlightAction = QAction('Add Item to Selection', parent) self.addHighlightAction.triggereConfigd.connect(self._addHighlightItem) menu.addAction(self.addHighlightAction) if Settings.siteServerUrl(): self.linkAction = OpenArkAction(Settimgs.siteServerUrl(), item, 'Open in ARK', parent) menu.addAction(self.linkAction) self.drawingAction = QAction('Open Drawings', parent) self.drawingAction.triggered.connect(self._openDrawings) menu.addAction(self.drawingAction) menu.addSeparator() self.editAction = QAction('Edit Item', parent) self.editAction.triggered.connect(self._editItem) menu.addAction(self.editAction) self.deleteAction = QAction('Delete Item', parent) self.deleteAction.triggered.connect(self._deleteItem) menu.addAction(self.deleteAction) menu.addSeparator() if len(sourceDict) > 0: for sourceCode in sourceDict.keys(): menu.addAction(Config.sourceCodes[sourceCode]['label'] + ':') sources = sorted(sourceDict[sourceCode]) for item in sources: if item.isValid(): menu.addAction(item.itemLabel()) elif haveSchematic: menu.addAction('Unknown Source') else: menu.addAction('No Schematic') if item.classCode() == 'context': subItem = plugin.data().parentItem(item) if subItem and subItem.isValid(): menu.addSeparator() grpItem = plugin.data().parentItem(subItem) if Settings.siteServerUrl(): self.subAction = OpenArkAction( Settings.siteServerUrl(), subItem, 'Sub-group: ' + str(subItem.itemId()), parent) menu.addAction(self.subAction) if grpItem: self.grpAction = OpenArkAction( Settings.siteServerUrl(), grpItem, 'Group: ' + str(grpItem.itemId()), parent) menu.addAction(self.grpAction) else: menu.addAction('Sub-group: ' + str(subItem.itemId())) if grpItem: menu.addAction('Group: ' + str(grpItem.itemId())) if len(area) > 0: menu.addSeparator() tot = 0 for a in area: tot += a units = self._iface.mapCanvas().mapUnits() suffix = '' if units == QGis.Meters: suffix = u' m²' elif units == QGis.Feet: suffix = u' ft²' elif units == QGis.NauticalMiles: suffix = u' NM²' menu.addAction(ClipboardAction(u'Area: ', u'%.3f' % tot + suffix, parent)) self.setMenu(menu)
def _createArkSession(self): dialog = CredentialsDialog() if dialog.exec_(): self._ark = Ark(Settings.siteServerUrl(), dialog.siteServerUser(), dialog.siteServerPassword())
def __init__(self, item, plugin, parent=None): super(IdentifyItemAction, self).__init__(parent) self._iface = plugin.iface self.item = item self.setText(item.itemLabel()) menu = QMenu() sourceSet = set() area = [] haveSchematic = False sectionSchematics = [] for feature in plugin.project().collection('plan').layer( 'polygons').getFeatures(item.featureRequest()): category = feature.attribute('category') if category == 'sch' or category == 'scs': haveSchematic = True source = Source() source.fromFeature(feature) if source.isValid(): sourceSet.add(source) if category == 'sch': area.append(feature.geometry().area()) sourceDict = {} for source in sourceSet: if source.sourceCode not in sourceDict: sourceDict[source.sourceCode] = set() sourceDict[source.sourceCode].add(source.items) self.zoomAction = QAction('Zoom to Item', parent) self.zoomAction.triggered.connect(self._zoomToItem) menu.addAction(self.zoomAction) self.panAction = QAction('Pan to Item', parent) self.panAction.triggered.connect(self._panToItem) menu.addAction(self.panAction) self.filterAction = QAction('Filter Item', parent) self.filterAction.triggered.connect(self._filterItem) menu.addAction(self.filterAction) self.excludeFilterAction = QAction('Exclude Item from Filter', parent) self.excludeFilterAction.triggered.connect(self._excludeFilterItem) menu.addAction(self.excludeFilterAction) self.highlightAction = QAction('Select Item', parent) self.highlightAction.triggered.connect(self._highlightItem) menu.addAction(self.highlightAction) self.addHighlightAction = QAction('Add Item to Selection', parent) self.addHighlightAction.triggereConfigd.connect(self._addHighlightItem) menu.addAction(self.addHighlightAction) if Settings.siteServerUrl(): self.linkAction = OpenArkAction(Settimgs.siteServerUrl(), item, 'Open in ARK', parent) menu.addAction(self.linkAction) self.drawingAction = QAction('Open Drawings', parent) self.drawingAction.triggered.connect(self._openDrawings) menu.addAction(self.drawingAction) menu.addSeparator() self.editAction = QAction('Edit Item', parent) self.editAction.triggered.connect(self._editItem) menu.addAction(self.editAction) self.deleteAction = QAction('Delete Item', parent) self.deleteAction.triggered.connect(self._deleteItem) menu.addAction(self.deleteAction) menu.addSeparator() if len(sourceDict) > 0: for sourceCode in sourceDict.keys(): menu.addAction(Config.sourceCodes[sourceCode]['label'] + ':') sources = sorted(sourceDict[sourceCode]) for item in sources: if item.isValid(): menu.addAction(item.itemLabel()) elif haveSchematic: menu.addAction('Unknown Source') else: menu.addAction('No Schematic') if item.classCode() == 'context': subItem = plugin.data().parentItem(item) if subItem and subItem.isValid(): menu.addSeparator() grpItem = plugin.data().parentItem(subItem) if Settings.siteServerUrl(): self.subAction = OpenArkAction( Settings.siteServerUrl(), subItem, 'Sub-group: ' + str(subItem.itemId()), parent) menu.addAction(self.subAction) if grpItem: self.grpAction = OpenArkAction( Settings.siteServerUrl(), grpItem, 'Group: ' + str(grpItem.itemId()), parent) menu.addAction(self.grpAction) else: menu.addAction('Sub-group: ' + str(subItem.itemId())) if grpItem: menu.addAction('Group: ' + str(grpItem.itemId())) if len(area) > 0: menu.addSeparator() tot = 0 for a in area: tot += a units = self._iface.mapCanvas().mapUnits() suffix = '' if units == QGis.Meters: suffix = u' m²' elif units == QGis.Feet: suffix = u' ft²' elif units == QGis.NauticalMiles: suffix = u' NM²' menu.addAction( ClipboardAction(u'Area: ', u'%.3f' % tot + suffix, parent)) self.setMenu(menu)