src/file.cpp

Sat, 13 Jul 2013 19:02:48 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 13 Jul 2013 19:02:48 +0300
changeset 377
271d1da66b7e
parent 373
91bea18bd77a
child 378
bc3f40dcfa9e
permissions
-rw-r--r--

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

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
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
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.
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
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.
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
199
10dd5909a50e Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 198
diff changeset
19 #include <QMessageBox>
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
20 #include <QFileDialog>
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QDir>
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
22 #include <QApplication>
202
a027f6fc6141 Un-templated CheckBoxGroup, moved it and RadioButton into widgets.cpp/widgets.h; removed license text tab because I think LICENSE is enough.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 200
diff changeset
23
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
24 #include <stdlib.h>
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "common.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "config.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "file.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "misc.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "bbox.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "gui.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "history.h"
200
5583af82087e Merged new part and LDraw path dialogs into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 199
diff changeset
32 #include "dialogs.h"
198
f246725199dc Split some stuff into separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 192
diff changeset
33 #include "gldraw.h"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
35 cfg( str, io_ldpath, "" );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
36 cfg( str, io_recentfiles, "" );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
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
38 static bool g_loadingMainFile = false;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
39 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
40 static bool g_aborted = false;
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
41
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
43 namespace LDPaths
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
44 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 static str pathError;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
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
47 struct {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 str LDConfigPath;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 str partsPath, primsPath;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 } pathInfo;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
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
52 void initPaths() {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
53 if( !tryConfigure( io_ldpath )) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 LDrawPathDialog dlg (false);
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
56 if( !dlg.exec () )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
57 exit( 0 );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
59 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
60 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
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
63 bool tryConfigure( str path ) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 QDir dir;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
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
66 if( !dir.cd( path )) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 pathError = "Directory does not exist.";
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 return false;
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
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
71 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
72 QStringList contents = dir.entryList( mustHave );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
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
74 if( contents.size() != mustHave.size() ) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
79 pathInfo.partsPath = fmt( "%1" DIRSLASH "parts", path );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
80 pathInfo.LDConfigPath = fmt( "%1" DIRSLASH "LDConfig.ldr", path );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
81 pathInfo.primsPath = fmt( "%1" DIRSLASH "p", path );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 // Accessors
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
87 str getError() { return pathError; }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
88 str ldconfig() { return pathInfo.LDConfigPath; }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
89 str prims() { return pathInfo.primsPath; }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
90 str parts() { return pathInfo.partsPath; }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
94 LDOpenFile::LDOpenFile()
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
95 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
96 setImplicit( true );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
97 setSavePos( -1 );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
98 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
99 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
102 LDOpenFile::~LDOpenFile()
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
103 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 // Clear everything from the model
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
105 for( LDObject* obj : m_objs )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 delete obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 // Clear the cache as well
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
109 for( LDObject* obj : m_cache )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 delete obj;
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 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
114 LDOpenFile* findLoadedFile( str name )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
115 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
116 for( LDOpenFile* file : g_loadedFiles )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
117 if( file->name () == name )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 return file;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 return null;
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 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
124 str dirname( str path ) {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
125 long lastpos = path.lastIndexOf( DIRSLASH );
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
126
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
127 if( lastpos > 0 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
128 return path.left( lastpos );
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
129
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
130 #ifndef _WIN32
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
131 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
132 return DIRSLASH;
b58d35dc5d52 Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents: 235
diff changeset
133 #endif // _WIN32
b58d35dc5d52 Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents: 235
diff changeset
134
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
135 return "";
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
136 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
137
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 // =============================================================================
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
139 str basename (str path) {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
140 long lastpos = path.lastIndexOf( DIRSLASH );
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
141
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
142 if( lastpos != -1 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
143 return path.mid( lastpos + 1 );
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
144
235
bb0a7bcca7eb fix basename
Santeri Piippo <crimsondusk64@gmail.com>
parents: 234
diff changeset
145 return path;
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
146 }
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
147
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
148 // =============================================================================
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
149 File* openLDrawFile (str relpath, bool subdirs) {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
150 print( "%1: Try to open %2\n", __func__, relpath );
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
151 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
152 str fullPath;
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
153
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
154 // 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
155 // 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
156 #ifndef WIN32
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
157 relpath.replace( "\\", "/" );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 #endif // WIN32
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
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
160 if( g_curfile ) {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
161 // First, try find the file in the current model's file path. We want a file
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
162 // in the immediate vicinity of the current model to override stock LDraw stuff.
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 276
diff changeset
163 str partpath = fmt ("%1" DIRSLASH "%2", dirname (g_curfile->name ()), relpath);
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
164
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
165 if (f->open (partpath, File::Read)) {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
166 return f; }}
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
167
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
168 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
169 return f;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
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
171 // 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
172 fullPath = fmt ("%1" DIRSLASH "%2", io_ldpath, relpath);
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
173
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
174 if( f->open( fullPath, File::Read ))
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
175 return f;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
176
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
177 if( subdirs ) {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
178 // Look in sub-directories: parts and p
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
179 for( auto subdir : initlist<const str>({ "parts", "p" })) {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
180 fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3",
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
181 io_ldpath, subdir, relpath);
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
182
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
183 if (f->open (fullPath, File::Read))
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
184 return f; }}
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
186 // Did not find the 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
187 print( "could not find %1\n", relpath );
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
188 delete f;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 return null;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 // =============================================================================
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
195 void FileLoader::start() {
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
196 setDone( false );
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
197 setProgress( 0 );
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
198 setAborted( false );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
200 if( concurrent() ) {
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
201 g_aborted = false;
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
202
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
203 // Show a progress dialog if we're loading the main file here and move
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
204 // the actual work to a separate thread as this can be a rather intensive
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
205 // operation and if we don't respond quickly enough, the program can be
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
206 // deemed inresponsive.. which is a bad thing.
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
207 dlg = new OpenProgressDialog (g_win);
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
208 dlg->setNumLines( lines().size() );
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
209 dlg->setModal( true );
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
210 dlg->show();
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
211
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
212 // Connect the loader in so we can show updates
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
213 connect( this, SIGNAL( workDone() ), dlg, SLOT( accept() ));
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
214 connect( dlg, SIGNAL( rejected() ), this, SLOT( abort() ));
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
215 } 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
216 dlg = null;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
217
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
218 work( 0 );
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
219 }
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
220
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
221 void FileLoader::work( ulong i ) {
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
222 if( aborted() ) {
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
223 // We were flagged for abortion, so abort.
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
224 for( LDObject* obj : m_objs )
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 delete obj;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
226
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
227 m_objs.clear();
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
228 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
229 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
230 }
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
231
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
232 ulong max = i + 300;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
233 for( ; i < max && i < lines().size(); ++i ) {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
234 str line = lines()[i];
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
235
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 // Trim the trailing newline
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 276
diff changeset
237 qchar c;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
238 while(( c = line[line.length () - 1] ) == '\n' || c == '\r' )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
239 line.chop( 1 );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
241 LDObject* obj = parseLine( line );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 // Check for parse errors and warn about tthem
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
244 if( obj->getType () == LDObject::Error ) {
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
245 log( "Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDErrorObject*> (obj)->reason );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246
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
247 if( m_warningsPointer ) {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
248 ( *m_warningsPointer )++; }}
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
250 m_objs << obj;
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
251 setProgress( i );
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
252
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
253 if( concurrent() )
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
254 dlg->updateProgress( i );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256
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
257 if( i >= lines().size() - 1 ) {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
258 emit workDone();
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
259 setDone( true ); }
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
260
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
261 if( !done() ) {
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
262 if( concurrent() )
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
263 QMetaObject::invokeMethod( this, "work", Qt::QueuedConnection, Q_ARG( ulong, i + 1 ));
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 else
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
265 work( i + 1 );
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
266 }
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
267 }
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
268
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
269 void FileLoader::abort() {
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
270 setAborted( true );
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
271
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
272 if( concurrent() )
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
273 g_aborted = true;
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
274 }
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
275
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
276 // =============================================================================
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
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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
278 // =============================================================================
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
279 vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* 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
280 vector<str> lines;
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
281 vector<LDObject*> objs;
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
282
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
283 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
284 *numWarnings = 0;
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
285
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
286 // Calculate the amount of lines
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
287 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
288 lines << line;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
289 f->rewind();
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
290
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
291 FileLoader* loader = new FileLoader;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
292 loader->setWarningsPointer( numWarnings );
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
293 loader->setLines( lines );
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
294 loader->setConcurrent( g_loadingMainFile );
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
295 loader->start();
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
296
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
297 while( loader->done() == false )
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
298 qApp->processEvents();
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
299
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
300 // If we wanted the success value, supply that now
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
301 if( ok )
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
302 *ok = !loader->aborted();
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
303
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
304 objs = loader->objs();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 return objs;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
311 LDOpenFile* openDATFile( str path, bool search )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
312 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 // Convert the file name to lowercase since some parts contain uppercase
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 // 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
315 // 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
316 File* f;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
317 if( search )
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
318 f = openLDrawFile (path.toLower (), true);
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
319 else {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
320 f = new File( path, File::Read );
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
321
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
322 if( !*f ) {
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
323 delete 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
324 return null; }}
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
326 if( !f )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 return null;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328
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
329 LDOpenFile* oldLoad = g_curfile;
232
4e44c92e21dd Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents: 227
diff changeset
330 LDOpenFile* load = new LDOpenFile;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
331 load->setName( path );
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
332
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
333 if( g_loadingMainFile )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
334 {
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
335 g_curfile = load;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
336 g_win->R()->setFile( load );
253
0737c217a54d Added ability to have multiple GLRenderers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 252
diff changeset
337 }
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
338
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 ulong numWarnings;
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
340 bool ok;
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
341 vector<LDObject*> objs = loadFileContents( f, &numWarnings, &ok );
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
342
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
343 if( !ok )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
344 {
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
345 if( g_loadingMainFile )
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
346 {
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
347 g_curfile = oldLoad;
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
348 g_win->R()->setFile( oldLoad );
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
349 }
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
350
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
351 return null;
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
352 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
354 for( LDObject* obj : objs )
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
355 load->addObject( obj );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
357 delete f;
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
358 g_loadedFiles << load;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
360 /*
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 logf ("File %s parsed successfully (%lu warning%s).\n",
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 276
diff changeset
362 qchars (path), numWarnings, plural (numWarnings));
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
363 */
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 return load;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
371 bool LDOpenFile::safeToClose()
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
372 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
373 typedef QMessageBox msgbox;
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
374 setlocale( LC_ALL, "C" );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 // If we have unsaved changes, warn and give the option of saving.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
377 if( !implicit() && history().pos() != savePos() )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
378 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
379 str message = fmt( "There are unsaved changes to %1. Should it be saved?",
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
380 (name().length() > 0) ? name() : "<anonymous>");
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
381 switch( msgbox::question( g_win, "Unsaved Changes", message,
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
382 ( msgbox::Yes | msgbox::No | msgbox::Cancel ), msgbox::Cancel ))
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
384 case msgbox::Yes:
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
385 // If we don't have a file path yet, we have to ask the user for one.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
386 if( name().length() == 0 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
387 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
388 str newpath = QFileDialog::getSaveFileName( g_win, "Save As",
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
389 g_curfile->name(), "LDraw files (*.dat *.ldr)" );
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
390
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
391 if( newpath.length() == 0 )
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
392 return false;
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
393
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
394 setName( newpath );
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
395 }
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
396
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
397 if( !save () ) {
321
48e429bfd58c Apply tr() for possible future translations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 320
diff changeset
398 message = fmt( QObject::tr( "Failed to save %1: %2\nDo you still want to close?" ),
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
399 name(), strerror( errno ));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
401 if( QMessageBox::critical( g_win, "Save Failure", message,
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
402 ( QMessageBox::Yes | QMessageBox::No ), QMessageBox::No ) == QMessageBox::No)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 {
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 break;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
410 case msgbox::Cancel:
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 default:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 break;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
424 void closeAll()
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
425 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
426 if( !g_loadedFiles.size() )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429 // Remove all loaded files and the objects they contain
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
430 for( LDOpenFile* file : g_loadedFiles )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 delete file;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 // Clear the array
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 g_loadedFiles.clear();
253
0737c217a54d Added ability to have multiple GLRenderers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 252
diff changeset
435 g_curfile = null;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
437 g_win->R()->setFile (null);
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
438 g_win->fullRefresh();
183
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 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
444 void newFile ()
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
445 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
446 closeAll();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
448 // Create a new anonymous file and set it to our current
232
4e44c92e21dd Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents: 227
diff changeset
449 LDOpenFile* f = new LDOpenFile;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
450 f->setName( "" );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
451 f->setImplicit( false );
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
452 g_loadedFiles << f;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 g_curfile = f;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
455 g_BBox.reset();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
456 g_win->R()->setFile( f );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
457 g_win->fullRefresh();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
458 g_win->updateTitle();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
459 f->history().updateActions();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
465 void addRecentFile( str path )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
466 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
467 QStringList rfiles = io_recentfiles.value.split( '@' );
273
0a9141118630 Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 272
diff changeset
468
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
469 int idx = rfiles.indexOf( path );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 // If this file already is in the list, pop it out.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
472 if( idx != -1 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
473 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
474 if( rfiles.size () == 1 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
475 return; // only recent file - abort and do nothing
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 // Pop it out.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
478 rfiles.removeAt( idx );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 // If there's too many recent files, drop one out.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
482 while( rfiles.size() > ( g_MaxRecentFiles - 1 ))
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
483 rfiles.removeAt( 0 );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
484
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 // Add the file
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
486 rfiles.push_back( path );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487
273
0a9141118630 Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 272
diff changeset
488 // Rebuild the config string
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
489 io_recentfiles = rfiles.join( "@" );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
491 config::save();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
492 g_win->updateRecentFilesMenu();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
496 // -----------------------------------------------------------------------------
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
497 // Open an LDraw file and set it as the main model
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
499 void openMainFile( str path )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
500 {
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
501 g_loadingMainFile = true;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
502 closeAll();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
504 LDOpenFile* file = openDATFile( path, false );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
505
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
506 if (!file)
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
507 {
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
508 // Loading failed, thus drop down to a new file since we
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
509 // closed everything prior.
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
510 newFile ();
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
511
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
512 if( !g_aborted )
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
513 {
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
514 // Tell the user loading failed.
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
515 setlocale( LC_ALL, "C" );
321
48e429bfd58c Apply tr() for possible future translations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 320
diff changeset
516 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
517 }
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
518
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
519 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
522
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
523 file->setImplicit( false );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 g_curfile = file;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 // Recalculate the bounding box
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527 g_BBox.calculate();
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529 // Rebuild the object tree view now.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
530 g_win->fullRefresh();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
531 g_win->updateTitle();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
532 g_win->R()->setFile( file );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
533 g_win->R()->resetAngles();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
534
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535 // Add it to the recent files list.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
536 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
537 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
543 bool LDOpenFile::save( str savepath )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
544 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
545 if( !savepath.length() )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
546 savepath = name();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
547
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
548 File f( savepath, File::Write );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
550 if( !f )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
552
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
553 // 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
554 // 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
555 // called "s" or "48", prepend that into the name.
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
556 LDCommentObject* fpathComment = null;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
557 LDObject* first = object( 1 );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
558 if( !implicit() && first != null && first->getType() == LDObject::Comment )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
559 {
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
560 fpathComment = static_cast<LDCommentObject*>( first );
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
561
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
562 if( fpathComment->text.left( 6 ) == "Name: " ) {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
563 str newname;
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
564 str dir = basename( dirname( savepath ));
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
565
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
566 if( dir == "s" || dir == "48" )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
567 newname = dir + "\\";
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
568
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
569 newname += basename( savepath );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
570 fpathComment->text = fmt( "Name: %1", newname );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
571 g_win->buildObjList();
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
572 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
573 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
574
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
575 // 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
576 // have DOS line endings, so we terminate the lines with \r\n.
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
577 for( LDObject* obj : objs() )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
578 f.write( obj->raw () + "\r\n" );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
580 // File is saved, now clean up.
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
581 f.close();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 // We have successfully saved, update the save position now.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
584 setSavePos( history().pos() );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
585 setName( savepath );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
587 g_win->updateTitle();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
591 // =============================================================================
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
592 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
593 // =============================================================================
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
594 #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
595 if (tokens.size() != N) \
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
596 return new LDErrorObject (line, "Bad amount of tokens");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
598 #define CHECK_TOKEN_NUMBERS( MIN, MAX ) \
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599 for (ushort i = MIN; i <= MAX; ++i) \
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
600 if (!isNumber (tokens[i])) \
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
601 return new LDErrorObject (line, fmt ("Token #%1 was `%2`, expected a number", \
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 276
diff changeset
602 (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
603
308
4e2425bd4dc7 Added an atof overload to convert from string to float, hopefully without any precision error
Santeri Piippo <crimsondusk64@gmail.com>
parents: 298
diff changeset
604 static vertex parseVertex( QStringList& s, const ushort n )
4e2425bd4dc7 Added an atof overload to convert from string to float, hopefully without any precision error
Santeri Piippo <crimsondusk64@gmail.com>
parents: 298
diff changeset
605 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
606 vertex v;
308
4e2425bd4dc7 Added an atof overload to convert from string to float, hopefully without any precision error
Santeri Piippo <crimsondusk64@gmail.com>
parents: 298
diff changeset
607 for( const Axis ax : g_Axes )
4e2425bd4dc7 Added an atof overload to convert from string to float, hopefully without any precision error
Santeri Piippo <crimsondusk64@gmail.com>
parents: 298
diff changeset
608 v[ax] = atof( s[n + ax] );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
610 return v;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
611 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
614 // -----------------------------------------------------------------------------
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
615 // 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
616 // 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
617 // the object will be LDError if it could not be parsed properly.
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
619 LDObject* parseLine( str line )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
620 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
621 QStringList tokens = line.split( " ", str::SkipEmptyParts );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
623 if( tokens.size() <= 0 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
624 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625 // Line was empty, or only consisted of whitespace
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
626 return new LDEmptyObject;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628
373
91bea18bd77a Fixed compilation under windows/qt5
Santeri Piippo <crimsondusk64@gmail.com>
parents: 371
diff changeset
629 if( tokens[0].length() != 1 || tokens[0][0].isDigit() == false )
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
630 return new LDErrorObject( line, "Illogical line code" );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
631
373
91bea18bd77a Fixed compilation under windows/qt5
Santeri Piippo <crimsondusk64@gmail.com>
parents: 371
diff changeset
632 int num = tokens[0][0].digitValue();
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 switch (num)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
634 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 case 0:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636 {
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
637 // Comment
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
638 str comm = line.mid( line.indexOf( "0" ) + 1 );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
639
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
640 // Remove any leading whitespace
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
641 while( comm[0] == ' ' )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
642 comm.remove( 0, 1 );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 // Handle BFC statements
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 if (tokens.size() > 2 && tokens[1] == "BFC") {
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
646 for (short i = 0; i < LDBFCObject::NumStatements; ++i)
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
647 if (comm == fmt ("BFC %1", LDBFCObject::statements [i]))
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
648 return new LDBFCObject ((LDBFCObject::Type) i);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 // MLCAD is notorious for stuffing these statements in parts it
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 // creates. The above block only handles valid statements, so we
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652 // need to handle MLCAD-style invertnext separately.
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653 if (comm == "BFC CERTIFY INVERTNEXT")
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
654 return new LDBFCObject (LDBFCObject::InvertNext);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
655 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
656
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
657 if (tokens.size() > 2 && tokens[1] == "!LDFORGE")
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
658 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
659 // Handle LDForge-specific types, they're embedded into comments too
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
660 if (tokens[2] == "VERTEX") {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
661 // Vertex (0 !LDFORGE VERTEX)
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
662 CHECK_TOKEN_COUNT (7)
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663 CHECK_TOKEN_NUMBERS (3, 6)
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
664
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
665 LDVertexObject* obj = new LDVertexObject;
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 276
diff changeset
666 obj->setColor (tokens[3].toLong ());
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
667
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
668 for (const Axis ax : g_Axes)
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 276
diff changeset
669 obj->pos[ax] = tokens[4 + ax].toDouble (); // 4 - 6
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
670
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
671 return obj;
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
672 } elif (tokens[2] == "OVERLAY") {
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
673 CHECK_TOKEN_COUNT (9);
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
674 CHECK_TOKEN_NUMBERS (5, 8)
316
b4fefda58f43 Made overlay data be contained in the part files, still wip
Santeri Piippo <crimsondusk64@gmail.com>
parents: 312
diff changeset
675
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
676 LDOverlayObject* obj = new LDOverlayObject;
317
e41ab239ed28 Added ability to load the overlay meta
Santeri Piippo <crimsondusk64@gmail.com>
parents: 316
diff changeset
677 obj->setFilename( tokens[3] );
e41ab239ed28 Added ability to load the overlay meta
Santeri Piippo <crimsondusk64@gmail.com>
parents: 316
diff changeset
678 obj->setCamera( tokens[4].toLong() );
e41ab239ed28 Added ability to load the overlay meta
Santeri Piippo <crimsondusk64@gmail.com>
parents: 316
diff changeset
679 obj->setX( tokens[5].toLong() );
e41ab239ed28 Added ability to load the overlay meta
Santeri Piippo <crimsondusk64@gmail.com>
parents: 316
diff changeset
680 obj->setY( tokens[6].toLong() );
e41ab239ed28 Added ability to load the overlay meta
Santeri Piippo <crimsondusk64@gmail.com>
parents: 316
diff changeset
681 obj->setWidth( tokens[7].toLong() );
e41ab239ed28 Added ability to load the overlay meta
Santeri Piippo <crimsondusk64@gmail.com>
parents: 316
diff changeset
682 obj->setHeight( tokens[8].toLong() );
316
b4fefda58f43 Made overlay data be contained in the part files, still wip
Santeri Piippo <crimsondusk64@gmail.com>
parents: 312
diff changeset
683 return obj;
b4fefda58f43 Made overlay data be contained in the part files, still wip
Santeri Piippo <crimsondusk64@gmail.com>
parents: 312
diff changeset
684 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
685 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
687 // Just a regular comment:
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
688 LDCommentObject* obj = new LDCommentObject;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
689 obj->text = comm;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
690 return obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
691 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
692
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
693 case 1:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
694 {
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
695 // Subfile
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
696 CHECK_TOKEN_COUNT( 15 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
697 CHECK_TOKEN_NUMBERS( 1, 13 )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
698
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
699 // Try open the file. Disable g_loadingMainFile temporarily since we're
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
700 // not loading the main file now, but the subfile in question.
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
701 bool tmp = g_loadingMainFile;
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
702 g_loadingMainFile = false;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
703 LDOpenFile* load = getFile( tokens[14] );
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
704 g_loadingMainFile = tmp;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
705
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
706 // If we cannot open the file, mark it an error
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
707 if( !load )
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
708 return new LDErrorObject( line, "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
709
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
710 LDSubfileObject* obj = new LDSubfileObject;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
711 obj->setColor( tokens[1].toLong() );
316
b4fefda58f43 Made overlay data be contained in the part files, still wip
Santeri Piippo <crimsondusk64@gmail.com>
parents: 312
diff changeset
712 obj->setPosition( parseVertex( tokens, 2 )); // 2 - 4
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713
268
778eed342ee4 Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents: 267
diff changeset
714 matrix transform;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
715 for( short i = 0; i < 9; ++i )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
716 transform[i] = tokens[i + 5].toDouble(); // 5 - 13
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
717
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
718 obj->setTransform( transform );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
719 obj->setFileInfo( load );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
720 return obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
722
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
723 case 2:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
724 {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
725 CHECK_TOKEN_COUNT( 8 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
726 CHECK_TOKEN_NUMBERS( 1, 7 )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
727
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728 // Line
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
729 LDLineObject* obj = new LDLineObject;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
730 obj->setColor( tokens[1].toLong() );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
731 for( short i = 0; i < 2; ++i )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
732 obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 7
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 return obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
734 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
736 case 3:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
737 {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
738 CHECK_TOKEN_COUNT( 11 )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
739 CHECK_TOKEN_NUMBERS( 1, 10 )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
740
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
741 // Triangle
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
742 LDTriangleObject* obj = new LDTriangleObject;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
743 obj->setColor( tokens[1].toLong() );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
744
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
745 for( short i = 0; i < 3; ++i )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
746 obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 10
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
747
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
748 return obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
749 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
750
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
751 case 4:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
752 case 5:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
753 {
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
754 CHECK_TOKEN_COUNT (14)
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
755 CHECK_TOKEN_NUMBERS (1, 13)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
757 // Quadrilateral / Conditional line
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
758 LDObject* obj = (num == 4) ? ((LDObject*) new LDQuadObject ) : ((LDObject*) new LDCondLineObject);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
759 obj->setColor( tokens[1].toLong() );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
760
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
761 for (short i = 0; i < 4; ++i)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
762 obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 13
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
763
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
764 return obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
765 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
766
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
767 default: // Strange line we couldn't parse
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
768 return new LDErrorObject (line, "Unknown line code number");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
769 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
771
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
772 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
773 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
774 // =============================================================================
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
775 LDOpenFile* getFile( str filename )
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
776 {
254
434c9844e45d Further work on image generation experiment
Santeri Piippo <crimsondusk64@gmail.com>
parents: 253
diff changeset
777 // Try find the file in the list of loaded files
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
778 LDOpenFile* load = findLoadedFile( filename );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
779
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
780 // If it's not loaded, try open it
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
781 if( !load )
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
782 load = openDATFile( filename, true );
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
783
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
784 return load;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
785 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
786
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
787 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
788 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
789 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 void reloadAllSubfiles () {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
791 if( !g_curfile )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
792 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
793
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
794 g_loadedFiles.clear();
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
795 g_loadedFiles << g_curfile;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 // Go through all objects in the current file and reload the subfiles
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
798 for( LDObject* obj : g_curfile->objs() )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
799 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
800 if( obj->getType() == LDObject::Subfile )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
801 {
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
802 LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj );
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
803 LDOpenFile* fileInfo = getFile( ref->fileInfo()->name() );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
804
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
805 if (fileInfo)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
806 ref->setFileInfo( fileInfo );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
807 else
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
808 ref->replace( new LDErrorObject( ref->raw(), "Could not open referred file" ));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
809 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
810
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
811 // 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
812 // of loading errors. Circumstances may be different now.
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
813 if( obj->getType() == LDObject::Error )
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
814 obj->replace( parseLine( static_cast<LDErrorObject*>( obj )->contents ));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
815 }
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
816
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
817 // Close all files left unused
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
818 LDOpenFile::closeUnused();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
819 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
820
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
822 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
823 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
824 ulong LDOpenFile::addObject (LDObject* obj)
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
825 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
826 PROP_NAME( history ).add( new AddHistory( PROP_NAME( objs ).size(), obj ));
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
827 PROP_NAME( objs ) << obj;
271
d5ec224c1879 Laid down the foundations of the new history system
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
828
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
829 if( obj->getType() == LDObject::Vertex )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
830 PROP_NAME( vertices ) << obj;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
831
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
832 if( this == g_curfile )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
833 g_BBox.calcObject( obj );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
834
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
835 return numObjs() - 1;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
836 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
837
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
838 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
839 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
840 // =============================================================================
232
4e44c92e21dd Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents: 227
diff changeset
841 void LDOpenFile::insertObj (const ulong pos, LDObject* obj) {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
842 m_history.add( new AddHistory( pos, obj ));
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
843 m_objs.insert( pos, obj );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
844
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
845 if( this == g_curfile )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
846 g_BBox.calcObject( obj );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
847 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
848
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
849 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
850 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
851 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
852 void LDOpenFile::forgetObject( LDObject* obj ) {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
853 ulong idx = obj->getIndex( this );
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
854 m_history.add( new DelHistory( idx, obj ));
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
855 m_objs.erase( idx );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
856
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
857 // Update the bounding box
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
858 if( this == g_curfile )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
859 g_BBox.calculate ();
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
860 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
861
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
862 // =============================================================================
226
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
863 bool safeToCloseAll () {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
864 for( LDOpenFile* f : g_loadedFiles )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
865 if( !f->safeToClose() )
226
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
866 return false;
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
867
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
868 return true;
250
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
869 }
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
870
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
871 // =============================================================================
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
872 void LDOpenFile::setObject (ulong idx, LDObject* obj) {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
873 assert( idx < numObjs() );
276
a21e49914264 Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents: 274
diff changeset
874
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
875 // Mark this change to history
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
876 str oldcode = object( idx )->raw ();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
877 str newcode = obj->raw();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
878 m_history << new EditHistory( idx, oldcode, newcode );
276
a21e49914264 Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents: 274
diff changeset
879
250
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
880 m_objs[idx] = obj;
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
881 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
882
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
883 static vector<LDOpenFile*> getFilesUsed (LDOpenFile* node) {
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
884 vector<LDOpenFile*> filesUsed;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
885
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
886 for (LDObject* obj : *node)
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
887 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
888 if( obj->getType() != LDObject::Subfile )
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
889 continue;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
890
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
891 LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj );
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
892 filesUsed << ref->fileInfo();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
893 filesUsed << getFilesUsed( ref->fileInfo() );
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
894 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
895
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
896 return filesUsed;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
897 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
898
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
899 // =============================================================================
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
900 // Find out which files are unused and close them.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
901 void LDOpenFile::closeUnused ()
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
902 {
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
903 vector<LDOpenFile*> filesUsed = getFilesUsed (g_curfile);
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
904
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
905 // Anything that's explicitly opened must not be closed
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
906 for( LDOpenFile* file : g_loadedFiles )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
907 if( !file->implicit() )
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
908 filesUsed << file;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
909
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
910 // Remove duplicated entries
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
911 filesUsed.makeUnique();
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
912
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
913 // Close all open files that aren't in filesUsed
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
914 for( LDOpenFile* file : g_loadedFiles )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
915 {
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
916 bool isused = false;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
917
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
918 for( LDOpenFile* usedFile : filesUsed )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
919 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
920 if( file == usedFile )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
921 {
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
922 isused = true;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
923 break;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
924 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
925 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
926
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
927 if( !isused )
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
928 delete file;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
929 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
930
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
931 g_loadedFiles.clear();
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
932 g_loadedFiles << filesUsed;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
933 }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
934
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
935 LDObject* LDOpenFile::object( ulong pos ) const
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
936 {
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
937 if( m_objs.size() <= pos )
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
938 return null;
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
939
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
940 return m_objs[pos];
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
941 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
942
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
943 LDOpenFile& LDOpenFile::operator<<( vector<LDObject*> objs )
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
944 {
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
945 for( LDObject* obj : objs )
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
946 m_objs << obj;
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
947
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
948 return *this;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
949 }

mercurial