src/document.cc

Fri, 10 Jan 2014 15:48:40 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 10 Jan 2014 15:48:40 +0200
changeset 617
f5059d144438
parent 613
2d01590da286
child 619
8bfe34c6ab1a
permissions
-rw-r--r--

- added a type alias LDObjectList

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"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "moc_document.cpp"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 cfg (String, io_ldpath, "");
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 cfg (List, io_recentfiles, {});
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 extern_cfg (String, net_downloadpath);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 extern_cfg (Bool, gl_logostuds);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 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
39 static const int g_maxRecentFiles = 10;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 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
41 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
42 static LDDocumentPointer g_logoedStud2 = null;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 LDDocument* LDDocument::m_curdoc = null;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
588
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
46 const QStringList g_specialSubdirectories ({ "s", "48", "8" });
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
47
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 // =============================================================================
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 namespace LDPaths
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
51 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
52 static QString pathError;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 struct
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
55 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
56 QString LDConfigPath;
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
57 QString partsPath, primsPath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 } pathInfo;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 void initPaths()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
61 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
62 if (!tryConfigure (io_ldpath))
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
63 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
64 LDrawPathDialog dlg (false);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 if (!dlg.exec())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 exit (0);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 io_ldpath = dlg.filename();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 }
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
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
73 bool tryConfigure (QString path)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
74 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
75 QDir dir;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 if (!dir.cd (path))
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
78 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
79 pathError = "Directory does not exist.";
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 return false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 }
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 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 QStringList contents = dir.entryList (mustHave);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 if (contents.size() != mustHave.size())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
87 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
88 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
89 return false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
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 pathInfo.partsPath = fmt ("%1" DIRSLASH "parts", path);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 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
94 pathInfo.primsPath = fmt ("%1" DIRSLASH "p", path);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 return true;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 }
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 // Accessors
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
100 QString getError()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
101 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
102 return pathError;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
105 QString ldconfig()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
106 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
107 return pathInfo.LDConfigPath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
110 QString prims()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
111 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
112 return pathInfo.primsPath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
115 QString parts()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
116 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
117 return pathInfo.partsPath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 }
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 LDDocument::LDDocument()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
124 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
125 setImplicit (true);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 setSavePosition (-1);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 setListItem (null);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 setHistory (new History);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 m_History->setFile (this);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131
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 LDDocument::~LDDocument()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
135 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
136 // 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
137 // 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
138 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
139
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 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
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 // Clear everything from the model
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 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
144 obj->deleteSelf();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 // Clear the cache as well
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 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
148 obj->deleteSelf();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 delete m_History;
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 // 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
153 // file as something else.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 if (this == getCurrentDocument())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
155 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
156 bool found = false;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 // 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
159 // 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
160 for (LDDocument* file : g_loadedFiles)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
161 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
162 if (!file->isImplicit())
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
163 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
164 LDDocument::setCurrent (file);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 found = true;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 break;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 if (!found)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 newFile();
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
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
174 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
175 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
176 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
177 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
178
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 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
180 log ("Closed %1", getName());
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
185 LDDocument* findDocument (QString name)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
186 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
187 for (LDDocument * file : g_loadedFiles)
577
17a88e2470c9 removed some debug code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 576
diff changeset
188 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
189 return file;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 return null;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 }
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 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
196 QString dirname (QString path)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
197 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
198 long lastpos = path.lastIndexOf (DIRSLASH);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 if (lastpos > 0)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 return path.left (lastpos);
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 #ifndef _WIN32
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 if (path[0] == DIRSLASH_CHAR)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 return DIRSLASH;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 #endif // _WIN32
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 return "";
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 }
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 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
213 QString basename (QString path)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
214 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
215 long lastpos = path.lastIndexOf (DIRSLASH);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 if (lastpos != -1)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 return path.mid (lastpos + 1);
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 return path;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 }
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 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 // -----------------------------------------------------------------------------
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
225 static QString findLDrawFilePath (QString relpath, bool subdirs)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
226 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
227 QString fullPath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 // 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
230 // 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
231 // forward-slashes as directory separators.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 #ifndef WIN32
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 relpath.replace ("\\", "/");
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 #endif // WIN32
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235
579
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
236 // 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
237 // 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
238 QString reltop = basename (dirname (relpath));
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
239
579
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
240 for (LDDocument* doc : g_loadedFiles)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
241 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
242 if (doc->getFullPath().isEmpty())
579
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
243 continue;
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
244
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
245 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
246 QFile f (partpath);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
248 if (f.exists())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
249 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
250 // 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
251 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
252
588
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
253 bool bogus = false;
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
254
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
255 for (QString s : g_specialSubdirectories)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
256 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
257 if ((proptop == s && reltop != s) || (reltop == s && proptop != s))
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
258 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
259 bogus = true;
588
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
260 break;
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
261 }
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
262 }
581
c57ddcaf1b58 - fixed configuration dialog not accepting values past 99.99 for grid angles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 579
diff changeset
263
c57ddcaf1b58 - fixed configuration dialog not accepting values past 99.99 for grid angles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 579
diff changeset
264 if (!bogus)
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
265 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
266 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
269 if (QFile::exists (relpath))
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
270 return relpath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 // Try with just the LDraw path first
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 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
274
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
275 if (QFile::exists (fullPath))
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
276 return fullPath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 if (subdirs)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
279 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
280 // 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
281 // 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
282 for (const QString& topdir : initlist<QString> ({ io_ldpath, net_downloadpath }))
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
283 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
284 for (const QString& subdir : initlist<QString> ({ "parts", "p" }))
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
285 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
286 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
287
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
288 if (QFile::exists (fullPath))
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
289 return fullPath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 }
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 // Did not find the file.
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
295 return "";
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
296 }
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
297
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
298 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
299 {
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
300 log ("Opening %1...\n", relpath);
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
301 QString path = findLDrawFilePath (relpath, subdirs);
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 if (pathpointer != null)
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
304 *pathpointer = path;
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 (path.isEmpty())
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
307 return null;
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 QFile* fp = new QFile (path);
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
310
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
311 if (fp->open (QIODevice::ReadOnly))
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
312 return fp;
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 fp->deleteLater();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 return null;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318 // =============================================================================
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 void LDFileLoader::start()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
321 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
322 setDone (false);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 setProgress (0);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 setAborted (false);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 if (isOnForeground())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
327 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
328 g_aborted = false;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 // 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
331 // 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
332 // 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
333 // block.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 dlg = new OpenProgressDialog (g_win);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 dlg->setNumLines (getLines().size());
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 dlg->setModal (true);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 dlg->show();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 // 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
340 connect (this, SIGNAL (workDone()), dlg, SLOT (accept()));
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 connect (dlg, SIGNAL (rejected()), this, SLOT (abort()));
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 else
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 dlg = null;
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 // Begin working
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 work (0);
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 // =============================================================================
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 void LDFileLoader::work (int i)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
353 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
354 // 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
355 if (isAborted())
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 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
358 obj->deleteSelf();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 m_Objects.clear();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 setDone (true);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 // Parse up to 300 lines per iteration
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 int max = i + 300;
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 for (; i < max && i < (int) getLines().size(); ++i)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
369 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
370 QString line = getLines()[i];
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 // Trim the trailing newline
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 QChar c;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374
613
2d01590da286 - use QCoreApplication::applicationDirPath instead of a custom hack to get the application path
Santeri Piippo <crimsondusk64@gmail.com>
parents: 609
diff changeset
375 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
376 line.chop (1);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 LDObject* obj = parseLine (line);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 // Check for parse errors and warn about tthem
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
381 if (obj->getType() == LDObject::EError)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
382 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
383 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
384
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 if (getWarnings() != null)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 (*getWarnings())++;
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 m_Objects << obj;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 setProgress (i);
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 // 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
393 if (isOnForeground())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 dlg->updateProgress (i);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 // 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
398 if (i >= ((int) getLines().size()) - 1)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
399 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
400 emit workDone();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 setDone (true);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 // Otherwise, continue, by recursing back.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 if (!isDone())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
407 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
408 // 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
409 // 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
410 // 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
411 // meta-object system.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 //
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 // 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
414 // 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
415 // 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
416 // 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
417 // 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
418 if (isOnForeground())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 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
420 else
582
5510207c2396 - OH MY FORKING GOD
Santeri Piippo <crimsondusk64@gmail.com>
parents: 581
diff changeset
421 work (i);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424
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 void LDFileLoader::abort()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
428 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
429 setAborted (true);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 if (isOnForeground())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 g_aborted = true;
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 // -----------------------------------------------------------------------------
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
437 LDObjectList loadFileContents (QFile* fp, int* numWarnings, bool* ok)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
438 {
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
439 QStringList lines;
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
440 LDObjectList objs;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 if (numWarnings)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 *numWarnings = 0;
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 // Read in the lines
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
446 while (fp->atEnd() == false)
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
447 lines << QString::fromUtf8 (fp->readLine());
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 LDFileLoader* loader = new LDFileLoader;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450 loader->setWarnings (numWarnings);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 loader->setLines (lines);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 loader->setOnForeground (g_loadingMainFile);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 loader->start();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 // 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
456 // 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
457 // 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
458 // 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
459 while (loader->isDone() == false)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 qApp->processEvents();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 // 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
463 if (ok)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 *ok = !loader->isAborted();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 objs = loader->getObjects();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 return objs;
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
472 LDDocument* openDocument (QString path, bool search)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
473 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
474 // 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
475 // 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
476 // 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
477 QFile* fp;
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
478 QString fullpath;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 if (search)
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
481 fp = openLDrawFile (path.toLower(), true, &fullpath);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482 else
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
483 {
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
484 fp = new QFile (path);
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
485 fullpath = path;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
487 if (!fp->open (QIODevice::ReadOnly))
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
488 {
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
489 delete fp;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 return null;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
494 if (!fp)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495 return null;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497 LDDocument* load = new LDDocument;
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
498 load->setFullPath (fullpath);
579
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
499 load->setName (LDDocument::shortenName (load->getFullPath()));
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
500 dlog ("name: %1 (%2)", load->getName(), load->getFullPath());
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
501 g_loadedFiles << load;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502
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
503 // 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
504 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
505
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506 int numWarnings;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507 bool ok;
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
508 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
509 fp->close();
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
510 fp->deleteLater();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
511
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
512 if (!ok)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
513 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
514 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
515 delete load;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 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
517 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518
579
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
519 load->addObjects (objs);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 if (g_loadingMainFile)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
522 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
523 LDDocument::setCurrent (load);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 g_win->R()->setFile (load);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525 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
526 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527
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
528 load->getHistory()->setIgnoring (false);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529 return load;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
530 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532 // =============================================================================
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 bool LDDocument::isSafeToClose()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
535 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
536 typedef QMessageBox msgbox;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 setlocale (LC_ALL, "C");
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 // 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
540 if (hasUnsavedChanges())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
541 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
542 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
543 (getName().length() > 0) ? getName() : tr ("<anonymous>"));
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544
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
545 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
546 (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
547
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548 switch (button)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
549 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
550 case msgbox::Yes:
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
551 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
552 // 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
553 if (getName().length() == 0)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
554 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
555 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
556 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
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 if (newpath.length() == 0)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
559 return false;
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 setName (newpath);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 }
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 if (!save())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
565 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
566 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
567 getName(), strerror (errno));
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
568
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
569 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
570 (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
571 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
572 return false;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 }
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
575 } break;
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 case msgbox::Cancel:
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 return false;
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 default:
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 break;
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 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
584
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585 return true;
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 // =============================================================================
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 void closeAll()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
591 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
592 // 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
593 QList<LDDocument*> files = g_loadedFiles;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594
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
595 for (LDDocument* file : files)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596 delete file;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599 // =============================================================================
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 void newFile()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
602 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
603 // 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
604 LDDocument* f = new LDDocument;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
605 f->setName ("");
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
606 f->setImplicit (false);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
607 g_loadedFiles << f;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
608 LDDocument::setCurrent (f);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609 LDDocument::closeInitialFile();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
610 g_win->R()->setFile (f);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
611 g_win->doFullRefresh();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612 g_win->updateTitle();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613 g_win->updateActions();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
615
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
618 void addRecentFile (QString path)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
619 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
620 auto& rfiles = io_recentfiles;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621 int idx = rfiles.indexOf (path);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
623 // 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
624 if (idx != -1)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
625 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
626 if (rfiles.size() == 1)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627 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
628
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
629 // Pop it out.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630 rfiles.removeAt (idx);
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633 // 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
634 while (rfiles.size() > (g_maxRecentFiles - 1))
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 rfiles.removeAt (0);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
637 // Add the file
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
638 rfiles << path;
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 Config::save();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641 g_win->updateRecentFilesMenu();
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 // 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
646 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
647 void openMainFile (QString path)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
648 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
649 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
650
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
651 // 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
652 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
653 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
654
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 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
656 {
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 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
658 {
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 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
660 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
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 }
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
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
664 // 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
665 // 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
666 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
667 {
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 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
669 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
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
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
672 LDDocument* file = openDocument (path, false);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
673
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
674 if (!file)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
675 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
676 // 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
677 // closed everything prior.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
678 newFile();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
679
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
680 if (!g_aborted)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
681 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
682 // Tell the user loading failed.
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
683 setlocale (LC_ALL, "C");
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
684 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
685 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
687 g_loadingMainFile = false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
688 return;
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
691 file->setImplicit (false);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
692
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
693 // 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
694 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
695 {
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 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
697 { 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
698 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
699
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 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
701 }
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 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
704 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
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
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
707 // 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
708 // (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
709 LDDocument::closeInitialFile();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
710
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
711 // Rebuild the object tree view now.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
712 LDDocument::setCurrent (file);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713 g_win->doFullRefresh();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
714
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
715 // Add it to the recent files list.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
716 addRecentFile (path);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
717 g_loadingMainFile = false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
718 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
719
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
720 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
722 bool LDDocument::save (QString savepath)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
723 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
724 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
725 savepath = getFullPath();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
726
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
727 QFile f (savepath);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
729 if (!f.open (QIODevice::WriteOnly))
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
730 return false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
731
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 // 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
733 // 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
734 LDObject* nameObject = getObject (1);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
736 if (!isImplicit() && nameObject != null && nameObject->getType() == LDObject::EComment)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
737 {
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
738 LDComment* nameComment = static_cast<LDComment*> (nameObject);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
739
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
740 if (nameComment->text.left (6) == "Name: ")
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
741 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
742 QString newname = shortenName (savepath);
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
743 nameComment->text = fmt ("Name: %1", newname);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
744 g_win->buildObjList();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
745 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
746 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
747
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
748 // 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
749 // 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
750 for (LDObject* obj : getObjects())
609
a8dc74a809c6 - removed the File class in favor of QFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 608
diff changeset
751 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
752
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
753 // File is saved, now clean up.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
754 f.close();
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 // 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
757 setSavePosition (getHistory()->getPosition());
575
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
758 setFullPath (savepath);
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
759 setName (shortenName (savepath));
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
760
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
761 g_win->updateDocumentListItem (this);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
762 g_win->updateTitle();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
763 return true;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
764 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
765
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
766 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
767 // -----------------------------------------------------------------------------
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
768 class LDParseError : public std::exception
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
769 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
770 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
771 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
772
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
773 public:
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
774 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
775
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
776 const char* what() const throw()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
777 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
778 return getError().toLocal8Bit().constData();
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
779 }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
780 };
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
781
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 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
784 void checkTokenCount (QString line, const QStringList& tokens, int num)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
785 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
786 if (tokens.size() != num)
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
787 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
788 }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
789
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
790 // =============================================================================
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
791 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
792 void checkTokenNumbers (QString line, const QStringList& tokens, int min, int max)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
793 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
794 bool ok;
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
795
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
796 // 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
797 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
798
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
799 for (int i = min; i <= max; ++i)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
800 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
801 tokens[i].toDouble (&ok);
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
802
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
803 if (!ok && !scient.exactMatch (tokens[i]))
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
804 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
805 }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
806 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
807
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
808 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
809 // -----------------------------------------------------------------------------
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
810 static Vertex parseVertex (QStringList& s, const int n)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
811 {
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
812 Vertex v;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
813
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814 for_axes (ax)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
815 v[ax] = s[n + ax].toDouble();
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 return v;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818 }
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 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 // 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
822 // 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
823 // 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
824 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
825 LDObject* parseLine (QString line)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
826 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
827 try
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
828 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
829 QStringList tokens = line.split (" ", QString::SkipEmptyParts);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
830
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
831 if (tokens.size() <= 0)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
832 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
833 // 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
834 return new LDEmpty;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
835 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
836
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
837 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
838 throw LDParseError (line, "Illogical line code");
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
839
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
840 int num = tokens[0][0].digitValue();
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
841
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
842 switch (num)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
843 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
844 case 0:
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
845 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
846 // Comment
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
847 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
848
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
849 // Handle BFC statements
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
850 if (tokens.size() > 2 && tokens[1] == "BFC")
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
851 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
852 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
853 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
854 return new LDBFC ( (LDBFC::Type) i);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
855
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
856 // 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
857 // 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
858 // 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
859 struct
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
860 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
861 QString a;
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
862 LDBFC::Type b;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
863 } BFCData[] =
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
864 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
865 { "INVERTNEXT", LDBFC::InvertNext },
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
866 { "NOCLIP", LDBFC::NoClip },
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
867 { "CLIP", LDBFC::Clip }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
868 };
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
869
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
870 for (const auto& i : BFCData)
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
871 if (comm == "BFC CERTIFY " + i.a)
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
872 return new LDBFC (i.b);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
873 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
874
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
875 if (tokens.size() > 2 && tokens[1] == "!LDFORGE")
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
876 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
877 // 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
878 if (tokens[2] == "VERTEX")
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 // Vertex (0 !LDFORGE VERTEX)
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
881 checkTokenCount (line, tokens, 7);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
882 checkTokenNumbers (line, tokens, 3, 6);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
883
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
884 LDVertex* obj = new LDVertex;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
885 obj->setColor (tokens[3].toLong());
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 for_axes (ax)
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
888 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
889
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
890 return obj;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
891 } elif (tokens[2] == "OVERLAY")
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
892 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
893 checkTokenCount (line, tokens, 9);;
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
894 checkTokenNumbers (line, tokens, 5, 8);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
895
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
896 LDOverlay* obj = new LDOverlay;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
897 obj->setFileName (tokens[3]);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
898 obj->setCamera (tokens[4].toLong());
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
899 obj->setX (tokens[5].toLong());
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
900 obj->setY (tokens[6].toLong());
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
901 obj->setWidth (tokens[7].toLong());
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
902 obj->setHeight (tokens[8].toLong());
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
903 return obj;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
904 }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
905 }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
906
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
907 // Just a regular comment:
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
908 LDComment* obj = new LDComment;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
909 obj->text = comm;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
910 return obj;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
911 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
912
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
913 case 1:
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
914 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
915 // Subfile
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
916 checkTokenCount (line, tokens, 15);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
917 checkTokenNumbers (line, tokens, 1, 13);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
918
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
919 // 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
920 // 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
921 bool tmp = g_loadingMainFile;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
922 g_loadingMainFile = false;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
923 LDDocument* load = getDocument (tokens[14]);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
924 g_loadingMainFile = tmp;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
925
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
926 // 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
927 // 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
928 if (!load)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
929 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
930 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
931 obj->setFileReferenced (tokens[14]);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
932 return obj;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
933 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
934
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
935 LDSubfile* obj = new LDSubfile;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
936 obj->setColor (tokens[1].toLong());
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
937 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
938
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
939 Matrix transform;
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
940
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
941 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
942 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
943
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
944 obj->setTransform (transform);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
945 obj->setFileInfo (load);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
946 return obj;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
947 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
948
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
949 case 2:
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
950 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
951 checkTokenCount (line, tokens, 8);
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
952 checkTokenNumbers (line, tokens, 1, 7);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
953
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
954 // Line
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
955 LDLine* obj = new LDLine;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
956 obj->setColor (tokens[1].toLong());
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
957
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
958 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
959 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
960
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
961 return obj;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
962 }
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 case 3:
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
965 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
966 checkTokenCount (line, tokens, 11);
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
967 checkTokenNumbers (line, tokens, 1, 10);
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
968
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
969 // Triangle
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
970 LDTriangle* obj = new LDTriangle;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
971 obj->setColor (tokens[1].toLong());
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
972
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
973 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
974 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
975
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
976 return obj;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
977 }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
978
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
979 case 4:
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
980 case 5:
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
981 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
982 checkTokenCount (line, tokens, 14);
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
983 checkTokenNumbers (line, tokens, 1, 13);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
984
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
985 // Quadrilateral / Conditional line
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
986 LDObject* obj;
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 if (num == 4)
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
989 obj = new LDQuad;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
990 else
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
991 obj = new LDCondLine;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
992
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
993 obj->setColor (tokens[1].toLong());
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
994
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
995 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
996 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
997
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
998 return obj;
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
999 }
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 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
1002 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
1003 }
572
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
1004 }
5a08d67ed770 - code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
1005 catch (LDParseError& e)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1006 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1007 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
1008 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1009 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1010
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 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
1013 LDDocument* getDocument (QString filename)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1014 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1015 // 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
1016 LDDocument* doc = findDocument (filename);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1017
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1018 // 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
1019 if (!doc)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1020 doc = openDocument (filename, true);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1021
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1022 return doc;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1023 }
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 // =============================================================================
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 void reloadAllSubfiles()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1028 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1029 if (!getCurrentDocument())
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1030 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1031
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1032 g_loadedFiles.clear();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1033 g_loadedFiles << getCurrentDocument();
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 // 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
1036 for (LDObject* obj : getCurrentDocument()->getObjects())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1037 {
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
1038 if (obj->getType() == LDObject::ESubfile)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1039 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1040 LDSubfile* ref = static_cast<LDSubfile*> (obj);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1041 LDDocument* fileInfo = getDocument (ref->getFileInfo()->getName());
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1042
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1043 if (fileInfo)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1044 ref->setFileInfo (fileInfo);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1045 else
579
4e140de264d2 further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents: 577
diff changeset
1046 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
1047 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1048
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1049 // 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
1050 // of loading errors. Circumstances may be different now.
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
1051 if (obj->getType() == LDObject::EError)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1052 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
1053 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1054 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1055
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 int LDDocument::addObject (LDObject* obj)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1059 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1060 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
1061 m_Objects << obj;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1062
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
1063 if (obj->getType() == LDObject::EVertex)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1064 m_Vertices << obj;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1065
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
1066 #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
1067 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
1068 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
1069 #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
1070
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1071 obj->setFile (this);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1072 return getObjectCount() - 1;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1073 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1074
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1075 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1076 // -----------------------------------------------------------------------------
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
1077 void LDDocument::addObjects (const LDObjectList objs)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1078 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1079 for (LDObject* obj : objs)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1080 if (obj)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1081 addObject (obj);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1082 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1083
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1084 // =============================================================================
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 void LDDocument::insertObj (int pos, LDObject* obj)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1087 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1088 getHistory()->add (new AddHistory (pos, obj));
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1089 m_Objects.insert (pos, obj);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1090 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
1091
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
1092 #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
1093 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
1094 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
1095 #endif
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1096 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1097
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1098 // =============================================================================
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 void LDDocument::forgetObject (LDObject* obj)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1101 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1102 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
1103 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
1104 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
1105
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 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
1107 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
1108
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1109 m_Objects.removeAt (idx);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1110 obj->setFile (null);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1111 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1112
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1113 // =============================================================================
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 bool safeToCloseAll()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1116 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1117 for (LDDocument* f : g_loadedFiles)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1118 if (!f->isSafeToClose())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1119 return false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1120
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1121 return true;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1122 }
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 // =============================================================================
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 void LDDocument::setObject (int idx, LDObject* obj)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1127 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1128 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
1129
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1130 // 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
1131 if (!m_History->isIgnoring())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1132 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
1133 QString oldcode = getObject (idx)->raw();
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
1134 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
1135 *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
1136 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1137
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
1138 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
1139 m_Objects[idx]->setFile (null);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1140 obj->setFile (this);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1141 m_Objects[idx] = obj;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1142 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1143
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1144 // =============================================================================
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
1145 // 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
1146 // -----------------------------------------------------------------------------
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
1147 void LDDocument::closeUnused()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1148 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1149 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
1150 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
1151 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
1152 }
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
1153
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
1154 // =============================================================================
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 // -----------------------------------------------------------------------------
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1156 LDObject* LDDocument::getObject (int pos) const
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1157 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1158 if (m_Objects.size() <= pos)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1159 return null;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1160
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1161 return m_Objects[pos];
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1162 }
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 // =============================================================================
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 int LDDocument::getObjectCount() const
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1167 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1168 return getObjects().size();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1169 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1170
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1171 // =============================================================================
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 bool LDDocument::hasUnsavedChanges() const
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1174 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1175 return !isImplicit() && getHistory()->getPosition() != getSavePosition();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1176 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1177
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1178 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1179 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
1180 QString LDDocument::getDisplayName()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1181 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1182 if (!getName().isEmpty())
575
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1183 return getName();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1184
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1185 if (!getDefaultName().isEmpty())
575
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1186 return "[" + getDefaultName() + "]";
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 return tr ("<anonymous>");
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1189 }
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 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1192 // -----------------------------------------------------------------------------
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
1193 LDObjectList LDDocument::inlineContents (LDSubfile::InlineFlags flags)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1194 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1195 // Possibly substitute with logoed studs:
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1196 // stud.dat -> stud-logo.dat
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1197 // stud2.dat -> stud-logo2.dat
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1198 if (gl_logostuds && (flags & LDSubfile::RendererInline))
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1199 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1200 // 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
1201 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
1202
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
1203 if (getName() == "stud.dat" && g_logoedStud)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1204 return g_logoedStud->inlineContents (flags);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1205 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
1206 return g_logoedStud2->inlineContents (flags);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1207 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1208
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
1209 LDObjectList objs, objcache;
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 bool deep = flags & LDSubfile::DeepInline,
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1212 doCache = flags & LDSubfile::CacheInline;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1213
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
1214 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
1215 {
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
1216 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
1217 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
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
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
1220 // 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
1221 if (deep && getCache().isEmpty() == false)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1222 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1223 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
1224 objs << obj->createCopy();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1225 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1226 else
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1227 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1228 if (!deep)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1229 doCache = false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1230
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1231 for (LDObject* obj : getObjects())
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1232 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1233 // Skip those without scemantic meaning
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1234 if (!obj->isScemantic())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1235 continue;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1236
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1237 // 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
1238 // 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
1239 // subfiles and this is not one. Yay, recursion!
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
1240 if (deep && obj->getType() == LDObject::ESubfile)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1241 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1242 LDSubfile* ref = static_cast<LDSubfile*> (obj);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1243
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1244 // 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
1245 // flag when recursing deeper in hierarchy.
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
1246 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
1247
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
1248 for (LDObject* otherobj : otherobjs)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1249 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1250 // Cache this object, if desired
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1251 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
1252 objcache << otherobj->createCopy();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1253
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1254 objs << otherobj;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1255 }
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 else
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1258 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1259 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
1260 objcache << obj->createCopy();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1261
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
1262 objs << obj->createCopy();
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1263 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1264 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1265
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1266 if (doCache)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1267 setCache (objcache);
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1270 return objs;
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 // =============================================================================
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 LDDocument* LDDocument::current()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1276 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1277 return m_curdoc;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1278 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1279
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1280 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1281 // 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
1282 // was an operation completely unheard of. ;)
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 // FIXME: f can be temporarily null. This probably should not be the case.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1285 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1286 void LDDocument::setCurrent (LDDocument* f)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1287 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1288 // 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
1289 // current.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1290 if (f && f->isImplicit())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1291 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1292
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1293 m_curdoc = f;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1294
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1295 if (g_win && f)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1296 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1297 // 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
1298 g_win->updateDocumentListItem (f);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1299 g_win->buildObjList();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1300 g_win->updateTitle();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1301 g_win->R()->setFile (f);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1302 g_win->R()->resetAllAngles();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1303 g_win->R()->repaint();
575
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1304 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
1305 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1306 }
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 int LDDocument::countExplicitFiles()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1311 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1312 int count = 0;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1313
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1314 for (LDDocument* f : g_loadedFiles)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1315 if (f->isImplicit() == false)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1316 count++;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1317
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1318 return 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
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 // 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
1323 // a new file over it.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1324 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1325 void LDDocument::closeInitialFile()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1326 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1327 if (
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1328 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
1329 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
1330 g_loadedFiles[1]->getName().isEmpty() == false &&
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1331 !g_loadedFiles[0]->hasUnsavedChanges()
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1332 )
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1333 delete g_loadedFiles[0];
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
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 void loadLogoedStuds()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1339 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1340 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
1341 return;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1342
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1343 delete g_logoedStud;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1344 delete g_logoedStud2;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1345
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1346 g_logoedStud = openDocument ("stud-logo.dat", true);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1347 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
1348
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
1349 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
1350 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1351
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 void LDDocument::addToSelection (LDObject* obj) // [protected]
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1355 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1356 if (obj->isSelected())
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1357 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1358
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1359 assert (obj->getFile() == this);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1360 m_sel << obj;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1361 obj->setSelected (true);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1362 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1363
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 void LDDocument::removeFromSelection (LDObject* obj) // [protected]
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1367 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1368 if (!obj->isSelected())
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1369 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1370
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1371 assert (obj->getFile() == this);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1372 m_sel.removeOne (obj);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1373 obj->setSelected (false);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1374 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1375
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 void LDDocument::clearSelection()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1379 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1380 for (LDObject* obj : m_sel)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1381 removeFromSelection (obj);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1382
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1383 assert (m_sel.isEmpty());
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
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 // -----------------------------------------------------------------------------
617
f5059d144438 - added a type alias LDObjectList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 613
diff changeset
1388 const LDObjectList& LDDocument::getSelection() const
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1389 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1390 return m_sel;
565
e403aad83f60 - history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents: 564
diff changeset
1391 }
e403aad83f60 - history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents: 564
diff changeset
1392
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 void LDDocument::swapObjects (LDObject* one, LDObject* other)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1396 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1397 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
1398 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
1399 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
1400 m_Objects[b] = one;
e403aad83f60 - history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents: 564
diff changeset
1401 m_Objects[a] = other;
e403aad83f60 - history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents: 564
diff changeset
1402 addToHistory (new SwapHistory (one->getID(), other->getID()));
575
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1403 }
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1404
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 // -----------------------------------------------------------------------------
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
1407 QString LDDocument::shortenName (QString a) // [static]
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1408 {
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
1409 QString shortname = basename (a);
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 604
diff changeset
1410 QString topdirname = basename (dirname (a));
575
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1411
588
720f7480c6b7 - now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
1412 if (g_specialSubdirectories.contains (topdirname))
575
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1413 shortname.prepend (topdirname + "\\");
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1414
59c0b57e843b - added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 572
diff changeset
1415 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
1416 }
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
1417
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 void LDDocument::addReference (LDDocumentPointer* ptr)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1421 {
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
1422 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
1423 }
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
1424
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 void LDDocument::removeReference (LDDocumentPointer* ptr)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
1428 {
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
1429 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
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 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
1432 invokeLater (closeUnused);
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1433 }

mercurial