src/parser.cpp

Sat, 24 Mar 2018 13:03:02 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 13:03:02 +0200
changeset 1328
d68d1ce89d05
parent 1326
69a90bd2dba2
child 1391
5fa4bf1fc781
permissions
-rw-r--r--

merged mathfunctions.cpp into algorithms/geometry.cpp

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
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1312
diff changeset
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"
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
28 /*
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
29 * Constructs an LDraw parser
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
30 */
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
31 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
32 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 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
34
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
35 /*
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
36 * Reads a single line from the device.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
37 */
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
38 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
39 {
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
40 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
41 }
d1e45f90654b Header parsing complete, 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
1295
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
43 const QMap<QString, decltype(LDHeader::type)> Parser::typeStrings {
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
44 {"Part", LDHeader::Part},
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
45 {"Subpart", LDHeader::Subpart},
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
46 {"Shortcut", LDHeader::Shortcut},
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
47 {"Primitive", LDHeader::Primitive},
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
48 {"8_Primitive", LDHeader::Primitive_8},
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
49 {"48_Primitive", LDHeader::Primitive_48},
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
50 {"Configuration", LDHeader::Configuration},
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
51 };
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
52
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
53 /*
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
54 * Parses a single line of the header.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
55 * Possible parse results:
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
56 * · ParseSuccess: the header line was parsed successfully.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
57 * · ParseFailure: the header line was parsed incorrectly and needs to be handled otherwise.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
58 * · StopParsing: the line does not belong in the header and header parsing needs to stop.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
59 */
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
60 Parser::HeaderParseResult Parser::parseHeaderLine(
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
61 LDHeader& header,
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
62 Winding& winding,
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
63 const QString& line
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
64 ) {
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
65 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
66 {
d1e45f90654b Header parsing complete, 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 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
68 }
d1e45f90654b Header parsing complete, 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 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
70 {
d1e45f90654b Header parsing complete, 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 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
72 }
d1e45f90654b Header parsing complete, 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 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
74 {
d1e45f90654b Header parsing complete, 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 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
76 .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
77 .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
78
d1e45f90654b Header parsing complete, 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 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
80 {
d1e45f90654b Header parsing complete, 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 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
82 // 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
83 // 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
84 // 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
85 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
86 partTypeString = partTypeString.mid(strlen("Unofficial_"));
1295
ac8f0297885b the header is now also saved
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 }
d1e45f90654b Header parsing complete, 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 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
98 {
d1e45f90654b Header parsing complete, 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 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
100 }
d1e45f90654b Header parsing complete, 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 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
103 {
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
104 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
105 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
106 }
d1e45f90654b Header parsing complete, 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 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
108 {
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
109 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
110 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
111 }
d1e45f90654b Header parsing complete, 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 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
113 {
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
114 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
115 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
116 }
d1e45f90654b Header parsing complete, 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 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
118 {
d1e45f90654b Header parsing complete, 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 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
120 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
121 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
122 };
d1e45f90654b Header parsing complete, 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 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
124 {
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
125 QString dateString = historyRegexp.capturedTexts().value(1);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
126 QString authorWithPrefix = historyRegexp.capturedTexts().value(2);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
127 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
128 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
129 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
130 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
131
d1e45f90654b Header parsing complete, 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 if (authorWithPrefix[0] == '{')
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
133 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
134 else
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
135 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
136
d1e45f90654b Header parsing complete, 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 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
138 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
139 }
d1e45f90654b Header parsing complete, 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 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
141 {
d1e45f90654b Header parsing complete, 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 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
143 }
d1e45f90654b Header parsing complete, 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 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
146 {
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
147 header.author = line.mid(strlen("0 Author: "));
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
148 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
149 }
d1e45f90654b Header parsing complete, 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 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
151 {
d1e45f90654b Header parsing complete, 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 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
153 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
154 }
d1e45f90654b Header parsing complete, 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 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
156 {
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
157 if (not header.help.isEmpty())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
158 header.help += "\n";
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
159 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
160 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
161 }
d1e45f90654b Header parsing complete, 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 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
163 {
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
164 if (not header.keywords.isEmpty())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
165 header.keywords += "\n";
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
166 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
167 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
168 }
d1e45f90654b Header parsing complete, 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 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
170 {
d1e45f90654b Header parsing complete, 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 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
172 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
173 }
d1e45f90654b Header parsing complete, 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 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
175 {
d1e45f90654b Header parsing complete, 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 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
177 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
178 }
d1e45f90654b Header parsing complete, 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 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
180 {
d1e45f90654b Header parsing complete, 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 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
182 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
183 }
d1e45f90654b Header parsing complete, 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 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
185 {
d1e45f90654b Header parsing complete, 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 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
187 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
188 }
d1e45f90654b Header parsing complete, 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 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
190 {
d1e45f90654b Header parsing complete, 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 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
192 }
d1e45f90654b Header parsing complete, 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
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
195 /*
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
196 * Parses the header from the device given at construction and returns
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
197 * the resulting header structure.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
198 */
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
199 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
200 {
d1e45f90654b Header parsing complete, 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 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
202
d1e45f90654b Header parsing complete, 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 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
204 {
d1e45f90654b Header parsing complete, 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 // 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
206 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
207 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
208 {
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents: 1289
diff changeset
209 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
210
d1e45f90654b Header parsing complete, 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 // 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
212 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
213 {
d1e45f90654b Header parsing complete, 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 const QString& line = this->readLine();
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1295
diff changeset
215 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
216
d1e45f90654b Header parsing complete, 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 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
218 {
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
219 // 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
220 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
221 }
d1e45f90654b Header parsing complete, 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 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
223 {
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
224 // 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
225 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
226 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
227 }
d1e45f90654b Header parsing complete, 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 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
231 {
d1e45f90654b Header parsing complete, 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 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
233 }
d1e45f90654b Header parsing complete, 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 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
237 }
d1e45f90654b Header parsing complete, 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
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
239 /*
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
240 * Parses the model body into the given model.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
241 */
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
242 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
243 {
d1e45f90654b Header parsing complete, 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 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
245
d1e45f90654b Header parsing complete, 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 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
247 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
248
d1e45f90654b Header parsing complete, 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 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
250 {
d1e45f90654b Header parsing complete, 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 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
252 {
d1e45f90654b Header parsing complete, 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 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
254 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
255 }
d1e45f90654b Header parsing complete, 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 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
258
d1e45f90654b Header parsing complete, 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 // 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
261 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
262 {
d1e45f90654b Header parsing complete, 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 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
264 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
265 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
266 ++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
267 }
d1e45f90654b Header parsing complete, 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 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
271 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
272
d1e45f90654b Header parsing complete, 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 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
274 }
d1e45f90654b Header parsing complete, 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 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
280 {
d1e45f90654b Header parsing complete, 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 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
282 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
283 }
d1e45f90654b Header parsing complete, 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 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
288 {
d1e45f90654b Header parsing complete, 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 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
290 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
291
d1e45f90654b Header parsing complete, 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 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
293 {
d1e45f90654b Header parsing complete, 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 // 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
295 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
296 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
297 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
298
d1e45f90654b Header parsing complete, 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 // 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
300 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
301 {
d1e45f90654b Header parsing complete, 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 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
303
d1e45f90654b Header parsing complete, 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 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
305 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
306 }
d1e45f90654b Header parsing complete, 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 // 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
309 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
310 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
311
d1e45f90654b Header parsing complete, 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 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
313 (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
314 }
d1e45f90654b Header parsing complete, 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 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
318 {
d1e45f90654b Header parsing complete, 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 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
320 }
d1e45f90654b Header parsing complete, 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
1289
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
322 /*
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
323 * Parses the given model body line and inserts the result into the given model.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
324 * The resulting object is also returned.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
325 *
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
326 * If an error happens, an error object is created. Result is guaranteed to be a valid pointer.
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
327 *
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
328 * TODO: rewrite this using regular expressions
ec5a38d19cf5 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
329 */
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
330 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
331 {
d1e45f90654b Header parsing complete, 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 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
333 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
334
d1e45f90654b Header parsing complete, 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 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
336 {
d1e45f90654b Header parsing complete, 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 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
338
d1e45f90654b Header parsing complete, 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 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
340 {
d1e45f90654b Header parsing complete, 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 // 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
342 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
343 }
d1e45f90654b Header parsing complete, 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 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
346 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
347
d1e45f90654b Header parsing complete, 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 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
349
d1e45f90654b Header parsing complete, 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 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
351 {
d1e45f90654b Header parsing complete, 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 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
353 {
d1e45f90654b Header parsing complete, 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 // 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
355 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
356
d1e45f90654b Header parsing complete, 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 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
358 {
d1e45f90654b Header parsing complete, 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 // 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
360 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
361 {
d1e45f90654b Header parsing complete, 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 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
363 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
364 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
365 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
366
d1e45f90654b Header parsing complete, 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 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
368 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
369
d1e45f90654b Header parsing complete, 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 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
371 }
d1e45f90654b Header parsing complete, 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 // 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
375 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
376 }
d1e45f90654b Header parsing complete, 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 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
379 {
d1e45f90654b Header parsing complete, 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 // 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
381 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
382 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
383
d1e45f90654b Header parsing complete, 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 Vertex referncePosition = parseVertex (tokens, 2); // 2 - 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
385 Matrix transform;
d1e45f90654b Header parsing complete, 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
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
387 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
388 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
389
d1e45f90654b Header parsing complete, 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 LDSubfileReference* obj = model.emplaceAt<LDSubfileReference>(position, tokens[14], transform, referncePosition);
d1e45f90654b Header parsing complete, 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 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
392 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
393 }
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
394
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
395 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
396 {
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
397 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
398 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
399
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
400 // 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
401 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
402 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
403
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
404 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
405 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
406
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
407 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
408 }
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
409
d1e45f90654b Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
410 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
411 {
d1e45f90654b Header parsing complete, 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 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
413 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
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 // 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
416 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
417 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
418
d1e45f90654b Header parsing complete, 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 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
420 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
421
d1e45f90654b Header parsing complete, 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 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
423 }
d1e45f90654b Header parsing complete, 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 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
426 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
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 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
429 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
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 // 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
432 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
433
d1e45f90654b Header parsing complete, 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 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
435 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
436 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
437 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
438
d1e45f90654b Header parsing complete, 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 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
440
d1e45f90654b Header parsing complete, 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 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
442 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
443
d1e45f90654b Header parsing complete, 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 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
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
d1e45f90654b Header parsing complete, 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 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
448 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
449 }
d1e45f90654b Header parsing complete, 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 }
d1e45f90654b Header parsing complete, 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 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
452 {
d1e45f90654b Header parsing complete, 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 // 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
454 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
455 }
d1e45f90654b Header parsing complete, 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 }

mercurial