src/main.h

Fri, 06 Mar 2020 20:13:10 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 06 Mar 2020 20:13:10 +0200
changeset 70
f21b800b02a4
parent 64
f99d52b1646b
child 73
97df974b5ed5
permissions
-rw-r--r--

Added axes rendering

/*
 *  LDForge: LDraw parts authoring CAD
 *  Copyright (C) 2013 - 2020 Teemu Piippo
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include <QString>
#include <QVector>
#include <QSet>
#include <memory>
#include "basics.h"
#include "utility.h"
#include "maths.h"
#include "geometry.h"
#include "functional.h"

namespace settingGroups
{
	// List of setting groups
	constexpr char mainwindow[] = "mainwindow";
}

namespace ldraw
{
	// Uniquely identifies a model body object
	struct Id
	{
		std::int32_t value;
		constexpr bool operator<(ldraw::Id other) const
		{
			return this->value < other.value;
		}
		friend constexpr unsigned int qHash(ldraw::Id id)
		{
			return qHash(id.value);
		}
		friend bool operator==(ldraw::Id one, ldraw::Id other)
		{
			return one.value == other.value;
		}
	};
	using id_t = Id;
	constexpr id_t NULL_ID = id_t{0};
}

constexpr std::size_t operator""_z(const unsigned long long int x)
{
	return static_cast<std::size_t>(x);
}

inline QString operator""_q(const char* string, const unsigned long int length)
{
	Q_UNUSED(length)
	return QString{string};
}

inline QPointF pointToPointF(const QPoint& point)
{
	return {static_cast<qreal>(point.x()), static_cast<qreal>(point.y())};
}

inline QPoint pointFToPoint(const QPointF& point)
{
	return {static_cast<int>(std::round(point.x())), static_cast<int>(std::round(point.y()))};
}

/**
 * \brief Hints to the specified vector that a certain amount of new elements are going to be added.
 * \param vector vector to consider
 * \param amount amount of new elements to expect
 */
template<typename T>
void reserveMore(std::vector<T>& vector, std::size_t amount)
{
	vector.reserve(vector.size() + amount);
}

inline QString vectorToString(const glm::vec2& vec)
{
	return "(%1, %2)"_q
		.arg(toDouble(vec.x))
		.arg(toDouble(vec.y));
}

inline QString vectorToString(const glm::vec3& vec)
{
	return "(%1, %2, %3)"_q
		.arg(toDouble(vec.x))
		.arg(toDouble(vec.y))
		.arg(toDouble(vec.z));
}

inline QString vectorToString(const glm::vec4& vec)
{
	return "(%1, %2, %3, %4)"_q
		.arg(toDouble(vec.x))
		.arg(toDouble(vec.y))
		.arg(toDouble(vec.z))
		.arg(toDouble(vec.w));
}

mercurial