src/ldObject.cc

Sun, 01 Jun 2014 03:15:36 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 01 Jun 2014 03:15:36 +0300
changeset 783
1db20d88650f
parent 776
624131d0163d
child 784
f82ab4d3c7b4
permissions
-rw-r--r--

- subfile inverting now detects flatness and acts accordingly instead of naively applying invertnext to everything

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
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
35 static QMap<long, LDObjectWeakPtr> g_allObjects;
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 m_document (null),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 qObjListEntry (null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 {
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
53 *selfptr = LDObjectPtr (this, [](LDObject* obj){ obj->finalDelete(); });
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 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
55 m_self = selfptr->toWeakRef();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 chooseID();
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
57 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
58 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
59 }
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
60
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
61 LDSubfile::LDSubfile (LDObjectPtr* selfptr) :
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
62 LDObject (selfptr)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
63 {
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
64 setLinkPointer (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
67 LDOBJ_DEFAULT_CTOR (LDEmpty, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
68 LDOBJ_DEFAULT_CTOR (LDError, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
69 LDOBJ_DEFAULT_CTOR (LDLine, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
70 LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
71 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
72 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
73 LDOBJ_DEFAULT_CTOR (LDVertex, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
74 LDOBJ_DEFAULT_CTOR (LDOverlay, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
75 LDOBJ_DEFAULT_CTOR (LDBFC, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
76 LDOBJ_DEFAULT_CTOR (LDComment, LDObject)
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
77
655
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 void LDObject::chooseID()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 {
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
82 // 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
83 // 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
84 // 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
85 if (g_idcursor < g_maxID)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 {
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
87 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
88 return;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
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
91 // 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
92 // 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
93 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
94 "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
95 (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
96 exit (0);
655
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 void LDObject::setVertexCoord (int i, Axis ax, double value)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 Vertex v = vertex (i);
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
104 v.setCoordinate (ax, value);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 setVertex (i, v);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
110 String LDComment::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 return format ("0 %1", text());
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
117 String LDSubfile::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 {
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
119 String val = format ("1 %1 %2 ", color(), position());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 val += transform().toString();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 val += ' ';
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 val += fileInfo()->name();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 return val;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
128 String LDLine::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 {
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
130 String val = format ("2 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 for (int i = 0; i < 2; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 return val;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
140 String LDTriangle::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 {
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
142 String val = format ("3 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 for (int i = 0; i < 3; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 return val;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
152 String LDQuad::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 {
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
154 String val = format ("4 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 for (int i = 0; i < 4; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 return val;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
164 String LDCondLine::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 {
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
166 String val = format ("5 %1", color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 // Add the coordinates
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 for (int i = 0; i < 4; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 val += format (" %1", vertex (i));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 return val;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
177 String LDError::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 return contents();
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
184 String LDVertex::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 return format ("0 !LDFORGE VERTEX %1 %2", color(), pos);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
191 String LDEmpty::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 return "";
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 const char* LDBFC::k_statementStrings[] =
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 "CERTIFY CCW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 "CCW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 "CERTIFY CW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 "CW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 "NOCERTIFY",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 "INVERTNEXT",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 "CLIP",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 "CLIP CCW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 "CLIP CW",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 "NOCLIP",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
212 String LDBFC::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 return format ("0 BFC %1", LDBFC::k_statementStrings[m_statement]);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
219 QList<LDTrianglePtr> LDQuad::splitToTriangles()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 // Create the two triangles based on this quadrilateral:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 // 0---3 0---3 3
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 // | | |/ / |
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 // 1---2 1 1---2
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
227 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
228 LDTrianglePtr tri2 (spawn<LDTriangle> (vertex (1), vertex (2), vertex (3)));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 // The triangles also inherit the quad's color
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 tri1->setColor (color());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 tri2->setColor (color());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
234 return {tri1, tri2};
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
239 void LDObject::replace (LDObjectPtr other)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 long idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 assert (idx != -1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 // Replace the instance of the old object with the new object
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 document()->setObject (idx, other);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 // Remove the old object
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 destroy();
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
253 void LDObject::swap (LDObjectPtr other)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 assert (document() == other->document());
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
256 document()->swapObjects (self(), other);
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 //
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
261 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
262 LDObject (selfptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 setVertex (0, v1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 setVertex (1, v2);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 //
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
270 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
271 const Vertex& v2, const Vertex& v3) :
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
272 LDObject (selfptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 setVertex (0, v0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 setVertex (1, v1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 setVertex (2, v2);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 setVertex (3, v3);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 //
770
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
282 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
283 const Vertex& v2, const Vertex& v3) :
b04c1e6ca1fb - hopefully stabilized the entire shared pointers deal now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 769
diff changeset
284 LDLine (selfptr)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
285 {
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
286 setVertex (0, v0);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
287 setVertex (1, v1);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
288 setVertex (2, v2);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
289 setVertex (3, v3);
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 // =============================================================================
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
293 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 LDObject::~LDObject() {}
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 void LDObject::destroy()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 // If this object was selected, unselect it now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 if (isSelected())
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
302 deselect();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 // If this object was associated to a file, remove it off it now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 if (document())
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
306 document()->forgetObject (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 // Delete the GL lists
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
309 g_win->R()->forgetObject (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
311 // 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
312 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
313 setDestructed (true);
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 //
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
317 // 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
318 //
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
319 void LDObject::finalDelete()
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
320 {
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
321 if (not isDestructed())
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
322 destroy();
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
323
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 delete this;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
329 static void transformObject (LDObjectPtr obj, Matrix transform, Vertex pos, int parentcolor)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 switch (obj->type())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 case LDObject::ELine:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 case LDObject::ECondLine:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 case LDObject::ETriangle:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 case LDObject::EQuad:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
338 for (int i = 0; i < obj->numVertices(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 Vertex v = obj->vertex (i);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 v.transform (transform, pos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 obj->setVertex (i, v);
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 case LDObject::ESubfile:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
349 LDSubfilePtr ref = qSharedPointerCast<LDSubfile> (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 Matrix newMatrix = transform * ref->transform();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 Vertex newpos = ref->position();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 newpos.transform (transform, pos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 ref->setPosition (newpos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 ref->setTransform (newMatrix);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 default:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 if (obj->color() == maincolor)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 obj->setColor (parentcolor);
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 // =============================================================================
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
367 // -----------------------------------------------------------------------------
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
368 LDObjectList LDSubfile::inlineContents (bool deep, bool render)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
370 LDObjectList objs = fileInfo()->inlineContents (deep, render);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 // Transform the objects
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
373 for (LDObjectPtr obj : objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 // 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
376 obj->setParent (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 transformObject (obj, transform(), position(), color());
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 return objs;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 //
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
385 LDPolygon* LDObject::getPolygon()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
386 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
387 Type ot = type();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
388 int num =
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
389 (ot == LDObject::ELine) ? 2 :
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
390 (ot == LDObject::ETriangle) ? 3 :
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
391 (ot == LDObject::EQuad) ? 4 :
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
392 (ot == LDObject::ECondLine) ? 5 :
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
393 0;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
394 if (num == 0)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
395 return null;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
396
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
397 LDPolygon* data = new LDPolygon;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
398 data->id = id();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
399 data->num = num;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
400 data->color = color();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
401
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
402 for (int i = 0; i < data->numVertices(); ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
403 data->vertices[i] = vertex (i);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
404
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
405 return data;
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 //
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
410 QList<LDPolygon> LDSubfile::inlinePolygons()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
411 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
412 QList<LDPolygon> data = fileInfo()->inlinePolygons();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
413
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
414 for (LDPolygon& entry : data)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
415 for (int i = 0; i < entry.numVertices(); ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
416 entry.vertices[i].transform (transform(), position());
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
417
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
418 return data;
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 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
422 // -----------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 long LDObject::lineNumber() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 assert (document() != null);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 for (int i = 0; i < document()->getObjectCount(); ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 if (document()->getObject (i) == this)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429 return i;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 return -1;
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 void LDObject::moveObjects (LDObjectList objs, const bool up)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 if (objs.isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 // 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
442 const long start = up ? 0 : (objs.size() - 1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 const long end = up ? objs.size() : -1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 const long incr = up ? 1 : -1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 LDObjectList objsToCompile;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 LDDocument* file = objs[0]->document();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 for (long i = start; i != end; i += incr)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
450 LDObjectPtr obj = objs[i];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 const long idx = obj->lineNumber(),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 target = idx + (up ? -1 : 1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
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
455 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
456 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 // 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
458 // 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
459 // abort the entire operation.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 assert (i == start);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 return;
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 objsToCompile << obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 objsToCompile << file->getObject (target);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 obj->swap (file->getObject (target));
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 removeDuplicates (objsToCompile);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472 // 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
473 // the wrong index colors which messes up selection.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
474 for (LDObjectPtr obj : objsToCompile)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 g_win->R()->compileObject (obj);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
480 String LDObject::typeName (LDObject::Type type)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
482 return LDObject::getDefault (type)->typeName();
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
487 String LDObject::describeObjects (const LDObjectList& objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
488 {
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
489 String text;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 if (objs.isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492 return "nothing"; // :)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493
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
494 for (Type objType = EFirstType; objType < ENumTypes; ++objType)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496 int count = 0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
498 for (LDObjectPtr obj : objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499 if (obj->type() == objType)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 count++;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 if (count == 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
504
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
505 if (not text.isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506 text += ", ";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
508 String noun = format ("%1%2", typeName (objType), plural (count));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
509
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
510 // Plural of "vertex" is "vertices", correct that
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
511 if (objType == EVertex && count != 1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
512 noun = "vertices";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 text += format ("%1 %2", count, noun);
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
517 return text;
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
522 LDObjectPtr LDObject::topLevelParent()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 if (parent() == null)
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
525 return self();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
527 LDObjectWeakPtr it (self());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
529 while (it.toStrongRef()->parent() != null)
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
530 it = it.toStrongRef()->parent();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
532 return it.toStrongRef();
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
536 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
537 LDObjectPtr LDObject::next() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 long idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540 assert (idx != -1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 if (idx == (long) document()->getObjectCount() - 1)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
543 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 return document()->getObject (idx + 1);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
550 LDObjectPtr LDObject::previous() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
552 long idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553 assert (idx != -1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
555 if (idx == 0)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
556 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
557
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 return document()->getObject (idx - 1);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 //
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
563 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
564 {
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
565 LDObjectPtr prev (previous());
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
566
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
567 if (prev != null && prev->type() == EBFC && prev.staticCast<LDBFC>()->statement() == LDBFC::InvertNext)
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
568 {
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
569 ptr = prev.staticCast<LDBFC>();
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
570 return true;
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
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
573 return false;
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 // =============================================================================
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
577 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 void LDObject::move (Vertex vect)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 if (hasMatrix())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
582 LDMatrixObjectPtr mo = self().toStrongRef().dynamicCast<LDMatrixObject>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 mo->setPosition (mo->position() + vect);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
584 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585 elif (type() == LDObject::EVertex)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 // ugh
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
588 self().toStrongRef().staticCast<LDVertex>()->pos += vect;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591 {
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
592 for (int i = 0; i < numVertices(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 setVertex (i, vertex (i) + vect);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
599 LDObjectPtr LDObject::getDefault (const LDObject::Type type)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
600 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
601 switch (type)
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
602 {
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
603 case EComment: return spawn<LDComment>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
604 case EBFC: return spawn<LDBFC>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
605 case ELine: return spawn<LDLine>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
606 case ECondLine: return spawn<LDCondLine>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
607 case ESubfile: return spawn<LDSubfile>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
608 case ETriangle: return spawn<LDTriangle>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
609 case EQuad: return spawn<LDQuad>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
610 case EEmpty: return spawn<LDEmpty>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
611 case EError: return spawn<LDError>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
612 case EVertex: return spawn<LDVertex>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
613 case EOverlay: return spawn<LDOverlay>();
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
614 case EUnidentified: assert (false);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
615 case ENumTypes: assert (false);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
616 }
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
617 return LDObjectPtr();
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622 void LDObject::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
623 void LDBFC::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
624 void LDEmpty::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625 void LDComment::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626 void LDError::invert() {}
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 // =============================================================================
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 void LDTriangle::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
631 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632 // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633 // Thus, we swap 1 and 2.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
634 Vertex tmp = vertex (1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 setVertex (1, vertex (2));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636 setVertex (2, tmp);
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 return;
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 // =============================================================================
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 void LDQuad::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 // Quad: 0 -> 1 -> 2 -> 3
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646 // rev: 0 -> 3 -> 2 -> 1
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
647 // Thus, we swap 1 and 3.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
648 Vertex tmp = vertex (1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649 setVertex (1, vertex (3));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 setVertex (3, tmp);
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
655 void LDSubfile::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
656 {
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
657 // 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
658 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
659 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
660
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 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
662 {
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 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
664 {
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 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
666
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 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
668 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
669
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 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
671 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
672
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 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
674 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
675 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
676
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
677 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
678 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
679 }
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 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
682 {
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 // 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
684 // 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
685 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
686
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 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
688 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
689
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 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
691 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
692
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 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
694 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
695
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 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
697 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
698 }
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 // Subfile is not flat. Resort to invertnext.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
701 int idx = lineNumber();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
702
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
703 if (idx > 0)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
704 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
705 LDBFCPtr bfc = previous().dynamicCast<LDBFC>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
706
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
707 if (not bfc.isNull() && bfc->statement() == LDBFC::InvertNext)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
708 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
709 // This is prefixed with an invertnext, thus remove it.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
710 bfc->destroy();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
711 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
712 }
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 // Not inverted, thus prefix it with a new invertnext.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
716 document()->insertObj (idx, spawn<LDBFC> (LDBFC::InvertNext));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
717 }
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 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
721 void LDLine::invert()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
722 {
775
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
723 // For lines, we swap the vertices.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
724 Vertex tmp = vertex (0);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
725 setVertex (0, vertex (1));
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
726 setVertex (1, tmp);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
727 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728
775
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
729 // =============================================================================
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
730 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
731 void LDCondLine::invert()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 {
775
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
733 // 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
734 // swapped, do they?
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
735 Vertex tmp = vertex (0);
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
736 setVertex (0, vertex (1));
4661d6e83630 - don't crash when inverting conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents: 773
diff changeset
737 setVertex (1, tmp);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
738 }
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 void LDVertex::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
741
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 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
744 LDLinePtr LDCondLine::demote()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
745 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
746 LDLinePtr replacement (spawn<LDLine>());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
747
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
748 for (int i = 0; i < replacement->numVertices(); ++i)
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
749 replacement->setVertex (i, vertex (i));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
750
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
751 replacement->setColor (color());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
752
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
753 replace (replacement);
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
754 return replacement;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
755 }
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 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
759 LDObjectPtr LDObject::fromID (int id)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
760 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
761 auto it = g_allObjects.find (id);
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
762
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
763 if (it != g_allObjects.end())
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
764 return *it;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
765
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
766 return LDObjectPtr();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
767 }
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 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
771 String LDOverlay::asText() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
772 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
773 return format ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
774 fileName(), camera(), x(), y(), width(), height());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
775 }
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 void LDOverlay::invert() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
778
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
779 // =============================================================================
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
780 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
781 // Hook the set accessors of certain properties to this changeProperty function.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
782 // 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
783 // makes history stuff work out of the box.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
784 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
785 template<typename T>
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
786 static void changeProperty (LDObjectPtr obj, T* ptr, const T& val)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
787 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
788 long idx;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
789
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 if (*ptr == val)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
791 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
792
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
793 if (obj->document() != null && (idx = obj->lineNumber()) != -1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
794 {
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
795 String before = obj->asText();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796 *ptr = val;
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
797 String after = obj->asText();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
798
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
799 if (before != after)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
800 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
801 obj->document()->addToHistory (new EditHistory (idx, before, after));
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
802 g_win->R()->compileObject (obj);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
803 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
804 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
805 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
806 *ptr = val;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
807 }
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 void LDObject::setColor (const int& val)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
812 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
813 changeProperty (self(), &m_color, val);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814 }
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 const Vertex& LDObject::vertex (int i) const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
819 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
820 return m_coords[i]->data();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 }
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 void LDObject::setVertex (int i, const Vertex& vert)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
826 {
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
827 if (document() != null)
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
828 document()->vertexChanged (*m_coords[i], vert);
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
829
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
830 changeProperty (self(), &m_coords[i], LDSharedVertex::getSharedVertex (vert));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
831 }
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 void LDMatrixObject::setPosition (const Vertex& a)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
836 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
837 LDObjectPtr ref = linkPointer().toStrongRef();
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
838
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
839 if (ref->document() != null)
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
840 ref->document()->removeKnownVerticesOf (ref);
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
841
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
842 changeProperty (ref, &m_position, LDSharedVertex::getSharedVertex (a));
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
843
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
844 if (ref->document() != null)
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
845 ref->document()->addKnownVerticesOf (ref);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
846 }
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 void LDMatrixObject::setTransform (const Matrix& val)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
851 {
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
852 LDObjectPtr ref = linkPointer().toStrongRef();
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
853
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
854 if (ref->document() != null)
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
855 ref->document()->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
856
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
857 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
858
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
859 if (ref->document() != null)
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
860 ref->document()->addKnownVerticesOf (ref);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
861 }
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 static QMap<Vertex, LDSharedVertex*> g_sharedVerts;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
866
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
867 LDSharedVertex* LDSharedVertex::getSharedVertex (const Vertex& a)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
868 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
869 auto it = g_sharedVerts.find (a);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
871 if (it == g_sharedVerts.end())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
872 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
873 LDSharedVertex* v = new LDSharedVertex (a);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
874 g_sharedVerts[a] = v;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
875 return v;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
876 }
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 return *it;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
879 }
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 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
883 void LDSharedVertex::addRef (LDObjectPtr a)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
884 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
885 m_refs << a;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
886 }
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 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
890 void LDSharedVertex::delRef (LDObjectPtr a)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
891 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
892 m_refs.removeOne (a);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
893
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
894 if (m_refs.empty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
895 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
896 g_sharedVerts.remove (m_data);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
897 delete this;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
898 }
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 void LDObject::select()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
904 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
905 assert (document() != null);
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
906 document()->addToSelection (self());
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
907
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
908 // 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
909 LDBFCPtr invertnext;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
910
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
911 if (previousIsInvertnext (invertnext))
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
912 invertnext->select();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
913 }
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 //
767
44f0d5322628 - slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 764
diff changeset
917 void LDObject::deselect()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
918 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
919 assert (document() != null);
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
920 document()->removeFromSelection (self());
776
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
921
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
922 // 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
923 LDBFCPtr invertnext;
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
924
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
925 if (previousIsInvertnext (invertnext))
624131d0163d - selecting an invertnext'd object now also selects the invertnext
Santeri Piippo <crimsondusk64@gmail.com>
parents: 775
diff changeset
926 invertnext->deselect();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
927 }
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 //
739
152b33a6d51b - type-aliased QString to String
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
931 String getLicenseText (int id)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
932 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
933 switch (id)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
934 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
935 case 0:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
936 return g_CALicense;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
937
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
938 case 1:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
939 return g_nonCALicense;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
940
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
941 case 2:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
942 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
943 }
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 assert (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
946 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
947 }
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 //
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
951 LDObjectPtr LDObject::createCopy() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
952 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
953 LDObjectPtr copy = parseLine (asText());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
954 return copy;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
955 }
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 void LDSubfile::setFileInfo (const LDDocumentPointer& a)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
960 {
725
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
961 if (document() != null)
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
962 document()->removeKnownVerticesOf (self());
725
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
963
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
964 m_fileInfo = a;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
965
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
966 // 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
967 // 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
968 // if they don't exist already.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
969 if (a != null &&
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
970 a->isImplicit() == false &&
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
971 a->polygonData().isEmpty())
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
972 {
719
f2cc5964f52d - sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
973 a->initializeCachedData();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
974 }
725
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
975
37b71daf4cb5 - added ability to draw with random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 724
diff changeset
976 if (document() != null)
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
977 document()->addKnownVerticesOf (self());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
978 };

mercurial