src/main.h

Thu, 05 Mar 2020 15:58:35 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 05 Mar 2020 15:58:35 +0200
changeset 67
612213a168da
parent 64
f99d52b1646b
child 73
97df974b5ed5
permissions
-rw-r--r--

grid autorotation

24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
1 /*
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
2 * LDForge: LDraw parts authoring CAD
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
4 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
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: 22
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
8 * (at your option) any later version.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
9 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
10 * This program is distributed in the hope that it will be useful,
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
13 * GNU General Public License for more details.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
14 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
15 * You should have received a copy of the GNU General Public License
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
17 */
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
18
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #pragma once
2
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
20 #include <QString>
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
21 #include <QVector>
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
22 #include <QSet>
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
23 #include <memory>
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents: 2
diff changeset
24 #include "basics.h"
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
25 #include "utility.h"
20
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
26 #include "maths.h"
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
27 #include "geometry.h"
63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
28 #include "functional.h"
2
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
29
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
30 namespace settingGroups
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
31 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
32 // List of setting groups
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
33 constexpr char mainwindow[] = "mainwindow";
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
34 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
35
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
36 namespace ldraw
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
37 {
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
38 // Uniquely identifies a model body object
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
39 struct Id
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
40 {
46
98645c8e7704 added the pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
41 std::int32_t value;
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
42 constexpr bool operator<(ldraw::Id other) const
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
43 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
44 return this->value < other.value;
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
45 }
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
46 friend constexpr unsigned int qHash(ldraw::Id id)
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
47 {
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
48 return qHash(id.value);
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
49 }
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
50 friend bool operator==(ldraw::Id one, ldraw::Id other)
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
51 {
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
52 return one.value == other.value;
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
53 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
54 };
46
98645c8e7704 added the pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
55 using id_t = Id;
98645c8e7704 added the pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
56 constexpr id_t NULL_ID = id_t{0};
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
57 }
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
58
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
59 constexpr std::size_t operator""_z(const unsigned long long int x)
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
60 {
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
61 return static_cast<std::size_t>(x);
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
62 }
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
63
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
64 inline QString operator""_q(const char* string, const unsigned long int length)
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
65 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
66 Q_UNUSED(length)
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
67 return QString{string};
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
68 }
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
69
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
70 inline QPointF pointToPointF(const QPoint& point)
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
71 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
72 return {static_cast<qreal>(point.x()), static_cast<qreal>(point.y())};
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
73 }
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
74
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
75 inline QPoint pointFToPoint(const QPointF& point)
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
76 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
77 return {static_cast<int>(std::round(point.x())), static_cast<int>(std::round(point.y()))};
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
78 }
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
79
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
80 /**
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
81 * \brief Hints to the specified vector that a certain amount of new elements are going to be added.
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
82 * \param vector vector to consider
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
83 * \param amount amount of new elements to expect
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
84 */
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
85 template<typename T>
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
86 void reserveMore(std::vector<T>& vector, std::size_t amount)
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
87 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
88 vector.reserve(vector.size() + amount);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
89 }
64
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
90
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
91 inline QString vectorToString(const glm::vec2& vec)
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
92 {
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
93 return "(%1, %2)"_q
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
94 .arg(toDouble(vec.x))
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
95 .arg(toDouble(vec.y));
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
96 }
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
97
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
98 inline QString vectorToString(const glm::vec3& vec)
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
99 {
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
100 return "(%1, %2, %3)"_q
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
101 .arg(toDouble(vec.x))
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
102 .arg(toDouble(vec.y))
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
103 .arg(toDouble(vec.z));
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
104 }
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
105
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
106 inline QString vectorToString(const glm::vec4& vec)
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
107 {
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
108 return "(%1, %2, %3, %4)"_q
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
109 .arg(toDouble(vec.x))
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
110 .arg(toDouble(vec.y))
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
111 .arg(toDouble(vec.z))
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
112 .arg(toDouble(vec.w));
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
113 }

mercurial