Mon, 06 May 2013 15:39:45 +0300
Further work on ext programs, LDObjectType_e integrated into LDObject
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 | 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> |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #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
|
23 | #include "config.h" |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "file.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "misc.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "bbox.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #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
|
28 | #include "history.h" |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | |
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
|
30 | 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
|
31 | 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
|
32 | |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | // ============================================================================= |
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
|
34 | 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
|
35 | 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
|
36 | 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
|
37 | } |
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
|
38 | |
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
|
39 | // ============================================================================= |
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
|
40 | 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
|
41 | // 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
|
42 | 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
|
43 | 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
|
44 | |
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
|
45 | // 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
|
46 | 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
|
47 | 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
|
48 | } |
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
|
49 | |
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
|
50 | // ============================================================================= |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | // ============================================================================= |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
53 | 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
|
54 | 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
|
55 | 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
|
56 | return file; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
104 | 58 | return null; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | // ============================================================================= |
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
|
64 | 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
|
65 | 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
|
66 | |
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
|
67 | #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
|
68 | 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
|
69 | #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
|
70 | |
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
|
71 | 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
|
72 | 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
|
73 | |
104 | 74 | 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
|
75 | 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
|
76 | |
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
|
77 | 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
|
78 | // Try with just the LDraw path first |
161 | 79 | 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
|
80 | io_ldpath.value.chars(), zTruePath.chars()); |
117
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
81 | 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
|
82 | |
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
|
83 | fp = fopen (zFilePath, "r"); |
104 | 84 | 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
|
85 | 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
|
86 | |
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
|
87 | 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
|
88 | 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
|
89 | "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
|
90 | "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
|
91 | }; |
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
|
92 | |
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
|
93 | for (char const* sSubdir : saSubdirectories) { |
161 | 94 | 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
|
95 | 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
|
96 | 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
|
97 | |
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
|
98 | 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
|
99 | |
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
|
100 | 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
|
101 | 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
|
102 | } |
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
|
103 | } |
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
|
104 | } |
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
|
105 | |
104 | 106 | 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
|
107 | } |
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
|
108 | |
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
|
109 | // ============================================================================= |
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
|
110 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
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
|
111 | // ============================================================================= |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
112 | 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
|
113 | char line[1024]; |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
114 | vector<str> lines; |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
115 | vector<LDObject*> objs; |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
116 | ulong lnum = 0; |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
117 | |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
118 | if (numWarnings) |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
119 | *numWarnings = 0; |
140
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
120 | |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
121 | 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
|
122 | // Trim the trailing newline |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
123 | str data = line; |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
124 | while (data[~data - 1] == '\n' || data[~data - 1] == '\r') |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
125 | data -= 1; |
140
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
126 | |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
127 | LDObject* obj = parseLine (data); |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
128 | 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
|
129 | |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
130 | // 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
|
131 | 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
|
132 | 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
|
133 | 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
|
134 | |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
135 | logf (LOG_Warning, "- Line was: %s\n", data.chars()); |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
136 | |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
137 | if (numWarnings) |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
138 | (*numWarnings)++; |
140
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
139 | } |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
140 | |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
141 | 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
|
142 | lnum++; |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
143 | } |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
144 | |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
145 | return objs; |
140
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
146 | } |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
147 | |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
148 | // ============================================================================= |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
149 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2e8c1626aef7
Added insert from action to import file contents from another file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
130
diff
changeset
|
150 | // ============================================================================= |
130
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
151 | 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
|
152 | 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
|
153 | |
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
|
154 | // 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
|
155 | // 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
|
156 | // 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
|
157 | FILE* fp; |
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
158 | if (search) |
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
159 | fp = openLDrawFile (-path, true); |
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
160 | else |
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
161 | 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
|
162 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | if (!fp) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno)); |
104 | 165 | return null; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | 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
|
169 | load->m_filename = path; |
141
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
170 | ulong numWarnings; |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
171 | std::vector<LDObject*> objs = loadFileContents (fp, &numWarnings); |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
172 | |
184d117e1b12
corrections to inserting from file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
140
diff
changeset
|
173 | 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
|
174 | 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
|
175 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | 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
|
177 | 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
|
178 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | logf (LOG_Success, "File %s parsed successfully (%lu warning%s).\n", |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | 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
|
181 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | return load; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | // ============================================================================= |
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
|
188 | 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
|
189 | 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
|
190 | |
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
|
191 | // 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
|
192 | 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
|
193 | switch (QMessageBox::question (g_win, "Unsaved Changes", |
161 | 194 | 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
|
195 | (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
|
196 | { |
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
|
197 | 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
|
198 | if (!save ()) { |
161 | 199 | 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
|
200 | 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
|
201 | |
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
|
202 | 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
|
203 | (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
|
204 | { |
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
|
205 | 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
|
206 | } |
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
|
207 | } |
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
|
208 | |
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
|
209 | 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
|
210 | |
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
|
211 | 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
|
212 | 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
|
213 | |
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
|
214 | 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
|
215 | 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
|
216 | } |
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
|
217 | } |
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
|
218 | |
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
|
219 | return true; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | 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
|
226 | 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
|
227 | return; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | // 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
|
230 | 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
|
231 | delete file; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | // 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
|
234 | 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
|
235 | g_curfile = NULL; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | |
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
|
237 | g_win->refresh (); |
26
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 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | void newFile () { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | // 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
|
245 | closeAll (); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | 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
|
248 | 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
|
249 | 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
|
250 | g_curfile = f; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | 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
|
253 | g_win->refresh (); |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | // ============================================================================= |
99
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
259 | void addRecentFile (str zPath) { |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
260 | 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
|
261 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
262 | // 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
|
263 | if (lPos != -1) { |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
264 | 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
|
265 | 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
|
266 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
267 | // Pop it out. |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
268 | 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
|
269 | 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
|
270 | 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
|
271 | } |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
272 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
273 | // 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
|
274 | 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
|
275 | 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
|
276 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
277 | // Add the file |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
278 | 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
|
279 | io_recentfiles.value += "@"; |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
280 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
281 | io_recentfiles += zPath; |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
282 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
283 | 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
|
284 | g_win->updateRecentFilesMenu (); |
99
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
285 | } |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
286 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
287 | // ============================================================================= |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
288 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
289 | // ============================================================================= |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | void openMainFile (str zPath) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | closeAll (); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | |
130
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
293 | OpenFile* pFile = openDATFile (zPath, false); |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
294 | |
130
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
295 | if (!pFile) { |
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
296 | // 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
|
297 | setlocale (LC_ALL, "C"); |
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
|
298 | QMessageBox::critical (g_win, "Load Failure", |
161 | 299 | fmt ("Failed to open %s\nReason: %s", zPath.chars(), strerror (errno)), |
130
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
300 | (QMessageBox::Close), QMessageBox::Close); |
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
301 | |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
302 | return; |
130
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
303 | } |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
304 | |
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 | pFile->m_implicit = false; |
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
|
306 | g_curfile = pFile; |
26
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 | // Recalculate the bounding box |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | g_BBox.calculate(); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | // 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
|
312 | 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
|
313 | g_win->setTitle (); |
99
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
314 | |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
315 | // Add it to the recent files list. |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
94
diff
changeset
|
316 | addRecentFile (zPath); |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | // ============================================================================= |
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
|
322 | 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
|
323 | 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
|
324 | path = m_filename; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | |
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
|
326 | 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
|
327 | |
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
|
328 | 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
|
329 | lastError = errno; |
28
208adc847377
added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
330 | 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
|
331 | } |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | // 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
|
334 | 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
|
335 | // LDraw requires lines to have DOS line endings |
161 | 336 | 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
|
337 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | 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
|
339 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | 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
|
342 | |
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
|
343 | // 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
|
344 | 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
|
345 | |
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
|
346 | 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
|
347 | |
28
208adc847377
added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
348 | return true; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | #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
|
352 | if (tokens.size() != N) \ |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | 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
|
354 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | #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
|
356 | 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
|
357 | if (!isNumber (tokens[i])) \ |
161 | 358 | 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
|
359 | (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
|
360 | |
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
|
361 | // ============================================================================= |
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
|
362 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
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
|
363 | // ============================================================================= |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
364 | 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
|
365 | // 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
|
366 | // 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
|
367 | // 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
|
368 | 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
|
369 | |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
370 | vertex v; |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
146
diff
changeset
|
371 | for (const Axis ax : g_Axes) |
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
146
diff
changeset
|
372 | v[ax] = atof (s[n + ax]); |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
373 | |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
374 | return v; |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
375 | } |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
376 | |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
377 | // ============================================================================= |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
378 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
379 | // ============================================================================= |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
380 | LDObject* parseLine (str zLine) { |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
381 | vector<str> tokens = zLine.split (" ", true); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
382 | |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
383 | if (!tokens.size ()) { |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | // 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
|
385 | return new LDEmpty; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
386 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
387 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
388 | if (~tokens[0] != 1) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
389 | 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
|
390 | |
73
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
391 | 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
|
392 | switch (c - '0') { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | case 0: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
394 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
395 | // Comment |
161 | 396 | str comm; |
73
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
397 | for (uint i = 1; i < tokens.size(); ++i) { |
161 | 398 | comm += tokens[i]; |
73
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
399 | |
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
400 | if (i != tokens.size() - 1) |
161 | 401 | comm += ' '; |
73
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
402 | } |
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
403 | |
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
404 | // Handle BFC statements |
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
405 | 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
|
406 | for (short i = 0; i < LDBFC::NumStatements; ++i) |
164 | 407 | 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
|
408 | return new LDBFC ((LDBFC::Type) i); |
73
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
409 | |
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
410 | // 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
|
411 | // 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
|
412 | // need to handle MLCAD-style invertnext separately. |
161 | 413 | 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
|
414 | return new LDBFC (LDBFC::InvertNext); |
73
d20867ac03cc
Added support for BFC types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
415 | } |
42
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
416 | |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
417 | if (tokens.size() > 2 && tokens[1] == "!LDFORGE") { |
42
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
418 | // Handle LDForge-specific types, they're embedded into comments |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
419 | |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
420 | if (tokens[2] == "VERTEX") { |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
421 | // Vertex (0 !LDFORGE VERTEX) |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
422 | CHECK_TOKEN_COUNT (7) |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
423 | CHECK_TOKEN_NUMBERS (3, 6) |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
424 | |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
425 | LDVertex* obj = new LDVertex; |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
426 | obj->dColor = atol (tokens[3]); |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
146
diff
changeset
|
427 | |
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
146
diff
changeset
|
428 | for (const Axis ax : g_Axes) |
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
146
diff
changeset
|
429 | 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
|
430 | |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
431 | return obj; |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
432 | } |
113
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
433 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
434 | if (tokens[2] == "RADIAL") { |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
435 | CHECK_TOKEN_COUNT (20) |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
436 | CHECK_TOKEN_NUMBERS (4, 19) |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
437 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
438 | LDRadial::Type eType = LDRadial::NumTypes; |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
439 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
440 | for (int i = 0; i < LDRadial::NumTypes; ++i) { |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
441 | 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
|
442 | eType = (LDRadial::Type) i; |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
443 | break; |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
444 | } |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
445 | } |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
446 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
447 | if (eType == LDRadial::NumTypes) |
161 | 448 | 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
|
449 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
450 | LDRadial* obj = new LDRadial; |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
451 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
452 | obj->eRadialType = eType; // 3 |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
453 | obj->dColor = atol (tokens[4]); // 4 |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
454 | obj->dSegments = atol (tokens[5]); // 5 |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
455 | obj->dDivisions = atol (tokens[6]); // 6 |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
456 | obj->dRingNum = atol (tokens[7]); // 7 |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
457 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
458 | obj->vPosition = parseVertex (tokens, 8); // 8 - 10 |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
459 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
460 | for (short i = 0; i < 9; ++i) |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
461 | 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
|
462 | |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
463 | return obj; |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
464 | } |
42
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
465 | } |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
466 | |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | LDComment* obj = new LDComment; |
164 | 468 | obj->text = comm; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
469 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
470 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
472 | case 1: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | // Subfile |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | CHECK_TOKEN_COUNT (15) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | 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
|
477 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
478 | // Try open the file |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
479 | 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
|
480 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
481 | // 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
|
482 | if (!pFile) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
483 | 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
|
484 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
485 | LDSubfile* obj = new LDSubfile; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
486 | obj->dColor = atol (tokens[1]); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
487 | 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
|
488 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
489 | 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
|
490 | 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
|
491 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
492 | obj->zFileName = tokens[14]; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
493 | obj->pFile = pFile; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
494 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
495 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
496 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
497 | case 2: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
498 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
499 | CHECK_TOKEN_COUNT (8) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
500 | 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
|
501 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
502 | // Line |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
503 | LDLine* obj = new LDLine; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
504 | 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
|
505 | 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
|
506 | 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
|
507 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
508 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
509 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
510 | case 3: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
511 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
512 | CHECK_TOKEN_COUNT (11) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
513 | 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
|
514 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
515 | // Triangle |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
516 | LDTriangle* obj = new LDTriangle; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
517 | 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
|
518 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
519 | 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
|
520 | 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
|
521 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
522 | return obj; |
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 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
525 | case 4: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
526 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
527 | CHECK_TOKEN_COUNT (14) |
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 | // Quadrilateral |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
531 | LDQuad* obj = new LDQuad; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
532 | 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
|
533 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
534 | 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
|
535 | 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
|
536 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
537 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
538 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
539 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
540 | case 5: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
541 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
542 | CHECK_TOKEN_COUNT (14) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
543 | 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
|
544 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
545 | // Conditional line |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
546 | LDCondLine* obj = new LDCondLine; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
547 | 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
|
548 | |
40
215b9f8f0cd7
Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
549 | 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
|
550 | 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
|
551 | |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
552 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
553 | } |
70
e6b8dab8f81a
Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
554 | |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
555 | 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
|
556 | 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
|
557 | } |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
558 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
559 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
560 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
561 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
562 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
563 | OpenFile* loadSubfile (str zFile) { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
564 | // Try open the file |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
565 | OpenFile* pFile = findLoadedFile (zFile); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
566 | if (!pFile) |
130
ec4b30b166fe
Show an error message box when main file loading fails.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
129
diff
changeset
|
567 | pFile = openDATFile (zFile, true); |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
568 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
569 | return pFile; |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
570 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
571 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
572 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
573 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
574 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
575 | 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
|
576 | if (!g_curfile) |
32
5d22b7ecf110
Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
577 | return; |
5d22b7ecf110
Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
578 | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
579 | // 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
|
580 | 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
|
581 | 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
|
582 | delete file; |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
583 | |
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
|
584 | 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
|
585 | g_loadedFiles.push_back (g_curfile); |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
586 | |
70
e6b8dab8f81a
Phased out FOREACH macro in favor of C++11-style for iteration.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
587 | // 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
|
588 | 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
|
589 | 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
|
590 | // 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
|
591 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
592 | OpenFile* pFile = loadSubfile (ref->zFileName); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
593 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
594 | if (pFile) |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
595 | ref->pFile = pFile; |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
596 | else { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
597 | // Couldn't load the file, mark it an error |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
598 | 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
|
599 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
600 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
601 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
602 | // 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
|
603 | // 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
|
604 | if (obj->getType() == LDObject::Gibberish) |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
605 | obj->replace (parseLine (static_cast<LDGibberish*> (obj)->zContents)); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
606 | } |
38
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
607 | } |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
608 | |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
609 | // ============================================================================= |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
610 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
611 | // ============================================================================= |
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
|
612 | 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
|
613 | 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
|
614 | |
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
|
615 | 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
|
616 | g_BBox.calcObject (obj); |
39
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
38
diff
changeset
|
617 | |
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
|
618 | 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
|
619 | } |
03a7bdcce50d
Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
620 | |
03a7bdcce50d
Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
621 | // ============================================================================= |
03a7bdcce50d
Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
622 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
03a7bdcce50d
Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
623 | // ============================================================================= |
03a7bdcce50d
Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
624 | 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
|
625 | 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
|
626 | |
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
|
627 | 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
|
628 | g_BBox.calcObject (obj); |
55
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
629 | } |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
630 | |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
631 | // ============================================================================= |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
632 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
633 | // ============================================================================= |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
634 | void OpenFile::forgetObject (LDObject* obj) { |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
635 | // Find the index for the given object |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
636 | 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
|
637 | 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
|
638 | if (m_objs[ulIndex] == obj) |
55
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
639 | break; // found it |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
640 | |
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
|
641 | if (ulIndex >= m_objs.size ()) |
55
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
642 | return; // was not found |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
643 | |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
644 | // 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
|
645 | 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
|
646 | |
03a7bdcce50d
Adding objects now actually updates the bounding box like it should be.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
647 | // 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
|
648 | 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
|
649 | g_BBox.calculate (); |
117
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
650 | } |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
651 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
652 | // ============================================================================= |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
653 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
654 | // ============================================================================= |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
655 | std::vector<partListEntry> g_PartList; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
656 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
657 | void initPartList () { |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
658 | logf ("%s: initializing parts.lst\n", __func__); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
659 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
660 | FILE* fp = openLDrawFile ("parts.lst", false); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
661 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
662 | if (!fp) |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
663 | return; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
664 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
665 | char sLine[1024]; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
666 | while (fgets (sLine, sizeof sLine, fp)) { |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
667 | // Locate the first whitespace |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
668 | char* cpWhite = strstr (sLine, " "); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
669 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
670 | char sName[65]; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
671 | size_t uLength = (cpWhite - sLine); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
672 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
673 | if (uLength >= 64) |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
674 | continue; // too long |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
675 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
676 | strncpy (sName, sLine, uLength); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
677 | sName[uLength] = '\0'; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
678 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
679 | // Surf through the whitespace sea! |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
680 | while (*cpWhite == ' ') |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
681 | cpWhite++; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
682 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
683 | // Get the end point |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
684 | char* cpEnd = strstr (sLine, "\r"); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
685 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
686 | if (cpEnd == null) { |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
687 | // must not be DOS-formatted |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
688 | cpEnd = strstr (sLine, "\n"); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
689 | } |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
690 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
691 | assert (cpEnd != null); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
692 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
693 | // Make the file title now |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
694 | char sTitle[81]; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
695 | uLength = (cpEnd - cpWhite); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
696 | strncpy (sTitle, cpWhite, uLength); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
697 | sTitle[uLength] = '\0'; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
698 | |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
699 | // Add it to the array. |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
700 | partListEntry entry; |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
701 | strcpy (entry.sName, sName); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
702 | strcpy (entry.sTitle, sTitle); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
703 | g_PartList.push_back (entry); |
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
704 | } |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
705 | } |