Mon, 13 Jan 2014 10:07:39 +0200
- refactoring
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
600
209e3f1f7b2c
- updated copyright year. Best wishes for 2014!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
590
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
4 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
8 | * (at your option) any later version. |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
9 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
14 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
19 | #ifndef LDFORGE_TYPES_H |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
20 | #define LDFORGE_TYPES_H |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
22 | #include <QString> |
290
be0c367e7420
Added primitive scanning, replaced parts list in subfile add dialog with it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
288
diff
changeset
|
23 | #include <QObject> |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
24 | #include <QStringList> |
622 | 25 | #include <QMetaType> |
26 | #include "property.h" | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
28 | class LDObject; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
29 | class QFile; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
30 | class QTextStream; |
271
d5ec224c1879
Laid down the foundations of the new history system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
31 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
32 | using int8 = qint8; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
33 | using int16 = qint16; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
34 | using int32 = qint32; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
35 | using int64 = qint64; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
36 | using uint8 = quint8; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
37 | using uint16 = quint16; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
38 | using uint32 = quint32; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
39 | using uint64 = quint64; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
41 | template<class T> |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
42 | using initlist = std::initializer_list<T>; |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
43 | |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
44 | template<class T, class R> |
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
45 | using pair = std::pair<T, R>; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
47 | enum Axis |
603 | 48 | { |
49 | X, | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
50 | Y, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
51 | Z |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
52 | }; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | // ============================================================================= |
617
f5059d144438
- added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents:
610
diff
changeset
|
55 | // |
f5059d144438
- added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents:
610
diff
changeset
|
56 | class LDObject; |
f5059d144438
- added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents:
610
diff
changeset
|
57 | using LDObjectList = QList<LDObject*>; |
f5059d144438
- added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents:
610
diff
changeset
|
58 | |
f5059d144438
- added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents:
610
diff
changeset
|
59 | // ============================================================================= |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | // matrix |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
63 | // |
274
d232fe4d88a6
Reworked properties a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
273
diff
changeset
|
64 | // A mathematical 3 x 3 matrix |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // ============================================================================= |
604 | 66 | class Matrix |
603 | 67 | { |
68 | public: | |
604 | 69 | Matrix() {} |
70 | Matrix (initlist<double> vals); | |
71 | Matrix (double fillval); | |
72 | Matrix (double vals[]); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
73 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
74 | double getDeterminant() const; |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
75 | Matrix mult (const Matrix& other) const; |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
76 | void puts() const; |
622 | 77 | QString toString() const; |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
78 | void zero(); |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
79 | Matrix& operator= (const Matrix& other); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
80 | |
494 | 81 | inline double& val (int idx) |
603 | 82 | { |
83 | return m_vals[idx]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
84 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
494 | 86 | inline const double& val (int idx) const |
603 | 87 | { |
88 | return m_vals[idx]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
89 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
90 | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
91 | inline Matrix operator* (const Matrix& other) const |
603 | 92 | { |
93 | return mult (other); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
94 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
95 | |
494 | 96 | inline double& operator[] (int idx) |
603 | 97 | { |
98 | return val (idx); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
99 | } |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
100 | |
494 | 101 | inline const double& operator[] (int idx) const |
603 | 102 | { |
103 | return val (idx); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
104 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
105 | |
604 | 106 | bool operator== (const Matrix& other) const; |
522
afa691788bdb
- migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
513
diff
changeset
|
107 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
108 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
109 | double m_vals[9]; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | // ============================================================================= |
604 | 115 | // Vertex |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
116 | // |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | // Vertex class, contains a single point in 3D space. Not to be confused with |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | // LDVertex, which is a vertex used in an LDraw part file. |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | // ============================================================================= |
604 | 120 | class Vertex |
603 | 121 | { |
122 | public: | |
604 | 123 | Vertex() {} |
124 | Vertex (double x, double y, double z); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
125 | |
604 | 126 | double distanceTo (const Vertex& other) const; |
127 | Vertex midpoint (const Vertex& other); | |
128 | void move (const Vertex& other); | |
622 | 129 | QString toString (bool mangled) const; |
130 | void transform (const Matrix& matr, const Vertex& pos); | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
131 | |
604 | 132 | Vertex& operator+= (const Vertex& other); |
133 | Vertex operator+ (const Vertex& other) const; | |
134 | Vertex operator/ (const double d) const; | |
135 | Vertex& operator/= (const double d); | |
136 | bool operator== (const Vertex& other) const; | |
137 | bool operator!= (const Vertex& other) const; | |
138 | Vertex operator-() const; | |
139 | int operator< (const Vertex& other) const; | |
622 | 140 | |
141 | inline double& operator[] (const Axis ax) | |
142 | { | |
143 | return getCoordinate ((int) ax); | |
144 | } | |
145 | ||
146 | inline const double& operator[] (const Axis ax) const | |
147 | { | |
148 | return getCoordinate ((int) ax); | |
149 | } | |
494 | 150 | |
622 | 151 | inline double& operator[] (const int ax) |
152 | { | |
153 | return getCoordinate (ax); | |
154 | } | |
155 | ||
156 | inline const double& operator[] (const int ax) const | |
157 | { | |
158 | return getCoordinate (ax); | |
159 | } | |
160 | ||
161 | inline double& getCoordinate (int n) | |
603 | 162 | { |
163 | return m_coords[n]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
164 | } |
494 | 165 | |
622 | 166 | inline const double& getCoordinate (int n) const |
603 | 167 | { |
168 | return m_coords[n]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
169 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
170 | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
171 | inline double& x() |
603 | 172 | { |
173 | return m_coords[X]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
174 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
175 | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
176 | inline const double& x() const |
603 | 177 | { |
178 | return m_coords[X]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
179 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
180 | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
181 | inline double& y() |
603 | 182 | { |
183 | return m_coords[Y]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
184 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
185 | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
186 | inline const double& y() const |
603 | 187 | { |
188 | return m_coords[Y]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
189 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
190 | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
191 | inline double& z() |
603 | 192 | { |
193 | return m_coords[Z]; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
194 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
195 | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
196 | inline const double& z() const |
603 | 197 | { |
198 | return m_coords[Z]; | |
574
10874674fe30
- line lengths are now displayed when drawing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
199 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
200 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
201 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
202 | double m_coords[3]; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | |
622 | 205 | Q_DECLARE_METATYPE (Vertex) |
206 | ||
251
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
207 | // ============================================================================= |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
208 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
209 | // ============================================================================= |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
210 | // StringFormatArg |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
211 | // |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
212 | // Converts a given value into a string that can be retrieved with ::value(). |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
213 | // Used as the argument type to the formatting functions, hence its name. |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
214 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
215 | class StringFormatArg |
603 | 216 | { |
217 | public: | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
218 | StringFormatArg (const QString& a) : m_val (a) {} |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
219 | StringFormatArg (const char& a) : m_val (a) {} |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
220 | StringFormatArg (const uchar& a) : m_val (a) {} |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
221 | StringFormatArg (const QChar& a) : m_val (a) {} |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
222 | StringFormatArg (int a) : m_val (QString::number (a)) {} |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
223 | StringFormatArg (const float& a) : m_val (QString::number (a)) {} |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
224 | StringFormatArg (const double& a) : m_val (QString::number (a)) {} |
622 | 225 | StringFormatArg (const Vertex& a) : m_val (a.toString (false)) {} |
226 | StringFormatArg (const Matrix& a) : m_val (a.toString()) {} | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
227 | StringFormatArg (const char* a) : m_val (a) {} |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
228 | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
229 | StringFormatArg (const void* a) |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
230 | { |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
231 | m_val.sprintf ("%p", a); |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
232 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
233 | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
234 | template<class T> StringFormatArg (const QList<T>& a) |
603 | 235 | { |
236 | m_val = "{ "; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
237 | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
238 | for (const T& it : a) |
603 | 239 | { |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
240 | if (&it != &a.first()) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
241 | m_val += ", "; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
242 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
243 | StringFormatArg arg (it); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
244 | m_val += arg.value(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
245 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
246 | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
247 | if (!a.isEmpty()) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
248 | m_val += " "; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
249 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
250 | m_val += "}"; |
297
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
293
diff
changeset
|
251 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
252 | |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
253 | inline QString value() const |
603 | 254 | { |
255 | return m_val; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
256 | } |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
257 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
258 | private: |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
259 | QString m_val; |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
260 | }; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
261 | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
262 | // ============================================================================= |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
263 | // LDBoundingBox |
380
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
264 | // |
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
265 | // The bounding box is the box that encompasses a given set of objects. |
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
266 | // v0 is the minimum vertex, v1 is the maximum vertex. |
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
267 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
268 | class LDBoundingBox |
603 | 269 | { |
610
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
270 | PROPERTY (private, bool, Empty, BOOL_OPS, STOCK_WRITE) |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
271 | PROPERTY (private, Vertex, Vertex0, NO_OPS, STOCK_WRITE) |
f8244301110d
- did stuff to types, fixed primitive listing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
609
diff
changeset
|
272 | PROPERTY (private, Vertex, Vertex1, NO_OPS, STOCK_WRITE) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
273 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
274 | public: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
275 | LDBoundingBox(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
276 | void reset(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
277 | void calculate(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
278 | double size() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
279 | void calcObject (LDObject* obj); |
604 | 280 | void calcVertex (const Vertex& v); |
281 | Vertex center() const; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
282 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
283 | LDBoundingBox& operator<< (LDObject* obj); |
604 | 284 | LDBoundingBox& operator<< (const Vertex& v); |
380
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
285 | }; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
286 | |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
287 | // Formatter function |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
288 | QString DoFormat (QList<StringFormatArg> args); |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
289 | |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
290 | // printf replacement |
609
a8dc74a809c6
- removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
291 | void doPrint (QFile& f, QList<StringFormatArg> args); |
a8dc74a809c6
- removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
292 | void doPrint (FILE* fp, QList<StringFormatArg> args); |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
293 | |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
294 | // log() - universal access to the message log. Defined here so that I don't have |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
295 | // to include messagelog.h here and recompile everything every time that file changes. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
296 | void DoLog (std::initializer_list<StringFormatArg> args); |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
297 | |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
298 | // Macros to access these functions |
513
29eb671b34f6
Added a crash catcher which trigger under Linux. It calls GDB and tries to get a backtrace. Also integrated assertion failure handling to this new system. Removed the print() function in the process (because the new bomb box uses a text edit and QTextDocuments's print method clashes with the macro and I figured it was a good idea to rid it anyway) and replaced all calls with log().
Santeri Piippo <crimsondusk64@gmail.com>
parents:
504
diff
changeset
|
299 | # ifndef IN_IDE_PARSER |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
300 | #define fmt(...) DoFormat ({__VA_ARGS__}) |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
301 | # define fprint(F, ...) doPrint (F, {__VA_ARGS__}) |
513
29eb671b34f6
Added a crash catcher which trigger under Linux. It calls GDB and tries to get a backtrace. Also integrated assertion failure handling to this new system. Removed the print() function in the process (because the new bomb box uses a text edit and QTextDocuments's print method clashes with the macro and I figured it was a good idea to rid it anyway) and replaced all calls with log().
Santeri Piippo <crimsondusk64@gmail.com>
parents:
504
diff
changeset
|
302 | # define log(...) DoLog({ __VA_ARGS__ }) |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
303 | #else |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
304 | QString fmt (const char* fmtstr, ...); |
609
a8dc74a809c6
- removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
305 | void fprint (QFile& f, const char* fmtstr, ...); |
a8dc74a809c6
- removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
306 | void fprint (FILE* fp, const char* fmtstr, ...); |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
307 | void log (const char* fmtstr, ...); |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
308 | #endif |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
309 | |
604 | 310 | extern const Vertex g_origin; // Vertex at (0, 0, 0) |
311 | extern const Matrix g_identity; // Identity matrix | |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
312 | |
456 | 313 | static const double pi = 3.14159265358979323846; |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
314 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
522
diff
changeset
|
315 | #endif // LDFORGE_TYPES_H |