src/header.cpp

Mon, 16 May 2022 01:40:49 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 16 May 2022 01:40:49 +0300
changeset 187
30204975694a
parent 140
2f383e88acf4
permissions
-rw-r--r--

work on circle tool

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

mercurial