/
showazimuthtool.py
93 lines (70 loc) · 3.58 KB
/
showazimuthtool.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
# -*- coding: latin1 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from QuickDigitize import resources
## Import own classes and tools.
from vertexfindertool import VertexFinderTool
from showazimuthgui import ShowAzimuthGui
from azimuth import Azimuth
#import cadutils
class ShowAzimuthTool:
def __init__(self, iface, toolBar):
# Save reference to the QGIS interface
self.iface = iface
self.canvas = self.iface.mapCanvas()
# Points and Markers
self.p1 = None
self.p2 = None
self.m1 = None
self.m2 = None
# Create actions
self.act_show_azimuth = QAction(QIcon('C:\Users\Sanjutha Indrajit\.qgis2\python\plugins\QuickDigitize/showazimuth.png'), QCoreApplication.translate("QuickDigitize", "Show Azimuth"), self.iface.mainWindow())
self.act_s2v= QAction(QIcon('C:\Users\Sanjutha Indrajit\.qgis2\python/plugins/QuickDigitize/select2vertex.png'), QCoreApplication.translate("QuickDigitize", "Select 2 Vertex Points"), self.iface.mainWindow())
self.act_s2v.setCheckable(True)
# Connect to signals for button behaviour
self.act_show_azimuth.triggered.connect(self.showDialog)
self.act_s2v.triggered.connect(self.s2v)
self.canvas.mapToolSet.connect(self.deactivate)
toolBar.addSeparator()
toolBar.addAction(self.act_s2v)
toolBar.addAction(self.act_show_azimuth)
# Get the tool
self.tool = VertexFinderTool(self.canvas)
def s2v(self):
mc = self.canvas
layer = mc.currentLayer()
# Set VertexFinderTool as current tool
mc.setMapTool(self.tool)
self.act_s2v.setChecked(True)
#Connect to the VertexFinderTool
self.tool.vertexFound.connect(self.storeVertexPointsAndMarkers)
def storeVertexPointsAndMarkers(self, result):
self.p1 = result[0]
self.p2 = result[1]
self.m1 = result[2]
self.m2 = result[3]
def showDialog(self):
if self.p1 == None or self.p2 == None:
QMessageBox.information(None, QCoreApplication.translate("ctools", "Cancel"), QCoreApplication.translate("ctools", "Not enough vertex selected."))
else:
az = Azimuth.calculate(self.p1, self.p2)
flags = Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.WindowMaximizeButtonHint # QgisGui.ModalDialogFlags
self.ctrl = ShowAzimuthGui(self.iface.mainWindow(), flags)
self.ctrl.initGui()
self.ctrl.show()
self.ctrl.writeAzimuth(az)
# connect the signals
# self.ctrl.distancesFromPoints.connect(self.calculateArcIntersection)
# self.ctrl.closeArcIntersectionGui.connect(self.deactivate)
self.ctrl.unsetTool.connect(self.unsetTool)
def unsetTool(self):
self.m1 = None
self.m2 = None
mc = self.canvas
mc.unsetMapTool(self.tool)
def deactivate(self):
self.p1 = None
self.p2 = None
#uncheck the button/menu and get rid off the SFtool signal
self.act_s2v.setChecked(False)