|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + Grass7AlgorithmProvider.py |
| 6 | + --------------------- |
| 7 | + Date : April 2014 |
| 8 | + Copyright : (C) 2014 by Victor Olaya |
| 9 | + Email : volayaf at gmail dot com |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +from processing.grass7.nviz7 import nviz7 |
| 21 | + |
| 22 | +__author__ = 'Victor Olaya' |
| 23 | +__date__ = 'April 2014' |
| 24 | +__copyright__ = '(C) 2014, Victor Olaya' |
| 25 | + |
| 26 | +# This will get replaced with a git SHA1 when you do a git archive |
| 27 | + |
| 28 | +__revision__ = '$Format:%H$' |
| 29 | + |
| 30 | +import os |
| 31 | +from PyQt4.QtCore import * |
| 32 | +from PyQt4.QtGui import * |
| 33 | +from processing.core.ProcessingConfig import ProcessingConfig, Setting |
| 34 | +from processing.core.AlgorithmProvider import AlgorithmProvider |
| 35 | +from processing.core.ProcessingLog import ProcessingLog |
| 36 | +from processing.grass7.Grass7Utils import Grass7Utils |
| 37 | +from processing.grass7.Grass7Algorithm import Grass7Algorithm |
| 38 | +from processing.tools.system import * |
| 39 | + |
| 40 | + |
| 41 | +class Grass7AlgorithmProvider(AlgorithmProvider): |
| 42 | + |
| 43 | + def __init__(self): |
| 44 | + AlgorithmProvider.__init__(self) |
| 45 | + self.createAlgsList() # Preloading algorithms to speed up |
| 46 | + |
| 47 | + def initializeSettings(self): |
| 48 | + AlgorithmProvider.initializeSettings(self) |
| 49 | + if isWindows() or isMac(): |
| 50 | + ProcessingConfig.addSetting(Setting(self.getDescription(), |
| 51 | + Grass7Utils.GRASS_FOLDER, 'GRASS7 folder', |
| 52 | + Grass7Utils.grassPath())) |
| 53 | + ProcessingConfig.addSetting(Setting(self.getDescription(), |
| 54 | + Grass7Utils.GRASS_WIN_SHELL, 'Msys folder', |
| 55 | + Grass7Utils.grassWinShell())) |
| 56 | + ProcessingConfig.addSetting(Setting(self.getDescription(), |
| 57 | + Grass7Utils.GRASS_LOG_COMMANDS, |
| 58 | + 'Log execution commands', False)) |
| 59 | + ProcessingConfig.addSetting(Setting(self.getDescription(), |
| 60 | + Grass7Utils.GRASS_LOG_CONSOLE, |
| 61 | + 'Log console output', False)) |
| 62 | + |
| 63 | + def unload(self): |
| 64 | + AlgorithmProvider.unload(self) |
| 65 | + if isWindows() or isMac(): |
| 66 | + ProcessingConfig.removeSetting(Grass7Utils.GRASS_FOLDER) |
| 67 | + ProcessingConfig.removeSetting(Grass7Utils.GRASS_WIN_SHELL) |
| 68 | + ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS) |
| 69 | + ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_CONSOLE) |
| 70 | + |
| 71 | + def createAlgsList(self): |
| 72 | + self.preloadedAlgs = [] |
| 73 | + folder = Grass7Utils.grassDescriptionPath() |
| 74 | + for descriptionFile in os.listdir(folder): |
| 75 | + if descriptionFile.endswith('txt'): |
| 76 | + try: |
| 77 | + alg = Grass7Algorithm(os.path.join(folder, descriptionFile)) |
| 78 | + if alg.name.strip() != '': |
| 79 | + self.preloadedAlgs.append(alg) |
| 80 | + else: |
| 81 | + ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, |
| 82 | + 'Could not open GRASS GIS 7 algorithm: ' |
| 83 | + + descriptionFile) |
| 84 | + except Exception, e: |
| 85 | + ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, |
| 86 | + 'Could not open GRASS GIS 7 algorithm: ' |
| 87 | + + descriptionFile) |
| 88 | + self.preloadedAlgs.append(nviz7()) |
| 89 | + |
| 90 | + def _loadAlgorithms(self): |
| 91 | + self.algs = self.preloadedAlgs |
| 92 | + |
| 93 | + def getDescription(self): |
| 94 | + return 'GRASS GIS 7 commands' |
| 95 | + |
| 96 | + def getName(self): |
| 97 | + return 'grass70' |
| 98 | + |
| 99 | + def getIcon(self): |
| 100 | + return QIcon(os.path.dirname(__file__) + '/../images/grass.png') |
| 101 | + |
| 102 | + def getSupportedOutputVectorLayerExtensions(self): |
| 103 | + return ['shp'] |
| 104 | + |
| 105 | + def getSupportedOutputRasterLayerExtensions(self): |
| 106 | + return ['tif'] |
| 107 | + |
0 commit comments