src/LDObject.cc

Sun, 09 Mar 2014 21:14:07 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 09 Mar 2014 21:14:07 +0200
changeset 693
8432b37034a9
parent 692
94feb28faffe
child 694
3868f52da6b9
permissions
-rw-r--r--

- LDDocument must be initialized with m_needsGLReInit as true or it will not be compiled properly...

629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include "Main.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "LDObject.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "Document.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "Misc.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "MainWindow.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "EditHistory.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "GLRenderer.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "Colors.h"
675
450827da2376 Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
27 #include "GLCompiler.h"
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 cfg (String, ld_defaultname, "");
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 cfg (String, ld_defaultuser, "");
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 cfg (Int, ld_defaultlicense, 0);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 // List of all LDObjects
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 static LDObjectList g_LDObjects;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 // =============================================================================
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 // LDObject constructors
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
38 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 LDObject::LDObject() :
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
40 m_isHidden (false),
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
41 m_isSelected (false),
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
42 m_parent (null),
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
43 m_document (null),
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
44 m_isGLInit (false),
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 qObjListEntry (null)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 memset (m_coords, 0, sizeof m_coords);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 chooseID();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 g_LDObjects << this;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
53 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 void LDObject::chooseID()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 int32 id = 1; // 0 shalt be null
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 for (LDObject* obj : g_LDObjects)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 assert (obj != this);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
62 if (obj->id() >= id)
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
63 id = obj->id() + 1;
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 setID (id);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
70 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 void LDObject::setVertexCoord (int i, Axis ax, double value)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
73 Vertex v = vertex (i);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 v[ax] = value;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 setVertex (i, v);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 LDError::LDError() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
81 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
82 QString LDComment::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
84 return format ("0 %1", text());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
88 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
89 QString LDSubfile::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
91 QString val = format ("1 %1 %2 ", color(), position());
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
92 val += transform().toString();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 val += ' ';
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
94 val += fileInfo()->name();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 return val;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
99 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
100 QString LDLine::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
102 QString val = format ("2 %1", color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 for (int i = 0; i < 2; ++i)
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
105 val += format (" %1", vertex (i));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 return val;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
111 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
112 QString LDTriangle::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
114 QString val = format ("3 %1", color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 for (int i = 0; i < 3; ++i)
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
117 val += format (" %1", vertex (i));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 return val;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
123 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
124 QString LDQuad::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
126 QString val = format ("4 %1", color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 for (int i = 0; i < 4; ++i)
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
129 val += format (" %1", vertex (i));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 return val;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
135 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
136 QString LDCondLine::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
138 QString val = format ("5 %1", color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 // Add the coordinates
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 for (int i = 0; i < 4; ++i)
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
142 val += format (" %1", vertex (i));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 return val;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
148 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
149 QString LDError::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 {
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
151 return contents();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
155 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
156 QString LDVertex::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
158 return format ("0 !LDFORGE VERTEX %1 %2", color(), pos);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
162 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
163 QString LDEmpty::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 return "";
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
169 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
170 const char* LDBFC::k_statementStrings[] =
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 "CERTIFY CCW",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 "CCW",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 "CERTIFY CW",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 "CW",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 "NOCERTIFY",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 "INVERTNEXT",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 "CLIP",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 "CLIP CCW",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 "CLIP CW",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 "NOCLIP",
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 };
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
184 QString LDBFC::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
186 return format ("0 BFC %1", LDBFC::k_statementStrings[m_statement]);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
190 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 QList<LDTriangle*> LDQuad::splitToTriangles()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 // Create the two triangles based on this quadrilateral:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 // 0---3 0---3 3
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // | | | / /|
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 // | | ==> | / / |
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 // | | |/ / |
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 // 1---2 1 1---2
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
199 LDTriangle* tri1 = new LDTriangle (vertex (0), vertex (1), vertex (3));
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
200 LDTriangle* tri2 = new LDTriangle (vertex (1), vertex (2), vertex (3));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 // The triangles also inherit the quad's color
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
203 tri1->setColor (color());
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
204 tri2->setColor (color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 QList<LDTriangle*> triangles;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 triangles << tri1;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 triangles << tri2;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 return triangles;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
213 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 void LDObject::replace (LDObject* other)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
216 long idx = lineNumber();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 assert (idx != -1);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 // Replace the instance of the old object with the new object
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
220 document()->setObject (idx, other);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 // Remove the old object
640
d4dda62c6600 - renamed LDObject::deleteSelf to LDObject::destroy
Santeri Piippo <crimsondusk64@gmail.com>
parents: 639
diff changeset
223 destroy();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
227 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 void LDObject::swap (LDObject* other)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 {
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
230 assert (document() == other->document());
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
231 document()->swapObjects (this, other);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
235 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 LDLine::LDLine (Vertex v1, Vertex v2)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 setVertex (0, v1);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 setVertex (1, v2);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
243 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 LDQuad::LDQuad (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 setVertex (0, v0);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 setVertex (1, v1);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 setVertex (2, v2);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 setVertex (3, v3);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
253 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 LDObject::~LDObject() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
257 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 LDSubfile::~LDSubfile() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
261 //
640
d4dda62c6600 - renamed LDObject::deleteSelf to LDObject::destroy
Santeri Piippo <crimsondusk64@gmail.com>
parents: 639
diff changeset
262 void LDObject::destroy()
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 // If this object was selected, unselect it now
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 if (isSelected())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 unselect();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 // If this object was associated to a file, remove it off it now
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
269 if (document())
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
270 document()->forgetObject (this);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 // Delete the GL lists
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
273 g_win->R()->forgetObject (this);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 // Remove this object from the list of LDObjects
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 g_LDObjects.removeOne (this);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 delete this;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
282 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 static void transformObject (LDObject* obj, Matrix transform, Vertex pos, int parentcolor)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
285 switch (obj->type())
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 case LDObject::ELine:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 case LDObject::ECondLine:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 case LDObject::ETriangle:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 case LDObject::EQuad:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 for (int i = 0; i < obj->vertices(); ++i)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
294 Vertex v = obj->vertex (i);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 v.transform (transform, pos);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 obj->setVertex (i, v);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 break;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 case LDObject::ESubfile:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 LDSubfile* ref = static_cast<LDSubfile*> (obj);
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
304 Matrix newMatrix = transform * ref->transform();
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
305 Vertex newpos = ref->position();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 newpos.transform (transform, pos);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 ref->setPosition (newpos);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 ref->setTransform (newMatrix);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
311 break;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 default:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 break;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
317 if (obj->color() == maincolor)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318 obj->setColor (parentcolor);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 // =============================================================================
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 // -----------------------------------------------------------------------------
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
323 LDObjectList LDSubfile::inlineContents (bool deep, bool render)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 {
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
325 LDObjectList objs = fileInfo()->inlineContents (deep, render);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 // Transform the objects
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 for (LDObject* obj : objs)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 // Set the parent now so we know what inlined the object.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 obj->setParent (this);
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
332 transformObject (obj, transform(), position(), color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 return objs;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
339 //
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
340 LDPolygon* LDObject::getPolygon()
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
341 {
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
342 Type ot = type();
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
343 int num =
684
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
344 (ot == LDObject::ELine) ? 2 :
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
345 (ot == LDObject::ETriangle) ? 3 :
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
346 (ot == LDObject::EQuad) ? 4 :
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
347 (ot == LDObject::ECondLine) ? 5 :
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
348 0;
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
349 if (num == 0)
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
350 return null;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
351
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
352 LDPolygon* data = new LDPolygon;
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
353 data->id = id();
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
354 data->num = num;
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
355 data->color = color();
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
356 data->origin = origin();
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
357
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
358 for (int i = 0; i < data->numVertices(); ++i)
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
359 data->vertices[i] = vertex (i);
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
360
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
361 return data;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
362 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
363
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
364 // =============================================================================
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
365 //
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
366 QList<LDPolygon> LDSubfile::inlinePolygons()
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
367 {
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
368 QList<LDPolygon> data = fileInfo()->inlinePolygons();
693
8432b37034a9 - LDDocument must be initialized with m_needsGLReInit as true or it will not be compiled properly...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 692
diff changeset
369 print ("LDSubfile::inlinePolygons: %1 has %2 polygons\n", fileInfo()->getDisplayName(), data.size());
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
370
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
371 for (LDPolygon& entry : data)
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
372 for (int i = 0; i < entry.numVertices(); ++i)
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
373 entry.vertices[i].transform (transform(), position());
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
374
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
375 return data;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
376 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
377
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
378 // =============================================================================
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 // -----------------------------------------------------------------------------
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
380 long LDObject::lineNumber() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 {
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
382 assert (document() != null);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
384 for (int i = 0; i < document()->getObjectCount(); ++i)
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
385 if (document()->getObject (i) == this)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 return i;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 return -1;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
392 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 void LDObject::moveObjects (LDObjectList objs, const bool up)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 if (objs.isEmpty())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 return;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 // If we move down, we need to iterate the array in reverse order.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 const long start = up ? 0 : (objs.size() - 1);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 const long end = up ? objs.size() : -1;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 const long incr = up ? 1 : -1;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 LDObjectList objsToCompile;
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
403 LDDocument* file = objs[0]->document();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 for (long i = start; i != end; i += incr)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 LDObject* obj = objs[i];
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
409 const long idx = obj->lineNumber(),
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410 target = idx + (up ? -1 : 1);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
412 if ((up && idx == 0) || (!up && idx == (long) (file->objects().size() - 1)))
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 // One of the objects hit the extrema. If this happens, this should be the first
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 // object to be iterated on. Thus, nothing has changed yet and it's safe to just
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 // abort the entire operation.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 assert (i == start);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 return;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 objsToCompile << obj;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 objsToCompile << file->getObject (target);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 obj->swap (file->getObject (target));
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 removeDuplicates (objsToCompile);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429 // The objects need to be recompiled, otherwise their pick lists are left with
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 // the wrong index colors which messes up selection.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 for (LDObject* obj : objsToCompile)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 g_win->R()->compileObject (obj);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
436 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 QString LDObject::typeName (LDObject::Type type)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 LDObject* obj = LDObject::getDefault (type);
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
440 QString name = obj->typeName();
640
d4dda62c6600 - renamed LDObject::deleteSelf to LDObject::destroy
Santeri Piippo <crimsondusk64@gmail.com>
parents: 639
diff changeset
441 obj->destroy();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 return name;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
446 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 QString LDObject::describeObjects (const LDObjectList& objs)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 bool firstDetails = true;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450 QString text = "";
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 if (objs.isEmpty())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 return "nothing"; // :)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 for (long i = 0; i < ENumTypes; ++i)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 Type objType = (Type) i;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 int count = 0;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 for (LDObject * obj : objs)
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
461 if (obj->type() == objType)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 count++;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 if (count == 0)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 continue;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 if (!firstDetails)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 text += ", ";
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
470 QString noun = format ("%1%2", typeName (objType), plural (count));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472 // Plural of "vertex" is "vertices", correct that
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 if (objType == EVertex && count != 1)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 noun = "vertices";
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
476 text += format ("%1 %2", count, noun);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 firstDetails = false;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 return text;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
484 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 LDObject* LDObject::topLevelParent()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486 {
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
487 if (parent() == null)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
488 return this;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 LDObject* it = this;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
492 while (it->parent() != null)
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
493 it = it->parent();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495 return it;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
499 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 LDObject* LDObject::next() const
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
502 long idx = lineNumber();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503 assert (idx != -1);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
504
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
505 if (idx == (long) document()->getObjectCount() - 1)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506 return null;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
508 return document()->getObject (idx + 1);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
509 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
510
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
511 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
512 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
513 LDObject* LDObject::previous() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
515 long idx = lineNumber();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 assert (idx != -1);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
517
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518 if (idx == 0)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519 return null;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
521 return document()->getObject (idx - 1);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
522 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
525 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 void LDObject::move (Vertex vect)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528 if (hasMatrix())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
530 LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (this);
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
531 mo->setPosition (mo->position() + vect);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532 }
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
533 elif (type() == LDObject::EVertex)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
534 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535 // ugh
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
536 static_cast<LDVertex*> (this)->pos += vect;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 else
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540 for (int i = 0; i < vertices(); ++i)
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
541 setVertex (i, vertex (i) + vect);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
546 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
547 #define CHECK_FOR_OBJ(N) \
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548 if (type == LDObject::E##N) \
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549 return new LD##N;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 LDObject* LDObject::getDefault (const LDObject::Type type)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
552 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553 CHECK_FOR_OBJ (Comment)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554 CHECK_FOR_OBJ (BFC)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
555 CHECK_FOR_OBJ (Line)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556 CHECK_FOR_OBJ (CondLine)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
557 CHECK_FOR_OBJ (Subfile)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 CHECK_FOR_OBJ (Triangle)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
559 CHECK_FOR_OBJ (Quad)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560 CHECK_FOR_OBJ (Empty)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
561 CHECK_FOR_OBJ (BFC)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 CHECK_FOR_OBJ (Error)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 CHECK_FOR_OBJ (Vertex)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564 CHECK_FOR_OBJ (Overlay)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 return null;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
567
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
568 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
569 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
570 void LDObject::invert() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
571 void LDBFC::invert() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 void LDEmpty::invert() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573 void LDComment::invert() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 void LDError::invert() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
575
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
576 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
577 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 void LDTriangle::invert()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 // Thus, we swap 1 and 2.
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
582 Vertex tmp = vertex (1);
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
583 setVertex (1, vertex (2));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
584 setVertex (2, tmp);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 return;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
590 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591 void LDQuad::invert()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 // Quad: 0 -> 1 -> 2 -> 3
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594 // rev: 0 -> 3 -> 2 -> 1
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
595 // Thus, we swap 1 and 3.
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
596 Vertex tmp = vertex (1);
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
597 setVertex (1, vertex (3));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598 setVertex (3, tmp);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
600
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
601 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
602 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
603 void LDSubfile::invert()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
604 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
605 // Subfiles are inverted when they're prefixed with
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
606 // a BFC INVERTNEXT statement. Thus we need to toggle this status.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
607 // For flat primitives it's sufficient that the determinant is
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
608 // flipped but I don't have a method for checking flatness yet.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609 // Food for thought...
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
610
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
611 int idx = lineNumber();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613 if (idx > 0)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
615 LDBFC* bfc = dynamic_cast<LDBFC*> (previous());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
617 if (bfc && bfc->statement() == LDBFC::InvertNext)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
619 // This is prefixed with an invertnext, thus remove it.
640
d4dda62c6600 - renamed LDObject::deleteSelf to LDObject::destroy
Santeri Piippo <crimsondusk64@gmail.com>
parents: 639
diff changeset
620 bfc->destroy();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621 return;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
623 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
624
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625 // Not inverted, thus prefix it with a new invertnext.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626 LDBFC* bfc = new LDBFC (LDBFC::InvertNext);
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
627 document()->insertObj (idx, bfc);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
631 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632 static void invertLine (LDObject* line)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
634 // For lines, we swap the vertices. I don't think that a
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 // cond-line's control points need to be swapped, do they?
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
636 Vertex tmp = line->vertex (0);
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
637 line->setVertex (0, line->vertex (1));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
638 line->setVertex (1, tmp);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
639 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
640
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641 void LDLine::invert()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643 invertLine (this);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646 void LDCondLine::invert()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
647 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
648 invertLine (this);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 void LDVertex::invert() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
654 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
655 LDLine* LDCondLine::demote()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
656 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
657 LDLine* repl = new LDLine;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
658
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
659 for (int i = 0; i < repl->vertices(); ++i)
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
660 repl->setVertex (i, vertex (i));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
661
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
662 repl->setColor (color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
664 replace (repl);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
665 return repl;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
666 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
667
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
668 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
669 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
670 LDObject* LDObject::fromID (int id)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
671 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
672 for (LDObject* obj : g_LDObjects)
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
673 if (obj->id() == id)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
674 return obj;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
675
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
676 return null;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
677 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
678
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
679 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
680 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
681 QString LDOverlay::asText() const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
682 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
683 return format ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6",
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
684 fileName(), camera(), x(), y(), width(), height());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
685 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
687 void LDOverlay::invert() {}
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
688
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
689 // =============================================================================
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
690 // Hook the set accessors of certain properties to this changeProperty function.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
691 // It takes care of history management so we can capture low-level changes, this
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
692 // makes history stuff work out of the box.
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
693 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
694 template<class T> static void changeProperty (LDObject* obj, T* ptr, const T& val)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
695 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
696 long idx;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
697
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
698 if (*ptr == val)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
699 return;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
700
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
701 if (obj->document() && (idx = obj->lineNumber()) != -1)
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
702 {
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
703 QString before = obj->asText();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
704 *ptr = val;
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
705 QString after = obj->asText();
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
706
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
707 if (before != after)
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
708 obj->document()->addToHistory (new EditHistory (idx, before, after));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
709 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
710 else
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
711 *ptr = val;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
712 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
714 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
715 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
716 void LDObject::setColor (const int& val)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
717 {
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
718 changeProperty (this, &m_color, val);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
719 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
720
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
722 //
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
723 const Vertex& LDObject::vertex (int i) const
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
724 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
725 return m_coords[i]->data();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
726 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
727
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
729 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
730 void LDObject::setVertex (int i, const Vertex& vert)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
731 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 changeProperty (this, &m_coords[i], LDSharedVertex::getSharedVertex (vert));
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
734
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
736 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
737 void LDMatrixObject::setPosition (const Vertex& a)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
738 {
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
739 changeProperty (linkPointer(), &m_position, LDSharedVertex::getSharedVertex (a));
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
740 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
741
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
742 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
743 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
744 void LDMatrixObject::setTransform (const Matrix& val)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
745 {
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
746 changeProperty (linkPointer(), &m_transform, val);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
747 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
748
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
749 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
750 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
751 static QMap<Vertex, LDSharedVertex*> g_sharedVerts;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
752
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
753 LDSharedVertex* LDSharedVertex::getSharedVertex (const Vertex& a)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
754 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
755 auto it = g_sharedVerts.find (a);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
757 if (it == g_sharedVerts.end())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
758 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
759 LDSharedVertex* v = new LDSharedVertex (a);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
760 g_sharedVerts[a] = v;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
761 return v;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
762 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
763
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
764 return *it;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
765 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
766
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
767 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
768 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
769 void LDSharedVertex::addRef (LDObject* a)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
771 m_refs << a;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
772 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
773
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
774 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
775 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
776 void LDSharedVertex::delRef (LDObject* a)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
777 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
778 m_refs.removeOne (a);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
779
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
780 if (m_refs.empty())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
781 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
782 g_sharedVerts.remove (m_data);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
783 delete this;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
784 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
785 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
786
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
787 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
788 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
789 void LDObject::select()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
791 assert (document() != null);
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
792 document()->addToSelection (this);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
793 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
794
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
795 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
796 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 void LDObject::unselect()
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
798 {
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 642
diff changeset
799 assert (document() != null);
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
800 document()->removeFromSelection (this);
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
801 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
802
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
803 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
804 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
805 QString getLicenseText (int id)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
806 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
807 switch (id)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
808 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
809 case 0:
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
810 return g_CALicense;
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
811
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
812 case 1:
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
813 return g_nonCALicense;
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
815 case 2:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
816 return "";
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
817 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
819 assert (false);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
820 return "";
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
822
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
823 // =============================================================================
639
851634b85893 - unified separator styles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 638
diff changeset
824 //
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
825 LDObject* LDObject::createCopy() const
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
826 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
827 /*
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
828 LDObject* copy = clone();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
829 copy->setFile (null);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
830 copy->setGLInit (false);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
831 copy->chooseID();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
832 copy->setSelected (false);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
833 */
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
834
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
835 /*
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
836 LDObject* copy = getDefault (getType());
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
837 copy->setColor (color());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
838
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
839 if (hasMatrix())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
840 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
841 LDMatrixObject* copyMo = static_cast<LDMatrixObject*> (copy);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
842 const LDMatrixObject* mo = static_cast<const LDMatrixObject*> (this);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
843 copyMo->setPosition (mo->getPosition());
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
844 copyMo->setTransform (mo->transform());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
845 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
846 else
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
847 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
848 for (int i = 0; i < vertices(); ++i)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
849 copy->setVertex (getVertex (i));
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
850 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
851
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
852 switch (getType())
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
853 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
854 case Subfile:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
855 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
856 LDSubfile* copyRef = static_cast<LDSubfile*> (copy);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
857 const LDSubfile* ref = static_cast<const LDSubfile*> (this);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
858
642
751a8df42842 - migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 640
diff changeset
859 copyRef->setFileInfo (ref->fileInfo());
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
860 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
861 }
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
862 */
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
863
638
382226e40865 - renamed several LDObject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 629
diff changeset
864 LDObject* copy = parseLine (asText());
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
865
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
866 if (origin().isEmpty() == false)
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
867 copy->setOrigin (origin());
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
868 elif (document() != null)
692
94feb28faffe - fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 690
diff changeset
869 copy->setOrigin (document()->getDisplayName() + ":" + QString::number (lineNumber()));
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
870
629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
871 return copy;
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
872 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
873
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
874 // =============================================================================
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
875 //
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
876 void LDSubfile::setFileInfo (const LDDocumentPointer& a)
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
877 {
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
878 m_fileInfo = a;
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
879
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
880 // If it's an immediate subfile reference (i.e. this subfile belongs in an
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
881 // explicit file), we need to pre-compile the GL polygons for the document
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
882 // if they don't exist already.
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
883 if (a != null &&
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
884 a->isImplicit() == false &&
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
885 a->polygonData().isEmpty())
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
886 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
887 a->initializeGLData();
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
888 }
690
9e9c52ca955e Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 684 644
diff changeset
889 };

mercurial