src/primitives.cpp

Fri, 13 Dec 2013 00:28:24 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 13 Dec 2013 00:28:24 +0200
changeset 554
2478a6b3106d
parent 553
2418d5955421
permissions
-rw-r--r--

- Reworked primitive listing. No longer uses multi-threading.

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
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
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
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
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
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
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>
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
20 #include <QRegExp>
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
21 #include <QFileDialog>
553
2418d5955421 - LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 551
diff changeset
22 #include "document.h"
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "gui.h"
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "primitives.h"
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
25 #include "ui_makeprim.h"
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
26 #include "misc.h"
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
27 #include "colors.h"
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
28 #include "moc_primitives.cpp"
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
30 QList<PrimitiveCategory*> g_PrimitiveCategories;
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
31 QList<Primitive> g_primitives;
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
32 static PrimitiveLister* g_activePrimLister = null;
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
33 PrimitiveCategory* g_unmatched = null;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
34
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
35 extern_cfg (String, ld_defaultname);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
36 extern_cfg (String, ld_defaultuser);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
37 extern_cfg (Int, ld_defaultlicense);
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
38
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
39 static const str g_radialNameRoots[] =
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
40 { "edge",
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 436
diff changeset
41 "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
42 "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
43 "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
44 "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
45 "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
46 };
321
48e429bfd58c Apply tr() for possible future translations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
47
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
48 PrimitiveLister* getPrimitiveLister()
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
49 { return g_activePrimLister;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
50 }
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
51
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
52 // =============================================================================
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
53 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
54 void loadPrimitives()
513
29eb671b34f6 Added a crash catcher which trigger under Linux. It calls GDB and tries to get a backtrace. Also integrated assertion failure handling to this new system. Removed the print() function in the process (because the new bomb box uses a text edit and QTextDocuments's print method clashes with the macro and I figured it was a good idea to rid it anyway) and replaced all calls with log().
Santeri Piippo <crimsondusk64@gmail.com>
parents: 508
diff changeset
55 { log ("Loading primitives...\n");
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
56 PrimitiveCategory::loadCategories();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
57
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
58 // Try to load prims.cfg
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 460
diff changeset
59 File conf (Config::filepath ("prims.cfg"), File::Read);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
60
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
61 if (!conf)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
62 { // No prims.cfg, build it
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
63 PrimitiveLister::start();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
64 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
65 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
66 { // Read primitives from prims.cfg
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
67 for (str line : conf)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
68 { int space = line.indexOf (" ");
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
69
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
70 if (space == -1)
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
71 continue;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
72
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
73 Primitive info;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
74 info.name = line.left (space);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
75 info.title = line.mid (space + 1);
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
76 g_primitives << info;
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
77 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
78
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
79 PrimitiveCategory::populateCategories();
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
80 }
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
81 }
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 // =============================================================================
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
84 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
85 static void recursiveGetFilenames (QDir dir, QList<str>& fnames)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
86 { QFileInfoList flist = dir.entryInfoList();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
87
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
88 for (const QFileInfo & info : flist)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
89 { if (info.fileName() == "." || info.fileName() == "..")
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 continue; // skip . and ..
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
91
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
92 if (info.isDir())
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
93 recursiveGetFilenames (QDir (info.absoluteFilePath()), fnames);
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 else
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
95 fnames << info.absoluteFilePath();
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 }
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
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
99 // =============================================================================
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
100 // -----------------------------------------------------------------------------
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
101 PrimitiveLister::PrimitiveLister (QObject* parent) :
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
102 QObject (parent),
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
103 m_i (0)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
104 { g_activePrimLister = this;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
105 QDir dir (LDPaths::prims());
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
106 assert (dir.exists());
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
107 m_baselen = dir.absolutePath().length();
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
108 recursiveGetFilenames (dir, m_files);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
109 emit starting (m_files.size());
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
110 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
111
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
112 // =============================================================================
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
113 // -----------------------------------------------------------------------------
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
114 PrimitiveLister::~PrimitiveLister()
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
115 { g_activePrimLister = null;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
116 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
117
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
118 // =============================================================================
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
119 // -----------------------------------------------------------------------------
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
120 void PrimitiveLister::work()
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
121 { int j = min (m_i + 300, m_files.size());
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
122 log ("PrimitiveLister::work: %1 -> %2\n", m_i, j);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
123
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
124 for (; m_i < j; ++m_i)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
125 { str fname = m_files[m_i];
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
126 File f (fname, File::Read);
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 Primitive info;
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
128 info.name = fname.mid (m_baselen + 1); // make full path relative
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
129 info.name.replace ('/', '\\'); // use DOS backslashes, they're expected
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
130 info.cat = null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
131
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
132 if (!f.readLine (info.title))
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 info.title = "";
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
134
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
135 info.title = info.title.simplified();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
136
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
137 if (info.title[0] == '0')
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
138 { info.title.remove (0, 1); // remove 0
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
139 info.title = info.title.simplified();
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
141
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 m_prims << info;
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
144
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
145 if (m_i == m_files.size())
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
146 { // Done with primitives, now save to a config file
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
147 File conf (Config::filepath ("prims.cfg"), File::Write);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
148
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
149 for (Primitive& info : m_prims)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
150 fprint (conf, "%1 %2\n", info.name, info.title);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
151
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
152 conf.close();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
153
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
154 g_primitives = m_prims;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
155 PrimitiveCategory::populateCategories();
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
156 log ("%1 primitives listed", g_primitives.size());
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
157 g_activePrimLister = null;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
158 emit workDone();
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
159 deleteLater();
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
160 }
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
161 else
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
162 { // Defer to event loop, pick up the work later
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
163 emit update (m_i);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
164 QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
165 }
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 }
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
168 // =============================================================================
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
169 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
170 void PrimitiveLister::start()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
171 { if (g_activePrimLister)
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
173
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 PrimitiveLister* lister = new PrimitiveLister;
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
175 /*
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
176 connect (lister, SIGNAL (starting (int)), g_win, SLOT (primitiveLoaderStart (int)));
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
177 connect (lister, SIGNAL (update (int)), g_win, SLOT (primitiveLoaderUpdate (int)));
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
178 connect (lister, SIGNAL (workDone()), g_win, SLOT (primitiveLoaderEnd()));
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
179 */
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
180 lister->work();
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 }
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
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
183 // =============================================================================
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
184 // -----------------------------------------------------------------------------
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
185 PrimitiveCategory::PrimitiveCategory (str name, QObject* parent) :
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
186 QObject (parent),
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
187 m_Name (name) {}
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
188
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
189 // =============================================================================
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
190 // -----------------------------------------------------------------------------
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
191 void PrimitiveCategory::populateCategories()
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
192 { for (PrimitiveCategory* cat : g_PrimitiveCategories)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
193 cat->prims.clear();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
194
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
195
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
196 for (Primitive& prim : g_primitives)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
197 { 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
198 prim.cat = null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
199
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
200 // 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
201 // the primitive's category is set to the category the regex beloings to.
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
202 for (PrimitiveCategory* cat : g_PrimitiveCategories)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
203 { for (RegexEntry& entry : cat->regexes)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
204 { switch (entry.type)
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
205 { case EFilenameRegex:
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
206 { // f-regex, check against filename
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
207 matched = entry.regex.exactMatch (prim.name);
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
208 } break;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
209
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
210 case ETitleRegex:
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
211 { // t-regex, check against title
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
212 matched = entry.regex.exactMatch (prim.title);
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
213 } break;
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
214 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
215
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
216 if (matched)
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
217 { prim.cat = 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 }
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
220 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
221
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
222 // Drop out if a category was decided on.
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
223 if (prim.cat != null)
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
224 break;
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
225 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
226
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
227 // 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
228 // Otherwise, add it to the list of unmatched primitives.
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
229 if (prim.cat != null)
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
230 prim.cat->prims << prim;
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
231 else
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
232 g_unmatched->prims << prim;
292
4779ca562d5e Moved primitive handling to new code files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 }
293
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
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
236 // =============================================================================
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
237 // -----------------------------------------------------------------------------
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
238 void PrimitiveCategory::loadCategories()
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
239 { for (PrimitiveCategory* cat : g_PrimitiveCategories)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
240 delete cat;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
241
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
242 g_PrimitiveCategories.clear();
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 460
diff changeset
243 File f (Config::dirpath() + "primregexps.cfg", File::Read);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
244
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
245 if (!f)
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
246 f.open (":/data/primitive-categories.cfg", File::Read);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
247
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
248 if (!f)
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
249 { critical (QObject::tr ("Failed to open primitive categories!"));
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
250 return;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
251 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
252
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
253 if (f)
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
254 { PrimitiveCategory* cat = null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
255
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
256 for (str line : f)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
257 { int colon;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
258
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
259 if (line.length() == 0 || line[0] == '#')
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
260 continue;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
261
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
262 if ((colon = line.indexOf (":")) == -1)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
263 { if (cat && cat->isValidToInclude())
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
264 g_PrimitiveCategories << cat;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
265
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
266 cat = new PrimitiveCategory (line);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
267 }
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
268 elif (cat != null)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
269 { str cmd = line.left (colon);
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
270 ERegexType type = EFilenameRegex;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
271
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
272 if (cmd == "f")
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
273 type = EFilenameRegex;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
274 elif (cmd == "t")
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
275 type = ETitleRegex;
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 321
diff changeset
276 else
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
277 { log (tr ("Warning: unknown command \"%1\" on line \"%2\""), cmd, line);
294
2892deee4c1b Better categorized Technic primitives
Santeri Piippo <crimsondusk64@gmail.com>
parents: 293
diff changeset
278 continue;
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
279 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
280
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
281 QRegExp regex (line.mid (colon + 1));
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
282 RegexEntry entry = { regex, type };
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
283 cat->regexes << entry;
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
284 }
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
285 else
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
286 log ("Warning: Rules given before the first category name");
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
287 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
288
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
289 if (cat->isValidToInclude())
293
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
290 g_PrimitiveCategories << cat;
a0ed563e14b2 Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents: 292
diff changeset
291 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
292
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
293 // Add a category for unmatched primitives.
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
294 // Note: if this function is called the second time, g_unmatched has been
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
295 // deleted at the beginning of the function and is dangling at this point.
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
296 g_unmatched = new PrimitiveCategory (tr ("Other"));
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
297 g_PrimitiveCategories << g_unmatched;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
298 }
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
299
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
300 // =============================================================================
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
301 // -----------------------------------------------------------------------------
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
302 bool PrimitiveCategory::isValidToInclude()
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
303 { if (regexes.size() == 0)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
304 { log (tr ("Warning: category \"%1\" left without patterns"), getName());
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
305 deleteLater();
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
306 return false;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
307 }
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
308
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
309 return true;
306
fef00a6cbff0 minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 297
diff changeset
310 }
fef00a6cbff0 minor improvements to primitive handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 297
diff changeset
311
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
312 // =============================================================================
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
313 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
314 bool isPrimitiveLoaderBusy()
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
315 { return g_activePrimLister != null;
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
316 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
317
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
318 // =============================================================================
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
319 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
320 static double radialPoint (int i, int divs, double (*func) (double))
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
321 { return (*func) ((i * 2 * pi) / divs);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
322 }
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
323
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
324 // =============================================================================
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
325 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
326 void makeCircle (int segs, int divs, double radius, QList<QLineF>& lines)
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
327 { for (int i = 0; i < segs; ++i)
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
328 { double x0 = radius * radialPoint (i, divs, cos),
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
329 x1 = radius * radialPoint (i + 1, divs, cos),
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
330 z0 = radius * radialPoint (i, divs, sin),
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
331 z1 = radius * radialPoint (i + 1, divs, sin);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
332
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
333 lines << QLineF (QPointF (x0, z0), QPointF (x1, z1));
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
334 }
363
75583c9f289d primitive generator: add conditional lines to cylinders; improved bad color handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
335 }
75583c9f289d primitive generator: add conditional lines to cylinders; improved bad color handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
336
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
337 // =============================================================================
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
338 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
339 QList<LDObject*> makePrimitive (PrimitiveType type, int segs, int divs, int num)
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
340 { QList<LDObject*> objs;
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
341 QList<int> condLineSegs;
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
342 QList<QLineF> circle;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
343
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
344 makeCircle (segs, divs, 1, circle);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
345
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
346 for (int i = 0; i < segs; ++i)
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
347 { double x0 = circle[i].x1(),
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
348 x1 = circle[i].x2(),
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
349 z0 = circle[i].y1(),
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
350 z1 = circle[i].y2();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
351
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
352 switch (type)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
353 { case Circle:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
354 { vertex v0 (x0, 0.0f, z0),
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
355 v1 (x1, 0.0f, z1);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
356
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
357 LDLine* line = new LDLine;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
358 line->setVertex (0, v0);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
359 line->setVertex (1, v1);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
360 line->setColor (edgecolor);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
361 objs << line;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
362 } break;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
363
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
364 case Cylinder:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
365 case Ring:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
366 case Cone:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
367 { double x2, x3, z2, z3;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
368 double y0, y1, y2, y3;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
369
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
370 if (type == Cylinder)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
371 { x2 = x1;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
372 x3 = x0;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
373 z2 = z1;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
374 z3 = z0;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
375
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
376 y0 = y1 = 0.0f;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
377 y2 = y3 = 1.0f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
378 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
379 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
380 { x2 = x1 * (num + 1);
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
381 x3 = x0 * (num + 1);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
382 z2 = z1 * (num + 1);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
383 z3 = z0 * (num + 1);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
384
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
385 x0 *= num;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
386 x1 *= num;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
387 z0 *= num;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
388 z1 *= num;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
389
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
390 if (type == Ring)
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
391 y0 = y1 = y2 = y3 = 0.0f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
392 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
393 { y0 = y1 = 1.0f;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
394 y2 = y3 = 0.0f;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
395 }
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
396 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
397
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
398 vertex v0 (x0, y0, z0),
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
399 v1 (x1, y1, z1),
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
400 v2 (x2, y2, z2),
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
401 v3 (x3, y3, z3);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
402
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
403 LDQuad* quad = new LDQuad;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
404 quad->setColor (maincolor);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
405 quad->setVertex (0, v0);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
406 quad->setVertex (1, v1);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
407 quad->setVertex (2, v2);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
408 quad->setVertex (3, v3);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
409
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
410 if (type == Cylinder)
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
411 quad->invert();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
412
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
413 objs << quad;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
414
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
415 if (type == Cylinder || type == Cone)
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
416 condLineSegs << i;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
417 } break;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
418
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
419 case Disc:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
420 case DiscNeg:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
421 { double x2, z2;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
422
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
423 if (type == Disc)
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
424 x2 = z2 = 0.0f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
425 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
426 { x2 = (x0 >= 0.0f) ? 1.0f : -1.0f;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
427 z2 = (z0 >= 0.0f) ? 1.0f : -1.0f;
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
428 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
429
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
430 vertex v0 (x0, 0.0f, z0),
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
431 v1 (x1, 0.0f, z1),
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
432 v2 (x2, 0.0f, z2);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
433
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
434 // Disc negatives need to go the other way around, otherwise
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
435 // 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
436 LDTriangle* seg = new LDTriangle;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
437 seg->setColor (maincolor);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
438 seg->setVertex (type == Disc ? 0 : 2, v0);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
439 seg->setVertex (1, v1);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
440 seg->setVertex (type == Disc ? 2 : 0, v2);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
441 objs << seg;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
442 } break;
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
443 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
444 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
445
365
b3f6c93db2e4 further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
446 // 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
447 // end, too.
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
448 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
449 condLineSegs << segs;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
450
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
451 for (int i : condLineSegs)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
452 { vertex v0 (radialPoint (i, divs, cos), 0.0f, radialPoint (i, divs, sin)),
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
453 v1,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
454 v2 (radialPoint (i + 1, divs, cos), 0.0f, radialPoint (i + 1, divs, sin)),
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
455 v3 (radialPoint (i - 1, divs, cos), 0.0f, radialPoint (i - 1, divs, sin));
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
456
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
457 if (type == Cylinder)
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
458 v1 = vertex (v0[X], 1.0f, v0[Z]);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
459 elif (type == Cone)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
460 { 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
461 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
462 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
463 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
464 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
465
551
0efe5dbcef07 renamed LDCndLine to LDCondLine
Santeri Piippo <crimsondusk64@gmail.com>
parents: 539
diff changeset
466 LDCondLine* line = new LDCondLine;
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
467 line->setColor (edgecolor);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
468 line->setVertex (0, v0);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
469 line->setVertex (1, v1);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
470 line->setVertex (2, v2);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
471 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
472 objs << line;
b3f6c93db2e4 further work on primitive cond-lines. I think I got it now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
473 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
474
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
475 return objs;
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
476 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
477
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
478 // =============================================================================
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
479 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
480 static str primitiveTypeName (PrimitiveType type)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
481 { // 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
482 return type == Circle ? "Circle" :
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
483 type == Cylinder ? "Cylinder" :
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
484 type == Disc ? "Disc" :
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
485 type == DiscNeg ? "Disc Negative" :
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
486 type == Ring ? "Ring" : "Cone";
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
487 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
488
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
489 // =============================================================================
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
490 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
491 str radialFileName (PrimitiveType type, int segs, int divs, int num)
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
492 { int numer = segs,
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
493 denom = divs;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
494
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
495 // Simplify the fractional part, but the denominator must be at least 4.
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
496 simplify (numer, denom);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
497
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
498 if (denom < 4)
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
499 { const int factor = 4 / denom;
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
500 numer *= factor;
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
501 denom *= factor;
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
502 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
503
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
504 // Compose some general information: prefix, fraction, root, ring number
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
505 str prefix = (divs == lores) ? "" : fmt ("%1/", divs);
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
506 str frac = fmt ("%1-%2", numer, denom);
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
507 str root = g_radialNameRoots[type];
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
508 str numstr = (type == Ring || type == Cone) ? fmt ("%1", num) : "";
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
509
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
510 // 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
511 // However, always keep the root at least 2 characters.
398
7f278b48079a restyle
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
512 int extra = (frac.length() + numstr.length() + root.length()) - 8;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
513 root.chop (clamp (extra, 0, 2));
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
514
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
515 // Stick them all together and return the result.
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
516 return prefix + frac + root + numstr + ".dat";
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
517 }
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
518
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 306
diff changeset
519 // =============================================================================
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
520 // -----------------------------------------------------------------------------
553
2418d5955421 - LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 551
diff changeset
521 LDDocument* generatePrimitive (PrimitiveType type, int segs, int divs, int num)
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
522 { // Make the description
508
7ace3537a560 removed some custom functions in favor of Qt implementations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
523 str frac = str::number ((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
524 str name = radialFileName (type, segs, divs, num);
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
525 str descr;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
526
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
527 // 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
528 if (frac.indexOf (".") == -1)
311
c6e38e5e4f33 Further work on the primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
529 frac += ".0";
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
530
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
531 if (type == Ring || type == Cone)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
532 { str spacing =
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
533 (num < 10) ? " " :
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
534 (num < 100) ? " " : "";
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
535
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
536 descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
537 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
538 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
539 descr = fmt ("%1 %2", primitiveTypeName (type), frac);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
540
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
541 // 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
542 if (divs == hires)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
543 descr.insert (0, "Hi-Res ");
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
544
553
2418d5955421 - LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 551
diff changeset
545 LDDocument* f = new LDDocument;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
546 f->setDefaultName (name);
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
547
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
548 str author = APPNAME;
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
549 str license = "";
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
550
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
551 if (ld_defaultname.value.isEmpty() == false)
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
552 { license = getLicenseText (ld_defaultlicense);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
553 author = fmt ("%1 [%2]", ld_defaultname, ld_defaultuser);
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
554 }
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
555
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
556 f->addObjects (
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
557 { new LDComment (descr),
484
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 475
diff changeset
558 new LDComment (fmt ("Name: %1", name)),
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
559 new LDComment (fmt ("Author: %1", author)),
484
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 475
diff changeset
560 new LDComment (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "")),
554
2478a6b3106d - Reworked primitive listing. No longer uses multi-threading.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
561 new LDComment (license),
484
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 475
diff changeset
562 new LDEmpty,
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 475
diff changeset
563 new LDBFC (LDBFC::CertifyCCW),
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 475
diff changeset
564 new LDEmpty,
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 475
diff changeset
565 });
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
566
484
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 475
diff changeset
567 f->addObjects (makePrimitive (type, segs, divs, num));
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
568 return f;
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
569 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
570
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
571 // =============================================================================
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
572 // -----------------------------------------------------------------------------
553
2418d5955421 - LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 551
diff changeset
573 LDDocument* getPrimitive (PrimitiveType type, int segs, int divs, int num)
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
574 { str name = radialFileName (type, segs, divs, num);
553
2418d5955421 - LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 551
diff changeset
575 LDDocument* f = getDocument (name);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
576
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
577 if (f != null)
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
578 return f;
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
579
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
580 return generatePrimitive (type, segs, divs, num);
408
81dc5f6b9c73 - fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 407
diff changeset
581 }
81dc5f6b9c73 - fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 407
diff changeset
582
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
583 // =============================================================================
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
584 // -----------------------------------------------------------------------------
408
81dc5f6b9c73 - fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 407
diff changeset
585 PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) :
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
586 QDialog (parent, f)
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
587 { ui = new Ui_MakePrimUI;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
588 ui->setupUi (this);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
589 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
590 }
81dc5f6b9c73 - fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 407
diff changeset
591
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
592 // =============================================================================
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
593 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
594 PrimitivePrompt::~PrimitivePrompt()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
595 { delete ui;
408
81dc5f6b9c73 - fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 407
diff changeset
596 }
81dc5f6b9c73 - fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 407
diff changeset
597
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
598 // =============================================================================
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
599 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
600 void PrimitivePrompt::hiResToggled (bool on)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
601 { ui->sb_segs->setMaximum (on ? hires : lores);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
602
408
81dc5f6b9c73 - fixed: checking the hi-res option would not allow segment values over 16.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 407
diff changeset
603 // 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
604 // spinbox to 48.
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
605 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
606 ui->sb_segs->setValue (hires);
491
7d1b5ecd76c0 it's LDForge's 1st birthday!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 484
diff changeset
607 }
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
608
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
609 // =============================================================================
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
610 // -----------------------------------------------------------------------------
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
611 DEFINE_ACTION (MakePrimitive, 0)
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
612 { PrimitivePrompt* dlg = new PrimitivePrompt (g_win);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
613
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
614 if (!dlg->exec())
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
615 return;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
616
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
617 int segs = dlg->ui->sb_segs->value();
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
618 int divs = dlg->ui->cb_hires->isChecked() ? hires : lores;
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
619 int num = dlg->ui->sb_ringnum->value();
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
620 PrimitiveType type =
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
621 dlg->ui->rb_circle->isChecked() ? Circle :
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
622 dlg->ui->rb_cylinder->isChecked() ? Cylinder :
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
623 dlg->ui->rb_disc->isChecked() ? Disc :
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
624 dlg->ui->rb_ndisc->isChecked() ? DiscNeg :
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
625 dlg->ui->rb_ring->isChecked() ? Ring : Cone;
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
626
553
2418d5955421 - LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 551
diff changeset
627 LDDocument* f = generatePrimitive (type, segs, divs, num);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
628
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
629 g_win->save (f, false);
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
630 delete f;
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
631 }

mercurial