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