src/file.cpp

Fri, 06 Dec 2013 20:53:36 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 06 Dec 2013 20:53:36 +0200
changeset 542
46a33bdc0b36
parent 541
0e38beeb050a
child 551
0efe5dbcef07
permissions
-rw-r--r--

- Improved coordinate rounding, replaced the hack with a proper implementation, now rounds properly and works on subfiles as well

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);
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
511 LDFile::closeInitialFile();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
512 g_win->R()->setFile (f);
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
513 g_win->doFullRefresh();
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
514 g_win->updateTitle();
542
46a33bdc0b36 - Improved coordinate rounding, replaced the hack with a proper implementation, now rounds properly and works on subfiles as well
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
515 g_win->updateActions();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
517
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518 // =============================================================================
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
519 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
520 void addRecentFile (str path)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
521 { alias rfiles = io_recentfiles.value;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
522 int idx = rfiles.indexOf (path);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
523
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 // 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
525 if (idx != -1)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
526 { if (rfiles.size() == 1)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
527 return; // only recent file - abort and do nothing
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
528
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529 // Pop it out.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
530 rfiles.removeAt (idx);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
532
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
533 // If there's too many recent files, drop one out.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
534 while (rfiles.size() > (g_MaxRecentFiles - 1))
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
535 rfiles.removeAt (0);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
536
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 // Add the file
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
538 rfiles << path;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
539
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 460
diff changeset
540 Config::save();
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
541 g_win->updateRecentFilesMenu();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544 // =============================================================================
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
545 // 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
546 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
547 void openMainFile (str path)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
548 { g_loadingMainFile = true;
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
549 LDFile* file = openDATFile (path, false);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
550
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
551 if (!file)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
552 { // 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
553 // closed everything prior.
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
554 newFile();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
555
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
556 if (!g_aborted)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
557 { // Tell the user loading failed.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
558 setlocale (LC_ALL, "C");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
559 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
560 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
561
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
562 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
565
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
566 file->setImplicit (false);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
567
390
57be36dfa55e behavior update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 389
diff changeset
568 // 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
569 // (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
570 LDFile::closeInitialFile();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
571
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 // Rebuild the object tree view now.
422
00eedf400f72 Fixed crash on opening a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
573 LDFile::setCurrent (file);
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
574 g_win->doFullRefresh();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
575
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
576 // Add it to the recent files list.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
577 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
578 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 // =============================================================================
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
582 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
583 bool LDFile::save (str savepath)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
584 { if (!savepath.length())
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
585 savepath = getName();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
586
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
587 File f (savepath, File::Write);
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 if (!f)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 return false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
591
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
592 // 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
593 // 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
594 // 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
595 LDComment* fpathComment = null;
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
596 LDObject* first = getObject (1);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
597
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
598 if (!isImplicit() && first != null && first->getType() == LDObject::Comment)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
599 { fpathComment = static_cast<LDComment*> (first);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
600
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
601 if (fpathComment->text.left (6) == "Name: ")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
602 { str newname;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
603 str dir = basename (dirname (savepath));
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
604
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
605 if (dir == "s" || dir == "48")
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
606 newname = dir + "\\";
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
607
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
608 newname += basename (savepath);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
609 fpathComment->text = fmt ("Name: %1", newname);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
610 g_win->buildObjList();
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
611 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
612 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
613
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
614 // 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
615 // 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
616 for (LDObject* obj : getObjects())
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
617 f.write (obj->raw() + "\r\n");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
618
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
619 // File is saved, now clean up.
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
620 f.close();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
621
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622 // 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
623 setSavePosition (getHistory()->getPosition());
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
624 setName (savepath);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
625
389
ccb763dbe98e Added actions for saving all files, closing and closing all files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
626 g_win->updateFileListItem (this);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
627 g_win->updateTitle();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
629 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
631 // =============================================================================
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
632 // -----------------------------------------------------------------------------
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
633 #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
634 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
635 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
636
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
637 #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
638 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
639 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
640 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
641
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
642 // =============================================================================
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
643 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
644 static vertex parseVertex (QStringList& s, const int n)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
645 { vertex v;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
646
508
7ace3537a560 removed some custom functions in favor of Qt implementations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
647 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
648 v[ax] = s[n + ax].toDouble();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
649
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 return v;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
654 // 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
655 // 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
656 // 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
657 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
658 LDObject* parseLine (str line)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
659 { QStringList tokens = line.split (" ", str::SkipEmptyParts);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
660
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
661 if (tokens.size() <= 0)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
662 { // 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
663 return new LDEmpty;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
664 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
665
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
666 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
667 return new LDError (line, "Illogical line code");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
668
373
91bea18bd77a Fixed compilation under windows/qt5
Santeri Piippo <crimsondusk64@gmail.com>
parents: 371
diff changeset
669 int num = tokens[0][0].digitValue();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
670
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
671 switch (num)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
672 { case 0:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
673 { // Comment
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
674 str comm = line.mid (line.indexOf ("0") + 1);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
675
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
676 // Remove any leading whitespace
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
677 while (comm[0] == ' ')
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
678 comm.remove (0, 1);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
679
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
680 // Handle BFC statements
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
681 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
682 { for (int i = 0; i < LDBFC::NumStatements; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
683 if (comm == fmt ("BFC %1", LDBFC::statements [i]))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
684 return new LDBFC ( (LDBFC::Type) i);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
685
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
686 // 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
687 // 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
688 // 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
689 struct
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
690 { const char* a;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
691 LDBFC::Type b;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
692 } BFCData[] =
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
693 { { "INVERTNEXT", LDBFC::InvertNext },
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
694 { "NOCLIP", LDBFC::NoClip },
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
695 { "CLIP", LDBFC::Clip }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
696 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
697
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
698 for (const auto & i : BFCData)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
699 if (comm == fmt ("BFC CERTIFY %1", i.a))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
700 return new LDBFC (i.b);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
701 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
702
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
703 if (tokens.size() > 2 && tokens[1] == "!LDFORGE")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
704 { // 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
705 if (tokens[2] == "VERTEX")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
706 { // Vertex (0 !LDFORGE VERTEX)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
707 CHECK_TOKEN_COUNT (7)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
708 CHECK_TOKEN_NUMBERS (3, 6)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
709
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
710 LDVertex* obj = new LDVertex;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
711 obj->setColor (tokens[3].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
712
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
713 for (const Axis ax : g_Axes)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
714 obj->pos[ax] = tokens[4 + ax].toDouble(); // 4 - 6
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
715
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
716 return obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
717 } elif (tokens[2] == "OVERLAY")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
718
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
719 { CHECK_TOKEN_COUNT (9);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
720 CHECK_TOKEN_NUMBERS (5, 8)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
721
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
722 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
723 obj->setFileName (tokens[3]);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
724 obj->setCamera (tokens[4].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
725 obj->setX (tokens[5].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
726 obj->setY (tokens[6].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
727 obj->setWidth (tokens[7].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
728 obj->setHeight (tokens[8].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
729 return obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
730 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
731 }
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 // Just a regular comment:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
734 LDComment* obj = new LDComment;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
735 obj->text = comm;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
736 return obj;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
737 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
738
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
739 case 1:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
740 { // Subfile
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
741 CHECK_TOKEN_COUNT (15)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
742 CHECK_TOKEN_NUMBERS (1, 13)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
743
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
744 // 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
745 // 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
746 bool tmp = g_loadingMainFile;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
747 g_loadingMainFile = false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
748 LDFile* load = getFile (tokens[14]);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
749 g_loadingMainFile = tmp;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
750
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
751 // 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
752 if (!load)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
753 { 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
754 obj->setFileReferenced (tokens[14]);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
755 return obj;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
757
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
758 LDSubfile* obj = new LDSubfile;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
759 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
760 obj->setPosition (parseVertex (tokens, 2)); // 2 - 4
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
761
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
762 matrix transform;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
763
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
764 for (int i = 0; i < 9; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
765 transform[i] = tokens[i + 5].toDouble(); // 5 - 13
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
766
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
767 obj->setTransform (transform);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
768 obj->setFileInfo (load);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
769 return obj;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
771
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
772 case 2:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
773 { CHECK_TOKEN_COUNT (8)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
774 CHECK_TOKEN_NUMBERS (1, 7)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
775
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
776 // Line
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
777 LDLine* obj = new LDLine;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
778 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
779
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
780 for (int i = 0; i < 2; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
781 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
782
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 423
diff changeset
783 return obj;
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 423
diff changeset
784 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
785
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
786 case 3:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
787 { CHECK_TOKEN_COUNT (11)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
788 CHECK_TOKEN_NUMBERS (1, 10)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
789
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
790 // Triangle
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
791 LDTriangle* obj = new LDTriangle;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
792 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
793
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
794 for (int i = 0; i < 3; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
795 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
796
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
797 return obj;
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
800 case 4:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
801 case 5:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
802 { CHECK_TOKEN_COUNT (14)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
803 CHECK_TOKEN_NUMBERS (1, 13)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
804
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
805 // Quadrilateral / Conditional line
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
806 LDObject* obj;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
807
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
808 if (num == 4)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
809 obj = new LDQuad;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
810 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
811 obj = new LDCndLine;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
812
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
813 obj->setColor (tokens[1].toLong());
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
814
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
815 for (int i = 0; i < 4; ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
816 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
817
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
818 return obj;
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
821 default: // Strange line we couldn't parse
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
822 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
823 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
824 }
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 // =============================================================================
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
827 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
828 LDFile* getFile (str filename)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
829 { // 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
830 LDFile* load = findLoadedFile (filename);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
831
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
832 // If it's not loaded, try open it
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
833 if (!load)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
834 load = openDATFile (filename, true);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
835
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
836 return load;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
837 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
838
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
839 // =============================================================================
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
840 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
841 void reloadAllSubfiles()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
842 { if (!LDFile::current())
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
843 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
844
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
845 g_loadedFiles.clear();
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
846 g_loadedFiles << LDFile::current();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
847
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
848 // 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
849 for (LDObject* obj : LDFile::current()->getObjects())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
850 { if (obj->getType() == LDObject::Subfile)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
851 { 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
852 LDFile* fileInfo = getFile (ref->getFileInfo()->getName());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
853
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
854 if (fileInfo)
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
855 ref->setFileInfo (fileInfo);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
856 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
857 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
858 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
859
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
860 // 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
861 // of loading errors. Circumstances may be different now.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
862 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
863 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
864 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
865
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
866 // Close all files left unused
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
867 LDFile::closeUnused();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
868 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
869
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870 // =============================================================================
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
871 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
872 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
873 { 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
874 m_Objects << obj;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
875
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
876 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
877 m_Vertices << obj;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
878
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
879 obj->setFile (this);
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
880 return getObjectCount() - 1;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
881 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
882
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
883 // =============================================================================
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
884 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
885 void LDFile::addObjects (const QList<LDObject*> objs)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
886 { for (LDObject * obj : objs)
484
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
887 if (obj)
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
888 addObject (obj);
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
889 }
5b5c77c7f3dd made LDFile interfacing a bit clearer
Santeri Piippo <crimsondusk64@gmail.com>
parents: 478
diff changeset
890
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 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
893 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
894 { 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
895 m_Objects.insert (pos, obj);
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
896 obj->setFile (this);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
897 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
898
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
899 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
900 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
901 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
902 { 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
903 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
904 m_Objects.removeAt (idx);
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
905 obj->setFile (null);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
906 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
907
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
908 // =============================================================================
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
909 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
910 bool safeToCloseAll()
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
911 { for (LDFile* f : g_loadedFiles)
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
912 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
913 return false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
914
226
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
915 return true;
250
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
916 }
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
917
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
918 // =============================================================================
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
919 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 497
diff changeset
920 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
921 { assert (idx < m_Objects.size());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
922
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
923 // Mark this change to history
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
924 str oldcode = getObject (idx)->raw();
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
925 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
926 *m_History << new EditHistory (idx, oldcode, newcode);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
927
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
928 obj->setFile (this);
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
929 m_Objects[idx] = obj;
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
930 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
931
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
932 // =============================================================================
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
933 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
934 static QList<LDFile*> getFilesUsed (LDFile* node)
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
935 { QList<LDFile*> filesUsed;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
936
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
937 for (LDObject* obj : node->getObjects())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
938 { if (obj->getType() != LDObject::Subfile)
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
939 continue;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
940
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
941 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
942 filesUsed << ref->getFileInfo();
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
943 filesUsed << getFilesUsed (ref->getFileInfo());
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
944 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
945
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
946 return filesUsed;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
947 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
948
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 // 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
951 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
952 void LDFile::closeUnused()
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
953 { QList<LDFile*> filesUsed = getFilesUsed (LDFile::current());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
954
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
955 // 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
956 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
957 if (!file->isImplicit())
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
958 filesUsed << file;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
959
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
960 // Remove duplicated entries
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
961 removeDuplicates (filesUsed);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
962
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
963 // 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
964 for (LDFile* file : g_loadedFiles)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
965 { bool isused = false;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
966
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 500
diff changeset
967 for (LDFile* usedFile : filesUsed)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
968 { if (file == usedFile)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
969 { isused = true;
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
970 break;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
971 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
972 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
973
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
974 if (!isused)
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
975 delete file;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
976 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
977
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
978 g_loadedFiles.clear();
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
979 g_loadedFiles << filesUsed;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
980 }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
981
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
982 // =============================================================================
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
983 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
984 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
985 { if (m_Objects.size() <= pos)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
986 return null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
987
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
988 return m_Objects[pos];
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
989 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
990
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
991 // =============================================================================
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
992 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
993 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
994 { 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
995 }
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
996
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
997 // =============================================================================
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
998 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
999 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
1000 { return !isImplicit() && getHistory()->getPosition() != getSavePosition();
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
1001 }
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
1002
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
1003 // =============================================================================
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
1004 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1005 str LDFile::getShortName()
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1006 { if (!getName().isEmpty())
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1007 return basename (getName());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1008
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1009 if (!getDefaultName().isEmpty())
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1010 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
1011
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
1012 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
1013 }
be1824f53c48 Added an action for creating a new, blank file, improved multi-file stability
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
1014
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
1015 // =============================================================================
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
1016 // -----------------------------------------------------------------------------
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
1017 QList<LDObject*> LDFile::inlineContents (LDSubfile::InlineFlags flags)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1018 { // 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
1019 // 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
1020 // stud2.dat -> stud-logo2.dat
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1021 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
1022 { 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
1023 return g_logoedStud->inlineContents (flags);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1024
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1025 elif (getName() == "stud2.dat" && g_logoedStud2)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1026 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
1027 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1028
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
1029 QList<LDObject*> objs, objcache;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1030
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
1031 bool deep = flags & LDSubfile::DeepInline,
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1032 doCache = flags & LDSubfile::CacheInline;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1033
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
1034 // 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
1035 if (deep && getCache().size())
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1036 { 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
1037 objs << obj->clone();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1038 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1039 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1040 { 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
1041 doCache = false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1042
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1043 for (LDObject* obj : getObjects())
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1044 { // 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
1045 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
1046 continue;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1047
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
1048 // 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
1049 // 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
1050 // subfiles and this is not one. Yay, recursion!
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1051 if (deep && obj->getType() == LDObject::Subfile)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1052 { LDSubfile* ref = static_cast<LDSubfile*> (obj);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1053
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
1054 // 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
1055 // 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
1056 QList<LDObject*> otherobjs = ref->inlineContents (flags & ~ (LDSubfile::CacheInline));
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1057
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1058 for (LDObject * otherobj : otherobjs)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1059 { // 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
1060 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
1061 objcache << otherobj->clone();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1062
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
1063 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
1064 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1065 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1066 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1067 { 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
1068 objcache << obj->clone();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1069
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 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
1071 }
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 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1073
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
1074 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
1075 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
1076 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1077
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
1078 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
1079 }
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
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1083 LDFile* LDFile::current()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1084 { 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
1085 }
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
1086
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1087 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
1088 // 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
1089 // 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
1090 //
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 // 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
1092 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1093 void LDFile::setCurrent (LDFile* f)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1094 { // 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
1095 // current.
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1096 if (f && f->isImplicit())
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1097 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1098
388
7ff483614aa1 Multiple file support works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 385
diff changeset
1099 m_curfile = f;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1100
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1101 if (g_win && f)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1102 { // 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
1103 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
1104 g_win->buildObjList();
422
00eedf400f72 Fixed crash on opening a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
1105 g_win->updateTitle();
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
1106 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
1107 g_win->R()->resetAllAngles();
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1108 g_win->R()->repaint();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1109
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 418
diff changeset
1110 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
1111 }
391
beef61ce962a Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 390
diff changeset
1112 }
beef61ce962a Finalized multi-file behavior. The future is here! :P
Santeri Piippo <crimsondusk64@gmail.com>
parents: 390
diff changeset
1113
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
1114 // =============================================================================
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
1115 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1116 int LDFile::countExplicitFiles()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1117 { int count = 0;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1118
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1119 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
1120 if (f->isImplicit() == false)
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1121 count++;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1122
417
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1123 return count;
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1124 }
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1125
14bfeed046f3 Added an option for listing implicit files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 416
diff changeset
1126 // =============================================================================
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
1127 // 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
1128 // 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
1129 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1130 void LDFile::closeInitialFile()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1131 { 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
1132 countExplicitFiles() == 2 &&
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1133 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
1134 !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
1135 )
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
1136 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
1137 }
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
1138
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1141 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
1142 { log ("Loading logoed studs...\n");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1143
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
1144 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
1145 delete g_logoedStud2;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
1146
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
1147 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
1148 g_logoedStud2 = openDATFile ("stud2-logo.dat", true);
491
7d1b5ecd76c0 it's LDForge's 1st birthday!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 484
diff changeset
1149 }
522
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1150
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1151 // =============================================================================
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 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
1154 { 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
1155 return;
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1156
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1157 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
1158 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
1159 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
1160 }
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1161
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 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
1165 { 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
1166 return;
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1167
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
1168 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
1169 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
1170 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
1171 }
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1172
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 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
1176 { 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
1177 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
1178
afa691788bdb - migrated selection from ForgeWindow to individual LDFiles. Should've done this long ago.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 519
diff changeset
1179 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
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
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 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 534
diff changeset
1184 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
1185 { 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
1186 }

mercurial