digitizingtools.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # -*- coding: utf-8 -*-
  2. """
  3. /***************************************************************************
  4. DigitizingTools
  5. A QGIS plugin
  6. Subsumes different tools useful during digitizing sessions
  7. some code adopted/adapted from:
  8. 'CadTools Plugin', Copyright (C) Stefan Ziegler
  9. -------------------
  10. begin : 2013-02-25
  11. copyright : (C) 2013 by Bernhard Ströbl
  12. email : bernhard.stroebl@jena.de
  13. ***************************************************************************/
  14. /***************************************************************************
  15. * *
  16. * This program is free software; you can redistribute it and/or modify *
  17. * it under the terms of the GNU General Public License as published by *
  18. * the Free Software Foundation; either version 2 of the License, or *
  19. * (at your option) any later version. *
  20. * *
  21. ***************************************************************************/
  22. """
  23. from __future__ import absolute_import
  24. from builtins import object
  25. # Import the PyQt and QGIS libraries
  26. from qgis.PyQt import QtCore, QtWidgets
  27. from qgis.core import *
  28. import os.path, sys
  29. # Set up current path.
  30. currentPath = os.path.dirname( __file__ )
  31. sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/tools'))
  32. sys.path.append(os.path.abspath(os.path.dirname(__file__)))
  33. from .dtDialog import DigitizingToolsAbout
  34. #import the tools
  35. import dtsplitmultipart
  36. import dtcutter
  37. import dtclipper
  38. import dtfillring
  39. import dtfillgap
  40. import dtflipline
  41. import dtsplitfeature
  42. import dtmovenodebyarea
  43. import dtmovesidebydistance
  44. import dtmovesidebyarea
  45. import dtmedianline
  46. import dtextractpart
  47. import dtmerge
  48. import dtexchangegeometry
  49. class DigitizingTools(object):
  50. """Main class for the plugin"""
  51. def __init__(self, iface):
  52. # Save reference to the QGIS interface
  53. self.iface = iface
  54. # initialize plugin directory
  55. self.plugin_dir = QtCore.QFileInfo(QgsApplication.qgisUserDatabaseFilePath()).path() + "/python/plugins/DigitizingTools"
  56. # initialize locale
  57. QgsMessageLog.logMessage("dir = " + self.plugin_dir)
  58. localePath = ""
  59. try:
  60. locale = QtCore.QSettings().value("locale/userLocale", "en", type=str)[0:2]
  61. except:
  62. locale = "en"
  63. if QtCore.QFileInfo(self.plugin_dir).exists():
  64. localePath = self.plugin_dir + "/i18n/digitizingtools_" + locale + ".qm"
  65. if QtCore.QFileInfo(localePath).exists():
  66. self.translator = QtCore.QTranslator()
  67. self.translator.load(localePath)
  68. QtCore.QCoreApplication.installTranslator(self.translator)
  69. def initGui(self):
  70. """Customize QGIS' GUI"""
  71. #. Add toolbar
  72. self.toolBar = self.iface.addToolBar("DigitizingTools")
  73. self.toolBar.setObjectName("DigitizingTools")
  74. #. Add a menu
  75. self.menuLabel = QtWidgets.QApplication.translate( "DigitizingTools","&DigitizingTools" )
  76. self.digitizingtools_help = QtWidgets.QAction( QtWidgets.QApplication.translate("DigitizingTools", "Help" ), self.iface.mainWindow() )
  77. self.digitizingtools_about = QtWidgets.QAction( QtWidgets.QApplication.translate("DigitizingTools", "About" ), self.iface.mainWindow() )
  78. self.digitizingtools_about.setObjectName("DtAbout")
  79. self.digitizingtools_settings = QtWidgets.QAction( QtWidgets.QApplication.translate("DigitizingTools", "Settings" ), self.iface.mainWindow() )
  80. self.iface.addPluginToMenu(self.menuLabel, self.digitizingtools_about)
  81. #. Add the tools
  82. self.multiPartSplitter = dtsplitmultipart.DtSplitMultiPartTool(self.iface, self.toolBar)
  83. self.partExtractor = dtextractpart.DtExtractPartTool(self.iface, self.toolBar)
  84. self.splitfeature = dtsplitfeature.DtSplitFeature(self.iface, self.toolBar)
  85. self.merger = dtmerge.DtMerge(self.iface, self.toolBar)
  86. self.exchangeGeometry = dtexchangegeometry.DtExchangeGeometry(self.iface, self.toolBar)
  87. self.cutter = dtcutter.DtCutWithPolygon(self.iface, self.toolBar)
  88. self.clipper = dtclipper.DtClipWithPolygon(self.iface, self.toolBar)
  89. self.ringFiller = dtfillring.DtFillRing(self.iface, self.toolBar)
  90. self.gapFiller = dtfillgap.DtFillGap(self.iface, self.toolBar)
  91. self.gapFillerAll = dtfillgap.DtFillGapAllLayers(self.iface, self.toolBar)
  92. self.flipLine = dtflipline.DtFlipLine(self.iface, self.toolBar)
  93. self.moveNodeByArea = dtmovenodebyarea.DtMoveNodeByArea(self.iface, self.toolBar)
  94. self.moveSideByDistance = dtmovesidebydistance.DtMoveSideByDistance(self.iface, self.toolBar)
  95. self.moveSideByArea = dtmovesidebyarea.DtMoveSideByArea(self.iface, self.toolBar)
  96. self.medianLine = dtmedianline.DtMedianLine(self.iface, self.toolBar)
  97. self.digitizingtools_about.triggered.connect(self.doAbout)
  98. #QObject.connect( self.digitizingtools_help, SIGNAL("triggered()"), self.doHelp )
  99. #QObject.connect( self.digitizingtools_settings, SIGNAL("triggered()"), self.doSettings )
  100. def doAbout(self):
  101. d = DigitizingToolsAbout(self.iface)
  102. d.exec_()
  103. def doHelp(self):
  104. webbrowser.open(currentPath + "/help/build/html/intro.html")
  105. def doSettings(self):
  106. settings = CadToolsSettingsGui(self.iface.mainWindow())
  107. settings.show()
  108. def unload(self):
  109. # remove toolbar and menu
  110. del self.toolBar
  111. self.iface.removePluginMenu(self.menuLabel, self.digitizingtools_about)