src/ldrawalgorithm.cpp

Tue, 28 Jun 2022 12:29:38 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 12:29:38 +0300
changeset 283
96b7eb68e9e6
parent 264
76a025db4948
child 333
07e65a4c6611
permissions
-rw-r--r--

Make settings editor scrollable

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: 262
diff changeset
1 #include "src/ldrawalgorithm.h"
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
3 std::pair<Triangle, Triangle> splitTriangles(
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
4 const Quadrilateral& q,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
5 ldraw::Diagonal diagonal)
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
7 std::pair<Triangle, Triangle> result;
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 switch (diagonal)
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 {
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 case ldraw::Diagonal::Diagonal_13:
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
11 result = {Triangle{q.p1, q.p2, q.p3}, {q.p1, q.p3, q.p4}};
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 break;
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 case ldraw::Diagonal::Diagonal_24:
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
14 result = {Triangle{q.p1, q.p2, q.p3}, {q.p2, q.p3, q.p4}};
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 break;
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 }
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 return result;
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 }
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19
262
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
20 std::vector<ModelAction> ldraw::makeUnofficial(const Model* model)
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 {
262
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
22 std::vector<ModelAction> actions;
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
23 if (model->size() >= 4) {
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
24 if (const Comment* comment = std::get_if<Comment>(&(*model)[3])) {
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
25 const QString& body = comment->text;
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 if (body.startsWith("!LDRAW_ORG ") and not body.startsWith("!LDRAW_ORG Unofficial_"))
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 {
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 // Add Unofficial_ to part type
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 QStringList tokens = body.split(" ");
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 tokens[1] = "Unofficial_" + tokens[1];
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 // Remove the UPDATE tag if it's there
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 if (tokens.size() >= 4 && tokens[2] == "UPDATE")
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 tokens.removeAt(3);
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 tokens.removeAt(2);
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 }
262
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
37 actions.push_back(ModifyModel{
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
38 .position = 3,
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
39 .newElement = Comment{.text = tokens.join(" ")}
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
40 });
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 }
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 }
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 }
262
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 248
diff changeset
44 return actions;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
45 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
46
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
47 ModelElement inverted(const ModelElement& element)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
48 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
49 return std::visit(overloaded{
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
50 [](Colored<SubfileReference> ref) -> ModelElement {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
51 ref.inverted = not ref.inverted;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
52 return ref;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
53 },
248
29986dfd1750 Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
54 [](Colored<CircularPrimitive> circ) -> ModelElement {
29986dfd1750 Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
55 circ.inverted = not circ.inverted;
29986dfd1750 Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
56 return circ;
29986dfd1750 Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
57 },
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
58 [](Colored<Triangle> triangle) -> ModelElement {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
59 std::swap(triangle.p1, triangle.p2);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
60 return triangle;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
61 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
62 [](Colored<Quadrilateral> quad) -> ModelElement {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
63 std::swap(quad.p2, quad.p4);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
64 return quad;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
65 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
66 [](const ModelElement& x) { return x; }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
67 }, element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
68 }

mercurial