src/ldrawalgorithm.cpp

Wed, 12 Apr 2023 01:53:42 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 12 Apr 2023 01:53:42 +0300
changeset 379
8d88adffb779
parent 338
719b909a7d2b
permissions
-rw-r--r--

Circular primitive type is now an enum class

336
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
1 #include <QTextBlock>
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
2 #include "src/ldrawalgorithm.h"
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
4 std::pair<Triangle, Triangle> splitTriangles(
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
5 const Quadrilateral& q,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
6 ldraw::Diagonal diagonal)
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
8 std::pair<Triangle, Triangle> result;
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 switch (diagonal)
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 {
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 case ldraw::Diagonal::Diagonal_13:
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
12 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
13 break;
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 case ldraw::Diagonal::Diagonal_24:
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
15 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
16 break;
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 }
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 return result;
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 }
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20
338
719b909a7d2b Delete unused code
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 336
diff changeset
21 std::vector<ModelAction> ldraw::makeUnofficial(const QTextDocument* model)
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 {
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
23 std::vector<ModelAction> actions;
336
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
24 constexpr int ldrawOrgLinePosition = 3;
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
25 const QTextBlock block = model->findBlockByLineNumber(ldrawOrgLinePosition);
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
26 if (block.isValid()) {
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
27 const QString body = block.text().simplified();
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
28 if (body.startsWith("0 !LDRAW_ORG ") and not body.startsWith("0 !LDRAW_ORG Unofficial_")) {
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
29 // Add Unofficial_ to part type
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
30 QStringList tokens = body.split(" ");
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
31 tokens[2] = "Unofficial_" + tokens[2];
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
32 // Remove the UPDATE tag if it's there
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
33 if (tokens.size() >= 5 && tokens[3] == "UPDATE")
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 {
336
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
35 tokens.removeAt(4);
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
36 tokens.removeAt(3);
154
47cb50cfa9ad add missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 }
336
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
38 actions.push_back(ModifyModel{
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
39 .position = ldrawOrgLinePosition,
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
40 .newElement = Comment{.text = tokens.mid(1).join(" ")}
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
41 });
154
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 }

mercurial