@@ -50,6 +50,9 @@ def __init__(self):
50
50
self .algPos = []
51
51
self .paramPos = []
52
52
53
+ #deactivated algorithms that should not be executed
54
+ self .deactivated = []
55
+
53
56
54
57
def getIcon (self ):
55
58
return QtGui .QIcon (os .path .dirname (__file__ ) + "/../images/model.png" )
@@ -137,6 +140,97 @@ def addAlgorithm(self, alg, parametersMap, valuesMap, outputsMap):
137
140
self .paramValues [value ] = valuesMap [value ]
138
141
self .algPos .append (self .getPositionForAlgorithmItem ())
139
142
143
+ def removeAlgorithm (self , index ):
144
+ if self .hasDependencies (self .algs [index ], index ):
145
+ return False
146
+ for out in self .algs [index ].outputs :
147
+ val = self .algOutputs [index ][out .name ]
148
+ if val :
149
+ name = self .getSafeNameForOutput (index , out )
150
+ self .removeOutputFromName (name )
151
+ del self .algs [index ]
152
+ del self .algParameters [index ]
153
+ del self .algOutputs [index ]
154
+ del self .algPos [index ]
155
+ self .updateModelerView ()
156
+ return True
157
+
158
+ def removeParameter (self , index ):
159
+ if self .hasDependencies (self .parameters [index ], index ):
160
+ return False
161
+ del self .parameters [index ]
162
+ del self .paramPos [index ]
163
+ self .updateModelerView ()
164
+ return True
165
+
166
+ def hasDependencies (self , element , elementIndex ):
167
+ '''This method returns true if some other element depends on the passed one'''
168
+ if isinstance (element , Parameter ):
169
+ for alg in self .algParameters :
170
+ for aap in alg .values ():
171
+ if aap .alg == AlgorithmAndParameter .PARENT_MODEL_ALGORITHM :
172
+ if aap .param == element .name :
173
+ return True
174
+ elif aap .param in self .paramValues : #check for multiple inputs
175
+ aap2 = self .paramValues [aap .param ]
176
+ if element .name in aap2 :
177
+ return True
178
+ if isinstance (element , ParameterVector ):
179
+ for param in self .parameters :
180
+ if isinstance (param , ParameterTableField ):
181
+ if param .parent == element .name :
182
+ return True
183
+ else :
184
+ for alg in self .algParameters :
185
+ for aap in alg .values ():
186
+ if aap .alg == elementIndex :
187
+ return True
188
+
189
+ return False
190
+
191
+ def deactivateAlgorithm (self , algIndex , update = False ):
192
+ if algIndex not in self .deactivated :
193
+ self .deactivated .append (algIndex )
194
+ dependent = self .getDependentAlgorithms (algIndex )
195
+ for alg in dependent :
196
+ self .deactivateAlgorithm (alg )
197
+ if update :
198
+ self .updateModelerView ()
199
+
200
+ def activateAlgorithm (self , algIndex , update = False ):
201
+ if algIndex in self .deactivated :
202
+ dependsOn = self .getDependsOnAlgorithms (algIndex )
203
+ for alg in dependsOn :
204
+ if alg in self .deactivated :
205
+ return False
206
+ self .deactivated .remove (algIndex )
207
+ dependent = self .getDependentAlgorithms (algIndex )
208
+ for alg in dependent :
209
+ self .activateAlgorithm (alg )
210
+ if update :
211
+ self .updateModelerView ()
212
+ return True
213
+
214
+ def getDependsOnAlgorithms (self , algIndex ):
215
+ '''This method returns a list with the indexes of algorithm a given one depends on'''
216
+ algs = []
217
+ for aap in self .algParameters [algIndex ].values ():
218
+ if aap .alg not in algs :
219
+ algs .append (aap .alg )
220
+ return algs
221
+
222
+ def getDependentAlgorithms (self , algIndex ):
223
+ '''This method returns a list with the indexes of algorithm depending on a given one'''
224
+ dependent = []
225
+ index = - 1
226
+ for alg in self .algParameters :
227
+ index += 1
228
+ for aap in alg .values ():
229
+ if aap .alg == algIndex :
230
+ dependent .append (index )
231
+ break
232
+ return dependent
233
+
140
234
def getPositionForAlgorithmItem (self ):
141
235
MARGIN = 20
142
236
BOX_WIDTH = 200
@@ -233,18 +327,22 @@ def processAlgorithm(self, progress):
233
327
self .producedOutputs = []
234
328
iAlg = 0
235
329
for alg in self .algs :
236
- try :
237
- alg = alg .getCopy ()#copy.deepcopy(alg)
238
- self .prepareAlgorithm (alg , iAlg )
239
- progress .setText ("Running " + alg .name + " [" + str (iAlg + 1 ) + "/" + str (len (self .algs )) + "]" )
240
- outputs = {}
241
- alg .execute (progress )
242
- for out in alg .outputs :
243
- outputs [out .name ] = out .value
244
- self .producedOutputs .append (outputs )
330
+ if iAlg in self .deactivated :
245
331
iAlg += 1
246
- except GeoAlgorithmExecutionException , e :
247
- raise GeoAlgorithmExecutionException ("Error executing algorithm " + str (iAlg ) + "\n " + e .msg )
332
+ else :
333
+ try :
334
+ alg = alg .getCopy ()#copy.deepcopy(alg)
335
+ self .prepareAlgorithm (alg , iAlg )
336
+ progress .setText ("Running " + alg .name + " [" + str (iAlg + 1 ) + "/"
337
+ + str (len (self .algs ) - len (self .deactivated )) + "]" )
338
+ outputs = {}
339
+ alg .execute (progress )
340
+ for out in alg .outputs :
341
+ outputs [out .name ] = out .value
342
+ self .producedOutputs .append (outputs )
343
+ iAlg += 1
344
+ except GeoAlgorithmExecutionException , e :
345
+ raise GeoAlgorithmExecutionException ("Error executing algorithm " + str (iAlg ) + "\n " + e .msg )
248
346
249
347
250
348
def getOutputType (self , i , outname ):
@@ -341,53 +439,6 @@ def updateModelerView(self):
341
439
if self .modelerdialog :
342
440
self .modelerdialog .repaintModel ()
343
441
344
- def removeAlgorithm (self , index ):
345
- if self .hasDependencies (self .algs [index ], index ):
346
- return False
347
- for out in self .algs [index ].outputs :
348
- val = self .algOutputs [index ][out .name ]
349
- if val :
350
- name = self .getSafeNameForOutput (index , out )
351
- self .removeOutputFromName (name )
352
- del self .algs [index ]
353
- del self .algParameters [index ]
354
- del self .algOutputs [index ]
355
- del self .algPos [index ]
356
- self .updateModelerView ()
357
- return True
358
-
359
- def removeParameter (self , index ):
360
- if self .hasDependencies (self .parameters [index ], index ):
361
- return False
362
- del self .parameters [index ]
363
- del self .paramPos [index ]
364
- self .updateModelerView ()
365
- return True
366
-
367
- def hasDependencies (self , element , elementIndex ):
368
- '''returns true if some other element depends on the passed one'''
369
- if isinstance (element , Parameter ):
370
- for alg in self .algParameters :
371
- for aap in alg .values ():
372
- if aap .alg == AlgorithmAndParameter .PARENT_MODEL_ALGORITHM :
373
- if aap .param == element .name :
374
- return True
375
- elif aap .param in self .paramValues : #check for multiple inputs
376
- aap2 = self .paramValues [aap .param ]
377
- if element .name in aap2 :
378
- return True
379
- if isinstance (element , ParameterVector ):
380
- for param in self .parameters :
381
- if isinstance (param , ParameterTableField ):
382
- if param .parent == element .name :
383
- return True
384
- else :
385
- for alg in self .algParameters :
386
- for aap in alg .values ():
387
- if aap .alg == elementIndex :
388
- return True
389
-
390
- return False
391
442
392
443
def helpfile (self ):
393
444
helpfile = self .descriptionFile + ".help"
0 commit comments