src/ldDocument.cc

Sun, 13 Jul 2014 16:48:29 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 13 Jul 2014 16:48:29 +0300
changeset 835
268413885cb1
parent 834
3e697ba996e8
child 836
a522e1cd92af
permissions
-rw-r--r--

- reimplemented vertex tracking using a method similar to what the GL compiler uses

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QMessageBox>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QFileDialog>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QDir>
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
22 #include <QTime>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QApplication>
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
24
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "main.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "configuration.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "miscallenous.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "mainWindow.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "editHistory.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "dialogs.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "glRenderer.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
33 #include "glCompiler.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
35 CFGENTRY (String, ldrawPath, "")
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
36 CFGENTRY (List, recentFiles, {})
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
37 EXTERN_CFGENTRY (String, downloadFilePath)
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
38 EXTERN_CFGENTRY (Bool, useLogoStuds)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 static bool g_loadingMainFile = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 static const int g_maxRecentFiles = 10;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 static bool g_aborted = false;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
43 static LDDocumentPtr g_logoedStud;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
44 static LDDocumentPtr g_logoedStud2;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
45 static QList<LDDocumentWeakPtr> g_allDocuments;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
46 static QList<LDDocumentPtr> g_explicitDocuments;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
47 static LDDocumentPtr g_currentDocument;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 const QStringList g_specialSubdirectories ({ "s", "48", "8" });
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 namespace LDPaths
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
55 static QString pathError;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 struct
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
59 QString LDConfigPath;
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
60 QString partsPath, primsPath;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 } pathInfo;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 void initPaths()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 {
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
65 if (not tryConfigure (cfg::ldrawPath))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 LDrawPathDialog dlg (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
69 if (not dlg.exec())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 exit (0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
72 cfg::ldrawPath = dlg.filename();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
76 bool tryConfigure (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 QDir dir;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
80 if (not dir.cd (path))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 pathError = "Directory does not exist.";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 QStringList contents = dir.entryList (mustHave);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 if (contents.size() != mustHave.size())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 pathInfo.partsPath = format ("%1" DIRSLASH "parts", path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 pathInfo.LDConfigPath = format ("%1" DIRSLASH "LDConfig.ldr", path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 pathInfo.primsPath = format ("%1" DIRSLASH "p", path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 // Accessors
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
103 QString getError()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 return pathError;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
108 QString ldconfig()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 return pathInfo.LDConfigPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
113 QString prims()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 return pathInfo.primsPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
118 QString parts()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 return pathInfo.partsPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
126 LDDocument::LDDocument (LDDocumentPtr* selfptr) :
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
127 m_isImplicit (true),
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
128 m_flags (0),
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
129 _verticesOutdated (true),
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
130 _needVertexMerge (true),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 m_gldata (new LDGLData)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
133 *selfptr = LDDocumentPtr (this);
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
134 setSelf (*selfptr);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 setSavePosition (-1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 setTabIndex (-1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 setHistory (new History);
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
138 history()->setDocument (*selfptr);
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
139 m_needsReCache = true;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
140 g_allDocuments << *selfptr;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
141 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
142
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
143 // =============================================================================
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
144 //
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
145 LDDocumentPtr LDDocument::createNew()
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
146 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
147 LDDocumentPtr ptr;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
148 new LDDocument (&ptr);
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
149 return ptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 LDDocument::~LDDocument()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
156 print ("Deleted %1", getDisplayName());
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
157 g_allDocuments.removeOne (self());
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
158 m_flags |= DOCF_IsBeingDestroyed;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
159 delete m_history;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 delete m_gldata;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
165 extern QMap<long, LDObjectWeakPtr> g_allObjects;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
166 void LDDocument::setImplicit (bool const& a)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
168 if (m_isImplicit != a)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
169 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
170 m_isImplicit = a;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
171
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
172 if (a == false)
788
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
173 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
174 g_explicitDocuments << self().toStrongRef();
788
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
175 print ("Opened %1", name());
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
176
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
177 // Implicit files are not compiled by the GL renderer. Now that this
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
178 // part is no longer implicit, it needs to be compiled.
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
179 if (g_win != null)
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
180 g_win->R()->compiler()->compileDocument (self());
c9d1dad83ad0 - added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
181 }
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
182 else
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
183 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
184 g_explicitDocuments.removeOne (self().toStrongRef());
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
185 print ("Closed %1", name());
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
186 int count = 0;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
187 for (LDObjectPtr obj : g_allObjects)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
188 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
189 LDSubfilePtr ref = obj.dynamicCast<LDSubfile>();
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
190 if (ref && ref->fileInfo() == self())
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
191 count++;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
192 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
193 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
194
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
195 if (g_win != null)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
196 g_win->updateDocumentList();
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
197
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
198 // If the current document just became implicit (e.g. it was 'closed'),
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
199 // we need to get a new current document.
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
200 if (current() == self() && isImplicit())
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
201 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
202 if (explicitDocuments().isEmpty())
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
203 newFile();
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
204 else
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
205 setCurrent (explicitDocuments().first());
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
206 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
207 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
208 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
209
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
210 // =============================================================================
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
211 //
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
212 QList<LDDocumentPtr> const& LDDocument::explicitDocuments()
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
213 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
214 return g_explicitDocuments;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
215 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
216
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
217 // =============================================================================
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
218 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
219 LDDocumentPtr findDocument (QString name)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
220 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
221 for (LDDocumentPtr file : g_allDocuments)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
222 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
223 if (file->name() == name)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 return file;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
225 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
227 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
232 QString dirname (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 long lastpos = path.lastIndexOf (DIRSLASH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 if (lastpos > 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 return path.left (lastpos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 #ifndef _WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 if (path[0] == DIRSLASH_CHAR)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 return DIRSLASH;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 #endif // _WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
249 QString basename (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 long lastpos = path.lastIndexOf (DIRSLASH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 if (lastpos != -1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 return path.mid (lastpos + 1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 return path;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
261 static QString findLDrawFilePath (QString relpath, bool subdirs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
263 QString fullPath;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 // LDraw models use Windows-style path separators. If we're not on Windows,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 // replace the path separator now before opening any files. Qt expects
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 // forward-slashes as directory separators.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 #ifndef WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 relpath.replace ("\\", "/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 #endif // WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 // Try find it relative to other currently open documents. We want a file
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 // in the immediate vicinity of a current model to override stock LDraw stuff.
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
274 QString reltop = basename (dirname (relpath));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
276 for (LDDocumentPtr doc : g_allDocuments)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 if (doc->fullPath().isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
281 QString partpath = format ("%1/%2", dirname (doc->fullPath()), relpath);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 QFile f (partpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 if (f.exists())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 // ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
287 QString proptop = basename (dirname (partpath));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 bool bogus = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
291 for (QString s : g_specialSubdirectories)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 if ((proptop == s && reltop != s) || (reltop == s && proptop != s))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 bogus = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
300 if (not bogus)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 return partpath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 if (QFile::exists (relpath))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 return relpath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 // Try with just the LDraw path first
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
309 fullPath = format ("%1" DIRSLASH "%2", cfg::ldrawPath, relpath);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
311 if (QFile::exists (fullPath))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 return fullPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 if (subdirs)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 // Look in sub-directories: parts and p. Also look in net_downloadpath, since that's
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 // where we download parts from the PT to.
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
318 for (const QString& topdir : QList<QString> ({ cfg::ldrawPath, cfg::downloadFilePath }))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
320 for (const QString& subdir : QList<QString> ({ "parts", "p" }))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 fullPath = format ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 if (QFile::exists (fullPath))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 return fullPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 // Did not find the file.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
334 // =============================================================================
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
335 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
336 QFile* openLDrawFile (QString relpath, bool subdirs, QString* pathpointer)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 print ("Opening %1...\n", relpath);
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
339 QString path = findLDrawFilePath (relpath, subdirs);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 if (pathpointer != null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 *pathpointer = path;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 if (path.isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 return null;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 QFile* fp = new QFile (path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 if (fp->open (QIODevice::ReadOnly))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 return fp;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 fp->deleteLater();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 return null;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 void LDFileLoader::start()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 setDone (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 setProgress (0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 setAborted (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 g_aborted = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 // Show a progress dialog if we're loading the main ldDocument.here so we can
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 // show progress updates and keep the WM posted that we're still here.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 // Of course we cannot exec() the dialog because then the dialog would
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 // block.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 dlg = new OpenProgressDialog (g_win);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 dlg->setNumLines (lines().size());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 dlg->setModal (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 dlg->show();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 // Connect the loader in so we can show updates
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 connect (this, SIGNAL (workDone()), dlg, SLOT (accept()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 connect (dlg, SIGNAL (rejected()), this, SLOT (abort()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 dlg = null;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 // Begin working
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 work (0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 void LDFileLoader::work (int i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 // User wishes to abort, so stop here now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 if (isAborted())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
395 for (LDObjectPtr obj : m_objects)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 obj->destroy();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 m_objects.clear();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 setDone (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 // Parse up to 300 lines per iteration
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 int max = i + 300;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 for (; i < max && i < (int) lines().size(); ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
408 QString line = lines()[i];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410 // Trim the trailing newline
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 QChar c;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 while (line.endsWith ("\n") || line.endsWith ("\r"))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 line.chop (1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
416 LDObjectPtr obj = parseLine (line);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 // Check for parse errors and warn about tthem
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 785
diff changeset
419 if (obj->type() == OBJ_Error)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
421 print ("Couldn't parse line #%1: %2", progress() + 1, obj.staticCast<LDError>()->reason());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 if (warnings() != null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 (*warnings())++;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 m_objects << obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 setProgress (i);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 // If we have a dialog pointer, update the progress now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 dlg->updateProgress (i);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 // If we're done now, tell the environment we're done and stop.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 if (i >= ((int) lines().size()) - 1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 emit workDone();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 setDone (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 // Otherwise, continue, by recursing back.
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
444 if (not isDone())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 // If we have a dialog to show progress output to, we cannot just call
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 // work() again immediately as the dialog needs some processor cycles as
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 // well. Thus, take a detour through the event loop by using the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 // meta-object system.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 // This terminates the loop here and control goes back to the function
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 // which called the file loader. It will keep processing the event loop
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 // until we're ready (see loadFileContents), thus the event loop will
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 // eventually catch the invokation we throw here and send us back. Though
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 // it's not technically recursion anymore, more like a for loop. :P
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (int, i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 work (i);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 void LDFileLoader::abort()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 setAborted (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 g_aborted = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 LDObjectList loadFileContents (QFile* fp, int* numWarnings, bool* ok)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 QStringList lines;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 LDObjectList objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 if (numWarnings)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 *numWarnings = 0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483 // Read in the lines
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
484 while (not fp->atEnd())
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
485 lines << QString::fromUtf8 (fp->readLine());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487 LDFileLoader* loader = new LDFileLoader;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
488 loader->setWarnings (numWarnings);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 loader->setLines (lines);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 loader->setOnForeground (g_loadingMainFile);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 loader->start();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493 // After start() returns, if the loader isn't done yet, it's delaying
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494 // its next iteration through the event loop. We need to catch this here
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495 // by telling the event loop to tick, which will tick the file loader again.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496 // We keep doing this until the file loader is ready.
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
497 while (not loader->isDone())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498 qApp->processEvents();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 // If we wanted the success value, supply that now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501 if (ok)
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
502 *ok = not loader->isAborted();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
504 objs = loader->objects();
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
505 delete loader;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506 return objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
508
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
509 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
510 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
511 LDDocumentPtr openDocument (QString path, bool search, bool implicit, LDDocumentPtr fileToOverride)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
512 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 // Convert the file name to lowercase since some parts contain uppercase
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 // file names. I'll assume here that the library will always use lowercase
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
515 // file names for the actual parts..
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 QFile* fp;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
517 QString fullpath;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519 if (search)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520 fp = openLDrawFile (path.toLower(), true, &fullpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
522 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523 fp = new QFile (path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 fullpath = path;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
526 if (not fp->open (QIODevice::ReadOnly))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528 delete fp;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
529 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
530 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
533 if (not fp)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
534 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
536 LDDocumentPtr load = (fileToOverride != null ? fileToOverride : LDDocument::createNew());
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
537 load->setImplicit (implicit);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 load->setFullPath (fullpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 load->setName (LDDocument::shortenName (load->fullPath()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
541 // Loading the file shouldn't count as actual edits to the document.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 load->history()->setIgnoring (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544 int numWarnings;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 bool ok;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546 LDObjectList objs = loadFileContents (fp, &numWarnings, &ok);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
547 fp->close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548 fp->deleteLater();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
550 if (not ok)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
552 load->dismiss();
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
553 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
555
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556 load->addObjects (objs);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
557
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 if (g_loadingMainFile)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
559 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560 LDDocument::setCurrent (load);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
561 g_win->R()->setDocument (load);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 print (QObject::tr ("File %1 parsed successfully (%2 errors)."), path, numWarnings);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 load->history()->setIgnoring (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566 return load;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
567 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
568
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
569 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
570 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
571 bool LDDocument::isSafeToClose()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573 typedef QMessageBox msgbox;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 setlocale (LC_ALL, "C");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
575
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
576 // If we have unsaved changes, warn and give the option of saving.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 if (hasUnsavedChanges())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
579 QString message = format (tr ("There are unsaved changes to %1. Should it be saved?"), getDisplayName());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 int button = msgbox::question (g_win, tr ("Unsaved Changes"), message,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
584 switch (button)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 case msgbox::Yes:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588 // If we don't have a file path yet, we have to ask the user for one.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 if (name().length() == 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
591 QString newpath = QFileDialog::getSaveFileName (g_win, tr ("Save As"),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592 getCurrentDocument()->name(), tr ("LDraw files (*.dat *.ldr)"));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594 if (newpath.length() == 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
595 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597 setName (newpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
600 if (not save())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
601 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
602 message = format (tr ("Failed to save %1 (%2)\nDo you still want to close?"),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
603 name(), strerror (errno));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
604
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
605 if (msgbox::critical (g_win, tr ("Save Failure"), message,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
606 (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
607 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
608 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
610 }
744
bbe0e1834065 - removed rest of the uses of <anonymous>
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
611 break;
bbe0e1834065 - removed rest of the uses of <anonymous>
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
612 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614 case msgbox::Cancel:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
615 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617 default:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
619 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
620 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
623 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
624
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627 void closeAll()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
629 for (LDDocumentPtr file : g_explicitDocuments)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
630 file->dismiss();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
631 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
634 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 void newFile()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
637 // Create a new anonymous file and set it to our current
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
638 LDDocumentPtr f = LDDocument::createNew();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
639 f->setName ("");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
640 f->setImplicit (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641 LDDocument::setCurrent (f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642 LDDocument::closeInitialFile();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643 g_win->R()->setDocument (f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 g_win->doFullRefresh();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 g_win->updateTitle();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646 g_win->updateActions();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
647 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
648
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
651 void addRecentFile (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652 {
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
653 auto& rfiles = cfg::recentFiles;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654 int idx = rfiles.indexOf (path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
656 // If this file already is in the list, pop it out.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
657 if (idx != -1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
658 {
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
659 if (idx == rfiles.size() - 1)
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
660 return; // first recent file - abort and do nothing
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
661
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
662 rfiles.removeAt (idx);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
664
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
665 // If there's too many recent files, drop one out.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
666 while (rfiles.size() > (g_maxRecentFiles - 1))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
667 rfiles.removeAt (0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
668
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
669 // Add the file
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
670 rfiles << path;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
671
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
672 Config::save();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
673 g_win->updateRecentFilesMenu();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
674 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
675
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
676 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
677 // Open an LDraw file and set it as the main model
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
678 // =============================================================================
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
679 void openMainFile (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
680 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
681 // If there's already a file with the same name, this file must replace it.
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
682 LDDocumentPtr documentToReplace;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
683 LDDocumentPtr file;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
684 QString shortName = LDDocument::shortenName (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
685
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
686 for (LDDocumentWeakPtr doc : g_allDocuments)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
687 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
688 if (doc.toStrongRef()->name() == shortName)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
689 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
690 documentToReplace = doc;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
691 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
692 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
693 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
694
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
695 // We cannot open this file if the document this would replace is not
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
696 // safe to close.
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
697 if (documentToReplace != null && not documentToReplace->isSafeToClose())
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
698 return;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
699
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
700 g_loadingMainFile = true;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
701
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
702 // If we're replacing an existing document, clear the document and
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
703 // make it ready for being loaded to.
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
704 if (documentToReplace != null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
705 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
706 file = documentToReplace;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
707 file->clear();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
708 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
709
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
710 file = openDocument (path, false, false, file);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
711
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
712 if (file == null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
714 if (not g_aborted)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
715 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
716 // Tell the user loading failed.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
717 setlocale (LC_ALL, "C");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
718 critical (format (QObject::tr ("Failed to open %1: %2"), path, strerror (errno)));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
719 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
720
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721 g_loadingMainFile = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
722 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
723 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
724
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
725 file->setImplicit (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
726
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
727 // If we have an anonymous, unchanged file open as the only open file
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728 // (aside of the one we just opened), close it now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
729 LDDocument::closeInitialFile();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
730
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
731 // Rebuild the object tree view now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 LDDocument::setCurrent (file);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 g_win->doFullRefresh();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
734
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735 // Add it to the recent files list.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
736 addRecentFile (path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
737 g_loadingMainFile = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
738 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
739
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
740 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
741 //
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
742 bool LDDocument::save (QString path, int64* sizeptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
743 {
781
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
744 if (isImplicit())
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
745 return false;
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
746
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
747 if (not path.length())
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
748 path = fullPath();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
749
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
750 // If the second object in the list holds the file name, update that now.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
751 LDObjectPtr nameObject = getObject (1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
752
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 785
diff changeset
753 if (nameObject != null && nameObject->type() == OBJ_Comment)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
754 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
755 LDCommentPtr nameComment = nameObject.staticCast<LDComment>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
757 if (nameComment->text().left (6) == "Name: ")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
758 {
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
759 QString newname = shortenName (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
760 nameComment->setText (format ("Name: %1", newname));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
761 g_win->buildObjList();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
762 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
763 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
764
781
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
765 QByteArray data;
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
766
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
767 if (sizeptr != null)
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
768 *sizeptr = 0;
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
769
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 // File is open, now save the model to it. Note that LDraw requires files to
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
771 // have DOS line endings, so we terminate the lines with \r\n.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
772 for (LDObjectPtr obj : objects())
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
773 {
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
774 QByteArray subdata ((obj->asText() + "\r\n").toUtf8());
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
775 data.append (subdata);
781
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
776
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
777 if (sizeptr != null)
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
778 *sizeptr += subdata.size();
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
779 }
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
780
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
781 QFile f (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
782
781
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
783 if (not f.open (QIODevice::WriteOnly))
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
784 return false;
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
785
aa823ba3241d - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
786 f.write (data);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
787 f.close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
788
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
789 // We have successfully saved, update the save position now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 setSavePosition (history()->position());
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
791 setFullPath (path);
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
792 setName (shortenName (path));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
793
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
794 g_win->updateDocumentListItem (self().toStrongRef());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
795 g_win->updateTitle();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
798
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
799 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
800 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
801 void LDDocument::clear()
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
802 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
803 for (LDObjectPtr obj : objects())
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
804 forgetObject (obj);
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
805 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
806
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
807 // =============================================================================
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
808 //
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
809 static void checkTokenCount (const QStringList& tokens, int num)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
810 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
811 if (tokens.size() != num)
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
812 throw QString (format ("Bad amount of tokens, expected %1, got %2", num, tokens.size()));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
813 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
815 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
816 //
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
817 static void checkTokenNumbers (const QStringList& tokens, int min, int max)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
819 bool ok;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
820
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 QRegExp scient ("\\-?[0-9]+\\.[0-9]+e\\-[0-9]+");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
822
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
823 for (int i = min; i <= max; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
824 {
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
825 // Check hex
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
826 if (tokens[i].startsWith ("0x"))
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
827 {
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
828 tokens[i].mid (2).toInt (&ok, 16);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
829
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
830 if (not ok)
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
831 {
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
832 // Check for floating point
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
833 tokens[i].toDouble (&ok);
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
834
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
835 // Also check scientific notation, e.g. 7.99361e-15
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
836 if (not ok && not scient.exactMatch (tokens[i]))
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
837 {
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
838 throw QString (format ("Token #%1 was `%2`, expected a number (matched length: %3)",
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
839 (i + 1), tokens[i], scient.matchedLength()));
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
840 }
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
841 }
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
842 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
843 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
844 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
845
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
846 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
847 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
848 static Vertex parseVertex (QStringList& s, const int n)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
849 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
850 Vertex v;
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 719
diff changeset
851 v.apply ([&] (Axis ax, double& a) { a = s[n + ax].toDouble(); });
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
852 return v;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
853 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
854
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
855 static int32 stringToNumber (QString a)
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
856 {
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
857 int base = 10;
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
858
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
859 if (a.startsWith ("0x"))
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
860 {
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
861 a.remove (0, 2);
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
862 base = 16;
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
863 }
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
864
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
865 return a.toLong (null, base);
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
866 }
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
867
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
868 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
869 // This is the LDraw code parser function. It takes in a string containing LDraw
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870 // code and returns the object parsed from it. parseLine never returns null,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
871 // the object will be LDError if it could not be parsed properly.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
872 // =============================================================================
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
873 LDObjectPtr parseLine (QString line)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
874 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
875 try
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
876 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
877 QStringList tokens = line.split (" ", QString::SkipEmptyParts);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
878
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
879 if (tokens.size() <= 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
880 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
881 // Line was empty, or only consisted of whitespace
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
882 return spawn<LDEmpty>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
883 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
884
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
885 if (tokens[0].length() != 1 || not tokens[0][0].isDigit())
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
886 throw QString ("Illogical line code");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
887
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
888 int num = tokens[0][0].digitValue();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
889
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
890 switch (num)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
891 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
892 case 0:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
893 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
894 // Comment
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
895 QString commentText (line.mid (line.indexOf ("0") + 2));
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
896 QString commentTextSimplified (commentText.simplified());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
897
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
898 // Handle BFC statements
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
899 if (tokens.size() > 2 && tokens[1] == "BFC")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
900 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
901 for (int i = 0; i < LDBFC::NumStatements; ++i)
746
893c43b337dd - don't simplify (aka remove extra whitespace from) comment texts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 744
diff changeset
902 if (commentTextSimplified == format ("BFC %1", LDBFC::k_statementStrings [i]))
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
903 return spawn<LDBFC> ((LDBFC::Statement) i);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
904
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
905 // MLCAD is notorious for stuffing these statements in parts it
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
906 // creates. The above block only handles valid statements, so we
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
907 // need to handle MLCAD-style invertnext, clip and noclip separately.
747
17a854ef4412 - simplified the code handling bfc statements a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 746
diff changeset
908 if (commentTextSimplified == "BFC CERTIFY INVERTNEXT")
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
909 return spawn<LDBFC> (LDBFC::InvertNext);
747
17a854ef4412 - simplified the code handling bfc statements a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 746
diff changeset
910 elif (commentTextSimplified == "BFC CERTIFY CLIP")
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
911 return spawn<LDBFC> (LDBFC::Clip);
747
17a854ef4412 - simplified the code handling bfc statements a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 746
diff changeset
912 elif (commentTextSimplified == "BFC CERTIFY NOCLIP")
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
913 return spawn<LDBFC> (LDBFC::NoClip);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
914 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
915
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
916 if (tokens.size() > 2 && tokens[1] == "!LDFORGE")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
917 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
918 // Handle LDForge-specific types, they're embedded into comments too
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
919 if (tokens[2] == "VERTEX")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
920 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
921 // Vertex (0 !LDFORGE VERTEX)
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
922 checkTokenCount (tokens, 7);
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
923 checkTokenNumbers (tokens, 3, 6);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
924
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
925 LDVertexPtr obj = spawn<LDVertex>();
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
926 obj->setColor (LDColor::fromIndex (stringToNumber (tokens[3])));
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 719
diff changeset
927 obj->pos.apply ([&](Axis ax, double& value) { value = tokens[4 + ax].toDouble(); });
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
928 return obj;
748
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
929 }
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
930 elif (tokens[2] == "OVERLAY")
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
931 {
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
932 checkTokenCount (tokens, 9);
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
933 checkTokenNumbers (tokens, 5, 8);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
934
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
935 LDOverlayPtr obj = spawn<LDOverlay>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
936 obj->setFileName (tokens[3]);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
937 obj->setCamera (tokens[4].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
938 obj->setX (tokens[5].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
939 obj->setY (tokens[6].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
940 obj->setWidth (tokens[7].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
941 obj->setHeight (tokens[8].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
942 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
943 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
944 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
945
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
946 // Just a regular comment:
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
947 LDCommentPtr obj = spawn<LDComment>();
746
893c43b337dd - don't simplify (aka remove extra whitespace from) comment texts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 744
diff changeset
948 obj->setText (commentText);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
949 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
950 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
951
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
952 case 1:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
953 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
954 // Subfile
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
955 checkTokenCount (tokens, 15);
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
956 checkTokenNumbers (tokens, 1, 13);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
957
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
958 // Try open the file. Disable g_loadingMainFile temporarily since we're
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
959 // not loading the main file now, but the subfile in question.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
960 bool tmp = g_loadingMainFile;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
961 g_loadingMainFile = false;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
962 LDDocumentPtr load = getDocument (tokens[14]);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
963 g_loadingMainFile = tmp;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
964
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
965 // If we cannot open the file, mark it an error. Note we cannot use LDParseError
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
966 // here because the error object needs the document reference.
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
967 if (not load)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
968 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
969 LDErrorPtr obj = spawn<LDError> (line, format ("Could not open %1", tokens[14]));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
970 obj->setFileReferenced (tokens[14]);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
971 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
972 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
973
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
974 LDSubfilePtr obj = spawn<LDSubfile>();
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
975 obj->setColor (LDColor::fromIndex (stringToNumber (tokens[1])));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
976 obj->setPosition (parseVertex (tokens, 2)); // 2 - 4
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
977
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
978 Matrix transform;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
979
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
980 for (int i = 0; i < 9; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
981 transform[i] = tokens[i + 5].toDouble(); // 5 - 13
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
982
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
983 obj->setTransform (transform);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
984 obj->setFileInfo (load);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
985 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
986 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
987
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
988 case 2:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
989 {
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
990 checkTokenCount (tokens, 8);
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
991 checkTokenNumbers (tokens, 1, 7);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
992
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
993 // Line
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
994 LDLinePtr obj (spawn<LDLine>());
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
995 obj->setColor (LDColor::fromIndex (stringToNumber (tokens[1])));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
996
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
997 for (int i = 0; i < 2; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
998 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
999
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1000 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1001 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1002
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1003 case 3:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1004 {
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
1005 checkTokenCount (tokens, 11);
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
1006 checkTokenNumbers (tokens, 1, 10);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1007
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1008 // Triangle
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1009 LDTrianglePtr obj (spawn<LDTriangle>());
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1010 obj->setColor (LDColor::fromIndex (stringToNumber (tokens[1])));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1011
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1012 for (int i = 0; i < 3; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1013 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1014
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1015 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1016 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1017
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1018 case 4:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1019 case 5:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1020 {
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
1021 checkTokenCount (tokens, 14);
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
1022 checkTokenNumbers (tokens, 1, 13);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1023
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1024 // Quadrilateral / Conditional line
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1025 LDObjectPtr obj;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1026
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1027 if (num == 4)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1028 obj = spawn<LDQuad>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1029 else
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1030 obj = spawn<LDCondLine>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1031
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1032 obj->setColor (LDColor::fromIndex (stringToNumber (tokens[1])));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1033
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1034 for (int i = 0; i < 4; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1035 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1036
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1037 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1038 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1039
748
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
1040 default:
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1041 throw QString ("Unknown line code number");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1042 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1043 }
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1044 catch (QString& e)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1045 {
748
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
1046 // Strange line we couldn't parse
782
70526ee626a0 - simplified parse error handling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 781
diff changeset
1047 return spawn<LDError> (line, e);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1048 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1049 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1050
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1051 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1052 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1053 LDDocumentPtr getDocument (QString filename)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1054 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1055 // Try find the file in the list of loaded files
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1056 LDDocumentPtr doc = findDocument (filename);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1057
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1058 // If it's not loaded, try open it
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1059 if (not doc)
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1060 doc = openDocument (filename, true, true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1061
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1062 return doc;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1063 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1064
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1065 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1066 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1067 void reloadAllSubfiles()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1068 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1069 if (not getCurrentDocument())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1070 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1071
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1072 // Go through all objects in the current file and reload the subfiles
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1073 for (LDObjectPtr obj : getCurrentDocument()->objects())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1074 {
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 785
diff changeset
1075 if (obj->type() == OBJ_Subfile)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1076 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1077 LDSubfilePtr ref = obj.staticCast<LDSubfile>();
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1078 LDDocumentPtr fileInfo = getDocument (ref->fileInfo()->name());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1079
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1080 if (fileInfo)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1081 ref->setFileInfo (fileInfo);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1082 else
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1083 ref->replace (spawn<LDError> (ref->asText(), format ("Could not open %1", ref->fileInfo()->name())));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1084 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1085
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1086 // Reparse gibberish files. It could be that they are invalid because
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1087 // of loading errors. Circumstances may be different now.
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 785
diff changeset
1088 if (obj->type() == OBJ_Error)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1089 obj->replace (parseLine (obj.staticCast<LDError>()->contents()));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1090 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1091 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1092
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1093 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1094 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1095 int LDDocument::addObject (LDObjectPtr obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1096 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1097 history()->add (new AddHistory (objects().size(), obj));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1098 m_objects << obj;
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1099 addKnownVertices (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1100
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1101 #ifdef DEBUG
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1102 if (not isImplicit())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1103 dprint ("Added object #%1 (%2)\n", obj->id(), obj->typeName());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1104 #endif
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1105
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1106 obj->setDocument (this);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1107 g_win->R()->compileObject (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1108 return getObjectCount() - 1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1109 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1110
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1111 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1112 //
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1113 void LDDocument::addObjects (const LDObjectList& objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1114 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1115 for (LDObjectPtr obj : objs)
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1116 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1117 if (obj != null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1118 addObject (obj);
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1119 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1120 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1121
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1122 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1123 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1124 void LDDocument::insertObj (int pos, LDObjectPtr obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1125 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1126 history()->add (new AddHistory (pos, obj));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1127 m_objects.insert (pos, obj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1128 obj->setDocument (this);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1129 g_win->R()->compileObject (obj);
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1130
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1131
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1132 #ifdef DEBUG
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1133 if (not isImplicit())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1134 dprint ("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1135 #endif
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1136 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1137
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1138 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1139 //
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1140 void LDDocument::addKnownVertices (LDObjectPtr obj)
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1141 {
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1142 auto it = _objectVertices.find (obj);
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1143
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1144 if (it == _objectVertices.end())
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1145 it = _objectVertices.insert (obj, QVector<Vertex>());
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1146 else
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1147 it->clear();
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1148
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1149 obj->getVertices (*it);
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1150 needVertexMerge();
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1151 }
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1152
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1153 // =============================================================================
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1154 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1155 void LDDocument::forgetObject (LDObjectPtr obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1156 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1157 int idx = obj->lineNumber();
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 761
diff changeset
1158 obj->deselect();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1159 assert (m_objects[idx] == obj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1160
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1161 if (not isImplicit() && not (flags() & DOCF_IsBeingDestroyed))
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1162 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1163 history()->add (new DelHistory (idx, obj));
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1164 _objectVertices.remove (obj);
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1165 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1166
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1167 m_objects.removeAt (idx);
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1168 obj->setDocument (LDDocumentPtr());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1169 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1170
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1171 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1172 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1173 bool safeToCloseAll()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1174 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1175 for (LDDocumentPtr f : LDDocument::explicitDocuments())
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1176 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1177 if (not f->isSafeToClose())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1178 return false;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1179 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1180
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1181 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1182 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1183
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1184 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1185 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1186 void LDDocument::setObject (int idx, LDObjectPtr obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1187 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1188 assert (idx >= 0 && idx < m_objects.size());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1189
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1190 // Mark this change to history
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1191 if (not m_history->isIgnoring())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1192 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1193 QString oldcode = getObject (idx)->asText();
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1194 QString newcode = obj->asText();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1195 *m_history << new EditHistory (idx, oldcode, newcode);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1196 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1197
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1198 _objectVertices.remove (m_objects[idx]);
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 761
diff changeset
1199 m_objects[idx]->deselect();
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1200 m_objects[idx]->setDocument (LDDocumentPtr());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1201 obj->setDocument (this);
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1202 addKnownVertices (obj);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1203 g_win->R()->compileObject (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1204 m_objects[idx] = obj;
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1205 needVertexMerge();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1206 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1207
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1208 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1209 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1210 LDObjectPtr LDDocument::getObject (int pos) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1211 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1212 if (m_objects.size() <= pos)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1213 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1214
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1215 return m_objects[pos];
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1216 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1217
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1218 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1219 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1220 int LDDocument::getObjectCount() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1221 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1222 return objects().size();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1223 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1224
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1225 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1226 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1227 bool LDDocument::hasUnsavedChanges() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1228 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1229 return not isImplicit() && history()->position() != savePosition();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1230 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1231
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1232 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1233 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1234 QString LDDocument::getDisplayName()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1235 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1236 if (not name().isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1237 return name();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1238
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1239 if (not defaultName().isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1240 return "[" + defaultName() + "]";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1241
734
cdce1cbaac7e - <anonymous> -> untitled
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
1242 return tr ("untitled");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1243 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1244
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1245 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1246 //
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1247 void LDDocument::initializeCachedData()
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1248 {
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1249 if (m_needsReCache)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1250 {
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1251 _vertices.clear();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1252
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1253 for (LDObjectPtr obj : inlineContents (true, true))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1254 {
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1255 assert (obj->type() != OBJ_Subfile);
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1256 LDPolygon* data = obj->getPolygon();
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1257
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1258 if (data != null)
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1259 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1260 m_polygonData << *data;
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1261 delete data;
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1262 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1263 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1264
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1265 m_needsReCache = false;
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1266 }
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1267
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1268 if (_verticesOutdated)
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1269 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1270 _objectVertices.clear();
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1271
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1272 for (LDObjectPtr obj : inlineContents (true, false))
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1273 addKnownVertices (obj);
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1274
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1275 mergeVertices();
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1276 _verticesOutdated = false;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1277 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1278
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1279 if (_needVertexMerge)
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1280 mergeVertices();
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1281 }
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1282
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1283 // =============================================================================
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1284 //
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1285 void LDDocument::mergeVertices()
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1286 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1287 _vertices.clear();
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1288
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1289 for (QVector<Vertex> const& verts : _objectVertices)
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1290 _vertices << verts;
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1291
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1292 removeDuplicates (_vertices);
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1293 _needVertexMerge = false;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1294 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1295
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1296 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1297 //
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1298 QList<LDPolygon> LDDocument::inlinePolygons()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1299 {
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1300 initializeCachedData();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1301 return polygonData();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1302 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1303
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1304 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1305 // -----------------------------------------------------------------------------
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1306 LDObjectList LDDocument::inlineContents (bool deep, bool renderinline)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1307 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1308 // Possibly substitute with logoed studs:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1309 // stud.dat -> stud-logo.dat
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1310 // stud2.dat -> stud-logo2.dat
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 748
diff changeset
1311 if (cfg::useLogoStuds && renderinline)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1312 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1313 // Ensure logoed studs are loaded first
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1314 loadLogoedStuds();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1315
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1316 if (name() == "stud.dat" && g_logoedStud != null)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1317 return g_logoedStud->inlineContents (deep, renderinline);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1318 elif (name() == "stud2.dat" && g_logoedStud2 != null)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1319 return g_logoedStud2->inlineContents (deep, renderinline);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1320 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1321
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1322 LDObjectList objs, objcache;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1323
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1324 for (LDObjectPtr obj : objects())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1325 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1326 // Skip those without scemantic meaning
714
b4a990f59a5e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 713 662
diff changeset
1327 if (not obj->isScemantic())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1328 continue;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1329
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1330 // Got another sub-file reference, inline it if we're deep-inlining. If not,
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1331 // just add it into the objects normally. Yay, recursion!
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 785
diff changeset
1332 if (deep == true && obj->type() == OBJ_Subfile)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1333 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1334 for (LDObjectPtr otherobj : obj.staticCast<LDSubfile>()->inlineContents (deep, renderinline))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1335 objs << otherobj;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1336 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1337 else
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1338 objs << obj->createCopy();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1339 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1340
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1341 return objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1342 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1343
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1344 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1345 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1346 LDDocumentPtr LDDocument::current()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1347 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1348 return g_currentDocument;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1349 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1350
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1351 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1352 // Sets the given file as the current one on display. At some point in time this
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1353 // was an operation completely unheard of. ;)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1354 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1355 // TODO: f can be temporarily null. This probably should not be the case.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1356 // =============================================================================
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1357 void LDDocument::setCurrent (LDDocumentPtr f)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1358 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1359 // Implicit files were loaded for caching purposes and must never be set
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1360 // current.
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1361 if (f != null && f->isImplicit())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1362 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1363
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1364 g_currentDocument = f;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1365
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1366 if (g_win && f)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1367 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1368 // A ton of stuff needs to be updated
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1369 g_win->updateDocumentListItem (f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1370 g_win->buildObjList();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1371 g_win->updateTitle();
737
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 735
diff changeset
1372 g_win->R()->setDocument (f);
735
54c321f4d102 - when setting the current document, the GL compiler must be told that a merge is necessary *before* setting the renderer's document as setDocument will call zoomToFit which renders the scene. this rendering must trigger a merge or ldforge crashes if a new document is created when a document is already open.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 734
diff changeset
1373 g_win->R()->compiler()->needMerge();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1374 print ("Changed file to %1", f->getDisplayName());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1375 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1376 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1377
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1378 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1379 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1380 int LDDocument::countExplicitFiles()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1381 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1382 return g_explicitDocuments.size();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1383 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1384
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1385 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1386 // This little beauty closes the initial file that was open at first when opening
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1387 // a new file over it.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1388 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1389 void LDDocument::closeInitialFile()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1390 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1391 if (g_explicitDocuments.size() == 2 &&
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1392 g_explicitDocuments[0]->name().isEmpty() &&
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1393 not g_explicitDocuments[1]->name().isEmpty() &&
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1394 not g_explicitDocuments[0]->hasUnsavedChanges())
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1395 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1396 g_explicitDocuments[0]->dismiss();
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1397 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1398 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1399
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1400 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1401 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1402 void loadLogoedStuds()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1403 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1404 if (g_logoedStud && g_logoedStud2)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1405 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1406
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1407 g_logoedStud = openDocument ("stud-logo.dat", true, true);
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1408 g_logoedStud2 = openDocument ("stud2-logo.dat", true, true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1409
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1410 print (LDDocument::tr ("Logoed studs loaded.\n"));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1411 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1412
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1413 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1414 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1415 void LDDocument::addToSelection (LDObjectPtr obj) // [protected]
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1416 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1417 if (obj->isSelected())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1418 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1419
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1420 assert (obj->document() == self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1421 m_sel << obj;
761
64ea52bf685c - significantly sped up selecting all objects, it is now an actually fast operation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
1422 g_win->R()->compileObject (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1423 obj->setSelected (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1424 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1425
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1426 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1427 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1428 void LDDocument::removeFromSelection (LDObjectPtr obj) // [protected]
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1429 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 656
diff changeset
1430 if (not obj->isSelected())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1431 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1432
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1433 assert (obj->document() == self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1434 m_sel.removeOne (obj);
761
64ea52bf685c - significantly sped up selecting all objects, it is now an actually fast operation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
1435 g_win->R()->compileObject (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1436 obj->setSelected (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1437 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1438
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1439 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1440 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1441 void LDDocument::clearSelection()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1442 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1443 for (LDObjectPtr obj : m_sel)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1444 removeFromSelection (obj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1445
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1446 assert (m_sel.isEmpty());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1447 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1448
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1449 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1450 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1451 const LDObjectList& LDDocument::getSelection() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1452 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1453 return m_sel;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1454 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1455
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1456 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1457 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1458 void LDDocument::swapObjects (LDObjectPtr one, LDObjectPtr other)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1459 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1460 int a = m_objects.indexOf (one);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1461 int b = m_objects.indexOf (other);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1462 assert (a != b && a != -1 && b != -1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1463 m_objects[b] = one;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1464 m_objects[a] = other;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1465 addToHistory (new SwapHistory (one->id(), other->id()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1466 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1467
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1468 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1469 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1470 QString LDDocument::shortenName (QString a) // [static]
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1471 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1472 QString shortname = basename (a);
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1473 QString topdirname = basename (dirname (a));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1474
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1475 if (g_specialSubdirectories.contains (topdirname))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1476 shortname.prepend (topdirname + "\\");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1477
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1478 return shortname;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1479 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1480
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1481 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1482 //
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1483 QVector<Vertex> const& LDDocument::inlineVertices()
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1484 {
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1485 initializeCachedData();
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1486 return _vertices;
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1487 }
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1488
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1489 void LDDocument::redoVertices()
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1490 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1491 _verticesOutdated = true;
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1492 }
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1493
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1494 void LDDocument::needVertexMerge()
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1495 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1496 _needVertexMerge = true;
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1497 }

mercurial