Wed, 08 Jun 2022 19:33:00 +0300
Concentrate model editing into one coroutine inside main()
154 | 1 | #include "ldrawalgorithm.h" |
2 | ||
200 | 3 | std::pair<Triangle, Triangle> splitTriangles( |
4 | const Quadrilateral& q, | |
5 | ldraw::Diagonal diagonal) | |
154 | 6 | { |
200 | 7 | std::pair<Triangle, Triangle> result; |
154 | 8 | switch (diagonal) |
9 | { | |
10 | case ldraw::Diagonal::Diagonal_13: | |
200 | 11 | result = {Triangle{q.p1, q.p2, q.p3}, {q.p1, q.p3, q.p4}}; |
154 | 12 | break; |
13 | case ldraw::Diagonal::Diagonal_24: | |
200 | 14 | result = {Triangle{q.p1, q.p2, q.p3}, {q.p2, q.p3, q.p4}}; |
154 | 15 | break; |
16 | } | |
17 | return result; | |
18 | } | |
19 | ||
20 | /** | |
21 | * @brief Modifies the !LDRAW_ORG line so that it becomes unofficial | |
22 | */ | |
200 | 23 | /* |
154 | 24 | void ldraw::makeUnofficial(ModelEditor& editor) |
25 | { | |
26 | if (editor.model().size() >= 4) | |
27 | { | |
28 | const ldraw::Object* ldrawOrgLine = editor.model()[3]; | |
29 | if (isA<ldraw::MetaCommand>(ldrawOrgLine)) | |
30 | { | |
31 | const QString& body = ldrawOrgLine->getProperty<ldraw::Property::Text>(); | |
32 | if (body.startsWith("!LDRAW_ORG ") and not body.startsWith("!LDRAW_ORG Unofficial_")) | |
33 | { | |
34 | // Add Unofficial_ to part type | |
35 | QStringList tokens = body.split(" "); | |
36 | tokens[1] = "Unofficial_" + tokens[1]; | |
37 | // Remove the UPDATE tag if it's there | |
38 | if (tokens.size() >= 4 && tokens[2] == "UPDATE") | |
39 | { | |
40 | tokens.removeAt(3); | |
41 | tokens.removeAt(2); | |
42 | } | |
43 | editor.setObjectProperty<ldraw::Property::Text>(ldrawOrgLine->id, tokens.join(" ")); | |
44 | } | |
45 | } | |
46 | } | |
200 | 47 | } |
48 | */ | |
49 | ||
50 | ModelElement inverted(const ModelElement& element) | |
51 | { | |
52 | return std::visit(overloaded{ | |
53 | [](Colored<SubfileReference> ref) -> ModelElement { | |
54 | ref.inverted = not ref.inverted; | |
55 | return ref; | |
56 | }, | |
57 | [](Colored<Triangle> triangle) -> ModelElement { | |
58 | std::swap(triangle.p1, triangle.p2); | |
59 | return triangle; | |
60 | }, | |
61 | [](Colored<Quadrilateral> quad) -> ModelElement { | |
62 | std::swap(quad.p2, quad.p4); | |
63 | return quad; | |
64 | }, | |
65 | [](const ModelElement& x) { return x; } | |
66 | }, element); | |
67 | } |