-
Notifications
You must be signed in to change notification settings - Fork 11
/
sectionmanager_dialog.py
185 lines (145 loc) · 7.33 KB
/
sectionmanager_dialog.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import os
from PyQt5 import QtCore, uic
from PyQt5 import QtWidgets
#from PyQt5 import QtGui
from qgis.core import *
from qgis.utils import *
from qgis.gui import *
from .sectionorthogonal_dialog import SectionOrthogonalDialog
from .dialogBase import dialogBase
from .SectionMapTool import SectionMapTool
from .Utils import *
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'sectionmanager_dialog_base.ui'))
class SectionManagerDialog(QtWidgets.QDialog, dialogBase, FORM_CLASS):
def __init__(self, drillManager, parent=None):
"""Constructor."""
super(SectionManagerDialog, self).__init__(parent)
# Keep a reference to the DrillManager
self.drillManager = drillManager
self.sectionManager = self.drillManager.sectionManager
self.sectionMapTool = SectionMapTool(iface.mapCanvas(), self)
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)
self.leSectionWidth.setText(str(self.drillManager.sectionWidth))
self.fillSectionList()
self.pbMapCanvas.pressed.connect(self.onMapCanvasPressed)
self.pbWestEast.pressed.connect(self.onWestEastPressed)
self.pbSouthNorth.pressed.connect(self.onSouthNorthPressed)
self.pbDeleteSection.pressed.connect(self.onDeletePressed)
self.pbShowSection.pressed.connect(self.onShowPressed)
self.pbNewWindow.pressed.connect(self.onNewWindowPressed)
self.pbRecreate.pressed.connect(self.onRecreatePressed)
self.listSection.itemDoubleClicked.connect(self.onListItemdoubleClicked)
self.checkSelectAll.toggled.connect(self.onSelectAllChecked)
def fillSectionList(self) :
self.listSection.clear()
if len(self.sectionManager.sectionReg) > 0:
self.sectionManager.sectionReg.sort(key = lambda x: x.name)
for s in self.sectionManager.sectionReg:
item = QtWidgets.QListWidgetItem()
item.setText(s.name)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
item.setCheckState(QtCore.Qt.Unchecked)
item.setData(QtCore.Qt.UserRole, s)
self.listSection.addItem(item)
def onMapCanvasPressed(self):
self.drillManager.sectionWidth = float(self.leSectionWidth.text())
iface.mapCanvas().activateWindow()
self.sectionMapTool.oldMapTool = iface.mapCanvas().mapTool()
iface.mapCanvas().setMapTool( self.sectionMapTool )
def onWestEastPressed(self):
self.drillManager.sectionWidth = float(self.leSectionWidth.text())
dlg = SectionOrthogonalDialog(self.drillManager, dirWestEast=True)
result = dlg.exec_()
if result:
self.drillManager.sectionNorth = float(dlg.leCenter.text())
self.drillManager.sectionLimitWest = float(dlg.leLimitMin.text())
self.drillManager.sectionLimitEast = float(dlg.leLimitMax.text())
self.drillManager.sectionWEName = dlg.leName.text()
# self.drillManager.sectionWidth = float(dlg.leSectionWidth.text())
self.drillManager.sectionLayers = getCheckedLayers(dlg.listLayers)
self.drillManager.elevationLayers = getCheckedLayers(dlg.listElevation)
dlg.close()
if result:
s = self.sectionManager.createSection(self.drillManager.sectionWEName, \
self.drillManager.sectionLimitWest, self.drillManager.sectionNorth, \
self.drillManager.sectionLimitEast, self.drillManager.sectionNorth, \
self.drillManager.sectionWidth, \
self.drillManager.sectionLayers, self.drillManager.elevationLayers)
self.fillSectionList()
self.sectionManager.showSection(s)
def onSouthNorthPressed(self):
self.drillManager.sectionWidth = float(self.leSectionWidth.text())
dlg = SectionOrthogonalDialog(self.drillManager, dirWestEast=False)
result = dlg.exec_()
if result:
self.drillManager.sectionEast = float(dlg.leCenter.text())
self.drillManager.sectionLimitSouth = float(dlg.leLimitMin.text())
self.drillManager.sectionLimitNorth = float(dlg.leLimitMax.text())
self.drillManager.sectionSNName = dlg.leName.text()
# self.drillManager.sectionWidth = float(dlg.leSectionWidth.text())
self.drillManager.sectionLayers = getCheckedLayers(dlg.listLayers)
self.drillManager.elevationLayers = getCheckedLayers(dlg.listElevation)
dlg.close()
if result:
s = self.sectionManager.createSection(self.drillManager.sectionSNName, \
self.drillManager.sectionEast, self.drillManager.sectionLimitSouth, \
self.drillManager.sectionEast, self.drillManager.sectionLimitNorth, \
self.drillManager.sectionWidth, \
self.drillManager.sectionLayers, self.drillManager.elevationLayers)
self.fillSectionList()
self.sectionManager.showSection(s)
def onDeletePressed(self):
#Build a list of sections from all checked ones, or if none checked, the currently selected one
sList = self.checkedSections()
if len(sList) == 0:
cs = self.currentSection()
if cs is not None:
sList.append( cs )
for s in sList:
self.sectionManager.deleteSection(s)
self.fillSectionList()
def onRecreatePressed(self):
#Build a list of sections from all checked ones, or if none checked, the currently selected one
sList = self.checkedSections()
if len(sList) == 0:
cs = self.currentSection()
if cs is not None:
sList.append( cs )
for s in sList:
self.sectionManager.recreateSection(s)
#If there was only 1 section to recreate, then show it as well
if len(sList) == 0:
self.sectionManager.showSection(s)
def onShowPressed(self):
self.showCurrentSelection()
def onNewWindowPressed(self):
cs = self.currentSection()
if cs is not None:
cs.createWindow()
def onListItemdoubleClicked(self):
self.showCurrentSelection()
def onSelectAllChecked(self):
self.selectAll(self.listSection, self.checkSelectAll.isChecked())
def showCurrentSelection(self):
cs = self.currentSection()
if cs != None:
self.sectionManager.showSection(cs)
def currentSection(self):
cs = None
item = self.listSection.currentItem()
if item is not None:
cs = item.data(QtCore.Qt.UserRole)
return cs
def checkedSections(self):
sList = []
for index in range(self.listSection.count()):
if self.listSection.item(index).checkState():
s = self.listSection.item(index).data(QtCore.Qt.UserRole)
sList.append(s)
return sList