src/ldObject.cc

Sat, 14 Jun 2014 09:05:29 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 14 Jun 2014 09:05:29 +0300
changeset 795
195fa1fff9c3
parent 789
4b7306f52bb5
child 805
d88c0354de97
permissions
-rw-r--r--

- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
19
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "main.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "ldObject.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "miscallenous.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "mainWindow.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "editHistory.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "glRenderer.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "colors.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
28 #include "glCompiler.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 751
diff changeset
30 CFGENTRY (String, defaultName, "");
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 751
diff changeset
31 CFGENTRY (String, defaultUser, "");
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 751
diff changeset
32 CFGENTRY (Int, defaultLicense, 0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 // List of all LDObjects
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
35 QMap<long, LDObjectWeakPtr> g_allObjects;
771
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
36 static int32 g_idcursor = 1; // 0 shalt be null
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
37 static constexpr int32 g_maxID = (1 << 24);
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
38
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
39 #define LDOBJ_DEFAULT_CTOR(T,BASE) \
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
40 T :: T (LDObjectPtr* selfptr) : \
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
41 BASE (selfptr) {}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 // LDObject constructors
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 //
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
46 LDObject::LDObject (LDObjectPtr* selfptr) :
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 m_isHidden (false),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 m_isSelected (false),
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
49 m_isDestructed (false),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 qObjListEntry (null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 {
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
52 *selfptr = LDObjectPtr (this, [](LDObject* obj){ obj->finalDelete(); });
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 memset (m_coords, 0, sizeof m_coords);
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
54 m_self = selfptr->toWeakRef();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 chooseID();
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
56 g_allObjects[id()] = self();
751
49d4eb8edcd8 - don't let random colors be too dark (or fully white either for dark backgrounds which use white lines)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 741
diff changeset
57 setRandomColor (QColor::fromHsv (rand() % 360, rand() % 256, rand() % 96 + 128));
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
58 }
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
59
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
60 LDSubfile::LDSubfile (LDObjectPtr* selfptr) :
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
61 LDObject (selfptr)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
62 {
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
63 setLinkPointer (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
66 LDOBJ_DEFAULT_CTOR (LDEmpty, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
67 LDOBJ_DEFAULT_CTOR (LDError, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
68 LDOBJ_DEFAULT_CTOR (LDLine, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
69 LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
70 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
71 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
72 LDOBJ_DEFAULT_CTOR (LDVertex, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
73 LDOBJ_DEFAULT_CTOR (LDOverlay, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
74 LDOBJ_DEFAULT_CTOR (LDBFC, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
75 LDOBJ_DEFAULT_CTOR (LDComment, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
76
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 void LDObject::chooseID()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 {
771
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
81 // If this is the first pass we can just use a global ID counter for each
773
6eb3c88982ac - bfc red/green view and random colors are now mutually exclusive, enabling one disables the other.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 771
diff changeset
82 // unique object. Let's hope that nobody goes to create 17 million objects
6eb3c88982ac - bfc red/green view and random colors are now mutually exclusive, enabling one disables the other.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 771
diff changeset
83 // anytime soon.
771
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
84 if (g_idcursor < g_maxID)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 {
771
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
86 setID (g_idcursor++);
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
87 return;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
771
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
90 // In case someone does, we cannot really continue execution. We must abort,
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
91 // give the user a chance to save their documents though.
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
92 critical ("Created too many objects. Execution cannot continue. You have a "
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
93 "chance to save any changes to documents, then restart.");
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
94 (void) safeToCloseAll();
0f04e34bec54 - use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
Santeri Piippo <crimsondusk64@gmail.com>
parents: 770
diff changeset
95 exit (0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 void LDObject::setVertexCoord (int i, Axis ax, double value)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 Vertex v = vertex (i);
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
103 v.setCoordinate (ax, value);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 setVertex (i, v);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
109 QString LDComment::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 return format ("0 %1", text());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
116 QString LDSubfile::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
118 QString val = format ("1 %1 %2 ", color(), position());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 val += transform().toString();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 val += ' ';
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 val += fileInfo()->name();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 return val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
127 QString LDLine::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
129 QString val = format ("2 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 for (int i = 0; i < 2; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 return val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
139 QString LDTriangle::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
141 QString val = format ("3 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 for (int i = 0; i < 3; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 return val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
151 QString LDQuad::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
153 QString val = format ("4 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 for (int i = 0; i < 4; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 return val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
163 QString LDCondLine::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
165 QString val = format ("5 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 // Add the coordinates
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 for (int i = 0; i < 4; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 return val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
176 QString LDError::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 return contents();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
183 QString LDVertex::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 return format ("0 !LDFORGE VERTEX %1 %2", color(), pos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
190 QString LDEmpty::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 const char* LDBFC::k_statementStrings[] =
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 "CERTIFY CCW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 "CCW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 "CERTIFY CW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 "CW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 "NOCERTIFY",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 "INVERTNEXT",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 "CLIP",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 "CLIP CCW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 "CLIP CW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 "NOCLIP",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
211 QString LDBFC::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 return format ("0 BFC %1", LDBFC::k_statementStrings[m_statement]);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
218 QList<LDTrianglePtr> LDQuad::splitToTriangles()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 // Create the two triangles based on this quadrilateral:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 // 0---3 0---3 3
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 // | | | / /|
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 // | | ==> | / / |
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 // | | |/ / |
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 // 1---2 1 1---2
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
226 LDTrianglePtr tri1 (spawn<LDTriangle> (vertex (0), vertex (1), vertex (3)));
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
227 LDTrianglePtr tri2 (spawn<LDTriangle> (vertex (1), vertex (2), vertex (3)));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 // The triangles also inherit the quad's color
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 tri1->setColor (color());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 tri2->setColor (color());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
233 return {tri1, tri2};
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
238 void LDObject::replace (LDObjectPtr other)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 long idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 assert (idx != -1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 // Replace the instance of the old object with the new object
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
244 document().toStrongRef()->setObject (idx, other);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 // Remove the old object
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 destroy();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
252 void LDObject::swap (LDObjectPtr other)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 assert (document() == other->document());
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
255 document().toStrongRef()->swapObjects (self(), other);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 //
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
260 LDLine::LDLine (LDObjectPtr* selfptr, Vertex v1, Vertex v2) :
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
261 LDObject (selfptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 setVertex (0, v1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 setVertex (1, v2);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 //
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
269 LDQuad::LDQuad (LDObjectPtr* selfptr, const Vertex& v0, const Vertex& v1,
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
270 const Vertex& v2, const Vertex& v3) :
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
271 LDObject (selfptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 setVertex (0, v0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 setVertex (1, v1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 setVertex (2, v2);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 setVertex (3, v3);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 //
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
281 LDCondLine::LDCondLine (LDObjectPtr* selfptr, const Vertex& v0, const Vertex& v1,
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
282 const Vertex& v2, const Vertex& v3) :
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
283 LDLine (selfptr)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
284 {
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
285 setVertex (0, v0);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
286 setVertex (1, v1);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
287 setVertex (2, v2);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
288 setVertex (3, v3);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
289 }
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
290
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
291 // =============================================================================
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
292 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 LDObject::~LDObject() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 void LDObject::destroy()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 // If this object was selected, unselect it now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 if (isSelected())
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
301 deselect();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 // If this object was associated to a file, remove it off it now
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
304 if (document() != null)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
305 document().toStrongRef()->forgetObject (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 // Delete the GL lists
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
308 g_win->R()->forgetObject (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 // Remove this object from the list of LDObjects
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
311 g_allObjects.erase (g_allObjects.find (id()));
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
312 setDestructed (true);
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
313 }
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
314
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
315 //
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
316 // Deletes the object. Only the shared pointer is to call this!
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
317 //
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
318 void LDObject::finalDelete()
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
319 {
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
320 if (not isDestructed())
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
321 destroy();
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
322
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 delete this;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 //
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
328 static void transformObject (LDObjectPtr obj, Matrix transform, Vertex pos, LDColor parentcolor)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 switch (obj->type())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 {
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
332 case OBJ_Line:
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
333 case OBJ_CondLine:
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
334 case OBJ_Triangle:
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
335 case OBJ_Quad:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
337 for (int i = 0; i < obj->numVertices(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 Vertex v = obj->vertex (i);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 v.transform (transform, pos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 obj->setVertex (i, v);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
346 case OBJ_Subfile:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
348 LDSubfilePtr ref = qSharedPointerCast<LDSubfile> (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 Matrix newMatrix = transform * ref->transform();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 Vertex newpos = ref->position();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 newpos.transform (transform, pos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 ref->setPosition (newpos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 ref->setTransform (newMatrix);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 default:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
361 if (obj->color() == maincolor())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 obj->setColor (parentcolor);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 // =============================================================================
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
366 // -----------------------------------------------------------------------------
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
367 LDObjectList LDSubfile::inlineContents (bool deep, bool render)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
369 LDObjectList objs = fileInfo()->inlineContents (deep, render);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 // Transform the objects
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
372 for (LDObjectPtr obj : objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 // Set the parent now so we know what inlined the object.
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
375 obj->setParent (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 transformObject (obj, transform(), position(), color());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 return objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 //
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
384 LDPolygon* LDObject::getPolygon()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
385 {
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
386 LDObjectType ot = type();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
387 int num =
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
388 (ot == OBJ_Line) ? 2 :
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
389 (ot == OBJ_Triangle) ? 3 :
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
390 (ot == OBJ_Quad) ? 4 :
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
391 (ot == OBJ_CondLine) ? 5 :
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
392 0;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
393 if (num == 0)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
394 return null;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
395
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
396 LDPolygon* data = new LDPolygon;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
397 data->id = id();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
398 data->num = num;
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
399 data->color = color()->index();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
400
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
401 for (int i = 0; i < data->numVertices(); ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
402 data->vertices[i] = vertex (i);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
403
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
404 return data;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
405 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
406
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
407 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
408 //
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
409 QList<LDPolygon> LDSubfile::inlinePolygons()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
410 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
411 QList<LDPolygon> data = fileInfo()->inlinePolygons();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
412
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
413 for (LDPolygon& entry : data)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
414 for (int i = 0; i < entry.numVertices(); ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
415 entry.vertices[i].transform (transform(), position());
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
416
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
417 return data;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
418 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
419
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
420 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
421 // -----------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 long LDObject::lineNumber() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 assert (document() != null);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
426 for (int i = 0; i < document().toStrongRef()->getObjectCount(); ++i)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
427 if (document().toStrongRef()->getObject (i) == this)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 return i;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 return -1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 void LDObject::moveObjects (LDObjectList objs, const bool up)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 if (objs.isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 // If we move down, we need to iterate the array in reverse order.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 const long start = up ? 0 : (objs.size() - 1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 const long end = up ? objs.size() : -1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 const long incr = up ? 1 : -1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 LDObjectList objsToCompile;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
445 LDDocumentPtr file = objs[0]->document();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 for (long i = start; i != end; i += incr)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
449 LDObjectPtr obj = objs[i];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 const long idx = obj->lineNumber(),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 target = idx + (up ? -1 : 1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
454 if ((up && idx == 0) || (not up && idx == (long) file->objects().size() - 1l))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 // One of the objects hit the extrema. If this happens, this should be the first
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 // object to be iterated on. Thus, nothing has changed yet and it's safe to just
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 // abort the entire operation.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 assert (i == start);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 objsToCompile << obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 objsToCompile << file->getObject (target);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 obj->swap (file->getObject (target));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 removeDuplicates (objsToCompile);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 // The objects need to be recompiled, otherwise their pick lists are left with
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472 // the wrong index colors which messes up selection.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
473 for (LDObjectPtr obj : objsToCompile)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 g_win->R()->compileObject (obj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
479 QString LDObject::typeName (LDObjectType type)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
481 return LDObject::getDefault (type)->typeName();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
484 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
486 QString LDObject::describeObjects (const LDObjectList& objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
488 QString text;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 if (objs.isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 return "nothing"; // :)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
493 for (LDObjectType objType = OBJ_FirstType; objType < OBJ_NumTypes; ++objType)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495 int count = 0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
497 for (LDObjectPtr obj : objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498 if (obj->type() == objType)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499 count++;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501 if (count == 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503
762
d259256e1394 - added a macro for adding operator++ and operator-- to enums, less cast hell this way
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
504 if (not text.isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
505 text += ", ";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
507 QString noun = format ("%1%2", typeName (objType), plural (count));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
508
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
509 // Plural of "vertex" is "vertices", correct that
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
510 if (objType == OBJ_Vertex && count != 1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
511 noun = "vertices";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
512
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 text += format ("%1 %2", count, noun);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
515
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 return text;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
517 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
521 LDObjectPtr LDObject::topLevelParent()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
522 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523 if (parent() == null)
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
524 return self();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
526 LDObjectWeakPtr it (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
528 while (it.toStrongRef()->parent() != null)
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
529 it = it.toStrongRef()->parent();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
530
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
531 return it.toStrongRef();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
533
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
534 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
536 LDObjectPtr LDObject::next() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 long idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 assert (idx != -1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
541 if (idx == (long) document().toStrongRef()->getObjectCount() - 1)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
542 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
544 return document().toStrongRef()->getObject (idx + 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
547 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
549 LDObjectPtr LDObject::previous() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 long idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
552 assert (idx != -1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554 if (idx == 0)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
555 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
557 return document().toStrongRef()->getObject (idx - 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
559
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
561 //
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
562 bool LDObject::previousIsInvertnext (LDBFCPtr& ptr)
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
563 {
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
564 LDObjectPtr prev (previous());
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
565
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
566 if (prev != null && prev->type() == OBJ_BFC && prev.staticCast<LDBFC>()->statement() == LDBFC::InvertNext)
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
567 {
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
568 ptr = prev.staticCast<LDBFC>();
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
569 return true;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
570 }
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
571
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
572 return false;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
573 }
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
574
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
575 // =============================================================================
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
576 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 void LDObject::move (Vertex vect)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579 if (hasMatrix())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
581 LDMatrixObjectPtr mo = self().toStrongRef().dynamicCast<LDMatrixObject>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 mo->setPosition (mo->position() + vect);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 }
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
584 elif (type() == OBJ_Vertex)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 // ugh
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
587 self().toStrongRef().staticCast<LDVertex>()->pos += vect;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 {
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
591 for (int i = 0; i < numVertices(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592 setVertex (i, vertex (i) + vect);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
595
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597 //
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
598 LDObjectPtr LDObject::getDefault (const LDObjectType type)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
600 switch (type)
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
601 {
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
602 case OBJ_Comment: return spawn<LDComment>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
603 case OBJ_BFC: return spawn<LDBFC>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
604 case OBJ_Line: return spawn<LDLine>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
605 case OBJ_CondLine: return spawn<LDCondLine>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
606 case OBJ_Subfile: return spawn<LDSubfile>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
607 case OBJ_Triangle: return spawn<LDTriangle>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
608 case OBJ_Quad: return spawn<LDQuad>();
787
67cc5b47bbff - made select by color/type no longer require uniform selection
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
609 case OBJ_Empty: return spawn<LDEmpty>();
67cc5b47bbff - made select by color/type no longer require uniform selection
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
610 case OBJ_Error: return spawn<LDError>();
786
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
611 case OBJ_Vertex: return spawn<LDVertex>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
612 case OBJ_Overlay: return spawn<LDOverlay>();
71d786ce0dcc - LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
613 case OBJ_NumTypes: assert (false);
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
614 }
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
615 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
619 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
620 void LDObject::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621 void LDBFC::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622 void LDEmpty::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
623 void LDComment::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
624 void LDError::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628 void LDTriangle::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
629 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630 // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
631 // Thus, we swap 1 and 2.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632 Vertex tmp = vertex (1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633 setVertex (1, vertex (2));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
634 setVertex (2, tmp);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
637 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
638
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
639 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
640 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641 void LDQuad::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643 // Quad: 0 -> 1 -> 2 -> 3
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 // rev: 0 -> 3 -> 2 -> 1
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 // Thus, we swap 1 and 3.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646 Vertex tmp = vertex (1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
647 setVertex (1, vertex (3));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
648 setVertex (3, tmp);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653 void LDSubfile::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
655 if (document() == null)
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
656 return;
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
657
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
658 // Check whether subfile is flat
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
659 int axisSet = (1 << X) | (1 << Y) | (1 << Z);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
660 LDObjectList objs = inlineContents (true, false);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
661
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
662 for (LDObjectPtr obj : objs)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
663 {
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
664 for (int i = 0; i < obj->numVertices(); ++i)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
665 {
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
666 Vertex const& vrt = obj->vertex (i);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
667
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
668 if (axisSet & (1 << X) && vrt.x() != 0.0)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
669 axisSet &= ~(1 << X);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
670
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
671 if (axisSet & (1 << Y) && vrt.y() != 0.0)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
672 axisSet &= ~(1 << Y);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
673
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
674 if (axisSet & (1 << Z) && vrt.z() != 0.0)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
675 axisSet &= ~(1 << Z);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
676 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
677
783
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
678 if (axisSet == 0)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
679 break;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
680 }
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
681
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
682 if (axisSet != 0)
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
683 {
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
684 // Subfile has all vertices zero on one specific plane, so it is flat.
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
685 // Let's flip it.
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
686 Matrix matrixModifier = g_identity;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
687
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
688 if (axisSet & (1 << X))
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
689 matrixModifier[0] = -1;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
690
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
691 if (axisSet & (1 << Y))
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
692 matrixModifier[4] = -1;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
693
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
694 if (axisSet & (1 << Z))
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
695 matrixModifier[8] = -1;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
696
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
697 setTransform (transform() * matrixModifier);
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
698 return;
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
699 }
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
700
1db20d88650f - subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything
Santeri Piippo <crimsondusk64@gmail.com>
parents: 776
diff changeset
701 // Subfile is not flat. Resort to invertnext.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
702 int idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
703
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
704 if (idx > 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
705 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
706 LDBFCPtr bfc = previous().dynamicCast<LDBFC>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
707
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
708 if (not bfc.isNull() && bfc->statement() == LDBFC::InvertNext)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
709 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
710 // This is prefixed with an invertnext, thus remove it.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
711 bfc->destroy();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
712 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
714 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
715
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
716 // Not inverted, thus prefix it with a new invertnext.
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
717 document().toStrongRef()->insertObj (idx, spawn<LDBFC> (LDBFC::InvertNext));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
718 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
719
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
720 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
722 void LDLine::invert()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
723 {
775
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
724 // For lines, we swap the vertices.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
725 Vertex tmp = vertex (0);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
726 setVertex (0, vertex (1));
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
727 setVertex (1, tmp);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
729
775
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
730 // =============================================================================
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
731 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 void LDCondLine::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 {
775
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
734 // I don't think that a conditional line's control points need to be
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
735 // swapped, do they?
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
736 Vertex tmp = vertex (0);
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
737 setVertex (0, vertex (1));
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
738 setVertex (1, tmp);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
739 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
740
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
741 void LDVertex::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
742
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
743 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
744 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
745 LDLinePtr LDCondLine::demote()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
746 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
747 LDLinePtr replacement (spawn<LDLine>());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
748
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
749 for (int i = 0; i < replacement->numVertices(); ++i)
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
750 replacement->setVertex (i, vertex (i));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
751
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
752 replacement->setColor (color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
753
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
754 replace (replacement);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
755 return replacement;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
757
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
758 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
759 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
760 LDObjectPtr LDObject::fromID (int id)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
761 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
762 auto it = g_allObjects.find (id);
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
763
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
764 if (it != g_allObjects.end())
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
765 return *it;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
766
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
767 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
768 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
769
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
771 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
772 QString LDOverlay::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
773 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
774 return format ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
775 fileName(), camera(), x(), y(), width(), height());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
776 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
777
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
778 void LDOverlay::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
779
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
780 // =============================================================================
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
781 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
782 // Hook the set accessors of certain properties to this changeProperty function.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
783 // It takes care of history management so we can capture low-level changes, this
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
784 // makes history stuff work out of the box.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
785 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
786 template<typename T>
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
787 static void changeProperty (LDObjectPtr obj, T* ptr, const T& val)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
788 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
789 long idx;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
791 if (*ptr == val)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
792 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
793
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
794 if (obj->document() != null && (idx = obj->lineNumber()) != -1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
795 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
796 QString before = obj->asText();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 *ptr = val;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
798 QString after = obj->asText();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
799
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
800 if (before != after)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
801 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
802 obj->document().toStrongRef()->addToHistory (new EditHistory (idx, before, after));
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
803 g_win->R()->compileObject (obj);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
804 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
805 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
806 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
807 *ptr = val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
808 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
809
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
810 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
811 //
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
812 void LDObject::setColor (LDColor const& val)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
813 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
814 changeProperty (self(), &m_color, val);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
815 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
816
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
817 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
819 const Vertex& LDObject::vertex (int i) const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
820 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 return m_coords[i]->data();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
822 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
823
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
824 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
825 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
826 void LDObject::setVertex (int i, const Vertex& vert)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
827 {
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
828 if (document() != null)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
829 document().toStrongRef()->vertexChanged (*m_coords[i], vert);
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
830
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
831 changeProperty (self(), &m_coords[i], LDSharedVertex::getSharedVertex (vert));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
832 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
833
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
834 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
835 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
836 void LDMatrixObject::setPosition (const Vertex& a)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
837 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
838 LDObjectPtr ref = linkPointer().toStrongRef();
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
839
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
840 if (ref->document() != null)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
841 ref->document().toStrongRef()->removeKnownVerticesOf (ref);
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
842
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
843 changeProperty (ref, &m_position, LDSharedVertex::getSharedVertex (a));
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
844
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
845 if (ref->document() != null)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
846 ref->document().toStrongRef()->addKnownVerticesOf (ref);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
847 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
848
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
849 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
850 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
851 void LDMatrixObject::setTransform (const Matrix& val)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
852 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
853 LDObjectPtr ref = linkPointer().toStrongRef();
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
854
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
855 if (ref->document() != null)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
856 ref->document().toStrongRef()->removeKnownVerticesOf (ref);
724
7a82693d971a - fixed: rotating a subfile would make known verts go out of sync
Santeri Piippo <crimsondusk64@gmail.com>
parents: 719
diff changeset
857
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
858 changeProperty (ref, &m_transform, val);
724
7a82693d971a - fixed: rotating a subfile would make known verts go out of sync
Santeri Piippo <crimsondusk64@gmail.com>
parents: 719
diff changeset
859
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
860 if (ref->document() != null)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
861 ref->document().toStrongRef()->addKnownVerticesOf (ref);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
862 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
863
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
864 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
865 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
866 static QMap<Vertex, LDSharedVertex*> g_sharedVerts;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
867
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
868 LDSharedVertex* LDSharedVertex::getSharedVertex (const Vertex& a)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
869 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870 auto it = g_sharedVerts.find (a);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
871
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
872 if (it == g_sharedVerts.end())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
873 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
874 LDSharedVertex* v = new LDSharedVertex (a);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
875 g_sharedVerts[a] = v;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
876 return v;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
877 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
878
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
879 return *it;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
880 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
881
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
882 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
883 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
884 void LDSharedVertex::addRef (LDObjectPtr a)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
885 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
886 m_refs << a;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
887 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
888
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
889 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
890 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
891 void LDSharedVertex::delRef (LDObjectPtr a)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
892 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
893 m_refs.removeOne (a);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
894
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
895 if (m_refs.empty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
896 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
897 g_sharedVerts.remove (m_data);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
898 delete this;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
899 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
900 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
901
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
902 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
903 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
904 void LDObject::select()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
905 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
906 assert (document() != null);
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
907 document().toStrongRef()->addToSelection (self());
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
908
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
909 // If this object is inverted with INVERTNEXT, pick the INVERTNEXT as well.
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
910 LDBFCPtr invertnext;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
911
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
912 if (previousIsInvertnext (invertnext))
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
913 invertnext->select();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
914 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
915
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
916 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
917 //
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
918 void LDObject::deselect()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
919 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
920 assert (document() != null);
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
921 document().toStrongRef()->removeFromSelection (self());
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
922
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
923 // If this object is inverted with INVERTNEXT, deselect the INVERTNEXT as well.
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
924 LDBFCPtr invertnext;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
925
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
926 if (previousIsInvertnext (invertnext))
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
927 invertnext->deselect();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
928 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
929
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
930 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
931 //
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 787
diff changeset
932 QString getLicenseText (int id)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
933 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
934 switch (id)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
935 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
936 case 0:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
937 return g_CALicense;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
938
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
939 case 1:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
940 return g_nonCALicense;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
941
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
942 case 2:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
943 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
944 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
945
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
946 assert (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
947 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
948 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
949
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
950 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
951 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
952 LDObjectPtr LDObject::createCopy() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
953 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
954 LDObjectPtr copy = parseLine (asText());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
955 return copy;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
956 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
957
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
958 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
959 //
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
960 void LDSubfile::setFileInfo (const LDDocumentPtr& a)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
961 {
725
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
962 if (document() != null)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
963 document().toStrongRef()->removeKnownVerticesOf (self());
725
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
964
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
965 m_fileInfo = a;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
966
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
967 // If it's an immediate subfile reference (i.e. this subfile belongs in an
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
968 // explicit file), we need to pre-compile the GL polygons for the document
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
969 // if they don't exist already.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
970 if (a != null &&
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
971 a->isImplicit() == false &&
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
972 a->polygonData().isEmpty())
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
973 {
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
974 a->initializeCachedData();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
975 }
725
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
976
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
977 if (document() != null)
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 783
diff changeset
978 document().toStrongRef()->addKnownVerticesOf (self());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
979 };

mercurial