Tue, 20 Aug 2013 14:47:21 +0300
- added "Go to line" action, renamed the config classes to proper camelcase
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
378 | 4 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
378 | 9 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
378 | 14 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
199
10dd5909a50e
Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
198
diff
changeset
|
19 | #include <QMessageBox> |
225
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
20 | #include <QFileDialog> |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QDir> |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
22 | #include <QApplication> |
202
a027f6fc6141
Un-templated CheckBoxGroup, moved it and RadioButton into widgets.cpp/widgets.h; removed license text tab because I think LICENSE is enough.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
200
diff
changeset
|
23 | |
213
a4113545242c
Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
24 | #include <stdlib.h> |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "common.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "config.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include "file.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | #include "misc.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "gui.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "history.h" |
200
5583af82087e
Merged new part and LDraw path dialogs into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
199
diff
changeset
|
31 | #include "dialogs.h" |
198
f246725199dc
Split some stuff into separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
192
diff
changeset
|
32 | #include "gldraw.h" |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
33 | #include "build/moc_file.cpp" |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
35 | cfg (String, io_ldpath, ""); |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
36 | cfg (String, io_recentfiles, ""); |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
37 | extern_cfg (String, net_downloadpath); |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
38 | extern_cfg (Bool, gl_logostuds); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
40 | static bool g_loadingMainFile = false; |
309 | 41 | static const int g_MaxRecentFiles = 5; |
320
737e466dae72
rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
319
diff
changeset
|
42 | static bool g_aborted = false; |
458
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
43 | static LDFile* g_logoedStud = null; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
44 | static LDFile* g_logoedStud2 = null; |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
45 | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
46 | LDFile* LDFile::m_curfile = null; |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
47 | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
48 | DEFINE_PROPERTY (QListWidgetItem*, LDFile, listItem, setListItem) |
383
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
49 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
51 | // ----------------------------------------------------------------------------- |
378 | 52 | namespace LDPaths { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | static str pathError; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
55 | struct { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | str LDConfigPath; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | str partsPath, primsPath; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | } pathInfo; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
60 | void initPaths() { |
378 | 61 | if (!tryConfigure (io_ldpath)) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | LDrawPathDialog dlg (false); |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
64 | if (!dlg.exec()) |
378 | 65 | exit (0); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | |
309 | 67 | io_ldpath = dlg.filename(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | |
378 | 71 | bool tryConfigure (str path) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | QDir dir; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
378 | 74 | if (!dir.cd (path)) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | pathError = "Directory does not exist."; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
309 | 79 | QStringList mustHave = { "LDConfig.ldr", "parts", "p" }; |
378 | 80 | QStringList contents = dir.entryList (mustHave); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
378 | 82 | if (contents.size() != mustHave.size()) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/."; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
378 | 87 | pathInfo.partsPath = fmt ("%1" DIRSLASH "parts", path); |
88 | pathInfo.LDConfigPath = fmt ("%1" DIRSLASH "LDConfig.ldr", path); | |
89 | pathInfo.primsPath = fmt ("%1" DIRSLASH "p", path); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | // Accessors |
309 | 95 | str getError() { return pathError; } |
96 | str ldconfig() { return pathInfo.LDConfigPath; } | |
97 | str prims() { return pathInfo.primsPath; } | |
98 | str parts() { return pathInfo.partsPath; } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
102 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
103 | LDFile::LDFile() { |
378 | 104 | setImplicit (true); |
105 | setSavePos (-1); | |
383
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
106 | setListItem (null); |
378 | 107 | m_history.setFile (this); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
111 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
112 | LDFile::~LDFile() { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | // Clear everything from the model |
378 | 114 | for (LDObject* obj : m_objs) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | delete obj; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | // Clear the cache as well |
378 | 118 | for (LDObject* obj : m_cache) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | delete obj; |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
120 | |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
121 | // Remove this file from the list of files |
393
01fffd08c25a
some rework with closing files, not right there, seems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
391
diff
changeset
|
122 | for (ulong i = 0; i < g_loadedFiles.size(); ++i) { |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
123 | if (g_loadedFiles[i] == this) { |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
124 | g_loadedFiles.erase (i); |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
125 | break; |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
126 | } |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
127 | } |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
128 | |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
129 | // If we just closed the current file, we need to set the current |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
130 | // file as something else. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
131 | if (this == LDFile::current()) { |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
132 | // If we closed the last file, create a blank one. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
133 | if (g_loadedFiles.size() == 0) |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
134 | newFile(); |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
135 | else |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
136 | LDFile::setCurrent (g_loadedFiles[0]); |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
137 | } |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
138 | |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
139 | g_win->updateFileList(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
143 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
144 | LDFile* findLoadedFile (str name) { |
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
145 | for (LDFile* file : g_loadedFiles) |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
146 | if (file->name() == name) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | return file; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | return null; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
153 | // ----------------------------------------------------------------------------- |
378 | 154 | str dirname (str path) { |
155 | long lastpos = path.lastIndexOf (DIRSLASH); | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
156 | |
378 | 157 | if (lastpos > 0) |
158 | return path.left (lastpos); | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
159 | |
236
b58d35dc5d52
Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents:
235
diff
changeset
|
160 | #ifndef _WIN32 |
378 | 161 | if (path[0] == DIRSLASH_CHAR) |
236
b58d35dc5d52
Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents:
235
diff
changeset
|
162 | return DIRSLASH; |
b58d35dc5d52
Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents:
235
diff
changeset
|
163 | #endif // _WIN32 |
b58d35dc5d52
Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents:
235
diff
changeset
|
164 | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
165 | return ""; |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
166 | } |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
167 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
169 | // ----------------------------------------------------------------------------- |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
170 | str basename (str path) { |
378 | 171 | long lastpos = path.lastIndexOf (DIRSLASH); |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
172 | |
378 | 173 | if (lastpos != -1) |
174 | return path.mid (lastpos + 1); | |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
175 | |
235 | 176 | return path; |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
177 | } |
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
178 | |
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
179 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
180 | // ----------------------------------------------------------------------------- |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
181 | File* openLDrawFile (str relpath, bool subdirs) { |
378 | 182 | print ("%1: Try to open %2\n", __func__, relpath); |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
183 | File* f = new File; |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
184 | str fullPath; |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
185 | |
309 | 186 | // LDraw models use Windows-style path separators. If we're not on Windows, |
187 | // replace the path separator now before opening any files. | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | #ifndef WIN32 |
378 | 189 | relpath.replace ("\\", "/"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | #endif // WIN32 |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
192 | if (LDFile::current()) { |
309 | 193 | // First, try find the file in the current model's file path. We want a file |
194 | // in the immediate vicinity of the current model to override stock LDraw stuff. | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
195 | str partpath = fmt ("%1" DIRSLASH "%2", dirname (LDFile::current()->name()), relpath); |
213
a4113545242c
Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
196 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
197 | if (f->open (partpath, File::Read)) |
378 | 198 | return f; |
199 | } | |
213
a4113545242c
Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
200 | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
201 | if (f->open (relpath, File::Read)) |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
202 | return f; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
204 | // Try with just the LDraw path first |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
205 | fullPath = fmt ("%1" DIRSLASH "%2", io_ldpath, relpath); |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
206 | |
378 | 207 | if (f->open (fullPath, File::Read)) |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
208 | return f; |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
209 | |
378 | 210 | if (subdirs) { |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
211 | // Look in sub-directories: parts and p. Also look in net_downloadpath. |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
212 | for (const str& topdir : initlist<str> ({ io_ldpath, net_downloadpath })) |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
213 | for (const str& subdir : initlist<str> ({ "parts", "p" })) { |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
214 | fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath); |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
215 | if (f->open (fullPath, File::Read)) |
378 | 216 | return f; |
217 | } | |
218 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | |
309 | 220 | // Did not find the file. |
378 | 221 | print ("could not find %1\n", relpath); |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
222 | delete f; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | return null; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
227 | // ----------------------------------------------------------------------------- |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
228 | void FileLoader::start() { |
378 | 229 | setDone (false); |
230 | setProgress (0); | |
231 | setAborted (false); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | |
378 | 233 | if (concurrent()) { |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
234 | g_aborted = false; |
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
235 | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
236 | // Show a progress dialog if we're loading the main file here and move |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
237 | // the actual work to a separate thread as this can be a rather intensive |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
238 | // operation and if we don't respond quickly enough, the program can be |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
239 | // deemed inresponsive.. which is a bad thing. |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
240 | dlg = new OpenProgressDialog (g_win); |
378 | 241 | dlg->setNumLines (lines().size()); |
242 | dlg->setModal (true); | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
243 | dlg->show(); |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
244 | |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
245 | // Connect the loader in so we can show updates |
378 | 246 | connect (this, SIGNAL (workDone()), dlg, SLOT (accept())); |
247 | connect (dlg, SIGNAL (rejected()), this, SLOT (abort())); | |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
248 | } else |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
249 | dlg = null; |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
250 | |
378 | 251 | work (0); |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
252 | } |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
253 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
254 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
255 | // ----------------------------------------------------------------------------- |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
256 | void FileLoader::work (int i) { |
378 | 257 | if (aborted()) { |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
258 | // We were flagged for abortion, so abort. |
378 | 259 | for (LDObject* obj : m_objs) |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
260 | delete obj; |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
261 | |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
262 | m_objs.clear(); |
378 | 263 | setDone (true); |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
264 | return; |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
265 | } |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
266 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
267 | int max = i + 300; |
378 | 268 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
269 | for (; i < max && i < (int) lines().size(); ++i) { |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
270 | str line = lines()[i]; |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
271 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | // Trim the trailing newline |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
276
diff
changeset
|
273 | qchar c; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
275 | while ((c = line[line.length() - 1]) == '\n' || c == '\r') |
378 | 276 | line.chop (1); |
277 | ||
278 | LDObject* obj = parseLine (line); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | // Check for parse errors and warn about tthem |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
281 | if (obj->getType() == LDObject::Error) { |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
282 | log ("Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDError*> (obj)->reason); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
284 | if (m_warningsPointer) |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
285 | (*m_warningsPointer)++; |
378 | 286 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | |
252
3f9067022d74
Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents:
251
diff
changeset
|
288 | m_objs << obj; |
378 | 289 | setProgress (i); |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
290 | |
378 | 291 | if (concurrent()) |
292 | dlg->updateProgress (i); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
295 | if (i >= ((int) lines().size()) - 1) { |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
296 | emit workDone(); |
378 | 297 | setDone (true); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
298 | return; |
378 | 299 | } |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
300 | |
378 | 301 | if (!done()) { |
302 | if (concurrent()) | |
303 | QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (ulong, i + 1)); | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
304 | else |
378 | 305 | work (i + 1); |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
306 | } |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
307 | } |
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
308 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
309 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
310 | // ----------------------------------------------------------------------------- |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
311 | void FileLoader::abort() { |
378 | 312 | setAborted (true); |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
313 | |
378 | 314 | if (concurrent()) |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
315 | g_aborted = true; |
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
316 | } |
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
317 | |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
318 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
319 | // ----------------------------------------------------------------------------- |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
320 | List<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) { |
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
321 | List<str> lines; |
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
322 | List<LDObject*> objs; |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
323 | |
378 | 324 | if (numWarnings) |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
325 | *numWarnings = 0; |
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
326 | |
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
327 | // Calculate the amount of lines |
378 | 328 | for (str line : *f) |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
329 | lines << line; |
378 | 330 | |
309 | 331 | f->rewind(); |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
332 | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
333 | FileLoader* loader = new FileLoader; |
378 | 334 | loader->setWarningsPointer (numWarnings); |
335 | loader->setLines (lines); | |
336 | loader->setConcurrent (g_loadingMainFile); | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
337 | loader->start(); |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
338 | |
378 | 339 | while (loader->done() == false) |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
340 | qApp->processEvents(); |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
341 | |
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
342 | // If we wanted the success value, supply that now |
378 | 343 | if (ok) |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
344 | *ok = !loader->aborted(); |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
345 | |
370
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
346 | objs = loader->objs(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | return objs; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
348 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
351 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
352 | LDFile* openDATFile (str path, bool search) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | // Convert the file name to lowercase since some parts contain uppercase |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | // file names. I'll assume here that the library will always use lowercase |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | // file names for the actual parts.. |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
356 | File* f; |
378 | 357 | |
358 | if (search) | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
359 | f = openLDrawFile (path.toLower(), true); |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
360 | else { |
378 | 361 | f = new File (path, File::Read); |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
362 | |
378 | 363 | if (!*f) { |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
364 | delete f; |
378 | 365 | return null; |
366 | } | |
367 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
368 | |
378 | 369 | if (!f) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | return null; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
371 | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
372 | LDFile* load = new LDFile; |
378 | 373 | load->setName (path); |
213
a4113545242c
Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
374 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | ulong numWarnings; |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
376 | bool ok; |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
377 | List<LDObject*> objs = loadFileContents (f, &numWarnings, &ok); |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
378 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
379 | if (!ok) |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
380 | return null; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
381 | |
378 | 382 | for (LDObject* obj : objs) |
383 | load->addObject (obj); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
385 | delete f; |
252
3f9067022d74
Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents:
251
diff
changeset
|
386 | g_loadedFiles << load; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
387 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
388 | if (g_loadingMainFile) { |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
389 | LDFile::setCurrent (load); |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
390 | g_win->R()->setFile (load); |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
391 | log (QObject::tr ("File %1 parsed successfully (%2 errors)."), path, numWarnings); |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
392 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
394 | return load; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
395 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
396 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
397 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
398 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
399 | bool LDFile::safeToClose() { |
309 | 400 | typedef QMessageBox msgbox; |
378 | 401 | setlocale (LC_ALL, "C"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
402 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
403 | // If we have unsaved changes, warn and give the option of saving. |
383
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
404 | if (hasUnsavedChanges()) { |
378 | 405 | str message = fmt ("There are unsaved changes to %1. Should it be saved?", |
406 | (name().length() > 0) ? name() : "<anonymous>"); | |
407 | ||
408 | int button = msgbox::question (g_win, "Unsaved Changes", message, | |
409 | (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel); | |
410 | ||
411 | switch (button) { | |
309 | 412 | case msgbox::Yes: |
225
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
413 | // If we don't have a file path yet, we have to ask the user for one. |
378 | 414 | if (name().length() == 0) { |
415 | str newpath = QFileDialog::getSaveFileName (g_win, "Save As", | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
416 | LDFile::current()->name(), "LDraw files (*.dat *.ldr)"); |
225
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
417 | |
378 | 418 | if (newpath.length() == 0) |
225
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
419 | return false; |
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
420 | |
378 | 421 | setName (newpath); |
225
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
422 | } |
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
423 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
424 | if (!save()) { |
378 | 425 | message = fmt (QObject::tr ("Failed to save %1: %2\nDo you still want to close?"), |
426 | name(), strerror (errno)); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
427 | |
378 | 428 | if (msgbox::critical (g_win, "Save Failure", message, |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
429 | (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
430 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
431 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
432 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
433 | break; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
434 | |
309 | 435 | case msgbox::Cancel: |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
436 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
437 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
438 | default: |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
439 | break; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
440 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
441 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
442 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
443 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
444 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
445 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
446 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
447 | // ----------------------------------------------------------------------------- |
378 | 448 | void closeAll() { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
449 | // Remove all loaded files and the objects they contain |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
450 | List<LDFile*> files = g_loadedFiles; |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
451 | for (LDFile* file : files) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
452 | delete file; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
453 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
454 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
455 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
456 | // ----------------------------------------------------------------------------- |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
457 | void newFile() { |
309 | 458 | // Create a new anonymous file and set it to our current |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
459 | LDFile* f = new LDFile; |
378 | 460 | f->setName (""); |
461 | f->setImplicit (false); | |
252
3f9067022d74
Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents:
251
diff
changeset
|
462 | g_loadedFiles << f; |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
463 | LDFile::setCurrent (f); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
465 | LDFile::closeInitialFile(); |
391
beef61ce962a
Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents:
390
diff
changeset
|
466 | |
378 | 467 | g_win->R()->setFile (f); |
309 | 468 | g_win->fullRefresh(); |
469 | g_win->updateTitle(); | |
470 | f->history().updateActions(); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
472 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
474 | // ----------------------------------------------------------------------------- |
378 | 475 | void addRecentFile (str path) { |
476 | QStringList rfiles = io_recentfiles.value.split ('@'); | |
477 | int idx = rfiles.indexOf (path); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
478 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
479 | // If this file already is in the list, pop it out. |
378 | 480 | if (idx != -1) { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
481 | if (rfiles.size() == 1) |
309 | 482 | return; // only recent file - abort and do nothing |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
483 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
484 | // Pop it out. |
378 | 485 | rfiles.removeAt (idx); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
486 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
487 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
488 | // If there's too many recent files, drop one out. |
378 | 489 | while (rfiles.size() > (g_MaxRecentFiles - 1)) |
490 | rfiles.removeAt (0); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
491 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
492 | // Add the file |
378 | 493 | rfiles << path; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
494 | |
273
0a9141118630
Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
272
diff
changeset
|
495 | // Rebuild the config string |
378 | 496 | io_recentfiles = rfiles.join ("@"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
497 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
498 | Config::save(); |
309 | 499 | g_win->updateRecentFilesMenu(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
500 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
501 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
502 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
503 | // Open an LDraw file and set it as the main model |
309 | 504 | // ----------------------------------------------------------------------------- |
378 | 505 | void openMainFile (str path) { |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
506 | g_loadingMainFile = true; |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
507 | LDFile* file = openDATFile (path, false); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
508 | |
378 | 509 | if (!file) { |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
510 | // Loading failed, thus drop down to a new file since we |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
511 | // closed everything prior. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
512 | newFile(); |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
513 | |
378 | 514 | if (!g_aborted) { |
320
737e466dae72
rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
319
diff
changeset
|
515 | // Tell the user loading failed. |
378 | 516 | setlocale (LC_ALL, "C"); |
517 | critical (fmt (QObject::tr ("Failed to open %1: %2"), path, strerror (errno))); | |
320
737e466dae72
rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
319
diff
changeset
|
518 | } |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
519 | |
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
520 | g_loadingMainFile = false; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
521 | return; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
522 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
523 | |
378 | 524 | file->setImplicit (false); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
525 | |
390 | 526 | // If we have an anonymous, unchanged file open as the only open file |
527 | // (aside of the one we just opened), close it now. | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
528 | LDFile::closeInitialFile(); |
390 | 529 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
530 | // Rebuild the object tree view now. |
422
00eedf400f72
Fixed crash on opening a file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
531 | LDFile::setCurrent (file); |
309 | 532 | g_win->fullRefresh(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
533 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
534 | // Add it to the recent files list. |
378 | 535 | addRecentFile (path); |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
536 | g_loadingMainFile = false; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
537 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
538 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
539 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
540 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
541 | bool LDFile::save (str savepath) { |
378 | 542 | if (!savepath.length()) |
309 | 543 | savepath = name(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
544 | |
378 | 545 | File f (savepath, File::Write); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
546 | |
378 | 547 | if (!f) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
548 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
549 | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
550 | // If the second object in the list holds the file name, update that now. |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
551 | // Only do this if the file is explicitly open. If it's saved into a directory |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
552 | // called "s" or "48", prepend that into the name. |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
553 | LDComment* fpathComment = null; |
378 | 554 | LDObject* first = object (1); |
555 | ||
556 | if (!implicit() && first != null && first->getType() == LDObject::Comment) { | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
557 | fpathComment = static_cast<LDComment*> (first); |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
558 | |
378 | 559 | if (fpathComment->text.left (6) == "Name: ") { |
309 | 560 | str newname; |
378 | 561 | str dir = basename (dirname (savepath)); |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
562 | |
378 | 563 | if (dir == "s" || dir == "48") |
309 | 564 | newname = dir + "\\"; |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
565 | |
378 | 566 | newname += basename (savepath); |
567 | fpathComment->text = fmt ("Name: %1", newname); | |
309 | 568 | g_win->buildObjList(); |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
569 | } |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
570 | } |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
571 | |
309 | 572 | // File is open, now save the model to it. Note that LDraw requires files to |
573 | // have DOS line endings, so we terminate the lines with \r\n. | |
378 | 574 | for (LDObject* obj : objs()) |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
575 | f.write (obj->raw() + "\r\n"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
576 | |
309 | 577 | // File is saved, now clean up. |
578 | f.close(); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
579 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
580 | // We have successfully saved, update the save position now. |
378 | 581 | setSavePos (history().pos()); |
582 | setName (savepath); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
583 | |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
584 | g_win->updateFileListItem (this); |
309 | 585 | g_win->updateTitle(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
586 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
587 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
588 | |
309 | 589 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
590 | // ----------------------------------------------------------------------------- |
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:
373
diff
changeset
|
591 | #define CHECK_TOKEN_COUNT(N) \ |
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:
373
diff
changeset
|
592 | if (tokens.size() != N) \ |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
593 | return new LDError (line, "Bad amount of tokens"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
594 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
595 | #define CHECK_TOKEN_NUMBERS(MIN, MAX) \ |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
596 | for (ushort i = MIN; i <= MAX; ++i) \ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
597 | if (!isNumber (tokens[i])) \ |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
598 | return new LDError (line, fmt ("Token #%1 was `%2`, expected a number", (i + 1), tokens[i])); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
599 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
600 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
601 | // ----------------------------------------------------------------------------- |
378 | 602 | static vertex parseVertex (QStringList& s, const ushort n) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
603 | vertex v; |
378 | 604 | |
605 | for (const Axis ax : g_Axes) | |
606 | v[ax] = atof (s[n + ax]); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
607 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
608 | return v; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
609 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
610 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
611 | // ============================================================================= |
309 | 612 | // This is the LDraw code parser function. It takes in a string containing LDraw |
613 | // code and returns the object parsed from it. parseLine never returns null, | |
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:
373
diff
changeset
|
614 | // the object will be LDError if it could not be parsed properly. |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
615 | // ----------------------------------------------------------------------------- |
378 | 616 | LDObject* parseLine (str line) { |
617 | QStringList tokens = line.split (" ", str::SkipEmptyParts); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
618 | |
378 | 619 | if (tokens.size() <= 0) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
620 | // Line was empty, or only consisted of whitespace |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
621 | return new LDEmpty; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
622 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
623 | |
378 | 624 | if (tokens[0].length() != 1 || tokens[0][0].isDigit() == false) |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
625 | return new LDError (line, "Illogical line code"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
626 | |
373
91bea18bd77a
Fixed compilation under windows/qt5
Santeri Piippo <crimsondusk64@gmail.com>
parents:
371
diff
changeset
|
627 | int num = tokens[0][0].digitValue(); |
378 | 628 | |
629 | switch (num) { | |
630 | case 0: { | |
631 | // Comment | |
632 | str comm = line.mid (line.indexOf ("0") + 1); | |
633 | ||
634 | // Remove any leading whitespace | |
635 | while (comm[0] == ' ') | |
636 | comm.remove (0, 1); | |
637 | ||
638 | // Handle BFC statements | |
639 | if (tokens.size() > 2 && tokens[1] == "BFC") { | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
640 | for (short i = 0; i < LDBFC::NumStatements; ++i) |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
641 | if (comm == fmt ("BFC %1", LDBFC::statements [i])) |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
642 | return new LDBFC ((LDBFC::Type) i); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
643 | |
378 | 644 | // MLCAD is notorious for stuffing these statements in parts it |
645 | // creates. The above block only handles valid statements, so we | |
418
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
646 | // need to handle MLCAD-style invertnext, clip and noclip separately. |
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
647 | struct { |
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
648 | const char* a; |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
649 | LDBFC::Type b; |
418
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
650 | } BFCData[] = { |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
651 | { "INVERTNEXT", LDBFC::InvertNext }, |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
652 | { "NOCLIP", LDBFC::NoClip }, |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
653 | { "CLIP", LDBFC::Clip } |
418
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
654 | }; |
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
655 | |
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
656 | for (const auto& i : BFCData) |
c435027ee5cd
added support for BFC CLIP/NOCLIP
Santeri Piippo <crimsondusk64@gmail.com>
parents:
417
diff
changeset
|
657 | if (comm == fmt ("BFC CERTIFY %1", i.a)) |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
658 | return new LDBFC (i.b); |
378 | 659 | } |
660 | ||
661 | if (tokens.size() > 2 && tokens[1] == "!LDFORGE") { | |
662 | // Handle LDForge-specific types, they're embedded into comments too | |
663 | if (tokens[2] == "VERTEX") { | |
664 | // Vertex (0 !LDFORGE VERTEX) | |
665 | CHECK_TOKEN_COUNT (7) | |
666 | CHECK_TOKEN_NUMBERS (3, 6) | |
667 | ||
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
668 | LDVertex* obj = new LDVertex; |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
669 | obj->setColor (tokens[3].toLong()); |
378 | 670 | |
671 | for (const Axis ax : g_Axes) | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
672 | obj->pos[ax] = tokens[4 + ax].toDouble(); // 4 - 6 |
378 | 673 | |
674 | return obj; | |
675 | } elif (tokens[2] == "OVERLAY") { | |
676 | CHECK_TOKEN_COUNT (9); | |
677 | CHECK_TOKEN_NUMBERS (5, 8) | |
678 | ||
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
679 | LDOverlay* obj = new LDOverlay; |
378 | 680 | obj->setFilename (tokens[3]); |
681 | obj->setCamera (tokens[4].toLong()); | |
682 | obj->setX (tokens[5].toLong()); | |
683 | obj->setY (tokens[6].toLong()); | |
684 | obj->setWidth (tokens[7].toLong()); | |
685 | obj->setHeight (tokens[8].toLong()); | |
686 | return obj; | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
687 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
688 | } |
378 | 689 | |
690 | // Just a regular comment: | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
691 | LDComment* obj = new LDComment; |
378 | 692 | obj->text = comm; |
693 | return obj; | |
694 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
695 | |
378 | 696 | case 1: { |
697 | // Subfile | |
698 | CHECK_TOKEN_COUNT (15) | |
699 | CHECK_TOKEN_NUMBERS (1, 13) | |
700 | ||
701 | // Try open the file. Disable g_loadingMainFile temporarily since we're | |
702 | // not loading the main file now, but the subfile in question. | |
703 | bool tmp = g_loadingMainFile; | |
704 | g_loadingMainFile = false; | |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
705 | LDFile* load = getFile (tokens[14]); |
378 | 706 | g_loadingMainFile = tmp; |
707 | ||
708 | // If we cannot open the file, mark it an error | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
423
diff
changeset
|
709 | if (!load) { |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
710 | LDError* obj = new LDError (line, fmt ("Could not open %1", tokens[14])); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
423
diff
changeset
|
711 | obj->setFileRef (tokens[14]); |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
423
diff
changeset
|
712 | return obj; |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
423
diff
changeset
|
713 | } |
378 | 714 | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
715 | LDSubfile* obj = new LDSubfile; |
378 | 716 | obj->setColor (tokens[1].toLong()); |
717 | obj->setPosition (parseVertex (tokens, 2)); // 2 - 4 | |
718 | ||
719 | matrix transform; | |
720 | ||
721 | for (short i = 0; i < 9; ++i) | |
722 | transform[i] = tokens[i + 5].toDouble(); // 5 - 13 | |
723 | ||
724 | obj->setTransform (transform); | |
725 | obj->setFileInfo (load); | |
726 | return obj; | |
727 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
728 | |
378 | 729 | case 2: { |
730 | CHECK_TOKEN_COUNT (8) | |
731 | CHECK_TOKEN_NUMBERS (1, 7) | |
732 | ||
733 | // Line | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
734 | LDLine* obj = new LDLine; |
378 | 735 | obj->setColor (tokens[1].toLong()); |
736 | ||
737 | for (short i = 0; i < 2; ++i) | |
738 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7 | |
739 | ||
740 | return obj; | |
741 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
742 | |
378 | 743 | case 3: { |
744 | CHECK_TOKEN_COUNT (11) | |
745 | CHECK_TOKEN_NUMBERS (1, 10) | |
746 | ||
747 | // Triangle | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
748 | LDTriangle* obj = new LDTriangle; |
378 | 749 | obj->setColor (tokens[1].toLong()); |
750 | ||
751 | for (short i = 0; i < 3; ++i) | |
752 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10 | |
753 | ||
754 | return obj; | |
755 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
756 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
757 | case 4: |
378 | 758 | case 5: { |
759 | CHECK_TOKEN_COUNT (14) | |
760 | CHECK_TOKEN_NUMBERS (1, 13) | |
761 | ||
762 | // Quadrilateral / Conditional line | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
763 | LDObject* obj; |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
764 | |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
765 | if (num == 4) |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
766 | obj = new LDQuad; |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
767 | else |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
768 | obj = new LDCndLine; |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
769 | |
378 | 770 | obj->setColor (tokens[1].toLong()); |
771 | ||
772 | for (short i = 0; i < 4; ++i) | |
773 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13 | |
774 | ||
775 | return obj; | |
776 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
777 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
778 | default: // Strange line we couldn't parse |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
779 | return new LDError (line, "Unknown line code number"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
780 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
781 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
782 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
783 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
784 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
785 | LDFile* getFile (str filename) { |
254
434c9844e45d
Further work on image generation experiment
Santeri Piippo <crimsondusk64@gmail.com>
parents:
253
diff
changeset
|
786 | // Try find the file in the list of loaded files |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
787 | LDFile* load = findLoadedFile (filename); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
788 | |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
789 | // If it's not loaded, try open it |
378 | 790 | if (!load) |
791 | load = openDATFile (filename, true); | |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
792 | |
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
793 | return load; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
794 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
795 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
796 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
797 | // ----------------------------------------------------------------------------- |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
798 | void reloadAllSubfiles() { |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
799 | if (!LDFile::current()) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
800 | return; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
801 | |
309 | 802 | g_loadedFiles.clear(); |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
803 | g_loadedFiles << LDFile::current(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
804 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
805 | // Go through all objects in the current file and reload the subfiles |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
806 | for (LDObject* obj : LDFile::current()->objs()) { |
378 | 807 | if (obj->getType() == LDObject::Subfile) { |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
808 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
809 | LDFile* fileInfo = getFile (ref->fileInfo()->name()); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
810 | |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
811 | if (fileInfo) |
378 | 812 | ref->setFileInfo (fileInfo); |
309 | 813 | else |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
814 | ref->replace (new LDError (ref->raw(), "Could not open referred file")); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
815 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
816 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
817 | // Reparse gibberish files. It could be that they are invalid because |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
236
diff
changeset
|
818 | // of loading errors. Circumstances may be different now. |
378 | 819 | if (obj->getType() == LDObject::Error) |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
820 | obj->replace (parseLine (static_cast<LDError*> (obj)->contents)); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
821 | } |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
822 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
823 | // Close all files left unused |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
824 | LDFile::closeUnused(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
825 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
826 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
827 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
828 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
829 | ulong LDFile::addObject (LDObject* obj) { |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
830 | m_history.add (new AddHistory (m_objs.size(), obj)); |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
831 | m_objs << obj; |
271
d5ec224c1879
Laid down the foundations of the new history system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
832 | |
378 | 833 | if (obj->getType() == LDObject::Vertex) |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
834 | m_vertices << obj; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
835 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
836 | obj->setFile (this); |
309 | 837 | return numObjs() - 1; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
838 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
839 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
840 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
841 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
842 | void LDFile::insertObj (const ulong pos, LDObject* obj) { |
378 | 843 | m_history.add (new AddHistory (pos, obj)); |
844 | m_objs.insert (pos, obj); | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
845 | obj->setFile (this); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
846 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
847 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
848 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
849 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
850 | void LDFile::forgetObject (LDObject* obj) { |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
851 | ulong idx = obj->getIndex(); |
378 | 852 | m_history.add (new DelHistory (idx, obj)); |
853 | m_objs.erase (idx); | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
854 | obj->setFile (null); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
855 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
856 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
857 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
858 | // ----------------------------------------------------------------------------- |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
859 | bool safeToCloseAll() { |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
860 | for (LDFile* f : g_loadedFiles) |
378 | 861 | if (!f->safeToClose()) |
226
3dd9e63698cd
Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
225
diff
changeset
|
862 | return false; |
3dd9e63698cd
Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
225
diff
changeset
|
863 | |
3dd9e63698cd
Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
225
diff
changeset
|
864 | return true; |
250
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
865 | } |
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
866 | |
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
867 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
868 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
869 | void LDFile::setObject (ulong idx, LDObject* obj) { |
378 | 870 | assert (idx < numObjs()); |
276
a21e49914264
Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
871 | |
309 | 872 | // Mark this change to history |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
873 | str oldcode = object (idx)->raw(); |
309 | 874 | str newcode = obj->raw(); |
378 | 875 | m_history << new EditHistory (idx, oldcode, newcode); |
276
a21e49914264
Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
876 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
877 | obj->setFile (this); |
250
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
878 | m_objs[idx] = obj; |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
879 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
880 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
881 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
882 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
883 | static List<LDFile*> getFilesUsed (LDFile* node) { |
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
884 | List<LDFile*> filesUsed; |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
885 | |
378 | 886 | for (LDObject* obj : *node) { |
887 | if (obj->getType() != LDObject::Subfile) | |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
888 | continue; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
889 | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
890 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
309 | 891 | filesUsed << ref->fileInfo(); |
378 | 892 | filesUsed << getFilesUsed (ref->fileInfo()); |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
893 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
894 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
895 | return filesUsed; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
896 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
897 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
898 | // ============================================================================= |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
899 | // Find out which files are unused and close them. |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
900 | // ----------------------------------------------------------------------------- |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
901 | void LDFile::closeUnused() { |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
902 | List<LDFile*> filesUsed = getFilesUsed (LDFile::current()); |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
903 | |
309 | 904 | // Anything that's explicitly opened must not be closed |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
905 | for (LDFile* file : g_loadedFiles) |
378 | 906 | if (!file->implicit()) |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
907 | filesUsed << file; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
908 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
909 | // Remove duplicated entries |
309 | 910 | filesUsed.makeUnique(); |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
911 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
912 | // Close all open files that aren't in filesUsed |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
913 | for (LDFile* file : g_loadedFiles) { |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
914 | bool isused = false; |
378 | 915 | |
417
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
916 | for (LDFile* usedFile : filesUsed) { |
378 | 917 | if (file == usedFile) { |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
918 | isused = true; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
919 | break; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
920 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
921 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
922 | |
378 | 923 | if (!isused) |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
924 | delete file; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
925 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
926 | |
309 | 927 | g_loadedFiles.clear(); |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
928 | g_loadedFiles << filesUsed; |
309 | 929 | } |
930 | ||
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
931 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
932 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
933 | LDObject* LDFile::object (ulong pos) const { |
378 | 934 | if (m_objs.size() <= pos) |
309 | 935 | return null; |
936 | ||
937 | return m_objs[pos]; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
938 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
939 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
940 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
941 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
942 | LDObject* LDFile::obj (ulong pos) const { |
379
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
943 | return object (pos); |
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
944 | } |
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
945 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
946 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
947 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
948 | ulong LDFile::numObjs() const { |
379
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
949 | return m_objs.size(); |
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
950 | } |
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
951 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
952 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
953 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
954 | LDFile& LDFile::operator<< (List<LDObject*> objs) { |
378 | 955 | for (LDObject* obj : objs) |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
956 | addObject (obj); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
957 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
958 | return *this; |
379
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
959 | } |
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
960 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
961 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
962 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
963 | bool LDFile::hasUnsavedChanges() const { |
383
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
964 | return !implicit() && history().pos() != savePos(); |
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
965 | } |
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
966 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
967 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
968 | // ----------------------------------------------------------------------------- |
416
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
969 | str LDFile::getShortName() { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
970 | if (name().length() > 0) |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
971 | return basename (name()); |
416
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
972 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
973 | return tr ("<anonymous>"); |
416
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
974 | } |
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
975 | |
379
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
976 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
977 | // ----------------------------------------------------------------------------- |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
978 | List<LDObject*> LDFile::inlineContents (LDSubfile::InlineFlags flags) { |
458
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
979 | // Possibly substitute with logoed studs: |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
980 | // stud.dat -> stud-logo.dat |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
981 | // stud2.dat -> stud-logo2.dat |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
982 | if (gl_logostuds && (flags & LDSubfile::RendererInline)) { |
458
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
983 | if (name() == "stud.dat" && g_logoedStud) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
984 | return g_logoedStud->inlineContents (flags); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
985 | elif (name() == "stud2.dat" && g_logoedStud2) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
986 | return g_logoedStud2->inlineContents (flags); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
987 | } |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
988 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
989 | List<LDObject*> objs, objcache; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
990 | |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
991 | bool deep = flags & LDSubfile::DeepInline, |
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
992 | doCache = flags & LDSubfile::CacheInline; |
458
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
993 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
994 | // If we have this cached, just clone that |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
995 | if (deep && cache().size()) { |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
996 | for (LDObject* obj : cache()) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
997 | objs << obj->clone(); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
998 | } else { |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
999 | if (!deep) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1000 | doCache = false; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1001 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1002 | for (LDObject* obj : m_objs) { |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1003 | // Skip those without scemantic meaning |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1004 | if (!obj->isScemantic()) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1005 | continue; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1006 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1007 | // Got another sub-file reference, inline it if we're deep-inlining. If not, |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1008 | // just add it into the objects normally. Also, we only cache immediate |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1009 | // subfiles and this is not one. Yay, recursion! |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1010 | if (deep && obj->getType() == LDObject::Subfile) { |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
1011 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
458
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1012 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1013 | // We only want to cache immediate subfiles, so shed the caching |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1014 | // flag when recursing deeper in hierarchy. |
460
b230ae09c8e5
Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
459
diff
changeset
|
1015 | List<LDObject*> otherobjs = ref->inlineContents (flags & ~(LDSubfile::CacheInline)); |
458
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1016 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1017 | for (LDObject* otherobj : otherobjs) { |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1018 | // Cache this object, if desired |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1019 | if (doCache) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1020 | objcache << otherobj->clone(); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1021 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1022 | objs << otherobj; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1023 | } |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1024 | } else { |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1025 | if (doCache) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1026 | objcache << obj->clone(); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1027 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1028 | objs << obj->clone(); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1029 | } |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1030 | } |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1031 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1032 | if (doCache) |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1033 | setCache (objcache); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1034 | } |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1035 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1036 | return objs; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1037 | } |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1038 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1039 | // ============================================================================= |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1040 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
1041 | LDFile* LDFile::current() { |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
1042 | return m_curfile; |
379
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
1043 | } |
f5f3faac60cd
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
378
diff
changeset
|
1044 | |
417
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1045 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1046 | // Sets the given file as the current one on display. At some point in time this |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1047 | // was an operation completely unheard of. ;) |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1048 | // |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1049 | // FIXME: f can be temporarily null. This probably should not be the case. |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1050 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
1051 | void LDFile::setCurrent (LDFile* f) { |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1052 | // Implicit files were loaded for caching purposes and must never be set |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1053 | // current. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
1054 | if (f && f->implicit()) |
417
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1055 | return; |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1056 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
1057 | m_curfile = f; |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
1058 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
1059 | if (g_win && f) { |
423
8516b8e14fb4
Angles need to be reset when changing the current file too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
422
diff
changeset
|
1060 | // A ton of stuff needs to be updated |
416
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
1061 | g_win->clearSelection(); |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
1062 | g_win->updateFileListItem (f); |
416
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
1063 | g_win->buildObjList(); |
422
00eedf400f72
Fixed crash on opening a file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
1064 | g_win->updateTitle(); |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
1065 | g_win->R()->setFile (f); |
423
8516b8e14fb4
Angles need to be reset when changing the current file too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
422
diff
changeset
|
1066 | g_win->R()->resetAngles(); |
417
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1067 | g_win->R()->repaint(); |
416
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
1068 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
1069 | log ("Changed file to %1", f->getShortName()); |
416
be1824f53c48
Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
1070 | } |
391
beef61ce962a
Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents:
390
diff
changeset
|
1071 | } |
beef61ce962a
Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents:
390
diff
changeset
|
1072 | |
401
89a9235b47d3
Use repaint() instead of update() when redrawing the scene after a pick so that the new scene is repainted immediately.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
400
diff
changeset
|
1073 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1074 | // ----------------------------------------------------------------------------- |
417
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1075 | int LDFile::countExplicitFiles() { |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1076 | int count = 0; |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1077 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
1078 | for (LDFile* f : g_loadedFiles) |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
418
diff
changeset
|
1079 | if (f->implicit() == false) |
417
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1080 | count++; |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1081 | |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1082 | return count; |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1083 | } |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1084 | |
14bfeed046f3
Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
416
diff
changeset
|
1085 | // ============================================================================= |
401
89a9235b47d3
Use repaint() instead of update() when redrawing the scene after a pick so that the new scene is repainted immediately.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
400
diff
changeset
|
1086 | // This little beauty closes the initial file that was open at first when opening |
89a9235b47d3
Use repaint() instead of update() when redrawing the scene after a pick so that the new scene is repainted immediately.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
400
diff
changeset
|
1087 | // a new file over it. |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1088 | // ----------------------------------------------------------------------------- |
409
8da2563c645a
Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
1089 | void LDFile::closeInitialFile() { |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1090 | if ( |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1091 | countExplicitFiles() == 2 && |
401
89a9235b47d3
Use repaint() instead of update() when redrawing the scene after a pick so that the new scene is repainted immediately.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
400
diff
changeset
|
1092 | g_loadedFiles[0]->name() == "" && |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1093 | !g_loadedFiles[0]->hasUnsavedChanges() |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1094 | ) |
401
89a9235b47d3
Use repaint() instead of update() when redrawing the scene after a pick so that the new scene is repainted immediately.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
400
diff
changeset
|
1095 | delete g_loadedFiles[0]; |
458
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1096 | } |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1097 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1098 | // ============================================================================= |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1099 | // ----------------------------------------------------------------------------- |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1100 | void loadLogoedStuds() { |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1101 | print ("Loading logoed studs...\n"); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1102 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1103 | delete g_logoedStud; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1104 | delete g_logoedStud2; |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1105 | |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1106 | g_logoedStud = openDATFile ("stud-logo.dat", true); |
cb360f4d8979
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
457
diff
changeset
|
1107 | g_logoedStud2 = openDATFile ("stud2-logo.dat", true); |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
1108 | } |