comparison framework/Document.cpp @ 269:40a0fa9af6b4 tonioni

added a new layer creator (not very nice though)
author matthiasm
date Tue, 26 Mar 2013 20:13:06 +0000
parents ecbf3b75c562
children 776e1aae635a
comparison
equal deleted inserted replaced
268:1f8251b3ad5d 269:40a0fa9af6b4
200 (TransformFactory::getInstance()-> 200 (TransformFactory::getInstance()->
201 getTransformFriendlyName(transform))); 201 getTransformFriendlyName(transform)));
202 202
203 return newLayer; 203 return newLayer;
204 } 204 }
205
206 Layer * 205 Layer *
207 Document::createDerivedLayer(const Transform &transform, 206 Document::createDerivedLayer(const Transform &transform,
208 const ModelTransformer::Input &input) 207 const ModelTransformer::Input &input)
209 { 208 {
210 QString message; 209 QString message;
256 } 255 }
257 256
258 emit layerAdded(newLayer); 257 emit layerAdded(newLayer);
259 return newLayer; 258 return newLayer;
260 } 259 }
260
261 Layer *
262 Document::createDerivedLayer(const Transform &transform,
263 const ModelTransformer::Input &input,
264 const LayerFactory::LayerType type)
265 {
266 // !!! THIS IS TOTALLY REDUNDANT CODE, EXCEPT FOR THE type SETTING
267
268 QString message;
269 Model *newModel = addDerivedModel(transform, input, message);
270 if (!newModel) {
271 emit modelGenerationFailed(transform.getIdentifier(), message);
272 return 0;
273 } else if (message != "") {
274 emit modelGenerationWarning(transform.getIdentifier(), message);
275 }
276
277 LayerFactory::LayerTypeSet types =
278 LayerFactory::getInstance()->getValidLayerTypes(newModel);
279
280 if (types.empty()) {
281 std::cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << std::endl;
282 newModel->aboutToDelete();
283 emit modelAboutToBeDeleted(newModel);
284 m_models.erase(newModel);
285 delete newModel;
286 return 0;
287 }
288
289 //!!! for now, just use the first suitable layer type
290
291 Layer *newLayer = createLayer(type);
292 setModel(newLayer, newModel);
293
294 //!!! We need to clone the model when adding the layer, so that it
295 //can be edited without affecting other layers that are based on
296 //the same model. Unfortunately we can't just clone it now,
297 //because it probably hasn't been completed yet -- the transform
298 //runs in the background. Maybe the transform has to handle
299 //cloning and cacheing models itself.
300 //
301 // Once we do clone models here, of course, we'll have to avoid
302 // leaking them too.
303 //
304 // We want the user to be able to add a model to a second layer
305 // _while it's still being calculated in the first_ and have it
306 // work quickly. That means we need to put the same physical
307 // model pointer in both layers, so they can't actually be cloned.
308
309 if (newLayer) {
310 newLayer->setObjectName(getUniqueLayerName
311 (TransformFactory::getInstance()->
312 getTransformFriendlyName
313 (transform.getIdentifier())));
314 }
315
316 emit layerAdded(newLayer);
317 return newLayer;
318 }
319
261 320
262 void 321 void
263 Document::setMainModel(WaveFileModel *model) 322 Document::setMainModel(WaveFileModel *model)
264 { 323 {
265 Model *oldMainModel = m_mainModel; 324 Model *oldMainModel = m_mainModel;