changeset 269:40a0fa9af6b4 tonioni

added a new layer creator (not very nice though)
author matthiasm
date Tue, 26 Mar 2013 20:13:06 +0000
parents 1f8251b3ad5d
children 776e1aae635a
files framework/Document.cpp framework/Document.h
diffstat 2 files changed, 70 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/framework/Document.cpp	Tue Mar 26 16:56:39 2013 +0000
+++ b/framework/Document.cpp	Tue Mar 26 20:13:06 2013 +0000
@@ -202,7 +202,6 @@
 
     return newLayer;
 }
-
 Layer *
 Document::createDerivedLayer(const Transform &transform,
                              const ModelTransformer::Input &input)
@@ -259,6 +258,66 @@
     return newLayer;
 }
 
+Layer *
+Document::createDerivedLayer(const Transform &transform,
+                             const ModelTransformer::Input &input,
+                             const LayerFactory::LayerType type)
+{
+	// !!! THIS IS TOTALLY REDUNDANT CODE, EXCEPT FOR THE type SETTING
+	
+    QString message;
+    Model *newModel = addDerivedModel(transform, input, message);
+    if (!newModel) {
+        emit modelGenerationFailed(transform.getIdentifier(), message);
+        return 0;
+    } else if (message != "") {
+        emit modelGenerationWarning(transform.getIdentifier(), message);
+    }
+
+    LayerFactory::LayerTypeSet types =
+	LayerFactory::getInstance()->getValidLayerTypes(newModel);
+
+    if (types.empty()) {
+	std::cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << std::endl;
+        newModel->aboutToDelete();
+        emit modelAboutToBeDeleted(newModel);
+        m_models.erase(newModel);
+	delete newModel;
+	return 0;
+    }
+
+    //!!! for now, just use the first suitable layer type
+
+    Layer *newLayer = createLayer(type);
+    setModel(newLayer, newModel);
+
+    //!!! We need to clone the model when adding the layer, so that it
+    //can be edited without affecting other layers that are based on
+    //the same model.  Unfortunately we can't just clone it now,
+    //because it probably hasn't been completed yet -- the transform
+    //runs in the background.  Maybe the transform has to handle
+    //cloning and cacheing models itself.
+    //
+    // Once we do clone models here, of course, we'll have to avoid
+    // leaking them too.
+    //
+    // We want the user to be able to add a model to a second layer
+    // _while it's still being calculated in the first_ and have it
+    // work quickly.  That means we need to put the same physical
+    // model pointer in both layers, so they can't actually be cloned.
+    
+    if (newLayer) {
+	newLayer->setObjectName(getUniqueLayerName
+                                (TransformFactory::getInstance()->
+                                 getTransformFriendlyName
+                                 (transform.getIdentifier())));
+    }
+
+    emit layerAdded(newLayer);
+    return newLayer;
+}
+
+
 void
 Document::setMainModel(WaveFileModel *model)
 {
--- a/framework/Document.h	Tue Mar 26 16:56:39 2013 +0000
+++ b/framework/Document.h	Tue Mar 26 20:13:06 2013 +0000
@@ -117,6 +117,16 @@
                               const ModelTransformer::Input &);
 
     /**
+     * Exactly the same as above, but providing exactly the layer type
+     * for cases in which the first suitable layer type for a transform
+     * is not the desired one.
+     * WARNING: highly redundant code (with the above creation funciotn)
+     */
+    Layer *createDerivedLayer(const Transform &,
+                              const ModelTransformer::Input &,
+                              const LayerFactory::LayerType type);
+
+    /**
      * Delete the given layer, and also its associated model if no
      * longer used by any other layer.  In general, this should be the
      * only method used to delete layers -- doing so directly is a bit