-
Notifications
You must be signed in to change notification settings - Fork 13
/
mgrsCapture.py
154 lines (129 loc) · 6.32 KB
/
mgrsCapture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from qgis.PyQt.QtCore import Qt, QUrl
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.core import QgsApplication
import processing
from .provider import MGRSProvider
from .zoomToMgrs import ZoomToMgrs
from .copyMgrsTool import CopyMgrsTool
from .mgrsGeomGenerator import MgrsGeomGenerator
from .settings import SettingsWidget
import os
import webbrowser
class MGRSCapture:
def __init__(self, iface):
self.iface = iface
self.canvas = iface.mapCanvas()
self.toolbar = self.iface.addToolBar('MGRS Toolbar')
self.toolbar.setObjectName('MGRSToolbar')
self.provider = MGRSProvider()
def initGui(self):
'''Initialize Lot Lon Tools GUI.'''
# Initialize the Settings Dialog box
self.settingsDialog = SettingsWidget(self.iface)
self.mapTool = CopyMgrsTool(self.iface)
# Add Interface for Coordinate Capturing
icon = QIcon(os.path.dirname(__file__) + "/images/copyMgrs.svg")
self.copyAction = QAction(icon, "Copy/Display MGRS Coordinate", self.iface.mainWindow())
self.copyAction.setObjectName('mgrsCopy')
self.copyAction.triggered.connect(self.startCapture)
self.copyAction.setCheckable(True)
self.toolbar.addAction(self.copyAction)
self.iface.addPluginToMenu("MGRS", self.copyAction)
# Add Interface for Zoom to Coordinate
icon = QIcon(os.path.dirname(__file__) + "/images/zoomToMgrs.svg")
self.zoomToAction = QAction(icon, "Zoom To MGRS Coordinate", self.iface.mainWindow())
self.zoomToAction.setObjectName('mgrsZoom')
self.zoomToAction.triggered.connect(self.showZoomToDialog)
self.toolbar.addAction(self.zoomToAction)
self.iface.addPluginToMenu('MGRS', self.zoomToAction)
self.zoomToDialog = ZoomToMgrs(self.iface, self.iface.mainWindow())
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog)
self.zoomToDialog.hide()
# Add Interface for MGRS geometry gnerator
icon = QIcon(os.path.dirname(__file__) + "/images/mgrsGeom.svg")
self.geomGenAction = QAction(icon, "MGRS Geometry Generator", self.iface.mainWindow())
self.geomGenAction.setObjectName('mgrsGeomGenerator')
self.geomGenAction.triggered.connect(self.showGeometryGenerator)
self.toolbar.addAction(self.geomGenAction)
self.iface.addPluginToMenu('MGRS', self.geomGenAction)
self.geomGenDialog = MgrsGeomGenerator(self.iface, self.iface.mainWindow())
self.geomGenDialog.hide()
# MGRS Grid Zone Designator
icon = QIcon(':/images/themes/default/processingAlgorithm.svg')
self.gzdAction = QAction(icon, "MGRS Grid Zone Designator", self.iface.mainWindow())
self.gzdAction.triggered.connect(self.gzd)
self.iface.addPluginToMenu("MGRS", self.gzdAction)
# Initialize the Settings Dialog Box
settingsicon = QIcon(':/images/themes/default/mActionOptions.svg')
self.settingsAction = QAction(settingsicon, "Settings", self.iface.mainWindow())
self.settingsAction.setObjectName('mgrsSettings')
self.settingsAction.triggered.connect(self.settings)
self.iface.addPluginToMenu('MGRS', self.settingsAction)
# Help
icon = QIcon(os.path.dirname(__file__) + '/images/help.svg')
self.helpAction = QAction(icon, "Help", self.iface.mainWindow())
self.helpAction.setObjectName('mgrsHelp')
self.helpAction.triggered.connect(self.help)
self.iface.addPluginToMenu('MGRS', self.helpAction)
self.canvas.mapToolSet.connect(self.resetTools)
# Add the processing provider
QgsApplication.processingRegistry().addProvider(self.provider)
def resetTools(self, newtool, oldtool):
'''Uncheck the Copy MGRS tool'''
try:
if oldtool is self.mapTool:
self.copyAction.setChecked(False)
if newtool is self.mapTool:
self.copyAction.setChecked(True)
except Exception:
pass
def unload(self):
'''Unload LatLonTools from the QGIS interface'''
self.zoomToDialog.removeMarker()
self.canvas.unsetMapTool(self.mapTool)
self.iface.removePluginMenu('MGRS', self.copyAction)
self.iface.removePluginMenu('MGRS', self.zoomToAction)
self.iface.removePluginMenu('MGRS', self.geomGenAction)
self.iface.removePluginMenu('MGRS', self.gzdAction)
self.iface.removePluginMenu('MGRS', self.settingsAction)
self.iface.removePluginMenu('MGRS', self.helpAction)
self.iface.removeDockWidget(self.zoomToDialog)
# Remove Toolbar Icons
self.iface.removeToolBarIcon(self.copyAction)
self.iface.removeToolBarIcon(self.zoomToAction)
self.iface.removeToolBarIcon(self.geomGenAction)
del self.toolbar
self.geomGenDialog = None
self.zoomToDialog = None
self.settingsDialog = None
self.mapTool = None
QgsApplication.processingRegistry().removeProvider(self.provider)
def startCapture(self):
'''Set the focus of the copy coordinate tool'''
self.canvas.setMapTool(self.mapTool)
def showZoomToDialog(self):
'''Show the zoom to docked widget.'''
self.zoomToDialog.show()
def showGeometryGenerator(self):
'''Show geometry generator dialog.'''
self.geomGenDialog.show()
def gzd(self):
processing.execAlgorithmDialog('mgrs:mgrsgzd', {})
def settings(self):
'''Show the settings dialog box'''
self.settingsDialog.show()
def help(self):
'''Display a help page'''
url = QUrl.fromLocalFile(os.path.dirname(__file__) + "/index.html").toString()
webbrowser.open(url, new=2)