Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Tool to split reaches with wastewater nodes and points #142

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions plugin/teksi_wastewater/gui/twwreachsplitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# -----------------------------------------------------------
#
# TEKSI Wastewater
# Copyright (C) 2014 Matthias Kuhn
# -----------------------------------------------------------
#
# licensed under the terms of GNU GPL 2
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, print to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ---------------------------------------------------------------------

import logging

from qgis.gui import QgsMessageBar
from qgis.PyQt.QtCore import pyqtSlot
from qgis.PyQt.QtWidgets import QDockWidget

from ..tools.twwsplitreach import TwwMapToolSplitReachWithNode
from ..utils import get_ui_class
from ..utils.twwlayermanager import TwwLayerManager

DOCK_WIDGET = get_ui_class("twwreachsplitter.ui")


class TwwReachSplitter(QDockWidget, DOCK_WIDGET):
logger = logging.getLogger(__name__)

def __init__(self, parent, iface):
QDockWidget.__init__(self, parent)
self.setupUi(self)
self.stateButton.clicked.connect(self.stateChanged)
self.iface = iface
self.mapToolSplitReachWithWN = TwwMapToolSplitReachWithNode(
self.iface,
TwwLayerManager.layer("vw_wastewater_node"),
self.mCbChannelSplitMode.isChecked(),
)
self.mapToolSplitReachWithWS = TwwMapToolSplitReachWithNode(
self.iface, TwwLayerManager.layer("vw_tww_wastewater_structure")
)
self.mapToolSplitReachWithNoNode = TwwMapToolSplitReachWithNode(
self.iface, None, self.mCbChannelSplitMode.isChecked()
)
self.layerComboBox.insertItem(
self.layerComboBox.count(),
self.tr("Wastewater Structure"),
"wastewater_structure",
)
self.layerComboBox.insertItem(
self.layerComboBox.count(), self.tr("Wastewater node"), "wastewater_node"
)
self.layerComboBox.insertItem(self.layerComboBox.count(), self.tr("No node"), "no node")
self.layerComboBox.setCurrentIndex(1)
self.stateButton.setProperty("state", "inactive")
self.msgtitle = self.tr(
f"Split reach with {self.layerComboBox.itemData(self.layerComboBox.currentIndex())}"
)
self.msg = "Left Click to digitize"
self.messageBarItem = QgsMessageBar.createMessage(self.msgtitle, self.msg)
self.layerComboBox.currentIndexChanged.connect(self.layerChanged)

@pyqtSlot(int)
def layerChanged(self, index):
try:
self.iface.messageBar().popWidget(self.messageBarItem)
except Exception:
pass
if (
self.layerComboBox.itemData(self.layerComboBox.currentIndex())
== "wastewater_structure"
):
lyr = TwwLayerManager.layer("vw_tww_wastewater_structure")
lyr.startEditing()
self.iface.mapCanvas().setMapTool(self.mapToolSplitReachWithWS)

elif self.layerComboBox.itemData(self.layerComboBox.currentIndex()) == "wastewater_node":
lyr = TwwLayerManager.layer("vw_wastewater_node")
lyr.startEditing()
self.iface.mapCanvas().setMapTool(self.mapToolSplitReachWithWN)
else: # current index is not initialized
# set current index for messageBar
self.layerComboBox.setCurrentIndex(1)

if self.stateButton.property("state") == "active":
self.msgtitle = self.tr(
f"Split reach with {self.layerComboBox.itemData(self.layerComboBox.currentIndex())}"
)
self.messageBarItem = QgsMessageBar.createMessage(self.msgtitle, self.msg)
self.iface.messageBar().pushItem(self.messageBarItem)

@pyqtSlot()
def stateChanged(self):
try:
self.iface.messageBar().popWidget(self.messageBarItem)
except Exception:
pass

if self.stateButton.property("state") != "active":
self.layerComboBox.setEnabled(True)
self.layerChanged(0)
self.stateButton.setText(self.tr("Stop Splitting Reaches"))
self.stateButton.setProperty("state", "active")
self.messageBarItem = QgsMessageBar.createMessage(self.msgtitle, self.msg)
self.iface.messageBar().pushItem(self.messageBarItem)
else:
self.layerComboBox.setEnabled(False)
self.stateButton.setText(self.tr("Start Splitting Reaches"))
self.stateButton.setProperty("state", "inactive")
179 changes: 179 additions & 0 deletions plugin/teksi_wastewater/icons/reachsplitter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions plugin/teksi_wastewater/teksi_wastewater_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
except ImportError:
TwwPlotSVGWidget = None
from .gui.twwprofiledockwidget import TwwProfileDockWidget
from .gui.twwreachsplitter import TwwReachSplitter
from .gui.twwsettingsdialog import TwwSettingsDialog
from .gui.twwwizard import TwwWizard
from .interlis import config
Expand Down Expand Up @@ -72,6 +73,9 @@ class TeksiWastewaterPlugin:
# Wizard
wizarddock = None

# Reach splitter
reachsplitterdock = None

# The layer ids the plugin will need
edgeLayer = None
nodeLayer = None
Expand Down Expand Up @@ -196,6 +200,16 @@ def initGui(self):
self.wizardAction.setCheckable(True)
self.wizardAction.triggered.connect(self.wizard)

self.reachsplitterAction = QAction(
QIcon(os.path.join(plugin_root_path(), "icons/reachsplitter.svg")),
"Reach Splitter",
self.iface.mainWindow(),
)
self.reachsplitterAction.setWhatsThis(self.tr("Split Reaches with nodes"))
self.reachsplitterAction.setEnabled(False)
self.reachsplitterAction.setCheckable(True)
self.reachsplitterAction.triggered.connect(self.reachsplitter)

self.connectNetworkElementsAction = QAction(
QIcon(os.path.join(plugin_root_path(), "icons/link-wastewater-networkelement.svg")),
QApplication.translate("teksi_wastewater", "Connect wastewater networkelements"),
Expand Down Expand Up @@ -250,6 +264,7 @@ def initGui(self):
self.toolbar.addAction(self.upstreamAction)
self.toolbar.addAction(self.downstreamAction)
self.toolbar.addAction(self.wizardAction)
self.toolbar.addAction(self.reachsplitterAction)
self.toolbar.addAction(self.refreshNetworkTopologyAction)
self.toolbar.addAction(self.connectNetworkElementsAction)

Expand All @@ -270,6 +285,7 @@ def initGui(self):
self.toolbarButtons.append(self.upstreamAction)
self.toolbarButtons.append(self.downstreamAction)
self.toolbarButtons.append(self.wizardAction)
self.toolbarButtons.append(self.reachsplitterAction)
self.toolbarButtons.append(self.refreshNetworkTopologyAction)
self.toolbarButtons.append(self.importAction)
self.toolbarButtons.append(self.exportAction)
Expand Down Expand Up @@ -318,6 +334,7 @@ def unload(self):
self.toolbar.removeAction(self.upstreamAction)
self.toolbar.removeAction(self.downstreamAction)
self.toolbar.removeAction(self.wizardAction)
self.toolbar.removeAction(self.reachsplitterAction)
self.toolbar.removeAction(self.refreshNetworkTopologyAction)
self.toolbar.removeAction(self.connectNetworkElementsAction)

Expand Down Expand Up @@ -381,6 +398,14 @@ def wizard(self):
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.wizarddock)
self.wizarddock.show()

def reachsplitter(self):
""""""
if not self.reachsplitterdock:
self.reachsplitterdock = TwwReachSplitter(self.iface.mainWindow(), self.iface)
self.logger.debug("Opening Reach Splitter")
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.reachsplitterdock)
self.reachsplitterdock.show()

def connectNetworkElements(self, checked):
self.iface.mapCanvas().setMapTool(self.maptool_connect_networkelements)

Expand Down
Loading