From 87a5ab4a51362a244e4843379b0e75175a9b645b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20M=C3=BCller?= <d_muel20@uni-muenster.de>
Date: Sun, 15 Apr 2018 15:57:23 +0200
Subject: [PATCH] * Did some cleanup

---
 Grinder/Version.h                             |  2 +-
 Grinder/common/properties/PropertyBase.cpp    |  4 ----
 Grinder/engine/processors/InputProcessor.cpp  | 15 +--------------
 Grinder/engine/processors/OutputProcessor.cpp |  8 ++------
 Grinder/image/DraftItem.cpp                   |  4 ----
 Grinder/image/ImageBuild.cpp                  | 19 -------------------
 Grinder/pipeline/Block.cpp                    |  4 ----
 Grinder/pipeline/Port.cpp                     |  4 ----
 Grinder/pipeline/blocks/InputBlock.cpp        | 19 +++++++++++++++++++
 Grinder/pipeline/blocks/InputBlock.h          |  2 ++
 Grinder/project/ImageReference.cpp            |  4 ----
 11 files changed, 25 insertions(+), 60 deletions(-)

diff --git a/Grinder/Version.h b/Grinder/Version.h
index 141ea40..4d22235 100644
--- a/Grinder/Version.h
+++ b/Grinder/Version.h
@@ -10,7 +10,7 @@
 
 #define GRNDR_INFO_TITLE		"Grinder"
 #define GRNDR_INFO_COPYRIGHT	"Copyright (c) WWU Muenster"
-#define GRNDR_INFO_DATE			"13.04.2018"
+#define GRNDR_INFO_DATE			"15.04.2018"
 #define GRNDR_INFO_COMPANY		"WWU Muenster"
 #define GRNDR_INFO_WEBSITE		"http://www.uni-muenster.de"
 
diff --git a/Grinder/common/properties/PropertyBase.cpp b/Grinder/common/properties/PropertyBase.cpp
index 14c4103..2797c92 100644
--- a/Grinder/common/properties/PropertyBase.cpp
+++ b/Grinder/common/properties/PropertyBase.cpp
@@ -25,9 +25,5 @@ void PropertyBase::serialize(SerializationContext& ctx) const
 
 void PropertyBase::deserialize(DeserializationContext& ctx)
 {
-	// Deserialize values
-	if (ctx.getMode() != DeserializationContext::Mode::ProjectSerialization)	// Already set when the object was created during deserialization
-		_id = ctx.settings()[Serialization_Value_ID].toString();
-
 	_name = ctx.settings()[Serialization_Value_Name].toString();
 }
diff --git a/Grinder/engine/processors/InputProcessor.cpp b/Grinder/engine/processors/InputProcessor.cpp
index a05804a..a093287 100644
--- a/Grinder/engine/processors/InputProcessor.cpp
+++ b/Grinder/engine/processors/InputProcessor.cpp
@@ -18,20 +18,7 @@ void InputProcessor::execute(EngineExecutionContext& ctx)
 {
 	Processor::execute(ctx);
 
-	ImageReference* imageReference = *_block->imageReference();
-
-	// Make sure that the image reference really exists (just in case)
-	if (imageReference)
-	{
-		if (!std::any_of(grinder()->project().imageReferences().cbegin(), grinder()->project().imageReferences().cend(), [imageReference](const auto& imageRef) { return imageRef.get() == imageReference; }))
-			imageReference = nullptr;
-	}
-
-	// If no image reference has been set, use the currently active one
-	if (!imageReference)
-		imageReference = grinder()->projectController().activeImageReference();
-
-	if (imageReference)
+	if (auto imageReference = _block->resolveImageReference())
 		ctx.setContextEntry(_block->outPort(), DataBlob{getPortDataDescriptor(_block->outPort()), imageReference->loadImage()});
 	else
 		throwProcessorException("There currently is no active image");
diff --git a/Grinder/engine/processors/OutputProcessor.cpp b/Grinder/engine/processors/OutputProcessor.cpp
index 25cfb26..928984f 100644
--- a/Grinder/engine/processors/OutputProcessor.cpp
+++ b/Grinder/engine/processors/OutputProcessor.cpp
@@ -39,12 +39,8 @@ void OutputProcessor::execute(EngineExecutionContext& ctx)
 
 		for (auto inputBlock : inputBlocks)
 		{
-			const ImageReference* imageReference = *inputBlock->imageReference();
-
-			if (!imageReference)
-				imageReference = ctx.activeImageReference();
-
-			imageReferences.insert(imageReference);
+			if (auto imageReference = inputBlock->resolveImageReference(ctx.activeImageReference()))
+				imageReferences.insert(imageReference);
 		}
 
 		// Finally, get the image build for this block and the used images and set its image data
diff --git a/Grinder/image/DraftItem.cpp b/Grinder/image/DraftItem.cpp
index f31b66d..aaded77 100644
--- a/Grinder/image/DraftItem.cpp
+++ b/Grinder/image/DraftItem.cpp
@@ -37,10 +37,6 @@ void DraftItem::serialize(SerializationContext& ctx) const
 void DraftItem::deserialize(DeserializationContext& ctx)
 {
 	PropertyObject::deserialize(ctx);
-
-	// Deserialize values
-	if (ctx.getMode() != DeserializationContext::Mode::ProjectSerialization)	// Already set when the object was created during deserialization
-		_type = ctx.settings()[Serialization_Value_Type].toString();
 }
 
 void DraftItem::createProperties()
diff --git a/Grinder/image/ImageBuild.cpp b/Grinder/image/ImageBuild.cpp
index 6f8b5aa..ca0f987 100644
--- a/Grinder/image/ImageBuild.cpp
+++ b/Grinder/image/ImageBuild.cpp
@@ -106,25 +106,6 @@ void ImageBuild::serialize(SerializationContext& ctx) const
 
 void ImageBuild::deserialize(DeserializationContext& ctx)
 {
-	// Deserialize image references
-	if (ctx.getMode() == SerializationContext::Mode::ProjectSerialization)
-	{
-		std::vector<const ImageReference*> imageReferences;
-
-		for (auto imageRef : ctx.settings()[Serialization_Value_ImageReferences].toString().split(","))
-		{
-			auto imageRefIndex = imageRef.toInt();
-
-			if (imageRefIndex != -1)
-			{
-				if (auto imageRef = ctx.getImageReference(imageRefIndex))
-					imageReferences.push_back(imageRef);
-			}
-		}
-
-		_imageReferences = std::move(imageReferences);
-	}
-
 	// Deserialize all layers
 	if (ctx.beginGroup(LayerVector::Serialization_Group))
 	{
diff --git a/Grinder/pipeline/Block.cpp b/Grinder/pipeline/Block.cpp
index 922feed..afa154b 100644
--- a/Grinder/pipeline/Block.cpp
+++ b/Grinder/pipeline/Block.cpp
@@ -80,10 +80,6 @@ void Block::deserialize(DeserializationContext& ctx)
 {
 	PipelineItem::deserialize(ctx);
 
-	// Deserialize values
-	if (ctx.getMode() != DeserializationContext::Mode::ProjectSerialization)	// Already set when the object was created during deserialization
-		_type = ctx.settings()[Serialization_Value_Type].toString();
-
 	ctx.addBlock(ctx.settings()[Serialization_Value_Index].toInt(), this);
 
 	// Deserialize all ports
diff --git a/Grinder/pipeline/Port.cpp b/Grinder/pipeline/Port.cpp
index e82964a..3a9530e 100644
--- a/Grinder/pipeline/Port.cpp
+++ b/Grinder/pipeline/Port.cpp
@@ -227,9 +227,5 @@ void Port::deserialize(DeserializationContext& ctx)
 {
 	PipelineItem::deserialize(ctx);
 
-	// Deserialize values
-	if (ctx.getMode() != DeserializationContext::Mode::ProjectSerialization)	// Already set when the object was created during deserialization
-		_type = ctx.settings()[Serialization_Value_Type].toString();
-
 	ctx.addPort(ctx.settings()[Serialization_Value_Index].toInt(), this);
 }
diff --git a/Grinder/pipeline/blocks/InputBlock.cpp b/Grinder/pipeline/blocks/InputBlock.cpp
index e4a5095..5d3191c 100644
--- a/Grinder/pipeline/blocks/InputBlock.cpp
+++ b/Grinder/pipeline/blocks/InputBlock.cpp
@@ -5,6 +5,7 @@
 
 #include "Grinder.h"
 #include "InputBlock.h"
+#include "core/GrinderApplication.h"
 #include "engine/processors/InputProcessor.h"
 
 const BlockType InputBlock::type_value = BlockType::Input;
@@ -20,6 +21,24 @@ std::unique_ptr<ProcessorBase> InputBlock::createProcessor() const
 	return std::make_unique<InputProcessor>(this);
 }
 
+const ImageReference* InputBlock::resolveImageReference(const ImageReference* activeImageReference) const
+{
+	const ImageReference* currentImageRef = *imageReference();
+
+	// Make sure that the image reference really exists (just in case)
+	if (currentImageRef)
+	{
+		if (!std::any_of(grinder()->project().imageReferences().cbegin(), grinder()->project().imageReferences().cend(), [currentImageRef](const auto& imageRef) { return imageRef.get() == currentImageRef; }))
+			currentImageRef = nullptr;
+	}
+
+	// If no image reference has been set, use the currently active one
+	if (!currentImageRef)
+		currentImageRef = activeImageReference ? activeImageReference : grinder()->projectController().activeImageReference();
+
+	return currentImageRef;
+}
+
 void InputBlock::createProperties()
 {
 	Block::createProperties();
diff --git a/Grinder/pipeline/blocks/InputBlock.h b/Grinder/pipeline/blocks/InputBlock.h
index 5af8a97..9fbcab8 100644
--- a/Grinder/pipeline/blocks/InputBlock.h
+++ b/Grinder/pipeline/blocks/InputBlock.h
@@ -25,6 +25,8 @@ namespace grndr
 	public:
 		virtual std::unique_ptr<ProcessorBase> createProcessor() const override;
 
+		const ImageReference* resolveImageReference(const ImageReference* activeImageReference = nullptr) const;
+
 	public:
 		auto imageReference() { return dynamic_cast<ImageReferenceProperty*>(_imageReference.get()); }
 		auto imageReference() const { return dynamic_cast<ImageReferenceProperty*>(_imageReference.get()); }
diff --git a/Grinder/project/ImageReference.cpp b/Grinder/project/ImageReference.cpp
index 806c9c0..02b644d 100644
--- a/Grinder/project/ImageReference.cpp
+++ b/Grinder/project/ImageReference.cpp
@@ -84,10 +84,6 @@ void ImageReference::serialize(SerializationContext& ctx) const
 
 void ImageReference::deserialize(DeserializationContext& ctx)
 {
-	// Deserialize values
-	if (ctx.getMode() != DeserializationContext::Mode::ProjectSerialization)	// Already set when the object was created during deserialization
-		_imageFilePath = ctx.settings()[Serialization_Value_File].toString();
-
 	ctx.addImageReference(ctx.settings()[Serialization_Value_Index].toInt(), this);
 }
 
-- 
GitLab