Sun, 24 Mar 2013 21:41:24 +0200
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.
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 |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
3 | * Copyright (C) 2013 Santeri `arezey` Piippo |
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> |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "common.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "file.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "misc.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "bbox.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "gui.h" |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | // ============================================================================= |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
30 | OpenFile* findLoadedFile (str zName) { |
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
|
31 | FOREACH (OpenFile, *, file, g_LoadedFiles) |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
32 | if (file->zFileName == zName) |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | return file; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | return nullptr; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | OpenFile* openDATFile (str path) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | 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
|
43 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | FILE* fp = fopen (path.chars (), "r"); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
46 | if (!fp && ~io_ldpath.value) { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
47 | char const* saSubdirectories[] = { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
48 | "parts", |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
49 | "p", |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
50 | }; |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
51 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
52 | for (ushort i = 0; i < sizeof saSubdirectories / sizeof *saSubdirectories; ++i) { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
53 | str zFilePath = str::mkfmt ("%s" DIRSLASH "%s" DIRSLASH "%s", |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
54 | io_ldpath.value.chars(), saSubdirectories[i], path.chars()); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
55 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
56 | printf ("trying %s...\n", zFilePath.chars ()); |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | fp = fopen (zFilePath.chars (), "r"); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | if (fp) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | break; |
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 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | if (!fp) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno)); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | return nullptr; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | OpenFile* load = new OpenFile; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | ulong numWarnings = 0; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | load->zFileName = path; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | vector<str> lines; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | char line[1024]; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | while (fgets (line, sizeof line, fp)) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | // Trim the trailing newline |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | str zLine = line; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | while (zLine[~zLine - 1] == '\n' || zLine[~zLine - 1] == '\r') |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | zLine -= 1; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | lines.push_back (zLine); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | fclose (fp); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | for (ulong i = 0; i < lines.size(); ++i) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | LDObject* obj = parseLine (lines[i]); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | load->objects.push_back (obj); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | // Check for parse errors and warn abotu tthem |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | if (obj->getType() == OBJ_Gibberish) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | logf (LOG_Warning, "Couldn't parse line #%lu: %s\n", |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | i, static_cast<LDGibberish*> (obj)->zReason.chars()); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | logf (LOG_Warning, "- Line was: %s\n", lines[i].chars()); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | numWarnings++; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | g_LoadedFiles.push_back (load); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | 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
|
106 | 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
|
107 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | return load; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | // Clear everything from the model |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | void OpenFile::close () { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | for (ulong j = 0; j < objects.size(); ++j) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | delete objects[j]; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | delete this; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | void closeAll () { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | if (!g_LoadedFiles.size()) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | return; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | // Remove all loaded files and the objects they contain |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | for (ushort i = 0; i < g_LoadedFiles.size(); i++) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | OpenFile* f = g_LoadedFiles[i]; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | f->close (); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | // Clear the array |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | g_LoadedFiles.clear(); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | g_CurrentFile = NULL; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
139 | g_qWindow->refresh (); |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | void newFile () { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | // 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
|
147 | closeAll (); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | OpenFile* f = new OpenFile; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | f->zFileName = ""; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | g_LoadedFiles.push_back (f); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | g_CurrentFile = f; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | g_BBox.calculate(); |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
155 | g_qWindow->refresh (); |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | // ============================================================================= |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | void openMainFile (str zPath) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | closeAll (); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | OpenFile* pFile = openDATFile (zPath); |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
165 | |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
166 | if (!pFile) |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
167 | return; |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
168 | |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | g_CurrentFile = pFile; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | // Recalculate the bounding box |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | g_BBox.calculate(); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | // Rebuild the object tree view now. |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
175 | g_qWindow->refresh (); |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | |
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 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | // ============================================================================= |
28
208adc847377
added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
181 | bool OpenFile::save (str zPath) { |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | if (!~zPath) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | zPath = zFileName; |
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 | FILE* fp = fopen (zPath, "w"); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | if (!fp) |
28
208adc847377
added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
187 | return false; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | // Write all entries now |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | for (ulong i = 0; i < objects.size(); ++i) { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | LDObject* obj = objects[i]; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | // LDraw requires lines to have DOS line endings |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | str zLine = str::mkfmt ("%s\r\n",obj->getContents ().chars ()); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | 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
|
197 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | fclose (fp); |
28
208adc847377
added Save As function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
200 | return true; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | #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
|
204 | if (tokens.size() != N) \ |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | 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
|
206 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | #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
|
208 | 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
|
209 | if (!isNumber (tokens[i])) \ |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | return new LDGibberish (zLine, str::mkfmt ("Token #%u was `%s`, expected a number", \ |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | (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
|
212 | |
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
|
213 | // ============================================================================= |
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
|
214 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
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
|
215 | // ============================================================================= |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
216 | 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
|
217 | // 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
|
218 | // 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
|
219 | // 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
|
220 | 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
|
221 | |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
222 | vertex v; |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
223 | v.x = atof (s[n]); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
224 | v.y = atof (s[n + 1]); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
225 | v.z = atof (s[n + 2]); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
226 | |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
227 | return v; |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
228 | } |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
229 | |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
230 | // ============================================================================= |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
231 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
232 | // ============================================================================= |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
233 | LDObject* parseLine (str zLine) { |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
234 | vector<str> tokens = zLine.split (" ", true); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
235 | |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
236 | if (!tokens.size ()) { |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | // 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
|
238 | return new LDEmpty; |
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 | if (~tokens[0] != 1) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | 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
|
243 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | char const c = tokens[0][0]; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | switch (c - '0') { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | case 0: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | // Comment |
42
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
249 | str zComment = zLine.substr (2, -1); |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
250 | |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
251 | if (tokens.size() > 2 && tokens[1] == "!LDFORGE") { |
42
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
252 | // Handle LDForge-specific types, they're embedded into comments |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
253 | |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
254 | if (tokens[2] == "VERTEX") { |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
255 | // Vertex (0 !LDFORGE VERTEX) |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
256 | CHECK_TOKEN_COUNT (7) |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
257 | CHECK_TOKEN_NUMBERS (3, 6) |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
258 | |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
259 | LDVertex* obj = new LDVertex; |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
260 | obj->dColor = atol (tokens[3]); |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
261 | obj->vPosition.x = atof (tokens[4]); |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
262 | obj->vPosition.y = atof (tokens[5]); |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
263 | obj->vPosition.z = atof (tokens[6]); |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
264 | |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
265 | return obj; |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
266 | } |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
267 | } |
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
268 | |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | LDComment* obj = new LDComment; |
42
499c25af0303
Added code for parsing vertices
Santeri Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
270 | obj->zText = zComment; |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | case 1: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | // Subfile |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | CHECK_TOKEN_COUNT (15) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | 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
|
279 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | #ifndef WIN32 |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | tokens[14].replace ("\\", "/"); |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | #endif // WIN32 |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | // Try open the file |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
285 | 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
|
286 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | // 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
|
288 | if (!pFile) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | 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
|
290 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | LDSubfile* obj = new LDSubfile; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
292 | obj->dColor = atol (tokens[1]); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
293 | 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
|
294 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | 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
|
296 | 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
|
297 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | obj->zFileName = tokens[14]; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | obj->pFile = pFile; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | case 2: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | CHECK_TOKEN_COUNT (8) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | 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
|
307 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | // Line |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | LDLine* obj = new LDLine; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
310 | 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
|
311 | 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
|
312 | 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
|
313 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | case 3: |
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 | CHECK_TOKEN_COUNT (11) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | 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
|
320 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | // Triangle |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | LDTriangle* obj = new LDTriangle; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
323 | 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
|
324 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | 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
|
326 | 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
|
327 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
331 | case 4: |
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 | CHECK_TOKEN_COUNT (14) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | 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
|
335 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | // Quadrilateral |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | LDQuad* obj = new LDQuad; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
338 | 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
|
339 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | 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
|
341 | 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
|
342 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
346 | case 5: |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | { |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
348 | CHECK_TOKEN_COUNT (14) |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | 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
|
350 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | // Conditional line |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
352 | LDCondLine* obj = new LDCondLine; |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
55
diff
changeset
|
353 | 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
|
354 | |
40
215b9f8f0cd7
Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
355 | 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
|
356 | 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
|
357 | return obj; |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | } |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | |
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
360 | 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
|
361 | 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
|
362 | } |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
363 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
364 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
365 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
366 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
367 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
368 | OpenFile* loadSubfile (str zFile) { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
369 | // Try open the file |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
370 | OpenFile* pFile = findLoadedFile (zFile); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
371 | if (!pFile) |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
372 | pFile = openDATFile (zFile); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
373 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
374 | return pFile; |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
375 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
376 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
377 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
378 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
379 | // ============================================================================= |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
380 | void reloadAllSubfiles () { |
32
5d22b7ecf110
Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
381 | if (!g_CurrentFile) |
5d22b7ecf110
Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
382 | return; |
5d22b7ecf110
Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
383 | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
384 | // First, close all but the current open file. |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
385 | for (ushort i = 0; i < g_LoadedFiles.size(); ++i) |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
386 | if (g_LoadedFiles[i] != g_CurrentFile) |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
387 | g_LoadedFiles[i]->close(); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
388 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
389 | g_LoadedFiles.clear (); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
390 | g_LoadedFiles.push_back (g_CurrentFile); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
391 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
392 | // Go through all the current file and reload the subfiles |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
393 | for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
394 | LDObject* obj = g_CurrentFile->objects[i]; |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
395 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
396 | // Reload subfiles |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
397 | if (obj->getType() == OBJ_Subfile) { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
398 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
399 | OpenFile* pFile = loadSubfile (ref->zFileName); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
400 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
401 | if (pFile) |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
402 | ref->pFile = pFile; |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
403 | else { |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
404 | // Couldn't load the file, mark it an error |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
405 | 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
|
406 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
407 | } |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
408 | |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
409 | // 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
|
410 | // the file could not be opened. Circumstances may be different now. |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
411 | if (obj->getType() == OBJ_Gibberish) |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
412 | obj->replace (parseLine (static_cast<LDGibberish*> (obj)->zContents)); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
28
diff
changeset
|
413 | } |
38
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
414 | } |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
415 | |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
416 | // ============================================================================= |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
417 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
418 | // ============================================================================= |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
419 | void OpenFile::addObject (LDObject* obj) { |
39
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
38
diff
changeset
|
420 | if (this != g_CurrentFile) { |
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
38
diff
changeset
|
421 | objects.insert (objects.end (), obj); |
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
38
diff
changeset
|
422 | return; |
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
38
diff
changeset
|
423 | } |
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
38
diff
changeset
|
424 | |
38
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
425 | const ulong ulSpot = g_qWindow->getInsertionPoint (); |
20f5eaae8425
Implemented insertion of triangles, quads, condlines and comments
Santeri Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
426 | objects.insert (objects.begin() + ulSpot, obj); |
55
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
427 | } |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
428 | |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
429 | // ============================================================================= |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
430 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
431 | // ============================================================================= |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
432 | void OpenFile::forgetObject (LDObject* obj) { |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
433 | // Find the index for the given object |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
434 | ulong ulIndex; |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
435 | for (ulIndex = 0; ulIndex < (ulong)objects.size(); ++ulIndex) |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
436 | if (objects[ulIndex] == obj) |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
437 | break; // found it |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
438 | |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
439 | if (ulIndex >= objects.size ()) |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
440 | return; // was not found |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
441 | |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
442 | // Erase it from memory |
b08f10e668e5
Added clipboard, added delete action
Santeri Piippo <crimsondusk64@gmail.com>
parents:
46
diff
changeset
|
443 | objects.erase (objects.begin() + ulIndex); |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
444 | } |