| |
1 #include "ldHeader.h" |
| |
2 |
| |
3 static const char* g_PartTypeNames[PARTTYPE_NUM_TYPES] = |
| |
4 { |
| |
5 "Part", |
| |
6 "Subpart", |
| |
7 "Primitive", |
| |
8 "48_Primitive", |
| |
9 "Shortcut", |
| |
10 "Unofficial_Part", |
| |
11 "Unofficial_Subpart", |
| |
12 "Unofficial_Primitive", |
| |
13 "Unofficial_48_Primitive", |
| |
14 "Unofficial_Shortcut", |
| |
15 }; |
| |
16 |
| |
17 static const char g_HeaderBFCNames[] = |
| |
18 { |
| |
19 "CCW", |
| |
20 "CW", |
| |
21 "NOCERTIFY", |
| |
22 } |
| |
23 |
| |
24 QString LDHeader::serialize() const |
| |
25 { |
| |
26 QStringList result; |
| |
27 |
| |
28 // Title, name and part type |
| |
29 result << m_title; |
| |
30 result << "Name:" + m_name; |
| |
31 result << format ("0 !LDRAW_ORG %1 %2", g_PartTypeNames[int (partType())], qualifiers()) |
| |
32 |
| |
33 // License (if any, heh) |
| |
34 if (not license().isEmpty()) |
| |
35 result << "0 !LICENSE " + license(); |
| |
36 |
| |
37 // Help text, if any |
| |
38 if (not help().isEmpty()) |
| |
39 { |
| |
40 result << ""; |
| |
41 |
| |
42 for (QString const& a : keywords()) |
| |
43 result << "0 !HELP " + a; |
| |
44 } |
| |
45 |
| |
46 // BFC type - specs say this isn't mandatory for NOCERTIFY parts but |
| |
47 // highly recommended, so we'll add it in. |
| |
48 result << ""; |
| |
49 result << "0 BFC " + g_HeaderBFCNames[int (headerBFC())]; |
| |
50 |
| |
51 // Category, if present |
| |
52 if (not category().isEmpty()) |
| |
53 { |
| |
54 result << ""; |
| |
55 result << "0 !CATEGORY " + category(); |
| |
56 } |
| |
57 |
| |
58 // Keywords, if any |
| |
59 if (not keywords.isEmpty()) |
| |
60 { |
| |
61 if (category.isEmpty()) |
| |
62 result << ""; |
| |
63 |
| |
64 for (QString const& a : keywords()) |
| |
65 result << "0 !KEYWORDS " + a; |
| |
66 } |
| |
67 |
| |
68 // Command line, if any |
| |
69 if (not commandLine().isEmpty()) |
| |
70 result << "" << "0 !CMDLINE " + commandLine(); |
| |
71 |
| |
72 // History entries, if any |
| |
73 if (not history().isEmpty()) |
| |
74 { |
| |
75 result << ""; |
| |
76 |
| |
77 for (LDHistoryEntry const& a : history()) |
| |
78 result << a.serialize(); |
| |
79 } |
| |
80 |
| |
81 // Comments, if any |
| |
82 if (not comments().isEmpty()) |
| |
83 { |
| |
84 result << ""; |
| |
85 |
| |
86 for (QString const& a : comments()) |
| |
87 result << "0 // " + a; |
| |
88 } |
| |
89 |
| |
90 result << ""; |
| |
91 QString resultText; |
| |
92 |
| |
93 // Wrap it all up into a single string |
| |
94 for (QString a : result) |
| |
95 { |
| |
96 // Remove trailing space |
| |
97 while (a.right (1) == " ") |
| |
98 a.chop (1); |
| |
99 |
| |
100 result += a + "\r\n"; |
| |
101 } |
| |
102 |
| |
103 return result; |
| |
104 } |
| |
105 |
| |
106 bool LDHeader::isUnofficial() const |
| |
107 { |
| |
108 return m_partType >= PARTTYPE_FIRST_UNOFFICIAL; |
| |
109 } |
| |
110 |
| |
111 void LDHeader::makeUnofficial() |
| |
112 { |
| |
113 if (not isUnofficial()) |
| |
114 m_partType += PARTTYPE_FIRST_UNOFFICIAL; |
| |
115 } |
| |
116 |
| |
117 void LDHeader::makeOfficial() |
| |
118 { |
| |
119 if (isUnofficial()) |
| |
120 m_partType -= PARTTYPE_FIRST_UNOFFICIAL; |
| |
121 } |
| |
122 |
| |
123 LDHistoryEntry::LDHistoryEntry() : |
| |
124 m_isRealName (false) {} |
| |
125 |
| |
126 QString LDHistoryEntry::serialize() const |
| |
127 { |
| |
128 QString userblock; |
| |
129 |
| |
130 if (isRealName()) |
| |
131 userblock = format ("{%1}", username()); |
| |
132 else |
| |
133 userblock = format ("[%1]", username()); |
| |
134 |
| |
135 return format ("0 !HISTORY %1 %2 %3", date().toString ("yyyy-MM-dd"), userblock, description); |
| |
136 } |