Sun, 18 Aug 2013 17:53:23 +0300
Cut the Object-suffix from LDObject types, it doesn't help things at all
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" |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
30 | List<PrimitiveCategory> g_PrimitiveCategories; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
31 | static PrimitiveLister* g_activePrimLister = null; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
32 | static bool g_primListerMutex = false; |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
33 | List<Primitive> g_primitives; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
34 | |
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 | |
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
|
37 | static const str g_radialNameRoots[] = { |
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
|
38 | "edge", |
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 | // ----------------------------------------------------------------------------- |
398 | 51 | void loadPrimitives() { |
52 | print ("Loading primitives...\n"); | |
358 | 53 | loadPrimitiveCatgories(); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
54 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
55 | // Try to load prims.cfg |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
56 | File conf (config::filepath ("prims.cfg"), File::Read); |
358 | 57 | |
398 | 58 | if (!conf) { |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
59 | // No prims.cfg, build it |
358 | 60 | PrimitiveLister::start(); |
398 | 61 | } else { |
62 | // Read primitives from prims.cfg | |
63 | for (str line : conf) { | |
64 | int space = line.indexOf (" "); | |
358 | 65 | |
398 | 66 | if (space == -1) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
67 | continue; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
68 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
69 | Primitive info; |
398 | 70 | info.name = line.left (space); |
71 | info.title = line.mid (space + 1); | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
72 | g_primitives << info; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
73 | } |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
74 | |
358 | 75 | populateCategories(); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
76 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
77 | } |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | // ============================================================================= |
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
|
80 | // ----------------------------------------------------------------------------- |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
81 | static void recursiveGetFilenames (QDir dir, List<str>& fnames) { |
358 | 82 | QFileInfoList flist = dir.entryInfoList(); |
83 | ||
398 | 84 | for (const QFileInfo & info : flist) { |
85 | if (info.fileName() == "." || info.fileName() == "..") | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | continue; // skip . and .. |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
398 | 88 | if (info.isDir()) |
89 | recursiveGetFilenames (QDir (info.absoluteFilePath()), fnames); | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | else |
358 | 91 | fnames << info.absoluteFilePath(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | } |
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 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
95 | // ============================================================================= |
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
|
96 | // ----------------------------------------------------------------------------- |
398 | 97 | void PrimitiveLister::work() { |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | g_activePrimLister = this; |
358 | 99 | m_prims.clear(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | |
398 | 101 | QDir dir (LDPaths::prims()); |
358 | 102 | ulong baselen = dir.absolutePath().length(); |
103 | 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
|
104 | List<str> fnames; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
398 | 106 | assert (dir.exists()); |
107 | recursiveGetFilenames (dir, fnames); | |
108 | emit starting (fnames.size()); | |
358 | 109 | |
398 | 110 | for (str fname : fnames) { |
111 | File f (fname, File::Read); | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | Primitive info; |
398 | 114 | info.name = fname.mid (baselen + 1); // make full path relative |
115 | info.name.replace ('/', '\\'); // use DOS backslashes, they're expected | |
358 | 116 | info.cat = null; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
398 | 118 | if (!f.readLine (info.title)) |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | info.title = ""; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | |
358 | 121 | info.title = info.title.simplified(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | |
398 | 123 | if (info.title[0] == '0') { |
124 | info.title.remove (0, 1); // remove 0 | |
358 | 125 | info.title = info.title.simplified(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | } |
398 | 127 | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | m_prims << info; |
398 | 129 | emit update (++i); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | // Save to a config file |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
133 | File conf (config::filepath ("prims.cfg"), File::Write); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | |
398 | 135 | for (Primitive & info : m_prims) |
136 | fprint (conf, "%1 %2\n", info.name, info.title); | |
358 | 137 | |
138 | conf.close(); | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | g_primListerMutex = true; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
141 | g_primitives = m_prims; |
358 | 142 | populateCategories(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | g_primListerMutex = false; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | g_activePrimLister = null; |
358 | 145 | emit workDone(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
148 | // ============================================================================= |
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
|
149 | // ----------------------------------------------------------------------------- |
398 | 150 | void PrimitiveLister::start() { |
151 | if (g_activePrimLister) | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | return; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | PrimitiveLister* lister = new PrimitiveLister; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | QThread* listerThread = new QThread; |
398 | 156 | lister->moveToThread (listerThread); |
157 | connect (lister, SIGNAL (starting (ulong)), g_win, SLOT (primitiveLoaderStart (ulong))); | |
158 | connect (lister, SIGNAL (update (ulong)), g_win, SLOT (primitiveLoaderUpdate (ulong))); | |
159 | connect (lister, SIGNAL (workDone()), g_win, SLOT (primitiveLoaderEnd())); | |
160 | connect (listerThread, SIGNAL (started()), lister, SLOT (work())); | |
161 | connect (listerThread, SIGNAL (finished()), lister, SLOT (deleteLater())); | |
358 | 162 | listerThread->start(); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
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
|
165 | // ============================================================================= |
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 | // ----------------------------------------------------------------------------- |
398 | 167 | static PrimitiveCategory* findCategory (str name) { |
168 | for (PrimitiveCategory& cat : g_PrimitiveCategories) | |
169 | if (cat.name() == name) | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
170 | return &cat; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
172 | return null; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
173 | } |
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 | // ============================================================================= |
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
|
176 | // ----------------------------------------------------------------------------- |
398 | 177 | static void populateCategories() { |
178 | for (PrimitiveCategory& cat : g_PrimitiveCategories) | |
358 | 179 | cat.prims.clear(); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
180 | |
398 | 181 | PrimitiveCategory* unmatched = findCategory (g_Other); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
182 | |
398 | 183 | if (!unmatched) { |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
184 | // Shouldn't happen.. but catch it anyway. |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
185 | PrimitiveCategory cat; |
398 | 186 | cat.setName (g_Other); |
187 | unmatched = & (g_PrimitiveCategories << cat); | |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | } |
398 | 189 | |
190 | for (Primitive& prim : g_primitives) { | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
191 | 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
|
192 | prim.cat = null; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
193 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
194 | // 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
|
195 | // the primitive's category is set to the category the regex beloings to. |
398 | 196 | for (PrimitiveCategory& cat : g_PrimitiveCategories) { |
197 | for (PrimitiveCategory::RegexEntry& entry : cat.regexes) { | |
198 | switch (entry.type) { | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
199 | case PrimitiveCategory::Filename: |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
200 | // f-regex, check against filename |
398 | 201 | matched = entry.regex.exactMatch (prim.name); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
202 | break; |
358 | 203 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
204 | case PrimitiveCategory::Title: |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
205 | // t-regex, check against title |
398 | 206 | matched = entry.regex.exactMatch (prim.title); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
207 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
208 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
209 | |
398 | 210 | if (matched) { |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
211 | prim.cat = &cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
212 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
213 | } |
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 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
216 | // Drop out if a category was decided on. |
398 | 217 | if (prim.cat) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
218 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
219 | } |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
221 | // 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
|
222 | // Otherwise, add it to the list of unmatched primitives. |
398 | 223 | if (prim.cat) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
224 | prim.cat->prims << prim; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
225 | else |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
226 | unmatched->prims << prim; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | } |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
228 | } |
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 | // ============================================================================= |
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
|
231 | // ----------------------------------------------------------------------------- |
398 | 232 | static void loadPrimitiveCatgories() { |
358 | 233 | g_PrimitiveCategories.clear(); |
398 | 234 | File f (config::dirpath() + "primregexps.cfg", File::Read); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
235 | |
398 | 236 | if (!f) |
237 | f.open (":/data/primitive-categories.cfg", File::Read); | |
358 | 238 | |
398 | 239 | if (!f) |
240 | critical (QObject::tr ("Failed to open primitive categories!")); | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
241 | |
398 | 242 | if (f) { |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
243 | PrimitiveCategory cat; |
358 | 244 | |
398 | 245 | for (str line : f) { |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
246 | int colon; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
247 | |
398 | 248 | if (line.length() == 0 || line[0] == '#') |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
249 | continue; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
250 | |
398 | 251 | if ((colon = line.indexOf (":")) == -1) { |
252 | if (cat.regexes.size() > 0) | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
253 | g_PrimitiveCategories << cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
254 | |
358 | 255 | cat.regexes.clear(); |
256 | cat.prims.clear(); | |
398 | 257 | cat.setName (line); |
258 | } else { | |
259 | str cmd = line.left (colon); | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
260 | PrimitiveCategory::Type type = PrimitiveCategory::Filename; |
358 | 261 | |
398 | 262 | if (cmd == "f") |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
263 | type = PrimitiveCategory::Filename; |
398 | 264 | elif (cmd == "t") |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
265 | type = PrimitiveCategory::Title; |
358 | 266 | else |
294
2892deee4c1b
Better categorized Technic primitives
Santeri Piippo <crimsondusk64@gmail.com>
parents:
293
diff
changeset
|
267 | continue; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
268 | |
398 | 269 | QRegExp regex (line.mid (colon + 1)); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
270 | PrimitiveCategory::RegexEntry entry = { regex, type }; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
271 | cat.regexes << entry; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
272 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
273 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
274 | |
398 | 275 | if (cat.regexes.size() > 0) |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
276 | g_PrimitiveCategories << cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
277 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
278 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
279 | // Add a category for unmatched primitives |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
280 | PrimitiveCategory cat; |
398 | 281 | cat.setName (g_Other); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
282 | g_PrimitiveCategories << cat; |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
283 | } |
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
284 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
285 | // ============================================================================= |
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
|
286 | // ----------------------------------------------------------------------------- |
398 | 287 | bool primitiveLoaderBusy() { |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
288 | return g_primListerMutex; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
289 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
290 | |
398 | 291 | // ============================================================================= |
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
|
292 | // ----------------------------------------------------------------------------- |
398 | 293 | static double radialPoint (int i, int divs, double (*func) (double)) { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
294 | 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
|
295 | } |
75583c9f289d
primitive generator: add conditional lines to cylinders; improved bad color handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
358
diff
changeset
|
296 | |
398 | 297 | // ============================================================================= |
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
|
298 | // ----------------------------------------------------------------------------- |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
299 | List<LDObject*> makePrimitive (PrimitiveType type, int segs, int divs, int num) { |
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
300 | List<LDObject*> objs; |
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
398
diff
changeset
|
301 | List<int> condLineSegs; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
302 | |
398 | 303 | for (int i = 0; i < segs; ++i) { |
304 | double x0 = radialPoint (i, divs, cos), | |
305 | x1 = radialPoint (i + 1, divs, cos), | |
306 | z0 = radialPoint (i, divs, sin), | |
307 | z1 = radialPoint (i + 1, divs, sin); | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
308 | |
398 | 309 | switch (type) { |
310 | case Circle: { | |
311 | vertex v0 (x0, 0.0f, z0), | |
312 | v1 (x1, 0.0f, z1); | |
358 | 313 | |
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
|
314 | LDLine* line = new LDLine; |
398 | 315 | line->setVertex (0, v0); |
316 | line->setVertex (1, v1); | |
317 | line->setColor (edgecolor); | |
363
75583c9f289d
primitive generator: add conditional lines to cylinders; improved bad color handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
358
diff
changeset
|
318 | objs << line; |
358 | 319 | } |
320 | break; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
321 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
322 | case Cylinder: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
323 | case Ring: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
324 | case Cone: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
325 | { |
398 | 326 | double x2, x3, z2, z3; |
327 | double y0, y1, y2, y3; | |
358 | 328 | |
398 | 329 | if (type == Cylinder) { |
330 | x2 = x1; | |
331 | x3 = x0; | |
332 | z2 = z1; | |
333 | z3 = z0; | |
334 | ||
335 | y0 = y1 = 0.0f; | |
336 | y2 = y3 = 1.0f; | |
337 | } else { | |
338 | x2 = x1 * (num + 1); | |
339 | x3 = x0 * (num + 1); | |
340 | z2 = z1 * (num + 1); | |
341 | z3 = z0 * (num + 1); | |
342 | ||
343 | x0 *= num; | |
344 | x1 *= num; | |
345 | z0 *= num; | |
346 | z1 *= num; | |
347 | ||
348 | if (type == Ring) | |
349 | y0 = y1 = y2 = y3 = 0.0f; | |
350 | else { | |
351 | y0 = y1 = 1.0f; | |
352 | y2 = y3 = 0.0f; | |
353 | } | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
354 | } |
398 | 355 | |
356 | vertex v0 (x0, y0, z0), | |
357 | v1 (x1, y1, z1), | |
358 | v2 (x2, y2, z2), | |
359 | v3 (x3, y3, z3); | |
360 | ||
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
|
361 | LDQuad* quad = new LDQuad; |
398 | 362 | quad->setColor (maincolor); |
363 | quad->setVertex (0, v0); | |
364 | quad->setVertex (1, v1); | |
365 | quad->setVertex (2, v2); | |
366 | quad->setVertex (3, v3); | |
367 | ||
368 | if (type == Cylinder) | |
369 | quad->invert(); | |
370 | ||
371 | objs << quad; | |
372 | ||
373 | if (type == Cylinder || type == Cone) | |
374 | condLineSegs << i; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
375 | } |
398 | 376 | break; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
377 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
378 | case Disc: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
379 | case DiscNeg: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
380 | { |
398 | 381 | double x2, z2; |
382 | ||
383 | if (type == Disc) | |
384 | x2 = z2 = 0.0f; | |
385 | else { | |
386 | x2 = (x0 >= 0.0f) ? 1.0f : -1.0f; | |
387 | z2 = (z0 >= 0.0f) ? 1.0f : -1.0f; | |
388 | } | |
389 | ||
390 | vertex v0 (x0, 0.0f, z0), | |
391 | v1 (x1, 0.0f, z1), | |
392 | v2 (x2, 0.0f, z2); | |
393 | ||
394 | // Disc negatives need to go the other way around, otherwise | |
395 | // 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
|
396 | LDTriangle* seg = new LDTriangle; |
398 | 397 | seg->setColor (maincolor); |
398 | seg->setVertex (type == Disc ? 0 : 2, v0); | |
399 | seg->setVertex (1, v1); | |
400 | seg->setVertex (type == Disc ? 2 : 0, v2); | |
401 | objs << seg; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
402 | } |
358 | 403 | break; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
404 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
405 | default: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
406 | break; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
407 | } |
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 | |
365
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
410 | // 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
|
411 | // end, too. |
398 | 412 | 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
|
413 | condLineSegs << segs; |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
414 | |
398 | 415 | for (int i : condLineSegs) { |
416 | vertex v0 (radialPoint (i, divs, cos), 0.0f, radialPoint (i, divs, sin)), | |
365
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
417 | v1, |
398 | 418 | v2 (radialPoint (i + 1, divs, cos), 0.0f, radialPoint (i + 1, divs, sin)), |
419 | v3 (radialPoint (i - 1, divs, cos), 0.0f, radialPoint (i - 1, divs, sin)); | |
365
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
420 | |
398 | 421 | if (type == Cylinder) |
422 | v1 = vertex (v0[X], 1.0f, v0[Z]); | |
423 | elif (type == Cone) { | |
424 | 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
|
425 | 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
|
426 | 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
|
427 | 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
|
428 | } |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
429 | |
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
|
430 | LDCndLine* line = new LDCndLine; |
398 | 431 | line->setColor (edgecolor); |
432 | line->setVertex (0, v0); | |
433 | line->setVertex (1, v1); | |
434 | line->setVertex (2, v2); | |
435 | 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
|
436 | objs << line; |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
437 | } |
b3f6c93db2e4
further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
438 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
439 | return objs; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
440 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
441 | |
398 | 442 | // ============================================================================= |
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
|
443 | // ----------------------------------------------------------------------------- |
398 | 444 | static str primitiveTypeName (PrimitiveType type) { |
321
48e429bfd58c
Apply tr() for possible future translations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
319
diff
changeset
|
445 | // 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
|
446 | return type == Circle ? "Circle" : |
398 | 447 | type == Cylinder ? "Cylinder" : |
448 | type == Disc ? "Disc" : | |
449 | type == DiscNeg ? "Disc Negative" : | |
450 | type == Ring ? "Ring" : "Cone"; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
451 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
452 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
453 | // ============================================================================= |
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
|
454 | // ----------------------------------------------------------------------------- |
398 | 455 | str radialFileName (PrimitiveType type, int segs, int divs, int num) { |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
456 | short numer = segs, |
398 | 457 | denom = divs; |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
458 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
459 | // Simplify the fractional part, but the denominator must be at least 4. |
398 | 460 | simplify (numer, denom); |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
461 | |
398 | 462 | if (denom < 4) { |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
463 | const short factor = 4 / denom; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
464 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
465 | numer *= factor; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
466 | denom *= factor; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
467 | } |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
468 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
469 | // Compose some general information: prefix, fraction, root, ring number |
398 | 470 | str prefix = (divs == lores) ? "" : fmt ("%1/", divs); |
471 | str frac = fmt ("%1-%2", numer, denom); | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
472 | str root = g_radialNameRoots[type]; |
398 | 473 | str numstr = (type == Ring || type == Cone) ? fmt ("%1", num) : ""; |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
474 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
475 | // 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
|
476 | // However, always keep the root at least 2 characters. |
398 | 477 | int extra = (frac.length() + numstr.length() + root.length()) - 8; |
478 | root.chop (min<short> (max<short> (extra, 0), 2)); | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
479 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
480 | // Stick them all together and return the result. |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
481 | return prefix + frac + root + numstr + ".dat"; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
482 | } |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
483 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
484 | // ============================================================================= |
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
|
485 | // ----------------------------------------------------------------------------- |
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
|
486 | void generatePrimitive() { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
487 | PrimitivePrompt* dlg = new PrimitivePrompt (g_win); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
488 | |
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
|
489 | if (!dlg->exec()) |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
490 | return; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
491 | |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
492 | int segs = dlg->ui->sb_segs->value(); |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
493 | int divs = dlg->ui->cb_hires->isChecked() ? hires : lores; |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
494 | int num = dlg->ui->sb_ringnum->value(); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
495 | PrimitiveType type = |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
496 | dlg->ui->rb_circle->isChecked() ? Circle : |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
497 | dlg->ui->rb_cylinder->isChecked() ? Cylinder : |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
498 | dlg->ui->rb_disc->isChecked() ? Disc : |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
499 | dlg->ui->rb_ndisc->isChecked() ? DiscNeg : |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
500 | dlg->ui->rb_ring->isChecked() ? Ring : Cone; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
501 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
502 | // Make the description |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
503 | 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
|
504 | str name = radialFileName (type, segs, divs, num); |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
505 | str descr; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
506 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
507 | // 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
|
508 | if (frac.indexOf (".") == -1) |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
509 | frac += ".0"; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
510 | |
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
|
511 | if (type == Ring || type == Cone) { |
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
|
512 | str spacing = |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
513 | (num < 10 ) ? " " : |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
514 | (num < 100) ? " " : ""; |
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
|
515 | |
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
|
516 | descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac); |
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
|
517 | } 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
|
518 | descr = fmt ("%1 %2", primitiveTypeName (type), frac); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
519 | |
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
|
520 | // 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
|
521 | if (divs == hires) |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
522 | descr.insert (0, "Hi-Res "); |
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
|
523 | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
408
diff
changeset
|
524 | LDFile* f = new LDFile; |
398 | 525 | f->setName (QFileDialog::getSaveFileName (null, QObject::tr ("Save Primitive"), name)); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
526 | |
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
|
527 | *f << new LDComment (descr); |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
528 | *f << new LDComment (fmt ("Name: %1", name)); |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
529 | *f << new LDComment (fmt ("Author: LDForge")); |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
530 | *f << new LDComment (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "")); |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
531 | *f << new LDComment (CALicense); |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
532 | *f << new LDEmpty; |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
533 | *f << new LDBFC (LDBFC::CertifyCCW); |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
534 | *f << new LDEmpty; |
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
|
535 | *f << makePrimitive (type, segs, divs, num); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
536 | |
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
|
537 | g_win->save (f, false); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
538 | delete f; |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
539 | } |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
540 | |
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
|
541 | // ============================================================================= |
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
|
542 | // ----------------------------------------------------------------------------- |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
543 | PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) : |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
544 | QDialog (parent, f) { |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
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); |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
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 | // ----------------------------------------------------------------------------- |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
553 | PrimitivePrompt::~PrimitivePrompt() { |
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
554 | delete ui; |
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 | // ----------------------------------------------------------------------------- |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
559 | void PrimitivePrompt::hiResToggled (bool on) { |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
560 | ui->sb_segs->setMaximum (on ? hires : lores); |
408
81dc5f6b9c73
- fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
407
diff
changeset
|
561 | |
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); |
410
a5aebcf4a1c8
Include the moc files in the source cpp files to reduce compile time
Santeri Piippo <crimsondusk64@gmail.com>
parents:
409
diff
changeset
|
566 | } |
a5aebcf4a1c8
Include the moc files in the source cpp files to reduce compile time
Santeri Piippo <crimsondusk64@gmail.com>
parents:
409
diff
changeset
|
567 | |
a5aebcf4a1c8
Include the moc files in the source cpp files to reduce compile time
Santeri Piippo <crimsondusk64@gmail.com>
parents:
409
diff
changeset
|
568 | #include "build/moc_primitives.cpp" |