diff transform/ModelTransformerFactory.cpp @ 877:b109b88bfa85 tonioni

Callback handler for additional models at end of processing
author Chris Cannam
date Wed, 29 Jan 2014 15:58:15 +0000
parents 13803edd513d
children a2689db084f4
line wrap: on
line diff
--- a/transform/ModelTransformerFactory.cpp	Wed Jan 29 09:31:22 2014 +0000
+++ b/transform/ModelTransformerFactory.cpp	Wed Jan 29 15:58:15 2014 +0000
@@ -195,13 +195,14 @@
 Model *
 ModelTransformerFactory::transform(const Transform &transform,
                                    const ModelTransformer::Input &input,
-                                   QString &message) 
+                                   QString &message,
+                                   AdditionalModelHandler *handler) 
 {
     SVDEBUG << "ModelTransformerFactory::transform: Constructing transformer with input model " << input.getModel() << endl;
 
     Transforms transforms;
     transforms.push_back(transform);
-    vector<Model *> mm = transformMultiple(transforms, input, message);
+    vector<Model *> mm = transformMultiple(transforms, input, message, handler);
     if (mm.empty()) return 0;
     else return mm[0];
 }
@@ -209,17 +210,22 @@
 vector<Model *>
 ModelTransformerFactory::transformMultiple(const Transforms &transforms,
                                            const ModelTransformer::Input &input,
-                                           QString &message) 
+                                           QString &message,
+                                           AdditionalModelHandler *handler) 
 {
     SVDEBUG << "ModelTransformerFactory::transformMultiple: Constructing transformer with input model " << input.getModel() << endl;
     
     ModelTransformer *t = createTransformer(transforms, input);
     if (!t) return vector<Model *>();
 
-    connect(t, SIGNAL(finished()), this, SLOT(transformerFinished()));
+    if (handler) {
+        m_handlers[t] = handler;
+    }
 
     m_runningTransformers.insert(t);
 
+    connect(t, SIGNAL(finished()), this, SLOT(transformerFinished()));
+
     t->start();
     vector<Model *> models = t->detachOutputModels();
 
@@ -270,6 +276,14 @@
 
     m_runningTransformers.erase(transformer);
 
+    if (m_handlers.find(transformer) != m_handlers.end()) {
+        if (transformer->willHaveAdditionalOutputModels()) {
+            vector<Model *> mm = transformer->detachAdditionalOutputModels();
+            m_handlers[transformer]->moreModelsAvailable(mm);
+        }
+        m_handlers.erase(transformer);
+    }
+
     transformer->wait(); // unnecessary but reassuring
     delete transformer;
 }