Thu, 11 Jan 2018 15:09:44 +0200
begin rendering rework
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1222 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #pragma once |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "basics.h" |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
21 | #include "colors.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | |
1221 | 23 | extern void printToLog(const QString& msg); |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
24 | |
1221 | 25 | |
26 | inline const QString& toString(const QString& text) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | { |
1221 | 28 | return text; |
29 | } | |
30 | ||
794 | 31 | |
1221 | 32 | inline QString toString(char character) |
33 | { | |
34 | return QString {character}; | |
35 | } | |
36 | ||
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
1221 | 38 | inline QString toString(unsigned char character) |
39 | { | |
40 | return QString {character}; | |
41 | } | |
794 | 42 | |
43 | ||
1221 | 44 | inline QString toString(QChar character) |
45 | { | |
46 | return character; | |
47 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
1221 | 50 | inline QString toString(int value) |
51 | { | |
52 | return QString::number(value); | |
53 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
55 | |
1221 | 56 | inline QString toString(short int value) |
57 | { | |
58 | return QString::number(value); | |
59 | } | |
60 | ||
61 | ||
62 | inline QString toString(long int value) | |
63 | { | |
64 | return QString::number(value); | |
65 | } | |
66 | ||
67 | ||
68 | inline QString toString(unsigned int value) | |
69 | { | |
70 | return QString::number(value); | |
71 | } | |
72 | ||
73 | ||
74 | inline QString toString(unsigned long int value) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | { |
1221 | 76 | return QString::number(value); |
77 | } | |
78 | ||
79 | ||
80 | inline QString toString(unsigned short int value) | |
81 | { | |
82 | return QString::number(value); | |
83 | } | |
84 | ||
85 | ||
86 | inline QString toString(float value) | |
87 | { | |
88 | return QString::number(value); | |
89 | } | |
90 | ||
91 | ||
92 | inline QString toString(double value) | |
93 | { | |
94 | return QString::number(value); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
97 | |
1221 | 98 | inline QString toString(const Vertex& position) |
99 | { | |
100 | return position.toString(); | |
101 | } | |
102 | ||
103 | ||
104 | inline QString toString(const Matrix& transformation) | |
105 | { | |
106 | return transformation.toString(); | |
107 | } | |
108 | ||
109 | ||
110 | inline QString toString(const char* text) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | { |
1221 | 112 | return text; |
113 | } | |
114 | ||
115 | ||
116 | inline QString toString(LDColor color) | |
117 | { | |
118 | return color.indexString(); | |
119 | } | |
120 | ||
121 | ||
122 | inline QString toString(const void* pointer) | |
123 | { | |
124 | QString result; | |
125 | result.sprintf("%p", pointer); | |
126 | return result; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
129 | |
1221 | 130 | template<typename T, int N> |
131 | QString toString(T(&array)[N]) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | { |
1221 | 133 | QString rep = "{"; |
134 | ||
135 | for (int i = 0; i < N; ++i) | |
136 | { | |
137 | if (i > 0) | |
138 | rep += ", "; | |
139 | rep += toString(array[i]); | |
140 | } | |
141 | ||
142 | rep += "}"; | |
143 | return rep; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | |
1221 | 147 | template<typename T> |
148 | QString toString(const QList<T>& list) | |
149 | { | |
150 | QString result = "{"; | |
151 | ||
152 | for (const T& element : list) | |
153 | { | |
154 | if (&element != &list.first()) | |
155 | result += ", "; | |
156 | ||
157 | result += toString(element); | |
158 | } | |
159 | ||
160 | result += "}"; | |
161 | return result; | |
162 | } | |
163 | ||
164 | ||
1231 | 165 | inline QString toString(const QSize& size) |
166 | { | |
167 | return toString(size.width()) + " × " + toString(size.height()); | |
168 | } | |
169 | ||
170 | ||
1221 | 171 | /* |
172 | * Formats the message with the given args using QString::arg(). | |
173 | */ | |
174 | template<typename Arg1, typename... Rest> | |
175 | QString format(const QString& string, Arg1 arg1, Rest&&... rest) | |
176 | { | |
177 | return format(string.arg(toString(arg1)), rest...); | |
178 | } | |
179 | ||
180 | ||
181 | template<typename... Rest> | |
182 | const QString& format(const QString& string) | |
183 | { | |
184 | return string; | |
185 | } | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
186 | |
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
187 | |
794 | 188 | // Format and print the given args to the message log. |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | template<typename... Args> |
1221 | 190 | void print(const QString& formatString, Args&&... args) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | { |
1221 | 192 | printToLog(format(formatString, args...)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | |
1221 | 195 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | template<typename... Args> |
1221 | 197 | void fprint(FILE* filePointer, const QString& formatString, Args&&... args) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | { |
1221 | 199 | fprintf(filePointer, "%s", qPrintable(format(formatString, args...))); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
202 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | template<typename... Args> |
1221 | 204 | void fprint(QIODevice& device, const QString& formatString, Args&&... args) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | { |
1221 | 206 | device.write(format(formatString, args...).toUtf8()); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
209 | |
794 | 210 | // Exactly like print() except no-op in release builds. |
1221 | 211 | #ifndef RELEASE |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | template<typename... Args> |
1221 | 213 | void dprint(const QString& formatString, Args&&... args) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | { |
1221 | 215 | print(formatString, args...); |
794 | 216 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | #else |
1221 | 218 | template<typename... Args> |
1217 | 219 | void dprint(QString, Args...) {} |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | #endif |