Tue, 19 Jun 2018 22:00:46 +0300
simplified
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 |
1326 | 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 | |
1039 | 19 | #include <QApplication> |
1156
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
20 | #include <QMessageBox> |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
21 | #include "lddocument.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
958
diff
changeset
|
22 | #include "mainwindow.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "primitives.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "colors.h" |
998 | 25 | #include "documentmanager.h" |
1318
568fcfc6da71
removed unnecessary files and includes
Teemu Piippo <teemu@hecknology.net>
parents:
1312
diff
changeset
|
26 | #include "editHistory.h" |
1319 | 27 | #include "algorithms/geometry.h" |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
28 | #include "generics/ring.h" |
1117
efcb47c64a72
Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
29 | #include "linetypes/comment.h" |
1141
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
30 | #include "linetypes/conditionaledge.h" |
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
31 | #include "linetypes/edgeline.h" |
1117
efcb47c64a72
Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
32 | #include "linetypes/empty.h" |
1149
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1148
diff
changeset
|
33 | #include "linetypes/quadrilateral.h" |
1148
96cb15a7611f
Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1145
diff
changeset
|
34 | #include "linetypes/triangle.h" |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
35 | #include "linetypes/circularprimitive.h" |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
36 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
37 | PrimitiveManager::PrimitiveManager(QObject* parent) : |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
38 | QAbstractItemModel {parent}, |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
39 | HierarchyElement {parent}, |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
40 | m_activeScanner {nullptr}, |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
41 | m_unmatched {nullptr} {} |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
42 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
43 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
44 | PrimitiveScanner* PrimitiveManager::activeScanner() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
46 | return m_activeScanner; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
49 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
50 | QString PrimitiveManager::getPrimitivesCfgPath() const |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
51 | { |
1332
1fffb24d4ffe
replaced remaining DIRSLASH, Dirname and Basename uses with Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents:
1326
diff
changeset
|
52 | return QDir {qApp->applicationDirPath()}.filePath("prims.cfg"); |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
53 | } |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
54 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
55 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
56 | void PrimitiveManager::loadPrimitives() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // Try to load prims.cfg |
1054 | 59 | QFile primitivesFile = {getPrimitivesCfgPath()}; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
1054 | 61 | if (not primitivesFile.open (QIODevice::ReadOnly)) |
655
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 | // No prims.cfg, build it |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
64 | startScan(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | { |
1285
0d165d277562
added signal emissions
Teemu Piippo <teemu@hecknology.net>
parents:
1284
diff
changeset
|
68 | emit layoutAboutToBeChanged(); |
0d165d277562
added signal emissions
Teemu Piippo <teemu@hecknology.net>
parents:
1284
diff
changeset
|
69 | m_primitives.clear(); |
0d165d277562
added signal emissions
Teemu Piippo <teemu@hecknology.net>
parents:
1284
diff
changeset
|
70 | |
1054 | 71 | while (not primitivesFile.atEnd()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | { |
1054 | 73 | QString line = primitivesFile.readLine().simplified(); |
74 | int space = line.indexOf(" "); | |
790
fe1b83f6ba82
- added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
75 | |
1054 | 76 | if (space != -1) |
77 | { | |
78 | Primitive info; | |
79 | info.name = line.left(space); | |
80 | info.title = line.mid(space + 1); | |
81 | m_primitives.append(info); | |
82 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
85 | populateCategories(); |
1285
0d165d277562
added signal emissions
Teemu Piippo <teemu@hecknology.net>
parents:
1284
diff
changeset
|
86 | emit layoutChanged(); |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
87 | print(tr("%1 primitives loaded.") + "\n", countof(m_primitives)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
91 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
92 | void PrimitiveManager::startScan() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
94 | if (m_activeScanner == nullptr) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
95 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
96 | loadCategories(); |
1054 | 97 | m_activeScanner = new PrimitiveScanner {this}; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
98 | m_activeScanner->work(); |
1054 | 99 | connect(m_activeScanner, &PrimitiveScanner::workDone, this, [&]() |
100 | { | |
101 | if (m_activeScanner) | |
102 | { | |
1284 | 103 | emit layoutAboutToBeChanged(); |
1054 | 104 | m_primitives = m_activeScanner->scannedPrimitives(); |
105 | populateCategories(); | |
1284 | 106 | emit layoutChanged(); |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
107 | print(tr("%1 primitives scanned"), countof(m_primitives)); |
1054 | 108 | delete m_activeScanner; |
109 | m_activeScanner = nullptr; | |
110 | } | |
111 | }); | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
112 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
116 | void PrimitiveManager::clearCategories() |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
117 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
118 | for (PrimitiveCategory* category : m_categories) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
119 | delete category; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
120 | |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
121 | m_categories.clear(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
122 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
123 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
124 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
125 | void PrimitiveManager::populateCategories() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | { |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
127 | loadCategories(); |
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
128 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
129 | for (PrimitiveCategory* category : m_categories) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
130 | category->primitives.clear(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
132 | for (Primitive& primitive : m_primitives) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | bool matched = false; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
135 | primitive.category = nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | // Go over the categories and their regexes, if and when there's a match, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | // the primitive's category is set to the category the regex beloings to. |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
139 | for (PrimitiveCategory* category : m_categories) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
141 | for (PrimitiveCategory::RegexEntry& entry : category->patterns) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | switch (entry.type) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
145 | case PrimitiveCategory::FilenamePattern: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
146 | // f-regex, check against filename |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
147 | matched = entry.regex.exactMatch (primitive.name); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
148 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
150 | case PrimitiveCategory::TitlePattern: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
151 | // t-regex, check against title |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
152 | matched = entry.regex.exactMatch (primitive.title); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
153 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | if (matched) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
158 | primitive.category = category; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | break; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
163 | // Drop off if a category was decided on. |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
164 | if (primitive.category) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | break; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | // If there was a match, add the primitive to the category. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | // Otherwise, add it to the list of unmatched primitives. |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
170 | if (primitive.category) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
171 | primitive.category->primitives << primitive; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | else |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
173 | m_unmatched->primitives << primitive; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | } |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
175 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
176 | // Sort the categories. Note that we only do this here because we needed the original order for pattern matching. |
1320
bdb4804bc09c
Moved includes, added squared() function
Teemu Piippo <teemu@hecknology.net>
parents:
1319
diff
changeset
|
177 | ::sort(m_categories.begin(), m_categories.end(), |
1054 | 178 | [](PrimitiveCategory* const& one, PrimitiveCategory* const& other) -> bool |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
179 | { |
1054 | 180 | return one->name() < other->name(); |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
181 | }); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
184 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
185 | void PrimitiveManager::loadCategories() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
187 | clearCategories(); |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
188 | QString path = ":/data/primitive-categories.cfg"; |
1054 | 189 | QFile categoriesFile = {path}; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | |
1054 | 191 | if (not categoriesFile.open (QIODevice::ReadOnly)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | { |
1156
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
193 | QString message = format(tr("Failed to open primitive categories: %1"), categoriesFile.errorString()); |
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
194 | QMessageBox::critical(m_window, tr("Cannot open categories"), message); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
198 | PrimitiveCategory* category = nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | |
1054 | 200 | while (not categoriesFile.atEnd()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | { |
1054 | 202 | QString line = QString::fromUtf8(categoriesFile.readLine()).trimmed(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | |
1064
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
204 | if (line.isEmpty() or line[0] == '#') |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | continue; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
207 | int colon = line.indexOf (":"); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
208 | if (colon == -1) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
210 | if (category and category->isValidToInclude()) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
211 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
212 | m_categories << category; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
213 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
214 | else if (category) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
215 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
216 | print (tr ("Warning: Category \"%1\" left without patterns"), category->name()); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
217 | delete category; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
218 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
220 | category = new PrimitiveCategory (line); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
222 | else if (category) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
224 | QString typechar = line.left (colon); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
225 | PrimitiveCategory::PatternType type = PrimitiveCategory::FilenamePattern; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
227 | if (typechar == "f") |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
228 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
229 | type = PrimitiveCategory::FilenamePattern; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
230 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
231 | else if (typechar == "t") |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
232 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
233 | type = PrimitiveCategory::TitlePattern; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
234 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | { |
1054 | 237 | print(tr("Warning: unknown pattern type \"%1\" on line \"%2\""), typechar, line); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | continue; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | QRegExp regex (line.mid (colon + 1)); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
242 | PrimitiveCategory::RegexEntry entry = { regex, type }; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
243 | category->patterns << entry; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | else |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
246 | { |
1054 | 247 | print("Warning: Rules given before the first category name"); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
248 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
251 | if (category->isValidToInclude()) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
252 | m_categories << category; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | // Add a category for unmatched primitives. |
1054 | 255 | // Note: if this function is called the second time, m_unmatched has been |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | // deleted at the beginning of the function and is dangling at this point. |
1054 | 257 | m_unmatched = new PrimitiveCategory {tr("Other")}; |
258 | m_categories.append(m_unmatched); | |
259 | categoriesFile.close(); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
262 | // Length of a single LDraw edge circle segment. Ideally, it is sqrt(2 - 2 * cos(π / 8)), but |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
263 | // rounding errors come into play so it's a tiny bit larger than that. |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
264 | // This actual value is given by: hypot(0.0761, 0.3827) |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
265 | static const double chordLength = 0.3901929010117944; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
266 | |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1364
diff
changeset
|
267 | void PrimitiveModel::generateCylinder(Model& model, Winding winding) const |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
268 | { |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
269 | auto circle = makeCircle(this->segments, this->divisions, 1); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
270 | bool useTangents = (this->segments != this->divisions); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
271 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
272 | QPointF tangent_1; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
273 | QPointF tangent_2; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
274 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
275 | if (useTangents) |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
276 | { |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
277 | tangent_1 = {1.0, -chordLength}; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
278 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
279 | double angle = double(segments) * 2 * pi / double(divisions) + (pi / 2); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
280 | tangent_2 = { |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
281 | circle.last().p2().x() + chordLength * cos(angle), |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
282 | circle.last().p2().y() + chordLength * sin(angle), |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
283 | }; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
284 | } |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
285 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
286 | for (int i = 0; i < this->segments; i += 1) |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
287 | { |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
288 | double x0 = circle[i].x1(); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
289 | double x1 = circle[i].x2(); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
290 | double z0 = circle[i].y1(); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
291 | double z1 = circle[i].y2(); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1364
diff
changeset
|
292 | double y1 = (winding == CounterClockwise) ? 0.0 : 1.0; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1364
diff
changeset
|
293 | double y2 = (winding == CounterClockwise) ? 1.0 : 0.0; |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
294 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
295 | LDQuadrilateral* quad = model.emplace<LDQuadrilateral>( |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1364
diff
changeset
|
296 | Vertex {x1, y1, z1}, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1364
diff
changeset
|
297 | Vertex {x0, y1, z0}, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1364
diff
changeset
|
298 | Vertex {x0, y2, z0}, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
1364
diff
changeset
|
299 | Vertex {x1, y2, z1} |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
300 | ); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
301 | quad->setColor(MainColor); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
302 | } |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
303 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
304 | for (int i = 0; i < this->segments + 1; i += 1) |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
305 | { |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
306 | QPointF p0 = ::pointOnLDrawCircumference(i, divisions); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
307 | QPointF p2 = ::pointOnLDrawCircumference(i - 1, divisions); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
308 | QPointF p3 = ::pointOnLDrawCircumference(i + 1, divisions); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
309 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
310 | if (useTangents and i == 0) |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
311 | p2 = tangent_1; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
312 | else if (useTangents and i == this->segments) |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
313 | p3 = tangent_2; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
314 | |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
315 | Vertex v0 = {p0.x(), 1.0, p0.y()}; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
316 | Vertex v1 = {v0.x, 0.0, v0.z}; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
317 | Vertex v2 = {p2.x(), 1.0, p2.y()}; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
318 | Vertex v3 = {p3.x(), 1.0, p3.y()}; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
319 | LDConditionalEdge* line = model.emplace<LDConditionalEdge>(); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
320 | line->setColor(EdgeColor); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
321 | line->setVertex(0, v0); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
322 | line->setVertex(1, v1); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
323 | line->setVertex(2, v2); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
324 | line->setVertex(3, v3); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
325 | } |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
326 | } |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
327 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
328 | /* |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
329 | * Builds a circle primitive. |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
330 | */ |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
331 | void PrimitiveModel::generateCircle(Model& model, const QMatrix4x4& matrix) const |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
332 | { |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
333 | QVector<QLineF> circle = makeCircle(segments, divisions, 1); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
334 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
335 | for (int i = 0; i < segments; ++i) |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
336 | { |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
337 | double x0 = circle[i].x1(); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
338 | double x1 = circle[i].x2(); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
339 | double z0 = circle[i].y1(); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
340 | double z1 = circle[i].y2(); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
341 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
342 | LDEdgeLine* line = model.emplace<LDEdgeLine>(); |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
343 | line->setVertex(0, Vertex {x0, 0.0f, z0}.transformed(matrix)); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
344 | line->setVertex(1, Vertex {x1, 0.0f, z1}.transformed(matrix)); |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
345 | line->setColor(EdgeColor); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
346 | } |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
347 | } |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
348 | |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
349 | void PrimitiveModel::generateDisc(Model& model) const |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
350 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
351 | QVector<QLineF> circle = makeCircle(segments, divisions, 1); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
352 | |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
353 | for (int i = 0; i < segments; ++i) |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
354 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
355 | LDTriangle* segment = model.emplace<LDTriangle>(); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
356 | segment->setColor(MainColor); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
357 | segment->setVertex(0, {circle[i].x1(), 0.0, circle[i].y1()}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
358 | segment->setVertex(1, {circle[i].x2(), 0.0, circle[i].y2()}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
359 | segment->setVertex(2, {0.0, 0.0, 0.0}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
360 | } |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
361 | } |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
362 | |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
363 | void PrimitiveModel::generateDiscNegative(Model& model) const |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
364 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
365 | QVector<QLineF> circle = makeCircle(segments, divisions, 1); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
366 | |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
367 | for (int i = 0; i < segments; ++i) |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
368 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
369 | LDTriangle* segment = model.emplace<LDTriangle>(); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
370 | segment->setColor(MainColor); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
371 | segment->setVertex(0, {(circle[i].x1() >= 0.0) ? 1.0 : -1.0, 0.0, (circle[i].y1() >= 0.0) ? 1.0 : -1.0}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
372 | segment->setVertex(1, {circle[i].x2(), 0.0, circle[i].y2()}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
373 | segment->setVertex(2, {circle[i].x1(), 0.0, circle[i].y1()}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
374 | } |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
375 | } |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
376 | |
1408
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
377 | void PrimitiveModel::generateChord(Model& model) const |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
378 | { |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
379 | QVector<QLineF> circle = makeCircle(segments, divisions, 1); |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
380 | |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
381 | for (int i = 1; i < segments; ++i) |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
382 | { |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
383 | LDTriangle* segment = model.emplace<LDTriangle>(); |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
384 | segment->setColor(MainColor); |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
385 | segment->setVertex(0, {circle[0].x1(), 0.0, circle[0].y1()}); |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
386 | segment->setVertex(1, {circle[i].x1(), 0.0, circle[i].y1()}); |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
387 | segment->setVertex(2, {circle[i].x2(), 0.0, circle[i].y2()}); |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
388 | } |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
389 | } |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
390 | |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
391 | void PrimitiveModel::generateBody(Model& model, bool deep) const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | { |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
393 | switch (type) |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
394 | { |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
395 | case Cylinder: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
396 | generateCylinder(model); |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
397 | return; |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
398 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
399 | case Circle: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
400 | generateCircle(model); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
401 | return; |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
402 | |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
403 | case Disc: |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
404 | generateDisc(model); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
405 | return; |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
406 | |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
407 | case DiscNegative: |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
408 | generateDiscNegative(model); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
409 | return; |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
410 | |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
411 | case CylinderClosed: |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
412 | if (deep) |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
413 | generateDisc(model); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
414 | else |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
415 | model.emplace<LDCircularPrimitive>(Disc, segments, divisions, QMatrix4x4 {}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
416 | case CylinderOpen: |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
417 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
418 | QMatrix4x4 endCircleMatrix; |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
419 | endCircleMatrix.translate(0, 1, 0); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
420 | |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
421 | if (deep) |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
422 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
423 | generateCylinder(model); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
424 | generateCircle(model); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
425 | generateCircle(model, endCircleMatrix); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
426 | } |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
427 | else |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
428 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
429 | model.emplace<LDCircularPrimitive>(Cylinder, segments, divisions, QMatrix4x4 {}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
430 | model.emplace<LDCircularPrimitive>(Circle, segments, divisions, QMatrix4x4 {}); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
431 | model.emplace<LDCircularPrimitive>(Circle, segments, divisions, endCircleMatrix); |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
432 | } |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
433 | } |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
434 | return; |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
435 | |
1408
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
436 | case Chord: |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
437 | generateChord(model); |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
438 | return; |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
439 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
440 | default: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
441 | break; |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
442 | } |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
443 | |
1053 | 444 | QVector<int> conditionalLineSegments; |
445 | QVector<QLineF> circle = makeCircle(segments, divisions, 1); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
446 | |
1053 | 447 | for (int i = 0; i < segments; ++i) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
448 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
449 | double x0 = circle[i].x1(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
450 | double x1 = circle[i].x2(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
451 | double z0 = circle[i].y1(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
452 | double z1 = circle[i].y2(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
453 | |
1053 | 454 | switch (type) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
455 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
456 | case Ring: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
457 | case Cone: |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
458 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
459 | double x2, x3, z2, z3; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
460 | double y0, y1, y2, y3; |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
461 | x2 = x1 * (ringNumber + 1); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
462 | x3 = x0 * (ringNumber + 1); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
463 | z2 = z1 * (ringNumber + 1); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
464 | z3 = z0 * (ringNumber + 1); |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
465 | x0 *= ringNumber; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
466 | x1 *= ringNumber; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
467 | z0 *= ringNumber; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
468 | z1 *= ringNumber; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
469 | |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
470 | if (type == Ring) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | { |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
472 | y0 = y1 = y2 = y3 = 0.0; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | { |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
476 | y0 = y1 = 1.0; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
477 | y2 = y3 = 0.0; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
478 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
479 | |
1053 | 480 | Vertex v0 = {x0, y0, z0}; |
481 | Vertex v1 = {x1, y1, z1}; | |
482 | Vertex v2 = {x2, y2, z2}; | |
483 | Vertex v3 = {x3, y3, z3}; | |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
484 | qSwap(v1, v3); |
1261
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1156
diff
changeset
|
485 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1117
diff
changeset
|
486 | LDQuadrilateral* quad = model.emplace<LDQuadrilateral>(v0, v1, v2, v3); |
1054 | 487 | quad->setColor(MainColor); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
488 | |
1053 | 489 | if (type == Cylinder or type == Cone) |
490 | conditionalLineSegments.append(i); | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
491 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
492 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
493 | |
1408
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
494 | case Chord: |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
495 | case Disc: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
496 | case DiscNegative: |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
497 | case Circle: |
1364 | 498 | case Cylinder: |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
499 | case CylinderClosed: |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
500 | case CylinderOpen: |
1364 | 501 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
502 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
503 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
504 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
505 | // If this is not a full circle, we need a conditional line at the other |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
506 | // end, too. |
1053 | 507 | if (segments < divisions and not conditionalLineSegments.isEmpty()) |
508 | conditionalLineSegments << segments; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
509 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
510 | for (int i : conditionalLineSegments) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
511 | { |
1325
f9abfc7ba676
Use 4 points of precision for circle point coordinates
Teemu Piippo <teemu@hecknology.net>
parents:
1323
diff
changeset
|
512 | QPointF p0 = ::pointOnLDrawCircumference(i, divisions); |
1346
c4cb7dc850aa
reworked primitive generator
Teemu Piippo <teemu@hecknology.net>
parents:
1345
diff
changeset
|
513 | QPointF p2 = ::pointOnLDrawCircumference(i - 1, divisions); |
c4cb7dc850aa
reworked primitive generator
Teemu Piippo <teemu@hecknology.net>
parents:
1345
diff
changeset
|
514 | QPointF p3 = ::pointOnLDrawCircumference(i + 1, divisions); |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
515 | Vertex v0 = {p0.x() * ringNumber, 1.0, p0.y() * ringNumber}; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
516 | Vertex v1 = {v0.x * (ringNumber + 1), 0.0, v0.z * (ringNumber + 1)}; |
1319 | 517 | Vertex v2 = {p2.x(), 0.0, p2.y()}; |
518 | Vertex v3 = {p3.x(), 0.0, p3.y()}; | |
1347
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
519 | v2 *= ringNumber; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
520 | v3 *= ringNumber; |
7dd217202126
refactor cylinder generation
Teemu Piippo <teemu@hecknology.net>
parents:
1346
diff
changeset
|
521 | v2.y = v3.y = 1.0; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
522 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1117
diff
changeset
|
523 | LDConditionalEdge* line = model.emplace<LDConditionalEdge>(); |
1053 | 524 | line->setColor(EdgeColor); |
525 | line->setVertex(0, v0); | |
526 | line->setVertex(1, v1); | |
527 | line->setVertex(2, v2); | |
528 | line->setVertex(3, v3); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
529 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
530 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
531 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
532 | |
1053 | 533 | QString PrimitiveModel::typeName() const |
534 | { | |
535 | return typeName(type); | |
536 | } | |
537 | ||
538 | ||
539 | QString PrimitiveModel::typeName(PrimitiveModel::Type type) | |
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 | // Not translated as primitives are in English. |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
542 | const char* names[] = |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
543 | { |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
544 | "Circle", |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
545 | "Cylinder", |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
546 | "Disc", |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
547 | "Disc Negative", |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
548 | "Ring", |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
549 | "Cone", |
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
550 | "Cylinder Closed", |
1408
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
551 | "Cylinder Open", |
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
552 | "Chord" |
1407
22bc5862cb56
added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
553 | }; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
554 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
555 | if (type >= 0 and type < countof(names)) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
556 | return names[type]; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
557 | else |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
558 | return "Unknown"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
559 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
560 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
561 | |
1345
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
562 | QString PrimitiveModel::makeFileName(FilenameStyle style) const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
563 | { |
1053 | 564 | int numerator = segments; |
565 | int denominator = divisions; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
566 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
567 | // Simplify the fractional part, but the denominator must be at least 4. |
1053 | 568 | simplify(numerator, denominator); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
569 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
570 | if (denominator < 4) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
571 | { |
1053 | 572 | int factor = 4 / denominator; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
573 | numerator *= factor; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
574 | denominator *= factor; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
575 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
576 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
577 | // Compose some general information: prefix, fraction, root, ring number |
1339
1f342d5abc85
Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1334
diff
changeset
|
578 | QString prefix = (divisions == MediumResolution) ? "" : format ("%1\\", divisions); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
579 | QString frac = format ("%1-%2", numerator, denominator); |
1408
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1407
diff
changeset
|
580 | static const char* roots[] = {"edge", "cyli", "disc", "ndis", "ring", "con", "chrd"}; |
1053 | 581 | QString root = roots[type]; |
582 | QString numberString = (type == Ring or type == Cone) ? format ("%1", ringNumber) : ""; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
583 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
584 | // Truncate the root if necessary (7-16rin4.dat for instance). |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
585 | // However, always keep the root at least 2 characters. |
1345
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
586 | if (style == LegacyStyleName) |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
587 | { |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
588 | int extra = (countof(frac) + countof(numberString) + countof(root)) - 8; |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
589 | root.chop(qBound(0, extra, 2)); |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
590 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
591 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
592 | // Stick them all together and return the result. |
1053 | 593 | return prefix + frac + root + numberString + ".dat"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
594 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
595 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
596 | |
1053 | 597 | LDDocument* PrimitiveManager::generatePrimitive(const PrimitiveModel& spec) |
655
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 | // Make the description |
1019
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
600 | QString fraction = QString::number ((float) spec.segments / spec.divisions); |
1345
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
601 | QString fileName = spec.makeFileName(PrimitiveModel::NewStyleName); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
602 | QString description; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
603 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
604 | // Ensure that there's decimals, even if they're 0. |
1054 | 605 | if (fraction.indexOf(".") == -1) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
606 | fraction += ".0"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
607 | |
1053 | 608 | if (spec.type == PrimitiveModel::Ring or spec.type == PrimitiveModel::Cone) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
609 | { |
1346
c4cb7dc850aa
reworked primitive generator
Teemu Piippo <teemu@hecknology.net>
parents:
1345
diff
changeset
|
610 | QString spacing = (spec.ringNumber < 10) ? " " : ""; |
1054 | 611 | description = format("%1 %2%3 x %4", PrimitiveModel::typeName(spec.type), spacing, spec.ringNumber, fraction); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
612 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
613 | else |
1346
c4cb7dc850aa
reworked primitive generator
Teemu Piippo <teemu@hecknology.net>
parents:
1345
diff
changeset
|
614 | { |
1054 | 615 | description = format("%1 %2", PrimitiveModel::typeName(spec.type), fraction); |
1346
c4cb7dc850aa
reworked primitive generator
Teemu Piippo <teemu@hecknology.net>
parents:
1345
diff
changeset
|
616 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
617 | |
1340
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
618 | // Prepend "Hi-Res" or "Lo-Res" as appropriate. |
1019
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
619 | if (spec.divisions == HighResolution) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
620 | description.insert (0, "Hi-Res "); |
1340
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
621 | else if (spec.divisions == LowResolution) |
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
622 | description.insert (0, "Lo-Res "); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
623 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
624 | LDDocument* document = m_window->newDocument(); |
1053 | 625 | document->setDefaultName(fileName); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
626 | |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1320
diff
changeset
|
627 | if (not config::defaultName().isEmpty()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
628 | { |
1340
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
629 | document->header.license = LDHeader::defaultLicense(); |
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
630 | document->header.author = format("%1 [%2]", config::defaultName(), config::defaultUser()); |
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
631 | } |
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
632 | else |
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
633 | { |
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
634 | document->header.author = APPNAME; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
635 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
636 | |
1090
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
637 | document->setFrozen(false); |
1312 | 638 | document->header.name = fileName; |
639 | document->header.description = description; | |
640 | ||
1340
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
641 | if (spec.divisions == HighResolution) |
1312 | 642 | document->header.type = LDHeader::Primitive_48; |
1340
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
643 | else if (spec.divisions == LowResolution) |
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
644 | document->header.type = LDHeader::Primitive_8; |
1312 | 645 | else |
1340
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
646 | document->header.type = LDHeader::Primitive; |
1312 | 647 | |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1320
diff
changeset
|
648 | if (config::useCaLicense()) |
1312 | 649 | document->header.license = LDHeader::CaLicense; |
650 | else | |
651 | document->header.license =LDHeader::UnspecifiedLicense; | |
652 | ||
653 | document->setWinding(CounterClockwise); | |
1080
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
654 | spec.generateBody(*document); |
1340
ea1b3ea9a3ca
more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
655 | document->history()->setIgnoring(false); |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
656 | return document; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
657 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
658 | |
1053 | 659 | /* |
660 | * PrimitiveManager :: getPrimitive | |
661 | * | |
662 | * Gets a primitive by the given model. If the primitive cannot be found, it will be automatically generated. | |
663 | */ | |
664 | LDDocument* PrimitiveManager::getPrimitive(const PrimitiveModel& model) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
665 | { |
1345
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
666 | // Try find with the new style name. |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
667 | QString name = model.makeFileName(PrimitiveModel::NewStyleName); |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
668 | LDDocument* document = m_window->documents()->getDocumentByName(name); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
669 | |
1090
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
670 | if (not document) |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
671 | { |
1345
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
672 | // Not found, try the legacy name |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
673 | QString name = model.makeFileName(PrimitiveModel::LegacyStyleName); |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
674 | document = m_window->documents()->getDocumentByName(name); |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
675 | } |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
676 | |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
677 | if (not document) |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
678 | { |
1e345ed80a1d
added support for new style primitive names
Teemu Piippo <teemu@hecknology.net>
parents:
1340
diff
changeset
|
679 | // Not found either, generate it. |
1090
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
680 | document = generatePrimitive(model); |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
681 | m_window->openDocumentForEditing(document); |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
682 | } |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
683 | |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
684 | return document; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
685 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
686 | |
1053 | 687 | /* |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
688 | * Returns the amount of columns in the primitives tree (1) |
1053 | 689 | */ |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
690 | int PrimitiveManager::columnCount(const QModelIndex&) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
691 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
692 | return 1; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
693 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
694 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
695 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
696 | * For an index that points to a primitive, returns the category that contains it |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
697 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
698 | static PrimitiveCategory* categoryForPrimitiveIndex(const QModelIndex& primitiveIndex) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
699 | { |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
700 | return static_cast<PrimitiveCategory*>(primitiveIndex.internalPointer()); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
701 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
702 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
703 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
704 | * Returns data from the tree model. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
705 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
706 | QVariant PrimitiveManager::data(const QModelIndex& index, int role) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
707 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
708 | if (index.isValid()) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
709 | { |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
710 | if (categoryForPrimitiveIndex(index) != nullptr) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
711 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
712 | // Index points to a primitive, return primitive information. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
713 | Primitive& primitive = categoryForPrimitiveIndex(index)->primitives[index.row()]; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
714 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
715 | switch(role) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
716 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
717 | case Qt::DisplayRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
718 | return format("%1 - %2", primitive.name, primitive.title); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
719 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
720 | case Qt::DecorationRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
721 | return MainWindow::getIcon("subfilereference"); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
722 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
723 | case PrimitiveNameRole: |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
724 | return primitive.name; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
725 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
726 | case PrimitiveDescriptionRole: |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
727 | return primitive.title; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
728 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
729 | default: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
730 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
731 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
732 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
733 | else |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
734 | { |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
735 | // Index points to a category, return category information. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
736 | PrimitiveCategory* category = this->m_categories[index.row()]; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
737 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
738 | switch (role) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
739 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
740 | case Qt::DisplayRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
741 | return category->name(); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
742 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
743 | case Qt::DecorationRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
744 | return MainWindow::getIcon("folder"); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1285
diff
changeset
|
745 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
746 | default: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
747 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
748 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
749 | } |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
750 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
751 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
752 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
753 | // Index is invalid. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
754 | return {}; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
755 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
756 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
757 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
758 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
759 | * For a row and parent index, returns a child index. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
760 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
761 | QModelIndex PrimitiveManager::index(int row, int, const QModelIndex& parent) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
762 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
763 | if (parent.isValid()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
764 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
765 | if (categoryForPrimitiveIndex(parent)) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
766 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
767 | // Parent is a primitive index. Primitives cannot have children so return an |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
768 | // invalid index. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
769 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
770 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
771 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
772 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
773 | // Parent is a category, return an index to a primitive |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
774 | PrimitiveCategory* category = m_categories[parent.row()]; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
775 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
776 | // Create an index inside the category |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
777 | if (row >= 0 and row < category->primitives.size()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
778 | return this->createIndex(row, 0, category); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
779 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
780 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
781 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
782 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
783 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
784 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
785 | // Create a top-level index pointing to a category |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
786 | if (row >= 0 and row < this->m_categories.size()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
787 | return this->createIndex(row, 0, nullptr); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
788 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
789 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
790 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
791 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
792 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
793 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
794 | * For a primitive index, find the category index that contains it. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
795 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
796 | QModelIndex PrimitiveManager::parent(const QModelIndex &index) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
797 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
798 | int row = this->m_categories.indexOf(categoryForPrimitiveIndex(index)); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
799 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
800 | if (row != -1) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
801 | return this->createIndex(row, 0, nullptr); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
802 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
803 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
804 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
805 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
806 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
807 | * Returns the amount of rows contained inside the given index. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
808 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
809 | int PrimitiveManager::rowCount(const QModelIndex& parent) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
810 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
811 | if (parent.isValid()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
812 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
813 | if (categoryForPrimitiveIndex(parent)) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
814 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
815 | // Primitives don't have child nodes, so return 0. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
816 | return 0; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
817 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
818 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
819 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
820 | // For categories, return the amount of primitives contained. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
821 | return this->m_categories[parent.row()]->primitives.size(); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
822 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
823 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
824 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
825 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
826 | // For top-level, return the amount of categories. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
827 | return this->m_categories.size(); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
828 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
829 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
830 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
831 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
832 | * Returns a static "Primitives" text for the header. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
833 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
834 | QVariant PrimitiveManager::headerData(int section, Qt::Orientation, int role) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
835 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
836 | if (section == 0 and role == Qt::DisplayRole) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
837 | return tr("Primitives"); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
838 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
839 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
840 | } |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
841 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
842 | // |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
843 | // --------------------------------------------------------------------------------------------------------------------- |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
844 | // |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
845 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
846 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
847 | PrimitiveCategory::PrimitiveCategory (QString name, QObject* parent) : |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
848 | QObject (parent), |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
849 | m_name (name) {} |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
850 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
851 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
852 | bool PrimitiveCategory::isValidToInclude() |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
853 | { |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
854 | return not patterns.isEmpty(); |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
855 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
856 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
857 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
858 | QString PrimitiveCategory::name() const |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
859 | { |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
860 | return m_name; |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
861 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
862 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
863 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
864 | /* |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
865 | * PrimitiveScanner :: PrimitiveScanner |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
866 | * |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
867 | * Constructs a primitive scanner. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
868 | */ |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
869 | PrimitiveScanner::PrimitiveScanner(PrimitiveManager* parent) : |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
870 | QObject(parent), |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
871 | HierarchyElement(parent), |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
872 | m_manager(parent) |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
873 | { |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1320
diff
changeset
|
874 | for (const Library& library : config::libraries()) |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
875 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
876 | QDir dir {library.path}; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
877 | if (dir.exists("p") and QFileInfo {dir.filePath("p")}.isDir()) |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
878 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
879 | directories.push(dir.filePath("p")); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
880 | |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
881 | if (dir.exists("p/48") and QFileInfo {dir.filePath("p/48")}.isDir()) |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
882 | directories.push(dir.filePath("p/48")); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
883 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
884 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
885 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
886 | print("Scanning primitives..."); |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
887 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
888 | |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
889 | PrimitiveScanner::~PrimitiveScanner() |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
890 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
891 | delete this->currentIterator; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
892 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
893 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
894 | /* |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
895 | * PrimitiveScanner :: scannedPrimitives |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
896 | * |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
897 | * Returns a vector containing all the primitives found. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
898 | */ |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
899 | const QVector<Primitive> &PrimitiveScanner::scannedPrimitives() const |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
900 | { |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
901 | return m_scannedPrimitives; |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
902 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
903 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
904 | /* |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
905 | * PrimitiveScanner :: work |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
906 | * |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
907 | * Does one step of work, processes up to 100 primitives. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
908 | * If the scanner does not finish work by this function call, it will ask the event loop to call this method again. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
909 | */ |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
910 | void PrimitiveScanner::work() |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
911 | { |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
912 | while (this->currentIterator == nullptr or not this->currentIterator->hasNext()) |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
913 | { |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
914 | delete this->currentIterator; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
915 | this->currentIterator = nullptr; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
916 | |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
917 | if (this->directories.isEmpty()) |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
918 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
919 | // If there are no more primitives to iterate, we're done. Now save this information into a cache file. |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
920 | std::sort( |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
921 | m_scannedPrimitives.begin(), |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
922 | m_scannedPrimitives.end(), |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
923 | [](const Primitive& one, const Primitive& other) -> bool |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
924 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
925 | return one.title < other.title; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
926 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
927 | ); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
928 | QString path = m_manager->getPrimitivesCfgPath(); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
929 | QFile configFile = {path}; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
930 | |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
931 | if (configFile.open(QIODevice::WriteOnly | QIODevice::Text)) |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
932 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
933 | for (Primitive& primitive : m_scannedPrimitives) |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
934 | fprint(configFile, "%1 %2\r\n", primitive.name, primitive.title); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
935 | |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
936 | configFile.close(); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
937 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
938 | else |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
939 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
940 | QMessageBox::critical( |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
941 | m_window, |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
942 | tr("Error"), |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
943 | format( |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
944 | tr("Couldn't write primitive list %1: %2"), |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
945 | path, |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
946 | configFile.errorString() |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
947 | ) |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
948 | ); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
949 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
950 | |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
951 | emit workDone(); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
952 | return; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
953 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
954 | else |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
955 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
956 | this->currentIterator = new QDirIterator {this->directories.pop()}; |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
957 | this->m_basePathLength = this->currentIterator->path().length(); |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
958 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
959 | } |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
960 | |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
961 | for (int i = 0; this->currentIterator->hasNext() and i < 100; ++i) |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
962 | { |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
963 | QString filename = this->currentIterator->next(); |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
964 | QFile file = {filename}; |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
965 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
966 | if (file.open (QIODevice::ReadOnly)) |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
967 | { |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
968 | Primitive primitive; |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
969 | primitive.name = LDDocument::shortenName(filename); |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
970 | primitive.category = nullptr; |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
971 | primitive.title = QString::fromUtf8(file.readLine().simplified()); |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
972 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
973 | if (primitive.title[0] == '0') |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
974 | { |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
975 | primitive.title.remove(0, 1); // remove 0 |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
976 | primitive.title = primitive.title.trimmed(); |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
977 | } |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
978 | |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
979 | m_scannedPrimitives << primitive; |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
980 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
981 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
982 | |
1309
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
983 | // Defer to event loop, pick up the work later. |
c72e7e09bda8
reworked primitive scanning
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
984 | QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection); |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
985 | } |