Sat, 05 Oct 2013 12:51:13 +0300
a bit more cleanup
297
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
1 | /* |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
358 | 4 | * |
297
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
8 | * (at your option) any later version. |
358 | 9 | * |
297
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
13 | * GNU General Public License for more details. |
358 | 14 | * |
297
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
17 | */ |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
18 | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QDir> |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QThread> |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
21 | #include <QRegExp> |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
22 | #include <QFileDialog> |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "file.h" |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "gui.h" |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "primitives.h" |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
26 | #include "ui_makeprim.h" |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
27 | #include "misc.h" |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
377
diff
changeset
|
28 | #include "colors.h" |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
29 | #include "moc_primitives.cpp" |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
31 | List<PrimitiveCategory> g_PrimitiveCategories; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
32 | List<Primitive> g_primitives; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
33 | static PrimitiveLister* g_activePrimLister = null; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
34 | static bool g_primListerMutex = false; |
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:
436
diff
changeset
|
35 | static const str g_Other = PrimitiveLister::tr ("Other"); |
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:
436
diff
changeset
|
36 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
37 | static const str g_radialNameRoots[] = |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
38 | { "edge", |
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:
436
diff
changeset
|
39 | "cyli", |
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:
436
diff
changeset
|
40 | "disc", |
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:
436
diff
changeset
|
41 | "ndis", |
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:
436
diff
changeset
|
42 | "ring", |
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:
436
diff
changeset
|
43 | "con" |
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:
436
diff
changeset
|
44 | }; |
321
48e429bfd58c
Apply tr() for possible future translations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
319
diff
changeset
|
45 | |
358 | 46 | static void populateCategories(); |
47 | static void loadPrimitiveCatgories(); | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
48 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
49 | // ============================================================================= |
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:
436
diff
changeset
|
50 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
51 | void loadPrimitives() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
52 | { print ("Loading primitives...\n"); |
358 | 53 | loadPrimitiveCatgories(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
54 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
55 | // Try to load prims.cfg |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
56 | File conf (Config::filepath ("prims.cfg"), File::Read); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
57 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
58 | if (!conf) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
59 | { // No prims.cfg, build it |
358 | 60 | PrimitiveLister::start(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
61 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
62 | else |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
63 | { // Read primitives from prims.cfg |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
64 | for (str line : conf) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
65 | { int space = line.indexOf (" "); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
66 | |
398 | 67 | if (space == -1) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
68 | continue; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
69 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
70 | Primitive info; |
398 | 71 | info.name = line.left (space); |
72 | info.title = line.mid (space + 1); | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
73 | g_primitives << info; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
74 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
75 | |
358 | 76 | populateCategories(); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
77 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
78 | } |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | // ============================================================================= |
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:
436
diff
changeset
|
81 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
82 | static void recursiveGetFilenames (QDir dir, List<str>& fnames) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
83 | { QFileInfoList flist = dir.entryInfoList(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
84 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
85 | for (const QFileInfo & info : flist) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
86 | { if (info.fileName() == "." || info.fileName() == "..") |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | continue; // skip . and .. |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
88 | |
398 | 89 | if (info.isDir()) |
90 | recursiveGetFilenames (QDir (info.absoluteFilePath()), fnames); | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | else |
358 | 92 | fnames << info.absoluteFilePath(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
96 | // ============================================================================= |
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:
436
diff
changeset
|
97 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
98 | void PrimitiveLister::work() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
99 | { g_activePrimLister = this; |
358 | 100 | m_prims.clear(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
101 | |
398 | 102 | QDir dir (LDPaths::prims()); |
358 | 103 | ulong baselen = dir.absolutePath().length(); |
104 | ulong i = 0; | |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
105 | List<str> fnames; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
106 | |
398 | 107 | assert (dir.exists()); |
108 | recursiveGetFilenames (dir, fnames); | |
109 | emit starting (fnames.size()); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
110 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
111 | for (str fname : fnames) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
112 | { File f (fname, File::Read); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
113 | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | Primitive info; |
398 | 115 | info.name = fname.mid (baselen + 1); // make full path relative |
116 | info.name.replace ('/', '\\'); // use DOS backslashes, they're expected | |
358 | 117 | info.cat = null; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
118 | |
398 | 119 | if (!f.readLine (info.title)) |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | info.title = ""; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
121 | |
358 | 122 | info.title = info.title.simplified(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
123 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
124 | if (info.title[0] == '0') |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
125 | { info.title.remove (0, 1); // remove 0 |
358 | 126 | info.title = info.title.simplified(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
128 | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | m_prims << info; |
398 | 130 | emit update (++i); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
132 | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | // Save to a config file |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
134 | File conf (Config::filepath ("prims.cfg"), File::Write); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
135 | |
398 | 136 | for (Primitive & info : m_prims) |
137 | fprint (conf, "%1 %2\n", info.name, info.title); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
138 | |
358 | 139 | conf.close(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
140 | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | g_primListerMutex = true; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
142 | g_primitives = m_prims; |
358 | 143 | populateCategories(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | g_primListerMutex = false; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | g_activePrimLister = null; |
358 | 146 | emit workDone(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
149 | // ============================================================================= |
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:
436
diff
changeset
|
150 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
151 | void PrimitiveLister::start() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
152 | { if (g_activePrimLister) |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
154 | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | PrimitiveLister* lister = new PrimitiveLister; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | QThread* listerThread = new QThread; |
398 | 157 | lister->moveToThread (listerThread); |
158 | connect (lister, SIGNAL (starting (ulong)), g_win, SLOT (primitiveLoaderStart (ulong))); | |
159 | connect (lister, SIGNAL (update (ulong)), g_win, SLOT (primitiveLoaderUpdate (ulong))); | |
160 | connect (lister, SIGNAL (workDone()), g_win, SLOT (primitiveLoaderEnd())); | |
161 | connect (listerThread, SIGNAL (started()), lister, SLOT (work())); | |
162 | connect (listerThread, SIGNAL (finished()), lister, SLOT (deleteLater())); | |
358 | 163 | listerThread->start(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | |
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:
436
diff
changeset
|
166 | // ============================================================================= |
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:
436
diff
changeset
|
167 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
168 | static PrimitiveCategory* findCategory (str name) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
169 | { for (PrimitiveCategory& cat : g_PrimitiveCategories) |
398 | 170 | if (cat.name() == name) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
171 | return &cat; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
172 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
173 | return null; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
174 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
175 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
176 | // ============================================================================= |
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:
436
diff
changeset
|
177 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
178 | static void populateCategories() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
179 | { for (PrimitiveCategory & cat : g_PrimitiveCategories) |
358 | 180 | cat.prims.clear(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
181 | |
398 | 182 | PrimitiveCategory* unmatched = findCategory (g_Other); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
183 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
184 | if (!unmatched) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
185 | { // Shouldn't happen.. but catch it anyway. |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
186 | PrimitiveCategory cat; |
398 | 187 | cat.setName (g_Other); |
188 | unmatched = & (g_PrimitiveCategories << cat); | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
190 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
191 | for (Primitive& prim : g_primitives) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
192 | { bool matched = false; |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
193 | prim.cat = null; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
194 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
195 | // Go over the categories and their regexes, if and when there's a match, |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
196 | // the primitive's category is set to the category the regex beloings to. |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
197 | for (PrimitiveCategory & cat : g_PrimitiveCategories) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
198 | { for (PrimitiveCategory::RegexEntry & entry : cat.regexes) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
199 | { switch (entry.type) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
200 | { case PrimitiveCategory::Filename: |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
201 | // f-regex, check against filename |
398 | 202 | matched = entry.regex.exactMatch (prim.name); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
203 | break; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
204 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
205 | case PrimitiveCategory::Title: |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
206 | // t-regex, check against title |
398 | 207 | matched = entry.regex.exactMatch (prim.title); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
208 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
209 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
210 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
211 | if (matched) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
212 | { prim.cat = &cat; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
213 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
214 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
215 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
216 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
217 | // Drop out if a category was decided on. |
398 | 218 | if (prim.cat) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
219 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
220 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
221 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
222 | // If there was a match, add the primitive to the category. |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
223 | // Otherwise, add it to the list of unmatched primitives. |
398 | 224 | if (prim.cat) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
225 | prim.cat->prims << prim; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
226 | else |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
227 | unmatched->prims << prim; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | } |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
229 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
230 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
231 | // ============================================================================= |
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:
436
diff
changeset
|
232 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
233 | static void loadPrimitiveCatgories() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
234 | { g_PrimitiveCategories.clear(); |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
235 | File f (Config::dirpath() + "primregexps.cfg", File::Read); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
236 | |
398 | 237 | if (!f) |
238 | f.open (":/data/primitive-categories.cfg", File::Read); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
239 | |
398 | 240 | if (!f) |
241 | critical (QObject::tr ("Failed to open primitive categories!")); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
242 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
243 | if (f) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
244 | { PrimitiveCategory cat; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
245 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
246 | for (str line : f) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
247 | { int colon; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
248 | |
398 | 249 | if (line.length() == 0 || line[0] == '#') |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
250 | continue; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
251 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
252 | if ( (colon = line.indexOf (":")) == -1) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
253 | { if (cat.regexes.size() > 0) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
254 | g_PrimitiveCategories << cat; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
255 | |
358 | 256 | cat.regexes.clear(); |
257 | cat.prims.clear(); | |
398 | 258 | cat.setName (line); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
259 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
260 | else |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
261 | { str cmd = line.left (colon); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
262 | PrimitiveCategory::Type type = PrimitiveCategory::Filename; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
263 | |
398 | 264 | if (cmd == "f") |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
265 | type = PrimitiveCategory::Filename; |
398 | 266 | elif (cmd == "t") |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
267 | type = PrimitiveCategory::Title; |
358 | 268 | else |
294
2892deee4c1b
Better categorized Technic primitives
Santeri Piippo <crimsondusk64@gmail.com>
parents:
293
diff
changeset
|
269 | continue; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
270 | |
398 | 271 | QRegExp regex (line.mid (colon + 1)); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
272 | PrimitiveCategory::RegexEntry entry = { regex, type }; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
273 | cat.regexes << entry; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
274 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
275 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
276 | |
398 | 277 | if (cat.regexes.size() > 0) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
278 | g_PrimitiveCategories << cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
279 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
280 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
281 | // Add a category for unmatched primitives |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
282 | PrimitiveCategory cat; |
398 | 283 | cat.setName (g_Other); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
284 | g_PrimitiveCategories << cat; |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
285 | } |
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
286 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
287 | // ============================================================================= |
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:
436
diff
changeset
|
288 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
289 | bool primitiveLoaderBusy() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
290 | { return g_primListerMutex; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
291 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
292 | |
398 | 293 | // ============================================================================= |
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:
436
diff
changeset
|
294 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
295 | static double radialPoint (int i, int divs, double (*func) (double)) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
296 | { return (*func) ((i * 2 * pi) / divs); |
363
75583c9f289d
primitive generator: add conditional lines to cylinders; improved bad color handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
358
diff
changeset
|
297 | } |
75583c9f289d
primitive generator: add conditional lines to cylinders; improved bad color handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
358
diff
changeset
|
298 | |
398 | 299 | // ============================================================================= |
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:
436
diff
changeset
|
300 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
301 | List<LDObject*> makePrimitive (PrimitiveType type, int segs, int divs, int num) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
302 | { List<LDObject*> objs; |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
303 | List<int> condLineSegs; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
304 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
305 | for (int i = 0; i < segs; ++i) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
306 | { double x0 = radialPoint (i, divs, cos), |
398 | 307 | x1 = radialPoint (i + 1, divs, cos), |
308 | z0 = radialPoint (i, divs, sin), | |
309 | z1 = radialPoint (i + 1, divs, sin); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
310 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
311 | switch (type) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
312 | { case Circle: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
313 | { vertex v0 (x0, 0.0f, z0), |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
314 | v1 (x1, 0.0f, z1); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
315 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
316 | LDLine* line = new LDLine; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
317 | line->setVertex (0, v0); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
318 | line->setVertex (1, v1); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
319 | line->setColor (edgecolor); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
320 | objs << line; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
321 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
322 | break; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
323 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
324 | case Cylinder: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
325 | case Ring: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
326 | case Cone: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
327 | { double x2, x3, z2, z3; |
398 | 328 | double y0, y1, y2, y3; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
329 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
330 | if (type == Cylinder) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
331 | { x2 = x1; |
398 | 332 | x3 = x0; |
333 | z2 = z1; | |
334 | z3 = z0; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
335 | |
398 | 336 | y0 = y1 = 0.0f; |
337 | y2 = y3 = 1.0f; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
338 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
339 | else |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
340 | { x2 = x1 * (num + 1); |
398 | 341 | x3 = x0 * (num + 1); |
342 | z2 = z1 * (num + 1); | |
343 | z3 = z0 * (num + 1); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
344 | |
398 | 345 | x0 *= num; |
346 | x1 *= num; | |
347 | z0 *= num; | |
348 | z1 *= num; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
349 | |
398 | 350 | if (type == Ring) |
351 | y0 = y1 = y2 = y3 = 0.0f; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
352 | else |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
353 | { y0 = y1 = 1.0f; |
398 | 354 | y2 = y3 = 0.0f; |
355 | } | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
356 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
357 | |
398 | 358 | vertex v0 (x0, y0, z0), |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
359 | v1 (x1, y1, z1), |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
360 | v2 (x2, y2, z2), |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
361 | v3 (x3, y3, z3); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
362 | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
363 | LDQuad* quad = new LDQuad; |
398 | 364 | quad->setColor (maincolor); |
365 | quad->setVertex (0, v0); | |
366 | quad->setVertex (1, v1); | |
367 | quad->setVertex (2, v2); | |
368 | quad->setVertex (3, v3); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
369 | |
398 | 370 | if (type == Cylinder) |
371 | quad->invert(); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
372 | |
398 | 373 | objs << quad; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
374 | |
398 | 375 | if (type == Cylinder || type == Cone) |
376 | condLineSegs << i; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
377 | } |
398 | 378 | break; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
379 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
380 | case Disc: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
381 | case DiscNeg: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
382 | { double x2, z2; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
383 | |
398 | 384 | if (type == Disc) |
385 | x2 = z2 = 0.0f; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
386 | else |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
387 | { x2 = (x0 >= 0.0f) ? 1.0f : -1.0f; |
398 | 388 | z2 = (z0 >= 0.0f) ? 1.0f : -1.0f; |
389 | } | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
390 | |
398 | 391 | vertex v0 (x0, 0.0f, z0), |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
392 | v1 (x1, 0.0f, z1), |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
393 | v2 (x2, 0.0f, z2); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
394 | |
398 | 395 | // Disc negatives need to go the other way around, otherwise |
396 | // they'll end up upside-down. | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
397 | LDTriangle* seg = new LDTriangle; |
398 | 398 | seg->setColor (maincolor); |
399 | seg->setVertex (type == Disc ? 0 : 2, v0); | |
400 | seg->setVertex (1, v1); | |
401 | seg->setVertex (type == Disc ? 2 : 0, v2); | |
402 | objs << seg; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
403 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
404 | break; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
405 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
406 | default: |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
407 | break; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
408 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
409 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
410 | |
365
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
411 | // If this is not a full circle, we need a conditional line at the other |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
412 | // end, too. |
398 | 413 | if (segs < divs && condLineSegs.size() != 0) |
365
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
414 | condLineSegs << segs; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
415 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
416 | for (int i : condLineSegs) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
417 | { vertex v0 (radialPoint (i, divs, cos), 0.0f, radialPoint (i, divs, sin)), |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
418 | v1, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
419 | v2 (radialPoint (i + 1, divs, cos), 0.0f, radialPoint (i + 1, divs, sin)), |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
420 | v3 (radialPoint (i - 1, divs, cos), 0.0f, radialPoint (i - 1, divs, sin)); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
421 | |
398 | 422 | if (type == Cylinder) |
423 | v1 = vertex (v0[X], 1.0f, v0[Z]); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
424 | elif (type == Cone) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
425 | { v1 = vertex (v0[X] * (num + 1), 0.0f, v0[Z] * (num + 1)); |
365
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
426 | v0[X] *= num; |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
427 | v0[Y] = 1.0f; |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
428 | v0[Z] *= num; |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
429 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
430 | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
431 | LDCndLine* line = new LDCndLine; |
398 | 432 | line->setColor (edgecolor); |
433 | line->setVertex (0, v0); | |
434 | line->setVertex (1, v1); | |
435 | line->setVertex (2, v2); | |
436 | line->setVertex (3, v3); | |
365
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
437 | objs << line; |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
438 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
439 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
440 | return objs; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
441 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
442 | |
398 | 443 | // ============================================================================= |
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:
436
diff
changeset
|
444 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
445 | static str primitiveTypeName (PrimitiveType type) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
446 | { // Not translated as primitives are in English. |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
447 | return type == Circle ? "Circle" : |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
448 | type == Cylinder ? "Cylinder" : |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
449 | type == Disc ? "Disc" : |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
450 | type == DiscNeg ? "Disc Negative" : |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
451 | type == Ring ? "Ring" : "Cone"; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
452 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
453 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
454 | // ============================================================================= |
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:
436
diff
changeset
|
455 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
456 | str radialFileName (PrimitiveType type, int segs, int divs, int num) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
457 | { short numer = segs, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
458 | denom = divs; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
459 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
460 | // Simplify the fractional part, but the denominator must be at least 4. |
398 | 461 | simplify (numer, denom); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
462 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
463 | if (denom < 4) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
464 | { const short factor = 4 / denom; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
465 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
466 | numer *= factor; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
467 | denom *= factor; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
468 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
469 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
470 | // Compose some general information: prefix, fraction, root, ring number |
398 | 471 | str prefix = (divs == lores) ? "" : fmt ("%1/", divs); |
472 | str frac = fmt ("%1-%2", numer, denom); | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
473 | str root = g_radialNameRoots[type]; |
398 | 474 | str numstr = (type == Ring || type == Cone) ? fmt ("%1", num) : ""; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
475 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
476 | // Truncate the root if necessary (7-16rin4.dat for instance). |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
477 | // However, always keep the root at least 2 characters. |
398 | 478 | int extra = (frac.length() + numstr.length() + root.length()) - 8; |
479 | root.chop (min<short> (max<short> (extra, 0), 2)); | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
480 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
481 | // Stick them all together and return the result. |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
482 | return prefix + frac + root + numstr + ".dat"; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
483 | } |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
484 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
485 | // ============================================================================= |
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:
436
diff
changeset
|
486 | // ----------------------------------------------------------------------------- |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
487 | LDFile* generatePrimitive (PrimitiveType type, int segs, int divs, int num) |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
488 | { // Make the description |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
489 | str frac = ftoa (((float) segs) / divs); |
377
271d1da66b7e
Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents:
365
diff
changeset
|
490 | str name = radialFileName (type, segs, divs, num); |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
491 | str descr; |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
492 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
493 | // Ensure that there's decimals, even if they're 0. |
377
271d1da66b7e
Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents:
365
diff
changeset
|
494 | if (frac.indexOf (".") == -1) |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
495 | frac += ".0"; |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
496 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
497 | if (type == Ring || type == Cone) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
498 | { str spacing = |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
499 | (num < 10) ? " " : |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
500 | (num < 100) ? " " : ""; |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
501 | |
407
c6530cdcd622
primitive generator: added support for multiple spaces before primitive numbers, add "Hi-Res" to the names of 48/ primitives
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
502 | descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
503 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
504 | else |
377
271d1da66b7e
Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents:
365
diff
changeset
|
505 | descr = fmt ("%1 %2", primitiveTypeName (type), frac); |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
506 | |
407
c6530cdcd622
primitive generator: added support for multiple spaces before primitive numbers, add "Hi-Res" to the names of 48/ primitives
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
507 | // Prepend "Hi-Res" if 48/ primitive. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
508 | if (divs == hires) |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
509 | descr.insert (0, "Hi-Res "); |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
510 | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
408
diff
changeset
|
511 | LDFile* f = new LDFile; |
398 | 512 | f->setName (QFileDialog::getSaveFileName (null, QObject::tr ("Save Primitive"), name)); |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
513 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
514 | f->addObjects ( |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
515 | { new LDComment (descr), |
484
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
516 | new LDComment (fmt ("Name: %1", name)), |
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
517 | new LDComment (fmt ("Author: LDForge")), |
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
518 | new LDComment (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "")), |
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
519 | new LDComment (CALicense), |
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
520 | new LDEmpty, |
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
521 | new LDBFC (LDBFC::CertifyCCW), |
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
522 | new LDEmpty, |
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
523 | }); |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
524 | |
484
5b5c77c7f3dd
made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
525 | f->addObjects (makePrimitive (type, segs, divs, num)); |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
526 | return f; |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
527 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
528 | |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
529 | // ============================================================================= |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
530 | // ----------------------------------------------------------------------------- |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
531 | LDFile* getPrimitive (PrimitiveType type, int segs, int divs, int num) |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
532 | { str name = radialFileName (type, segs, divs, num); |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
533 | LDFile* f = getFile (name); |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
534 | if (f != null) |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
535 | return f; |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
536 | |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
537 | return generatePrimitive (type, segs, divs, num); |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
538 | } |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
539 | |
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:
436
diff
changeset
|
540 | // ============================================================================= |
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:
436
diff
changeset
|
541 | // ----------------------------------------------------------------------------- |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
542 | PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) : |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
543 | QDialog (parent, f) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
544 | { |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
545 | |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
546 | ui = new Ui_MakePrimUI; |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
547 | ui->setupUi (this); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
548 | connect (ui->cb_hires, SIGNAL (toggled (bool)), this, SLOT (hiResToggled (bool))); |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
549 | } |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
550 | |
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:
436
diff
changeset
|
551 | // ============================================================================= |
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:
436
diff
changeset
|
552 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
553 | PrimitivePrompt::~PrimitivePrompt() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
554 | { delete ui; |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
555 | } |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
556 | |
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:
436
diff
changeset
|
557 | // ============================================================================= |
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:
436
diff
changeset
|
558 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
559 | void PrimitivePrompt::hiResToggled (bool on) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
560 | { ui->sb_segs->setMaximum (on ? hires : lores); |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
561 | |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
562 | // If the current value is 16 and we switch to hi-res, default the |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
563 | // spinbox to 48. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
564 | if (on && ui->sb_segs->value() == lores) |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
565 | ui->sb_segs->setValue (hires); |
491
7d1b5ecd76c0
it's LDForge's 1st birthday!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
484
diff
changeset
|
566 | } |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
567 | |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
568 | // ============================================================================= |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
569 | // ----------------------------------------------------------------------------- |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
570 | DEFINE_ACTION (MakePrimitive, 0) |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
571 | { PrimitivePrompt* dlg = new PrimitivePrompt (g_win); |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
572 | |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
573 | if (!dlg->exec()) |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
574 | return; |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
575 | |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
576 | int segs = dlg->ui->sb_segs->value(); |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
577 | int divs = dlg->ui->cb_hires->isChecked() ? hires : lores; |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
578 | int num = dlg->ui->sb_ringnum->value(); |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
579 | PrimitiveType type = |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
580 | dlg->ui->rb_circle->isChecked() ? Circle : |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
581 | dlg->ui->rb_cylinder->isChecked() ? Cylinder : |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
582 | dlg->ui->rb_disc->isChecked() ? Disc : |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
583 | dlg->ui->rb_ndisc->isChecked() ? DiscNeg : |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
584 | dlg->ui->rb_ring->isChecked() ? Ring : Cone; |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
585 | |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
586 | LDFile* f = generatePrimitive (type, segs, divs, num); |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
587 | |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
588 | g_win->save (f, false); |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
589 | delete f; |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
590 | } |