Mon, 04 Jun 2018 23:12:40 +0300
added work done on cylinders
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | /* |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | * |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | * |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | * |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | */ |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #include "parser.h" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include "lddocument.h" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include "linetypes/comment.h" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "linetypes/conditionaledge.h" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | #include "linetypes/edgeline.h" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | #include "linetypes/empty.h" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | #include "linetypes/quadrilateral.h" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | #include "linetypes/triangle.h" |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
27 | #include "linetypes/cylinder.h" |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | |
1289 | 29 | /* |
30 | * Constructs an LDraw parser | |
31 | */ | |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | Parser::Parser(QIODevice& device, QObject* parent) : |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | QObject {parent}, |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | device {device} {} |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | |
1289 | 36 | /* |
37 | * Reads a single line from the device. | |
38 | */ | |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | QString Parser::readLine() |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | { |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
41 | return QString::fromUtf8(this->device.readLine()).trimmed(); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | |
1295
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
44 | const QMap<QString, decltype(LDHeader::type)> Parser::typeStrings { |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
45 | {"Part", LDHeader::Part}, |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
46 | {"Subpart", LDHeader::Subpart}, |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
47 | {"Shortcut", LDHeader::Shortcut}, |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
48 | {"Primitive", LDHeader::Primitive}, |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
49 | {"8_Primitive", LDHeader::Primitive_8}, |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
50 | {"48_Primitive", LDHeader::Primitive_48}, |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
51 | {"Configuration", LDHeader::Configuration}, |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
52 | }; |
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
53 | |
1289 | 54 | /* |
55 | * Parses a single line of the header. | |
56 | * Possible parse results: | |
57 | * · ParseSuccess: the header line was parsed successfully. | |
58 | * · ParseFailure: the header line was parsed incorrectly and needs to be handled otherwise. | |
59 | * · StopParsing: the line does not belong in the header and header parsing needs to stop. | |
60 | */ | |
1306
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
61 | Parser::HeaderParseResult Parser::parseHeaderLine( |
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
62 | LDHeader& header, |
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
63 | Winding& winding, |
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
64 | const QString& line |
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
65 | ) { |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | if (line.isEmpty()) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | else if (not line.startsWith("0") or line.startsWith("0 //")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | return StopParsing; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | else if (line.startsWith("0 !LDRAW_ORG ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | QStringList tokens = line |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | .mid(strlen("0 !LDRAW_ORG ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | .split(" ", QString::SkipEmptyParts); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | if (not tokens.isEmpty()) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | QString partTypeString = tokens[0]; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | // Anything that enters LDForge becomes unofficial in any case if saved. |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | // Therefore we don't need to give the Unofficial type any special |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | // consideration. |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | if (partTypeString.startsWith("Unofficial_")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | partTypeString = partTypeString.mid(strlen("Unofficial_")); |
1295
ac8f0297885b
the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
88 | header.type = Parser::typeStrings.value(partTypeString, LDHeader::Part); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | header.qualfiers = 0; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | if (tokens.contains("Alias")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
91 | header.qualfiers |= LDHeader::Alias; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
92 | if (tokens.contains("Physical_Color")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | header.qualfiers |= LDHeader::Physical_Color; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
94 | if (tokens.contains("Flexible_Section")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
95 | header.qualfiers |= LDHeader::Flexible_Section; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
98 | else |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
99 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
100 | return ParseFailure; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
102 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
103 | else if (line == "0 BFC CERTIFY CCW") |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
104 | { |
1306
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
105 | winding = CounterClockwise; |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
106 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
107 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
108 | else if (line == "0 BFC CERTIFY CW") |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
109 | { |
1306
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
110 | winding = Clockwise; |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
111 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
112 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
113 | else if (line == "0 BFC NOCERTIFY") |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
114 | { |
1306
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
115 | winding = NoWinding; |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
116 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
117 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
118 | else if (line.startsWith("0 !HISTORY ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
119 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
120 | static const QRegExp historyRegexp { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
121 | R"(0 !HISTORY\s+(\d{4}-\d{2}-\d{2})\s+)" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
122 | R"((\{[^}]+|\[[^]]+)[\]}]\s+(.+))" |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
123 | }; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
124 | if (historyRegexp.exactMatch(line)) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
125 | { |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
126 | QString dateString = historyRegexp.capturedTexts().value(1); |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
127 | QString authorWithPrefix = historyRegexp.capturedTexts().value(2); |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
128 | QString description = historyRegexp.capturedTexts().value(3); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
129 | LDHeader::HistoryEntry historyEntry; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
130 | historyEntry.date = QDate::fromString(dateString, Qt::ISODate); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
131 | historyEntry.description = description; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
132 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
133 | if (authorWithPrefix[0] == '{') |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
134 | historyEntry.author = authorWithPrefix + "}"; |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
135 | else |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
136 | historyEntry.author = authorWithPrefix.mid(1); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
137 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
138 | header.history.append(historyEntry); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
139 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
140 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
141 | else |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
142 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
143 | return ParseFailure; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
144 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
145 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
146 | else if (line.startsWith("0 Author: ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
147 | { |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
148 | header.author = line.mid(strlen("0 Author: ")); |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
149 | return ParseSuccess; |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
150 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
151 | else if (line.startsWith("0 Name: ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
152 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
153 | header.name = line.mid(strlen("0 Name: ")); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
154 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
155 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
156 | else if (line.startsWith("0 !HELP ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
157 | { |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
158 | if (not header.help.isEmpty()) |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
159 | header.help += "\n"; |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
160 | header.help += line.mid(strlen("0 !HELP ")); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
161 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
162 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
163 | else if (line.startsWith("0 !KEYWORDS ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
164 | { |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
165 | if (not header.keywords.isEmpty()) |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
166 | header.keywords += "\n"; |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
167 | header.keywords += line.mid(strlen("0 !KEYWORDS ")); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
168 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
169 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
170 | else if (line.startsWith("0 !CATEGORY ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
171 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
172 | header.category = line.mid(strlen("0 !CATEGORY ")); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
173 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
174 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
175 | else if (line.startsWith("0 !CMDLINE ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
176 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
177 | header.cmdline = line.mid(strlen("0 !CMDLINE ")); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
178 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
179 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
180 | else if (line.startsWith("0 !LICENSE Redistributable under CCAL version 2.0")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
181 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
182 | header.license = LDHeader::CaLicense; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
183 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
184 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
185 | else if (line.startsWith("0 !LICENSE Not redistributable")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
186 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
187 | header.license = LDHeader::NonCaLicense; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
188 | return ParseSuccess; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
189 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
190 | else |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
191 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
192 | return ParseFailure; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
193 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
194 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
195 | |
1289 | 196 | /* |
197 | * Parses the header from the device given at construction and returns | |
198 | * the resulting header structure. | |
199 | */ | |
1306
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
200 | LDHeader Parser::parseHeader(Winding& winding) |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
201 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
202 | LDHeader header = {}; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
203 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
204 | if (not this->device.atEnd()) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
205 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
206 | // Parse the description |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
207 | QString descriptionLine = this->readLine(); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
208 | if (descriptionLine.startsWith("0 ")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
209 | { |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1289
diff
changeset
|
210 | header.description = descriptionLine.mid(strlen("0 ")).trimmed(); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
211 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
212 | // Parse the rest of the header |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
213 | while (not this->device.atEnd()) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
214 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
215 | const QString& line = this->readLine(); |
1306
be85306198a2
red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents:
1295
diff
changeset
|
216 | auto result = parseHeaderLine(header, winding, line); |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
217 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
218 | if (result == ParseFailure) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
219 | { |
1289 | 220 | // Failed to parse this header line, add it as a comment into the body later. |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
221 | this->bag.append(line); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
222 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
223 | else if (result == StopParsing) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
224 | { |
1289 | 225 | // Header parsing stops, add this line to the body. |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
226 | this->bag.append(line); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
227 | break; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
228 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
229 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
230 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
231 | else |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
232 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
233 | this->bag.append(descriptionLine); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
234 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
235 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
236 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
237 | return header; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
238 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
239 | |
1289 | 240 | /* |
241 | * Parses the model body into the given model. | |
242 | */ | |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
243 | void Parser::parseBody(Model& model) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
244 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
245 | bool invertNext = false; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
246 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
247 | while (not this->device.atEnd()) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
248 | this->bag.append(this->readLine()); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
249 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
250 | for (const QString& line : this->bag) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
251 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
252 | if (line == "0 BFC INVERTNEXT" or line == "0 BFC CERTIFY INVERTNEXT") |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
253 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
254 | invertNext = true; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
255 | continue; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
256 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
257 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
258 | LDObject* object = parseFromString(model, model.size(), line); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
259 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
260 | /* |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
261 | // Check for parse errors and warn about them |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
262 | if (obj->type() == LDObjectType::Error) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
263 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
264 | emit parseErrorMessage(format( |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
265 | tr("Couldn't parse line #%1: %2"), |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
266 | progress() + 1, static_cast<LDError*> (obj)->reason())); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
267 | ++m_warningCount; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
268 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
269 | */ |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
270 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
271 | if (invertNext and object->type() == LDObjectType::SubfileReference) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
272 | object->setInverted(true); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
273 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
274 | invertNext = false; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
275 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
276 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
277 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
278 | // ============================================================================= |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
279 | // |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
280 | static void CheckTokenCount (const QStringList& tokens, int num) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
281 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
282 | if (countof(tokens) != num) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
283 | throw QString (format ("Bad amount of tokens, expected %1, got %2", num, countof(tokens))); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
284 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
285 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
286 | // ============================================================================= |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
287 | // |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
288 | static void CheckTokenNumbers (const QStringList& tokens, int min, int max) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
289 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
290 | bool ok; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
291 | QRegExp scientificRegex ("\\-?[0-9]+\\.[0-9]+e\\-[0-9]+"); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
292 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
293 | for (int i = min; i <= max; ++i) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
294 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
295 | // Check for floating point |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
296 | tokens[i].toDouble (&ok); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
297 | if (ok) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
298 | return; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
299 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
300 | // Check hex |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
301 | if (tokens[i].startsWith ("0x")) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
302 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
303 | tokens[i].mid (2).toInt (&ok, 16); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
304 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
305 | if (ok) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
306 | return; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
307 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
308 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
309 | // Check scientific notation, e.g. 7.99361e-15 |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
310 | if (scientificRegex.exactMatch (tokens[i])) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
311 | return; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
312 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
313 | throw QString (format ("Token #%1 was `%2`, expected a number (matched length: %3)", |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
314 | (i + 1), tokens[i], scientificRegex.matchedLength())); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
315 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
316 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
317 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
318 | static Vertex parseVertex(QStringList& tokens, const int n) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
319 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
320 | return {tokens[n].toDouble(), tokens[n + 1].toDouble(), tokens[n + 2].toDouble()}; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
321 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
322 | |
1289 | 323 | /* |
324 | * Parses the given model body line and inserts the result into the given model. | |
325 | * The resulting object is also returned. | |
326 | * | |
327 | * If an error happens, an error object is created. Result is guaranteed to be a valid pointer. | |
328 | * | |
329 | * TODO: rewrite this using regular expressions | |
330 | */ | |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
331 | LDObject* Parser::parseFromString(Model& model, int position, QString line) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
332 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
333 | if (position == EndOfModel) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
334 | position = model.size(); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
335 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
336 | try |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
337 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
338 | QStringList tokens = line.split(" ", QString::SkipEmptyParts); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
339 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
340 | if (tokens.isEmpty()) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
341 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
342 | // Line was empty, or only consisted of whitespace |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
343 | return model.emplaceAt<LDEmpty>(position); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
344 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
345 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
346 | if (countof(tokens[0]) != 1 or not tokens[0][0].isDigit()) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
347 | throw QString ("Illogical line code"); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
348 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
349 | int num = tokens[0][0].digitValue(); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
350 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
351 | switch (num) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
352 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
353 | case 0: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
354 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
355 | // Comment |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
356 | QString commentText = line.mid(line.indexOf("0") + 2); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
357 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
358 | if (countof(tokens) > 2 and tokens[1] == "!LDFORGE") |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
359 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
360 | // Handle LDForge-specific types, they're embedded into comments too |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
361 | if (tokens[2] == "BEZIER_CURVE") |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
362 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
363 | CheckTokenCount (tokens, 16); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
364 | CheckTokenNumbers (tokens, 3, 15); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
365 | LDBezierCurve* obj = model.emplaceAt<LDBezierCurve>(position); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
366 | obj->setColor(tokens[3].toInt(nullptr, 0)); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
367 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
368 | for (int i = 0; i < 4; ++i) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
369 | obj->setVertex (i, parseVertex (tokens, 4 + (i * 3))); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
370 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
371 | return obj; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
372 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
373 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
374 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
375 | // Just a regular comment: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
376 | return model.emplaceAt<LDComment>(position, commentText); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
377 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
378 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
379 | case 1: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
380 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
381 | // Subfile |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
382 | CheckTokenCount (tokens, 15); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
383 | CheckTokenNumbers (tokens, 1, 13); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
384 | |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
385 | Vertex displacement = parseVertex (tokens, 2); // 2 - 4 |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
386 | Matrix transform; |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
387 | QString referenceName = tokens[14]; |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
388 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
389 | for (int i = 0; i < 9; ++i) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
390 | transform.value(i) = tokens[i + 5].toDouble(); // 5 - 13 |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
391 | |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
392 | static const QRegExp cylinderRegexp {R"((?:(\d+)\\)?(\d+)-(\d+)cyli\.dat)"}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
393 | LDObject* obj; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
394 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
395 | if (cylinderRegexp.exactMatch(referenceName)) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
396 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
397 | int resolution = MediumResolution; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
398 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
399 | if (not cylinderRegexp.capturedTexts()[1].isEmpty()) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
400 | resolution = cylinderRegexp.capturedTexts()[1].toInt(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
401 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
402 | int numerator = cylinderRegexp.capturedTexts()[2].toInt(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
403 | int denominator = cylinderRegexp.capturedTexts()[3].toInt(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
404 | int segments = (numerator * resolution) / denominator; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
405 | obj = model.emplaceAt<LDCylinder>(position, segments, resolution, transform, displacement); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
406 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
407 | else |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
408 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
409 | obj = model.emplaceAt<LDSubfileReference>(position, referenceName, transform, displacement); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
410 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
411 | |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
412 | obj->setColor (tokens[1].toInt(nullptr, 0)); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
413 | return obj; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
414 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
415 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
416 | case 2: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
417 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
418 | CheckTokenCount (tokens, 8); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
419 | CheckTokenNumbers (tokens, 1, 7); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
420 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
421 | // Line |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
422 | LDEdgeLine* obj = model.emplaceAt<LDEdgeLine>(position); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
423 | obj->setColor (tokens[1].toInt(nullptr, 0)); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
424 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
425 | for (int i = 0; i < 2; ++i) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
426 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7 |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
427 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
428 | return obj; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
429 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
430 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
431 | case 3: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
432 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
433 | CheckTokenCount (tokens, 11); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
434 | CheckTokenNumbers (tokens, 1, 10); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
435 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
436 | // Triangle |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
437 | LDTriangle* obj = model.emplaceAt<LDTriangle>(position); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
438 | obj->setColor (tokens[1].toInt(nullptr, 0)); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
439 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
440 | for (int i = 0; i < 3; ++i) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
441 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10 |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
442 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
443 | return obj; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
444 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
445 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
446 | case 4: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
447 | case 5: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
448 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
449 | CheckTokenCount (tokens, 14); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
450 | CheckTokenNumbers (tokens, 1, 13); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
451 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
452 | // Quadrilateral / Conditional line |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
453 | LDObject* obj; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
454 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
455 | if (num == 4) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
456 | obj = model.emplaceAt<LDQuadrilateral>(position); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
457 | else |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
458 | obj = model.emplaceAt<LDConditionalEdge>(position); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
459 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
460 | obj->setColor (tokens[1].toInt(nullptr, 0)); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
461 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
462 | for (int i = 0; i < 4; ++i) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
463 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13 |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
464 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
465 | return obj; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
466 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
467 | |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
468 | default: |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
469 | throw QString {"Unknown line code number"}; |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
470 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
471 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
472 | catch (QString& errorMessage) |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
473 | { |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
474 | // Strange line we couldn't parse |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
475 | return model.emplaceAt<LDError>(position, line, errorMessage); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
476 | } |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
477 | } |