|
17 | 17 |
|
18 | 18 | #include "qgsprocessingmodelalgorithm.h"
|
19 | 19 | #include "qgsprocessingregistry.h"
|
| 20 | +#include "qgsprocessingfeedback.h" |
20 | 21 | #include "qgsxmlutils.h"
|
21 | 22 | #include <QFile>
|
22 | 23 | #include <QTextStream>
|
@@ -285,13 +286,77 @@ QString QgsProcessingModelAlgorithm::svgIconPath() const
|
285 | 286 |
|
286 | 287 | QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const
|
287 | 288 | {
|
288 |
| - Q_UNUSED( parameters ); |
289 |
| - Q_UNUSED( context ); |
290 |
| - Q_UNUSED( feedback ); |
291 |
| - return QVariantMap(); |
292 |
| -} |
| 289 | + QSet< QString > toExecute; |
| 290 | + QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); |
| 291 | + for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt ) |
| 292 | + { |
| 293 | + if ( childIt->isActive() ) |
| 294 | + toExecute.insert( childIt->childId() ); |
| 295 | + } |
| 296 | + |
| 297 | + QMap< QString, QVariantMap > resultsMap; |
| 298 | + QSet< QString > executed; |
| 299 | + while ( executed.count() < toExecute.count() ) |
| 300 | + { |
| 301 | + Q_FOREACH ( const QString &childId, toExecute ) |
| 302 | + { |
| 303 | + if ( executed.contains( childId ) ) |
| 304 | + continue; |
| 305 | + |
| 306 | + bool canExecute = true; |
| 307 | + Q_FOREACH ( const QString &dependency, dependsOnChildAlgorithms( childId ) ) |
| 308 | + { |
| 309 | + if ( !executed.contains( dependency ) ) |
| 310 | + { |
| 311 | + canExecute = false; |
| 312 | + break; |
| 313 | + } |
| 314 | + } |
| 315 | + |
| 316 | + if ( !canExecute ) |
| 317 | + continue; |
| 318 | + |
| 319 | + feedback->pushDebugInfo( QObject::tr( "Prepare algorithm: %1" ).arg( childId ) ); |
| 320 | + |
| 321 | + const ChildAlgorithm &child = mChildAlgorithms[ childId ]; |
| 322 | + |
| 323 | + // self.prepareAlgorithm( alg ) |
| 324 | + |
| 325 | + feedback->setProgressText( QObject::tr( "Running %1 [%2/%3]" ).arg( child.description() ).arg( executed.count() + 1 ).arg( toExecute.count() ) ); |
| 326 | + //feedback->pushDebugInfo( "Parameters: " + ', '.join( [str( p ).strip() + |
| 327 | + // '=' + str( p.value ) for p in alg.algorithm.parameters] ) ) |
| 328 | + //t0 = time.time() |
| 329 | + QVariantMap results = child.algorithm()->run( parameters, context, feedback ); |
| 330 | + resultsMap.insert( childId, results ); |
| 331 | + |
| 332 | + //dt = time.time() - t0 |
| 333 | +#if 0 |
| 334 | + |
| 335 | +# copy algorithm output value(s) back to model in case the algorithm modified those |
| 336 | + for out in alg.algorithm().outputs : |
| 337 | + if not out.flags() & QgsProcessingParameterDefinition.FlagHidden: |
| 338 | + if out.name() in alg.modelOutputs(): |
| 339 | + modelOut = self.getOutputFromName( self.getSafeNameForOutput( alg.childId(), out.name() ) ) |
| 340 | + if modelOut: |
| 341 | + modelOut.value = out.value |
| 342 | +#endif |
| 343 | + |
| 344 | + executed.insert( childId ); |
| 345 | + //feedback->pushDebugInfo( QObject::tr( "OK. Execution took %1 ms (%2 outputs)." ).arg( dt, len( alg.algorithm.modelOutputs() ) ) ) |
| 346 | +#if 0 |
| 347 | + except GeoAlgorithmExecutionException as e: |
| 348 | + feedback.pushDebugInfo( self.tr( 'Failed', 'ModelerAlgorithm' ) ) |
| 349 | + raise GeoAlgorithmExecutionException( |
| 350 | + self.tr( 'Error executing algorithm {0}\n{1}', 'ModelerAlgorithm' ).format( alg.description, e.msg ) ) |
| 351 | +#endif |
| 352 | + } |
| 353 | + } |
| 354 | + feedback->pushDebugInfo( QObject::tr( "Model processed ok. Executed %1 algorithms total" ).arg( executed.count() ) ); |
| 355 | + |
| 356 | + return QVariantMap(); |
| 357 | + } |
293 | 358 |
|
294 |
| -void QgsProcessingModelAlgorithm::setName( const QString &name ) |
| 359 | + void QgsProcessingModelAlgorithm::setName( const QString &name ) |
295 | 360 | {
|
296 | 361 | mModelName = name;
|
297 | 362 | }
|
|
0 commit comments