src/linetypes/conditionaledge.cpp

Sun, 05 Mar 2017 16:50:06 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 05 Mar 2017 16:50:06 +0200
changeset 1187
46dc716238fd
parent 1186
eae8b3bce545
permissions
-rw-r--r--

Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.

1141
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "../model.h"
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include "conditionaledge.h"
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 LDConditionalEdge::LDConditionalEdge(Model* model) :
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 LDEdgeLine {model} {}
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 LDConditionalEdge::LDConditionalEdge (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) :
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 LDEdgeLine {model}
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 {
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 setVertex (0, v0);
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 setVertex (1, v1);
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 setVertex (2, v2);
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 setVertex (3, v3);
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 }
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 QString LDConditionalEdge::asText() const
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 {
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 QString result = format("5 %1", color());
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 // Add the coordinates
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 for (int i = 0; i < 4; ++i)
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 result += format(" %1", vertex(i));
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 return result;
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 }
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 void LDConditionalEdge::invert()
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 // I don't think that a conditional line's control points need to be swapped, do they?
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 Vertex temp = vertex(0);
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 setVertex(0, vertex(1));
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 setVertex(1, temp);
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 }
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 LDEdgeLine* LDConditionalEdge::becomeEdgeLine()
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 {
1187
46dc716238fd Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents: 1186
diff changeset
55 LDEdgeLine* replacement = model()->replace<LDEdgeLine>(this);
1141
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56
1186
eae8b3bce545 Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
57 if (replacement)
eae8b3bce545 Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
58 {
eae8b3bce545 Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
59 for (int i = 0; i < replacement->numVertices(); ++i)
eae8b3bce545 Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
60 replacement->setVertex (i, vertex (i));
1141
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61
1186
eae8b3bce545 Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
62 replacement->setColor (color());
eae8b3bce545 Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
63 }
eae8b3bce545 Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
64
1141
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 return replacement;
7dc2c981937e Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 }

mercurial