src/model.h

Thu, 15 Jun 2023 16:18:03 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Thu, 15 Jun 2023 16:18:03 +0300
changeset 383
530d23cd4e97
parent 379
8d88adffb779
permissions
-rw-r--r--

Refactor, make selecting elements from the model select the corresponding line from the editor as well

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
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #pragma once
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
20 #include <QAbstractListModel>
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include <memory>
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
22 #include "src/basics.h"
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
23 #include "src/colors.h"
333
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 328
diff changeset
24 #include <QTextDocument>
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 328
diff changeset
25
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
26 struct SubfileReference
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
27 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
28 QString name;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
29 glm::mat4 transformation;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
30 };
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
31
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
32 template<typename T>
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
33 struct Colored
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
34 {
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
35 T element;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
36 ldraw::Color color;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
37 };
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
38
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
39 struct Comment
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
40 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
41 QString text;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
42 };
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
44 struct ParseError
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
45 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
46 QString code;
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
47 };
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
48
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
49 struct Empty {};
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
50
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
51 struct CircularFraction
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
52 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
53 unsigned int segments;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
54 unsigned int divisions;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
55 };
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
56
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
57 constexpr bool operator<(const CircularFraction& p, const CircularFraction& q)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
58 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
59 // a/b < c/d
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
60 // a < c * b / d
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
61 // a * d < c * b
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
62 return p.segments * q.divisions < q.segments / p.divisions;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
63 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
64
379
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
65 enum class circular_primitive_type_e
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
66 {
379
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
67 circle,
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
68 disc,
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
69 cylinder,
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
70 cylinder_open,
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
71 cylinder_closed,
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
72 disc_negative,
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
73 chord,
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
74 };
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
75
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
76 struct circular_primitive
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
77 {
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
78 static constexpr int NUM_TYPES = static_cast<int>(circular_primitive_type_e::chord) + 1;
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
79 circular_primitive_type_e type;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
80 CircularFraction fraction;
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
81 glm::mat4 transformation;
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 242
diff changeset
82 bool inverted = false;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
83 };
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
84
379
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
85 constexpr char circularPrimitiveStems[circular_primitive::NUM_TYPES][5] = {
242
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
86 "edge",
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
87 "disc",
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
88 "cyli",
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
89 "cylo",
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
90 "cylc",
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
91 "ndis",
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
92 "chrd",
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
93 };
16855456992d Substitute circular primitives in during file parsing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
94
379
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
95 Q_DECLARE_METATYPE(circular_primitive_type_e)
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
96
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
97 struct CircleToolOptions
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
98 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
99 CircularFraction fraction;
379
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
100 circular_primitive_type_e type;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
101 };
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
102
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
103 using ModelElement = std::variant<
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
104 Colored<SubfileReference>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
105 Colored<LineSegment>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
106 Colored<Triangle>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
107 Colored<Quadrilateral>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
108 Colored<ConditionalEdge>,
379
8d88adffb779 Circular primitive type is now an enum class
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 374
diff changeset
109 Colored<circular_primitive>,
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
110 Comment,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
111 Empty,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
112 ParseError>;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
113
305
d891da20abca Add support for BFC CERTIFY statements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
114 using PlainPolygonElement = std::variant<
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
115 LineSegment,
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
116 Triangle,
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
117 Quadrilateral,
305
d891da20abca Add support for BFC CERTIFY statements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
118 ConditionalEdge>;
d891da20abca Add support for BFC CERTIFY statements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
119
d891da20abca Add support for BFC CERTIFY statements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
120 using PolygonElement = Colored<PlainPolygonElement>;
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
121
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
122 template<typename Ret, typename Fn1, typename Fn2, typename Fn3, typename Fn4, typename T>
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
123 constexpr auto visitPolygon(Fn1&& f1, Fn2&& f2, Fn3&& f3, Fn4&& f4, T&& element)
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
124 {
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
125 if (std::holds_alternative<LineSegment>(element)) {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
126 return f1(std::get<LineSegment>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
127 }
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
128 else if (std::holds_alternative<Triangle>(element)) {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
129 return f2(std::get<Triangle>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
130 }
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
131 else if (std::holds_alternative<Quadrilateral>(element)) {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
132 return f3(std::get<Quadrilateral>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
133 }
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
134 else {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
135 return f4(std::get<ConditionalEdge>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
136 }
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
137 }
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
138
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
139 template<typename T, typename Fn>
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
140 constexpr void visitPoints(Fn&& func, T&& element)
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
141 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
142 visitPolygon<void>(
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
143 [&func](transfer_cvref_t<T&&, LineSegment> edge)
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
144 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
145 func(edge.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
146 func(edge.p2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
147 },
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
148 [&func](transfer_cvref_t<T&&, Triangle>& tri)
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
149 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
150 func(tri.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
151 func(tri.p2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
152 func(tri.p3);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
153 },
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
154 [&func](transfer_cvref_t<T&&, Quadrilateral>& quad)
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
155 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
156 func(quad.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
157 func(quad.p2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
158 func(quad.p3);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
159 func(quad.p4);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
160 },
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
161 [&func](transfer_cvref_t<T&&, ConditionalEdge>& cedge)
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
162 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
163 func(cedge.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
164 func(cedge.p2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
165 func(cedge.c1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
166 func(cedge.c2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
167 },
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
168 element);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
169 }
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
170
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
171 constexpr Colored<LineSegment> edge(const glm::vec3& p1, const glm::vec3& p2)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
172 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
173 return Colored<LineSegment>{{.p1 = p1, .p2 = p2}, EDGE_COLOR};
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
174 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
175
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
176 constexpr Colored<Triangle> triangle(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& p3)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
177 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
178 return Colored<Triangle>{{.p1 = p1, .p2 = p2, .p3 = p3}, MAIN_COLOR};
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
179 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
180
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
181 constexpr Colored<Quadrilateral> quadrilateral(
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
182 const glm::vec3& p1,
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
183 const glm::vec3& p2,
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
184 const glm::vec3& p3,
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
185 const glm::vec3& p4)
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
186 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
187 return Colored<Quadrilateral>{{.p1 = p1, .p2 = p2, .p3 = p3, .p4 = p4}, MAIN_COLOR};
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
188 }
262
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
189
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
190 struct AppendToModel
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
191 {
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
192 ModelElement newElement;
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
193 };
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
194
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
195 struct DeleteFromModel
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
196 {
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
197 std::size_t position;
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
198 };
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
199
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
200 struct ModifyModel
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
201 {
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
202 std::size_t position;
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
203 ModelElement newElement;
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
204 };
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
205
383
530d23cd4e97 Refactor, make selecting elements from the model select the corresponding line from the editor as well
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 379
diff changeset
206 struct SelectInModel
530d23cd4e97 Refactor, make selecting elements from the model select the corresponding line from the editor as well
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 379
diff changeset
207 {
530d23cd4e97 Refactor, make selecting elements from the model select the corresponding line from the editor as well
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 379
diff changeset
208 std::size_t position;
530d23cd4e97 Refactor, make selecting elements from the model select the corresponding line from the editor as well
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 379
diff changeset
209 };
530d23cd4e97 Refactor, make selecting elements from the model select the corresponding line from the editor as well
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 379
diff changeset
210
262
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
211 using ModelAction = std::variant<
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
212 AppendToModel,
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
213 DeleteFromModel,
383
530d23cd4e97 Refactor, make selecting elements from the model select the corresponding line from the editor as well
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 379
diff changeset
214 ModifyModel,
530d23cd4e97 Refactor, make selecting elements from the model select the corresponding line from the editor as well
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 379
diff changeset
215 SelectInModel>;
336
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
216
e07425ac5834 Draw mode and make unofficial tools now work again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
217 QString modelElementToString(const ModelElement &element);

mercurial