Tue, 02 Jul 2013 23:29:57 +0300
Show values in file opening prompt
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 |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
4 | * |
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. |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
9 | * |
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. |
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
294
diff
changeset
|
14 | * |
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" |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
29 | vector<PrimitiveCategory> g_PrimitiveCategories; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
30 | static PrimitiveLister* g_activePrimLister = null; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
31 | static bool g_primListerMutex = false; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
32 | vector<Primitive> g_primitives; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
33 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
34 | static void populateCategories (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
35 | static void loadPrimitiveCatgories (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
36 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
37 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
38 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
39 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
40 | void loadPrimitives () { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
41 | print ("Loading primitives...\n"); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
42 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
43 | loadPrimitiveCatgories (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
44 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
45 | // Try to load prims.cfg |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
46 | File conf (config::dirpath () + "prims.cfg", File::Read); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
47 | if (!conf) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
48 | // No prims.cfg, build it |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
49 | PrimitiveLister::start (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
50 | } else { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
51 | for (str line : conf) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
52 | int space = line.indexOf (" "); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
53 | if (space == -1) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
54 | continue; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
55 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
56 | Primitive info; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
57 | info.name = line.left (space); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
58 | info.title = line.mid (space + 1); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
59 | g_primitives << info; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
60 | } |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
61 | |
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
62 | populateCategories (); |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
63 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
64 | } |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | // ============================================================================= |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // ============================================================================= |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | void recursiveGetFilenames (QDir dir, vector<str>& fnames) { |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | QFileInfoList flist = dir.entryInfoList (); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | for (const QFileInfo& info : flist) { |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | if (info.fileName () == "." || info.fileName () == "..") |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | continue; // skip . and .. |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | if (info.isDir ()) |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | recursiveGetFilenames (QDir (info.absoluteFilePath ()), fnames); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | else |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | fnames << info.absoluteFilePath (); |
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 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
82 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
83 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
84 | // ============================================================================= |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | void PrimitiveLister::work () { |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | g_activePrimLister = this; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | m_prims.clear (); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | QDir dir (LDPaths::prims ()); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | assert (dir.exists ()); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | ulong baselen = dir.absolutePath ().length (); |
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 | vector<str> fnames; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | recursiveGetFilenames (dir, fnames); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | emit starting (fnames.size ()); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | ulong i = 0; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | for (str fname : fnames) { |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | File f (fname, File::Read); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | Primitive info; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | info.name = fname.mid (baselen + 1); // make full path relative |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | info.name.replace ('/', '\\'); // use DOS backslashes, they're expected |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | if (!f.readLine (info.title)) |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | info.title = ""; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | info.title = info.title.simplified (); |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
110 | info.cat = null; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | if (info.title[0] == '0') { |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | info.title.remove (0, 1); // remove 0 |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | info.title = info.title.simplified (); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | m_prims << info; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | emit update (++i); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | // Save to a config file |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | File conf (config::dirpath () + "prims.cfg", File::Write); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | for (Primitive& info : m_prims) |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | fprint (conf, "%1 %2\n", info.name, info.title); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | conf.close (); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | g_primListerMutex = true; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
129 | g_primitives = m_prims; |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
130 | populateCategories (); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | g_primListerMutex = false; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | g_activePrimLister = null; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | emit workDone (); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
136 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
137 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
138 | // ============================================================================= |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | void PrimitiveLister::start () { |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | if (g_activePrimLister) |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | return; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | PrimitiveLister* lister = new PrimitiveLister; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | QThread* listerThread = new QThread; |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | lister->moveToThread (listerThread); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | connect (lister, SIGNAL (starting (ulong)), g_win, SLOT (primitiveLoaderStart (ulong))); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | connect (lister, SIGNAL (update (ulong)), g_win, SLOT (primitiveLoaderUpdate (ulong))); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | connect (lister, SIGNAL (workDone ()), g_win, SLOT (primitiveLoaderEnd ())); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | connect (listerThread, SIGNAL (started ()), lister, SLOT (work ())); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | connect (listerThread, SIGNAL (finished ()), lister, SLOT (deleteLater ())); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | listerThread->start (); |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
154 | static PrimitiveCategory* findCategory (str name) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
155 | for (PrimitiveCategory& cat : g_PrimitiveCategories) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
156 | if (cat.name () == name) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
157 | return &cat; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
159 | return null; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
160 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
161 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
162 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
163 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
164 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
165 | static void populateCategories () { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
166 | for (PrimitiveCategory& cat : g_PrimitiveCategories) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
167 | cat.prims.clear (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
168 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
169 | PrimitiveCategory* unmatched = findCategory ("Other"); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
170 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
171 | if (!unmatched) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
172 | // Shouldn't happen.. but catch it anyway. |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
173 | print ("No `Other` category found! Creating one...\n"); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
174 | PrimitiveCategory cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
175 | cat.setName ("Other"); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
176 | unmatched = &(g_PrimitiveCategories << cat); |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | } |
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
179 | for (Primitive& prim : g_primitives) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
180 | bool matched = false; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
181 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
182 | // 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
|
183 | // the primitive's category is set to the category the regex beloings to. |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
184 | for (PrimitiveCategory& cat : g_PrimitiveCategories) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
185 | for (PrimitiveCategory::RegexEntry& entry : cat.regexes) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
186 | switch (entry.type) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
187 | case PrimitiveCategory::Filename: |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
188 | // f-regex, check against filename |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
189 | matched = entry.regex.exactMatch (prim.name); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
190 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
191 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
192 | case PrimitiveCategory::Title: |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
193 | // t-regex, check against title |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
194 | matched = entry.regex.exactMatch (prim.title); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
195 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
196 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
197 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
198 | if (matched) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
199 | prim.cat = &cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
200 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
201 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
202 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
203 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
204 | // Drop out if a category was decided on. |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
205 | if (prim.cat) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
206 | break; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
207 | } |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
209 | // 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
|
210 | // Otherwise, add it to the list of unmatched primitives. |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
211 | if (prim.cat) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
212 | prim.cat->prims << prim; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
213 | else |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
214 | unmatched->prims << prim; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | } |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
216 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
217 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
218 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
219 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
220 | // ============================================================================= |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
221 | static void loadPrimitiveCatgories () { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
222 | g_PrimitiveCategories.clear (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
223 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
224 | File f (config::dirpath () + "primregexps.cfg", File::Read); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
225 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
226 | if (!f) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
227 | f.open (":/data/primitive-categories.cfg", File::Read); |
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 | if (!f) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
230 | critical ("Failed to open primitive categories!"); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
231 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
232 | if (f) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
233 | PrimitiveCategory cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
234 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
235 | for (str line : f) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
236 | int colon; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
237 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
238 | if (line.length () == 0 || line[0] == '#') |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
239 | continue; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
240 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
241 | if ((colon = line.indexOf (":")) == -1) { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
242 | if (cat.regexes.size () > 0) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
243 | g_PrimitiveCategories << cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
244 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
245 | cat.regexes.clear (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
246 | cat.prims.clear (); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
247 | cat.setName (line); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
248 | } else { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
249 | str cmd = line.left (colon); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
250 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
251 | PrimitiveCategory::Type type = PrimitiveCategory::Filename; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
252 | if (cmd == "f") { |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
253 | type = PrimitiveCategory::Filename; |
319
d0f41342ef51
Show values in file opening prompt
Santeri Piippo <crimsondusk64@gmail.com>
parents:
311
diff
changeset
|
254 | } elif (cmd == "t") { |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
255 | type = PrimitiveCategory::Title; |
294
2892deee4c1b
Better categorized Technic primitives
Santeri Piippo <crimsondusk64@gmail.com>
parents:
293
diff
changeset
|
256 | } else |
2892deee4c1b
Better categorized Technic primitives
Santeri Piippo <crimsondusk64@gmail.com>
parents:
293
diff
changeset
|
257 | continue; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
258 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
259 | QRegExp regex (line.mid (colon + 1)); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
260 | PrimitiveCategory::RegexEntry entry = { regex, type }; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
261 | cat.regexes << entry; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
262 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
263 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
264 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
265 | if (cat.regexes.size () > 0) |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
266 | g_PrimitiveCategories << cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
267 | } |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
268 | |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
269 | // Add a category for unmatched primitives |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
270 | PrimitiveCategory cat; |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
271 | cat.setName ("Other"); |
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
292
diff
changeset
|
272 | g_PrimitiveCategories << cat; |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
273 | } |
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
274 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
275 | // ============================================================================= |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
276 | bool primitiveLoaderBusy() |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
277 | { |
306
fef00a6cbff0
minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
297
diff
changeset
|
278 | return g_primListerMutex; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
279 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
280 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
281 | vector<LDObject*> makePrimitive( PrimitiveType type, int segs, int divs, int num ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
282 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
283 | vector<LDObject*> objs; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
284 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
285 | for( int i = 0; i < segs; ++i ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
286 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
287 | double x0 = cos(( i * 2 * pi ) / divs ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
288 | x1 = cos((( i + 1 ) * 2 * pi) / divs ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
289 | z0 = sin(( i * 2 * pi ) / divs ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
290 | z1 = sin((( i + 1 ) * 2 * pi ) / divs ); |
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 | LDObject* obj = null; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
293 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
294 | switch( type ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
295 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
296 | case Circle: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
297 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
298 | vertex v0( x0, 0.0f, z0 ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
299 | v1( x1, 0.0f, z1 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
300 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
301 | LDLine* line = new LDLine; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
302 | line->setVertex( 0, v0 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
303 | line->setVertex( 1, v1 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
304 | line->setColor( edgecolor ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
305 | obj = line; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
306 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
307 | break; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
308 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
309 | case Cylinder: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
310 | case Ring: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
311 | case Cone: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
312 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
313 | double x2, x3, z2, z3; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
314 | double y0, y1, y2, y3; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
315 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
316 | if( type == Cylinder ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
317 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
318 | x2 = x1; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
319 | x3 = x0; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
320 | z2 = z1; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
321 | z3 = z0; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
322 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
323 | y0 = y1 = 0.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
324 | y2 = y3 = 1.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
325 | } else { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
326 | x2 = x1 * (num + 1); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
327 | x3 = x0 * (num + 1); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
328 | z2 = z1 * (num + 1); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
329 | z3 = z0 * (num + 1); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
330 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
331 | x0 *= num; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
332 | x1 *= num; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
333 | z0 *= num; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
334 | z1 *= num; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
335 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
336 | if( type == Ring ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
337 | y0 = y1 = y2 = y3 = 0.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
338 | else |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
339 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
340 | y0 = y1 = 1.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
341 | y2 = y3 = 0.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
342 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
343 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
344 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
345 | vertex v0( x0, y0, z0 ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
346 | v1( x1, y1, z1 ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
347 | v2( x2, y2, z2 ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
348 | v3( x3, y3, z3 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
349 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
350 | LDQuad* quad = new LDQuad; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
351 | quad->setColor( maincolor ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
352 | quad->setVertex( 0, v0 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
353 | quad->setVertex( 1, v1 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
354 | quad->setVertex( 2, v2 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
355 | quad->setVertex( 3, v3 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
356 | obj = quad; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
357 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
358 | break; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
359 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
360 | case Disc: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
361 | case DiscNeg: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
362 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
363 | double x2, z2; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
364 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
365 | if( type == Disc ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
366 | x2 = z2 = 0.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
367 | else |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
368 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
369 | x2 = ( x0 >= 0.0f ) ? 1.0f : -1.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
370 | z2 = ( z0 >= 0.0f ) ? 1.0f : -1.0f; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
371 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
372 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
373 | vertex v0( x0, 0.0f, z0 ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
374 | v1( x1, 0.0f, z1 ), |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
375 | v2( x2, 0.0f, z2 ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
376 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
377 | // Disc negatives need to go the other way around, otherwise |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
378 | // they'll end up upside-down. |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
379 | LDTriangle* seg = new LDTriangle; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
380 | seg->setColor( maincolor ); |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
381 | seg->setVertex( type == Disc ? 0 : 2, v0 ); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
382 | seg->setVertex( 1, v1 ); |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
383 | seg->setVertex( type == Disc ? 2 : 0, v2 ); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
384 | obj = seg; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
385 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
386 | break; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
387 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
388 | default: |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
389 | break; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
390 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
391 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
392 | if( obj ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
393 | objs << obj; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
394 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
395 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
396 | return objs; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
397 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
398 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
399 | str primitiveTypeName( PrimitiveType type ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
400 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
401 | return type == Circle ? "Circle" : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
402 | type == Cylinder ? "Cylinder" : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
403 | type == Disc ? "Disc" : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
404 | type == DiscNeg ? "Disc Negative" : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
405 | type == Ring ? "Ring" : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
406 | "Cone"; |
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 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
409 | static const str g_radialNameRoots[] = { |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
410 | "edge", |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
411 | "cyli", |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
412 | "disc", |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
413 | "ndis", |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
414 | "ring", |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
415 | "con" |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
416 | }; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
417 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
418 | // ============================================================================= |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
419 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
420 | // ============================================================================= |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
421 | str radialFileName( PrimitiveType type, int segs, int divs, int num ) |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
422 | { |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
423 | short numer = segs, |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
424 | denom = divs; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
425 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
426 | // Simplify the fractional part, but the denominator must be at least 4. |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
427 | simplify( numer, denom ); |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
428 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
429 | if( denom < 4 ) |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
430 | { |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
431 | const short factor = 4 / denom; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
432 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
433 | numer *= factor; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
434 | denom *= factor; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
435 | } |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
436 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
437 | // Compose some general information: prefix, fraction, root, ring number |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
438 | str prefix = (divs == lores) ? "" : fmt( "%1/", divs ); |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
439 | str frac = fmt( "%1-%2", numer, denom ); |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
440 | str root = g_radialNameRoots[type]; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
441 | str numstr = ( type == Ring || type == Cone ) ? fmt ( "%1", num ) : ""; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
442 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
443 | // 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
|
444 | // However, always keep the root at least 2 characters. |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
445 | int extra = ( frac.length() + numstr.length() + root.length() ) - 8; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
446 | root.chop( min<short>( max<short>( extra, 0 ), 2 )); |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
447 | |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
448 | // Stick them all together and return the result. |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
449 | return prefix + frac + root + numstr + ".dat"; |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
450 | } |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
451 | |
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 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
454 | // ============================================================================= |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
455 | void generatePrimitive() |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
456 | { |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
457 | QDialog* dlg = new QDialog( g_win ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
458 | Ui::MakePrimUI ui; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
459 | ui.setupUi( dlg ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
460 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
461 | if( !dlg->exec() ) |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
462 | return; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
463 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
464 | int segs = ui.sb_segs->value(); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
465 | int divs = ui.cb_hires->isChecked() ? hires : lores; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
466 | int num = ui.sb_ringnum->value(); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
467 | PrimitiveType type = |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
468 | ui.rb_circle->isChecked() ? Circle : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
469 | ui.rb_cylinder->isChecked() ? Cylinder : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
470 | ui.rb_disc->isChecked() ? Disc : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
471 | ui.rb_ndisc->isChecked() ? DiscNeg : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
472 | ui.rb_ring->isChecked() ? Ring : |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
473 | Cone; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
474 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
475 | // Make the description |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
476 | str frac = ftoa(( (float) segs ) / divs ); |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
477 | str name = radialFileName( type, segs, divs, num ); |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
478 | str descr; |
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 | // Ensure that there's decimals, even if they're 0. |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
481 | if( frac.indexOf( "." ) == -1 ) |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
482 | frac += ".0"; |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
483 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
484 | if (type == Ring || type == Cone) |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
485 | descr = fmt( "%1 %2 x %3", primitiveTypeName( type ), num, frac ); |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
486 | else |
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
487 | 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
|
488 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
489 | LDOpenFile* f = new LDOpenFile; |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
490 | 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
|
491 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
492 | *f << new LDComment( descr ); |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
493 | *f << new LDComment( fmt( "Name: %1", name )); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
494 | *f << new LDComment( fmt( "Author: LDForge" )); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
495 | *f << new LDComment( fmt( "!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "" )); |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
496 | *f << new LDComment( CALicense ); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
497 | *f << new LDEmpty; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
498 | *f << new LDBFC( LDBFC::CertifyCCW ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
499 | *f << new LDEmpty; |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
500 | *f << makePrimitive( type, segs, divs, num ); |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
306
diff
changeset
|
501 | |
311
c6e38e5e4f33
Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
502 | 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
|
503 | delete f; |
292
4779ca562d5e
Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
504 | } |