src/model.h

Tue, 14 Jun 2022 17:55:50 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 14 Jun 2022 17:55:50 +0300
changeset 217
6d95c1a41e6e
parent 212
27259810da6d
child 218
63125c36de73
permissions
-rw-r--r--

reimplement EditTools as a render layer

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>
206
654661eab7f3 More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
22 #include "basics.h"
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
23 #include "colors.h"
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
24
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
25 struct SubfileReference
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
26 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
27 QString name;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
28 glm::mat4 transformation;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
29 bool inverted = false;
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>
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
33 struct Colored : T
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
34 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
35 ldraw::Color color;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
36 };
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 struct Comment
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
39 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
40 QString text;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
41 };
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
43 struct ParseError
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
44 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
45 QString code;
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
46 };
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
47
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
48 struct Empty {};
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
49
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
50 template<typename T, typename R>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
51 struct transfer_reference
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
52 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
53 using type = std::remove_reference_t<R>;
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
54 };
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
55
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
56 template<typename T, typename R>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
57 struct transfer_reference<T&, R>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
58 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
59 using type = std::remove_reference_t<R>&;
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
60 };
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
61
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
62 template<typename T, typename R>
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
63 struct transfer_reference<const T&, R>
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
64 {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
65 using type = const std::remove_reference_t<R>&;
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
66 };
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
67
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
68 template<typename T, typename R>
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
69 struct transfer_reference<T&&, R>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
70 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
71 using type = std::remove_reference_t<R>&&;
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
72 };
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
73
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
74 template<typename T, typename R>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
75 using transfer_reference_t = typename transfer_reference<T, R>::type;
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
76 static_assert(std::is_same_v<transfer_reference_t<int, char>, char>);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
77 static_assert(std::is_same_v<transfer_reference_t<int&, char>, char&>);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
78 static_assert(std::is_same_v<transfer_reference_t<int&&, char>, char&&>);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
79
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
80 using ModelElement = std::variant<
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
81 Colored<SubfileReference>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
82 Colored<LineSegment>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
83 Colored<Triangle>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
84 Colored<Quadrilateral>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
85 Colored<ConditionalEdge>,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
86 Comment,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
87 Empty,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
88 ParseError>;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
89
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
90 using PolygonElement = Colored<std::variant<
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
91 LineSegment,
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
92 Triangle,
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
93 Quadrilateral,
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
94 ConditionalEdge>>;
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
95
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
96 template<typename T>
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
97 struct remove_color {};
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
98
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
99 template<typename T>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
100 struct remove_color<Colored<T>> { using type = T; };
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
101
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
102 template<typename T>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
103 struct remove_color<Colored<T>&> { using type = T&; };
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
104
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
105 template<typename T>
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
106 struct remove_color<const Colored<T>&> { using type = const T&; };
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
107
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
108 template<typename T>
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
109 struct remove_color<Colored<T>&&> { using type = T&&; };
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
110
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
111 template<typename T>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
112 using remove_color_t = typename remove_color<T>::type;
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
113
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
114 static_assert(std::is_same_v<remove_color_t<Colored<Triangle>>, Triangle>);
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
115 static_assert(std::is_same_v<remove_color_t<Colored<Triangle>&>, Triangle&>);
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
116 static_assert(std::is_same_v<remove_color_t<const Colored<Triangle>&>, const Triangle&>);
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
117
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
118 template<typename T>
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
119 constexpr remove_color_t<T&&> extract_colored(T&& x)
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
120 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
121 return static_cast<remove_color_t<T&&>>(x);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
122 }
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
123
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
124 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
125 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
126 {
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
127 if (std::holds_alternative<LineSegment>(element)) {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
128 return f1(std::get<LineSegment>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
129 }
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
130 else if (std::holds_alternative<Triangle>(element)) {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
131 return f2(std::get<Triangle>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
132 }
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
133 else if (std::holds_alternative<Quadrilateral>(element)) {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
134 return f3(std::get<Quadrilateral>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
135 }
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
136 else {
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
137 return f4(std::get<ConditionalEdge>(element));
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
138 }
210
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
139 }
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
140
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
141 template<typename T, typename Fn>
211
b27b90fb993f Now builds again
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 210
diff changeset
142 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
143 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
144 visitPolygon<void>(
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
145 [&func](transfer_reference_t<T&&, LineSegment> edge)
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
146 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
147 func(edge.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
148 func(edge.p2);
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](transfer_reference_t<T&&, Triangle>& tri)
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
151 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
152 func(tri.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
153 func(tri.p2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
154 func(tri.p3);
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](transfer_reference_t<T&&, Quadrilateral>& quad)
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
157 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
158 func(quad.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
159 func(quad.p2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
160 func(quad.p3);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
161 func(quad.p4);
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](transfer_reference_t<T&&, ConditionalEdge>& cedge)
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
164 {
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
165 func(cedge.p1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
166 func(cedge.p2);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
167 func(cedge.c1);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
168 func(cedge.c2);
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 element);
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
171 }
232e7634cc8a more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
172
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
173 QString modelElementToString(const ModelElement& element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
174 struct ModelId
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
175 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
176 std::int32_t value;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
177 constexpr auto operator<=>(const ModelId& other) const = default;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
178 };
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
179
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
180 constexpr int qHash(ModelId id)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
181 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
182 return qHash(id.value);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
183 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
184
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
185 class Model : public QAbstractListModel
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187 Q_OBJECT
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
188 struct Entry {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
189 ModelElement data;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
190 ModelId id;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
191 };
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
192 std::vector<Entry> body;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
193 std::map<ModelId, int> positions;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
194 ModelId runningId = {1};
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
195 public:
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
196 Model(QObject* parent);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
197 virtual ~Model();
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
198 ModelId append(const ModelElement& value);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
199 const ModelElement& at(int position) const;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
200 ModelId idAt(int position) const;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
201 void assignAt(int position, const ModelElement& element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
202 std::optional<int> find(ModelId id) const;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
203 void remove(int index);
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
204 int rowCount(const QModelIndex&) const override;
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
205 QVariant data(const QModelIndex& index, int role) const override;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
206 const ModelElement& operator[](int index) const;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
207 int size() const;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
208 auto operator[](int index) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
209 struct {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
210 Model& model;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
211 int index;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
212 operator const ModelElement&() {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
213 return model.at(index);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
214 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
215 auto& operator=(const ModelElement& newData) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
216 model.assignAt(index, newData);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
217 return *this;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
218 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
219 const auto* operator&() {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
220 return &(this->operator const ModelElement&());
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
221 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
222 } result{*this, index};
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
223 return result;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
224 }
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
225 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
226
151
e628fc2e0c72 Clean up Model
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
227 void save(const Model& model, QIODevice *device);
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 173
diff changeset
228 void updateHeaderNameField(Model& model, const QString &name);
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
229
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
230 template<typename T>
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
231 void iterate(const Model& model, std::function<void(const T&)> fn)
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
232 {
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
233 for (int i = 0; i < model.size(); ++i) {
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
234 if (std::holds_alternative<T>(model[i])) {
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
235 fn(std::get<T>(model[i]));
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
236 }
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
237 }
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 211
diff changeset
238 }

mercurial