src/document.cc

Mon, 13 Jan 2014 10:07:39 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 13 Jan 2014 10:07:39 +0200
changeset 622
622c49e60348
parent 619
8bfe34c6ab1a
permissions
-rw-r--r--

- refactoring

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

mercurial