src/ldDocument.cc

Thu, 23 Oct 2014 16:44:52 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 23 Oct 2014 16:44:52 +0300
branch
experimental
changeset 911
5209474e9f38
parent 891
00d76b281021
parent 902
3a69c2e0532c
permissions
-rw-r--r--

- merged with default

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
844
11587d419d2f - changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
3 * Copyright (C) 2013, 2014 Teemu Piippo
655
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"
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
34 #include "partDownloader.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
36 CFGENTRY (String, LDrawPath, "")
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
37 CFGENTRY (List, RecentFiles, {})
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
38 EXTERN_CFGENTRY (String, DownloadFilePath)
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
39 EXTERN_CFGENTRY (Bool, UseLogoStuds)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 static bool g_loadingMainFile = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 static const int g_maxRecentFiles = 10;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 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
44 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
45 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
46 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
47 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
48 static LDDocumentPtr g_currentDocument;
877
7c50b61ad5b6 - fixed infinite recursion when loading logoed studs
Teemu Piippo <crimsondusk64@gmail.com>
parents: 872
diff changeset
49 static bool g_loadingLogoedStuds = false;
655
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 const QStringList g_specialSubdirectories ({ "s", "48", "8" });
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 namespace LDPaths
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
57 static QString pathError;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 struct
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
61 QString LDConfigPath;
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
62 QString partsPath, primsPath;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 } pathInfo;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 void initPaths()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 {
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
67 if (not tryConfigure (cfg::LDrawPath))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 LDrawPathDialog dlg (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
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
71 if (not dlg.exec())
857
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
72 Exit();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
74 cfg::LDrawPath = dlg.filename();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
78 bool tryConfigure (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 QDir dir;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
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
82 if (not dir.cd (path))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 pathError = "Directory does not exist.";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 QStringList contents = dir.entryList (mustHave);
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 if (contents.size() != mustHave.size())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 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
94 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 pathInfo.partsPath = format ("%1" DIRSLASH "parts", path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 pathInfo.LDConfigPath = format ("%1" DIRSLASH "LDConfig.ldr", path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 pathInfo.primsPath = format ("%1" DIRSLASH "p", path);
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 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 // Accessors
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
105 QString getError()
655
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 return pathError;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
110 QString ldconfig()
655
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 return pathInfo.LDConfigPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
115 QString prims()
655
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 return pathInfo.primsPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
120 QString parts()
655
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 return pathInfo.partsPath;
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
128 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
129 m_isImplicit (true),
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
130 m_flags (0),
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
131 m_verticesOutdated (true),
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
132 m_needVertexMerge (true),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 m_gldata (new LDGLData)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
135 *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
136 setSelf (*selfptr);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 setSavePosition (-1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 setTabIndex (-1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 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
140 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
141 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
142 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
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 // =============================================================================
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 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
148 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
149 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
150 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
151 return ptr;
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 LDDocument::~LDDocument()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 {
857
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
158 // Don't bother during program termination
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
159 if (IsExiting())
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
160 return;
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
161
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
162 g_allDocuments.removeOne (self());
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
163 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
164 delete m_history;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 delete m_gldata;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
170 void LDDocument::setImplicit (bool const& a)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 {
784
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 (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
173 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
174 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
175
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
176 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
177 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
178 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
179 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
180
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 // 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
182 // 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
183 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
184 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
185 }
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
186 else
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
187 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
188 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
189 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
190 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
191
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
192 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
193 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
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 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
196 // we need to get a new current document.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
197 if (current() == self() and isImplicit())
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
198 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
199 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
200 newFile();
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
201 else
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
202 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
203 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
204 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
205 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
206
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
207 LDObjectList const& LDDocument::objects()
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
208 {
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
209 sweepBFC();
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
210 return m_objects;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
211 }
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
212
784
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 //
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
215 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
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 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
218 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
219
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 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
222 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
223 {
866
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
224 for (LDDocumentWeakPtr weakfile : g_allDocuments)
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 {
866
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
226 if (weakfile == null)
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
227 continue;
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
228
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
229 LDDocumentPtr file (weakfile.toStrongRef());
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
230
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
231 if (Eq (name, file->name(), file->defaultName()))
4951b737f8cb - now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents: 863
diff changeset
232 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
233 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
235 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237
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 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
240 QString Dirname (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 long lastpos = path.lastIndexOf (DIRSLASH);
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 if (lastpos > 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 return path.left (lastpos);
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 #ifndef _WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 if (path[0] == DIRSLASH_CHAR)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 return DIRSLASH;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 #endif // _WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254
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 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
257 QString Basename (QString path)
655
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 long lastpos = path.lastIndexOf (DIRSLASH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 if (lastpos != -1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 return path.mid (lastpos + 1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 return path;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
269 static QString FindDocumentPath (QString relpath, bool subdirs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
271 QString fullPath;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 // 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
274 // replace the path separator now before opening any files. Qt expects
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 // forward-slashes as directory separators.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 #ifndef WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 relpath.replace ("\\", "/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 #endif // WIN32
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 // 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
281 // in the immediate vicinity of a current model to override stock LDraw stuff.
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
282 QString reltop = Basename (Dirname (relpath));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283
836
a522e1cd92af - fixed incorrect conversions of weak pointers to strong ones
Teemu Piippo <crimsondusk64@gmail.com>
parents: 835
diff changeset
284 for (LDDocumentWeakPtr doc : g_allDocuments)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 {
836
a522e1cd92af - fixed incorrect conversions of weak pointers to strong ones
Teemu Piippo <crimsondusk64@gmail.com>
parents: 835
diff changeset
286 if (doc == null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
289 QString partpath = format ("%1/%2", Dirname (doc.toStrongRef()->fullPath()), relpath);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 QFile f (partpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 if (f.exists())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 // ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
295 QString proptop = Basename (Dirname (partpath));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 bool bogus = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
299 for (QString s : g_specialSubdirectories)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
301 if ((proptop == s and reltop != s) or (reltop == s and proptop != s))
655
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 bogus = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
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
308 if (not bogus)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 return partpath;
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 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 if (QFile::exists (relpath))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 return relpath;
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 // Try with just the LDraw path first
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
317 fullPath = format ("%1" DIRSLASH "%2", cfg::LDrawPath, relpath);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 if (QFile::exists (fullPath))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 return fullPath;
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 if (subdirs)
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 // 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
325 // where we download parts from the PT to.
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
326 for (const QString& topdir : QList<QString> ({ cfg::LDrawPath, cfg::DownloadFilePath }))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
328 for (const QString& subdir : QList<QString> ({ "parts", "p" }))
655
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 fullPath = format ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 if (QFile::exists (fullPath))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 return fullPath;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 }
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 // Did not find the file.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 return "";
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
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
342 // =============================================================================
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
343 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
344 QFile* OpenLDrawFile (QString relpath, bool subdirs, QString* pathpointer)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 print ("Opening %1...\n", relpath);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
347 QString path = FindDocumentPath (relpath, subdirs);
655
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 (pathpointer != null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 *pathpointer = path;
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 if (path.isEmpty())
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 QFile* fp = new QFile (path);
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 if (fp->open (QIODevice::ReadOnly))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 return fp;
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 fp->deleteLater();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 return null;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 }
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 // =============================================================================
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 void LDFileLoader::start()
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 setDone (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 setProgress (0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 setAborted (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 g_aborted = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 // 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
377 // 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
378 // 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
379 // block.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 dlg = new OpenProgressDialog (g_win);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 dlg->setNumLines (lines().size());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 dlg->setModal (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 dlg->show();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 // Connect the loader in so we can show updates
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 connect (this, SIGNAL (workDone()), dlg, SLOT (accept()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 connect (dlg, SIGNAL (rejected()), this, SLOT (abort()));
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 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 dlg = null;
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 // Begin working
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 work (0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 // =============================================================================
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 void LDFileLoader::work (int i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 // User wishes to abort, so stop here now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 if (isAborted())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
403 for (LDObjectPtr obj : m_objects)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 obj->destroy();
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 m_objects.clear();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 setDone (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 return;
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 // Parse up to 300 lines per iteration
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 int max = i + 300;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
414 for (; i < max and i < (int) lines().size(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
416 QString line = lines()[i];
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 // Trim the trailing newline
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 QChar c;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
421 while (line.endsWith ("\n") or line.endsWith ("\r"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 line.chop (1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
424 LDObjectPtr obj = ParseLine (line);
655
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 // 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
427 if (obj->type() == OBJ_Error)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 {
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
429 print ("Couldn't parse line #%1: %2",
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
430 progress() + 1, obj.staticCast<LDError>()->reason());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 if (warnings() != null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 (*warnings())++;
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 m_objects << obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 setProgress (i);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 // If we have a dialog pointer, update the progress now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 dlg->updateProgress (i);
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 // 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
445 if (i >= ((int) lines().size()) - 1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 emit workDone();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 setDone (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 return;
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 // 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
453 if (not isDone())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 // 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
456 // work() again immediately as the dialog needs some processor cycles as
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 // 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
458 // meta-object system.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 // 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
461 // 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
462 // until we're ready (see loadFileContents), thus the event loop will
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 // 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
464 // 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
465 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (int, i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 work (i);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 }
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 void LDFileLoader::abort()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476 setAborted (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 if (isOnForeground())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479 g_aborted = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481
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 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
484 LDObjectList LoadFileContents (QFile* fp, int* numWarnings, bool* ok)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486 QStringList lines;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487 LDObjectList objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
488
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 if (numWarnings)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 *numWarnings = 0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492 // 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
493 while (not fp->atEnd())
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
494 lines << QString::fromUtf8 (fp->readLine());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496 LDFileLoader* loader = new LDFileLoader;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497 loader->setWarnings (numWarnings);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498 loader->setLines (lines);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499 loader->setOnForeground (g_loadingMainFile);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 loader->start();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 // 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
503 // 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
504 // 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
505 // 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
506 while (not loader->isDone())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507 qApp->processEvents();
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 // If we wanted the success value, supply that now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
510 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
511 *ok = not loader->isAborted();
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 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
514 delete loader;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
515 return objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
517
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 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
520 LDDocumentPtr OpenDocument (QString path, bool search, bool implicit, LDDocumentPtr fileToOverride)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 {
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
522 // Convert the file name to lowercase when searching because some parts contain subfile
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
523 // subfile references with uppercase file names. I'll assume here that the library will always
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
524 // use lowercase file names for the part files.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525 QFile* fp;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
526 QString fullpath;
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 if (search)
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
529 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
530 fp = OpenLDrawFile (path.toLower(), true, &fullpath);
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
531 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
533 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
534 fp = new QFile (path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535 fullpath = path;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
536
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
537 if (not fp->open (QIODevice::ReadOnly))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 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
540 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543
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
544 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
545 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
547 LDDocumentPtr load = (fileToOverride != null ? fileToOverride : LDDocument::createNew());
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
548 load->setImplicit (implicit);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549 load->setFullPath (fullpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550 load->setName (LDDocument::shortenName (load->fullPath()));
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 // 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
553 load->history()->setIgnoring (true);
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 int numWarnings;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556 bool ok;
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
557 LDObjectList objs = LoadFileContents (fp, &numWarnings, &ok);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 fp->close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
559 fp->deleteLater();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560
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
561 if (not ok)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
563 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
564 return LDDocumentPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
567 load->addObjects (objs);
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 if (g_loadingMainFile)
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 LDDocument::setCurrent (load);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 g_win->R()->setDocument (load);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573 print (QObject::tr ("File %1 parsed successfully (%2 errors)."), path, numWarnings);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 }
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 load->history()->setIgnoring (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 return load;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 bool LDDocument::isSafeToClose()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 {
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
584 using msgbox = QMessageBox;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585 setlocale (LC_ALL, "C");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 // 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
588 if (hasUnsavedChanges())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
590 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
591
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592 int button = msgbox::question (g_win, tr ("Unsaved Changes"), message,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
595 switch (button)
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 case msgbox::Yes:
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 // 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
600 if (name().length() == 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
601 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
602 QString newpath = QFileDialog::getSaveFileName (g_win, tr ("Save As"),
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
603 CurrentDocument()->name(), tr ("LDraw files (*.dat *.ldr)"));
655
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 (newpath.length() == 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
606 return false;
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 setName (newpath);
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
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
611 if (not save())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613 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
614 name(), strerror (errno));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
615
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616 if (msgbox::critical (g_win, tr ("Save Failure"), message,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617 (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
619 return false;
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 }
744
bbe0e1834065 - removed rest of the uses of <anonymous>
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
622 break;
bbe0e1834065 - removed rest of the uses of <anonymous>
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
623 }
655
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 case msgbox::Cancel:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628 default:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
629 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630 }
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 return true;
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
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 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
638 void CloseAllDocuments()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
639 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
640 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
641 file->dismiss();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646 void newFile()
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 // 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
649 LDDocumentPtr f = LDDocument::createNew();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 f->setName ("");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 f->setImplicit (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652 LDDocument::setCurrent (f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653 LDDocument::closeInitialFile();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654 g_win->R()->setDocument (f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
655 g_win->doFullRefresh();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
656 g_win->updateTitle();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
657 g_win->updateActions();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
658 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
659
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
660 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
661 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
662 void AddRecentFile (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663 {
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
664 int idx = cfg::RecentFiles.indexOf (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
665
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
666 // If this file already is in the list, pop it out.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
667 if (idx != -1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
668 {
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
669 if (idx == cfg::RecentFiles.size() - 1)
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
670 return; // first recent file - abort and do nothing
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
671
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
672 cfg::RecentFiles.removeAt (idx);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
673 }
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 // If there's too many recent files, drop one out.
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
676 while (cfg::RecentFiles.size() > (g_maxRecentFiles - 1))
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
677 cfg::RecentFiles.removeAt (0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
678
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
679 // Add the file
872
977099f224d0 - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
680 cfg::RecentFiles << path;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
681
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 847
diff changeset
682 Config::Save();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
683 g_win->updateRecentFilesMenu();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
684 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
685
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
687 // Open an LDraw file and set it as the main model
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
688 // =============================================================================
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
689 void OpenMainModel (QString path)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
690 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
691 // 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
692 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
693 LDDocumentPtr file;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
694 QString shortName = LDDocument::shortenName (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
695
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
696 for (LDDocumentWeakPtr doc : g_allDocuments)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
697 {
883
69b8adc9a669 - fixed: due to a shared pointer called via reference called dismiss() in LDDocument::closeInitialFile, this could cause LDDocuments to delete themselves in setImplicit(true) as no shared pointers were left inside closeInitialFile to keep the refcount up.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
698 if (doc != null and doc.toStrongRef()->name() == shortName)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
699 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
700 documentToReplace = doc;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
701 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
702 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
703 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
704
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
705 // 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
706 // safe to close.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
707 if (documentToReplace != null and 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
708 return;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
709
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
710 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
711
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 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
713 // 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
714 if (documentToReplace != null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
715 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
716 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
717 file->clear();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
718 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
719
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
720 file = OpenDocument (path, false, false, file);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
722 if (file == null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
723 {
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
724 if (not g_aborted)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
725 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
726 // Tell the user loading failed.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
727 setlocale (LC_ALL, "C");
882
2f3cc8e045d5 - fixed compilation on windows
Teemu Piippo <crimsondusk64@gmail.com>
parents: 881
diff changeset
728 Critical (format (QObject::tr ("Failed to open %1: %2"), path, strerror (errno)));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
729 }
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 g_loadingMainFile = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 }
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 file->setImplicit (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
736
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
737 // 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
738 // (aside of the one we just opened), close it now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
739 LDDocument::closeInitialFile();
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 // Rebuild the object tree view now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
742 LDDocument::setCurrent (file);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
743 g_win->doFullRefresh();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
744
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
745 // Add it to the recent files list.
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
746 AddRecentFile (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
747 g_loadingMainFile = false;
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
748
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
749 // If there were problems loading subfile references, try see if we can find these
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
750 // files on the parts tracker.
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
751 QStringList unknowns;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
752
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
753 for (LDObjectPtr obj : file->objects())
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
754 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
755 if (obj->type() != OBJ_Error or obj.staticCast<LDError>()->fileReferenced().isEmpty())
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
756 continue;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
757
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
758 unknowns << obj.staticCast<LDError>()->fileReferenced();
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
759 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
760
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
761 if (not unknowns.isEmpty())
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
762 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
763 PartDownloader dl;
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
764 dl.setSource (PartDownloader::PartsTracker);
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
765 dl.setPrimaryFile (file);
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
766
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
767 for (QString const& unknown : unknowns)
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
768 dl.downloadFromPartsTracker (unknown);
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
769
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
770 dl.exec();
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
771 dl.checkIfFinished();
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
772 file->reloadAllSubfiles();
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
773 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
774 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
775
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
776 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
777 //
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
778 bool LDDocument::save (QString path, int64* sizeptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
779 {
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
780 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
781 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
782
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
783 if (not path.length())
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
784 path = fullPath();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
785
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
786 // 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
787 LDObjectPtr nameObject = getObject (1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
788
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
789 if (nameObject != null and nameObject->type() == OBJ_Comment)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
791 LDCommentPtr nameComment = nameObject.staticCast<LDComment>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
792
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
793 if (nameComment->text().left (6) == "Name: ")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
794 {
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
795 QString newname = shortenName (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796 nameComment->setText (format ("Name: %1", newname));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 g_win->buildObjList();
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
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
801 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
802
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
803 if (sizeptr != null)
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
804 *sizeptr = 0;
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
805
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
806 // 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
807 // 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
808 for (LDObjectPtr obj : objects())
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
809 {
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
810 QByteArray subdata ((obj->asText() + "\r\n").toUtf8());
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
811 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
812
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
813 if (sizeptr != null)
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
814 *sizeptr += subdata.size();
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
815 }
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
816
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
817 QFile f (path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818
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
819 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
820 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
821
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
822 f.write (data);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
823 f.close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
824
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
825 // We have successfully saved, update the save position now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
826 setSavePosition (history()->position());
834
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
827 setFullPath (path);
3e697ba996e8 - now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents: 831
diff changeset
828 setName (shortenName (path));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
829
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
830 g_win->updateDocumentListItem (self().toStrongRef());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
831 g_win->updateTitle();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
832 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
833 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
834
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
835 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
836 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
837 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
838 {
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
839 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
840 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
841 }
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
842
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
843 // =============================================================================
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
844 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
845 static void CheckTokenCount (const QStringList& tokens, int num)
655
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 if (tokens.size() != num)
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
848 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
849 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
850
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
851 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
852 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
853 static void CheckTokenNumbers (const QStringList& tokens, int min, int max)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
854 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
855 bool ok;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
856
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
857 QRegExp scient ("\\-?[0-9]+\\.[0-9]+e\\-[0-9]+");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
858
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
859 for (int i = min; i <= max; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
860 {
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
861 // Check for floating point
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
862 tokens[i].toDouble (&ok);
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
863 if (ok)
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
864 return;
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
865
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
866 // 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
867 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
868 {
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
869 tokens[i].mid (2).toInt (&ok, 16);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
871 if (ok)
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
872 return;
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
873 }
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
874
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
875 // Check scientific notation, e.g. 7.99361e-15
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
876 if (scient.exactMatch (tokens[i]))
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
877 return;
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
878
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
879 throw QString (format ("Token #%1 was `%2`, expected a number (matched length: %3)",
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
880 (i + 1), tokens[i], scient.matchedLength()));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
881 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
882 }
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
885 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
886 static Vertex ParseVertex (QStringList& s, const int n)
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 Vertex v;
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 719
diff changeset
889 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
890 return v;
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
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
893 static int32 StringToNumber (QString a, bool* ok = null)
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
894 {
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
895 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
896
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
897 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
898 {
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
899 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
900 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
901 }
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
902
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
903 return a.toLong (ok, base);
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
904 }
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
905
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
906 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
907 // 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
908 // 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
909 // 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
910 // =============================================================================
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
911 LDObjectPtr ParseLine (QString line)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
912 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
913 try
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
914 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
915 QStringList tokens = line.split (" ", QString::SkipEmptyParts);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
916
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
917 if (tokens.size() <= 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
918 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
919 // Line was empty, or only consisted of whitespace
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
920 return LDSpawn<LDEmpty>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
921 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
922
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
923 if (tokens[0].length() != 1 or not tokens[0][0].isDigit())
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
924 throw QString ("Illogical line code");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
925
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
926 int num = tokens[0][0].digitValue();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
927
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
928 switch (num)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
929 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
930 case 0:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
931 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
932 // Comment
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
933 QString commentText (line.mid (line.indexOf ("0") + 2));
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
934 QString commentTextSimplified (commentText.simplified());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
935
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
936 // Handle BFC statements
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
937 if (tokens.size() > 2 and tokens[1] == "BFC")
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
938 {
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
939 for_enum (BFCStatement, i)
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
940 {
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
941 if (commentTextSimplified == format ("BFC %1",
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
942 LDBFC::StatementStrings[int (i)]))
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
943 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
944 return LDSpawn<LDBFC> (i);
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
945 }
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
946 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
947
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
948 // MLCAD is notorious for stuffing these statements in parts it
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
949 // creates. The above block only handles valid statements, so we
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
950 // 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
951 if (commentTextSimplified == "BFC CERTIFY INVERTNEXT")
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
952 return LDSpawn<LDBFC> (BFCStatement::InvertNext);
747
17a854ef4412 - simplified the code handling bfc statements a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 746
diff changeset
953 elif (commentTextSimplified == "BFC CERTIFY CLIP")
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
954 return LDSpawn<LDBFC> (BFCStatement::Clip);
747
17a854ef4412 - simplified the code handling bfc statements a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 746
diff changeset
955 elif (commentTextSimplified == "BFC CERTIFY NOCLIP")
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
956 return LDSpawn<LDBFC> (BFCStatement::NoClip);
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
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
959 if (tokens.size() > 2 and tokens[1] == "!LDFORGE")
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
960 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
961 // Handle LDForge-specific types, they're embedded into comments too
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
962 if (tokens[2] == "VERTEX")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
963 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
964 // Vertex (0 !LDFORGE VERTEX)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
965 CheckTokenCount (tokens, 7);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
966 CheckTokenNumbers (tokens, 3, 6);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
967
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
968 LDVertexPtr obj = LDSpawn<LDVertex>();
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
969 obj->setColor (LDColor::fromIndex (StringToNumber (tokens[3])));
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
970 obj->pos.apply ([&](Axis ax, double& value)
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
971 { value = tokens[4 + ax].toDouble(); });
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
972 return obj;
748
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
973 }
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
974 elif (tokens[2] == "OVERLAY")
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
975 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
976 CheckTokenCount (tokens, 9);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
977 CheckTokenNumbers (tokens, 5, 8);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
978
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
979 LDOverlayPtr obj = LDSpawn<LDOverlay>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
980 obj->setFileName (tokens[3]);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
981 obj->setCamera (tokens[4].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
982 obj->setX (tokens[5].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
983 obj->setY (tokens[6].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
984 obj->setWidth (tokens[7].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
985 obj->setHeight (tokens[8].toLong());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
986 return obj;
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 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
989
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
990 // Just a regular comment:
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
991 LDCommentPtr obj = LDSpawn<LDComment>();
746
893c43b337dd - don't simplify (aka remove extra whitespace from) comment texts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 744
diff changeset
992 obj->setText (commentText);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
993 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
994 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
995
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
996 case 1:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
997 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
998 // Subfile
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
999 CheckTokenCount (tokens, 15);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1000 CheckTokenNumbers (tokens, 1, 13);
655
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 // Try open the file. Disable g_loadingMainFile temporarily since we're
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1003 // not loading the main file now, but the subfile in question.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1004 bool tmp = g_loadingMainFile;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1005 g_loadingMainFile = false;
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1006 LDDocumentPtr load = GetDocument (tokens[14]);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1007 g_loadingMainFile = tmp;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1008
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1009 // 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
1010 // 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
1011 if (not load)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1012 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1013 LDErrorPtr obj = LDSpawn<LDError> (line, format ("Could not open %1", tokens[14]));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1014 obj->setFileReferenced (tokens[14]);
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
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1018 LDSubfilePtr obj = LDSpawn<LDSubfile>();
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1019 obj->setColor (LDColor::fromIndex (StringToNumber (tokens[1])));
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1020 obj->setPosition (ParseVertex (tokens, 2)); // 2 - 4
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1021
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1022 Matrix transform;
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 for (int i = 0; i < 9; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1025 transform[i] = tokens[i + 5].toDouble(); // 5 - 13
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 obj->setTransform (transform);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1028 obj->setFileInfo (load);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1029 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1030 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1031
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1032 case 2:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1033 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1034 CheckTokenCount (tokens, 8);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1035 CheckTokenNumbers (tokens, 1, 7);
655
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 // Line
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1038 LDLinePtr obj (LDSpawn<LDLine>());
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1039 obj->setColor (LDColor::fromIndex (StringToNumber (tokens[1])));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1040
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1041 for (int i = 0; i < 2; ++i)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1042 obj->setVertex (i, ParseVertex (tokens, 2 + (i * 3))); // 2 - 7
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1043
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1044 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1045 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1046
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1047 case 3:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1048 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1049 CheckTokenCount (tokens, 11);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1050 CheckTokenNumbers (tokens, 1, 10);
655
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 // Triangle
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1053 LDTrianglePtr obj (LDSpawn<LDTriangle>());
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1054 obj->setColor (LDColor::fromIndex (StringToNumber (tokens[1])));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1055
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1056 for (int i = 0; i < 3; ++i)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1057 obj->setVertex (i, ParseVertex (tokens, 2 + (i * 3))); // 2 - 10
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1058
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1059 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1060 }
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 case 4:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1063 case 5:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1064 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1065 CheckTokenCount (tokens, 14);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1066 CheckTokenNumbers (tokens, 1, 13);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1067
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1068 // Quadrilateral / Conditional line
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1069 LDObjectPtr obj;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1070
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1071 if (num == 4)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1072 obj = LDSpawn<LDQuad>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1073 else
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1074 obj = LDSpawn<LDCondLine>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1075
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1076 obj->setColor (LDColor::fromIndex (StringToNumber (tokens[1])));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1077
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1078 for (int i = 0; i < 4; ++i)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1079 obj->setVertex (i, ParseVertex (tokens, 2 + (i * 3))); // 2 - 13
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1080
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1081 return obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1082 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1083
748
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
1084 default:
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1085 throw QString ("Unknown line code number");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1086 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1087 }
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1088 catch (QString& e)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1089 {
748
8d4a9d03e246 - some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 747
diff changeset
1090 // Strange line we couldn't parse
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1091 return LDSpawn<LDError> (line, e);
655
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1095 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1096 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1097 LDDocumentPtr GetDocument (QString filename)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1098 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1099 // Try find the file in the list of loaded files
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1100 LDDocumentPtr doc = FindDocument (filename);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1101
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1102 // 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
1103 if (not doc)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1104 doc = OpenDocument (filename, true, true);
655
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 return doc;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1107 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1108
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 //
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1111 void LDDocument::reloadAllSubfiles()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1112 {
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1113 print ("Reloading subfiles of %1", getDisplayName());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1114
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1115 // Go through all objects in the current file and reload the subfiles
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1116 for (LDObjectPtr obj : objects())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1117 {
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 785
diff changeset
1118 if (obj->type() == OBJ_Subfile)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1119 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1120 LDSubfilePtr ref = obj.staticCast<LDSubfile>();
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1121 LDDocumentPtr fileInfo = GetDocument (ref->fileInfo()->name());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1122
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1123 if (fileInfo != null)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1124 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1125 ref->setFileInfo (fileInfo);
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1126 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1127 else
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1128 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1129 ref->replace (LDSpawn<LDError> (ref->asText(),
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1130 format ("Could not open %1", ref->fileInfo()->name())));
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1131 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1132 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1133
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1134 // Reparse gibberish files. It could be that they are invalid because
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1135 // 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
1136 if (obj->type() == OBJ_Error)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1137 obj->replace (ParseLine (obj.staticCast<LDError>()->contents()));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1138 }
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1139
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1140 m_needsReCache = true;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1141
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1142 if (self() == CurrentDocument())
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1143 g_win->buildObjList();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1144 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1145
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1146 // =============================================================================
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1147 // Adds an object at the end of the file.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1148 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1149 int LDDocument::addObject (LDObjectPtr obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1150 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1151 history()->add (new AddHistory (objects().size(), obj));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1152 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
1153 addKnownVertices (obj);
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
1154 obj->setDocument (self());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1155 g_win->R()->compileObject (obj);
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1156 requireBFCSweep();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1157 return getObjectCount() - 1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1158 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1159
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1160 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1161 //
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1162 void LDDocument::addObjects (const LDObjectList& objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1163 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1164 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
1165 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1166 if (obj != null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1167 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
1168 }
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1169
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1170 requireBFCSweep();
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1174 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1175 void LDDocument::insertObj (int pos, LDObjectPtr obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1176 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1177 history()->add (new AddHistory (pos, obj));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1178 m_objects.insert (pos, obj);
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
1179 obj->setDocument (self());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1180 g_win->R()->compileObject (obj);
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1181 requireBFCSweep();
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1182
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1183 #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
1184 if (not isImplicit())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1185 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
1186 #endif
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
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 //
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1191 void LDDocument::addKnownVertices (LDObjectPtr obj)
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1192 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1193 auto it = m_objectVertices.find (obj);
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1194
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1195 if (it == m_objectVertices.end())
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1196 it = m_objectVertices.insert (obj, QVector<Vertex>());
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1197 else
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1198 it->clear();
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1199
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1200 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
1201 needVertexMerge();
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1202 }
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1203
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1204 // =============================================================================
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1205 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1206 void LDDocument::forgetObject (LDObjectPtr obj)
655
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 int idx = obj->lineNumber();
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 761
diff changeset
1209 obj->deselect();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1210 assert (m_objects[idx] == obj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1211
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1212 if (not isImplicit() and not (flags() & DOCF_IsBeingDestroyed))
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1213 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1214 history()->add (new DelHistory (idx, obj));
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1215 m_objectVertices.remove (obj);
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
1216 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1217
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1218 // We only need a sweep if we got rid of a BFC object, no processing is required if a polygon
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1219 // just got removed.
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1220 if (obj->type() == OBJ_BFC)
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1221 requireBFCSweep();
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1222
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1223 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
1224 obj->setDocument (LDDocumentPtr());
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1228 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1229 bool IsSafeToCloseAll()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1230 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1231 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
1232 {
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
1233 if (not f->isSafeToClose())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1234 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
1235 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1236
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1237 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1238 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1239
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1240 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1241 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1242 void LDDocument::setObject (int idx, LDObjectPtr obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1243 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1244 assert (idx >= 0 and idx < m_objects.size());
655
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 // 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
1247 if (not m_history->isIgnoring())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1248 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1249 QString oldcode = getObject (idx)->asText();
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1250 QString newcode = obj->asText();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1251 *m_history << new EditHistory (idx, oldcode, newcode);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1252 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1253
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1254 m_objectVertices.remove (m_objects[idx]);
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 761
diff changeset
1255 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
1256 m_objects[idx]->setDocument (LDDocumentPtr());
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
1257 obj->setDocument (self());
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1258 addKnownVertices (obj);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1259 g_win->R()->compileObject (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1260 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
1261 needVertexMerge();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1262 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1263
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1264 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1265 //
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1266 LDObjectPtr LDDocument::getObject (int pos)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1267 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1268 if (m_objects.size() <= pos)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1269 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1270
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1271 sweepBFC();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1272 return m_objects[pos];
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1273 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1274
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1275 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1276 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1277 int LDDocument::getObjectCount() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1278 {
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1279 return m_objects.size();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1280 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1281
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1282 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1283 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1284 bool LDDocument::hasUnsavedChanges() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1285 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1286 return not isImplicit() and history()->position() != savePosition();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1287 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1288
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1289 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1290 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1291 QString LDDocument::getDisplayName()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1292 {
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
1293 if (not name().isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1294 return name();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1295
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
1296 if (not defaultName().isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1297 return "[" + defaultName() + "]";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1298
734
cdce1cbaac7e - <anonymous> -> untitled
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
1299 return tr ("untitled");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1300 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1301
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1302 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1303 //
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1304 void LDDocument::initializeCachedData()
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1305 {
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1306 if (m_needsReCache)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1307 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1308 m_vertices.clear();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1309
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1310 for (LDObjectPtr obj : inlineContents (true, true))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1311 {
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1312 if (obj->type() == OBJ_Subfile)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1313 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1314 print ("Warning: unable to inline %1 into %2",
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1315 obj.staticCast<LDSubfile>()->fileInfo()->getDisplayName(),
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1316 getDisplayName());
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1317 continue;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1318 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1319
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1320 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
1321
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1322 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
1323 {
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1324 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
1325 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
1326 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1327 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1328
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1329 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
1330 }
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1331
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1332 if (m_verticesOutdated)
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1333 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1334 m_objectVertices.clear();
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1335
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1336 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
1337 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
1338
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1339 mergeVertices();
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1340 m_verticesOutdated = false;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1341 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1342
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1343 if (m_needVertexMerge)
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1344 mergeVertices();
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1345 }
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1346
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1347 // =============================================================================
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1348 //
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1349 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
1350 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1351 m_vertices.clear();
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1352
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1353 for (QVector<Vertex> const& verts : m_objectVertices)
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1354 m_vertices << verts;
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1355
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1356 RemoveDuplicates (m_vertices);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1357 m_needVertexMerge = false;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1358 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1359
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1360 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1361 //
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1362 QList<LDPolygon> LDDocument::inlinePolygons()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1363 {
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1364 initializeCachedData();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1365 return polygonData();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1366 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1367
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1368 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1369 // -----------------------------------------------------------------------------
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1370 LDObjectList LDDocument::inlineContents (bool deep, bool renderinline)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1371 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1372 // Possibly substitute with logoed studs:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1373 // stud.dat -> stud-logo.dat
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1374 // stud2.dat -> stud-logo2.dat
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
1375 if (cfg::UseLogoStuds and renderinline)
655
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 // Ensure logoed studs are loaded first
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1378 LoadLogoStuds();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1379
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1380 if (name() == "stud.dat" and g_logoedStud != null)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1381 return g_logoedStud->inlineContents (deep, renderinline);
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1382 elif (name() == "stud2.dat" and g_logoedStud2 != null)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1383 return g_logoedStud2->inlineContents (deep, renderinline);
655
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 LDObjectList objs, objcache;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1387
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1388 for (LDObjectPtr obj : objects())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1389 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1390 // Skip those without scemantic meaning
714
b4a990f59a5e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 713 662
diff changeset
1391 if (not obj->isScemantic())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1392 continue;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1393
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1394 // 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
1395 // just add it into the objects normally. Yay, recursion!
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1396 if (deep == true and obj->type() == OBJ_Subfile)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1397 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1398 for (LDObjectPtr otherobj : obj.staticCast<LDSubfile>()->inlineContents (deep, renderinline))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1399 objs << otherobj;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1400 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1401 else
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1402 objs << obj->createCopy();
655
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1405 return objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1406 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1407
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1408 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1409 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1410 LDDocumentPtr LDDocument::current()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1411 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1412 return g_currentDocument;
655
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1415 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1416 // 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
1417 // was an operation completely unheard of. ;)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1418 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1419 // 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
1420 // =============================================================================
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1421 void LDDocument::setCurrent (LDDocumentPtr f)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1422 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1423 // 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
1424 // current.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1425 if (f != null and f->isImplicit())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1426 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1427
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1428 g_currentDocument = f;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1429
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1430 if (g_win and f)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1431 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1432 // A ton of stuff needs to be updated
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1433 g_win->updateDocumentListItem (f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1434 g_win->buildObjList();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1435 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
1436 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
1437 g_win->R()->compiler()->needMerge();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1438 print ("Changed file to %1", f->getDisplayName());
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1442 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1443 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1444 int LDDocument::countExplicitFiles()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1445 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1446 return g_explicitDocuments.size();
655
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 // 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
1451 // a new file over it.
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 void LDDocument::closeInitialFile()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1454 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1455 if (g_explicitDocuments.size() == 2 and
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1456 g_explicitDocuments[0]->name().isEmpty() and
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1457 not g_explicitDocuments[1]->name().isEmpty() and
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1458 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
1459 {
883
69b8adc9a669 - fixed: due to a shared pointer called via reference called dismiss() in LDDocument::closeInitialFile, this could cause LDDocuments to delete themselves in setImplicit(true) as no shared pointers were left inside closeInitialFile to keep the refcount up.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
1460 LDDocumentPtr filetoclose = g_explicitDocuments.first();
69b8adc9a669 - fixed: due to a shared pointer called via reference called dismiss() in LDDocument::closeInitialFile, this could cause LDDocuments to delete themselves in setImplicit(true) as no shared pointers were left inside closeInitialFile to keep the refcount up.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
1461 filetoclose->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
1462 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1463 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1464
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1465 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1466 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1467 void LoadLogoStuds()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1468 {
877
7c50b61ad5b6 - fixed infinite recursion when loading logoed studs
Teemu Piippo <crimsondusk64@gmail.com>
parents: 872
diff changeset
1469 if (g_loadingLogoedStuds or (g_logoedStud and g_logoedStud2))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1470 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1471
877
7c50b61ad5b6 - fixed infinite recursion when loading logoed studs
Teemu Piippo <crimsondusk64@gmail.com>
parents: 872
diff changeset
1472 g_loadingLogoedStuds = true;
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1473 g_logoedStud = OpenDocument ("stud-logo.dat", true, true);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1474 g_logoedStud2 = OpenDocument ("stud2-logo.dat", true, true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1475 print (LDDocument::tr ("Logoed studs loaded.\n"));
877
7c50b61ad5b6 - fixed infinite recursion when loading logoed studs
Teemu Piippo <crimsondusk64@gmail.com>
parents: 872
diff changeset
1476 g_loadingLogoedStuds = false;
655
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
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 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1481 void LDDocument::addToSelection (LDObjectPtr obj) // [protected]
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1482 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1483 if (obj->isSelected())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1484 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1485
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1486 assert (obj->document() == self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1487 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
1488 g_win->R()->compileObject (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1489 obj->setSelected (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1490 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1491
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1492 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1493 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1494 void LDDocument::removeFromSelection (LDObjectPtr obj) // [protected]
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1495 {
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
1496 if (not obj->isSelected())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1497 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1498
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 782
diff changeset
1499 assert (obj->document() == self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1500 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
1501 g_win->R()->compileObject (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1502 obj->setSelected (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1503 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1504
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1505 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1506 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1507 void LDDocument::clearSelection()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1508 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1509 for (LDObjectPtr obj : m_sel)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1510 removeFromSelection (obj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1511
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1512 assert (m_sel.isEmpty());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1513 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1514
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1515 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1516 //
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1517 const LDObjectList& LDDocument::getSelection()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1518 {
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1519 sweepBFC();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1520 return m_sel;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1521 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1522
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1523 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1524 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1525 void LDDocument::swapObjects (LDObjectPtr one, LDObjectPtr other)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1526 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1527 int a = m_objects.indexOf (one);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1528 int b = m_objects.indexOf (other);
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 836
diff changeset
1529 assert (a != b and a != -1 and b != -1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1530 m_objects[b] = one;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1531 m_objects[a] = other;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1532 addToHistory (new SwapHistory (one->id(), other->id()));
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1533 requireBFCSweep();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1534 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1535
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1536 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1537 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 788
diff changeset
1538 QString LDDocument::shortenName (QString a) // [static]
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1539 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1540 QString shortname = Basename (a);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1541 QString topdirname = Basename (Dirname (a));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1542
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1543 if (g_specialSubdirectories.contains (topdirname))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1544 shortname.prepend (topdirname + "\\");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1545
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1546 return shortname;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1547 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1548
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1549 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1550 //
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1551 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
1552 {
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1553 initializeCachedData();
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1554 return m_vertices;
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
1555 }
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1556
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1557 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
1558 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1559 m_verticesOutdated = true;
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1560 }
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1561
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1562 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
1563 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
1564 m_needVertexMerge = true;
835
268413885cb1 - reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 834
diff changeset
1565 }
891
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1566
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1567 //
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1568 // Sweeps through the file and adjusts the block windings of all objects.
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1569 //
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1570 void LDDocument::sweepBFC()
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1571 {
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1572 if (not m_needBFCSweep)
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1573 return;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1574
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1575 QTime t0 (QTime::currentTime());
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1576 Winding winding (Winding::None);
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1577 Winding preclip (winding);
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1578 LDBFCPtr bfc;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1579 bool invertnext (false);
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1580
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1581 for (LDObjectPtr obj : m_objects)
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1582 {
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1583 if (obj->type() == OBJ_BFC)
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1584 {
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1585 switch (obj.staticCast<LDBFC>()->statement())
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1586 {
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1587 case BFCStatement::CCW:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1588 case BFCStatement::CertifyCCW:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1589 winding = Winding::CCW;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1590 break;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1591
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1592 case BFCStatement::CW:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1593 case BFCStatement::CertifyCW:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1594 winding = Winding::CW;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1595
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1596 case BFCStatement::NoCertify:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1597 winding = Winding::None;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1598 break;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1599
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1600 case BFCStatement::NoClip:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1601 preclip = winding;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1602 winding = Winding::None;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1603 break;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1604
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1605 case BFCStatement::InvertNext:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1606 invertnext = true;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1607 break;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1608
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1609 case BFCStatement::Clip:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1610 winding = preclip;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1611 break;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1612
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1613 default:
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1614 break;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1615 }
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1616 }
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1617 else
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1618 {
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1619 Winding objwinding (winding);
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1620
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1621 if (invertnext)
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1622 {
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1623 invertWinding (objwinding);
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1624 invertnext = false;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1625 }
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1626
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1627 print ("%1: BFC sweep: set winding of %2 to %3", getDisplayName(), obj->id(), int (objwinding));
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1628 obj->setBlockWinding (objwinding);
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1629 }
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1630 }
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1631
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1632 print ("%1: BFC sweep done in %2ms", getDisplayName(), t0.msecsTo (QTime::currentTime()));
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1633 m_needBFCSweep = false;
00d76b281021 - re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
1634 }

mercurial