Mon, 21 Sep 2020 19:48:18 +0300
added a color select dialog
24 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2020 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
0 | 19 | #pragma once |
2 | 20 | #include <QString> |
21 | #include <QVector> | |
22 | #include <QSet> | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
23 | #include <memory> |
3 | 24 | #include "basics.h" |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
25 | #include "utility.h" |
20 | 26 | #include "maths.h" |
55 | 27 | #include "geometry.h" |
63
f7dd937667a5
omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
28 | #include "functional.h" |
2 | 29 | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
30 | namespace settingGroups |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
31 | { |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
32 | // List of setting groups |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
33 | constexpr char mainwindow[] = "mainwindow"; |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
34 | } |
21 | 35 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
36 | namespace ldraw |
21 | 37 | { |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
38 | class Object; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
39 | |
21 | 40 | // Uniquely identifies a model body object |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
41 | template<typename T> |
21 | 42 | struct Id |
43 | { | |
46 | 44 | std::int32_t value; |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
45 | template<typename A, typename B> |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
46 | static constexpr bool is_base_or_base_of = std::disjunction_v<std::is_base_of<A, B>, std::is_base_of<B, A>>; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
47 | template<typename R, typename = std::enable_if_t<is_base_or_base_of<T, R>>> |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
48 | constexpr bool operator<(ldraw::Id<R> other) const |
26 | 49 | { |
50 | return this->value < other.value; | |
51 | } | |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
52 | friend constexpr unsigned int qHash(ldraw::Id<T> id) |
51 | 53 | { |
54 | return qHash(id.value); | |
55 | } | |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
56 | // Allow comparing ids as long as they are related |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
57 | template<typename R, typename = std::enable_if_t<is_base_or_base_of<T, R>>> |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
58 | friend bool operator==(ldraw::Id<T> one, ldraw::Id<R> other) |
51 | 59 | { |
60 | return one.value == other.value; | |
61 | } | |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
62 | // Allow upcasting |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
63 | template<typename R, typename = std::enable_if_t<std::is_base_of_v<R, T>>> |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
64 | constexpr operator Id<R>() const |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
65 | { |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
66 | return Id<R>{this->value}; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
67 | } |
21 | 68 | }; |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
69 | |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
70 | using id_t = Id<Object>; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
71 | using triangleid_t = Id<class Triangle>; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
72 | using quadrilateralid_t = Id<class Quadrilateral>; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
73 | using edgeid_t = Id<class EdgeLine>; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
74 | using conditionaledgeid_t = Id<class ConditionalEdge>; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
75 | using subfileid_t = Id<class SubfileReference>; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
76 | |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
77 | constexpr struct NullId |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
78 | { |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
79 | template<typename T> |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
80 | constexpr operator Id<T>() const |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
81 | { |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
82 | return Id<T>{0}; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
83 | } |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
84 | static constexpr decltype(ldraw::id_t::value) value = 0; |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
85 | } NULL_ID = {}; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
86 | |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
87 | template<typename T> |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
88 | inline bool operator==(Id<T> one, decltype(NULL_ID)) |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
89 | { |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
90 | return one.value == 0; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
91 | } |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
92 | |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
93 | template<typename T> |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
94 | inline bool operator<(Id<T> one, decltype(NULL_ID)) |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
95 | { |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
96 | return one.value < 0; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
97 | } |
21 | 98 | } |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
99 | |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
100 | constexpr std::size_t operator""_z(const unsigned long long int x) |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
101 | { |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
102 | return static_cast<std::size_t>(x); |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
103 | } |
26 | 104 | |
105 | inline QString operator""_q(const char* string, const unsigned long int length) | |
106 | { | |
107 | Q_UNUSED(length) | |
108 | return QString{string}; | |
109 | } | |
110 | ||
111 | inline QPointF pointToPointF(const QPoint& point) | |
112 | { | |
113 | return {static_cast<qreal>(point.x()), static_cast<qreal>(point.y())}; | |
114 | } | |
115 | ||
116 | inline QPoint pointFToPoint(const QPointF& point) | |
117 | { | |
118 | return {static_cast<int>(std::round(point.x())), static_cast<int>(std::round(point.y()))}; | |
119 | } | |
120 | ||
121 | /** | |
122 | * \brief Hints to the specified vector that a certain amount of new elements are going to be added. | |
123 | * \param vector vector to consider | |
124 | * \param amount amount of new elements to expect | |
125 | */ | |
126 | template<typename T> | |
127 | void reserveMore(std::vector<T>& vector, std::size_t amount) | |
128 | { | |
129 | vector.reserve(vector.size() + amount); | |
130 | } | |
64
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
131 | |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
132 | inline QString vectorToString(const glm::vec2& vec) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
133 | { |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
134 | return "(%1, %2)"_q |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
135 | .arg(toDouble(vec.x)) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
136 | .arg(toDouble(vec.y)); |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
137 | } |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
138 | |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
139 | inline QString vectorToString(const glm::vec3& vec) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
140 | { |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
141 | return "(%1, %2, %3)"_q |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
142 | .arg(toDouble(vec.x)) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
143 | .arg(toDouble(vec.y)) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
144 | .arg(toDouble(vec.z)); |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
145 | } |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
146 | |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
147 | inline QString vectorToString(const glm::vec4& vec) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
148 | { |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
149 | return "(%1, %2, %3, %4)"_q |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
150 | .arg(toDouble(vec.x)) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
151 | .arg(toDouble(vec.y)) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
152 | .arg(toDouble(vec.z)) |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
153 | .arg(toDouble(vec.w)); |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
154 | } |