src/file.cpp

Fri, 06 Dec 2013 00:29:44 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 06 Dec 2013 00:29:44 +0200
changeset 541
0e38beeb050a
parent 539
72ad83a67165
child 542
46a33bdc0b36
permissions
-rw-r--r--

- Renamed common.h to main.h, split the PROPERTY macro and supporting macros to property.h

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
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
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
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
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
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
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/>.
471
Santeri Piippo <crimsondusk64@gmail.com>
parents: 470
diff changeset
17 * =====================================================================
Santeri Piippo <crimsondusk64@gmail.com>
parents: 470
diff changeset
18 *
Santeri Piippo <crimsondusk64@gmail.com>
parents: 470
diff changeset
19 * file.cpp: File I/O and management.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 470
diff changeset
20 * - File loading, parsing, manipulation, saving, closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 470
diff changeset
21 * - LDraw path verification.
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 */
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23
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
24 #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
25 #include <QFileDialog>
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #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
27 #include <QApplication>
541
0e38beeb050a - Renamed common.h to main.h, split the PROPERTY macro and supporting macros to property.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 539
diff changeset
28 #include "main.h"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "config.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "file.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "misc.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "gui.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "history.h"
200
5583af82087e Merged new part and LDraw path dialogs into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 199
diff changeset
34 #include "dialogs.h"
198
f246725199dc Split some stuff into separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 192
diff changeset
35 #include "gldraw.h"
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
36 #include "moc_file.cpp"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 460
diff changeset
38 cfg (String, io_ldpath, "");
467
59549731151a Added ListConfig type, using it in recent files now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 461
diff changeset
39 cfg (List, io_recentfiles, {});
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 460
diff changeset
40 extern_cfg (String, net_downloadpath);
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 460
diff changeset
41 extern_cfg (Bool, gl_logostuds);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
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
43 static bool g_loadingMainFile = false;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
44 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
45 static bool g_aborted = false;
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
46 static LDFile* g_logoedStud = null;
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
47 static LDFile* g_logoedStud2 = null;
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
48
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
49 LDFile* LDFile::m_curfile = null;
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
50
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
52 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
53 namespace LDPaths
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
54 { static str pathError;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
55
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
56 struct
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
57 { str LDConfigPath;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 str partsPath, primsPath;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 } pathInfo;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
60
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
61 void initPaths()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
62 { if (!tryConfigure (io_ldpath))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
63 { LDrawPathDialog dlg (false);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
64
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
65 if (!dlg.exec())
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
66 exit (0);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
67
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
68 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
69 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
71
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
72 bool tryConfigure (str path)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
73 { QDir dir;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
74
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
75 if (!dir.cd (path))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
76 { pathError = "Directory does not exist.";
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
79
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
80 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
81 QStringList contents = dir.entryList (mustHave);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
82
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
83 if (contents.size() != mustHave.size())
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
84 { pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
87
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
88 pathInfo.partsPath = fmt ("%1" DIRSLASH "parts", path);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
89 pathInfo.LDConfigPath = fmt ("%1" DIRSLASH "LDConfig.ldr", path);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
90 pathInfo.primsPath = fmt ("%1" DIRSLASH "p", path);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
91
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
94
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 // Accessors
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
96 str getError()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
97 { return pathError;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
98 }
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
99
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
100 str ldconfig()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
101 { return pathInfo.LDConfigPath;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
102 }
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
103
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
104 str prims()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
105 { return pathInfo.primsPath;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
106 }
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
107
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
108 str parts()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
109 { return pathInfo.partsPath;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
110 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
114 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
115 LDFile::LDFile()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
116 { setImplicit (true);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
117 setSavePosition (-1);
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
118 setListItem (null);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
119 setHistory (new History);
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
120 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
121 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
124 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
125 LDFile::~LDFile()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
126 { // Clear everything from the model
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
127 for (LDObject* obj : getObjects())
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 delete obj;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
129
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 // Clear the cache as well
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
131 for (LDObject* obj : getCache())
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 delete obj;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
133
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
134 delete m_History;
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
135
389
ccb763dbe98e Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
136 // Remove this file from the list of files
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
137 g_loadedFiles.removeOne (this);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
138
389
ccb763dbe98e Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
139 // 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
140 // file as something else.
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
141 if (this == LDFile::current())
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
142 { bool found = false;
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
143
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
144 // Try find an explicitly loaded file - if we can't find one,
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
145 // we need to create a new file to switch to.
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
146 for (LDFile* file : g_loadedFiles)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
147 { if (!file->isImplicit())
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
148 { LDFile::setCurrent (file);
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
149 found = true;
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
150 break;
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
151 }
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
152 }
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
153
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
154 if (!found)
389
ccb763dbe98e Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
155 newFile();
ccb763dbe98e Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
156 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
157
389
ccb763dbe98e Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
158 g_win->updateFileList();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
162 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
163 LDFile* findLoadedFile (str name)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
164 { for (LDFile * file : g_loadedFiles)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
165 if (!file->getName().isEmpty() && file->getShortName() == name)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 return file;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
167
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 return null;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
172 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
173 str dirname (str path)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
174 { long lastpos = path.lastIndexOf (DIRSLASH);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
175
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
176 if (lastpos > 0)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
177 return path.left (lastpos);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
178
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
179 #ifndef _WIN32
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
180
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
181 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
182 return DIRSLASH;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
183
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
184 #endif // _WIN32
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
185
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
186 return "";
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
187 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
188
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
190 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
191 str basename (str path)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
192 { long lastpos = path.lastIndexOf (DIRSLASH);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
193
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
194 if (lastpos != -1)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
195 return path.mid (lastpos + 1);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
196
235
bb0a7bcca7eb fix basename
Santeri Piippo <crimsondusk64@gmail.com>
parents: 234
diff changeset
197 return path;
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
198 }
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
199
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
200 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
201 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
202 File* openLDrawFile (str relpath, bool subdirs)
527
47c068f2e7e3 more minor changes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 522
diff changeset
203 { log ("Opening %1...\n", relpath);
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
204 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
205 str fullPath;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
206
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
207 // LDraw models use Windows-style path separators. If we're not on Windows,
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
208 // 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
209 #ifndef WIN32
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
210 relpath.replace ("\\", "/");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 #endif // WIN32
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
212
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
213 if (LDFile::current())
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
214 { // First, try find the file in the current model's file path. We want a file
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
215 // in the immediate vicinity of the current model to override stock LDraw stuff.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
216 str partpath = fmt ("%1" DIRSLASH "%2", dirname (LDFile::current()->getName()), relpath);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
217
430
8458cf2719d1 added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 429
diff changeset
218 if (f->open (partpath, File::Read))
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
219 return f;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
220 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
221
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
222 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
223 return f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
224
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
225 // 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
226 fullPath = fmt ("%1" DIRSLASH "%2", io_ldpath, relpath);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
227
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
228 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
229 return f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
230
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
231 if (subdirs)
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
232 { // Look in sub-directories: parts and p. Also look in net_downloadpath, since that's
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
233 // where we download parts from the PT to.
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
234 for (const str& topdir : initlist<str> ({ io_ldpath, net_downloadpath }))
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
235 { for (const str& subdir : initlist<str> ({ "parts", "p" }))
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
236 { fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
237
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
238 if (f->open (fullPath, File::Read))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
239 return f;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
240 }
497
c51941e590b6 a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
241 }
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
242 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
243
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
244 // Did not find the file.
527
47c068f2e7e3 more minor changes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 522
diff changeset
245 log ("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
246 delete f;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 return null;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
251 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
252 void FileLoader::start()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
253 { setDone (false);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
254 setProgress (0);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
255 setAborted (false);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
256
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
257 if (isOnForeground())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
258 { g_aborted = false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
259
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
260 // Show a progress dialog if we're loading the main file here so we can
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
261 // show progress updates and keep the WM posted that we're still here.
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
262 // Of course we cannot exec() the dialog because then the dialog would
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
263 // block.
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
264 dlg = new OpenProgressDialog (g_win);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
265 dlg->setNumLines (getLines().size());
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
266 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
267 dlg->show();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
268
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
269 // Connect the loader in so we can show updates
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
270 connect (this, SIGNAL (workDone()), dlg, SLOT (accept()));
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
271 connect (dlg, SIGNAL (rejected()), this, SLOT (abort()));
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
272 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
273 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
274 dlg = null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
275
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
276 // Begin working
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
277 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
278 }
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
279
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
280 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
281 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
282 void FileLoader::work (int i)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
283 { // User wishes to abort, so stop here now.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
284 if (isAborted())
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
285 { for (LDObject* obj : m_Objects)
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
286 delete obj;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
287
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
288 m_Objects.clear();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
289 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
290 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
291 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
292
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
293 // Parse up to 300 lines per iteration
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
294 int max = i + 300;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
295
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
296 for (; i < max && i < (int) getLines().size(); ++i)
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
297 { str line = getLines()[i];
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
298
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 // Trim the trailing newline
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
300 QChar c;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
301
510
ee90c55dfeef Fixed: LDForge would sometimes crash over unitialized data in the GL renderer. This crash sure eluded me for a while. Turned out zoomToFit(), which uses m_width and m_height is called before resizeGL() which initializes these variables. This data is used in an operator new[] call.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 509
diff changeset
302 while (!line.isEmpty() && ((c = line[line.length() - 1]) == '\n' || c == '\r'))
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
303 line.chop (1);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
304
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
305 LDObject* obj = parseLine (line);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
306
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 // Check for parse errors and warn about tthem
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
308 if (obj->getType() == LDObject::Error)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
309 { log ("Couldn't parse line #%1: %2", getProgress() + 1, static_cast<LDError*> (obj)->reason);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
310
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
311 if (getWarnings() != null)
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
312 (*getWarnings())++;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
313 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
314
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
315 m_Objects << obj;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
316 setProgress (i);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
317
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
318 // If we have a dialog pointer, update the progress now
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
319 if (isOnForeground())
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
320 dlg->updateProgress (i);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
322
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
323 // If we're done now, tell the environment we're done and stop.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
324 if (i >= ((int) getLines().size()) - 1)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
325 { emit workDone();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
326 setDone (true);
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
327 return;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
328 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
329
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
330 // Otherwise, continue, by recursing back.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
331 if (!isDone())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
332 { // If we have a dialog to show progress output to, we cannot just call
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
333 // work() again immediately as the dialog needs some processor cycles as
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
334 // well. Thus, take a detour through the event loop by using the
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
335 // meta-object system.
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
336 //
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
337 // This terminates the loop here and control goes back to the function
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
338 // which called the file loader. It will keep processing the event loop
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
339 // until we're ready (see loadFileContents), thus the event loop will
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
340 // eventually catch the invokation we throw here and send us back. Though
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
341 // it's not technically recursion anymore, more like a for loop. :P
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
342 if (isOnForeground())
518
623c01862eb8 fixed: the file loader would skip every 300th line. And I thought I was going nuts when my quads kept disappearing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
343 QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (int, 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
344 else
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
345 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
346 }
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
347 }
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
348
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
349 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
350 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
351 void FileLoader::abort()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
352 { setAborted (true);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
353
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
354 if (isOnForeground())
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
355 g_aborted = true;
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
356 }
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
357
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
358 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
359 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
360 QList<LDObject*> loadFileContents (File* f, int* numWarnings, bool* ok)
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
361 { QList<str> lines;
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
362 QList<LDObject*> objs;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
363
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
364 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
365 *numWarnings = 0;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
366
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
367 // Calculate the amount of lines
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
368 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
369 lines << line;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
370
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
371 f->rewind();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
372
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
373 FileLoader* loader = new FileLoader;
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
374 loader->setWarnings (numWarnings);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
375 loader->setLines (lines);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
376 loader->setOnForeground (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
377 loader->start();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
378
478
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
379 // After start() returns, if the loader isn't done yet, it's delaying
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
380 // its next iteration through the event loop. We need to catch this here
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
381 // by telling the event loop to tick, which will tick the file loader again.
c7f8989c995f bit of a clarification
Santeri Piippo <crimsondusk64@gmail.com>
parents: 477
diff changeset
382 // We keep doing this until the file loader is ready.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
383 while (loader->isDone() == 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
384 qApp->processEvents();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
385
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
386 // If we wanted the success value, supply that now
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
387 if (ok)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
388 *ok = !loader->isAborted();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
389
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
390 objs = loader->getObjects();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 return objs;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
395 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
396 LDFile* openDATFile (str path, bool search)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
397 { // Convert the file name to lowercase since some parts contain uppercase
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 // 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
399 // 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
400 File* f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
401
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
402 if (search)
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
403 f = openLDrawFile (path.toLower(), true);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
404 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
405 { f = new File (path, File::Read);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
406
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
407 if (!*f)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
408 { delete f;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
409 return null;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
410 }
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
411 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
412
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
413 if (!f)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 return null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
415
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
416 LDFile* load = new LDFile;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
417 load->setName (path);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
418
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
419 int 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
420 bool ok;
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
421 QList<LDObject*> objs = loadFileContents (f, &numWarnings, &ok);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
422
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
423 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
424 return null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
425
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
426 for (LDObject* obj : objs)
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
427 load->addObject (obj);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
428
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
429 delete f;
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
430 g_loadedFiles << load;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
431
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
432 if (g_loadingMainFile)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
433 { LDFile::setCurrent (load);
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
434 g_win->R()->setFile (load);
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
435 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
436 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
437
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 return load;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
442 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
443 bool LDFile::isSafeToClose()
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
444 { typedef QMessageBox msgbox;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
445 setlocale (LC_ALL, "C");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
446
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 // If we have unsaved changes, warn and give the option of saving.
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
448 if (hasUnsavedChanges())
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
449 { str message = fmt ("There are unsaved changes to %1. Should it be saved?",
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
450 (getName().length() > 0) ? getName() : "<anonymous>");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
451
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
452 int button = msgbox::question (g_win, "Unsaved Changes", message,
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
453 (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
454
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
455 switch (button)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
456 { case msgbox::Yes:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
457
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
458 // If we don't have a file path yet, we have to ask the user for one.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
459 if (getName().length() == 0)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
460 { str newpath = QFileDialog::getSaveFileName (g_win, "Save As",
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
461 LDFile::current()->getName(), "LDraw files (*.dat *.ldr)");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
462
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
463 if (newpath.length() == 0)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
464 return false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
465
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
466 setName (newpath);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
468
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
469 if (!save())
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
470 { message = fmt (QObject::tr ("Failed to save %1: %2\nDo you still want to close?"),
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
471 getName(), strerror (errno));
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
472
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
473 if (msgbox::critical (g_win, "Save Failure", message,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
474 (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
475 { return false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
476 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
477 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
478
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
479 break;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
480
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
481 case msgbox::Cancel:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
482 return false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
483
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
484 default:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
485 break;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
488
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
493 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
494 void closeAll()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
495 { // Remove all loaded files and the objects they contain
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
496 QList<LDFile*> files = g_loadedFiles;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
497
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
498 for (LDFile * file : files)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499 delete file;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
503 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
504 void newFile()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
505 { // Create a new anonymous file and set it to our current
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
506 LDFile* f = new LDFile;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
507 f->setName ("");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
508 f->setImplicit (false);
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
509 g_loadedFiles << f;
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
510 LDFile::setCurrent (f);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
511
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
512 LDFile::closeInitialFile();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
513
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
514 g_win->R()->setFile (f);
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
515 g_win->doFullRefresh();
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
516 g_win->updateTitle();
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
517 f->getHistory()->updateActions();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
521 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
522 void addRecentFile (str path)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
523 { alias rfiles = io_recentfiles.value;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
524 int idx = rfiles.indexOf (path);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
525
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 // If this file already is in the list, pop it out.
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
527 if (idx != -1)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
528 { if (rfiles.size() == 1)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
529 return; // only recent file - abort and do nothing
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
530
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 // Pop it out.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
532 rfiles.removeAt (idx);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
533 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
534
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535 // If there's too many recent files, drop one out.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
536 while (rfiles.size() > (g_MaxRecentFiles - 1))
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
537 rfiles.removeAt (0);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
538
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 // Add the file
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
540 rfiles << path;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
541
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 460
diff changeset
542 Config::save();
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
543 g_win->updateRecentFilesMenu();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
547 // Open an LDraw file and set it as the main model
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
548 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
549 void openMainFile (str path)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
550 { g_loadingMainFile = true;
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
551 LDFile* file = openDATFile (path, false);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
552
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
553 if (!file)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
554 { // Loading failed, thus drop down to a new file since we
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
555 // closed everything prior.
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
556 newFile();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
557
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
558 if (!g_aborted)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
559 { // Tell the user loading failed.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
560 setlocale (LC_ALL, "C");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
561 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
562 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
563
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
564 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
567
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
568 file->setImplicit (false);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
569
390
57be36dfa55e behavior update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 389
diff changeset
570 // If we have an anonymous, unchanged file open as the only open file
57be36dfa55e behavior update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 389
diff changeset
571 // (aside of the one we just opened), close it now.
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
572 LDFile::closeInitialFile();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
573
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 // Rebuild the object tree view now.
422
00eedf400f72 Fixed crash on opening a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
575 LDFile::setCurrent (file);
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
576 g_win->doFullRefresh();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
577
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 // Add it to the recent files list.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
579 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
580 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
584 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
585 bool LDFile::save (str savepath)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
586 { if (!savepath.length())
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
587 savepath = getName();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
588
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
589 File f (savepath, File::Write);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
590
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
591 if (!f)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592 return false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
593
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
594 // 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
595 // 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
596 // called "s" or "48", prepend that into the name.
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
597 LDComment* fpathComment = null;
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
598 LDObject* first = getObject (1);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
599
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
600 if (!isImplicit() && first != null && first->getType() == LDObject::Comment)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
601 { fpathComment = static_cast<LDComment*> (first);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
602
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
603 if (fpathComment->text.left (6) == "Name: ")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
604 { str newname;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
605 str dir = basename (dirname (savepath));
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
606
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
607 if (dir == "s" || dir == "48")
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
608 newname = dir + "\\";
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
609
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
610 newname += basename (savepath);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
611 fpathComment->text = fmt ("Name: %1", newname);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
612 g_win->buildObjList();
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
613 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
614 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
615
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
616 // File is open, now save the model to it. Note that LDraw requires files to
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
617 // have DOS line endings, so we terminate the lines with \r\n.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
618 for (LDObject* obj : getObjects())
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
619 f.write (obj->raw() + "\r\n");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
620
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
621 // File is saved, now clean up.
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
622 f.close();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
623
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
624 // We have successfully saved, update the save position now.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
625 setSavePosition (getHistory()->getPosition());
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
626 setName (savepath);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
627
389
ccb763dbe98e Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
628 g_win->updateFileListItem (this);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
629 g_win->updateTitle();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
631 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
633 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
634 // -----------------------------------------------------------------------------
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
635 #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
636 if (tokens.size() != N) \
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
637 return new LDError (line, "Bad amount of tokens");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
638
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
639 #define CHECK_TOKEN_NUMBERS(MIN, MAX) \
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
640 for (int i = MIN; i <= MAX; ++i) \
508
7ace3537a560 removed some custom functions in favor of Qt implementations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
641 if (!numeric (tokens[i])) \
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
642 return new LDError (line, fmt ("Token #%1 was `%2`, expected a number", (i + 1), tokens[i]));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
644 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
645 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
646 static vertex parseVertex (QStringList& s, const int n)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
647 { vertex v;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
648
508
7ace3537a560 removed some custom functions in favor of Qt implementations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
649 for (const Axis ax : g_Axes)
7ace3537a560 removed some custom functions in favor of Qt implementations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
650 v[ax] = s[n + ax].toDouble();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
651
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652 return v;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
655 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
656 // This is the LDraw code parser function. It takes in a string containing LDraw
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
657 // 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
658 // the object will be LDError if it could not be parsed properly.
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
659 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
660 LDObject* parseLine (str line)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
661 { QStringList tokens = line.split (" ", str::SkipEmptyParts);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
662
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
663 if (tokens.size() <= 0)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
664 { // Line was empty, or only consisted of whitespace
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
665 return new LDEmpty;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
666 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
667
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
668 if (tokens[0].length() != 1 || tokens[0][0].isDigit() == false)
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
669 return new LDError (line, "Illogical line code");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
670
373
91bea18bd77a Fixed compilation under windows/qt5
Santeri Piippo <crimsondusk64@gmail.com>
parents: 371
diff changeset
671 int num = tokens[0][0].digitValue();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
672
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
673 switch (num)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
674 { case 0:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
675 { // Comment
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
676 str comm = line.mid (line.indexOf ("0") + 1);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
677
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
678 // Remove any leading whitespace
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
679 while (comm[0] == ' ')
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
680 comm.remove (0, 1);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
681
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
682 // Handle BFC statements
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
683 if (tokens.size() > 2 && tokens[1] == "BFC")
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
684 { for (int i = 0; i < LDBFC::NumStatements; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
685 if (comm == fmt ("BFC %1", LDBFC::statements [i]))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
686 return new LDBFC ( (LDBFC::Type) i);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
687
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
688 // MLCAD is notorious for stuffing these statements in parts it
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
689 // creates. The above block only handles valid statements, so we
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
690 // need to handle MLCAD-style invertnext, clip and noclip separately.
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
691 struct
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
692 { const char* a;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
693 LDBFC::Type b;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
694 } BFCData[] =
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
695 { { "INVERTNEXT", LDBFC::InvertNext },
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
696 { "NOCLIP", LDBFC::NoClip },
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
697 { "CLIP", LDBFC::Clip }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
698 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
699
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
700 for (const auto & i : BFCData)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
701 if (comm == fmt ("BFC CERTIFY %1", i.a))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
702 return new LDBFC (i.b);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
703 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
704
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
705 if (tokens.size() > 2 && tokens[1] == "!LDFORGE")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
706 { // Handle LDForge-specific types, they're embedded into comments too
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
707 if (tokens[2] == "VERTEX")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
708 { // Vertex (0 !LDFORGE VERTEX)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
709 CHECK_TOKEN_COUNT (7)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
710 CHECK_TOKEN_NUMBERS (3, 6)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
711
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
712 LDVertex* obj = new LDVertex;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
713 obj->setColor (tokens[3].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
714
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
715 for (const Axis ax : g_Axes)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
716 obj->pos[ax] = tokens[4 + ax].toDouble(); // 4 - 6
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
717
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
718 return obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
719 } elif (tokens[2] == "OVERLAY")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
720
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
721 { CHECK_TOKEN_COUNT (9);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
722 CHECK_TOKEN_NUMBERS (5, 8)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
723
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
724 LDOverlay* obj = new LDOverlay;
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
725 obj->setFileName (tokens[3]);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
726 obj->setCamera (tokens[4].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
727 obj->setX (tokens[5].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
728 obj->setY (tokens[6].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
729 obj->setWidth (tokens[7].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
730 obj->setHeight (tokens[8].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
731 return obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
732 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
733 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
734
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
735 // Just a regular comment:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
736 LDComment* obj = new LDComment;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
737 obj->text = comm;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
738 return obj;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
739 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
740
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
741 case 1:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
742 { // Subfile
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
743 CHECK_TOKEN_COUNT (15)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
744 CHECK_TOKEN_NUMBERS (1, 13)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
745
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
746 // Try open the file. Disable g_loadingMainFile temporarily since we're
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
747 // not loading the main file now, but the subfile in question.
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
748 bool tmp = g_loadingMainFile;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
749 g_loadingMainFile = false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
750 LDFile* load = getFile (tokens[14]);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
751 g_loadingMainFile = tmp;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
752
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
753 // If we cannot open the file, mark it an error
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
754 if (!load)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
755 { LDError* obj = new LDError (line, fmt ("Could not open %1", tokens[14]));
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
756 obj->setFileReferenced (tokens[14]);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
757 return obj;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
758 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
759
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
760 LDSubfile* obj = new LDSubfile;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
761 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
762 obj->setPosition (parseVertex (tokens, 2)); // 2 - 4
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
763
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
764 matrix transform;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
765
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
766 for (int i = 0; i < 9; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
767 transform[i] = tokens[i + 5].toDouble(); // 5 - 13
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
768
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
769 obj->setTransform (transform);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
770 obj->setFileInfo (load);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
771 return obj;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
772 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
773
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
774 case 2:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
775 { CHECK_TOKEN_COUNT (8)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
776 CHECK_TOKEN_NUMBERS (1, 7)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
777
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
778 // Line
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
779 LDLine* obj = new LDLine;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
780 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
781
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
782 for (int i = 0; i < 2; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
783 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
784
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 423
diff changeset
785 return obj;
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 423
diff changeset
786 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
787
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
788 case 3:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
789 { CHECK_TOKEN_COUNT (11)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
790 CHECK_TOKEN_NUMBERS (1, 10)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
791
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
792 // Triangle
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
793 LDTriangle* obj = new LDTriangle;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
794 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
795
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
796 for (int i = 0; i < 3; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
797 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
798
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
799 return obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
800 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
801
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
802 case 4:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
803 case 5:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
804 { CHECK_TOKEN_COUNT (14)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
805 CHECK_TOKEN_NUMBERS (1, 13)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
806
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
807 // Quadrilateral / Conditional line
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
808 LDObject* obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
809
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
810 if (num == 4)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
811 obj = new LDQuad;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
812 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
813 obj = new LDCndLine;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
814
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
815 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
816
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
817 for (int i = 0; i < 4; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
818 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
819
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
820 return obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
821 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
822
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
823 default: // Strange line we couldn't parse
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
824 return new LDError (line, "Unknown line code number");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
825 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
826 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
827
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
828 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
829 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
830 LDFile* getFile (str filename)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
831 { // Try find the file in the list of loaded files
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
832 LDFile* load = findLoadedFile (filename);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
833
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
834 // If it's not loaded, try open it
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
835 if (!load)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
836 load = openDATFile (filename, true);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
837
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
838 return load;
183
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
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
841 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
842 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
843 void reloadAllSubfiles()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
844 { if (!LDFile::current())
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
845 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
846
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
847 g_loadedFiles.clear();
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
848 g_loadedFiles << LDFile::current();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
849
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
850 // Go through all objects in the current file and reload the subfiles
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
851 for (LDObject* obj : LDFile::current()->getObjects())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
852 { if (obj->getType() == LDObject::Subfile)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
853 { LDSubfile* ref = static_cast<LDSubfile*> (obj);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
854 LDFile* fileInfo = getFile (ref->getFileInfo()->getName());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
855
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
856 if (fileInfo)
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
857 ref->setFileInfo (fileInfo);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
858 else
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
859 ref->replace (new LDError (ref->raw(), "Could not open referred file"));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
860 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
861
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
862 // 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
863 // of loading errors. Circumstances may be different now.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
864 if (obj->getType() == LDObject::Error)
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
865 obj->replace (parseLine (static_cast<LDError*> (obj)->contents));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
866 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
867
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
868 // Close all files left unused
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
869 LDFile::closeUnused();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
871
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
872 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
873 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
874 int LDFile::addObject (LDObject* obj)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
875 { getHistory()->add (new AddHistory (getObjects().size(), obj));
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
876 m_Objects << obj;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
877
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
878 if (obj->getType() == LDObject::Vertex)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
879 m_Vertices << obj;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
880
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
881 obj->setFile (this);
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
882 return getObjectCount() - 1;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
883 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
884
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
885 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
886 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
887 void LDFile::addObjects (const QList<LDObject*> objs)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
888 { for (LDObject * obj : objs)
484
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
889 if (obj)
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
890 addObject (obj);
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
891 }
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
892
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
893 // =============================================================================
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
894 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
895 void LDFile::insertObj (int pos, LDObject* obj)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
896 { getHistory()->add (new AddHistory (pos, obj));
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
897 m_Objects.insert (pos, obj);
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
898 obj->setFile (this);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
899 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
900
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
901 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
902 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
903 void LDFile::forgetObject (LDObject* obj)
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
904 { int idx = obj->getIndex();
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
905 getHistory()->add (new DelHistory (idx, obj));
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
906 m_Objects.removeAt (idx);
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
907 obj->setFile (null);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
908 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
909
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
910 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
911 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
912 bool safeToCloseAll()
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
913 { for (LDFile* f : g_loadedFiles)
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
914 if (!f->isSafeToClose())
226
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
915 return false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
916
226
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
917 return true;
250
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
918 }
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
919
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
920 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
921 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
922 void LDFile::setObject (int idx, LDObject* obj)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
923 { assert (idx < m_Objects.size());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
924
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
925 // Mark this change to history
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
926 str oldcode = getObject (idx)->raw();
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
927 str newcode = obj->raw();
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
928 *m_History << new EditHistory (idx, oldcode, newcode);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
929
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
930 obj->setFile (this);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
931 m_Objects[idx] = obj;
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
932 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
933
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
934 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
935 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
936 static QList<LDFile*> getFilesUsed (LDFile* node)
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
937 { QList<LDFile*> filesUsed;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
938
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
939 for (LDObject* obj : node->getObjects())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
940 { if (obj->getType() != LDObject::Subfile)
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
941 continue;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
942
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
943 LDSubfile* ref = static_cast<LDSubfile*> (obj);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
944 filesUsed << ref->getFileInfo();
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
945 filesUsed << getFilesUsed (ref->getFileInfo());
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
946 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
947
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
948 return filesUsed;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
949 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
950
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
951 // =============================================================================
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
952 // Find out which files are unused and close them.
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
953 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
954 void LDFile::closeUnused()
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
955 { QList<LDFile*> filesUsed = getFilesUsed (LDFile::current());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
956
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
957 // Anything that's explicitly opened must not be closed
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
958 for (LDFile* file : g_loadedFiles)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
959 if (!file->isImplicit())
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
960 filesUsed << file;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
961
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
962 // Remove duplicated entries
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
963 removeDuplicates (filesUsed);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
964
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
965 // Close all open files that aren't in filesUsed
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
966 for (LDFile* file : g_loadedFiles)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
967 { bool isused = false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
968
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
969 for (LDFile* usedFile : filesUsed)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
970 { if (file == usedFile)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
971 { isused = true;
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
972 break;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
973 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
974 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
975
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
976 if (!isused)
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
977 delete file;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
978 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
979
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
980 g_loadedFiles.clear();
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
981 g_loadedFiles << filesUsed;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
982 }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
983
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
984 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
985 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
986 LDObject* LDFile::getObject (int pos) const
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
987 { if (m_Objects.size() <= pos)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
988 return null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
989
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
990 return m_Objects[pos];
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
991 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
992
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
993 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
994 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
995 int LDFile::getObjectCount() const
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
996 { return getObjects().size();
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
997 }
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
998
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
999 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1000 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1001 bool LDFile::hasUnsavedChanges() const
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1002 { return !isImplicit() && getHistory()->getPosition() != getSavePosition();
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
1003 }
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
1004
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1005 // =============================================================================
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1006 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1007 str LDFile::getShortName()
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1008 { if (!getName().isEmpty())
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1009 return basename (getName());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1010
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1011 if (!getDefaultName().isEmpty())
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1012 return getDefaultName();
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
1013
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
1014 return tr ("<anonymous>");
416
be1824f53c48 Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
1015 }
be1824f53c48 Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
1016
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
1017 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1018 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
1019 QList<LDObject*> LDFile::inlineContents (LDSubfile::InlineFlags flags)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1020 { // Possibly substitute with logoed studs:
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1021 // stud.dat -> stud-logo.dat
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1022 // stud2.dat -> stud-logo2.dat
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1023 if (gl_logostuds && (flags & LDSubfile::RendererInline))
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1024 { if (getName() == "stud.dat" && g_logoedStud)
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1025 return g_logoedStud->inlineContents (flags);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1026
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1027 elif (getName() == "stud2.dat" && g_logoedStud2)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1028 return g_logoedStud2->inlineContents (flags);
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1029 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1030
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
1031 QList<LDObject*> objs, objcache;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1032
460
b230ae09c8e5 Cut the Object-suffix from LDObject types, it doesn't help things at all
Santeri Piippo <crimsondusk64@gmail.com>
parents: 459
diff changeset
1033 bool deep = flags & LDSubfile::DeepInline,
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1034 doCache = flags & LDSubfile::CacheInline;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1035
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1036 // If we have this cached, just clone that
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1037 if (deep && getCache().size())
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1038 { for (LDObject* obj : getCache())
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1039 objs << obj->clone();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1040 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1041 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1042 { if (!deep)
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1043 doCache = false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1044
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1045 for (LDObject* obj : getObjects())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1046 { // Skip those without scemantic meaning
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1047 if (!obj->isScemantic())
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1048 continue;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1049
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1050 // Got another sub-file reference, inline it if we're deep-inlining. If not,
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1051 // just add it into the objects normally. Also, we only cache immediate
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1052 // subfiles and this is not one. Yay, recursion!
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1053 if (deep && obj->getType() == LDObject::Subfile)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1054 { LDSubfile* ref = static_cast<LDSubfile*> (obj);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1055
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1056 // We only want to cache immediate subfiles, so shed the caching
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1057 // flag when recursing deeper in hierarchy.
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
1058 QList<LDObject*> otherobjs = ref->inlineContents (flags & ~ (LDSubfile::CacheInline));
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1059
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1060 for (LDObject * otherobj : otherobjs)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1061 { // Cache this object, if desired
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1062 if (doCache)
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1063 objcache << otherobj->clone();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1064
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1065 objs << otherobj;
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1066 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1067 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1068 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1069 { if (doCache)
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1070 objcache << obj->clone();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1071
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1072 objs << obj->clone();
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1073 }
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1074 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1075
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1076 if (doCache)
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1077 setCache (objcache);
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1078 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1079
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1080 return objs;
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1081 }
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1082
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1083 // =============================================================================
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1084 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1085 LDFile* LDFile::current()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1086 { 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
1087 }
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
1088
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1089 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1090 // Sets the given file as the current one on display. At some point in time this
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1091 // was an operation completely unheard of. ;)
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1092 //
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1093 // FIXME: f can be temporarily null. This probably should not be the case.
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1094 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1095 void LDFile::setCurrent (LDFile* f)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1096 { // Implicit files were loaded for caching purposes and must never be set
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1097 // current.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1098 if (f && f->isImplicit())
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1099 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1100
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
1101 m_curfile = f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1102
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1103 if (g_win && f)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1104 { // A ton of stuff needs to be updated
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
1105 g_win->updateFileListItem (f);
416
be1824f53c48 Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
1106 g_win->buildObjList();
422
00eedf400f72 Fixed crash on opening a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
1107 g_win->updateTitle();
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
1108 g_win->R()->setFile (f);
534
3ed2ebcbc84f Made rotation/pan/zoom values camera-dependant (so now there's 7 sets of them instead of 1)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 527
diff changeset
1109 g_win->R()->resetAllAngles();
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1110 g_win->R()->repaint();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1111
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
1112 log ("Changed file to %1", f->getShortName());
416
be1824f53c48 Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
1113 }
391
beef61ce962a Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 390
diff changeset
1114 }
beef61ce962a Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 390
diff changeset
1115
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
1116 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1117 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1118 int LDFile::countExplicitFiles()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1119 { int count = 0;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1120
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1121 for (LDFile* f : g_loadedFiles)
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1122 if (f->isImplicit() == false)
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1123 count++;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1124
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1125 return count;
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1126 }
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1127
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1128 // =============================================================================
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
1129 // 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
1130 // a new file over it.
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1131 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1132 void LDFile::closeInitialFile()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1133 { if (
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1134 countExplicitFiles() == 2 &&
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1135 g_loadedFiles[0]->getName() == "" &&
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1136 !g_loadedFiles[0]->hasUnsavedChanges()
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1137 )
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
1138 delete g_loadedFiles[0];
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1139 }
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1140
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1141 // =============================================================================
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1142 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1143 void loadLogoedStuds()
513
29eb671b34f6 Added a crash catcher which trigger under Linux. It calls GDB and tries to get a backtrace. Also integrated assertion failure handling to this new system. Removed the print() function in the process (because the new bomb box uses a text edit and QTextDocuments's print method clashes with the macro and I figured it was a good idea to rid it anyway) and replaced all calls with log().
Santeri Piippo <crimsondusk64@gmail.com>
parents: 510
diff changeset
1144 { log ("Loading logoed studs...\n");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1145
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1146 delete g_logoedStud;
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1147 delete g_logoedStud2;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1148
458
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1149 g_logoedStud = openDATFile ("stud-logo.dat", true);
cb360f4d8979 Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 457
diff changeset
1150 g_logoedStud2 = openDATFile ("stud2-logo.dat", true);
491
7d1b5ecd76c0 it's LDForge's 1st birthday!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 484
diff changeset
1151 }
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1152
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1153 // =============================================================================
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1154 // -----------------------------------------------------------------------------
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1155 void LDFile::addToSelection (LDObject* obj) // [protected]
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1156 { if (obj->isSelected())
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1157 return;
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1158
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1159 assert (obj->getFile() == this);
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1160 m_sel << obj;
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1161 obj->setSelected (true);
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1162 }
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1163
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1164 // =============================================================================
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1165 // -----------------------------------------------------------------------------
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1166 void LDFile::removeFromSelection (LDObject* obj) // [protected]
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1167 { if (!obj->isSelected())
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1168 return;
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1169
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1170 assert (obj->getFile() == this);
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1171 m_sel.removeOne (obj);
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1172 obj->setSelected (false);
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1173 }
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1174
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1175 // =============================================================================
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1176 // -----------------------------------------------------------------------------
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1177 void LDFile::clearSelection()
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1178 { for (LDObject* obj : m_sel)
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1179 removeFromSelection (obj);
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1180
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1181 assert (m_sel.isEmpty());
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1182 }
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1183
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1184 // =============================================================================
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1185 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
1186 const QList<LDObject*>& LDFile::getSelection() const
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1187 { return m_sel;
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1188 }

mercurial