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