src/editmodes/magicWandMode.cpp

Thu, 23 Feb 2017 23:36:59 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 23 Feb 2017 23:36:59 +0200
changeset 1172
3defab8cfd93
parent 1145
02264bf0108d
child 1240
cebb7ef54f41
permissions
-rw-r--r--

Changed QByteArray to QVector to avoid that ugly reinterpret_cast.

818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
19 #include <QMouseEvent>
830
a741a0b9df49 - updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
20 #include "magicWandMode.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1139
diff changeset
21 #include "../lddocument.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
22 #include "../mainwindow.h"
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
23 #include "../canvas.h"
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
25 MagicWandMode::MagicWandMode (Canvas* canvas) :
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
26 Super (canvas)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 // Get vertex<->object data
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 977
diff changeset
29 for (LDObject* obj : currentDocument()->objects())
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 // Note: this deliberately only takes vertex-objects into account.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 // The magic wand does not process subparts.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 for (int i = 0; i < obj->numVertices(); ++i)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
34 m_vertices[obj->vertex (i)] << obj;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
38 EditModeType MagicWandMode::type() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
39 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
40 return EditModeType::MagicWand;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
41 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
42
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
43 void MagicWandMode::fillBoundaries (LDObject* obj, QVector<BoundaryType>& boundaries, QSet<LDObject*>& candidates)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 // All boundaries obviously share vertices with the object, therefore they're all in the list
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 // of candidates.
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
47 for (LDObject* candidate : candidates)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
49 if (not isOneOf(candidate->type(), LDObjectType::EdgeLine, LDObjectType::ConditionalEdge)
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
50 or candidate->vertex (0) == candidate->vertex (1))
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
51 {
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 continue;
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
53 }
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 int matches = 0;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 for (int i = 0; i < obj->numVertices(); ++i)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 {
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
59 if (not isOneOf (obj->vertex (i), candidate->vertex (0), candidate->vertex (1)))
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 continue;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 if (++matches == 2)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 {
833
ad681d97d341 - magic wand: when flood-selecting surfaces, also pick any matching conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 830
diff changeset
64 // Boundary found. If it's an edgeline, add it to the boundaries list, if a
ad681d97d341 - magic wand: when flood-selecting surfaces, also pick any matching conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 830
diff changeset
65 // conditional line, select it.
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
66 if (candidate->type() == LDObjectType::ConditionalEdge)
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
67 m_selection << candidate;
833
ad681d97d341 - magic wand: when flood-selecting surfaces, also pick any matching conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 830
diff changeset
68 else
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
69 boundaries.append (std::make_tuple (candidate->vertex (0), candidate->vertex (1)));
833
ad681d97d341 - magic wand: when flood-selecting surfaces, also pick any matching conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 830
diff changeset
70
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 break;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
77 void MagicWandMode::doMagic (LDObject* obj, MagicWandMode::MagicType type)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
79 if (obj == nullptr)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 if (type == Set)
819
e3d59b6bf053 - update the object list when the magic wand empties the selection when clicking on background
Santeri Piippo <crimsondusk64@gmail.com>
parents: 818
diff changeset
82 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 977
diff changeset
83 currentDocument()->clearSelection();
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
84 m_window->buildObjectList();
819
e3d59b6bf053 - update the object list when the magic wand empties the selection when clicking on background
Santeri Piippo <crimsondusk64@gmail.com>
parents: 818
diff changeset
85 }
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 return;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 int matchesneeded = 0;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 QVector<BoundaryType> boundaries;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 LDObjectType objtype = obj->type();
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 if (type != InternalRecursion)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
96 m_selection.clear();
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
97 m_selection.append (obj);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 switch (obj->type())
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
102 case LDObjectType::EdgeLine:
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
103 case LDObjectType::ConditionalEdge:
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 matchesneeded = 1;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 break;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
107 case LDObjectType::Triangle:
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
108 case LDObjectType::Quadrilateral:
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 matchesneeded = 2;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 break;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 default:
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 return;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
116 QSet<LDObject*> candidates;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 // Get the list of objects that touch this object, i.e. share a vertex
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 // with this.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 for (int i = 0; i < obj->numVertices(); ++i)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
121 candidates += m_vertices[obj->vertex (i)];
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 // If we're dealing with surfaces, get a list of boundaries.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 if (matchesneeded > 1)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 fillBoundaries (obj, boundaries, candidates);
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
127 for (LDObject* candidate : candidates)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 try
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 // If we're doing this on lines, we need exact type match. Surface types (quads and
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 // triangles) can be mixed. Also don't consider self a candidate, and don't consider
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 // objects we have already processed.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 833
diff changeset
134 if ((candidate == obj) or
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 833
diff changeset
135 (candidate->color() != obj->color()) or
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
136 (m_selection.contains (candidate)) or
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 833
diff changeset
137 (matchesneeded == 1 and (candidate->type() != objtype)) or
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 ((candidate->numVertices() > 2) ^ (matchesneeded == 2)))
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 throw 0;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 // Now ensure the two objects share enough vertices.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 QVector<Vertex> matches;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 for (int i = 0; i < obj->numVertices(); ++i)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 for (int j = 0; j < candidate->numVertices(); ++j)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 if (obj->vertex(i) == candidate->vertex(j))
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 matches << obj->vertex(i);
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 break;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
158 if (countof(matches) < matchesneeded)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 throw 0; // Not enough matches.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 // Check if a boundary gets in between the objects.
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 for (auto boundary : boundaries)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 {
966
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
164 if (isOneOf (matches[0], std::get<0> (boundary), std::get<1> (boundary)) and
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
165 isOneOf (matches[1], std::get<0> (boundary), std::get<1> (boundary)))
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 throw 0;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
171 m_selection.append (candidate);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 doMagic (candidate, InternalRecursion);
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 catch (int&)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 {
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 continue;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 switch (type)
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 {
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
182 case Set:
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 977
diff changeset
183 currentDocument()->clearSelection();
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
184 case Additive:
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
185 for (LDObject* obj : m_selection)
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
186 currentDocument()->addToSelection(obj);
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
187 break;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
189 case Subtractive:
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
190 for (LDObject* obj : m_selection)
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
191 currentDocument()->removeFromSelection(obj);
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
192 break;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193
977
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
194 case InternalRecursion:
dc3ceb65cda7 More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
195 break;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 if (type != InternalRecursion)
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
199 m_window->buildObjectList();
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 }
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
201
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
202 bool MagicWandMode::mouseReleased (MouseEventData const& data)
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
203 {
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
204 if (Super::mouseReleased (data))
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
205 return true;
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
206
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 833
diff changeset
207 if (data.releasedButtons & Qt::LeftButton and not data.mouseMoved)
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
208 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
209 MagicType wandtype = MagicWandMode::Set;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
210
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
211 if (data.keymods & Qt::ShiftModifier)
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
212 wandtype = MagicWandMode::Additive;
967
eb586d3e1a6a elif -> else if
Teemu Piippo <crimsondusk64@gmail.com>
parents: 966
diff changeset
213 else if (data.keymods & Qt::ControlModifier)
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
214 wandtype = MagicWandMode::Subtractive;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
215
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1104
diff changeset
216 doMagic (renderer()->pick (data.ev->x(), data.ev->y()), wandtype);
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
217 return true;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
218 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
219
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
220 return false;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 819
diff changeset
221 }

mercurial