28
28
29
29
import os
30
30
import importlib
31
- from qgis .PyQt .QtCore import QCoreApplication
32
- from qgis .PyQt .QtGui import QIcon
33
31
from qgis .core import (QgsProcessingUtils ,
34
32
QgsMessageLog )
35
- from processing .core .GeoAlgorithm import GeoAlgorithm
36
33
from processing .core .ProcessingConfig import ProcessingConfig
37
34
from processing .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
38
35
from processing .core .parameters import (getParameterFromString ,
53
50
from processing .tools .system import getTempFilename
54
51
from processing .algs .saga .SagaNameDecorator import decoratedAlgorithmName , decoratedGroupName
55
52
from . import SagaUtils
53
+ from .SagaAlgorithmBase import SagaAlgorithmBase
56
54
57
55
pluginPath = os .path .normpath (os .path .join (
58
56
os .path .split (os .path .dirname (__file__ ))[0 ], os .pardir ))
59
57
60
58
sessionExportedLayers = {}
61
59
62
60
63
- class SagaAlgorithm (GeoAlgorithm ):
61
+ class SagaAlgorithm (SagaAlgorithmBase ):
64
62
65
63
OUTPUT_EXTENT = 'OUTPUT_EXTENT'
66
64
67
65
def __init__ (self , descriptionfile ):
68
- GeoAlgorithm .__init__ (self )
69
- self .hardcodedStrings = []
70
- self .allowUnmatchingGridExtents = False
71
- self .descriptionFile = descriptionfile
72
- self .defineCharacteristicsFromFile ()
73
- self ._icon = None
66
+ super ().__init__ ()
67
+ self .hardcoded_strings = []
68
+ self .allow_nonmatching_grid_extents = False
69
+ self .description_file = descriptionfile
70
+ self .undecorated_group = None
74
71
self ._name = ''
75
72
self ._display_name = ''
76
73
self ._group = ''
74
+ self .params = []
75
+ self .defineCharacteristicsFromFile ()
76
+
77
+ def createInstance (self ):
78
+ return SagaAlgorithm (self .description_file )
77
79
78
- def icon (self ):
79
- if self . _icon is None :
80
- self ._icon = QIcon ( os . path . join ( pluginPath , 'images' , 'saga.png' ) )
81
- return self . _icon
80
+ def initAlgorithm (self , config = None ):
81
+ #for p in self.params :
82
+ # self.addParameter(p )
83
+ pass
82
84
83
85
def name (self ):
84
86
return self ._name
@@ -93,7 +95,7 @@ def shortHelpString(self):
93
95
return shortHelp .get (self .id (), None )
94
96
95
97
def defineCharacteristicsFromFile (self ):
96
- with open (self .descriptionFile ) as lines :
98
+ with open (self .description_file ) as lines :
97
99
line = lines .readline ().strip ('\n ' ).strip ()
98
100
self ._name = line
99
101
if '|' in self ._name :
@@ -104,33 +106,34 @@ def defineCharacteristicsFromFile(self):
104
106
105
107
else :
106
108
self .cmdname = self ._name
107
- self ._display_name = QCoreApplication . translate ( "SAGAAlgorithm" , str (self ._name ))
109
+ self ._display_name = self . tr ( str (self ._name ))
108
110
self ._name = decoratedAlgorithmName (self ._name )
109
- self ._display_name = QCoreApplication . translate ( "SAGAAlgorithm" , str (self ._name ))
111
+ self ._display_name = self . tr ( str (self ._name ))
110
112
111
113
self ._name = self ._name .lower ()
112
114
validChars = \
113
115
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:'
114
116
self ._name = '' .join (c for c in self ._name if c in validChars )
115
117
116
118
line = lines .readline ().strip ('\n ' ).strip ()
117
- self .undecoratedGroup = line
118
- self ._group = QCoreApplication . translate ( "SAGAAlgorithm" , decoratedGroupName (self .undecoratedGroup ))
119
+ self .undecorated_group = line
120
+ self ._group = self . tr ( decoratedGroupName (self .undecorated_group ))
119
121
line = lines .readline ().strip ('\n ' ).strip ()
120
122
while line != '' :
121
123
if line .startswith ('Hardcoded' ):
122
- self .hardcodedStrings .append (line [len ('Hardcoded|' ):])
124
+ self .hardcoded_strings .append (line [len ('Hardcoded|' ):])
123
125
elif line .startswith ('Parameter' ):
124
- self .addParameter (getParameterFromString (line ))
126
+ self .params . append (getParameterFromString (line ))
125
127
elif line .startswith ('AllowUnmatching' ):
126
- self .allowUnmatchingGridExtents = True
128
+ self .allow_nonmatching_grid_extents = True
127
129
elif line .startswith ('Extent' ):
128
130
# An extent parameter that wraps 4 SAGA numerical parameters
129
131
self .extentParamNames = line [6 :].strip ().split (' ' )
130
- self .addParameter (ParameterExtent (self .OUTPUT_EXTENT ,
131
- 'Output extent' ))
132
+ self .params . append (ParameterExtent (self .OUTPUT_EXTENT ,
133
+ 'Output extent' ))
132
134
else :
133
- self .addOutput (getOutputFromString (line ))
135
+ pass # TODO
136
+ #self.addOutput(getOutputFromString(line))
134
137
line = lines .readline ().strip ('\n ' ).strip ()
135
138
136
139
def processAlgorithm (self , parameters , context , feedback ):
@@ -206,8 +209,8 @@ def processAlgorithm(self, parameters, context, feedback):
206
209
extent = QgsProcessingUtils .combineLayerExtents ([layer ])
207
210
208
211
# 2: Set parameters and outputs
209
- command = self .undecoratedGroup + ' "' + self .cmdname + '"'
210
- command += ' ' + ' ' .join (self .hardcodedStrings )
212
+ command = self .undecorated_group + ' "' + self .cmdname + '"'
213
+ command += ' ' + ' ' .join (self .hardcoded_strings )
211
214
212
215
for param in self .parameterDefinitions ():
213
216
if not param .name () in parameters or parameters [param .name ()] is None :
@@ -365,7 +368,7 @@ def checkParameterValues(self, parameters, context):
365
368
if layer .bandCount () > 1 :
366
369
return False , self .tr ('Input layer {0} has more than one band.\n '
367
370
'Multiband layers are not supported by SAGA' ).format (layer .name ())
368
- if not self .allowUnmatchingGridExtents :
371
+ if not self .allow_nonmatching_grid_extents :
369
372
if extent is None :
370
373
extent = (layer .extent (), layer .height (), layer .width ())
371
374
else :
0 commit comments