Sat, 24 Mar 2018 13:53:56 +0200
removed unused include
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 |
1326 | 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 |
1039 | 20 | #include <QIODevice> |
1092
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
21 | #include <QGenericMatrix> |
1244 | 22 | #include <QModelIndex> |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #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
|
24 | #include "colors.h" |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1095
diff
changeset
|
25 | #include "types/matrix.h" |
1316 | 26 | #include "types/vertex.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
794 | 28 | // Converts a given value into a string that can be retrieved with text(). |
29 | // Used as the argument type to the formatting functions, hence its name. | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | class StringFormatArg |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | { |
794 | 32 | public: |
33 | StringFormatArg (const QString& a) : m_text (a) {} | |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
34 | StringFormatArg (char a) : m_text (a) {} |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
35 | StringFormatArg (uchar a) : m_text (a) {} |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
36 | StringFormatArg (QChar a) : m_text (a) {} |
794 | 37 | StringFormatArg (int a) : m_text (QString::number (a)) {} |
38 | StringFormatArg (long a) : m_text (QString::number (a)) {} | |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
39 | StringFormatArg (float a) : m_text (QString::number (a)) {} |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
40 | StringFormatArg (double a) : m_text (QString::number (a)) {} |
794 | 41 | StringFormatArg (const Vertex& a) : m_text (a.toString()) {} |
42 | StringFormatArg (const Matrix& a) : m_text (a.toString()) {} | |
43 | StringFormatArg (const char* a) : m_text (a) {} | |
806
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
795
diff
changeset
|
44 | StringFormatArg (LDColor a) : m_text (a.indexString()) {} |
794 | 45 | |
46 | StringFormatArg (const void* a) | |
47 | { | |
48 | m_text.sprintf ("%p", a); | |
49 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
794 | 51 | template<typename T> |
1058
695edd4f0411
Cleaned up crash catcher, fixed missing <math.h> include
Teemu Piippo <teemu@hecknology.net>
parents:
1039
diff
changeset
|
52 | StringFormatArg (const QVector<T>& a) |
794 | 53 | { |
54 | m_text = "{"; | |
55 | ||
56 | for (const T& it : a) | |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
57 | { |
794 | 58 | if (&it != &a.first()) |
59 | m_text += ", "; | |
60 | ||
61 | StringFormatArg arg (it); | |
62 | m_text += arg.text(); | |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
63 | } |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
64 | |
794 | 65 | m_text += "}"; |
66 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
1092
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
68 | template<int Columns, int Rows, typename Type> |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
69 | StringFormatArg(const QGenericMatrix<Columns, Rows, Type>& matrix) |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
70 | { |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
71 | m_text = "{"; |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
72 | for (int row = 0; row < Rows; ++row) |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
73 | { |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
74 | if (row > 0) |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
75 | m_text += ", "; |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
76 | |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
77 | m_text += "{"; |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
78 | |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
79 | for (int column = 0; column < Rows; ++column) |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
80 | { |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
81 | if (column > 0) |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
82 | m_text += ", "; |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
83 | |
1095
cb58a160bed3
- Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents:
1092
diff
changeset
|
84 | m_text += StringFormatArg {matrix(row, column)}.text(); |
1092
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
85 | } |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
86 | |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
87 | m_text += "}"; |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
88 | } |
1095
cb58a160bed3
- Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents:
1092
diff
changeset
|
89 | m_text += "}"; |
1092
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
90 | } |
7a50a7f6b492
Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
91 | |
1244 | 92 | StringFormatArg(const QModelIndex& index) |
93 | { | |
94 | m_text = QString("{%1, %2}").arg(index.row(), index.column()); | |
95 | } | |
96 | ||
794 | 97 | inline QString text() const |
98 | { | |
99 | return m_text; | |
100 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
794 | 102 | private: |
103 | QString m_text; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
106 | |
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
107 | // Helper function for format() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | template<typename Arg1, typename... Rest> |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
109 | void formatHelper (QString& str, Arg1 arg1, Rest... rest) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | str = str.arg (StringFormatArg (arg1).text()); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | formatHelper (str, rest...); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
115 | |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
116 | static void formatHelper (QString& str) __attribute__ ((unused)); |
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
117 | static void formatHelper (QString& str) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | (void) str; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
122 | |
794 | 123 | // Format the message with the given args. |
124 | // | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
125 | // The formatting ultimately uses String's arg() method to actually format the args so the format string should be |
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
126 | // prepared accordingly, with %1 referring to the first arg, %2 to the second, etc. |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | template<typename... Args> |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
128 | QString format (QString fmtstr, Args... args) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | formatHelper (fmtstr, args...); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | return fmtstr; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | template<typename... Args> |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
135 | void fprint (FILE* fp, QString fmtstr, Args... args) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | formatHelper (fmtstr, args...); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | fprintf (fp, "%s", qPrintable (fmtstr)); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
141 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | template<typename... Args> |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
143 | void fprint (QIODevice& dev, QString fmtstr, Args... args) |
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 | formatHelper (fmtstr, args...); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | dev.write (fmtstr.toUtf8()); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | } |