src/model.cpp

Sun, 09 Apr 2023 16:27:22 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 09 Apr 2023 16:27:22 +0300
changeset 366
ea656dead697
parent 338
719b909a7d2b
child 374
75efc3ba5a56
permissions
-rw-r--r--

Also connect up "Select all"

24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
1 /*
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
2 * LDForge: LDraw parts authoring CAD
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
4 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
6 * it under the terms of the GNU General Public License as published by
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
8 * (at your option) any later version.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
9 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
10 * This program is distributed in the hope that it will be useful,
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
13 * GNU General Public License for more details.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
14 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
15 * You should have received a copy of the GNU General Public License
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
17 */
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
18
208
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
19 #include <QPixmap>
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
20 #include "src/model.h"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
22 constexpr unsigned int gcd(unsigned int a, unsigned int b)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
23 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
24 while (a != b) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
25 if (b > a) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
26 b -= a;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
27 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
28 else if (a > b) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
29 a -= b;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
30 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
31 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
32 return a;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
33 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
34
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
35 static_assert(gcd(16, 15) == 1);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
36 static_assert(gcd(16, 4) == 4);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
37 static_assert(gcd(272, 192) == 16);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
38
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
39 static constexpr const char* circularPrimitiveTypeString(const CircularPrimitive& circ)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
40 {
242
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
41 return circularPrimitiveStems[circ.type];
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
42 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
43
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
44 static QString circularPrimitiveFilePath(const CircularPrimitive& circ)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
45 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
46 QString result;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
47 if (circ.fraction.divisions != 16) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
48 result += QString::number(circ.fraction.divisions) + QStringLiteral("\\");
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
49 }
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 242
diff changeset
50 const unsigned int factor = gcd(circ.fraction.segments, circ.fraction.divisions);
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 242
diff changeset
51 unsigned int num = circ.fraction.segments / factor;
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 242
diff changeset
52 unsigned int denom = circ.fraction.divisions / factor;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
53 if (denom < 4) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
54 num *= 4 / denom;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
55 denom = 4;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
56 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
57 result += QStringLiteral("%1-%2").arg(num).arg(denom);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
58 result += QString::fromLatin1(circularPrimitiveTypeString(circ));
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
59 result += QStringLiteral(".dat");
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
60 return result;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
61 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
62
208
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
63 static const char* iconPathForElement(const ModelElement& element)
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
64 {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
65 return std::visit(overloaded{
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
66 [](const Colored<SubfileReference>&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
67 return ":/icons/linetype-subfile.png";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
68 },
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
69 [](const Colored<LineSegment>&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
70 return ":/icons/linetype-edgeline.png";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
71 },
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
72 [](const Colored<Triangle>&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
73 return ":/icons/linetype-triangle.png";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
74 },
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
75 [](const Colored<Quadrilateral>&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
76 return ":/icons/linetype-quadrilateral.png";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
77 },
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
78 [](const Colored<ConditionalEdge>&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
79 return ":/icons/linetype-conditionaledge.png";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
80 },
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
81 [](const Colored<CircularPrimitive>&) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
82 return ":/icons/linetype-circularprimitive.png";
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
83 },
208
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
84 [](const Comment&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
85 return ":/icons/chatbubble-ellipses-outline.png";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
86 },
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
87 [](const Empty&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
88 return "";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
89 },
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
90 [](const ParseError&) {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
91 return ":/icons/linetype-errorline.png";
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
92 },
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
93 }, element);
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
94 }
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
95
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
96 static QPixmap iconForElement(const ModelElement& element)
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
97 {
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
98 // We avoid processing the same image over and over again by storing it
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
99 // in a static constant. However, we need one per each possible type
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
100 // of ModelElement, so we put the pixmap constant inside a templated lambda,
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
101 // which gets instiated once for each type of ModelElement.
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
102 return std::visit([](auto&& element){
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
103 static const QPixmap pixmap = QPixmap::fromImage(
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
104 QImage{iconPathForElement(element)}
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
105 .scaledToHeight(24, Qt::SmoothTransformation)
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
106 );
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
107 return pixmap;
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
108 }, element);
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
109 }
930928b760a2 Add model icons back into the list view
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
110
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
111 QString modelElementToString(const ModelElement &element)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
112 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
113 return std::visit(overloaded{
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
114 [](const Colored<SubfileReference>& ref) {
326
65dbfcb859a7 Add missing 0 BFC INVERTNEXT when writing out subfile references
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
115 QString result;
65dbfcb859a7 Add missing 0 BFC INVERTNEXT when writing out subfile references
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
116 result += QStringLiteral("1 %1 %2 %3")
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
117 .arg(ref.color.index)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
118 .arg(transformToString(ref.transformation))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
119 .arg(ref.name);
326
65dbfcb859a7 Add missing 0 BFC INVERTNEXT when writing out subfile references
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
120 return result;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
121 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
122 [](const Colored<LineSegment>& seg) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
123 return QStringLiteral("2 %1 %2 %3")
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
124 .arg(seg.color.index)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
125 .arg(vertexToString(seg.p1))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
126 .arg(vertexToString(seg.p2));
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
127 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
128 [](const Colored<Triangle>& triangle) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
129 return QStringLiteral("3 %1 %2 %3 %4")
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
130 .arg(triangle.color.index)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
131 .arg(vertexToString(triangle.p1))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
132 .arg(vertexToString(triangle.p2))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
133 .arg(vertexToString(triangle.p3));
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
134 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
135 [](const Colored<Quadrilateral>& quad) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
136 return QStringLiteral("4 %1 %2 %3 %4 %5")
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
137 .arg(quad.color.index)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
138 .arg(vertexToString(quad.p1))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
139 .arg(vertexToString(quad.p2))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
140 .arg(vertexToString(quad.p3))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
141 .arg(vertexToString(quad.p4));
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
142 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
143 [](const Colored<ConditionalEdge>& cedge) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
144 return QStringLiteral("5 %1 %2 %3 %4 %5")
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
145 .arg(cedge.color.index)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
146 .arg(vertexToString(cedge.p1))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
147 .arg(vertexToString(cedge.p2))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
148 .arg(vertexToString(cedge.c1))
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
149 .arg(vertexToString(cedge.c2));
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
150 },
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
151 [](const Colored<CircularPrimitive>& circ) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
152 return QStringLiteral("1 %1 %2 %3")
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
153 .arg(circ.color.index)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
154 .arg(transformToString(circ.transformation))
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
155 .arg(circularPrimitiveFilePath(circ));
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 208
diff changeset
156 },
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
157 [](const Comment& comment) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
158 return "0 " + comment.text;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
159 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
160 [](const Empty&) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
161 return QStringLiteral("");
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
162 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
163 [](const ParseError& parseError) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
164 return parseError.code;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
165 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
166 }, element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
167 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
168
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
169 template<typename K, typename V>
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
170 void removeFromMap(std::map<K, V>& map, const K& key)
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
171 {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
172 const auto it = map.find(key);
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
173 if (it != map.end()) {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
174 map.erase(it);
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
175 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
176 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
177
137
fb9990772357 Add documentation to model.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 133
diff changeset
178 /**
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
179 * @brief Sets the path to the model
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
180 * @param path New path to use
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
181 */
338
719b909a7d2b Delete unused code
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 335
diff changeset
182 void updateHeaderNameField(QTextDocument& model, const QString &name)
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
183 {
333
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 329
diff changeset
184 #if 0
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
185 // Update the "Name: 1234.dat" comment
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
186 if (model.size() >= 2) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
187 if (const Comment* nameObject = std::get_if<Comment>(&model[1])) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
188 if (nameObject->text.startsWith("Name: ")) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
189 model[1] = Comment{"Name: " + name};
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
190 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
191 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
192 }
333
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 329
diff changeset
193 #endif
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 140
diff changeset
194 }

mercurial