Tue, 30 Jul 2013 07:38:08 +0300
Renamed vector to List, changed it to wrap around std::deque.
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" |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
378 | 34 | cfg (str, io_ldpath, ""); |
35 | cfg (str, io_recentfiles, ""); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
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
|
37 | static bool g_loadingMainFile = false; |
309 | 38 | 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
|
39 | static bool g_aborted = false; |
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 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
41 | LDOpenFile* LDOpenFile::m_curfile = null; |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
42 | |
383
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
43 | DEFINE_PROPERTY (QListWidgetItem*, LDOpenFile, listItem, setListItem) |
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
44 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | // ============================================================================= |
378 | 46 | namespace LDPaths { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | static str pathError; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
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
|
49 | struct { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | str LDConfigPath; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | str partsPath, primsPath; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | } pathInfo; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
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
|
54 | void initPaths() { |
378 | 55 | 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
|
56 | LDrawPathDialog dlg (false); |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
378 | 58 | if (!dlg.exec ()) |
59 | exit (0); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
309 | 61 | 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
|
62 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
378 | 65 | 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
|
66 | QDir dir; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
378 | 68 | 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
|
69 | 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
|
70 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
309 | 73 | QStringList mustHave = { "LDConfig.ldr", "parts", "p" }; |
378 | 74 | 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
|
75 | |
378 | 76 | 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
|
77 | 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
|
78 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
378 | 81 | pathInfo.partsPath = fmt ("%1" DIRSLASH "parts", path); |
82 | pathInfo.LDConfigPath = fmt ("%1" DIRSLASH "LDConfig.ldr", path); | |
83 | 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
|
84 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | // Accessors |
309 | 89 | str getError() { return pathError; } |
90 | str ldconfig() { return pathInfo.LDConfigPath; } | |
91 | str prims() { return pathInfo.primsPath; } | |
92 | 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
|
93 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | // ============================================================================= |
378 | 96 | LDOpenFile::LDOpenFile() { |
97 | setImplicit (true); | |
98 | setSavePos (-1); | |
383
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
99 | setListItem (null); |
378 | 100 | 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
|
101 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | // ============================================================================= |
378 | 104 | LDOpenFile::~LDOpenFile() { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | // Clear everything from the model |
378 | 106 | 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
|
107 | delete obj; |
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 | // Clear the cache as well |
378 | 110 | 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
|
111 | delete obj; |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
112 | |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
113 | // 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
|
114 | 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
|
115 | 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
|
116 | 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
|
117 | break; |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
118 | } |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
119 | } |
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 | // 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
|
122 | // file as something else. |
400
af39fae829f6
Fixed crashing when closing all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
393
diff
changeset
|
123 | if( this == LDOpenFile::current() ) { |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
124 | // If we closed the last file, create a blank one. |
400
af39fae829f6
Fixed crashing when closing all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
393
diff
changeset
|
125 | 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
|
126 | newFile(); |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
127 | else |
400
af39fae829f6
Fixed crashing when closing all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
393
diff
changeset
|
128 | LDOpenFile::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
|
129 | } |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
130 | |
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
131 | g_win->updateFileList(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | // ============================================================================= |
378 | 135 | LDOpenFile* findLoadedFile (str name) { |
136 | for (LDOpenFile* file : g_loadedFiles) | |
137 | 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
|
138 | return file; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | return null; |
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 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | // ============================================================================= |
378 | 144 | str dirname (str path) { |
145 | long lastpos = path.lastIndexOf (DIRSLASH); | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
146 | |
378 | 147 | if (lastpos > 0) |
148 | return path.left (lastpos); | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
149 | |
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
|
150 | #ifndef _WIN32 |
378 | 151 | 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
|
152 | 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
|
153 | #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
|
154 | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
155 | return ""; |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
156 | } |
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
157 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | // ============================================================================= |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
159 | str basename (str path) { |
378 | 160 | long lastpos = path.lastIndexOf (DIRSLASH); |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
161 | |
378 | 162 | if (lastpos != -1) |
163 | return path.mid (lastpos + 1); | |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
164 | |
235 | 165 | return path; |
234
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
166 | } |
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
167 | |
79b120b0aa51
added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
232
diff
changeset
|
168 | // ============================================================================= |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
169 | File* openLDrawFile (str relpath, bool subdirs) { |
378 | 170 | 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
|
171 | 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
|
172 | 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
|
173 | |
309 | 174 | // LDraw models use Windows-style path separators. If we're not on Windows, |
175 | // 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
|
176 | #ifndef WIN32 |
378 | 177 | relpath.replace ("\\", "/"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | #endif // WIN32 |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
180 | if (LDOpenFile::current()) { |
309 | 181 | // First, try find the file in the current model's file path. We want a file |
182 | // in the immediate vicinity of the current model to override stock LDraw stuff. | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
183 | str partpath = fmt ("%1" DIRSLASH "%2", dirname (LDOpenFile::current()->name ()), relpath); |
213
a4113545242c
Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
184 | |
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
|
185 | if (f->open (partpath, File::Read)) { |
378 | 186 | return f; |
187 | } | |
188 | } | |
213
a4113545242c
Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
189 | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
190 | 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
|
191 | return f; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
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
|
193 | // 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
|
194 | 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
|
195 | |
378 | 196 | 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
|
197 | 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
|
198 | |
378 | 199 | if (subdirs) { |
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
|
200 | // Look in sub-directories: parts and p |
378 | 201 | for (auto subdir : initlist<const str> ({ "parts", "p" })) { |
202 | fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", io_ldpath, 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
|
203 | |
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 | if (f->open (fullPath, File::Read)) |
378 | 205 | return f; |
206 | } | |
207 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | |
309 | 209 | // Did not find the file. |
378 | 210 | 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
|
211 | delete f; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | return null; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | // ============================================================================= |
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
|
218 | void FileLoader::start() { |
378 | 219 | setDone (false); |
220 | setProgress (0); | |
221 | setAborted (false); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | |
378 | 223 | if (concurrent()) { |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
224 | g_aborted = false; |
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
225 | |
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
|
226 | // 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
|
227 | // 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
|
228 | // 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
|
229 | // 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
|
230 | dlg = new OpenProgressDialog (g_win); |
378 | 231 | dlg->setNumLines (lines().size()); |
232 | 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
|
233 | 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
|
234 | |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
235 | // Connect the loader in so we can show updates |
378 | 236 | connect (this, SIGNAL (workDone()), dlg, SLOT (accept())); |
237 | 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
|
238 | } 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
|
239 | 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
|
240 | |
378 | 241 | 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
|
242 | } |
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 | |
378 | 244 | void FileLoader::work (ulong i) { |
245 | 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
|
246 | // We were flagged for abortion, so abort. |
378 | 247 | 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
|
248 | 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
|
249 | |
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 | m_objs.clear(); |
378 | 251 | 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
|
252 | 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
|
253 | } |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
254 | |
843b3dbbd849
make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
363
diff
changeset
|
255 | ulong max = i + 300; |
378 | 256 | |
257 | for (; i < max && i < lines().size(); ++i) { | |
258 | 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
|
259 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | // Trim the trailing newline |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
276
diff
changeset
|
261 | qchar c; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | |
378 | 263 | while ((c = line[line.length () - 1]) == '\n' || c == '\r') |
264 | line.chop (1); | |
265 | ||
266 | 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
|
267 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | // Check for parse errors and warn about tthem |
378 | 269 | if (obj->getType () == LDObject::Error) { |
270 | log ("Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDErrorObject*> (obj)->reason); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | |
378 | 272 | if (m_warningsPointer) { |
273 | (*m_warningsPointer) ++; | |
274 | } | |
275 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | |
252
3f9067022d74
Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents:
251
diff
changeset
|
277 | m_objs << obj; |
378 | 278 | 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
|
279 | |
378 | 280 | if (concurrent()) |
281 | dlg->updateProgress (i); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | |
378 | 284 | if (i >= 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
|
285 | emit workDone(); |
378 | 286 | setDone (true); |
287 | } | |
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
|
288 | |
378 | 289 | if (!done()) { |
290 | if (concurrent()) | |
291 | 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
|
292 | else |
378 | 293 | 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
|
294 | } |
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
|
295 | } |
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
|
296 | |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
297 | void FileLoader::abort() { |
378 | 298 | setAborted (true); |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
299 | |
378 | 300 | if (concurrent()) |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
301 | g_aborted = true; |
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
302 | } |
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
303 | |
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
|
304 | // ============================================================================= |
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
|
305 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
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
|
306 | // ============================================================================= |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
307 | 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
|
308 | List<str> lines; |
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
309 | 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
|
310 | |
378 | 311 | 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
|
312 | *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
|
313 | |
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
|
314 | // Calculate the amount of lines |
378 | 315 | 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
|
316 | lines << line; |
378 | 317 | |
309 | 318 | 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
|
319 | |
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
|
320 | FileLoader* loader = new FileLoader; |
378 | 321 | loader->setWarningsPointer (numWarnings); |
322 | loader->setLines (lines); | |
323 | 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
|
324 | 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
|
325 | |
378 | 326 | 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
|
327 | 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
|
328 | |
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
|
329 | // If we wanted the success value, supply that now |
378 | 330 | if (ok) |
371
e8ef9fb4721b
make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
370
diff
changeset
|
331 | *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
|
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 | objs = loader->objs(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | return objs; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | // ============================================================================= |
378 | 340 | LDOpenFile* 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
|
341 | // 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
|
342 | // 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
|
343 | // 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
|
344 | File* f; |
378 | 345 | |
346 | if (search) | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
347 | f = openLDrawFile (path.toLower (), true); |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
348 | else { |
378 | 349 | 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
|
350 | |
378 | 351 | if (!*f) { |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
352 | delete f; |
378 | 353 | return null; |
354 | } | |
355 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | |
378 | 357 | if (!f) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | return null; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | |
232
4e44c92e21dd
Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents:
227
diff
changeset
|
360 | LDOpenFile* load = new LDOpenFile; |
378 | 361 | load->setName (path); |
213
a4113545242c
Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
362 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
363 | 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
|
364 | bool ok; |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
365 | 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
|
366 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
367 | 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
|
368 | return null; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
369 | |
378 | 370 | for (LDObject* obj : objs) |
371 | load->addObject (obj); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
373 | delete f; |
252
3f9067022d74
Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents:
251
diff
changeset
|
374 | g_loadedFiles << load; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
376 | if (g_loadingMainFile) { |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
377 | LDOpenFile::setCurrent (load); |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
378 | g_win->R()->setFile (load); |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
379 | 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
|
380 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
381 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
382 | return load; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
383 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
386 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
387 | // ============================================================================= |
378 | 388 | bool LDOpenFile::safeToClose() { |
309 | 389 | typedef QMessageBox msgbox; |
378 | 390 | 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
|
391 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | // 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
|
393 | if (hasUnsavedChanges()) { |
378 | 394 | str message = fmt ("There are unsaved changes to %1. Should it be saved?", |
395 | (name().length() > 0) ? name() : "<anonymous>"); | |
396 | ||
397 | int button = msgbox::question (g_win, "Unsaved Changes", message, | |
398 | (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel); | |
399 | ||
400 | switch (button) { | |
309 | 401 | 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
|
402 | // If we don't have a file path yet, we have to ask the user for one. |
378 | 403 | if (name().length() == 0) { |
404 | str newpath = QFileDialog::getSaveFileName (g_win, "Save As", | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
405 | LDOpenFile::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
|
406 | |
378 | 407 | 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
|
408 | return false; |
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
409 | |
378 | 410 | 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
|
411 | } |
a78179b182e1
Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents:
224
diff
changeset
|
412 | |
378 | 413 | if (!save ()) { |
414 | message = fmt (QObject::tr ("Failed to save %1: %2\nDo you still want to close?"), | |
415 | name(), strerror (errno)); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
416 | |
378 | 417 | if (msgbox::critical (g_win, "Save Failure", message, |
418 | (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
|
419 | { |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
420 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
421 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
422 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
423 | break; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
424 | |
309 | 425 | case msgbox::Cancel: |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
426 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
427 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
428 | default: |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
429 | break; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
430 | } |
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 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
434 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
435 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
436 | // ============================================================================= |
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 | // ============================================================================= |
378 | 439 | void closeAll() { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
440 | // Remove all loaded files and the objects they contain |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
441 | List<LDOpenFile*> files = g_loadedFiles; |
400
af39fae829f6
Fixed crashing when closing all
Santeri Piippo <crimsondusk64@gmail.com>
parents:
393
diff
changeset
|
442 | for( LDOpenFile* file : files ) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
443 | delete file; |
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 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
447 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
448 | // ============================================================================= |
378 | 449 | void newFile () { |
309 | 450 | // Create a new anonymous file and set it to our current |
232
4e44c92e21dd
Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents:
227
diff
changeset
|
451 | LDOpenFile* f = new LDOpenFile; |
378 | 452 | f->setName (""); |
453 | f->setImplicit (false); | |
252
3f9067022d74
Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents:
251
diff
changeset
|
454 | g_loadedFiles << f; |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
455 | LDOpenFile::setCurrent (f); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
456 | |
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
|
457 | LDOpenFile::closeInitialFile(); |
391
beef61ce962a
Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents:
390
diff
changeset
|
458 | |
378 | 459 | g_win->R()->setFile (f); |
309 | 460 | g_win->fullRefresh(); |
461 | g_win->updateTitle(); | |
462 | f->history().updateActions(); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
463 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
465 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | // ============================================================================= |
378 | 468 | void addRecentFile (str path) { |
469 | QStringList rfiles = io_recentfiles.value.split ('@'); | |
470 | 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
|
471 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
472 | // If this file already is in the list, pop it out. |
378 | 473 | if (idx != -1) { |
474 | if (rfiles.size () == 1) | |
309 | 475 | 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
|
476 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
477 | // Pop it out. |
378 | 478 | rfiles.removeAt (idx); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
479 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
480 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
481 | // If there's too many recent files, drop one out. |
378 | 482 | while (rfiles.size() > (g_MaxRecentFiles - 1)) |
483 | rfiles.removeAt (0); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
484 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
485 | // Add the file |
378 | 486 | rfiles << path; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
487 | |
273
0a9141118630
Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
272
diff
changeset
|
488 | // Rebuild the config string |
378 | 489 | 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
|
490 | |
309 | 491 | config::save(); |
492 | g_win->updateRecentFilesMenu(); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
493 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
494 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
495 | // ============================================================================= |
309 | 496 | // ----------------------------------------------------------------------------- |
497 | // Open an LDraw file and set it as the main model | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
498 | // ============================================================================= |
378 | 499 | 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
|
500 | g_loadingMainFile = true; |
378 | 501 | LDOpenFile* 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
|
502 | |
378 | 503 | if (!file) { |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
504 | // 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
|
505 | // closed everything prior. |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
506 | newFile (); |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
507 | |
378 | 508 | 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
|
509 | // Tell the user loading failed. |
378 | 510 | setlocale (LC_ALL, "C"); |
511 | 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
|
512 | } |
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
|
513 | |
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
|
514 | g_loadingMainFile = false; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
515 | return; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
516 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
517 | |
378 | 518 | file->setImplicit (false); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
519 | |
390 | 520 | // If we have an anonymous, unchanged file open as the only open file |
521 | // (aside of the one we just opened), close it now. | |
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
|
522 | LDOpenFile::closeInitialFile(); |
390 | 523 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
524 | // Rebuild the object tree view now. |
309 | 525 | g_win->fullRefresh(); |
526 | g_win->updateTitle(); | |
378 | 527 | g_win->R()->setFile (file); |
309 | 528 | g_win->R()->resetAngles(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
529 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
530 | // Add it to the recent files list. |
378 | 531 | 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
|
532 | g_loadingMainFile = false; |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
533 | |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
534 | LDOpenFile::setCurrent (file); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
535 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
536 | |
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 | // ============================================================================= |
378 | 540 | bool LDOpenFile::save (str savepath) { |
541 | if (!savepath.length()) | |
309 | 542 | savepath = name(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
543 | |
378 | 544 | 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
|
545 | |
378 | 546 | if (!f) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
547 | return false; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
548 | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
549 | // 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
|
550 | // 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
|
551 | // called "s" or "48", prepend that into the name. |
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
|
552 | LDCommentObject* fpathComment = null; |
378 | 553 | LDObject* first = object (1); |
554 | ||
555 | if (!implicit() && first != null && first->getType() == LDObject::Comment) { | |
556 | fpathComment = static_cast<LDCommentObject*> (first); | |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
557 | |
378 | 558 | if (fpathComment->text.left (6) == "Name: ") { |
309 | 559 | str newname; |
378 | 560 | str dir = basename (dirname (savepath)); |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
561 | |
378 | 562 | if (dir == "s" || dir == "48") |
309 | 563 | newname = dir + "\\"; |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
564 | |
378 | 565 | newname += basename (savepath); |
566 | fpathComment->text = fmt ("Name: %1", newname); | |
309 | 567 | g_win->buildObjList(); |
227
e13cd69b16dd
Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents:
226
diff
changeset
|
568 | } |
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 | |
309 | 571 | // File is open, now save the model to it. Note that LDraw requires files to |
572 | // have DOS line endings, so we terminate the lines with \r\n. | |
378 | 573 | for (LDObject* obj : objs()) |
574 | 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
|
575 | |
309 | 576 | // File is saved, now clean up. |
577 | f.close(); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
578 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
579 | // We have successfully saved, update the save position now. |
378 | 580 | setSavePos (history().pos()); |
581 | setName (savepath); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
582 | |
389
ccb763dbe98e
Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
388
diff
changeset
|
583 | g_win->updateFileListItem (this); |
309 | 584 | g_win->updateTitle(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
585 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
586 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
587 | |
309 | 588 | // ============================================================================= |
589 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
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) \ |
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
|
593 | return new LDErrorObject (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 | |
309 | 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])) \ |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
598 | return new LDErrorObject (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 | |
378 | 600 | 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
|
601 | vertex v; |
378 | 602 | |
603 | for (const Axis ax : g_Axes) | |
604 | 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
|
605 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
606 | return v; |
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 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
609 | // ============================================================================= |
309 | 610 | // ----------------------------------------------------------------------------- |
611 | // This is the LDraw code parser function. It takes in a string containing LDraw | |
612 | // 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
|
613 | // the object will be LDError if it could not be parsed properly. |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
614 | // ============================================================================= |
378 | 615 | LDObject* parseLine (str line) { |
616 | 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
|
617 | |
378 | 618 | 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
|
619 | // Line was empty, or only consisted of whitespace |
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
|
620 | return new LDEmptyObject; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
621 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
622 | |
378 | 623 | if (tokens[0].length() != 1 || tokens[0][0].isDigit() == false) |
624 | return new LDErrorObject (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
|
625 | |
373
91bea18bd77a
Fixed compilation under windows/qt5
Santeri Piippo <crimsondusk64@gmail.com>
parents:
371
diff
changeset
|
626 | int num = tokens[0][0].digitValue(); |
378 | 627 | |
628 | switch (num) { | |
629 | case 0: { | |
630 | // Comment | |
631 | str comm = line.mid (line.indexOf ("0") + 1); | |
632 | ||
633 | // Remove any leading whitespace | |
634 | while (comm[0] == ' ') | |
635 | comm.remove (0, 1); | |
636 | ||
637 | // Handle BFC statements | |
638 | if (tokens.size() > 2 && tokens[1] == "BFC") { | |
639 | for (short i = 0; i < LDBFCObject::NumStatements; ++i) | |
640 | if (comm == fmt ("BFC %1", LDBFCObject::statements [i])) | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
641 | return new LDBFCObject ((LDBFCObject::Type) i); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
642 | |
378 | 643 | // MLCAD is notorious for stuffing these statements in parts it |
644 | // creates. The above block only handles valid statements, so we | |
645 | // need to handle MLCAD-style invertnext separately. | |
646 | if (comm == "BFC CERTIFY INVERTNEXT") | |
647 | return new LDBFCObject (LDBFCObject::InvertNext); | |
648 | } | |
649 | ||
650 | if (tokens.size() > 2 && tokens[1] == "!LDFORGE") { | |
651 | // Handle LDForge-specific types, they're embedded into comments too | |
652 | if (tokens[2] == "VERTEX") { | |
653 | // Vertex (0 !LDFORGE VERTEX) | |
654 | CHECK_TOKEN_COUNT (7) | |
655 | CHECK_TOKEN_NUMBERS (3, 6) | |
656 | ||
657 | LDVertexObject* obj = new LDVertexObject; | |
658 | obj->setColor (tokens[3].toLong ()); | |
659 | ||
660 | for (const Axis ax : g_Axes) | |
661 | obj->pos[ax] = tokens[4 + ax].toDouble (); // 4 - 6 | |
662 | ||
663 | return obj; | |
664 | } elif (tokens[2] == "OVERLAY") { | |
665 | CHECK_TOKEN_COUNT (9); | |
666 | CHECK_TOKEN_NUMBERS (5, 8) | |
667 | ||
668 | LDOverlayObject* obj = new LDOverlayObject; | |
669 | obj->setFilename (tokens[3]); | |
670 | obj->setCamera (tokens[4].toLong()); | |
671 | obj->setX (tokens[5].toLong()); | |
672 | obj->setY (tokens[6].toLong()); | |
673 | obj->setWidth (tokens[7].toLong()); | |
674 | obj->setHeight (tokens[8].toLong()); | |
675 | return obj; | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
676 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
677 | } |
378 | 678 | |
679 | // Just a regular comment: | |
680 | LDCommentObject* obj = new LDCommentObject; | |
681 | obj->text = comm; | |
682 | return obj; | |
683 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
684 | |
378 | 685 | case 1: { |
686 | // Subfile | |
687 | CHECK_TOKEN_COUNT (15) | |
688 | CHECK_TOKEN_NUMBERS (1, 13) | |
689 | ||
690 | // Try open the file. Disable g_loadingMainFile temporarily since we're | |
691 | // not loading the main file now, but the subfile in question. | |
692 | bool tmp = g_loadingMainFile; | |
693 | g_loadingMainFile = false; | |
694 | LDOpenFile* load = getFile (tokens[14]); | |
695 | g_loadingMainFile = tmp; | |
696 | ||
697 | // If we cannot open the file, mark it an error | |
698 | if (!load) | |
699 | return new LDErrorObject (line, "Could not open referred file"); | |
700 | ||
701 | LDSubfileObject* obj = new LDSubfileObject; | |
702 | obj->setColor (tokens[1].toLong()); | |
703 | obj->setPosition (parseVertex (tokens, 2)); // 2 - 4 | |
704 | ||
705 | matrix transform; | |
706 | ||
707 | for (short i = 0; i < 9; ++i) | |
708 | transform[i] = tokens[i + 5].toDouble(); // 5 - 13 | |
709 | ||
710 | obj->setTransform (transform); | |
711 | obj->setFileInfo (load); | |
712 | return obj; | |
713 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
714 | |
378 | 715 | case 2: { |
716 | CHECK_TOKEN_COUNT (8) | |
717 | CHECK_TOKEN_NUMBERS (1, 7) | |
718 | ||
719 | // Line | |
720 | LDLineObject* obj = new LDLineObject; | |
721 | obj->setColor (tokens[1].toLong()); | |
722 | ||
723 | for (short i = 0; i < 2; ++i) | |
724 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7 | |
725 | ||
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 3: { |
730 | CHECK_TOKEN_COUNT (11) | |
731 | CHECK_TOKEN_NUMBERS (1, 10) | |
732 | ||
733 | // Triangle | |
734 | LDTriangleObject* obj = new LDTriangleObject; | |
735 | obj->setColor (tokens[1].toLong()); | |
736 | ||
737 | for (short i = 0; i < 3; ++i) | |
738 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10 | |
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 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
743 | case 4: |
378 | 744 | case 5: { |
745 | CHECK_TOKEN_COUNT (14) | |
746 | CHECK_TOKEN_NUMBERS (1, 13) | |
747 | ||
748 | // Quadrilateral / Conditional line | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
749 | LDObject* obj; |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
750 | |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
751 | if (num == 4) |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
752 | obj = new LDQuadObject; |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
753 | else |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
754 | obj = new LDCondLineObject; |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
755 | |
378 | 756 | obj->setColor (tokens[1].toLong()); |
757 | ||
758 | for (short i = 0; i < 4; ++i) | |
759 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13 | |
760 | ||
761 | return obj; | |
762 | } | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
763 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
764 | default: // Strange line we couldn't parse |
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
|
765 | return new LDErrorObject (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
|
766 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
767 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
768 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
769 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
770 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
771 | // ============================================================================= |
378 | 772 | LDOpenFile* getFile (str filename) { |
254
434c9844e45d
Further work on image generation experiment
Santeri Piippo <crimsondusk64@gmail.com>
parents:
253
diff
changeset
|
773 | // Try find the file in the list of loaded files |
378 | 774 | LDOpenFile* load = findLoadedFile (filename); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
775 | |
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
|
776 | // If it's not loaded, try open it |
378 | 777 | if (!load) |
778 | 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
|
779 | |
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
|
780 | return load; |
183
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 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
784 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
785 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
786 | void reloadAllSubfiles () { |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
787 | if (!LDOpenFile::current()) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
788 | return; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
789 | |
309 | 790 | g_loadedFiles.clear(); |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
791 | g_loadedFiles << LDOpenFile::current(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
792 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
793 | // Go through all objects in the current file and reload the subfiles |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
794 | for (LDObject* obj : LDOpenFile::current()->objs()) { |
378 | 795 | if (obj->getType() == LDObject::Subfile) { |
796 | LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); | |
797 | LDOpenFile* 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
|
798 | |
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
|
799 | if (fileInfo) |
378 | 800 | ref->setFileInfo (fileInfo); |
309 | 801 | else |
378 | 802 | ref->replace (new LDErrorObject (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
|
803 | } |
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 | // 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
|
806 | // of loading errors. Circumstances may be different now. |
378 | 807 | if (obj->getType() == LDObject::Error) |
808 | obj->replace (parseLine (static_cast<LDErrorObject*> (obj)->contents)); | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
809 | } |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
810 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
811 | // Close all files left unused |
309 | 812 | LDOpenFile::closeUnused(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
813 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
814 | |
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 | // ============================================================================= |
378 | 818 | ulong LDOpenFile::addObject (LDObject* obj) { |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
819 | 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
|
820 | m_objs << obj; |
271
d5ec224c1879
Laid down the foundations of the new history system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
821 | |
378 | 822 | if (obj->getType() == LDObject::Vertex) |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
823 | m_vertices << obj; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
824 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
825 | obj->setFile (this); |
309 | 826 | return numObjs() - 1; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
827 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
828 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
829 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
830 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
831 | // ============================================================================= |
232
4e44c92e21dd
Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents:
227
diff
changeset
|
832 | void LDOpenFile::insertObj (const ulong pos, LDObject* obj) { |
378 | 833 | m_history.add (new AddHistory (pos, obj)); |
834 | m_objs.insert (pos, obj); | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
835 | obj->setFile (this); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
836 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
837 | |
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 | // ============================================================================= |
378 | 841 | void LDOpenFile::forgetObject (LDObject* obj) { |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
842 | ulong idx = obj->getIndex(); |
378 | 843 | m_history.add (new DelHistory (idx, obj)); |
844 | m_objs.erase (idx); | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
845 | obj->setFile (null); |
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 | // ============================================================================= |
226
3dd9e63698cd
Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
225
diff
changeset
|
849 | bool safeToCloseAll () { |
378 | 850 | for (LDOpenFile* f : g_loadedFiles) |
851 | 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
|
852 | return false; |
3dd9e63698cd
Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
225
diff
changeset
|
853 | |
3dd9e63698cd
Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
225
diff
changeset
|
854 | return true; |
250
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
855 | } |
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
856 | |
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
857 | // ============================================================================= |
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
858 | void LDOpenFile::setObject (ulong idx, LDObject* obj) { |
378 | 859 | assert (idx < numObjs()); |
276
a21e49914264
Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
860 | |
309 | 861 | // Mark this change to history |
378 | 862 | str oldcode = object (idx)->raw (); |
309 | 863 | str newcode = obj->raw(); |
378 | 864 | m_history << new EditHistory (idx, oldcode, newcode); |
276
a21e49914264
Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
865 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
866 | obj->setFile (this); |
250
6e80f038e8df
Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents:
249
diff
changeset
|
867 | m_objs[idx] = obj; |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
868 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
869 | |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
870 | static List<LDOpenFile*> getFilesUsed (LDOpenFile* node) { |
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
871 | List<LDOpenFile*> filesUsed; |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
872 | |
378 | 873 | for (LDObject* obj : *node) { |
874 | if (obj->getType() != LDObject::Subfile) | |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
875 | continue; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
876 | |
378 | 877 | LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); |
309 | 878 | filesUsed << ref->fileInfo(); |
378 | 879 | filesUsed << getFilesUsed (ref->fileInfo()); |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
880 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
881 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
882 | return filesUsed; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
883 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
884 | |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
885 | // ============================================================================= |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
886 | // Find out which files are unused and close them. |
378 | 887 | void LDOpenFile::closeUnused () { |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
888 | List<LDOpenFile*> filesUsed = getFilesUsed (LDOpenFile::current()); |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
889 | |
309 | 890 | // Anything that's explicitly opened must not be closed |
378 | 891 | for (LDOpenFile* file : g_loadedFiles) |
892 | if (!file->implicit()) | |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
893 | filesUsed << file; |
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 | // Remove duplicated entries |
309 | 896 | filesUsed.makeUnique(); |
269
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 | // Close all open files that aren't in filesUsed |
378 | 899 | for (LDOpenFile* file : g_loadedFiles) { |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
900 | bool isused = false; |
378 | 901 | |
902 | for (LDOpenFile* usedFile : filesUsed) { | |
903 | if (file == usedFile) { | |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
904 | isused = true; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
905 | break; |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
906 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
907 | } |
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
908 | |
378 | 909 | if (!isused) |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
910 | delete file; |
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 | |
309 | 913 | g_loadedFiles.clear(); |
269
2d71227f35cb
Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents:
268
diff
changeset
|
914 | g_loadedFiles << filesUsed; |
309 | 915 | } |
916 | ||
378 | 917 | LDObject* LDOpenFile::object (ulong pos) const { |
918 | if (m_objs.size() <= pos) | |
309 | 919 | return null; |
920 | ||
921 | return m_objs[pos]; | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
922 | } |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
923 | |
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
|
924 | LDObject* LDOpenFile::obj (ulong pos) const { |
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
|
925 | 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
|
926 | } |
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
|
927 | |
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
|
928 | ulong LDOpenFile::numObjs() const { |
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
|
929 | 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
|
930 | } |
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
|
931 | |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
401
diff
changeset
|
932 | LDOpenFile& LDOpenFile::operator<< (List<LDObject*> objs) { |
378 | 933 | for (LDObject* obj : objs) |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
934 | addObject (obj); |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
935 | |
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
309
diff
changeset
|
936 | 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
|
937 | } |
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
|
938 | |
383
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
939 | bool LDOpenFile::hasUnsavedChanges() const { |
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
940 | return !implicit() && history().pos() != savePos(); |
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
941 | } |
10e60ae9ed58
File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
942 | |
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 | // ============================================================================= |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
944 | LDOpenFile* LDOpenFile::current() { |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
945 | 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
|
946 | } |
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
|
947 | |
388
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
948 | void LDOpenFile::setCurrent (LDOpenFile* f) { |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
949 | m_curfile = f; |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
950 | |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
951 | if (g_win && f) |
7ff483614aa1
Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
385
diff
changeset
|
952 | g_win->updateFileListItem (f); |
391
beef61ce962a
Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents:
390
diff
changeset
|
953 | } |
beef61ce962a
Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents:
390
diff
changeset
|
954 | |
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
|
955 | // ============================================================================= |
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
|
956 | // 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
|
957 | // a new file over it. |
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
|
958 | void LDOpenFile::closeInitialFile() { |
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
|
959 | if (g_loadedFiles.size() == 2 && |
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
|
960 | g_loadedFiles[0]->name() == "" && |
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
|
961 | !g_loadedFiles[0]->hasUnsavedChanges()) |
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
|
962 | { |
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
|
963 | delete g_loadedFiles[0]; |
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
|
964 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
965 | } |