src/linetypes/subfilereference.cpp

changeset 200
ca23936b455b
parent 199
6988973515d2
child 201
5d201ee4a9c3
--- a/src/linetypes/subfilereference.cpp	Wed May 25 20:36:34 2022 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,128 +0,0 @@
-#include "subfilereference.h"
-#include "documentmanager.h"
-#include "invert.h"
-#include "polygoncache.h"
-
-ldraw::SubfileReference::SubfileReference
-(
-	const glm::mat4& transformation,
-	const QString& referenceName,
-	const Color color
-) :
-	CompoundObject{transformation, color},
-	referenceName{referenceName}
-{
-}
-
-QVariant ldraw::SubfileReference::getProperty(Property property) const
-{
-	switch (property)
-	{
-	case Property::ReferenceName:
-		return this->referenceName;
-	default:
-		return CompoundObject::getProperty(property);
-	}
-}
-
-void ldraw::SubfileReference::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
-{
-	LDRAW_OBJECT_HANDLE_SET_PROPERTY(ReferenceName, {this->referenceName = value;});
-	ldraw::CompoundObject::setProperty(result, pair);
-}
-
-QString ldraw::SubfileReference::textRepresentation() const
-{
-	return this->referenceName + " " + utility::vertexToStringParens(this->position());
-}
-
-void ldraw::SubfileReference::getPolygons
-(
-	std::vector<gl::Polygon>& polygons,
-	GetPolygonsContext* context
-) const
-{
-	Model* dependency = this->resolve(context->modelId, context->documents);
-	PolygonCache* cache = nullptr;
-	if (dependency != nullptr)
-	{
-		const auto dependencyModelId = context->documents->findIdForModel(dependency);
-		if (dependencyModelId.has_value())
-		{
-			cache = context->documents->getPolygonCacheForModel(dependencyModelId.value());
-		}
-	}
-	if (cache != nullptr)
-	{
-		const bool needInverting = glm::determinant(this->transformation) < 0;
-		const std::vector<gl::Polygon> modelPolygons = getCachedPolygons(
-			cache,
-			dependency,
-			context->documents);
-		polygons.reserve(polygons.size() + modelPolygons.size());
-		for (gl::Polygon polygon : modelPolygons)
-		{
-			for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1)
-			{
-				glm::vec4 vertex {polygon.vertices[i], 1};
-				vertex = this->transformation * vertex;
-				polygon.vertices[i] = vertex;
-			}
-			if (needInverting != this->isInverted)
-			{
-				gl::invert(polygon);
-			}
-			if (polygon.color == ldraw::MAIN_COLOR)
-			{
-				polygon.color = this->colorIndex;
-			}
-			polygon.id = this->id;
-			polygons.push_back(polygon);
-		}
-	}
-}
-
-Model* ldraw::SubfileReference::resolve(const ModelId callingModelId, DocumentManager* documents) const
-{
-	return documents->findDependencyByName(callingModelId, this->referenceName);
-}
-
-ldraw::Object::Type ldraw::SubfileReference::typeIdentifier() const
-{
-	return Type::SubfileReference;
-}
-
-QDataStream& ldraw::SubfileReference::serialize(QDataStream &stream) const
-{
-	return CompoundObject::serialize(stream) << this->referenceName;
-}
-
-QDataStream& ldraw::SubfileReference::deserialize(QDataStream &stream)
-{
-	return CompoundObject::deserialize(stream) >> this->referenceName;
-}
-
-QString ldraw::SubfileReference::toLDrawCode() const
-{
-	QString result;
-	if (this->isInverted)
-	{
-		result += "0 BFC INVERTNEXT\r\n";
-	}
-	result += utility::format(
-		"1 %1 %2 %3",
-		this->colorIndex.index,
-		this->transformToBareString(),
-		this->referenceName);
-	return result;
-}
-
-QString ldraw::SubfileReference::iconName() const
-{
-	return ":/icons/linetype-subfile.png";
-}
-
-QString ldraw::SubfileReference::typeName() const
-{
-	return QObject::tr("subfile reference");
-}

mercurial