Tue, 11 Apr 2023 20:27:04 +0300
Simplify signature of updateRenderPreferences
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 | 3 | |
200 | 4 | std::pair<Triangle, Triangle> splitTriangles( |
5 | const Quadrilateral& q, | |
6 | ldraw::Diagonal diagonal) | |
154 | 7 | { |
200 | 8 | std::pair<Triangle, Triangle> result; |
154 | 9 | switch (diagonal) |
10 | { | |
11 | case ldraw::Diagonal::Diagonal_13: | |
200 | 12 | result = {Triangle{q.p1, q.p2, q.p3}, {q.p1, q.p3, q.p4}}; |
154 | 13 | break; |
14 | case ldraw::Diagonal::Diagonal_24: | |
200 | 15 | result = {Triangle{q.p1, q.p2, q.p3}, {q.p2, q.p3, q.p4}}; |
154 | 16 | break; |
17 | } | |
18 | return result; | |
19 | } | |
20 | ||
338 | 21 | std::vector<ModelAction> ldraw::makeUnofficial(const QTextDocument* model) |
154 | 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 | 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 | 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 | 42 | } |
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 | 45 | } |