src/linetypes/quadrilateral.cpp

Sun, 05 Mar 2017 16:47:52 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 05 Mar 2017 16:47:52 +0200
changeset 1186
eae8b3bce545
parent 1149
502c866b8512
child 1261
5d2c9d36da9d
permissions
-rw-r--r--

Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.

1149
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "quadrilateral.h"
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 LDQuadrilateral::LDQuadrilateral(Model *model) :
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 LDObject {model} {}
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 LDQuadrilateral::LDQuadrilateral(const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model) :
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 LDObject {model}
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 {
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 setVertex(0, v1);
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 setVertex(1, v2);
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 setVertex(2, v3);
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 setVertex(3, v4);
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 }
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 int LDQuadrilateral::numVertices() const
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 {
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 return 4;
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 }
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 QString LDQuadrilateral::typeName() const
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 {
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 return "quad";
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 }
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 QString LDQuadrilateral::asText() const
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 {
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 QString result = format("4 %1", color());
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 for (int i = 0; i < 4; ++i)
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 result += format(" %1", vertex(i));
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 return result;
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 }
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 int LDQuadrilateral::triangleCount() const
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 {
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 return 2;
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 }
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 void LDQuadrilateral::invert()
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 {
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 // Quad: 0 -> 1 -> 2 -> 3
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 // reversed: 0 -> 3 -> 2 -> 1
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 // Thus, we swap 1 and 3.
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 Vertex temp = vertex(1);
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 setVertex(1, vertex(3));
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 setVertex(3, temp);
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 }
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 LDObjectType LDQuadrilateral::type() const
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 {
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 return SubclassType;
502c866b8512 Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 }

mercurial