Thu, 03 Mar 2022 11:42:52 +0200
extract polygon cache out of Model
140 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2020 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #include "header.h" | |
20 | ||
21 | const QString LDHeader::caLicenseString = "0 !LICENSE Redistributable under CCAL version 2.0"; | |
22 | const QString LDHeader::nonCaLicenseString = "0 !LICENSE Not redistributable"; | |
23 | ||
24 | static const QMap<QString, LDHeader::FileType> typeStrings = { | |
25 | {"Part", LDHeader::Part}, | |
26 | {"Subpart", LDHeader::Subpart}, | |
27 | {"Shortcut", LDHeader::Shortcut}, | |
28 | {"Primitive", LDHeader::Primitive}, | |
29 | {"8_Primitive", LDHeader::Primitive_8}, | |
30 | {"48_Primitive", LDHeader::Primitive_48}, | |
31 | {"Configuration", LDHeader::Configuration}, | |
32 | }; | |
33 | ||
34 | QString headerTypeToString(const LDHeader::FileType fileType) | |
35 | { | |
36 | QMapIterator<QString, LDHeader::FileType> it{::typeStrings}; | |
37 | while (it.hasNext()) | |
38 | { | |
39 | it.next(); | |
40 | if (it.value() == fileType) | |
41 | { | |
42 | return it.key(); | |
43 | } | |
44 | } | |
45 | return "Part"; | |
46 | } | |
47 | ||
48 | LDHeader::FileType headerTypeFromString(const QString& string) | |
49 | { | |
50 | return ::typeStrings.value(string, LDHeader::Part); | |
51 | } | |
52 | ||
53 | QString headerToString(const LDHeader& header) | |
54 | { | |
55 | QString result; | |
56 | result += "0 " + header.description + "\r\n"; | |
57 | result += "Name: " + header.name + "\r\n"; | |
58 | result += "Author: " + header.author + "\r\n"; | |
59 | if (header.type != LDHeader::NoHeader) | |
60 | { | |
61 | result += "0 !LDRAW Unofficial_" + headerTypeToString(header.type) + "\r\n"; | |
62 | } | |
63 | switch (header.license) | |
64 | { | |
65 | case LDHeader::UnspecifiedLicense: | |
66 | break; | |
67 | case LDHeader::CaLicense: | |
68 | result += LDHeader::caLicenseString + "\r\n"; | |
69 | break; | |
70 | case LDHeader::NonCaLicense: | |
71 | result += LDHeader::nonCaLicenseString + "\r\n"; | |
72 | break; | |
73 | } | |
74 | if (not header.help.isEmpty()) | |
75 | { | |
76 | result += "\r\n"; | |
77 | for (const QString& helpLine : header.help.split("\n")) | |
78 | { | |
79 | result += "0 !HELP " + helpLine + "\r\n"; | |
80 | } | |
81 | } | |
82 | result += "\r\n"; | |
83 | // FIXME: continue | |
84 | return result; | |
85 | } |