Thu, 11 Jan 2018 15:30:30 +0200
renderer rework
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 |
1222 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
655
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QMessageBox> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QFileDialog> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QDir> |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
22 | #include <QTime> |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <QApplication> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "main.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "ldDocument.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "miscallenous.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
959
diff
changeset
|
27 | #include "mainwindow.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | #include "editHistory.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "glRenderer.h" |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
30 | #include "glCompiler.h" |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
31 | #include "partdownloader.h" |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
32 | #include "ldpaths.h" |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
979
diff
changeset
|
33 | #include "documentloader.h" |
957
429c7ed3cc54
Refactor OpenProgressDialog out of dialogs.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
954
diff
changeset
|
34 | #include "dialogs/openprogressdialog.h" |
998 | 35 | #include "documentmanager.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
1217 | 37 | LDDocument::LDDocument(DocumentManager* parent) : |
38 | QObject(parent), | |
39 | HierarchyElement(parent), | |
40 | m_history(new EditHistory(this)), | |
41 | m_isCache(true), | |
42 | m_verticesOutdated(true), | |
43 | m_needVertexMerge(true), | |
44 | m_beingDestroyed(false), | |
45 | m_gldata(new LDGLData), | |
46 | m_manager(parent) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | { |
1217 | 48 | setSavePosition(-1); |
49 | setTabIndex(-1); | |
719
f2cc5964f52d
- sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
50 | m_needsReCache = true; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | LDDocument::~LDDocument() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | { |
998 | 55 | m_beingDestroyed = true; |
56 | ||
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
994
diff
changeset
|
57 | for (int i = 0; i < m_objects.size(); ++i) |
998 | 58 | m_objects[i]->destroy(); |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
994
diff
changeset
|
59 | |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
60 | delete m_history; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | delete m_gldata; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
64 | QString LDDocument::name() const |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
65 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
66 | return m_name; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
67 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
68 | |
1217 | 69 | void LDDocument::setName(QString value) |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
70 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
71 | m_name = value; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
72 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
73 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
74 | const LDObjectList& LDDocument::objects() const |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
75 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
76 | return m_objects; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
77 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
78 | |
983
05ba93066194
Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
981
diff
changeset
|
79 | EditHistory* LDDocument::history() const |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
80 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
81 | return m_history; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
82 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
83 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
84 | QString LDDocument::fullPath() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
85 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
86 | return m_fullPath; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
87 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
88 | |
1217 | 89 | void LDDocument::setFullPath(QString value) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | { |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
91 | m_fullPath = value; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
92 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
93 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
94 | int LDDocument::tabIndex() const |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
95 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
96 | return m_tabIndex; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
97 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
98 | |
1217 | 99 | void LDDocument::setTabIndex(int value) |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
100 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
101 | m_tabIndex = value; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
102 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
103 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
104 | const QList<LDPolygon>& LDDocument::polygonData() const |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
105 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
106 | return m_polygonData; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
107 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
108 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
109 | long LDDocument::savePosition() const |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
110 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
111 | return m_savePosition; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
112 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
113 | |
1217 | 114 | void LDDocument::setSavePosition(long value) |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
115 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
116 | m_savePosition = value; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
117 | } |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
118 | |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
119 | QString LDDocument::defaultName() const |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
120 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
121 | return m_defaultName; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
122 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
123 | |
1217 | 124 | void LDDocument::setDefaultName(QString value) |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
125 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
126 | m_defaultName = value; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
127 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
128 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
129 | void LDDocument::openForEditing() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
130 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
131 | if (m_isCache) |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
132 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
133 | m_isCache = false; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
134 | m_window->updateDocumentList(); |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
135 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
136 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
137 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
138 | bool LDDocument::isCache() const |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
139 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
140 | return m_isCache; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
141 | } |
788
c9d1dad83ad0
- added an action for opening the subfiles pointed to by selected references as editable documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
786
diff
changeset
|
142 | |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
143 | void LDDocument::addHistoryStep() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
144 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
145 | history()->addStep(); |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
146 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
147 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
148 | void LDDocument::undo() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
149 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
150 | history()->undo(); |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
151 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
152 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
153 | void LDDocument::redo() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
154 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
155 | history()->redo(); |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
156 | } |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
157 | |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
158 | void LDDocument::clearHistory() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
159 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
160 | history()->clear(); |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
161 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
162 | |
1217 | 163 | void LDDocument::addToHistory(AbstractHistoryEntry* entry) |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
164 | { |
1217 | 165 | history()->add(entry); |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
166 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
167 | |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
168 | void LDDocument::close() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
169 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
170 | if (not isCache()) |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
171 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
172 | m_isCache = true; |
1217 | 173 | print("Closed %1", name()); |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
174 | m_window->updateDocumentList(); |
1231 | 175 | emit closed(); |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
176 | } |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
177 | } |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
178 | |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
179 | LDGLData* LDDocument::glData() |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
180 | { |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
181 | return m_gldata; |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
182 | } |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
183 | |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
184 | // ============================================================================= |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
185 | // |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
186 | // Performs safety checks. Do this before closing any files! |
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
187 | // |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | bool LDDocument::isSafeToClose() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | { |
847 | 190 | using msgbox = QMessageBox; |
1217 | 191 | setlocale(LC_ALL, "C"); |
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 | // If we have unsaved changes, warn and give the option of saving. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | if (hasUnsavedChanges()) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | { |
1217 | 196 | QString message = format(tr("There are unsaved changes to %1. Should it be saved?"), getDisplayName()); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | |
1217 | 198 | int button = msgbox::question(m_window, QObject::tr("Unsaved Changes"), message, |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | |
1217 | 201 | switch(button) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | case msgbox::Yes: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | // If we don't have a file path yet, we have to ask the user for one. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | if (name().length() == 0) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | { |
1217 | 208 | QString newpath = QFileDialog::getSaveFileName(m_window, QObject::tr("Save As"), |
209 | name(), QObject::tr("LDraw files(*.dat *.ldr)")); | |
655
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 | if (newpath.length() == 0) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | return false; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | |
1217 | 214 | setName(newpath); |
655
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 | |
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:
656
diff
changeset
|
217 | if (not save()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | { |
1217 | 219 | message = format(QObject::tr("Failed to save %1(%2)\nDo you still want to close?"), |
220 | name(), strerror(errno)); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | |
1217 | 222 | if (msgbox::critical(m_window, QObject::tr("Save Failure"), message, |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No) |
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 | return false; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | } |
744
bbe0e1834065
- removed rest of the uses of <anonymous>
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
228 | break; |
bbe0e1834065
- removed rest of the uses of <anonymous>
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
229 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | case msgbox::Cancel: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | return false; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | default: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | break; |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | return true; |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | // |
1217 | 244 | bool LDDocument::save(QString path, int64* sizeptr) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | { |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
246 | if (isCache()) |
781
aa823ba3241d
- when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
770
diff
changeset
|
247 | return false; |
aa823ba3241d
- when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
770
diff
changeset
|
248 | |
834
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
249 | if (not path.length()) |
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
250 | path = fullPath(); |
655
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 | // If the second object in the list holds the file name, update that now. |
1217 | 253 | LDObject* nameObject = getObject(1); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
255 | if (nameObject and nameObject->type() == OBJ_Comment) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | { |
1217 | 257 | LDComment* nameComment = static_cast<LDComment*>(nameObject); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | |
1217 | 259 | if (nameComment->text().left(6) == "Name: ") |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | { |
1217 | 261 | QString newname = shortenName(path); |
262 | nameComment->setText(format("Name: %1", newname)); | |
981
5d5d84ab2c48
Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
980
diff
changeset
|
263 | m_window->buildObjectList(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | |
781
aa823ba3241d
- when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
770
diff
changeset
|
267 | QByteArray data; |
aa823ba3241d
- when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
770
diff
changeset
|
268 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
269 | if (sizeptr) |
834
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
270 | *sizeptr = 0; |
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
271 | |
944 | 272 | // File is open, now save the model to it. Note that LDraw requires files to have DOS line endings. |
273 | for (LDObject* obj : objects()) | |
834
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
274 | { |
1217 | 275 | QByteArray subdata((obj->asText() + "\r\n").toUtf8()); |
276 | data.append(subdata); | |
781
aa823ba3241d
- when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
770
diff
changeset
|
277 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
278 | if (sizeptr) |
834
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
279 | *sizeptr += subdata.size(); |
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
280 | } |
3e697ba996e8
- now prints the filesize upon successful save
Santeri Piippo <crimsondusk64@gmail.com>
parents:
831
diff
changeset
|
281 | |
1217 | 282 | QFile f(path); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | |
1217 | 284 | if (not f.open(QIODevice::WriteOnly)) |
781
aa823ba3241d
- when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
770
diff
changeset
|
285 | return false; |
aa823ba3241d
- when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
770
diff
changeset
|
286 | |
1217 | 287 | f.write(data); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | f.close(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | // We have successfully saved, update the save position now. |
1217 | 291 | setSavePosition(history()->position()); |
292 | setFullPath(path); | |
293 | setName(shortenName(path)); | |
294 | m_window->updateDocumentListItem(this); | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
295 | m_window->updateTitle(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | return true; |
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 | |
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 | // |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
301 | void LDDocument::clear() |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
302 | { |
944 | 303 | for (LDObject* obj : objects()) |
1217 | 304 | forgetObject(obj); |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
305 | } |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
306 | |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
307 | // ============================================================================= |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
782
diff
changeset
|
308 | // |
1217 | 309 | static void CheckTokenCount(const QStringList& tokens, int num) |
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 | if (tokens.size() != num) |
1217 | 312 | throw QString(format("Bad amount of tokens, expected %1, got %2", num, tokens.size())); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | // |
1217 | 317 | static void CheckTokenNumbers(const QStringList& tokens, int min, int max) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | bool ok; |
1217 | 320 | QRegExp scientificRegex("\\-?[0-9]+\\.[0-9]+e\\-[0-9]+"); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | for (int i = min; i <= max; ++i) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | { |
847 | 324 | // Check for floating point |
1217 | 325 | tokens[i].toDouble(&ok); |
847 | 326 | if (ok) |
327 | return; | |
328 | ||
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
329 | // Check hex |
1217 | 330 | if (tokens[i].startsWith("0x")) |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
331 | { |
1217 | 332 | tokens[i].mid(2).toInt(&ok, 16); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | |
847 | 334 | if (ok) |
335 | return; | |
336 | } | |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
337 | |
847 | 338 | // Check scientific notation, e.g. 7.99361e-15 |
1217 | 339 | if (scientificRegex.exactMatch(tokens[i])) |
847 | 340 | return; |
341 | ||
1217 | 342 | throw QString(format("Token #%1 was `%2`, expected a number(matched length: %3)", |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1003
diff
changeset
|
343 | (i + 1), tokens[i], scientificRegex.matchedLength())); |
655
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 | } |
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 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
348 | // |
1217 | 349 | static Vertex ParseVertex(QStringList& s, const int n) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | Vertex v; |
1217 | 352 | v.apply([&](Axis ax, double& a) { a = s[n + ax].toDouble(); }); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | return v; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | |
1217 | 356 | static int32 StringToNumber(QString a, bool* ok = nullptr) |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
357 | { |
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
358 | int base = 10; |
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
359 | |
1217 | 360 | if (a.startsWith("0x")) |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
361 | { |
1217 | 362 | a.remove(0, 2); |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
363 | base = 16; |
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
364 | } |
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
365 | |
1217 | 366 | return a.toLong(ok, base); |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
367 | } |
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
789
diff
changeset
|
368 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
369 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | // This is the LDraw code parser function. It takes in a string containing LDraw |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
371 | // code and returns the object parsed from it. parseLine never returns null, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | // the object will be LDError if it could not be parsed properly. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
373 | // ============================================================================= |
1217 | 374 | LDObject* ParseLine(QString line) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
376 | try |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
377 | { |
1217 | 378 | QStringList tokens = line.split(" ", QString::SkipEmptyParts); |
655
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 | if (tokens.size() <= 0) |
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 | // Line was empty, or only consisted of whitespace |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
383 | return LDSpawn<LDEmpty>(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | |
840
d077dd19bf9a
- changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
836
diff
changeset
|
386 | if (tokens[0].length() != 1 or not tokens[0][0].isDigit()) |
1217 | 387 | throw QString("Illogical line code"); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
388 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
389 | int num = tokens[0][0].digitValue(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
390 | |
1217 | 391 | switch(num) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | case 0: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
394 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
395 | // Comment |
1217 | 396 | QString commentText(line.mid(line.indexOf("0") + 2)); |
397 | QString commentTextSimplified(commentText.simplified()); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
398 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
399 | // Handle BFC statements |
840
d077dd19bf9a
- changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
836
diff
changeset
|
400 | if (tokens.size() > 2 and tokens[1] == "BFC") |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
401 | { |
1217 | 402 | for_enum(BfcStatement, i) |
847 | 403 | { |
1217 | 404 | if (commentTextSimplified == format("BFC %1", LDBfc::statementToString(i))) |
405 | return LDSpawn<LDBfc>(i); | |
847 | 406 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
407 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
408 | // MLCAD is notorious for stuffing these statements in parts it |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
409 | // creates. The above block only handles valid statements, so we |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
410 | // need to handle MLCAD-style invertnext, clip and noclip separately. |
747
17a854ef4412
- simplified the code handling bfc statements a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
746
diff
changeset
|
411 | if (commentTextSimplified == "BFC CERTIFY INVERTNEXT") |
1217 | 412 | return LDSpawn<LDBfc>(BfcStatement::InvertNext); |
967 | 413 | else if (commentTextSimplified == "BFC CERTIFY CLIP") |
1217 | 414 | return LDSpawn<LDBfc>(BfcStatement::Clip); |
967 | 415 | else if (commentTextSimplified == "BFC CERTIFY NOCLIP") |
1217 | 416 | return LDSpawn<LDBfc>(BfcStatement::NoClip); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
417 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
418 | |
840
d077dd19bf9a
- changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
836
diff
changeset
|
419 | if (tokens.size() > 2 and tokens[1] == "!LDFORGE") |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
420 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
421 | // Handle LDForge-specific types, they're embedded into comments too |
959
737245eee433
Remove the vertex object type
Teemu Piippo <crimsondusk64@gmail.com>
parents:
958
diff
changeset
|
422 | if (tokens[2] == "OVERLAY") |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
423 | { |
1217 | 424 | CheckTokenCount(tokens, 9); |
425 | CheckTokenNumbers(tokens, 5, 8); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
426 | |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
944
diff
changeset
|
427 | LDOverlay* obj = LDSpawn<LDOverlay>(); |
1217 | 428 | obj->setFileName(tokens[3]); |
429 | obj->setCamera(tokens[4].toLong()); | |
430 | obj->setX(tokens[5].toLong()); | |
431 | obj->setY(tokens[6].toLong()); | |
432 | obj->setWidth(tokens[7].toLong()); | |
433 | obj->setHeight(tokens[8].toLong()); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
434 | return obj; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
435 | } |
1003
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
436 | else if (tokens[2] == "BEZIER_CURVE") |
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
437 | { |
1217 | 438 | CheckTokenCount(tokens, 16); |
439 | CheckTokenNumbers(tokens, 3, 15); | |
1003
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
440 | LDBezierCurve* obj = LDSpawn<LDBezierCurve>(); |
1217 | 441 | obj->setColor(StringToNumber(tokens[3])); |
1003
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
442 | |
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
443 | for (int i = 0; i < 4; ++i) |
1217 | 444 | obj->setVertex(i, ParseVertex(tokens, 4 +(i * 3))); |
1003
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
445 | |
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
446 | return obj; |
31873c3cbdbc
Bézier curves are now parsed correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
447 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
448 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
449 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
450 | // Just a regular comment: |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
944
diff
changeset
|
451 | LDComment* obj = LDSpawn<LDComment>(); |
1217 | 452 | obj->setText(commentText); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
453 | return obj; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
454 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
455 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
456 | case 1: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
457 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
458 | // Subfile |
1217 | 459 | CheckTokenCount(tokens, 15); |
460 | CheckTokenNumbers(tokens, 1, 13); | |
461 | LDDocument* document = g_win->documents()->getDocumentByName(tokens[14]); | |
655
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 | // If we cannot open the file, mark it an error. Note we cannot use LDParseError |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | // here because the error object needs the document reference. |
998 | 465 | if (not document) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | { |
1217 | 467 | LDError* obj = LDSpawn<LDError>(line, format("Could not open %1", tokens[14])); |
468 | obj->setFileReferenced(tokens[14]); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
469 | return obj; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
470 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1003
diff
changeset
|
472 | LDSubfileReference* obj = LDSpawn<LDSubfileReference>(); |
1217 | 473 | obj->setColor(StringToNumber(tokens[1])); |
474 | obj->setPosition(ParseVertex(tokens, 2)); // 2 - 4 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | Matrix transform; |
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 | for (int i = 0; i < 9; ++i) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
479 | transform[i] = tokens[i + 5].toDouble(); // 5 - 13 |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
480 | |
1217 | 481 | obj->setTransform(transform); |
482 | obj->setFileInfo(document); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
483 | return obj; |
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 | case 2: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
487 | { |
1217 | 488 | CheckTokenCount(tokens, 8); |
489 | CheckTokenNumbers(tokens, 1, 7); | |
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 | // Line |
1217 | 492 | LDLine* obj(LDSpawn<LDLine>()); |
493 | obj->setColor(StringToNumber(tokens[1])); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
494 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
495 | for (int i = 0; i < 2; ++i) |
1217 | 496 | obj->setVertex(i, ParseVertex(tokens, 2 +(i * 3))); // 2 - 7 |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
497 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
498 | return obj; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
499 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
500 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
501 | case 3: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
502 | { |
1217 | 503 | CheckTokenCount(tokens, 11); |
504 | CheckTokenNumbers(tokens, 1, 10); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
505 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
506 | // Triangle |
1217 | 507 | LDTriangle* obj(LDSpawn<LDTriangle>()); |
508 | obj->setColor(StringToNumber(tokens[1])); | |
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 | for (int i = 0; i < 3; ++i) |
1217 | 511 | obj->setVertex(i, ParseVertex(tokens, 2 +(i * 3))); // 2 - 10 |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
512 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
513 | return obj; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
514 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
515 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
516 | case 4: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
517 | case 5: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
518 | { |
1217 | 519 | CheckTokenCount(tokens, 14); |
520 | CheckTokenNumbers(tokens, 1, 13); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
521 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
522 | // Quadrilateral / Conditional line |
944 | 523 | LDObject* obj; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
524 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
525 | if (num == 4) |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
526 | obj = LDSpawn<LDQuad>(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
527 | else |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
528 | obj = LDSpawn<LDCondLine>(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
529 | |
1217 | 530 | obj->setColor(StringToNumber(tokens[1])); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
531 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
532 | for (int i = 0; i < 4; ++i) |
1217 | 533 | obj->setVertex(i, ParseVertex(tokens, 2 +(i * 3))); // 2 - 13 |
655
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 | return obj; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
536 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
537 | |
748
8d4a9d03e246
- some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
747
diff
changeset
|
538 | default: |
1217 | 539 | throw QString("Unknown line code number"); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
540 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
541 | } |
1217 | 542 | catch(QString& e) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
543 | { |
748
8d4a9d03e246
- some minor cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
747
diff
changeset
|
544 | // Strange line we couldn't parse |
1217 | 545 | return LDSpawn<LDError>(line, e); |
655
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 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
550 | // |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
551 | void LDDocument::reloadAllSubfiles() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
552 | { |
1217 | 553 | print("Reloading subfiles of %1", getDisplayName()); |
655
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 | // Go through all objects in the current file and reload the subfiles |
944 | 556 | for (LDObject* obj : objects()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
557 | { |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1003
diff
changeset
|
558 | if (obj->type() == OBJ_SubfileReference) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
559 | { |
1217 | 560 | LDSubfileReference* ref = static_cast<LDSubfileReference*>(obj); |
561 | LDDocument* fileInfo = m_documents->getDocumentByName(ref->fileInfo()->name()); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
562 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
563 | if (fileInfo) |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
564 | { |
1217 | 565 | ref->setFileInfo(fileInfo); |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
566 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
567 | else |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
568 | { |
1217 | 569 | ref->replace(LDSpawn<LDError>(ref->asText(), |
570 | format("Could not open %1", ref->fileInfo()->name()))); | |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
571 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
572 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
573 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
574 | // Reparse gibberish files. It could be that they are invalid because |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
575 | // of loading errors. Circumstances may be different now. |
786
71d786ce0dcc
- LDObject::Type moved back to global namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents:
785
diff
changeset
|
576 | if (obj->type() == OBJ_Error) |
1217 | 577 | obj->replace(ParseLine(static_cast<LDError*>(obj)->contents())); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
578 | } |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
579 | |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
580 | m_needsReCache = true; |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
581 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
582 | if (this == m_window->currentDocument()) |
981
5d5d84ab2c48
Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
980
diff
changeset
|
583 | m_window->buildObjectList(); |
655
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 | |
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 | // |
1217 | 588 | int LDDocument::addObject(LDObject* obj) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
589 | { |
1217 | 590 | history()->add(new AddHistoryEntry(objects().size(), obj)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
591 | m_objects << obj; |
1217 | 592 | addKnownVertices(obj); |
593 | obj->setDocument(this); | |
1231 | 594 | m_window->currentRenderer()->compileObject(obj); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
595 | return getObjectCount() - 1; |
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 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
599 | // |
1217 | 600 | void LDDocument::addObjects(const LDObjectList& objs) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
601 | { |
944 | 602 | for (LDObject* obj : objs) |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
603 | { |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
604 | if (obj) |
1217 | 605 | addObject(obj); |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
606 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
607 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
608 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
609 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
610 | // |
1217 | 611 | void LDDocument::insertObj(int pos, LDObject* obj) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
612 | { |
1217 | 613 | history()->add(new AddHistoryEntry(pos, obj)); |
614 | m_objects.insert(pos, obj); | |
615 | obj->setDocument(this); | |
1231 | 616 | m_window->currentRenderer()->compileObject(obj); |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
617 | |
890
903ec1e46298
- backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
889
diff
changeset
|
618 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
619 | #ifdef DEBUG |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
620 | if (not isCache()) |
1217 | 621 | dprint("Inserted object #%1(%2) at %3\n", obj->id(), obj->typeName(), pos); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
622 | #endif |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
623 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
624 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
625 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
626 | // |
1217 | 627 | void LDDocument::addKnownVertices(LDObject* obj) |
717
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
628 | { |
1217 | 629 | auto it = m_objectVertices.find(obj); |
717
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
630 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
631 | if (it == m_objectVertices.end()) |
1217 | 632 | it = m_objectVertices.insert(obj, QVector<Vertex>()); |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
633 | else |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
634 | it->clear(); |
719
f2cc5964f52d
- sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
635 | |
1217 | 636 | obj->getVertices(*it); |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
637 | needVertexMerge(); |
717
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
638 | } |
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
639 | |
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
640 | // ============================================================================= |
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
641 | // |
1217 | 642 | void LDDocument::forgetObject(LDObject* obj) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
643 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
644 | int idx = obj->lineNumber(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
645 | |
949
a9ba8ffd9534
actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
646 | if (m_objects[idx] == obj) |
717
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
647 | { |
949
a9ba8ffd9534
actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
648 | obj->deselect(); |
a9ba8ffd9534
actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
649 | |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
650 | if (not isCache() and not m_beingDestroyed) |
949
a9ba8ffd9534
actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
651 | { |
1217 | 652 | history()->add(new DelHistoryEntry(idx, obj)); |
653 | m_objectVertices.remove(obj); | |
949
a9ba8ffd9534
actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
654 | } |
a9ba8ffd9534
actually added updaterevision.py, more fixing
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
655 | |
1217 | 656 | m_objects.removeAt(idx); |
657 | obj->setDocument(nullptr); | |
717
fdc285e5952f
- reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
714
diff
changeset
|
658 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
659 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
660 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
661 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
662 | // |
1217 | 663 | void LDDocument::setObject(int idx, LDObject* obj) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
664 | { |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
665 | if (idx < 0 or idx >= m_objects.size()) |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
666 | return; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
667 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
668 | // Mark this change to history |
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:
656
diff
changeset
|
669 | if (not m_history->isIgnoring()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
670 | { |
1217 | 671 | QString oldcode = getObject(idx)->asText(); |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
788
diff
changeset
|
672 | QString newcode = obj->asText(); |
1217 | 673 | m_history->add(new EditHistoryEntry(idx, oldcode, newcode)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
674 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
675 | |
1217 | 676 | m_objectVertices.remove(m_objects[idx]); |
767
44f0d5322628
- slight refactor in ldobject methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
761
diff
changeset
|
677 | m_objects[idx]->deselect(); |
1217 | 678 | m_objects[idx]->setDocument(nullptr); |
679 | obj->setDocument(this); | |
680 | addKnownVertices(obj); | |
1231 | 681 | m_window->currentRenderer()->compileObject(obj); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
682 | m_objects[idx] = obj; |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
683 | needVertexMerge(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
684 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
685 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
686 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
687 | // |
1217 | 688 | LDObject* LDDocument::getObject(int pos) const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
689 | { |
943
af81220741d9
Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents:
920
diff
changeset
|
690 | if (pos < m_objects.size()) |
af81220741d9
Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents:
920
diff
changeset
|
691 | return m_objects[pos]; |
af81220741d9
Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents:
920
diff
changeset
|
692 | else |
af81220741d9
Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents:
920
diff
changeset
|
693 | return nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
694 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
695 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
696 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
697 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
698 | int LDDocument::getObjectCount() const |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
699 | { |
890
903ec1e46298
- backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
889
diff
changeset
|
700 | return objects().size(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
701 | } |
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 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
704 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
705 | bool LDDocument::hasUnsavedChanges() const |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
706 | { |
979
880d3fe9ac7c
Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
707 | return not isCache() and history()->position() != savePosition(); |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
710 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
711 | // |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
788
diff
changeset
|
712 | QString LDDocument::getDisplayName() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
713 | { |
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:
656
diff
changeset
|
714 | if (not name().isEmpty()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
715 | return name(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
716 | |
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:
656
diff
changeset
|
717 | if (not defaultName().isEmpty()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
718 | return "[" + defaultName() + "]"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
719 | |
1217 | 720 | return QObject::tr("untitled"); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
721 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
722 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
723 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
724 | // |
719
f2cc5964f52d
- sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
725 | void LDDocument::initializeCachedData() |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
726 | { |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
727 | if (m_needsReCache) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
728 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
729 | m_vertices.clear(); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
730 | |
1217 | 731 | for (LDObject* obj : inlineContents(true, true)) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
732 | { |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1003
diff
changeset
|
733 | if (obj->type() == OBJ_SubfileReference) |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
734 | { |
1217 | 735 | print("Warning: unable to inline %1 into %2", |
736 | static_cast<LDSubfileReference*>(obj)->fileInfo()->getDisplayName(), | |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
737 | getDisplayName()); |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
738 | continue; |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
739 | } |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
740 | |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
741 | LDPolygon* data = obj->getPolygon(); |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
742 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
743 | if (data) |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
744 | { |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
745 | m_polygonData << *data; |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
746 | delete data; |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
747 | } |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
748 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
749 | |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
750 | m_needsReCache = false; |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
751 | } |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
752 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
753 | if (m_verticesOutdated) |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
754 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
755 | m_objectVertices.clear(); |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
756 | |
1217 | 757 | for (LDObject* obj : inlineContents(true, false)) |
758 | addKnownVertices(obj); | |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
759 | |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
760 | mergeVertices(); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
761 | m_verticesOutdated = false; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
762 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
763 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
764 | if (m_needVertexMerge) |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
765 | mergeVertices(); |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
766 | } |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
767 | |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
768 | // ============================================================================= |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
769 | // |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
770 | void LDDocument::mergeVertices() |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
771 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
772 | m_vertices.clear(); |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
773 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
774 | for (QVector<Vertex> const& verts : m_objectVertices) |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
775 | m_vertices << verts; |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
776 | |
1217 | 777 | removeDuplicates(m_vertices); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
778 | m_needVertexMerge = false; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
779 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
780 | |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
781 | // ============================================================================= |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
782 | // |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
783 | QList<LDPolygon> LDDocument::inlinePolygons() |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
784 | { |
719
f2cc5964f52d
- sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
785 | initializeCachedData(); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
786 | return polygonData(); |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
787 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
788 | |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
789 | // ============================================================================= |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
790 | // ----------------------------------------------------------------------------- |
1217 | 791 | LDObjectList LDDocument::inlineContents(bool deep, bool renderinline) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
792 | { |
998 | 793 | LDObjectList objs; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
794 | |
1217 | 795 | if (m_manager->preInline(this, objs, deep, renderinline)) |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
994
diff
changeset
|
796 | return objs; // Manager dealt with this inline |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
797 | |
944 | 798 | for (LDObject* obj : objects()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
799 | { |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
800 | // Skip those without scemantic meaning |
714 | 801 | if (not obj->isScemantic()) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
802 | continue; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
803 | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
804 | // Got another sub-file reference, inline it if we're deep-inlining. If not, |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
805 | // just add it into the objects normally. Yay, recursion! |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1003
diff
changeset
|
806 | if (deep == true and obj->type() == OBJ_SubfileReference) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
807 | { |
1217 | 808 | for (LDObject* otherobj : static_cast<LDSubfileReference*>(obj)->inlineContents(deep, renderinline)) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
809 | objs << otherobj; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
810 | } |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
811 | else |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
812 | objs << obj->createCopy(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
813 | } |
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 | return objs; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
816 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
817 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
818 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
819 | // |
1217 | 820 | void LDDocument::addToSelection(LDObject* obj) // [protected] |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
821 | { |
988
ac4a2ae54f76
Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
822 | if (obj->isSelected() and obj->document() == this) |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
823 | { |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
824 | m_sel << obj; |
1231 | 825 | m_window->currentRenderer()->compileObject(obj); |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
826 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
827 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
828 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
829 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
830 | // |
1217 | 831 | void LDDocument::removeFromSelection(LDObject* obj) // [protected] |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
832 | { |
988
ac4a2ae54f76
Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
833 | if (not obj->isSelected() and obj->document() == this) |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
834 | { |
1217 | 835 | m_sel.removeOne(obj); |
1231 | 836 | m_window->currentRenderer()->compileObject(obj); |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
837 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
838 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
839 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
840 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
841 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
842 | void LDDocument::clearSelection() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
843 | { |
944 | 844 | for (LDObject* obj : m_sel) |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
845 | { |
988
ac4a2ae54f76
Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
846 | obj->deselect(); |
1231 | 847 | m_window->currentRenderer()->compileObject(obj); |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
848 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
849 | |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
850 | m_sel.clear(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
851 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
852 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
853 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
854 | // |
890
903ec1e46298
- backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
889
diff
changeset
|
855 | const LDObjectList& LDDocument::getSelection() const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
856 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
857 | return m_sel; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
858 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
859 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
860 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
861 | // |
1217 | 862 | void LDDocument::swapObjects(LDObject* one, LDObject* other) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
863 | { |
1217 | 864 | int a = m_objects.indexOf(one); |
865 | int b = m_objects.indexOf(other); | |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
866 | |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
867 | if (a != b and a != -1 and b != -1) |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
868 | { |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
869 | m_objects[b] = one; |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
870 | m_objects[a] = other; |
1217 | 871 | addToHistory(new SwapHistoryEntry(one->id(), other->id())); |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
957
diff
changeset
|
872 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
873 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
874 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
875 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
876 | // |
1217 | 877 | QString LDDocument::shortenName(QString a) // [static] |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
878 | { |
1217 | 879 | QString shortname = Basename(a); |
880 | QString topdirname = Basename(Dirname(a)); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
881 | |
1217 | 882 | if (g_specialSubdirectories.contains(topdirname)) |
883 | shortname.prepend(topdirname + "\\"); | |
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 | return shortname; |
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 | // |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
890 | QVector<Vertex> const& LDDocument::inlineVertices() |
719
f2cc5964f52d
- sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
891 | { |
f2cc5964f52d
- sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
892 | initializeCachedData(); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
893 | return m_vertices; |
719
f2cc5964f52d
- sped up known vertex information gathering by an order of magnitude
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
894 | } |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
895 | |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
896 | void LDDocument::redoVertices() |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
897 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
898 | m_verticesOutdated = true; |
835
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
899 | } |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
900 | |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
901 | void LDDocument::needVertexMerge() |
268413885cb1
- reimplemented vertex tracking using a method similar to what the GL compiler uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
834
diff
changeset
|
902 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
903 | m_needVertexMerge = true; |
1231 | 904 | } |