file.cpp

Wed, 08 May 2013 03:53:45 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 08 May 2013 03:53:45 +0300
changeset 179
f98391b179ab
parent 172
a65547b84ef8
child 180
16306e69a895
permissions
-rw-r--r--

Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...

30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
1 /*
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
2 * LDForge: LDraw parts authoring CAD
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 99
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
4 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
5 * This program is free software: you can redistribute it and/or modify
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
6 * it under the terms of the GNU General Public License as published by
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
8 * (at your option) any later version.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
9 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
10 * This program is distributed in the hope that it will be useful,
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
13 * GNU General Public License for more details.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
14 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
15 * You should have received a copy of the GNU General Public License
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
17 */
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
18
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <vector>
99
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
20 #include <stdio.h>
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
21 #include <qmessagebox.h>
179
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
22 #include <QDir>
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "common.h"
69
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
24 #include "config.h"
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "file.h"
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "misc.h"
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "bbox.h"
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "gui.h"
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
29 #include "history.h"
179
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
30 #include "zz_ldrawPathDialog.h"
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
69
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
32 cfg (str, io_ldpath, "");
99
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
33 cfg (str, io_recentfiles, "");
69
6790dea720a8 Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
34
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 // =============================================================================
179
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
36 namespace LDPaths {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
37 static str pathError;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
38
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
39 struct {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
40 str LDConfigPath;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
41 str partsPath, primsPath;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
42 } pathInfo;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
43
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
44 void initPaths () {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
45 if (!tryConfigure (io_ldpath)) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
46 LDrawPathDialog dlg;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
47
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
48 if (!dlg.exec ())
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
49 exit (0);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
50
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
51 io_ldpath = dlg.path ();
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
52 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
53 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
54
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
55 bool tryConfigure (str path) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
56 QDir dir;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
57
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
58 if (!dir.cd (path)) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
59 pathError = "Directory does not exist.";
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
60 return false;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
61 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
62
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
63 QStringList mustHave = {"LDConfig.ldr", "parts", "p"};
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
64 QStringList contents = dir.entryList (mustHave);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
65
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
66 if (contents.size () != mustHave.size ()) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
67 pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
68 return false;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
69 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
70
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
71 pathInfo.partsPath = fmt ("%s" DIRSLASH "parts", path.chars ());
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
72 pathInfo.LDConfigPath = fmt ("%s" DIRSLASH "LDConfig.ldr", path.chars ());
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
73 pathInfo.primsPath = fmt ("%s" DIRSLASH "p", path.chars ());
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
74
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
75 return true;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
76 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
77
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
78 // Accessors
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
79 str getError () { return pathError; }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
80 str ldconfig () { return pathInfo.LDConfigPath; }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
81 str prims () { return pathInfo.primsPath; }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
82 str parts () { return pathInfo.partsPath; }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
83 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
84
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 172
diff changeset
85 // =============================================================================
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
86 OpenFile::OpenFile () {
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
87 m_implicit = true;
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
88 savePos = -1;
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
89 }
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
90
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
91 // =============================================================================
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
92 OpenFile::~OpenFile () {
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
93 // Clear everything from the model
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
94 for (LDObject* obj : m_objs)
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
95 delete obj;
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
96
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
97 // Clear the cache as well
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
98 for (LDObject* obj : m_objCache)
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
99 delete obj;
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
100 }
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
101
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
102 // =============================================================================
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 // =============================================================================
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
105 OpenFile* findLoadedFile (str zName) {
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
106 for (OpenFile* file : g_loadedFiles)
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
107 if (file->m_filename == zName)
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 return file;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 99
diff changeset
110 return null;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 // =============================================================================
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
116 FILE* openLDrawFile (str path, bool bSubDirectories) {
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
117 str zTruePath = path;
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
118
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
119 #ifndef WIN32
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
120 zTruePath.replace ("\\", "/");
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
121 #endif // WIN32
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
122
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
123 FILE* fp = fopen (path.chars (), "r");
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
124 str zFilePath;
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
125
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 99
diff changeset
126 if (fp != null)
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
127 return fp;
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
128
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
129 if (~io_ldpath.value) {
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
130 // Try with just the LDraw path first
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
131 zFilePath = fmt ("%s" DIRSLASH "%s",
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
132 io_ldpath.value.chars(), zTruePath.chars());
117
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
133 logf ("Trying %s\n", zFilePath.chars());
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
134
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
135 fp = fopen (zFilePath, "r");
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 99
diff changeset
136 if (fp != null)
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
137 return fp;
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
138
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
139 if (bSubDirectories) {
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
140 char const* saSubdirectories[] = {
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
141 "parts",
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
142 "p",
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
143 };
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
144
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
145 for (char const* sSubdir : saSubdirectories) {
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
146 zFilePath = fmt ("%s" DIRSLASH "%s" DIRSLASH "%s",
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
147 io_ldpath.value.chars(), sSubdir, zTruePath.chars());
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
148 printf ("try %s\n", zFilePath.chars());
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
149
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
150 fp = fopen (zFilePath.chars (), "r");
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
151
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
152 if (fp)
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
153 return fp;
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
154 }
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
155 }
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
156 }
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
157
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 99
diff changeset
158 return null;
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
159 }
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
160
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
161 // =============================================================================
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
163 // =============================================================================
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
164 std::vector<LDObject*> loadFileContents (FILE* fp, ulong* numWarnings) {
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
165 char line[1024];
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
166 vector<str> lines;
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
167 vector<LDObject*> objs;
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
168 ulong lnum = 0;
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
169
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
170 if (numWarnings)
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
171 *numWarnings = 0;
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
172
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
173 while (fgets (line, sizeof line, fp)) {
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
174 // Trim the trailing newline
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
175 str data = line;
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
176 while (data[~data - 1] == '\n' || data[~data - 1] == '\r')
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
177 data -= 1;
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
178
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
179 LDObject* obj = parseLine (data);
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
180 assert (obj != null);
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
181
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
182 // Check for parse errors and warn about tthem
168
96691a009dff Further work on ext programs, LDObjectType_e integrated into LDObject
Santeri Piippo <crimsondusk64@gmail.com>
parents: 164
diff changeset
183 if (obj->getType() == LDObject::Gibberish) {
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
184 logf (LOG_Warning, "Couldn't parse line #%lu: %s\n",
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
185 lnum, static_cast<LDGibberish*> (obj)->zReason.chars());
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
186
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
187 logf (LOG_Warning, "- Line was: %s\n", data.chars());
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
188
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
189 if (numWarnings)
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
190 (*numWarnings)++;
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
191 }
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
192
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
193 objs.push_back (obj);
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
194 lnum++;
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
195 }
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
196
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
197 return objs;
140
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
198 }
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
199
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
200 // =============================================================================
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2e8c1626aef7 Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
202 // =============================================================================
130
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
203 OpenFile* openDATFile (str path, bool search) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 logf ("Opening %s...\n", path.chars());
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205
66
12aca5d5a51e Restructured inlining to use a proper caching.. one cache per sub-file reference? What was I thinking? *whacks self with a 55295.dat*
Santeri Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
206 // Convert the file name to lowercase since some parts contain uppercase
12aca5d5a51e Restructured inlining to use a proper caching.. one cache per sub-file reference? What was I thinking? *whacks self with a 55295.dat*
Santeri Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
207 // file names. I'll assume here that the library will always use lowercase
12aca5d5a51e Restructured inlining to use a proper caching.. one cache per sub-file reference? What was I thinking? *whacks self with a 55295.dat*
Santeri Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
208 // file names for the actual parts..
130
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
209 FILE* fp;
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
210 if (search)
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
211 fp = openLDrawFile (-path, true);
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
212 else
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
213 fp = fopen (path, "r");
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 if (!fp) {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno));
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 99
diff changeset
217 return null;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 OpenFile* load = new OpenFile;
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
221 load->m_filename = path;
141
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
222 ulong numWarnings;
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
223 std::vector<LDObject*> objs = loadFileContents (fp, &numWarnings);
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
224
184d117e1b12 corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
225 for (LDObject* obj : objs)
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
226 load->m_objs.push_back (obj);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 fclose (fp);
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
229 g_loadedFiles.push_back (load);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230
169
f562323760a2 Added grouping basics - will be needed for ext programs (Intersector, Isecalc and a lot of others use 2 or more inputs, need to get all of those in somehow...) plus I think they can be useful for the actual authoring process
Santeri Piippo <crimsondusk64@gmail.com>
parents: 168
diff changeset
231 logf ("File %s parsed successfully (%lu warning%s).\n",
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 path.chars(), numWarnings, PLURAL (numWarnings));
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 return load;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 // =============================================================================
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
240 bool OpenFile::safeToClose () {
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
241 setlocale (LC_ALL, "C");
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
243 // If we have unsaved changes, warn and give the option of saving.
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
244 if (!m_implicit && History::pos () != savePos) {
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
245 switch (QMessageBox::question (g_win, "Unsaved Changes",
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
246 fmt ("There are unsaved changes to %s. Should it be saved?", m_filename.chars ()),
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
247 (QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel), QMessageBox::Cancel))
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
248 {
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
249 case QMessageBox::Yes:
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
250 if (!save ()) {
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
251 str errormsg = fmt ("Failed to save %s: %s\nDo you still want to close?",
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
252 m_filename.chars (), strerror (lastError));
129
9cf313447c8f A saving failure is a critical error, not a warning and should be drawn as such
Santeri Piippo <crimsondusk64@gmail.com>
parents: 128
diff changeset
253
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
254 if (QMessageBox::critical (g_win, "Save Failure", errormsg,
129
9cf313447c8f A saving failure is a critical error, not a warning and should be drawn as such
Santeri Piippo <crimsondusk64@gmail.com>
parents: 128
diff changeset
255 (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::No)
9cf313447c8f A saving failure is a critical error, not a warning and should be drawn as such
Santeri Piippo <crimsondusk64@gmail.com>
parents: 128
diff changeset
256 {
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
257 return false;
129
9cf313447c8f A saving failure is a critical error, not a warning and should be drawn as such
Santeri Piippo <crimsondusk64@gmail.com>
parents: 128
diff changeset
258 }
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
259 }
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
260
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
261 break;
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
262
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
263 case QMessageBox::Cancel:
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
264 return false;
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
265
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
266 default:
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
267 break;
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
268 }
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
269 }
71
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 70
diff changeset
270
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
271 return true;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 void closeAll () {
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
278 if (!g_loadedFiles.size())
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 return;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 // Remove all loaded files and the objects they contain
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
282 for (OpenFile* file : g_loadedFiles)
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
283 delete file;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 // Clear the array
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
286 g_loadedFiles.clear();
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
287 g_curfile = NULL;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
289 g_win->refresh ();
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 void newFile () {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 // Create a new anonymous file and set it to our current
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 closeAll ();
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 OpenFile* f = new OpenFile;
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
300 f->m_filename = "";
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
301 g_loadedFiles.push_back (f);
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
302 g_curfile = f;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 g_BBox.calculate();
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
305 g_win->refresh ();
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 // =============================================================================
99
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
311 void addRecentFile (str zPath) {
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
312 long lPos = io_recentfiles.value.first (zPath);
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
313
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
314 // If this file already is in the list, pop it out.
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
315 if (lPos != -1) {
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
316 if (~io_recentfiles.value == ~zPath)
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
317 return; // only recent file - do nothing
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
318
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
319 // Pop it out.
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
320 str zFront = io_recentfiles.value.substr (0, lPos);
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
321 str zBack = io_recentfiles.value.substr (lPos + ~zPath + 1, -1);
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
322 io_recentfiles.value = zFront + zBack;
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
323 }
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
324
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
325 // If there's too many recent files, drop one out.
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
326 while (io_recentfiles.value.count ('@') > 3)
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
327 io_recentfiles.value = io_recentfiles.value.substr (io_recentfiles.value.first ("@") + 1, -1);
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
328
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
329 // Add the file
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
330 if (~io_recentfiles.value > 0)
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
331 io_recentfiles.value += "@";
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
332
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
333 io_recentfiles += zPath;
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
334
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
335 config::save ();
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
336 g_win->updateRecentFilesMenu ();
99
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
337 }
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
338
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
339 // =============================================================================
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
341 // =============================================================================
172
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
342 void openMainFile (str path) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 closeAll ();
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344
172
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
345 OpenFile* file = openDATFile (path, false);
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
346
172
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
347 if (!file) {
130
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
348 // Tell the user loading failed.
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
349 setlocale (LC_ALL, "C");
172
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
350 critical (fmt ("Failed to open %s: %s", path.chars(), strerror (errno)));
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
351 return;
130
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
352 }
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
353
172
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
354 file->m_implicit = false;
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
355 g_curfile = file;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 // Recalculate the bounding box
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 g_BBox.calculate();
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 // Rebuild the object tree view now.
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
361 g_win->refresh ();
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
362 g_win->setTitle ();
172
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
363 g_win->R ()->resetAngles ();
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
364
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
365 History::clear ();
99
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
366
920d51fec412 Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
367 // Add it to the recent files list.
172
a65547b84ef8 Restructured the shortcut configuration tab a little, allowing it to be sorted.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 169
diff changeset
368 addRecentFile (path);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 // =============================================================================
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 // =============================================================================
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
374 bool OpenFile::save (str path) {
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
375 if (!~path)
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
376 path = m_filename;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
378 FILE* fp = fopen (path, "w");
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
379
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
380 if (!fp) {
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
381 lastError = errno;
28
208adc847377 added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
382 return false;
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
383 }
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 // Write all entries now
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
386 for (LDObject* obj : m_objs) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 // LDraw requires lines to have DOS line endings
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
388 str zLine = fmt ("%s\r\n", obj->getContents ().chars ());
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 fwrite (zLine.chars(), 1, ~zLine, fp);
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 fclose (fp);
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
394
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
395 // We have successfully saved, update the save position now.
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
396 savePos = History::pos ();
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
397
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
398 g_win->setTitle ();
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
399
28
208adc847377 added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
400 return true;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 #define CHECK_TOKEN_COUNT(N) \
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 if (tokens.size() != N) \
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 return new LDGibberish (zLine, "Bad amount of tokens");
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 #define CHECK_TOKEN_NUMBERS(MIN,MAX) \
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 for (ushort i = MIN; i <= MAX; ++i) \
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409 if (!isNumber (tokens[i])) \
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
410 return new LDGibberish (zLine, fmt ("Token #%u was `%s`, expected a number", \
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 (i + 1), tokens[i].chars()));
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412
45
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
413 // =============================================================================
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
415 // =============================================================================
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
416 static vertex parseVertex (vector<str>& s, const ushort n) {
45
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
417 // Disable the locale while parsing the line or atof's behavior changes
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
418 // between locales (i.e. fails to read decimals properly). That is
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
419 // quite undesired...
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
420 setlocale (LC_NUMERIC, "C");
19d99d62d88e Disable the locale when parsing LDraw code or atof's behavior becomes locale-dependant. Who the hell thought that was a great idea?
Santeri Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
421
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
422 vertex v;
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 146
diff changeset
423 for (const Axis ax : g_Axes)
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 146
diff changeset
424 v[ax] = atof (s[n + ax]);
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
425
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
426 return v;
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
427 }
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
428
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
429 // =============================================================================
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
430 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
431 // =============================================================================
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
432 LDObject* parseLine (str zLine) {
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
433 vector<str> tokens = zLine.split (" ", true);
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
434
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
435 if (!tokens.size ()) {
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 // Line was empty, or only consisted of whitespace
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 return new LDEmpty;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 if (~tokens[0] != 1)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 return new LDGibberish (zLine, "Illogical line code");
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442
73
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
443 const char c = tokens[0][0];
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 switch (c - '0') {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 case 0:
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 // Comment
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
448 str comm;
73
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
449 for (uint i = 1; i < tokens.size(); ++i) {
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
450 comm += tokens[i];
73
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
451
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
452 if (i != tokens.size() - 1)
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
453 comm += ' ';
73
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
454 }
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
455
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
456 // Handle BFC statements
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
457 if (tokens.size() > 2 && tokens[1] == "BFC") {
114
fe1bfc5f59ed Added functionality for getting a primitive name from a radial.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
458 for (short i = 0; i < LDBFC::NumStatements; ++i)
164
8c93d8e38494 cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 161
diff changeset
459 if (comm == fmt ("BFC %s", LDBFC::statements [i]))
114
fe1bfc5f59ed Added functionality for getting a primitive name from a radial.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
460 return new LDBFC ((LDBFC::Type) i);
73
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
461
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
462 // MLCAD is notorious for stuffing these statements in parts it
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
463 // creates. The above block only handles valid statements, so we
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
464 // need to handle MLCAD-style invertnext separately.
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
465 if (comm == "BFC CERTIFY INVERTNEXT")
114
fe1bfc5f59ed Added functionality for getting a primitive name from a radial.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
466 return new LDBFC (LDBFC::InvertNext);
73
d20867ac03cc Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
467 }
42
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
468
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
469 if (tokens.size() > 2 && tokens[1] == "!LDFORGE") {
42
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
470 // Handle LDForge-specific types, they're embedded into comments
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
471
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
472 if (tokens[2] == "VERTEX") {
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
473 // Vertex (0 !LDFORGE VERTEX)
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
474 CHECK_TOKEN_COUNT (7)
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
475 CHECK_TOKEN_NUMBERS (3, 6)
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
476
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
477 LDVertex* obj = new LDVertex;
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
478 obj->dColor = atol (tokens[3]);
147
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 146
diff changeset
479
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 146
diff changeset
480 for (const Axis ax : g_Axes)
291a1fe2d278 Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents: 146
diff changeset
481 obj->vPosition[ax] = atof (tokens[4 + ax]); // 4 - 6
42
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
482
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
483 return obj;
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
484 }
113
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
485
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
486 if (tokens[2] == "RADIAL") {
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
487 CHECK_TOKEN_COUNT (20)
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
488 CHECK_TOKEN_NUMBERS (4, 19)
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
489
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
490 LDRadial::Type eType = LDRadial::NumTypes;
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
491
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
492 for (int i = 0; i < LDRadial::NumTypes; ++i) {
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
493 if (str (LDRadial::radialTypeName ((LDRadial::Type) i)).toupper ().strip (' ') == tokens[3]) {
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
494 eType = (LDRadial::Type) i;
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
495 break;
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
496 }
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
497 }
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
498
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
499 if (eType == LDRadial::NumTypes)
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 160
diff changeset
500 return new LDGibberish (zLine, fmt ("Unknown radial type %s", tokens[3].chars ()));
113
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
501
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
502 LDRadial* obj = new LDRadial;
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
503
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
504 obj->eRadialType = eType; // 3
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
505 obj->dColor = atol (tokens[4]); // 4
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
506 obj->dSegments = atol (tokens[5]); // 5
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
507 obj->dDivisions = atol (tokens[6]); // 6
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
508 obj->dRingNum = atol (tokens[7]); // 7
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
509
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
510 obj->vPosition = parseVertex (tokens, 8); // 8 - 10
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
511
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
512 for (short i = 0; i < 9; ++i)
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
513 obj->mMatrix[i] = atof (tokens[i + 11]); // 11 - 19
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
514
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
515 return obj;
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
516 }
42
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
517 }
499c25af0303 Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
518
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519 LDComment* obj = new LDComment;
164
8c93d8e38494 cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 161
diff changeset
520 obj->text = comm;
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 return obj;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
522 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 case 1:
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525 {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 // Subfile
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527 CHECK_TOKEN_COUNT (15)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528 CHECK_TOKEN_NUMBERS (1, 13)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
530 // Try open the file
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
531 OpenFile* pFile = loadSubfile (tokens[14]);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
533 // If we cannot open the file, mark it an error
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
534 if (!pFile)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535 return new LDGibberish (zLine, "Could not open referred file");
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
536
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 LDSubfile* obj = new LDSubfile;
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
538 obj->dColor = atol (tokens[1]);
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
539 obj->vPosition = parseVertex (tokens, 2); // 2 - 4
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541 for (short i = 0; i < 9; ++i)
64
ada4679d5bce Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
542 obj->mMatrix[i] = atof (tokens[i + 5]); // 5 - 13
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544 obj->zFileName = tokens[14];
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 obj->pFile = pFile;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546 return obj;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
547 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549 case 2:
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550 {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 CHECK_TOKEN_COUNT (8)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
552 CHECK_TOKEN_NUMBERS (1, 7)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554 // Line
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
555 LDLine* obj = new LDLine;
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
556 obj->dColor = atol (tokens[1]);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
557 for (short i = 0; i < 2; ++i)
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
558 obj->vaCoords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 7
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
559 return obj;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
561
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 case 3:
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564 CHECK_TOKEN_COUNT (11)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 CHECK_TOKEN_NUMBERS (1, 10)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
567 // Triangle
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
568 LDTriangle* obj = new LDTriangle;
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
569 obj->dColor = atol (tokens[1]);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
570
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
571 for (short i = 0; i < 3; ++i)
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
572 obj->vaCoords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 10
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 return obj;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
575 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
576
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 case 4:
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579 CHECK_TOKEN_COUNT (14)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 CHECK_TOKEN_NUMBERS (1, 13)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 // Quadrilateral
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 LDQuad* obj = new LDQuad;
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
584 obj->dColor = atol (tokens[1]);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 for (short i = 0; i < 4; ++i)
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
587 obj->vaCoords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 13
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 return obj;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 }
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592 case 5:
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 {
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594 CHECK_TOKEN_COUNT (14)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
595 CHECK_TOKEN_NUMBERS (1, 13)
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597 // Conditional line
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598 LDCondLine* obj = new LDCondLine;
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
599 obj->dColor = atol (tokens[1]);
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
600
40
215b9f8f0cd7 Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
601 for (short i = 0; i < 4; ++i)
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 55
diff changeset
602 obj->vaCoords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 13
70
e6b8dab8f81a Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 69
diff changeset
603
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
604 return obj;
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
605 }
70
e6b8dab8f81a Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 69
diff changeset
606
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
607 default: // Strange line we couldn't parse
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
608 return new LDGibberish (zLine, "Unknown line code number");
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609 }
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
610 }
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
611
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
612 // =============================================================================
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
613 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
614 // =============================================================================
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
615 OpenFile* loadSubfile (str zFile) {
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
616 // Try open the file
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
617 OpenFile* pFile = findLoadedFile (zFile);
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
618 if (!pFile)
130
ec4b30b166fe Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
619 pFile = openDATFile (zFile, true);
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
620
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
621 return pFile;
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
622 }
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
623
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
624 // =============================================================================
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
625 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
626 // =============================================================================
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
627 void reloadAllSubfiles () {
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
628 if (!g_curfile)
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
629 return;
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
630
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
631 // First, close all but the current open file.
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
632 for (OpenFile* file : g_loadedFiles)
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
633 if (file != g_curfile)
127
a6e2067bb2f1 Keep track of when the file was last saved and warn if there are unsaved changes when the application is closing.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
634 delete file;
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
635
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
636 g_loadedFiles.clear ();
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
637 g_loadedFiles.push_back (g_curfile);
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
638
70
e6b8dab8f81a Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 69
diff changeset
639 // Go through all objects in the current file and reload the subfiles
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
640 for (LDObject* obj : g_curfile->m_objs) {
168
96691a009dff Further work on ext programs, LDObjectType_e integrated into LDObject
Santeri Piippo <crimsondusk64@gmail.com>
parents: 164
diff changeset
641 if (obj->getType() == LDObject::Subfile) {
70
e6b8dab8f81a Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 69
diff changeset
642 // Note: ref->pFile is invalid right now since all subfiles were closed.
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
643 LDSubfile* ref = static_cast<LDSubfile*> (obj);
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
644 OpenFile* pFile = loadSubfile (ref->zFileName);
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
645
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
646 if (pFile)
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
647 ref->pFile = pFile;
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
648 else {
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
649 // Couldn't load the file, mark it an error
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
650 ref->replace (new LDGibberish (ref->getContents (), "Could not open referred file"));
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
651 }
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
652 }
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
653
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
654 // Reparse gibberish files. It could be that they are invalid because
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
655 // the file could not be opened. Circumstances may be different now.
168
96691a009dff Further work on ext programs, LDObjectType_e integrated into LDObject
Santeri Piippo <crimsondusk64@gmail.com>
parents: 164
diff changeset
656 if (obj->getType() == LDObject::Gibberish)
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
657 obj->replace (parseLine (static_cast<LDGibberish*> (obj)->zContents));
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
658 }
38
20f5eaae8425 Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
659 }
20f5eaae8425 Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
660
20f5eaae8425 Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
661 // =============================================================================
20f5eaae8425 Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
662 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
20f5eaae8425 Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
663 // =============================================================================
94
a9e67f6e610e Added history management for cut and paste, copy doesn't alter the object list by itself so it doesn't touch history
Santeri Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
664 ulong OpenFile::addObject (LDObject* obj) {
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
665 m_objs.push_back (obj);
153
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
666
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
667 if (this == g_curfile)
153
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
668 g_BBox.calcObject (obj);
39
110669124caf Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
669
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
670 return m_objs.size() - 1;
153
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
671 }
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
672
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
673 // =============================================================================
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
674 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
675 // =============================================================================
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
676 void OpenFile::insertObj (const ulong pos, LDObject* obj) {
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
677 m_objs.insert (m_objs.begin () + pos, obj);
153
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
678
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
679 if (this == g_curfile)
153
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
680 g_BBox.calcObject (obj);
55
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
681 }
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
682
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
683 // =============================================================================
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
684 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
685 // =============================================================================
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
686 void OpenFile::forgetObject (LDObject* obj) {
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
687 // Find the index for the given object
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
688 ulong ulIndex;
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
689 for (ulIndex = 0; ulIndex < (ulong)m_objs.size(); ++ulIndex)
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
690 if (m_objs[ulIndex] == obj)
55
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
691 break; // found it
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
692
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
693 if (ulIndex >= m_objs.size ())
55
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
694 return; // was not found
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
695
b08f10e668e5 Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
696 // Erase it from memory
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
697 m_objs.erase (m_objs.begin() + ulIndex);
153
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
698
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
699 // Update the bounding box
160
edcb03f3ef75 Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 153
diff changeset
700 if (this == g_curfile)
153
03a7bdcce50d Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 147
diff changeset
701 g_BBox.calculate ();
117
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
702 }
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
703
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
704 // =============================================================================
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
705 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
706 // =============================================================================
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
707 std::vector<partListEntry> g_PartList;
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
708
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
709 void initPartList () {
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
710 logf ("%s: initializing parts.lst\n", __func__);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
711
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
712 FILE* fp = openLDrawFile ("parts.lst", false);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
713
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
714 if (!fp)
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
715 return;
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
716
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
717 char sLine[1024];
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
718 while (fgets (sLine, sizeof sLine, fp)) {
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
719 // Locate the first whitespace
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
720 char* cpWhite = strstr (sLine, " ");
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
721
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
722 char sName[65];
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
723 size_t uLength = (cpWhite - sLine);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
724
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
725 if (uLength >= 64)
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
726 continue; // too long
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
727
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
728 strncpy (sName, sLine, uLength);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
729 sName[uLength] = '\0';
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
730
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
731 // Surf through the whitespace sea!
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
732 while (*cpWhite == ' ')
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
733 cpWhite++;
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
734
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
735 // Get the end point
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
736 char* cpEnd = strstr (sLine, "\r");
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
737
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
738 if (cpEnd == null) {
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
739 // must not be DOS-formatted
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
740 cpEnd = strstr (sLine, "\n");
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
741 }
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
742
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
743 assert (cpEnd != null);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
744
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
745 // Make the file title now
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
746 char sTitle[81];
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
747 uLength = (cpEnd - cpWhite);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
748 strncpy (sTitle, cpWhite, uLength);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
749 sTitle[uLength] = '\0';
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
750
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
751 // Add it to the array.
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
752 partListEntry entry;
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
753 strcpy (entry.sName, sName);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
754 strcpy (entry.sTitle, sTitle);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
755 g_PartList.push_back (entry);
7eb7a43a511b Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
756 }
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
757 }

mercurial